Mesa (master): gallium/hud: add CPU usage support for DragonFly/NetBSD/OpenBSD

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Sep 4 02:54:38 UTC 2019


Module: Mesa
Branch: master
Commit: 8e92ce9ba566dd34e6f99b0042d16cba4b12f787
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8e92ce9ba566dd34e6f99b0042d16cba4b12f787

Author: Jan Beich <jbeich at FreeBSD.org>
Date:   Sat Aug 31 18:32:16 2019 +0000

gallium/hud: add CPU usage support for DragonFly/NetBSD/OpenBSD

Each BSD has slightly different sysctl for retrieving per-CPU times.
FreeBSD returns long while NetBSD returns uint64_t. On OpenBSD return
type differs between summation and per-CPU times. DragonFly is
compatible with FreeBSD.

Signed-off-by: Jan Beich <jbeich at FreeBSD.org>

---

 src/gallium/auxiliary/hud/hud_cpu.c | 43 +++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/hud/hud_cpu.c b/src/gallium/auxiliary/hud/hud_cpu.c
index 7059226985d..f10640bb40f 100644
--- a/src/gallium/auxiliary/hud/hud_cpu.c
+++ b/src/gallium/auxiliary/hud/hud_cpu.c
@@ -38,11 +38,15 @@
 #ifdef PIPE_OS_WINDOWS
 #include <windows.h>
 #endif
-#ifdef PIPE_OS_FREEBSD
+#if defined(PIPE_OS_BSD)
 #include <sys/types.h>
 #include <sys/sysctl.h>
+#if defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD)
+#include <sys/sched.h>
+#else
 #include <sys/resource.h>
 #endif
+#endif
 
 
 #ifdef PIPE_OS_WINDOWS
@@ -91,20 +95,54 @@ get_cpu_stats(unsigned cpu_index, uint64_t *busy_time, uint64_t *total_time)
    return TRUE;
 }
 
-#elif defined(PIPE_OS_FREEBSD)
+#elif defined(PIPE_OS_BSD)
 
 static boolean
 get_cpu_stats(unsigned cpu_index, uint64_t *busy_time, uint64_t *total_time)
 {
+#if defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD)
+   uint64_t cp_time[CPUSTATES];
+#else
    long cp_time[CPUSTATES];
+#endif
    size_t len;
 
    if (cpu_index == ALL_CPUS) {
       len = sizeof(cp_time);
 
+#if defined(PIPE_OS_NETBSD)
+      int mib[] = { CTL_KERN, KERN_CP_TIME };
+
+      if (sysctl(mib, ARRAY_SIZE(mib), cp_time, &len, NULL, 0) == -1)
+         return FALSE;
+#elif defined(PIPE_OS_OPENBSD)
+      int mib[] = { CTL_KERN, KERN_CPTIME };
+      long sum_cp_time[CPUSTATES];
+
+      len = sizeof(sum_cp_time);
+      if (sysctl(mib, ARRAY_SIZE(mib), sum_cp_time, &len, NULL, 0) == -1)
+         return FALSE;
+
+      for (int state = 0; state < CPUSTATES; state++)
+         cp_time[state] = sum_cp_time[state];
+#else
       if (sysctlbyname("kern.cp_time", cp_time, &len, NULL, 0) == -1)
          return FALSE;
+#endif
    } else {
+#if defined(PIPE_OS_NETBSD)
+      int mib[] = { CTL_KERN, KERN_CP_TIME, cpu_index };
+
+      len = sizeof(cp_time);
+      if (sysctl(mib, ARRAY_SIZE(mib), cp_time, &len, NULL, 0) == -1)
+         return FALSE;
+#elif defined(PIPE_OS_OPENBSD)
+      int mib[] = { CTL_KERN, KERN_CPTIME2, cpu_index };
+
+      len = sizeof(cp_time);
+      if (sysctl(mib, ARRAY_SIZE(mib), cp_time, &len, NULL, 0) == -1)
+         return FALSE;
+#else
       long *cp_times = NULL;
 
       if (sysctlbyname("kern.cp_times", NULL, &len, NULL, 0) == -1)
@@ -121,6 +159,7 @@ get_cpu_stats(unsigned cpu_index, uint64_t *busy_time, uint64_t *total_time)
       memcpy(cp_time, cp_times + (cpu_index * CPUSTATES),
             sizeof(cp_time));
       free(cp_times);
+#endif
    }
 
    *busy_time = cp_time[CP_USER] + cp_time[CP_NICE] +




More information about the mesa-commit mailing list