diff options
author | Jan Beich <[email protected]> | 2019-08-31 18:32:16 +0000 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2019-09-03 22:53:15 -0400 |
commit | 8e92ce9ba566dd34e6f99b0042d16cba4b12f787 (patch) | |
tree | 6672cc6fe547116e0d5d112050eb9be31adc0a08 | |
parent | ef621a73f720e1956ca356c1147d3b3dc680da0d (diff) |
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 <[email protected]>
-rw-r--r-- | src/gallium/auxiliary/hud/hud_cpu.c | 43 |
1 files 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] + |