[PATCH:intel-gpu-tools 3/3] Add Solaris implementation of intel_get_total_swap_mb()

Alan Coopersmith alan.coopersmith at oracle.com
Mon Jan 23 20:13:49 PST 2012


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 configure.ac    |    1 +
 lib/intel_drm.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 9089420..b94d355 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_HEADERS([termios.h])
 AC_CHECK_MEMBERS([struct sysinfo.totalram],[],[],[AC_INCLUDES_DEFAULT
 #include <sys/sysinfo.h>
 ])
+AC_CHECK_FUNCS([swapctl])
 
 # Initialize libtool
 AC_DISABLE_STATIC
diff --git a/lib/intel_drm.c b/lib/intel_drm.c
index 9e25448..42cad3e 100644
--- a/lib/intel_drm.c
+++ b/lib/intel_drm.c
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2008 Intel Corporation
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -40,6 +41,8 @@
 #include <sys/mman.h>
 #ifdef HAVE_STRUCT_SYSINFO_TOTALRAM
 #include <sys/sysinfo.h>
+#elif defined(HAVE_SWAPCTL) /* Solaris */
+#include <sys/swap.h>
 #endif
 
 #include "intel_gpu_tools.h"
@@ -99,7 +102,7 @@ intel_get_total_ram_mb(void)
 	pagesize = sysconf(_SC_PAGESIZE);
         npages = sysconf(_SC_PHYS_PAGES);
 
-	retval = pagesize * npages;
+	retval = (uint64_t) pagesize * npages;
 #else
 #error "Unknown how to get RAM size for this OS"
 #endif
@@ -121,9 +124,66 @@ intel_get_total_swap_mb(void)
 
 	retval = sysinf.totalswap;
 	retval *= sysinf.mem_unit;
+#elif defined(HAVE_SWAPCTL) /* Solaris */
+	long pagesize = sysconf(_SC_PAGESIZE);
+	uint64_t totalpages = 0;
+	swaptbl_t *swt;
+	char *buf;
+	int n, i;
+
+	if ((n = swapctl(SC_GETNSWP, NULL)) == -1) {
+	    perror("swapctl: GETNSWP");
+	    return 0;
+	}
+	if (n == 0) {
+	    /* no error, but no swap devices either */
+	    return 0;
+	}
+
+	swt = malloc(sizeof(struct swaptable) + (n * sizeof(swapent_t)));
+	buf = malloc(n * MAXPATHLEN);
+	if (!swt || !buf) {
+	    perror("malloc");
+	} else {
+	    swt->swt_n = n;
+	    for (i = 0 ; i < n; i++) {
+		swt->swt_ent[i].ste_path = buf + (i * MAXPATHLEN);
+	    }
+
+	    if ((n = swapctl(SC_LIST, swt)) == -1) {
+		perror("swapctl: LIST");
+	    } else {
+		for (i = 0; i < swt->swt_n; i++) {
+		    totalpages += swt->swt_ent[i].ste_pages;
+		}
+	    }
+	}
+	free(swt);
+	free(buf);
+
+	retval = (uint64_t) pagesize * totalpages;
 #else
 #error "Unknown how to get swap size for this OS"
 #endif
 
 	return retval / (1024*1024);
 }
+
+
+/*
+ * When testing a port to a new platform, create a standalone test binary
+ * by running:
+ * cc -o porttest intel_drm.c -I.. -DSTANDALONE_TEST `pkg-config --cflags libdrm`
+ * and then running the resulting porttest program.
+ */
+#ifdef STANDALONE_TEST
+void *mmio;
+
+int main(int argc, char **argv)
+{
+    printf("Total RAM:  %" PRIu64 " Mb\n", intel_get_total_ram_mb());
+    printf("Total Swap: %" PRIu64 " Mb\n", intel_get_total_swap_mb());
+
+    return 0;
+}
+#endif /* STANDALONE_TEST */
-- 
1.7.3.2



More information about the xorg-devel mailing list