summaryrefslogtreecommitdiffstats
path: root/sys/sys/sched.h
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2018-11-17 23:10:07 +0000
committercheloha <cheloha@openbsd.org>2018-11-17 23:10:07 +0000
commitd52dbbbe91d6edf63cb99c67478456e8a00214a8 (patch)
tree3f5d1be5500cfe1f46a79bcce81b236b47276077 /sys/sys/sched.h
parentBe more careful when dumping cmsghdr struct. In the SCM_RIGHTS case an (diff)
downloadwireguard-openbsd-d52dbbbe91d6edf63cb99c67478456e8a00214a8.tar.xz
wireguard-openbsd-d52dbbbe91d6edf63cb99c67478456e8a00214a8.zip
Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.
Because of hw.smt we need a way to determine whether a given CPU is "online" or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS with an extensible struct. At the moment it's just KERN_CPTIME2 with a flags member, but it can grow as needed. KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are few (if any) packages in the wild still using the symbol so breakage in ports should be near zero. No other system inherited the symbol from BSDi, either. Then, use the new sysctl(2) in systat(1) and top(1): - systat(1) draws placeholder marks ('-') instead of percentages for offline CPUs in the cpu view. - systat(1) omits offline CPU ticks when drawing the "big bar" in the vmstat view. The upshot is that the bar isn't half idle when half your logical CPUs are disabled. - top(1) does not draw lines for offline CPUs; if CPUs toggle on or offline in interactive mode we redraw the display to expand/reduce space for the new/missing CPUs. This is consistent with what some top(1) implementations do on Linux. - top(1) omits offline CPUs from the totals when CPU totals are combined into a single line (the '-1' flag). Originally prompted by deraadt@. Discussed endlessly with deraadt@, ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also discussed with jca@. Earlier versions tested by jmc@, tb@, and many others. docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@, "Is your stuff in yet?" deraadt@
Diffstat (limited to 'sys/sys/sched.h')
-rw-r--r--sys/sys/sched.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/sys/sys/sched.h b/sys/sys/sched.h
index 103f1feaad0..baddb0669cf 100644
--- a/sys/sys/sched.h
+++ b/sys/sys/sched.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sched.h,v 1.49 2018/10/05 18:56:57 cheloha Exp $ */
+/* $OpenBSD: sched.h,v 1.50 2018/11/17 23:10:08 cheloha Exp $ */
/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
/*-
@@ -113,6 +113,13 @@ struct schedstate_percpu {
volatile u_int spc_spinning; /* this cpu is currently spinning */
};
+struct cpustats {
+ uint64_t cs_time[CPUSTATES]; /* CPU state statistics */
+ uint64_t cs_flags; /* see below */
+};
+
+#define CPUSTATS_ONLINE 0x0001 /* CPU is schedulable */
+
#ifdef _KERNEL
/* spc_flags */
@@ -161,6 +168,7 @@ void sched_stop_secondary_cpus(void);
#endif
#define cpu_is_idle(ci) ((ci)->ci_schedstate.spc_whichqs == 0)
+int cpu_is_online(struct cpu_info *);
void sched_init_runqueues(void);
void setrunqueue(struct proc *);