Mesa (master): gallium/hud: add CPU usage support for FreeBSD
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Apr 7 07:04:23 UTC 2019
Module: Mesa
Branch: master
Commit: c5a6e72e15b67b37e5b2e35721261ec3da60c045
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c5a6e72e15b67b37e5b2e35721261ec3da60c045
Author: Greg V <greg at unrelenting.technology>
Date: Sun Mar 3 18:40:58 2019 +0300
gallium/hud: add CPU usage support for FreeBSD
Reviewed-by: Eric Engestrom <eric at engestrom.ch>
---
src/gallium/auxiliary/hud/hud_cpu.c | 45 +++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/src/gallium/auxiliary/hud/hud_cpu.c b/src/gallium/auxiliary/hud/hud_cpu.c
index b7a524330bf..7059226985d 100644
--- a/src/gallium/auxiliary/hud/hud_cpu.c
+++ b/src/gallium/auxiliary/hud/hud_cpu.c
@@ -38,6 +38,11 @@
#ifdef PIPE_OS_WINDOWS
#include <windows.h>
#endif
+#ifdef PIPE_OS_FREEBSD
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/resource.h>
+#endif
#ifdef PIPE_OS_WINDOWS
@@ -86,6 +91,46 @@ get_cpu_stats(unsigned cpu_index, uint64_t *busy_time, uint64_t *total_time)
return TRUE;
}
+#elif defined(PIPE_OS_FREEBSD)
+
+static boolean
+get_cpu_stats(unsigned cpu_index, uint64_t *busy_time, uint64_t *total_time)
+{
+ long cp_time[CPUSTATES];
+ size_t len;
+
+ if (cpu_index == ALL_CPUS) {
+ len = sizeof(cp_time);
+
+ if (sysctlbyname("kern.cp_time", cp_time, &len, NULL, 0) == -1)
+ return FALSE;
+ } else {
+ long *cp_times = NULL;
+
+ if (sysctlbyname("kern.cp_times", NULL, &len, NULL, 0) == -1)
+ return FALSE;
+
+ if (len < (cpu_index + 1) * sizeof(cp_time))
+ return FALSE;
+
+ cp_times = malloc(len);
+
+ if (sysctlbyname("kern.cp_times", cp_times, &len, NULL, 0) == -1)
+ return FALSE;
+
+ memcpy(cp_time, cp_times + (cpu_index * CPUSTATES),
+ sizeof(cp_time));
+ free(cp_times);
+ }
+
+ *busy_time = cp_time[CP_USER] + cp_time[CP_NICE] +
+ cp_time[CP_SYS] + cp_time[CP_INTR];
+
+ *total_time = *busy_time + cp_time[CP_IDLE];
+
+ return TRUE;
+}
+
#else
static boolean
More information about the mesa-commit
mailing list