From: Menglong Dong <menglong.dong@linux.dev>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
Linux trace kernel <linux-trace-kernel@vger.kernel.org>,
bpf <bpf@vger.kernel.org>, Masami Hiramatsu <mhiramat@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v5] tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast
Date: Mon, 12 Jan 2026 15:23:13 +0800 [thread overview]
Message-ID: <13926791.uLZWGnKmhe@7940hx> (raw)
In-Reply-To: <20260109160202.22975aa4@gandalf.local.home>
On 2026/1/10 05:02 Steven Rostedt <rostedt@goodmis.org> write:
> On Fri, 9 Jan 2026 15:21:19 -0500
> Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:
>
> > * preempt disable/enable pair: 1.1 ns
> > * srcu-fast lock/unlock: 1.5 ns
> >
> > CONFIG_RCU_REF_SCALE_TEST=y
> > * migrate disable/enable pair: 3.0 ns
> > * calls to migrate disable/enable pair within noinline functions: 17.0 ns
> >
> > CONFIG_RCU_REF_SCALE_TEST=m
> > * migrate disable/enable pair: 22.0 ns
>
> OUCH! So migrate disable/enable has a much larger overhead when executed in
> a module than in the kernel? This means all spin_locks() in modules
> converted to mutexes in PREEMPT_RT are taking this hit!
>
> It looks like it has to allow access to the rq->nr_pinned. There's a hack to
> expose this part of the rq struct for in-kernel by the following:
>
> kernel/sched/rq-offsets.c: DEFINE(RQ_nr_pinned, offsetof(struct rq, nr_pinned));
>
> Then for the in-kernel code we have:
>
> #define this_rq_raw() arch_raw_cpu_ptr(&runqueues)
> #else
> #define this_rq_raw() PERCPU_PTR(&runqueues)
> #endif
> #define this_rq_pinned() (*(unsigned int *)((void *)this_rq_raw() + RQ_nr_pinned))
>
> Looking at the scheduler code, the rq->nr_pinned is referenced by a static
> function with:
>
> static inline bool rq_has_pinned_tasks(struct rq *rq)
> {
> return rq->nr_pinned;
> }
>
> Which is only referenced in hotplug code and a balance_push() path in load
> balancing. Does this variable really need to be in the runqueue struct?
>
> Why not just make it a per-cpu variable. Maybe call it cpu_nr_pinned_tasks,
> and export that for all to use?
>
> It will not only fix the discrepancy between the overhead of
> migrate_disable/enable in modules vs in-kernel. But it also removes the
> hack to expose a portion of the runqueue.
I think it's a good idea to factor out the "nr_pinned" from struct rq.
The current approach that we inline the migrate_disable is a little
obscure. The initial propose of inline migrate_disable is to optimize the
performance of bpf trampoline, so the modules are not considered.
As you said, rq_has_pinned_tasks() is the only place that use the
nr_pinned, except the migrate_disable/migrate_enable. After more
analysis, I think maybe we can do it this way:
DEFINE_PER_CPU_SHARED_ALIGNED(int, cpu_nr_pinned_tasks);
And change rq_has_pinned_tasks() to:
static inline bool rq_has_pinned_tasks(struct rq *rq)
{
return *per_cpu_ptr(&cpu_nr_pinned_tasks, rq->cpu);
}
The "rq" in rq_has_pinned_tasks() may come from other CPU, so we
can't use "return this_cpu_read(cpu_nr_pinned_tasks)" directly.
Thanks!
Menglong Dong
>
> -- Steve
>
>
next prev parent reply other threads:[~2026-01-12 7:23 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 3:05 [PATCH v5] tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast Steven Rostedt
2026-01-09 14:40 ` Mathieu Desnoyers
2026-01-09 17:21 ` Steven Rostedt
2026-01-09 18:58 ` Mathieu Desnoyers
2026-01-13 13:56 ` Sebastian Andrzej Siewior
2026-01-09 19:10 ` Alexei Starovoitov
2026-01-09 19:19 ` Steven Rostedt
2026-01-09 20:21 ` Mathieu Desnoyers
2026-01-09 21:02 ` Steven Rostedt
2026-01-12 7:23 ` Menglong Dong [this message]
2026-01-12 15:31 ` Peter Zijlstra
2026-01-12 15:36 ` Steven Rostedt
2026-01-12 15:44 ` Peter Zijlstra
2026-01-09 21:54 ` Alexei Starovoitov
2026-01-09 22:00 ` Steven Rostedt
2026-01-09 22:18 ` Alexei Starovoitov
2026-01-09 22:31 ` Mathieu Desnoyers
2026-01-09 22:33 ` Steven Rostedt
2026-01-09 22:39 ` Steven Rostedt
2026-01-10 0:35 ` Alexei Starovoitov
2026-01-10 16:14 ` Steven Rostedt
2026-01-11 20:04 ` Alexei Starovoitov
2026-01-11 22:09 ` Steven Rostedt
2026-01-11 23:38 ` Alexei Starovoitov
2026-01-12 13:53 ` Steven Rostedt
2026-01-12 17:19 ` Alexei Starovoitov
2026-01-13 14:23 ` Sebastian Andrzej Siewior
2026-01-13 23:44 ` Alexei Starovoitov
2026-01-09 19:19 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13926791.uLZWGnKmhe@7940hx \
--to=menglong.dong@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox