dynamic smp aware modules (was: Re: Multiple kernel building/installing)
Matthew Dillon
dillon at apollo.backplane.com
Fri Feb 23 11:08:48 PST 2007
:I think we should change this. And actually it is quite easy. Replace
:
:#ifdef SMP
: code
:#endif
:
:with
: if (is_smp) {
: code
: }
:
:and have some header doing
:
:#ifndef _KERNEL_MODULE
:const static int is_smp =3D
:# ifdef SMP
: 1;
:# else
: 0;
:# endif
:#else
:extern const int is_smp;
:#endif
:
:and initialize is_smp appropriately in some kernel source.
:
:The kernel will be compiled optimized, because the compiler knows that is=
:_smp is a const value and thus can remove dead code. Modules will take t=
:he penalty of checking this variable, but that's hardly an impact, becaus=
:e it will be in the cache anyways. Just make sure that the variable is i=
:n its own cache line, which never changes.
:
:comments?
:
:cheers
: simon
This works to some degree. The only issue is that #ifdef'd SMP code
is not parsed at all if SMP is not defined, and so it may reference
variables and procedures that otherwise do not exist (and are undeclared)
for non-SMP kernels.
if (IS_SMP) { ... } code *IS* parsed by the compiler, so even
though the compiler may optimize it out you could still end up with
warnings and errors pertaining to variables that are not declared
for SMP builds.
My only other comment on the matter is that constant declarations
replacing #ifdef's should probably be all-caps. e.g. IS_SMP rather
then is_smp, to differentiate those variables from normal variables
and make the code more readable.
I use the const trick for the KTR logging code. It works quite well
given the caveats.
-Matt
More information about the Kernel
mailing list