summaryrefslogtreecommitdiff
path: root/sys/kern/kern_sysctl.c
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2020-01-02 08:52:54 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2020-01-02 08:52:54 +0000
commit7251a25e74118a15dfe6f4a785d0773a61f934a0 (patch)
tree4816fff7579fb9030220a4d32f7374aec19e1abb /sys/kern/kern_sysctl.c
parent5392528d26f2d18eb16e7b5807cb1dd868f4ad4f (diff)
Exclude offline cpus in KERN_CPTIME calculation. Without this too high
idle time is reported in tools like vmstat. OK visa@ benno@ krw@
Diffstat (limited to 'sys/kern/kern_sysctl.c')
-rw-r--r--sys/kern/kern_sysctl.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 0f61c5de1c0..e33a115ea98 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.368 2019/12/11 07:30:09 guenther Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.369 2020/01/02 08:52:53 claudio Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -521,17 +521,20 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
CPU_INFO_ITERATOR cii;
struct cpu_info *ci;
long cp_time[CPUSTATES];
- int i;
+ int i, n = 0;
memset(cp_time, 0, sizeof(cp_time));
CPU_INFO_FOREACH(cii, ci) {
+ if (!cpu_is_online(ci))
+ continue;
+ n++;
for (i = 0; i < CPUSTATES; i++)
cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
}
for (i = 0; i < CPUSTATES; i++)
- cp_time[i] /= ncpus;
+ cp_time[i] /= n;
return (sysctl_rdstruct(oldp, oldlenp, newp, &cp_time,
sizeof(cp_time)));