Reputation: 7034
On my Ubuntu machine, default kernel image which is running is built for smp (CONFIG_SMP=y
). But this machine has only 1 cpu.
On uni-processor kernel, unlike smp kernel, spin_lock/unlock
are null functions.
So how does spin_lock()
and spin_unlock()
behave in this setup?
Is there any performance impact due to such smp specific code?
Upvotes: 8
Views: 1157
Reputation: 37188
Current Linux kernels contain a patch that you can google for with the terms "SMP alternatives". In short, during boot, if the kernel detects that it's running on a uniprocessor machines, the spinlock functions are hot-patched with no-ops.
Upvotes: 3
Reputation: 19445
Yes (And probably no).
Yes: A. The spin lock/unlock will run the actual code of the locking and unlocking because when you compile it the compiler doesn't know if you going to run it on a machine with one or more CPUs. B. Although you have one CPU you may still want to use it if you using threads.
Probably no: I'm guessing you asking because you don't use threads for the part you need to lock, and you only have one CPU. In that case the spin lock should never get into spin. So the performance overhead is negligible.
Upvotes: 0