mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-10 17:36:11 +00:00
Add Solaris implementation of intel_get_total_swap_mb()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
parent
5c4e041dc8
commit
fbae138990
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user