In Linux, PREEMPT is a mode that defines preemption, or the ability of a process to interrupt an already running one. Inside of the kernel you have a bunch of cond_resched()
which tell the system where preemption can happen (even on PREEMPT_NONE). yes this is a kinda hack as there is some places that needs it that doesn't have it and also some that really shouldn't have it...
Preemption will be driven by a flag (TIF_NEED_RESCHED
) which declares that a given task needs to "get of the damn thread" (; When the flag is used the task won't be ejected right away, but will wait until the next viable moment (like the exit of interrupts) in order to switch the task with the next.[4]
(PREEMPT_NONE)
The traditional model, with no preemption at all. The kernel must give up the CPU, via a return to user space, a blocking operation, or a cond_resched()
call, before another task can run.[5]
(PREEMPT_VOLUNTARY)
might_sleep()
and might_resched()
now = cond_resched()
The only part of the kernel who will allow PREEMPT are them that voluntarily give it up.[5]
(PREEMPT_LAZY)
Lazy add a new flag TIF_NEED_RESCHED_LAZY
which is a weak version of TIF_NEED_RESCHED
. Behavior will be the same as PREEMPT_VOLUNTARY needing TIF_NEED_RESCHED
in order to preempt, but some feature of PREEMPT_FULL will apply when either is used. One example of this would be the return to user space from the kernel[6]
(PREEMPT) or (PREEMPT_FULL)
The kernel can be preempted at any point where some factor (such as holding a spinlock or explicitly disabling preemption) does not explicitly prevent it.[5]
(PREEMPT_RT)
Everything becomes preemptable.
The goal of Realtime linux is reliability in the latency of kernel commands, in other words, is running a set a linux command take 150ms the first time it is executed, it should take the exact same time the second time around.
With traditional scheduler and kernel, other process running on your system will change the latency of your commands. Unless overloaded, RT-linux will always be consistent.
added Reatime
after 20 Years of work.
Initial support for ARM64, RISC-V, and x86 / x86_64[1]
golden commit: social.kernel.org [2]
added Lazy[3]
The end goal of this work is to have a scheduler with only two non-realtime modes: PREEMPT_LAZY and PREEMPT_FULL. The lazy mode will occupy a place between PREEMPT_NONE and PREEMPT_VOLUNTARY, replacing both of them. It will, however, not need the voluntary preemption points that were added for the two modes it replaces. Since preemption can now happen almost anywhere, there is no longer a need to enable it in specific spots.[6]
ALSO The Loongarch architecture has gained support for realtime preemption and lazy preemption.[7]