-/* $OpenBSD: sysconf.c,v 1.25 2017/09/10 18:20:00 guenther Exp $ */
+/* $OpenBSD: sysconf.c,v 1.26 2018/07/12 01:23:38 cheloha Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
break;
case _SC_NPROCESSORS_ONLN:
mib[0] = CTL_HW;
- mib[1] = HW_NCPU;
+ mib[1] = HW_NCPUONLINE;
break;
default:
-.\" $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.
.\" 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
.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"
.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
unsigned
thread::hardware_concurrency() _NOEXCEPT
{
-#if defined(CTL_HW) && defined(HW_NCPU)
+#if defined(CTL_HW) && defined(HW_NCPUONLINE)
unsigned n;
- int mib[2] = {CTL_HW, HW_NCPU};
+ int mib[2] = {CTL_HW, HW_NCPUONLINE};
std::size_t s = sizeof(n);
sysctl(mib, 2, &n, &s, 0, 0);
return n;
-/* $OpenBSD: kern_pledge.c,v 1.234 2018/06/25 22:29:16 kettenis Exp $ */
+/* $OpenBSD: kern_pledge.c,v 1.235 2018/07/12 01:23:38 cheloha Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
if (miblen == 2 && /* setproctitle() */
mib[0] == CTL_VM && mib[1] == VM_PSSTRINGS)
return (0);
- if (miblen == 2 && /* hw.ncpu */
- mib[0] == CTL_HW && mib[1] == HW_NCPU)
+ if (miblen == 2 && /* hw.ncpu / hw.ncpuonline */
+ mib[0] == CTL_HW && (mib[1] == HW_NCPU || mib[1] == HW_NCPUONLINE))
return (0);
if (miblen == 2 && /* vm.loadavg / getloadavg(3) */
mib[0] == CTL_VM && mib[1] == VM_LOADAVG)
-/* $OpenBSD: kern_sched.c,v 1.50 2018/07/07 15:19:25 visa Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.51 2018/07/12 01:23:38 cheloha Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
to->cs_set[i] = b->cs_set[i] & ~a->cs_set[i];
}
+int
+cpuset_cardinality(struct cpuset *cs)
+{
+ int cardinality, i, n;
+
+ cardinality = 0;
+
+ for (i = 0; i < CPUSET_ASIZE(ncpus); i++)
+ for (n = cs->cs_set[i]; n != 0; n &= n - 1)
+ cardinality++;
+
+ return (cardinality);
+}
+
+int
+sysctl_hwncpuonline(void)
+{
+ return cpuset_cardinality(&sched_all_cpus);
+}
+
#ifdef __HAVE_CPU_TOPOLOGY
#include <sys/sysctl.h>
-/* $OpenBSD: kern_sysctl.c,v 1.345 2018/07/02 14:36:33 visa Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.346 2018/07/12 01:23:38 cheloha Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
return (sysctl_rdint(oldp, oldlenp, newp, ncpus));
case HW_NCPUFOUND:
return (sysctl_rdint(oldp, oldlenp, newp, ncpusfound));
+ case HW_NCPUONLINE:
+ return (sysctl_rdint(oldp, oldlenp, newp,
+ sysctl_hwncpuonline()));
case HW_BYTEORDER:
return (sysctl_rdint(oldp, oldlenp, newp, BYTE_ORDER));
case HW_PHYSMEM:
-/* $OpenBSD: proc.h,v 1.250 2018/07/10 04:19:59 guenther Exp $ */
+/* $OpenBSD: proc.h,v 1.251 2018/07/12 01:23:38 cheloha Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
void cpuset_union(struct cpuset *, struct cpuset *, struct cpuset *);
void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *);
void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *);
+int cpuset_cardinality(struct cpuset *);
struct cpu_info *cpuset_first(struct cpuset *);
#endif /* _KERNEL */
-/* $OpenBSD: sched.h,v 1.46 2018/06/19 19:29:52 kettenis Exp $ */
+/* $OpenBSD: sched.h,v 1.47 2018/07/12 01:23:38 cheloha Exp $ */
/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
/*-
int sysctl_hwsetperf(void *, size_t *, void *, size_t);
int sysctl_hwperfpolicy(void *, size_t *, void *, size_t);
int sysctl_hwsmt(void *, size_t *, void *, size_t);
+int sysctl_hwncpuonline(void);
#ifdef MULTIPROCESSOR
void sched_start_secondary_cpus(void);
-/* $OpenBSD: sysctl.h,v 1.178 2018/06/19 19:29:52 kettenis Exp $ */
+/* $OpenBSD: sysctl.h,v 1.179 2018/07/12 01:23:38 cheloha Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
*/
#define HW_MACHINE 1 /* string: machine class */
#define HW_MODEL 2 /* string: specific machine model */
-#define HW_NCPU 3 /* int: number of cpus being used */
+#define HW_NCPU 3 /* int: number of configured cpus */
#define HW_BYTEORDER 4 /* int: machine byte order */
#define HW_PHYSMEM 5 /* int: total memory */
#define HW_USERMEM 6 /* int: non-kernel memory */
#define HW_UUID 18 /* string: universal unique id */
#define HW_PHYSMEM64 19 /* quad: total memory */
#define HW_USERMEM64 20 /* quad: non-kernel memory */
-#define HW_NCPUFOUND 21 /* int: number of cpus found*/
+#define HW_NCPUFOUND 21 /* int: number of cpus found */
#define HW_ALLOWPOWERDOWN 22 /* allow power button shutdown */
#define HW_PERFPOLICY 23 /* set performance policy */
#define HW_SMT 24 /* int: enable SMT/HT/CMT */
-#define HW_MAXID 25 /* number of valid hw ids */
+#define HW_NCPUONLINE 25 /* int: number of cpus being used */
+#define HW_MAXID 26 /* number of valid hw ids */
#define CTL_HW_NAMES { \
{ 0, 0 }, \
{ "allowpowerdown", CTLTYPE_INT }, \
{ "perfpolicy", CTLTYPE_STRING }, \
{ "smt", CTLTYPE_INT }, \
+ { "ncpuonline", CTLTYPE_INT }, \
}
/*