LAZY_PREEMPT

在5.15的RT补丁集中,不支持在RISC-V平台启用LAZY_PREEMPT配置,但它是RT-Linux中的一个重要特性。此补丁提高了非RT工作负载性能,因此有必要去支持它。尽管RT-Linux不支持RISC-V架构,但是我们可以使用其他的架构补丁(ARM/x86)来实现。

附录A中列出了RISC-V LAZY_PREEPMT的实现方法。该补丁已通过OpenPLC测试验证。 通过测试结果改进了延迟和抖动。

获取LAZY_PREEMPT的更多细节,请查看下面LAZY_PREEMPT补丁的commit信息:

It has become an obsession to mitigate the determinism vs. throughput loss of RT.Looking at the mainline semantics of preemption points gives a hint why RT sucks throughput wise for ordinary SCHED_OTHER tasks.One major issue is the wakeup of tasks which are right away preempting the waking task while the waking task holds a lock on which the woken task will block right after having preempted the wakee.In mainline this is prevented due to the implicit preemption disable of spin/rw_lock held regions.On RT this is not possible due to the fully preemptible nature of sleeping spinlocks.

Though for a SCHED_OTHER task preempting another SCHED_OTHER task this is really not a correctness issue.RT folks are concerned about SCHED_FIFO/RR tasks preemption and not about the purely fairness driven SCHED_OTHER preemption latencies.

So I introduced a lazy preemption mechanism which only applies to SCHED_OTHER tasks preempting another SCHED_OTHER task.Aside of the existing preempt_count each tasks sports now a preempt_lazy_count which is manipulated on lock acquiry and release.This is slightly incorrect as for lazyness reasons I coupled this on migrate_disable/enable so some other mechanisms get the same treatment (e.g. get_cpu_light).

Now on the scheduler side instead of setting NEED_RESCHED this sets NEED_RESCHED_LAZY in case of a SCHED_OTHER/SCHED_OTHER preemption and therefor allows to exit the waking task the lock held region before the woken task preempts.That also works better for cross CPU wakeups as the other side can stay in the adaptive spinning loop.

For RT class preemption there is no change.This simply sets NEED_RESCHED and forgoes the lazy preemption counter.