From 90fdb320e64210bdbea1cbe460e0fd5a61de71ad Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sun, 19 Apr 2009 17:53:40 +0000 Subject: Count number of cpus found (potentially not attached) and store that in sysctl hw.ncpufound; ok miod kettenis --- sys/arch/amd64/amd64/mpbios.c | 6 ++++-- sys/arch/macppc/macppc/mainbus.c | 6 +++++- sys/arch/sparc64/sparc64/autoconf.c | 10 ++++++---- sys/dev/acpi/acpimadt.c | 6 ++++-- sys/kern/init_main.c | 3 ++- sys/kern/kern_sysctl.c | 4 +++- sys/sys/sysctl.h | 8 +++++--- sys/sys/systm.h | 5 +++-- 8 files changed, 32 insertions(+), 16 deletions(-) diff --git a/sys/arch/amd64/amd64/mpbios.c b/sys/arch/amd64/amd64/mpbios.c index fcd933ca661..ea9c270d1da 100644 --- a/sys/arch/amd64/amd64/mpbios.c +++ b/sys/arch/amd64/amd64/mpbios.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpbios.c,v 1.16 2009/01/13 19:38:44 grange Exp $ */ +/* $OpenBSD: mpbios.c,v 1.17 2009/04/19 17:53:39 deraadt Exp $ */ /* $NetBSD: mpbios.c,v 1.7 2003/05/15 16:32:50 fvdl Exp $ */ /*- @@ -692,8 +692,10 @@ mpbios_cpu(const u_int8_t *ent, struct device *self) /* check for BSP flag */ if (entry->cpu_flags & PROCENTRY_FLAG_BP) caa.cpu_role = CPU_ROLE_BP; - else + else { caa.cpu_role = CPU_ROLE_AP; + ncpusfound++; + } caa.caa_name = "cpu"; caa.cpu_number = entry->apic_id; diff --git a/sys/arch/macppc/macppc/mainbus.c b/sys/arch/macppc/macppc/mainbus.c index 17979431d74..25887a56cae 100644 --- a/sys/arch/macppc/macppc/mainbus.c +++ b/sys/arch/macppc/macppc/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.20 2007/10/14 17:29:04 kettenis Exp $ */ +/* $OpenBSD: mainbus.c,v 1.21 2009/04/19 17:53:39 deraadt Exp $ */ /* * Copyright (c) 1994, 1995 Carnegie-Mellon University. @@ -123,6 +123,7 @@ mbattach(struct device *parent, struct device *self, void *aux) */ cpucnt = 0; + ncpusfound = 0; node = OF_finddevice("/cpus"); if (node != -1) { for (node = OF_child(node); node != 0; node = OF_peer(node)) { @@ -135,6 +136,7 @@ mbattach(struct device *parent, struct device *self, void *aux) nca.ca_reg = reg; reg[0] = cpucnt; config_found(self, &nca, mbprint); + ncpusfound++; cpucnt++; } } @@ -144,6 +146,7 @@ mbattach(struct device *parent, struct device *self, void *aux) nca.ca_bus = &sc->sc_bus; nca.ca_reg = reg; reg[0] = 0; + ncpusfound++; config_found(self, &nca, mbprint); } @@ -167,6 +170,7 @@ mbattach(struct device *parent, struct device *self, void *aux) nca.ca_bus = &sc->sc_bus; nca.ca_reg = reg; reg[0] = 1; + ncpusfound++; config_found(self, &nca, mbprint); } } diff --git a/sys/arch/sparc64/sparc64/autoconf.c b/sys/arch/sparc64/sparc64/autoconf.c index 06cbd43b8cd..143f29289e1 100644 --- a/sys/arch/sparc64/sparc64/autoconf.c +++ b/sys/arch/sparc64/sparc64/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.104 2009/04/12 14:53:15 kettenis Exp $ */ +/* $OpenBSD: autoconf.c,v 1.105 2009/04/19 17:53:39 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.51 2001/07/24 19:32:11 eeh Exp $ */ /* @@ -215,7 +215,6 @@ str2hex(char *str, long *vp) int get_ncpus(void) { -#ifdef MULTIPROCESSOR int node, child, stack[4], depth, ncpus; char buf[32]; @@ -228,7 +227,7 @@ get_ncpus(void) if (node == 0 || node == -1) { if (--depth < 0) - return (ncpus); + goto done; stack[depth] = OF_peer(stack[depth]); continue; @@ -245,7 +244,10 @@ get_ncpus(void) stack[depth] = OF_peer(stack[depth]); } - return (0); +done: + ncpusfound = ncpus; +#ifdef MULTIPROCESSOR + return (ncpus); #else return (1); #endif diff --git a/sys/dev/acpi/acpimadt.c b/sys/dev/acpi/acpimadt.c index e0a8c9fd66b..6397c462617 100644 --- a/sys/dev/acpi/acpimadt.c +++ b/sys/dev/acpi/acpimadt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpimadt.c,v 1.22 2009/02/16 20:11:06 kettenis Exp $ */ +/* $OpenBSD: acpimadt.c,v 1.23 2009/04/19 17:53:39 deraadt Exp $ */ /* * Copyright (c) 2006 Mark Kettenis * @@ -240,8 +240,10 @@ acpimadt_attach(struct device *parent, struct device *self, void *aux) memset(&caa, 0, sizeof(struct cpu_attach_args)); if (lapic_cpu_number() == entry->madt_lapic.apic_id) caa.cpu_role = CPU_ROLE_BP; - else + else { caa.cpu_role = CPU_ROLE_AP; + ncpusfound++; + } caa.caa_name = "cpu"; caa.cpu_number = entry->madt_lapic.apic_id; #ifdef MULTIPROCESSOR diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index b65ebbc9393..ba5887bdc6f 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.158 2009/03/05 19:52:24 kettenis Exp $ */ +/* $OpenBSD: init_main.c,v 1.159 2009/04/19 17:53:38 deraadt Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -125,6 +125,7 @@ struct vnode *rootvp, *swapdev_vp; int boothowto; struct timeval boottime; int ncpus = 1; +int ncpusfound = 1; /* number of cpus we find */ __volatile int start_init_exec; /* semaphore for start_init() */ #if !defined(NO_PROPOLICE) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index c9bbbf61653..322816d1090 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.168 2009/01/21 21:02:40 miod Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.169 2009/04/19 17:53:38 deraadt Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -564,6 +564,8 @@ hw_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, return (sysctl_rdstring(oldp, oldlenp, newp, cpu_model)); case HW_NCPU: return (sysctl_rdint(oldp, oldlenp, newp, ncpus)); + case HW_NCPUFOUND: + return (sysctl_rdint(oldp, oldlenp, newp, ncpusfound)); case HW_BYTEORDER: return (sysctl_rdint(oldp, oldlenp, newp, BYTE_ORDER)); case HW_PHYSMEM: diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 15570aa37ab..19524fe8de0 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.95 2009/01/21 21:02:41 miod Exp $ */ +/* $OpenBSD: sysctl.h,v 1.96 2009/04/19 17:53:39 deraadt Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -536,7 +536,7 @@ struct kinfo_proc2 { */ #define HW_MACHINE 1 /* string: machine class */ #define HW_MODEL 2 /* string: specific machine model */ -#define HW_NCPU 3 /* int: number of cpus */ +#define HW_NCPU 3 /* int: number of cpus being used */ #define HW_BYTEORDER 4 /* int: machine byte order */ #define HW_PHYSMEM 5 /* int: total memory */ #define HW_USERMEM 6 /* int: non-kernel memory */ @@ -554,7 +554,8 @@ struct kinfo_proc2 { #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_MAXID 21 /* number of valid hw ids */ +#define HW_NCPUFOUND 21 /* int: number of cpus found*/ +#define HW_MAXID 22 /* number of valid hw ids */ #define CTL_HW_NAMES { \ { 0, 0 }, \ @@ -578,6 +579,7 @@ struct kinfo_proc2 { { "uuid", CTLTYPE_STRING }, \ { "physmem", CTLTYPE_QUAD }, \ { "usermem", CTLTYPE_QUAD }, \ + { "ncpufound", CTLTYPE_INT }, \ } /* diff --git a/sys/sys/systm.h b/sys/sys/systm.h index e549e664515..672d9e16ba5 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systm.h,v 1.75 2008/11/06 19:12:37 deraadt Exp $ */ +/* $OpenBSD: systm.h,v 1.76 2009/04/19 17:53:39 deraadt Exp $ */ /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ /*- @@ -79,7 +79,8 @@ extern const char osversion[]; extern const char osrelease[]; extern int cold; /* cold start flag initialized in locore */ -extern int ncpus; /* number of CPUs */ +extern int ncpus; /* number of CPUs used */ +extern int ncpusfound; /* number of CPUs found */ extern int nblkdev; /* number of entries in bdevsw */ extern int nchrdev; /* number of entries in cdevsw */ -- cgit v1.2.3