Thread (2 messages) 2 messages, 2 authors, 13d ago

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

From: Steven Rostedt <rostedt@goodmis.org>
Date: 2026-06-29 10:46:54
Also in: lkml

On Mon, 29 Jun 2026 16:58:38 +0700
Martin Weiss [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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 <redacted>
---
 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);
 }
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help