linux/tools/perf
Ian Rogers b02027776a perf tests: Fix flakiness in BPF counters test on hybrid systems
The `perf stat --bpf-counters test` fails intermittently on hybrid
architectures or systems with dynamic frequency scaling (DVFS). This
happens because the test workload (`sqrtloop`) runs for a fixed 1-second
duration, and the CPU frequency can scale dynamically between idle and
maximum frequency. As the first run runs on a cold CPU and the second run
runs on a warmed-up CPU (or vice versa), the number of instructions
executed in 1 second differs by up to 2.2x, violating the comparison
tolerance.

Also, when running as root, BPF tracepoints and scheduling programs
trigger frequently. Since standard `perf stat -e instructions` measures
both user and kernel space instructions, it counts BPF helper and program
execution overheads, whereas the BPF counters themselves do not self-
measure. This introduces a large kernel-space instruction count
discrepancy between standard and BPF counters.

Fix these issues by:
1. Switching the workload to a strictly deterministic, iteration-based
   workload: `awk 'BEGIN { for (i=0; i<10000000; i++) sum+=i }'`. We pin
the
   workload to a single random allowed CPU using `taskset -c $CPU` via a
bash array.
2. Restricting the counted event to user-space only (`instructions:u` or
`/u`).
3. Tightening the comparison tolerance from 20% to 15%.

These modifications isolate the measurements to user-space instructions of
the deterministic loop, which executes a virtually identical number of
instructions on both runs (with less than 0.001% variation), eliminating
Dynamic Frequency Scaling (DVFS), kernel scheduling noise, and BPF helper
self-measurement overheads.

Fixes: 2c0cb9f560 ("perf test: Add a shell test for 'perf stat --bpf-counters' new option")
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-06-30 17:09:14 -07:00
..
arch perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
bench perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
check-header_ignore_hunks/lib perf tools: update expected diff for lib/list_sort.c 2024-11-05 17:12:33 -08:00
dlfilters perf tools: Simplify evsel__add_modifier() 2024-10-22 09:52:11 -07:00
Documentation perf tools: Document recent additions to the perf.data file header 2026-06-15 16:54:39 -03:00
include/perf perf dso: Move build_id to dso_id 2025-07-25 10:37:56 -07:00
jvmti perf tools: Use calloc() where applicable 2026-04-08 19:21:05 -07:00
pmu-events perf vendor events intel: Update tigerlake events from 1.18 to 1.19 2026-06-30 10:24:21 -07:00
python perf python: Add LiveSession helper 2026-06-30 10:17:19 -07:00
scripts perf scripts: Add configurable sorting option to powerpc-hcalls 2026-06-30 10:24:21 -07:00
tests perf tests: Fix flakiness in BPF counters test on hybrid systems 2026-06-30 17:09:14 -07:00
trace perf tools changes for v7.2: 2026-06-23 11:34:49 -07:00
ui perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
util perf parse-events: Restrict core PMU bypass to --cputype option 2026-06-30 17:09:13 -07:00
.clang-format perf clang-format: Add a perf clang-format that overrides some kernel behaviors 2026-05-20 15:37:50 -03:00
.gitignore perf pmu-events: Split big_c_string storage into standalone compilation unit 2026-05-20 17:46:45 -03:00
bpf_skel.mak perf build: Compile BPF skeletons with -mcpu=v3 2026-06-04 10:58:32 -03:00
Build perf trace beauty: Make beauty generated C code standalone .o files 2026-05-20 17:46:45 -03:00
builtin-annotate.c perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
builtin-bench.c perf bench: Constify tables 2026-04-08 19:21:05 -07:00
builtin-buildid-cache.c perf symbol: Fix ENOENT case for filename__read_build_id 2025-12-17 07:30:51 -08:00
builtin-buildid-list.c perf build-id: Fix off-by-one bug when printing kernel/module build-id 2026-05-20 15:50:32 -03:00
builtin-c2c.c perf c2c: Fix hist entry and format list leaks in c2c_he_free() 2026-06-17 09:21:03 -03:00
builtin-check.c perf data ctf: replace libbabeltrace with babeltrace2-ctf-writer 2026-06-04 17:34:52 -03:00
builtin-config.c perf tools: Make more global variables static 2026-04-08 19:21:04 -07:00
builtin-daemon.c perf tools: Replace basename() calls with perf_basename() 2026-04-08 19:21:05 -07:00
builtin-data.c perf data ctf: replace libbabeltrace with babeltrace2-ctf-writer 2026-06-04 17:34:52 -03:00
builtin-diff.c perf tools: Guard test_bit from out-of-bounds sample CPU 2026-06-04 17:34:52 -03:00
builtin-evlist.c perf tool: Add the perf_tool argument to all callbacks 2025-11-07 13:25:05 -08:00
builtin-ftrace.c perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
builtin-help.c perf help: Move common_cmds into builtin-help 2026-01-14 17:22:50 -03:00
builtin-inject.c perf python: Use evsel in sample in pyrf_event 2026-06-30 10:17:12 -07:00
builtin-kallsyms.c perf machine: Explicitly pass in host perf_env 2025-07-25 10:37:57 -07:00
builtin-kmem.c perf tools: Include file offset and event type name in skip messages 2026-06-03 16:31:03 -03:00
builtin-kvm.c perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
builtin-kwork.c perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
builtin-list.c Merge remote-tracking branch 'torvalds/master' into perf-tools-next 2026-01-26 17:03:53 -03:00
builtin-lock.c perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
builtin-mem.c perf tool: Remove evsel from tool APIs that pass the sample 2026-05-20 16:34:23 -03:00
builtin-probe.c perf tools: Add layout support for --symfs option 2026-03-10 23:13:30 -07:00
builtin-record.c perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
builtin-report.c perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
builtin-sched.c tools/perf/sched: Update process names of processes in zombie state for both -s and -S options 2026-06-30 10:24:20 -07:00
builtin-script.c perf parse-events: Restrict core PMU bypass to --cputype option 2026-06-30 17:09:13 -07:00
builtin-stat.c perf parse-events: Restrict core PMU bypass to --cputype option 2026-06-30 17:09:13 -07:00
builtin-timechart.c perf timechart: Fix memory leaks in draw_wakeups() 2026-06-30 17:04:51 -07:00
builtin-top.c perf evlist: Add reference count checking 2026-06-30 10:17:11 -07:00
builtin-trace.c perf python: Use evsel in sample in pyrf_event 2026-06-30 10:17:12 -07:00
builtin-version.c perf check: Share the feature status printing routine with 'perf version' 2025-04-10 10:44:04 -03:00
builtin.h perf check: Allow showing a tip for opt-in features not built into perf 2025-04-10 10:44:42 -03:00
check-headers.sh perf beauty: Move copy of fadvise.h from tools/include/ to tools/perf/trace/beauty/include/ 2026-03-31 20:23:06 -07:00
CREDITS
design.txt
Makefile perf build: Add make check-headers target 2026-05-14 14:48:32 -07:00
Makefile.config perf s390: Fix TEXTREL in Python extension by compiling as PIC 2026-06-10 17:03:53 -03:00
Makefile.perf perf python: Add perf.pyi stubs file 2026-06-30 10:17:18 -07:00
MANIFEST perf tools: Fix arm64 source package build 2025-05-13 17:26:35 -03:00
perf-archive.sh tools/perf: Add --exclude-buildids option to perf archive command 2025-06-26 15:40:19 -07:00
perf-completion.sh
perf-iostat.sh
perf-read-vdso.c
perf-sys.h
perf.c perf tool: Constify the command and option arrays 2026-03-13 14:26:27 -07:00
perf.h perf: Completely remove possibility to override MAX_NR_CPUS 2025-09-12 10:52:22 -03:00