Re: [PATCH 00/15] tracepoint: Avoid double static_branch evaluation at guarded call sites
Mathieu Desnoyers <[email protected]> Thu, 12 Mar 2026 11:12:41 -0400
| Newsgroups | org.kernel.vger.linux-sctp,org.freedesktop.lists.amd-gfx,org.freedesktop.lists.dri-devel,org.kernel.vger.bpf,org.kernel.vger.io-uring,org.kernel.vger.linux-btrfs,org.kernel.vger.linux-i2c,org.kernel.vger.linux-input,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pm,org.kernel.vger.linux-scsi,org.kernel.vger.linux-spi,org.kernel.vger.linux-trace-kernel,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
On 2026-03-12 11:04, Vineeth Pillai (Google) wrote:
> When a caller already guards a tracepoint with an explicit enabled check:
>
> if (trace_foo_enabled() && cond)
> trace_foo(args);
>
> trace_foo() internally re-evaluates the static_branch_unlikely() key.
> Since static branches are patched binary instructions the compiler cannot
> fold the two evaluations, so every such site pays the cost twice.
>
> This series introduces trace_invoke_##name() as a companion to
> trace_##name(). It calls __do_trace_##name() directly, bypassing the
> redundant static-branch re-check, while preserving all other correctness
> properties of the normal path (RCU-watching assertion, might_fault() for
> syscall tracepoints). The internal __do_trace_##name() symbol is not
> leaked to call sites; trace_invoke_##name() is the only new public API.
>
> if (trace_foo_enabled() && cond)
> trace_invoke_foo(args); /* calls __do_trace_foo() directly */
FYI, we have a similar concept in LTTng-UST for userspace
instrumentation already:
if (lttng_ust_tracepoint_enabled(provider, name))
lttng_ust_do_tracepoint(provider, name, ...);
Perhaps it can provide some ideas about API naming.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com