From fbae13899013491fa78499ba27641c2fadef1fb0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 23 Jan 2012 20:13:49 -0800 Subject: [PATCH] Add Solaris implementation of intel_get_total_swap_mb() Signed-off-by: Alan Coopersmith Signed-off-by: Daniel Vetter --- configure.ac | 1 + lib/intel_drm.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index edae77fa..c97c185a 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 ]) +AC_CHECK_FUNCS([swapctl]) # Initialize libtool AC_DISABLE_STATIC diff --git a/lib/intel_drm.c b/lib/intel_drm.c index 9e25448a..42cad3eb 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 #ifdef HAVE_STRUCT_SYSINFO_TOTALRAM #include +#elif defined(HAVE_SWAPCTL) /* Solaris */ +#include #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 */