Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/powerd/powerd.c
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
read_usage_times(int *load) | read_usage_times(int *load) | ||||
{ | { | ||||
static long *cp_times = NULL, *cp_times_old = NULL; | static long *cp_times = NULL, *cp_times_old = NULL; | ||||
static int ncpus = 0; | static int ncpus = 0; | ||||
size_t cp_times_len; | size_t cp_times_len; | ||||
int error, cpu, i, total; | int error, cpu, i, total; | ||||
int cpuload; | |||||
if (cp_times == NULL) { | if (cp_times == NULL) { | ||||
cp_times_len = 0; | cp_times_len = 0; | ||||
error = sysctl(cp_times_mib, 2, NULL, &cp_times_len, NULL, 0); | error = sysctl(cp_times_mib, 2, NULL, &cp_times_len, NULL, 0); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
if ((cp_times = malloc(cp_times_len)) == NULL) | if ((cp_times = malloc(cp_times_len)) == NULL) | ||||
return (errno); | return (errno); | ||||
Show All 15 Lines | if (load) { | ||||
for (cpu = 0; cpu < ncpus; cpu++) { | for (cpu = 0; cpu < ncpus; cpu++) { | ||||
total = 0; | total = 0; | ||||
for (i = 0; i < CPUSTATES; i++) { | for (i = 0; i < CPUSTATES; i++) { | ||||
total += cp_times[cpu * CPUSTATES + i] - | total += cp_times[cpu * CPUSTATES + i] - | ||||
cp_times_old[cpu * CPUSTATES + i]; | cp_times_old[cpu * CPUSTATES + i]; | ||||
} | } | ||||
if (total == 0) | if (total == 0) | ||||
continue; | continue; | ||||
*load += 100 - (cp_times[cpu * CPUSTATES + CP_IDLE] - | cpuload = 100 - (cp_times[cpu * CPUSTATES + CP_IDLE] - | ||||
cp_times_old[cpu * CPUSTATES + CP_IDLE]) * 100 / total; | cp_times_old[cpu * CPUSTATES + CP_IDLE]) * 100 / total; | ||||
if (cpuload > *load) | |||||
*load = cpuload; | |||||
} | } | ||||
} | } | ||||
memcpy(cp_times_old, cp_times, cp_times_len); | memcpy(cp_times_old, cp_times, cp_times_len); | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 617 Lines • Show Last 20 Lines |