Re: [PATCH v2 21/35] sched: prepare for lazy rescheduling in resched_curr()

Peter Zijlstra
2024-05-29T09:32:21Z

On Mon, May 27, 2024 at 05:35:07PM -0700, Ankur Arora wrote:

> @@ -1041,25 +1041,34 @@ void wake_up_q(struct wake_q_head *head)
> void resched_curr(struct rq *rq)
> {
> struct task_struct *curr = rq->curr;
> + resched_t rs = RESCHED_NOW;
> int cpu;
>
> lockdep_assert_rq_held(rq);
>
> - if (__test_tsk_need_resched(curr, RESCHED_NOW))
> + /*
> + * TIF_NEED_RESCHED is the higher priority bit, so if it is already
> + * set, nothing more to be done.
> + */
> + if (__test_tsk_need_resched(curr, RESCHED_NOW) ||
> + (rs == RESCHED_LAZY && __test_tsk_need_resched(curr, RESCHED_LAZY)))
> return;
>
> cpu = cpu_of(rq);
>
> if (cpu == smp_processor_id()) {
> - __set_tsk_need_resched(curr, RESCHED_NOW);
> - set_preempt_need_resched();
> + __set_tsk_need_resched(curr, rs);
> + if (rs == RESCHED_NOW)
> + set_preempt_need_resched();
> return;
> }
>
> - if (set_nr_and_not_polling(curr))
> - smp_send_reschedule(cpu);
> - else
> + if (set_nr_and_not_polling(curr, rs)) {
> + if (rs == RESCHED_NOW)
> + smp_send_reschedule(cpu);

I'm thinking this wants at least something like:

WARN_ON_ONCE(rs == RESCHED_LAZY && is_idle_task(curr));

> + } else {
> trace_sched_wake_idle_without_ipi(cpu);
> + }
> }
>
> void resched_cpu(int cpu)