aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorGreg V <[email protected]>2019-03-03 18:40:58 +0300
committerEric Engestrom <[email protected]>2019-04-07 06:47:57 +0000
commitc5a6e72e15b67b37e5b2e35721261ec3da60c045 (patch)
tree35d367d3fea1abd4a9887648bfceb54c1df963ed /src/gallium/auxiliary
parent9c46046f79a13e26440b517e73e76110ba095d00 (diff)
gallium/hud: add CPU usage support for FreeBSD
Reviewed-by: Eric Engestrom <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/hud/hud_cpu.c45
1 files changed, 45 insertions, 0 deletions
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