Re: [PATCH] sched: Make preempt_enable_no_resched() behave like preempt_enable() on PREEMPT_RT

From: Peter Zijlstra
Date: Tue Mar 01 2022 - 15:15:40 EST


On Tue, Mar 01, 2022 at 07:30:32PM +0100, Sebastian Andrzej Siewior wrote:
> From: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>
> Use the distinction that has been made earlier between
> preempt_enable_no_resched() and sched_preempt_enable_no_resched().
> sched_preempt_enable_no_resched() is used within the scheduler where an
> immediate schedule() follows. preempt_enable_no_resched() is used
> outside of the scheduler and an immediate schedule() invocation may not
> follow for other reasons.
>
> The lack of an immediate schedule() invocation matters on PREEMPT_RT
> where it will introduce latencies while the scheduler expects a context
> switch.
>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
> ---
> include/linux/preempt.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/preempt.h b/include/linux/preempt.h
> index b4381f255a5ca..582e43856a532 100644
> --- a/include/linux/preempt.h
> +++ b/include/linux/preempt.h
> @@ -210,7 +210,11 @@ do { \
> preempt_count_dec(); \
> } while (0)
>
> -#define preempt_enable_no_resched() sched_preempt_enable_no_resched()
> +#ifdef CONFIG_PREEMPT_RT
> +# define preempt_enable_no_resched() preempt_enable()
> +#else
> +# define preempt_enable_no_resched() sched_preempt_enable_no_resched()
> +#endif

Ignoring !x86 for a moment:

arch/x86/mm/kmmio.c: preempt_enable_no_resched();
arch/x86/mm/kmmio.c: preempt_enable_no_resched();
include/linux/preempt.h:#define sched_preempt_enable_no_resched() \
include/linux/preempt.h:#define preempt_enable_no_resched() sched_preempt_enable_no_resched()
include/linux/preempt.h:#define preempt_enable_no_resched_notrace() \
include/linux/preempt.h:#define sched_preempt_enable_no_resched() barrier()
include/linux/preempt.h:#define preempt_enable_no_resched() barrier()
include/linux/preempt.h:#define preempt_enable_no_resched_notrace() barrier()
include/linux/preempt.h:#undef sched_preempt_enable_no_resched
include/linux/preempt.h:#undef preempt_enable_no_resched
include/linux/preempt.h:#undef preempt_enable_no_resched_notrace
kernel/sched/core.c: preempt_enable_no_resched();
kernel/sched/core.c: preempt_enable_no_resched();
kernel/sched/core.c: sched_preempt_enable_no_resched();
kernel/sched/core.c: sched_preempt_enable_no_resched();
kernel/sched/core.c: sched_preempt_enable_no_resched();
kernel/sched/core.c: preempt_enable_no_resched_notrace();
kernel/sched/core.c: preempt_enable_no_resched_notrace();
kernel/sched/core.c: sched_preempt_enable_no_resched();
kernel/sched/core.c: sched_preempt_enable_no_resched();
kernel/signal.c: preempt_enable_no_resched();
kernel/smpboot.c: preempt_enable_no_resched();
lib/smp_processor_id.c: preempt_enable_no_resched_notrace();


Surely we can audit that... At a glance the proposed patch does more
harm than good. Only the kmmio case looks obviousl fail, but then IIRC
kmmio had worse problems.