diff --git a/src/system.c b/src/system.c index 9a0caf4..c8f40db 100644 --- a/src/system.c +++ b/src/system.c @@ -249,7 +249,9 @@ _cpu_state_get(cpu_core_t **cores, int ncpu) core->idle = idle; } #elif defined(__OpenBSD__) - struct cpustats cpu_times[CPU_STATES]; + static struct cpustats cpu_times[CPU_STATES]; + static int cpu_time_mib[] = { CTL_KERN, KERN_CPUSTATS, 0 }; + memset(&cpu_times, 0, CPU_STATES * sizeof(struct cpustats)); if (!ncpu) return; @@ -257,7 +259,6 @@ _cpu_state_get(cpu_core_t **cores, int ncpu) for (i = 0; i < ncpu; i++) { core = cores[i]; - int cpu_time_mib[] = { CTL_KERN, KERN_CPUSTATS, 0 }; size = sizeof(struct cpustats); cpu_time_mib[2] = i; if (sysctl(cpu_time_mib, 3, &cpu_times[i], &size, NULL, 0) < 0) diff --git a/src/tingle/tingle.c b/src/tingle/tingle.c index c1a8358..ced4b90 100644 --- a/src/tingle/tingle.c +++ b/src/tingle/tingle.c @@ -314,7 +314,9 @@ _cpu_state_get(cpu_core_t **cores, int ncpu) core->idle = idle; } #elif defined(__OpenBSD__) - struct cpustats cpu_times[CPU_STATES]; + static struct cpustats cpu_times[CPU_STATES]; + static int cpu_time_mib[] = { CTL_KERN, KERN_CPUSTATS, 0 }; + memset(&cpu_times, 0, CPU_STATES * sizeof(struct cpustats)); if (!ncpu) return; @@ -322,7 +324,6 @@ _cpu_state_get(cpu_core_t **cores, int ncpu) for (i = 0; i < ncpu; i++) { core = cores[i]; - int cpu_time_mib[] = { CTL_KERN, KERN_CPUSTATS, 0 }; size = sizeof(struct cpustats); cpu_time_mib[2] = i; if (sysctl(cpu_time_mib, 3, &cpu_times[i], &size, NULL, 0) < 0)