开发者

Do spin_lock and spin_unlock hurt performance of an SMP kernel on a single-cpu machine?

开发者 https://www.devze.com 2022-12-10 06:30 出处:网络
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 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 sp开发者_运维百科ecific code?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号