clinuxoperating-systemkernel

Is there a function/Macro in Linux Kernel to get current preemption status on smp machine?


In my project I use get_cpu() and put_cpu() to disable and enable the preemption in the kernel on a smp machine.

Is there a safe way to get the current preemption status in an smp machine i.e. whether the preemption is turned on or off.


Solution

  • preempt_count() returns current thread's preemption count. 0 value means that preemtion is allowed.

    Usually, you shouldn't request preemtion status unless for the selfcheck. If some block of code requires preemtion to be disabled, it should be wrapped with preempt_disable()/preempt_enable() calls (or their alternatives).