[PATCH 3/3] perf ftrace: Use atomic inc to update histogram in BPF

From: Namhyung Kim
Date: Thu Feb 27 2025 - 14:16:21 EST


It should use an atomic instruction to update even if the histogram is
keyed by delta as it's also used for stats.

Cc: Gabriele Monaco <gmonaco@xxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/bpf_skel/func_latency.bpf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/bpf_skel/func_latency.bpf.c b/tools/perf/util/bpf_skel/func_latency.bpf.c
index ad70547446786c54..e731a79a753a4d2d 100644
--- a/tools/perf/util/bpf_skel/func_latency.bpf.c
+++ b/tools/perf/util/bpf_skel/func_latency.bpf.c
@@ -142,7 +142,7 @@ int BPF_PROG(func_end)
if (!hist)
return 0;

- *hist += 1;
+ __sync_fetch_and_add(hist, 1);

__sync_fetch_and_add(&total, delta); // always in nsec
__sync_fetch_and_add(&count, 1);
--
2.48.1.711.g2feabab25a-goog