Re: [RFC PATCH v15 7/7] sched: Start blocked_on chain processing in find_proxy_task()

Peter Zijlstra
2025-03-17T16:47:35Z

On Wed, Mar 12, 2025 at 03:11:37PM -0700, John Stultz wrote:
> @@ -6791,6 +6890,7 @@ static void __sched notrace __schedule(int sched_mode)
> struct rq_flags rf;
> struct rq *rq;
> int cpu;
> + bool preserve_need_resched = false;
>
> cpu = smp_processor_id();
> rq = cpu_rq(cpu);
> @@ -6858,9 +6958,12 @@ static void __sched notrace __schedule(int sched_mode)
> next = find_proxy_task(rq, next, &rf);
> if (!next)
> goto pick_again;
> + if (next == rq->idle)
> + preserve_need_resched = true;
> }
> picked:
> - clear_tsk_need_resched(prev);
> + if (!preserve_need_resched)
> + clear_tsk_need_resched(prev);
> clear_preempt_need_resched();
> #ifdef CONFIG_SCHED_DEBUG
> rq->last_seen_need_resched_ns = 0;

I would really rather this was done like so:

--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6957,12 +6944,12 @@ static void __sched notrace __schedule(i
if (!next)
goto pick_again;
if (next == rq->idle)
- preserve_need_resched = true;
+ goto keep_resched;
}
picked:
- if (!preserve_need_resched)
- clear_tsk_need_resched(prev);
+ clear_tsk_need_resched(prev);
clear_preempt_need_resched();
+keep_resched:
#ifdef CONFIG_SCHED_DEBUG
rq->last_seen_need_resched_ns = 0;
#endif