Re: [PATCH 00/15] tracepoint: Avoid double static_branch evaluation at guarded call sites

From: Mathieu Desnoyers

Date: Thu Mar 12 2026 - 11:20:50 EST


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