Re: [PATCH v2] sched: set TIF_NEED_RESCHED before calling __trace_set_need_resched()

From: K Prateek Nayak

Date: Mon Jun 29 2026 - 00:11:34 EST


Hello Sechang,

On 6/27/2026 1:46 PM, Sechang Lim wrote:
> static inline void clear_tsk_need_resched(struct task_struct *tsk)
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index b8871449d3c6..b358fac315d0 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1172,6 +1172,7 @@ static void __resched_curr(struct rq *rq, int tif)
> struct task_struct *curr = rq->curr;
> struct thread_info *cti = task_thread_info(curr);
> int cpu;
> + bool need_ipi;

nit. This declaration can go before "int cpu;" to preserve the
reverse x-mas arrangement for the independent variables.

>
> lockdep_assert_rq_held(rq);
>
> @@ -1187,15 +1188,17 @@ static void __resched_curr(struct rq *rq, int tif)
>
> cpu = cpu_of(rq);
>
> - trace_sched_set_need_resched_tp(curr, cpu, tif);
> if (cpu == smp_processor_id()) {
> set_ti_thread_flag(cti, tif);
> if (tif == TIF_NEED_RESCHED)
> set_preempt_need_resched();
> + trace_sched_set_need_resched_tp(curr, cpu, tif);
> return;
> }
>
> - if (set_nr_and_not_polling(cti, tif)) {
> + need_ipi = set_nr_and_not_polling(cti, tif);
> + trace_sched_set_need_resched_tp(curr, cpu, tif);

Unrelated to changes here: This tracepoint seems to be missing from
wake_up_idle_cpu() which modifies the ti->flags without taking the
rq_lock.

A newly enqueued timer can race with the wakeup on idle CPU and you can
see a wakeup + sched_switch without seeing a corresponding
trace_sched_set_need_resched_tp() for the CPU.

Gabriele, is that a concern for RV?

> + if (need_ipi) {
> if (tif == TIF_NEED_RESCHED)
> smp_send_reschedule(cpu);
> } else {
> --
> 2.43.0
>

--
Thanks and Regards,
Prateek