From: Jan Beich Date: Sat, 31 Aug 2019 18:32:16 +0000 (+0000) Subject: gallium/hud: add CPU usage support for DragonFly/NetBSD/OpenBSD X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8e92ce9ba566dd34e6f99b0042d16cba4b12f787;p=mesa.git 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 --- 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 #endif -#ifdef PIPE_OS_FREEBSD +#if defined(PIPE_OS_BSD) #include #include +#if defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD) +#include +#else #include #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] +