From owner-freebsd-smp Fri Oct 5 1:23:50 2001 Delivered-To: freebsd-smp@freebsd.org Received: from nasu.utsunomiya-u.ac.jp (nasu.utsunomiya-u.ac.jp [160.12.128.3]) by hub.freebsd.org (Postfix) with ESMTP id 11FDB37B406 for ; Fri, 5 Oct 2001 01:23:34 -0700 (PDT) Received: from nantai.utsunomiya-u.ac.jp by nasu.utsunomiya-u.ac.jp (8.11.2/1.1.29.3/26Jan01-1134AM) id f958NC575670; Fri, 5 Oct 2001 17:23:12 +0900 (JST) Received: from zodiac.mech.utsunomiya-u.ac.jp by nantai.utsunomiya-u.ac.jp (8.11.2/1.1.29.3/30Jan01-0241PM) id f958NBE40080; Fri, 5 Oct 2001 17:23:11 +0900 (JST) Received: from zodiac.mech.utsunomiya-u.ac.jp (IDENT:Ladmw4xZdVojmnOc4k04PojxyQAjwRxJ@zodiac.mech.utsunomiya-u.ac.jp [160.12.43.7]) by zodiac.mech.utsunomiya-u.ac.jp (8.9.3+3.2W/3.7W/zodiac-May2000) with ESMTP id RAA28872; Fri, 5 Oct 2001 17:33:00 +0900 (JST) Message-Id: <200110050833.RAA28872@zodiac.mech.utsunomiya-u.ac.jp> To: Alfred Perlstein Cc: smp@freebsd.org, yokota@zodiac.mech.utsunomiya-u.ac.jp Subject: Re: How to distinguish the SMP kernel and the UP kernel In-reply-to: Your message of "Thu, 04 Oct 2001 13:00:51 EST." <20011004130051.B59854@elvis.mu.org> References: <200110030310.MAA13836@zodiac.mech.utsunomiya-u.ac.jp> <3BBB6757.9A668E99@mindspring.com> <200110041211.VAA24646@zodiac.mech.utsunomiya-u.ac.jp> <20011004130051.B59854@elvis.mu.org> Date: Fri, 05 Oct 2001 17:32:59 +0900 From: Kazutaka YOKOTA Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >> >Kazutaka YOKOTA wrote: >> >> >> >> Is there any way for the loadable module to detect if >> >> the kernel is configured for SMP or UP? >> > >> >There is a global variable, "ncpu". Its name may have changed >> >recently, so you will want to look at the SYSCTL() stuff in >> >/sys/i386/i386 to be sure. >> > >> >-- Terry >> >> The sysctl variable hw.ncpu returns 1 in the UP kernel, >> and returns the number of active CPUs in the SMP kernel. >> >> When hw.ncpu == 1, it doesn't necessarily signifies the kernel >> is configured for UP. Because it is perfectly permissible >> to run the SMP kernel on the multi-CPU motherboard with only one >> CPU installed... >> >> Am I wrong? > >I'm quite sure you're right. It would probably make sense >to have a sysctl that says weather or not MP is configured or >not. - The following patch will add a new sysctl variable. kern.smp.kernel This will be 0 for the UP kernel and 1 for the SMP kernel. - It also make kern.smp.active available in the UP kernel as well. (Previously this sysctl variable was only present in the SMP kernel.) It will always be 0 for the UP kernel. - The patch will also add a new kernel global variable. It corresponds to the sysctl variable kern.smp.kernel. int smp_kernel It will be 0 for the UP kernel and 1 for the SMP kernel. - The kernel global variable smp_active is also made available in the UP kernel too. It is always 0 in the UP kernel. So, the userland program can check for the SMP kernel by reading the sysctl variable kern.smp.kernel and kern.smp.active. The kernel and loadable modules can use the global variables smp_kernel and smp_active to see if it is in the SMP configuration. Kazu Index: /sys/kern/subr_smp.c =================================================================== RCS file: /src/CVS/src/sys/kern/subr_smp.c,v retrieving revision 1.158 diff -u -r1.158 subr_smp.c --- /sys/kern/subr_smp.c 12 Sep 2001 08:37:45 -0000 1.158 +++ /sys/kern/subr_smp.c 5 Oct 2001 02:25:26 -0000 @@ -45,6 +45,18 @@ #include #include +SYSCTL_NODE(_kern, OID_AUTO, smp, CTLFLAG_RD, NULL, "Kernel SMP"); + +#ifndef SMP + +int smp_kernel = 0; /* we are not configured for SMP */ +SYSCTL_INT(_kern_smp, OID_AUTO, kernel, CTLFLAG_RW, &smp_kernel, 0, ""); + +int smp_active = 0; /* alwasy zero */ +SYSCTL_INT(_kern_smp, OID_AUTO, active, CTLFLAG_RW, &smp_active, 0, ""); + +#else /* SMP */ + volatile u_int stopped_cpus; volatile u_int started_cpus; @@ -54,7 +66,8 @@ volatile int smp_started; u_int all_cpus; -SYSCTL_NODE(_kern, OID_AUTO, smp, CTLFLAG_RD, NULL, "Kernel SMP"); +int smp_kernel = 1; /* we are configured for SMP */ +SYSCTL_INT(_kern_smp, OID_AUTO, kernel, CTLFLAG_RW, &smp_kernel, 0, ""); int smp_active = 0; /* are the APs allowed to run? */ SYSCTL_INT(_kern_smp, OID_AUTO, active, CTLFLAG_RW, &smp_active, 0, ""); @@ -304,3 +317,5 @@ /* release lock */ mtx_unlock_spin(&smp_rv_mtx); } + +#endif /* SMP */ Index: /sys/sys/smp.h =================================================================== RCS file: /src/CVS/src/sys/sys/smp.h,v retrieving revision 1.68 diff -u -r1.68 smp.h --- /sys/sys/smp.h 12 Sep 2001 08:38:05 -0000 1.68 +++ /sys/sys/smp.h 5 Oct 2001 02:23:01 -0000 @@ -20,6 +20,7 @@ #ifdef SMP extern void (*cpustop_restartfunc)(void); extern int mp_ncpus; +extern int smp_kernel; extern int smp_active; extern int smp_started; extern int smp_cpus; @@ -62,6 +63,8 @@ void (*)(void *), void *arg); #else /* SMP */ +extern int smp_kernel; +extern int smp_active; #define CPU_ABSENT(x_cpu) (0) #endif /* SMP */ #endif /* !LOCORE */ Index: /sys/conf/files =================================================================== RCS file: /src/CVS/src/sys/conf/files,v retrieving revision 1.564 diff -u -r1.564 files --- /sys/conf/files 7 Sep 2001 02:54:54 -0000 1.564 +++ /sys/conf/files 5 Oct 2001 02:23:42 -0000 @@ -817,7 +817,7 @@ kern/subr_rman.c standard kern/subr_sbuf.c standard kern/subr_scanf.c standard -kern/subr_smp.c optional smp +kern/subr_smp.c standard kern/subr_taskqueue.c standard kern/subr_trap.c standard kern/subr_witness.c optional witness To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message