summaryrefslogtreecommitdiff
path: root/lib/libc/sys
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2018-07-12 01:23:39 +0000
committercheloha <cheloha@cvs.openbsd.org>2018-07-12 01:23:39 +0000
commit002672cb62f0ac2d4943a71f9ffdf5e1ec38e10d (patch)
tree1f01707e432a7f62f55ac7c1fa4880b4b059b9b5 /lib/libc/sys
parent83a7dd06f8186000336c23fb99f58ba067be43b8 (diff)
Add hw.ncpuonline to count the number of online CPUs.
The introduction of hw.smt means that logical CPUs can be disabled after boot and prior to suspend/resume. If hw.smt=0 (the default), there needs to be a way to count the number of hardware threads available on the system at any given time. So, import HW_NCPUONLINE/hw.ncpuonline from NetBSD and document it. hw.ncpu becomes equal to the number of CPUs given to sched_init_cpu() during boot, while hw.ncpuonline is equal to the number of CPUs available to the scheduler in the cpuset "sched_all_cpus". Set_SC_NPROCESSORS_ONLN equal to this new sysctl and keep _SC_NPROCESSORS_CONF equal to hw.ncpu. This is preferable to adding a new sysctl to count the number of configured CPUs and keeping hw.ncpu equal to the number of online CPUs because such a change would break software in the ecosystem that relies on HW_NCPU/hw.ncpu to measure CPU usage and the like. Such software in base includes top(1), systat(1), and snmpd(8), and perhaps others. We don't need additional locking to count the cardinality of a cpuset in this case because the only interfaces that can modify said cardinality are sysctl(2) and ioctl(2), both of which are under the KERNEL_LOCK. Software using HW_NCPU/hw.ncpu to determine optimal parallism will need to be updated to use HW_NCPUONLINE/hw.ncpuonline. Until then, such software may perform suboptimally. However, most changes will be similar to the change included here for libcxx's std::thread:hardware_concurrency(): using HW_NCPUONLINE in lieu of HW_NCPU should be sufficient for determining optimal parallelism for most software if the change to _SC_NPROCESSORS_ONLN is insufficient. Prompted by deraadt. Discussed at length with kettenis, deraadt, and sthen. Lots of patch tweaks from kettenis. ok kettenis, "proceed" deraadt
Diffstat (limited to 'lib/libc/sys')
-rw-r--r--lib/libc/sys/sysctl.29
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/libc/sys/sysctl.2 b/lib/libc/sys/sysctl.2
index 6a1de7b0231..b600074fea1 100644
--- a/lib/libc/sys/sysctl.2
+++ b/lib/libc/sys/sysctl.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sysctl.2,v 1.9 2018/06/21 20:28:36 jmc Exp $
+.\" $OpenBSD: sysctl.2,v 1.10 2018/07/12 01:23:38 cheloha Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: June 21 2018 $
+.Dd $Mdocdate: July 12 2018 $
.Dt SYSCTL 2
.Os
.Sh NAME
@@ -286,6 +286,7 @@ privileges may change the value.
.It Dv HW_MODEL Ta "string" Ta "no"
.It Dv HW_NCPU Ta "integer" Ta "no"
.It Dv HW_NCPUFOUND Ta "integer" Ta "no"
+.It Dv HW_NCPUONLINE Ta "integer" Ta "no"
.It Dv HW_PAGESIZE Ta "integer" Ta "no"
.It Dv HW_PERFPOLICY Ta "string" Ta "yes"
.It Dv HW_PHYSMEM Ta "integer" Ta "no"
@@ -328,9 +329,11 @@ The machine class.
.It Dv HW_MODEL Pq Va hw.model
The machine model.
.It Dv HW_NCPU Pq Va hw.ncpu
-The number of CPUs being used.
+The number of CPUs configured.
.It Dv HW_NCPUFOUND Pq Va hw.ncpufound
The number of CPUs found.
+.It Dv HW_NCPUONLINE Pq Va hw.ncpuonline
+The number of CPUs online.
.It Dv HW_PAGESIZE Pq Va hw.pagesize
The software page size.
.It Dv HW_PERFPOLICY Pq Va hw.perfpolicy