Re: [PATCH] trace_branch: use per-cpu counters for correct/incorrect stats

From: Steven Rostedt

Date: Mon Jun 29 2026 - 06:47:05 EST


On Mon, 29 Jun 2026 16:58:38 +0700
Martin Weiss <martin.githubacc@xxxxxxxxx> wrote:

> Replace per-task counters with per-cpu increments to avoid race
> conditions in the branch profiler fast path.
>
> Fixes FIXME about atomicity.
>
> Signed-off-by: Martin Weiss <Martin.weiss2410@xxxxxxxxx>
> ---
> kernel/trace/trace_branch.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
> index d8e97ad798f0..960bcb3d7dbf 100644
> --- a/kernel/trace/trace_branch.c
> +++ b/kernel/trace/trace_branch.c
> @@ -213,11 +213,11 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
> */
> trace_likely_condition(f, val, expect);
>
> - /* FIXME: Make this atomic! */
> + /* use per-cpu counters to avoid contention */
> if (val == expect)
> - f->data.correct++;
> + this_cpu_inc(f->data.correct);
> else
> - f->data.incorrect++;
> + this_cpu_inc(f->data.incorrect);

I don't think this does what you think it does.

Did you even test this? I'm guessing it would blow up in some fantastic
ways.

NAK.

-- Steve


>
> user_access_restore(flags);
> }