summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_aux.h1
-rw-r--r--lib/intel_os.c34
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 25a479f2..948101d2 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -61,6 +61,7 @@ void igt_wait_for_keypress(void);
/* These are separate to allow easier testing when porting, see the comment at
* the bottom of intel_os.c. */
+uint64_t intel_get_avail_ram_mb(void);
uint64_t intel_get_total_ram_mb(void);
uint64_t intel_get_total_swap_mb(void);
diff --git a/lib/intel_os.c b/lib/intel_os.c
index fb9f19cb..6f0621c7 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -86,6 +86,40 @@ intel_get_total_ram_mb(void)
}
/**
+ * intel_get_avail_ram_mb:
+ *
+ * Returns:
+ * The amount of unused system RAM available in MB.
+ */
+uint64_t
+intel_get_avail_ram_mb(void)
+{
+ uint64_t retval;
+
+#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
+ struct sysinfo sysinf;
+ int ret;
+
+ ret = sysinfo(&sysinf);
+ assert(ret == 0);
+
+ retval = sysinf.freeram;
+ retval *= sysinf.mem_unit;
+#elif defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES) /* Solaris */
+ long pagesize, npages;
+
+ pagesize = sysconf(_SC_PAGESIZE);
+ npages = sysconf(_SC_AVPHYS_PAGES);
+
+ retval = (uint64_t) pagesize * npages;
+#else
+#error "Unknown how to get available RAM for this OS"
+#endif
+
+ return retval / (1024*1024);
+}
+
+/**
* intel_get_total_swap_mb:
*
* Returns: