Re: Mapping from preempted task to running task on same CPU
From: Peter Zijlstra
Date: Fri Oct 16 2026 - 03:29:48 EST
On Fri, Oct 16, 2026 at 10:14:27AM +0530, K Prateek Nayak wrote:
> > @@ -372,17 +381,24 @@ static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
> > raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
> > while (i) {
> > t = ts[--i];
> > - if (task_call_func(t, check_slow_task, &rscr))
> > + if (task_call_func(t, check_slow_task, &rscr)) {
> > pr_cont(" P%d", t->pid);
> > - else
> > - pr_cont(" P%d/%d:%c%c%c%c%c%c",
> > + } else {
> > + tc = rscr.rcu_rdr_cpu_task;
> > + pr_cont(" P%d/%d:%c%c%c%c%c%c CPU %d%s %s (%d)%s",
> > t->pid, rscr.nesting,
> > ".b"[rscr.rs.b.blocked],
> > ".q"[rscr.rs.b.need_qs],
> > ".e"[rscr.rs.b.exp_hint],
> > ".l"[rscr.on_blkd_list],
> > ".R"[rscr.rcu_rdr_running],
> > - ".B?"[rscr.rcu_rdr_boosted]);
> > + ".B?"[rscr.rcu_rdr_boosted],
> > + rscr.rcu_rdr_cpu,
> > + rscr.rcu_rdr_cpu_offline ? "!" : "",
> > + tc ? tc->comm : "???",
> > + tc ? tc->pid : -1,
> > + tc ? (is_idle_task(tc) ? " (idle!)" : "") : " (no task)");
> > + }
> > lockdep_assert_irqs_disabled();
>
> ... since you are IRQs disabled, it should be fine to use it here.
>
> If you don't want to take the overhead of rq_lock() + barrier,
> you can perhaps define a cpu_curr_snapshot_rcu() like:
>
> struct task_struct *cpu_curr_snapshot_rcu(int cpu)
> {
> return rcu_dereference_all(cpu_curr(cpu));
> }
>
> in kernel/sched/core.c and expose it similar to
> cpu_curr_snapshot().
>
> I'll let Peter comment if he hates it or not ;-)
I would much rather do this than expose rq_lock().