Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 05 Oct 2001 09:12:46 -0700 (PDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
Cc:        smp@freebsd.org, Alfred Perlstein <bright@mu.org>
Subject:   Re: How to distinguish the SMP kernel and the UP kernel
Message-ID:  <XFMail.011005091246.jhb@FreeBSD.org>
In-Reply-To: <200110050833.RAA28872@zodiac.mech.utsunomiya-u.ac.jp>

next in thread | previous in thread | raw e-mail | index | archive | help

On 05-Oct-01 Kazutaka YOKOTA wrote:
> 
>>> >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.

This shouldn't be done.  There's no need for 2 copies of the same sysctl. 
Actually, userland can _already_ tell if it is an SMP kernel or not by looking
if the kern.smp.active sysctl exists.  This is how top works, for example. 
Thus, userland doesn't need any of this.  Only in the kernel do you need this. 
Now, ideally kernel modules shouldn't care if they are on a SMP kernel or not. 
Why does the module in question care?  The only thing I would do here is
possibly export a global variable saying if SMP was compiled in, nothing more.

-- 

John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.011005091246.jhb>