[igt-dev] [PATCH i-g-t 25/29] lib/intel_os: Implement get_avail_ram and get_total_swap for FreeBSD
D Scott Phillips
d.scott.phillips at intel.com
Wed Dec 11 00:52:31 UTC 2019
FreeBSD provides these values through sysctl.
Signed-off-by: D Scott Phillips <d.scott.phillips at intel.com>
---
lib/intel_os.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/lib/intel_os.c b/lib/intel_os.c
index 8458d39a..d476e9bc 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -44,6 +44,8 @@
#include <sys/sysinfo.h>
#elif defined(HAVE_SWAPCTL) /* Solaris */
#include <sys/swap.h>
+#elif defined(__FreeBSD__)
+#include <sys/sysctl.h>
#endif
#include <sys/resource.h>
@@ -148,6 +150,14 @@ intel_get_avail_ram_mb(void)
npages = sysconf(_SC_AVPHYS_PAGES);
retval = (uint64_t) pagesize * npages;
+#elif defined(__FreeBSD__)
+ int hw_physmem[] = {CTL_HW, HW_PHYSMEM};
+ size_t size = sizeof(retval);
+ int ret;
+ ret = sysctl(hw_physmem, ARRAY_SIZE(hw_physmem), &retval, &size, NULL,
+ 0);
+ if (ret != 0 || size != sizeof(retval))
+ retval = 0;
#else
#error "Unknown how to get available RAM for this OS"
#endif
@@ -210,6 +220,12 @@ intel_get_total_swap_mb(void)
free(buf);
retval = (uint64_t) pagesize * totalpages;
+#elif defined(__FreeBSD__)
+ size_t size = sizeof(retval);
+ int ret;
+ ret = sysctlbyname("vm.swap_total", &retval, &size, NULL, 0);
+ if (ret != 0 || size != sizeof(retval))
+ retval = 0;
#else
#warning "Unknown how to get swap size for this OS"
return 0;
--
2.23.0
More information about the igt-dev
mailing list