[igt-dev] [PATCH i-g-t v1 4/6] lib/igt_os.c: Add FreeBSD system info collection
Jake Freeland
jake at technologyfriends.net
Fri Oct 7 23:27:55 UTC 2022
Use sysctlbyname() to gather RAM and swap information for
any FreeBSD system using igt.
Signed-off-by: Jake Freeland <jfree at freebsd.org>
---
lib/igt_os.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lib/igt_os.c b/lib/igt_os.c
index bdd5d933..ac8960f8 100644
--- a/lib/igt_os.c
+++ b/lib/igt_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,15 @@ igt_get_avail_ram_mb(void)
npages = sysconf(_SC_AVPHYS_PAGES);
retval = (uint64_t) pagesize * npages;
+#elif defined(__FreeBSD__)
+ uint64_t npages, pagesize;
+ size_t npages_len = sizeof(npages);
+ size_t pagesize_len = sizeof(pagesize);
+
+ sysctlbyname("vm.stats.vm.v_free_count", &npages, &npages_len, NULL, 0);
+ sysctlbyname("vm.stats.vm.v_page_size", &pagesize, &pagesize_len, NULL, 0);
+
+ retval = pagesize * npages;
#else
#error "Unknown how to get available RAM for this OS"
#endif
@@ -210,6 +221,13 @@ igt_get_total_swap_mb(void)
free(buf);
retval = (uint64_t) pagesize * totalpages;
+#elif defined(__FreeBSD__)
+ uint64_t swap_total;
+ size_t swap_total_len = sizeof(swap_total);
+
+ sysctlbyname("vm.swap_total", &swap_total, &swap_total_len, NULL, 0);
+
+ retval = swap_total;
#else
#warning "Unknown how to get swap size for this OS"
return 0;
--
2.37.3
More information about the igt-dev
mailing list