perf coverage: A harness for perf, and the fixes it found
Arnaldo Carvalho de Melo
maintainerv4 cover perf coverage: A harness for perf, and the fixes it found
From: Arnaldo Carvalho de Melo <[email protected]>
Hi,
Nothing measured how much of perf the test suite reaches. Patch 1 adds tools/perf/scripts/coverage.sh: it builds perf with clang source based coverage, runs the complete perf test suite and reports line and function coverage for the whole tree, optionally against a baseline, with --table and --html like pahole's coverage_table.py. Also as 'make -C tools/perf coverage', 'coverage-prep' and 'coverage-table'.
The useful output is the list of files with the most uncovered lines, computed over the whole tree and not only the files the tests already
touch: that is where new tests should try to get more coverage.
The rest is what the first runs found, in the code, the build and the tests:
- The data type resolver missed 32-bit absolute addressing (patch 2) and clang DWARF 5 DW_OP_addrx globals (patch 3); a struct pointer kept in a register at -O2 had no test (patch 6).
- The flexible array member had no test; one showed the struct row at
0.00% while the member said 100.00% (patches 4-5).
- --insn-stat was printed before the loop that accounts the samples, so --code-with-type showed zeros (patch 7).
- The libbfd probe printed a missing bfd.h error five times per build-test run (patch 8).
- FEATURE-DUMP didn't record llvm-perf and rust, disabling both in the build-test builds (patch 9).
- The Intel PT virtual LBR check lost every aux sample with a single data page (patch 10).
- The dlfilter test kept samples whose IP the kernel now zeroes on a userspace-to-kernel skid (patch 11).
- The LBR inline unwinding check failed instead of reporting Skip when the AMD PMU rejects branch sampling (patch 12).
In a root run on this box (coverage-prep as the developer, the tests as root; the machine has no Intel PT, so the PT tests skip) the suite covered 51.12% of perf's 205,007 lines. The only failure is the POLL_HUP tracepoint regression, in code this series does not change.
The harness and the tests were developed with an AI coding assistant (OpenCode), which drafted the script and the tests and helped debug the failures; I reviewed every change and reproduced each failure before fixing it.
What changed from v3:
- Patch 1: a .profraw left half written used to make llvm-profdata drop the whole merge, and with it the run's measurement; the bad files are now skipped and counted (found running the harness on the arm64 boards).
- Patch 2: only set mem_ref for bare number operands when the offset is
non-zero, and guard find_data_type against reg1 == -1 (sashiko-bot).
- Patch 3: move DW_OP_addrx fallback to dwarf-aux.h so annotate-data.c builds with older elfutils, and fix typo in Fixes SHA (sashiko-bot).
- Patch 12: only "Invalid argument"/"not supported" skips (exit 2); stderr goes to a file, any other record failure prints it and fails.
- Ian Rogers' Reviewed-by on v3 is carried on patches 4-6, 8 and 10-11; patches 1 and 12 changed after that review and need a new look.
What changed from v2:
- Patch 2 is new: absolute addressing is resolved, so the new data type tests pass on 32-bit non-PIE builds and skip on 32-bit PIE.
- Patches 3, 4 and 6: the C programs became 'perf test -w' workloads (global_data, flex_array, regptr), the shell tests no longer compile anything (Ian Rogers).
- Patch 6: regptr uses long long members, so the offsets are the same
on ILP32 and LP64.
- Patch 5: add the missing annotated_member__extent() stub, so a build with slang but without libdw works (sashiko-bot); it is now a method of struct annotated_member.
What changed from v1:
- Patch 9 (cs-etm) is gone: Leo Yan's series replaces it.
- Patch 1: O= is accepted by all targets, the Python extension is in the report, -f is normalized and the delta matches its baseline.
- Patch 5: the TUI browser counts flexible array accesses too.
- Patch 7: the stats test skips without libdw.
- Patches 10 and 12: Fixes tags corrected.
Best regards,
- Arnaldo
Arnaldo Carvalho de Melo (12):
perf scripts: Add a coverage harness for perf
perf annotate: Handle absolute addressing in data type profiling perf annotate-data: Resolve DW_OP_addrx global variables perf tests: Exercise the flexible array member path
perf annotate-data: Count flexible array accesses for the whole struct perf tests: Exercise data type resolution from a register perf annotate: Print the stats after the annotations
perf tests: Silence the libbfd probe in build-test
perf build: Record the display-only features in FEATURE-DUMP perf tests: Fix the Intel PT virtual LBR check
perf test: Drop samples without an IP in the dlfilter test perf test: Skip the LBR inline unwinding check when unsupported
tools/perf/.gitignore | 1 + tools/perf/Makefile | 11 +- tools/perf/Makefile.config | 4 + tools/perf/Makefile.perf | 4 + tools/perf/builtin-annotate.c | 10 +- tools/perf/scripts/coverage.sh | 738 +++++++++++++++++++++++++ tools/perf/tests/builtin-test.c | 3 + tools/perf/tests/make | 2 +- tools/perf/tests/shell/addr2line_inlines.sh | 23 +- tools/perf/tests/shell/annotate_stats.sh | 64 +++ tools/perf/tests/shell/data_type_flex_array.sh | 108 ++++ tools/perf/tests/shell/data_type_global.sh | 70 +++ tools/perf/tests/shell/data_type_register.sh | 64 +++ tools/perf/tests/shell/script_dlfilter.sh | 2 +- tools/perf/tests/shell/test_intel_pt.sh | 9 +- tools/perf/tests/tests.h | 3 + tools/perf/tests/workloads/Build | 6 + tools/perf/tests/workloads/flex_array.c | 54 ++ tools/perf/tests/workloads/global_data.c | 55 ++ tools/perf/tests/workloads/regptr.c | 60 ++ tools/perf/ui/browsers/annotate-data.c | 7 +- tools/perf/util/annotate-arch/annotate-x86.c | 45 +- tools/perf/util/annotate-data.c | 28 +- tools/perf/util/annotate-data.h | 8 + tools/perf/util/annotate.c | 23 +- tools/perf/util/annotate.h | 6 + tools/perf/util/dwarf-aux.c | 37 +- tools/perf/util/dwarf-aux.h | 5 + 28 files changed, 1421 insertions(+), 29 deletions(-) create mode 100755 tools/perf/scripts/coverage.sh create mode 100755 tools/perf/tests/shell/annotate_stats.sh create mode 100755 tools/perf/tests/shell/data_type_flex_array.sh create mode 100755 tools/perf/tests/shell/data_type_global.sh create mode 100755 tools/perf/tests/shell/data_type_register.sh create mode 100644 tools/perf/tests/workloads/flex_array.c create mode 100644 tools/perf/tests/workloads/global_data.c create mode 100644 tools/perf/tests/workloads/regptr.c
base-commit: cc905a18a647a8e3ad42cd1596baa0e08fba26eb
v1-head: 3f5465bea8f5a97a
v2-head: 9706c488afffeb6d
v3-head: f2daf1586528671a
v4-head: b9e240a1b80ecd2a
Signature · 1 line
2.56.0
Arnaldo Carvalho de Melo
maintainerPATCH v4 1/12 perf scripts: Add a coverage harness for perf
From: Arnaldo Carvalho de Melo <[email protected]>
Build perf with clang source based coverage, run the complete perf test suite, merge the raw profiles and report line and function coverage for the whole tree, optionally against a baseline. This is pahole's coverage/coverage.sh + coverage-diff.sh merged into one script, wired as 'make -C tools/perf coverage' and listed in 'make help'.
Without -f the report lists the files with the most uncovered lines, which is where new tests should try to get more coverage; -t narrows the tests, -f focuses on specific files, --html writes a browsable report and --table/-T, also available as 'make -C tools/perf coverage-table', prints the last run as an ASCII table with the per-file line and function coverage, like pahole's coverage_table.py.
The build can be split from the test run: 'make -C tools/perf coverage-prep' builds the instrumented perf and records the build directory, and a later run as root, which needs no make, checks that build, runs the tests and renders the report, or prints the table with --table. This is for running the tests that need root on the bare metal host while the instrumented perf is built in the development container.
The report covers the whole tree, not only the paths the tests walk, so the per-file table is a map of what the suite does not reach in a given run. The uncovered line list and the failures the runs exposed are what drove the rest of this series.
$ make -C tools/perf coverage-prep O=~/coverage-build ... $ sudo scripts/coverage.sh ... Total: 104798 of 205007 lines covered (51.12%)
largest uncovered files (>= 100 lines)
file lines cover missed fn-cover
util/intel-pt.c 3237 0.00% 3237 0.00%
util/intel-pt-decoder/intel-pt-decoder.c 3208 0.00% 3208 0.00%
ui/browsers/hists.c 2730 0.00% 2730 0.00%
builtin-sched.c 3737 41.24% 2196 43.97%
builtin-script.c 3212 33.50% 2136 37.90%
util/auxtrace.c 2013 4.47% 1923 11.11%
util/session.c 2686 41.14% 1581 48.80%
... Report: /home/acme/coverage-build/cov/report.txt
The numbers above are from the split run: coverage-prep built the instrumented perf as the developer, the tests and the report ran as root. This machine has no Intel PT, so the PT tests skip and leave intel-pt.c and intel-pt-decoder.c at 0.0%; the TUI browser is in the list because the suite does not drive it.
169 tests passed, 27 skipped, one failure (20.2: Tracepoint event), in code this series does not change.
--- tools/perf/.gitignore | 1 + tools/perf/Makefile | 11 +- tools/perf/Makefile.perf | 4 + tools/perf/scripts/coverage.sh | 738 +++++++++++++++++++++++++++++++++ 4 files changed, 753 insertions(+), 1 deletion(-) create mode 100755 tools/perf/scripts/coverage.sh
tools/perf/.gitignore +1 -0
@@ -27,6 +27,7 @@ stats-*.csv cscope* config.mak config.mak.autogen +.coverage-build-dir *-bison.* *-flex.* *.pyc
tools/perf/Makefile +10 -1
@@ -140,6 +140,15 @@ check-headers: sync-headers: @./scripts/sync-headers.sh $(SYNC_HEADERS_ARGS) +coverage-prep: + @./scripts/coverage.sh --prep $(if $(FULL_O),--build-dir=$(FULL_O)) $(COVERAGE_ARGS) + +coverage: + @./scripts/coverage.sh $(if $(FULL_O),--build-dir=$(FULL_O)) $(COVERAGE_ARGS) + +coverage-table: + @./scripts/coverage.sh --table $(if $(FULL_O),--build-dir=$(FULL_O)) $(COVERAGE_ARGS) + # # All other targets get passed through: #
@@ -147,4 +156,4 @@ sync-headers: $(print_msg) $(make) -.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball check-headers sync-headers +.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball check-headers sync-headers coverage coverage-prep coverage-table
tools/perf/Makefile.perf +4 -0
@@ -873,6 +873,10 @@ help: @echo ' check-headers - check which header copies are out of sync with the kernel' @echo ' sync-headers - sync those header copies with the kernel, creating commits' @echo ' (SYNC_HEADERS_ARGS="..." passes options to the script)' + @echo ' coverage-prep - build perf with clang coverage, ready for a root test run' + @echo ' coverage - build perf with clang coverage, run the tests and report' + @echo ' coverage-table - print an ASCII table of the last coverage run' + @echo ' (COVERAGE_ARGS="..." passes options to the script)' DOC_TARGETS := doc man html info pdf
tools/perf/scripts/coverage.sh new file +738 -0
738 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 01/12] perf scripts: Add a coverage harness for perf
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Build perf with clang source based coverage, run the complete perf test suite, merge the raw profiles and report line and function coverage for the whole tree, optionally against a baseline. This is pahole's
coverage/coverage.sh+coverage-diff.shmerged into one script, wired as 'make -Ctools/perfcoverage' and listed in 'make help'.Without -f the report lists the files with the most uncovered lines, which is where new tests should try to get more coverage; -t narrows the tests, -f focuses on specific files, --html writes a browsable report and --table/-T, also available as 'make -C
tools/perfcoverage-table', prints the last run as an ASCII table with the per-file line and function coverage, like pahole'scoverage_table.py.
Quoted 6 lines
[ ... ]
169 tests passed, 27 skipped, one failure (20.2: Tracepoint event), in code this series does not change.
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Arnaldo Carvalho de Melo
maintainerPATCH v4 2/12 perf annotate: Handle absolute addressing in data type profiling
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
32-bit x86 accesses globals with absolute addresses, like "movl %eax,0x8c73448", but the operand parser only recognized the offset(reg) forms, so the operand had no memory reference, the resolver saw a zero data address and resolved nothing.
Parse a bare number as an absolute memory operand, leaving jumps and calls out, use the address in the resolver, and let the instruction tracking record the type of an absolute global load in the destination register. The displacement is sign extended for 64-bit objects, as the CPU does, and zero extended for 32-bit ones; a zero address is skipped by both users, since it is what an unrelocated operand looks like.
With bare numbers being memory operands, a frame base register of -1, "none", would also compare equal to the -1 "no register" of an absolute operand and take it for a stack access, so guard those comparisons.
--- tools/perf/util/annotate-arch/annotate-x86.c | 45 ++++++++++++++++++-- tools/perf/util/annotate.c | 23 +++++++++- tools/perf/util/annotate.h | 6 +++ 3 files changed, 69 insertions(+), 5 deletions(-)
tools/perf/util/annotate-arch/annotate-x86.c +41 -4
@@ -230,6 +230,11 @@ static bool vtable_get_rettype(Dwarf_Die *class_die, int offset,return die_get_real_type (&func_die, type_die) !=NULL ; } +static bool is_stack_or_fb_reg (struct type_state *state,int fbreg,int reg) +{ +return (fbreg !=-1 && reg == fbreg) || reg == state->stack_reg; +} +static void update_insn_state_x86 (struct type_state *state,struct data_loc_info *dloc,Dwarf_Die *cu_die,struct disasm_line *dl)
@@ -437,7 +442,7 @@ static void update_insn_state_x86(struct type_state *state,invalidate_reg_state (tsr);/* Case 1: Based on stack pointer or frame pointer */ -if (sreg == fbreg || sreg == state->stack_reg) { +if (is_stack_or_fb_reg (state, fbreg, sreg)) {struct type_state_stack *stack;int offset = src->offset - fboff;
@@ -626,7 +631,7 @@ static void update_insn_state_x86(struct type_state *state, retry:/* Check stack variables with offset */ -if (sreg == fbreg || sreg == state->stack_reg) { +if (is_stack_or_fb_reg (state, fbreg, sreg)) {struct type_state_stack *stack;int offset = src->offset - fboff;
@@ -741,6 +746,29 @@ static void update_insn_state_x86(struct type_state *state, insn_offset, addr, dst->reg1);pr_debug_type_name (&type_die, tsr->kind); } +/* Or an absolute address, as used by 32-bit code */ +else if (annotated_op_loc__is_abs (src)) { +struct map_symbol *ms = dloc->ms; +u64 ip = ms->sym->start + dl->al.offset; +u64 addr =annotated_op_loc__abs_addr (src,map__dso (ms->map)); +int offset; + +if (!get_global_var_type (cu_die, dloc, ip, addr, &offset, + &type_die) || + !die_get_member_type (&type_die, offset, &type_die)) { +invalidate_reg_state (tsr); +return ; + } + + tsr->type = type_die; + tsr->kind =TSR_KIND_TYPE ; + tsr->offset =0 ; + tsr->ok = true; + +pr_debug_dtp ("mov [%x] global addr=%#" PRIx64" -> reg%d" , + insn_offset, addr, dst->reg1); +pr_debug_type_name (&type_die, tsr->kind); + }/* And check percpu access with base register */ else if (has_reg_type (state, sreg) && state->regs[sreg].kind ==TSR_KIND_PERCPU_BASE ) {
@@ -827,7 +855,7 @@ static void update_insn_state_x86(struct type_state *state,/* Case 3. register to memory transfers */ if (!src->mem_ref && dst->mem_ref) {/* Check stack variables with offset */ -if (dst->reg1 == fbreg || dst->reg1 == state->stack_reg) { +if (is_stack_or_fb_reg (state, fbreg, dst->reg1)) {struct type_state_stack *stack;int offset = dst->offset - fboff;
@@ -931,7 +959,7 @@ static int extract_reg_offset(const struct arch *arch, const char *str, }static void extract_op_location_x86 (const struct arch *arch, -struct disasm_line *dl__maybe_unused , +struct disasm_line *dl,const char *op_str,int op_idx__maybe_unused ,struct annotated_op_loc *op_loc) {
@@ -960,6 +988,15 @@ static void extract_op_location_x86(const struct arch *arch, op_loc->offset =strtol (s +1 , &p,0 );if (p && p != s +1 ) op_loc->imm = true; + }else if (isdigit (*s) && !ins__is_jump (&dl->ins) && + !ins__is_call (&dl->ins)) { +u64 offset =strtoull (s,NULL ,0 ); + +if (offset !=0 ) { +/* Absolute address, as used by 32-bit code */ + op_loc->mem_ref = true; + op_loc->offset = offset; + } } } }
tools/perf/util/annotate.c +22 -1
@@ -2605,6 +2605,19 @@ int arch__dwarf_regnum(const struct arch *arch, const char *str)return reg <0 ?-1 : reg; } +bool annotated_op_loc__is_abs (const struct annotated_op_loc *op_loc) +{ +return op_loc->mem_ref && op_loc->reg1 ==-1 && op_loc->reg2 ==-1 && + op_loc->segment ==INSN_SEG_NONE && op_loc->offset !=0 ; +} + +/* The disp32 of a 64-bit object is sign extended, a 32-bit one is not */ +u64 annotated_op_loc__abs_addr (const struct annotated_op_loc *op_loc, +const struct dso *dso) +{ +return dso__is_64_bit (dso) ? (u64 )(s64 )op_loc->offset : (u32 )op_loc->offset; +} +/** * annotate_get_insn_location - Get location of instruction * @arch: the architecture info
@@ -2622,7 +2635,7 @@ int arch__dwarf_regnum(const struct arch *arch, const char *str)* mov (%rax), %rcx # src_reg1 = rax, src_mem = 1, src_offset = 0 * # dst_reg1 = rcx, dst_mem = 0 * -* mov 0x18, %r8 # src_reg1 = -1, src_mem = 0 +* mov 0x18, %r8 # src_reg1 = -1, src_mem = 1, src_offset = 0x18 * # dst_reg1 = r8, dst_mem = 0 * * mov %rsi, 8(%rbx,%rcx,4) # src_reg1 = rsi, src_mem = 0, src_multi_regs = 0
@@ -2894,6 +2907,11 @@ __hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch, dloc.var_addr =annotate_calc_pcrel (ms, dloc.ip, op_loc->offset, dl); } +/* Absolute addressing, as used by 32-bit code */ +else if (annotated_op_loc__is_abs (op_loc)) { + dloc.var_addr =annotated_op_loc__abs_addr (op_loc,map__dso (ms->map)); + op_loc->reg1 =DWARF_REG_PC ; + }/* This CPU access in kernel - pretend PC-relative addressing */ if (dso__kernel(map__dso(ms->map)) && arch__is_x86(arch) &&
@@ -2902,6 +2920,9 @@ __hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch, op_loc->reg1 =DWARF_REG_PC ; } +if (op_loc->reg1 ==-1 ) +continue ; + mem_type =find_data_type (&dloc);if (mem_type ==NULL &&is_stack_canary (arch, op_loc)) {
tools/perf/util/annotate.h +6 -0
@@ -18,6 +18,7 @@#include "branch.h" #include "evsel.h" +struct dso ;struct hist_browser_timer ;struct hist_entry ;struct map ;
@@ -638,6 +639,11 @@ struct annotated_insn_loc { i <INSN_OP_MAX ; \ i++, op_loc++) +/* Bare number operand, as used by 32-bit code to access globals */ +bool annotated_op_loc__is_abs (const struct annotated_op_loc *op_loc); +u64 annotated_op_loc__abs_addr (const struct annotated_op_loc *op_loc, +const struct dso *dso); +/* Get detailed location info in the instruction */ int annotate_get_insn_location (const struct arch *arch,struct disasm_line *dl,struct annotated_insn_loc *loc);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 02/12] perf annotate: Handle absolute addressing in data type profiling
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines
From: Arnaldo Carvalho de Melo <[email protected]>
32-bit x86 accesses globals with absolute addresses, like "movl %eax,0x8c73448", but the operand parser only recognized the offset(reg) forms, so the operand had no memory reference, the resolver saw a zero data address and resolved nothing.
Parse a bare number as an absolute memory operand, leaving jumps and calls out, use the address in the resolver, and let the instruction tracking record the type of an absolute global load in the destination register. The displacement is sign extended for 64-bit objects, as the CPU does, and zero extended for 32-bit ones; a zero address is skipped by both users, since it is what an unrelocated operand looks like.
Quoted 5 lines
With bare numbers being memory operands, a frame base register of -1, "none", would also compare equal to the -1 "no register" of an absolute operand and take it for a stack access, so guard those comparisons.
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Arnaldo Carvalho de Melo
maintainerPATCH v4 3/12 perf annotate-data: Resolve DW_OP_addrx global variables
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
clang emits DW_AT_location with DW_OP_addrx for global variables in DWARF 5, gcc emits DW_OP_addr. The address index was not resolved, so those variables were not found by address; the by-name fallback also missed the ones in .bss past the file backed end of the last segment.
Resolve the index with dwarf_getlocation_attr() + dwarf_formaddr() and use the resulting address in the by-address lookup and in the global variable cache. The new global_data workload keeps a zero initialized struct in .bss and its test checks that the accesses are annotated: when perf is built with clang and DWARF 5 it goes through DW_OP_addrx, with gcc through DW_OP_addr. The test skips on 32-bit PIE builds, which load globals through the GOT, something the resolver does not follow.
--- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/data_type_global.sh | 70 ++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 2 + tools/perf/tests/workloads/global_data.c | 55 +++++++++++++++++ tools/perf/util/annotate-data.c | 4 ++ tools/perf/util/dwarf-aux.c | 37 ++++++++++-- tools/perf/util/dwarf-aux.h | 5 ++ 8 files changed, 170 insertions(+), 5 deletions(-) create mode 100755 tools/perf/tests/shell/data_type_global.sh create mode 100644 tools/perf/tests/workloads/global_data.c
tools/perf/tests/builtin-test.c +1 -0
@@ -199,6 +199,7 @@ static struct test_workload *workloads[] = { &workload__deterministic, &workload__callchain, &workload__false_sharing, + &workload__global_data, #ifdef HAVE_RUST_SUPPORT &workload__code_with_type,
tools/perf/tests/shell/data_type_global.sh new file +70 -0
70 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -272,6 +272,7 @@ DECLARE_WORKLOAD(context_switch_loop);DECLARE_WORKLOAD (deterministic);DECLARE_WORKLOAD (callchain);DECLARE_WORKLOAD (false_sharing); +DECLARE_WORKLOAD (global_data);#ifdef HAVE_RUST_SUPPORT DECLARE_WORKLOAD (code_with_type);
tools/perf/tests/workloads/Build +2 -0
@@ -17,6 +17,7 @@ perf-test-y += context_switch_loop.o perf-test-y += deterministic.o perf-test-y += callchain.o perf-test-y += false_sharing.o +perf-test-y += global_data.o ifeq ($(CONFIG_RUST_SUPPORT),y) perf-test-y += code_with_type.o
@@ -35,3 +36,4 @@ CFLAGS_deterministic.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_named_threads.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_callchain.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_false_sharing.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_global_data.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE
tools/perf/tests/workloads/global_data.c new file +55 -0
55 lines not on this page · raw message
tools/perf/util/annotate-data.c +4 -0
@@ -140,6 +140,10 @@ static void pr_debug_location(Dwarf_Die *die, u64 pc, int reg)case DW_OP_addr:pr_info ("address=%#lx\n" , (long )ops->number);break ; +case DW_OP_addrx: +case DW_OP_GNU_addr_index: +pr_info ("address index=%#lx\n" , (long )ops->number); +break ;default :pr_info ("unknown: code=%#x, number=%#lx\n" , ops->atom, (long )ops->number);
tools/perf/util/dwarf-aux.c +32 -5
@@ -1629,6 +1629,31 @@ Dwarf_Die *die_find_variable_by_reg(Dwarf_Die *sc_die, Dwarf_Addr pc, int reg,return result; } +/* +* Get the absolute address of a location expression that consists of a +* single address, either DW_OP_addr or DW_OP_addrx. libdw leaves the +* DWARF 5 address index unresolved, it has to be looked up in .debug_addr. +*/ +static bool die_get_location_addr (Dwarf_Attribute *attr,Dwarf_Op *ops, +Dwarf_Addr *addr) +{ +if (ops->atom == DW_OP_addr) { + *addr = ops->number; +return true; + } + +if (ops->atom == DW_OP_addrx) { +Dwarf_Attribute addr_attr; + +if (dwarf_getlocation_attr (attr, ops, &addr_attr) !=0 ) +return false; + +return dwarf_formaddr (&addr_attr, addr) ==0 ; + } + +return false; +} +/* Only checks direct child DIEs in the given scope */ static int __die_find_var_addr_cb (Dwarf_Die *die_mem,void *arg) {
@@ -1647,11 +1672,13 @@ static int __die_find_var_addr_cb(Dwarf_Die *die_mem, void *arg)return DIE_FIND_CB_SIBLING ;while ((off =dwarf_getlocations (&attr, off, &base, &start, &end, &ops, &nops)) >0 ) { -if (ops->atom != DW_OP_addr) +Dwarf_Addr addr; + +if (!die_get_location_addr (&attr, ops, &addr))continue ;if (check_allowed_ops (ops, nops) && -match_var_offset (die_mem, data, data->addr, ops->number, +match_var_offset (die_mem, data, data->addr, addr,/*is_pointer=*/ false))return DIE_FIND_CB_END ; }
@@ -1777,7 +1804,7 @@ static int __die_collect_global_vars_cb(Dwarf_Die *die_mem, void *arg)Dwarf_Die type_die;int tag =dwarf_tag (die_mem);Dwarf_Attribute attr; -Dwarf_Addr base, start, end; +Dwarf_Addr base, start, end, addr;Dwarf_Op *ops;size_t nops;struct die_var_type *vt;
@@ -1792,7 +1819,7 @@ static int __die_collect_global_vars_cb(Dwarf_Die *die_mem, void *arg)if (dwarf_getlocations (&attr,0 , &base, &start, &end, &ops, &nops) <=0 )return DIE_FIND_CB_SIBLING ; -if (ops->atom != DW_OP_addr) +if (!die_get_location_addr (&attr, ops, &addr))return DIE_FIND_CB_SIBLING ;if (!check_allowed_ops (ops, nops))
@@ -1808,7 +1835,7 @@ static int __die_collect_global_vars_cb(Dwarf_Die *die_mem, void *arg) vt->die_off =dwarf_dieoffset (&type_die); vt->die_tag =dwarf_tag (&type_die); vt->from_alt = !die_same_file (die_mem, &type_die); - vt->addr = ops->number; + vt->addr = addr; vt->end =0 ; vt->has_range = false; vt->reg =-1 ;
tools/perf/util/dwarf-aux.h +5 -0
@@ -10,6 +10,11 @@#include <elfutils/libdwfl.h> #include <elfutils/version.h> +/* DWARF 5 address index, libdw's dwarf_getlocations() returns it unresolved */ +#ifndef DW_OP_addrx +#define DW_OP_addrx 0xa1 +#endif +static inline const char *die_name (Dwarf_Die *die) {return dwarf_diename (die) ?:"<unknown>" ;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 03/12] perf annotate-data: Resolve DW_OP_addrx global variables
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
From: Arnaldo Carvalho de Melo <[email protected]>
clang emits
DW_AT_locationwithDW_OP_addrxfor global variables in DWARF 5, gcc emitsDW_OP_addr. The address index was not resolved, so those variables were not found by address; the by-name fallback also missed the ones in .bss past the file backed end of the last segment.Resolve the index with
dwarf_getlocation_attr()+dwarf_formaddr()and use the resulting address in the by-address lookup and in the global variable cache. The newglobal_dataworkload keeps a zero initialized struct in .bss and its test checks that the accesses are annotated: when perf is built with clang and DWARF 5 it goes throughDW_OP_addrx, with gcc throughDW_OP_addr. The test skips on 32-bit PIE builds, which load globals through the GOT, something the resolver does not follow.
Quoted 4 lines
Fixes d60469d7c0e5c4e8 ("perf dwarf-aux: Add die_find_variable_by_addr()")Fixes d7b60803a790b716 ("perf dwarf-aux: Add die_collect_global_vars()")Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v4 03/12] perf annotate-data: Resolve DW_OP_addrx global variables
In reply to Arnaldo Carvalho de MeloQuoted 7 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
clang emits
DW_AT_locationwithDW_OP_addrxfor global variables in DWARF 5, gcc emitsDW_OP_addr. The address index was not resolved, so those variables were not found by address; the by-name fallback also missed the ones in .bss past the file backed end of the last segment.
Quoted 7 lines
Resolve the index with
dwarf_getlocation_attr()+dwarf_formaddr()and use the resulting address in the by-address lookup and in the global variable cache. The newglobal_dataworkload keeps a zero initialized struct in .bss and its test checks that the accesses are annotated: when perf is built with clang and DWARF 5 it goes throughDW_OP_addrx, with gcc throughDW_OP_addr. The test skips on 32-bit PIE builds, which load globals through the GOT, something the resolver does not follow.
[PATCH v4 2/4] perf dwarf-aux: Support DW_OP_addrx locations for global variables
By James fixes this, I'll leave this just as a shell test in v5.
- Arnaldo
Quoted 308 lines
Fixes d60469d7c0e5c4e8 ("perf dwarf-aux: Add die_find_variable_by_addr()")Fixes d7b60803a790b716 ("perf dwarf-aux: Add die_collect_global_vars()")Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/data_type_global.sh | 70 ++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 2 + tools/perf/tests/workloads/global_data.c | 55 +++++++++++++++++ tools/perf/util/annotate-data.c | 4 ++ tools/perf/util/dwarf-aux.c | 37 ++++++++++-- tools/perf/util/dwarf-aux.h | 5 ++ 8 files changed, 170 insertions(+), 5 deletions(-) create mode 100755 tools/perf/tests/shell/data_type_global.sh create mode 100644 tools/perf/tests/workloads/global_data.ctools/perf/tests/builtin-test.c +1
-0@@ -199,6 +199,7 @@ static struct test_workload *workloads[] = { &workload__deterministic, &workload__callchain, &workload__false_sharing, + &workload__global_data, #ifdef HAVE_RUST_SUPPORT &workload__code_with_type,tools/perf/tests/shell/data_type_global.sh new file +70
-0@@ -0,0 +1,70 @@ +#!/bin/bash +# perf data type profiling test for a global variable +# SPDX-License-Identifier: GPL-2.0 + +set -e + +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) +perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX) + +cleanup() +{ + rm -f "$perfdata" "$perfout" + trap - EXIT TERM INT +} + +trap_cleanup() +{ + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +if ! perf check feature -q dwarf; then + echo "Skip: no DWARF (libdw) support" + cleanup + exit 2 +fi + +# 32-bit PIE loads globals through the GOT, which the resolver does not follow +if [ "$(getconf LONG_BIT)" = 32 ] && + [ "$(od -An -tx1 -j16 -N2 "$(command -v perf)" | awk '{print $1}')" = 03 ]; then + echo "Skip: 32-bit PIE uses GOT-relative global accesses" + cleanup + exit 2 +fi + +# No point in recording if the PMU cannot do memory events. +if perf mem record -o /dev/null -- true 2>&1 | \ + grep -q "failed: no PMU supports the memory events"; then + cleanup + exit 2 +fi +if ! perf mem record -o /dev/null -- true 2>/dev/null; then + echo "Skip: cannot record memory events on this PMU" + cleanup + exit 2 +fi + +if ! perf mem record -o "$perfdata" -- perf test -w global_data 1 > /dev/null 2>&1; then + echo "FAIL: perf mem record" + cleanup + exit 1 +fi + +if ! perf annotate --code-with-type -i "$perfdata" --stdio \ + --percent-limit 1 > "$perfout" 2>/dev/null; then + echo "FAIL: perf annotate" + cleanup + exit 1 +fi + +if ! grep -q "# data-type: struct conn" "$perfout"; then + echo "FAIL: global variable in .bss not resolved" + cleanup + exit 1 +fi + +echo "global variable resolved" +cleanuptools/perf/tests/tests.h +1
-0@@ -272,6 +272,7 @@ DECLARE_WORKLOAD(context_switch_loop);DECLARE_WORKLOAD (deterministic);DECLARE_WORKLOAD (callchain);DECLARE_WORKLOAD (false_sharing); +DECLARE_WORKLOAD (global_data);#ifdef HAVE_RUST_SUPPORT DECLARE_WORKLOAD (code_with_type);tools/perf/tests/workloads/Build +2
-0@@ -17,6 +17,7 @@ perf-test-y += context_switch_loop.o perf-test-y += deterministic.o perf-test-y += callchain.o perf-test-y += false_sharing.o +perf-test-y += global_data.o ifeq ($(CONFIG_RUST_SUPPORT),y) perf-test-y += code_with_type.o@@ -35,3 +36,4 @@ CFLAGS_deterministic.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_named_threads.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_callchain.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_false_sharing.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_global_data.o = -g -O0 -fno-inline -U_FORTIFY_SOURCEtools/perf/tests/workloads/global_data.c new file +55
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* A zero initialized global struct, so it lands in .bss, past the file +* backed end of the last segment. clang describes its address with +* DW_OP_addrx in DWARF 5, gcc with DW_OP_addr. +* +* 'perf mem record' of this workload followed by 'perf annotate +* --code-with-type' (see tests/shell/data_type_global.sh) resolves the +* accesses to struct conn. +*/ +#include <signal.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/compiler.h> +#include "../tests.h" + +struct conn { +int saddr; +int daddr; +long bytes; +}; + +static volatile struct conn conn; +static volatile unsigned long conn_sink; +static volatile sig_atomic_t done; + +static void sighandler (int sig__maybe_unused ) +{ + done =1 ; +} + +static int global_data (int argc,const char **argv) +{ +unsigned long sum =0 ; +int i =0 ; +int sec =1 ; + +if (argc >0 ) + sec =atoi (argv[0 ]); + +signal (SIGINT , sighandler); +signal (SIGALRM , sighandler); +alarm (sec); + +while (!done) { + conn.saddr = i; + conn.daddr = i +1 ; + sum += conn.bytes; + i++; + } + conn_sink = sum; +return 0 ; +} + +DEFINE_WORKLOAD (global_data);tools/perf/util/annotate-data.c +4
-0@@ -140,6 +140,10 @@ static void pr_debug_location(Dwarf_Die *die, u64 pc, int reg)case DW_OP_addr:pr_info ("address=%#lx\n" , (long )ops->number);break ; +case DW_OP_addrx: +case DW_OP_GNU_addr_index: +pr_info ("address index=%#lx\n" , (long )ops->number); +break ;default :pr_info ("unknown: code=%#x, number=%#lx\n" , ops->atom, (long )ops->number);tools/perf/util/dwarf-aux.c +32
-5@@ -1629,6 +1629,31 @@ Dwarf_Die *die_find_variable_by_reg(Dwarf_Die *sc_die, Dwarf_Addr pc, int reg,return result; } +/* +* Get the absolute address of a location expression that consists of a +* single address, either DW_OP_addr or DW_OP_addrx. libdw leaves the +* DWARF 5 address index unresolved, it has to be looked up in .debug_addr. +*/ +static bool die_get_location_addr (Dwarf_Attribute *attr,Dwarf_Op *ops, +Dwarf_Addr *addr) +{ +if (ops->atom == DW_OP_addr) { + *addr = ops->number; +return true; + } + +if (ops->atom == DW_OP_addrx) { +Dwarf_Attribute addr_attr; + +if (dwarf_getlocation_attr (attr, ops, &addr_attr) !=0 ) +return false; + +return dwarf_formaddr (&addr_attr, addr) ==0 ; + } + +return false; +} +/* Only checks direct child DIEs in the given scope */ static int __die_find_var_addr_cb (Dwarf_Die *die_mem,void *arg) {@@ -1647,11 +1672,13 @@ static int __die_find_var_addr_cb(Dwarf_Die *die_mem, void *arg)return DIE_FIND_CB_SIBLING ;while ((off =dwarf_getlocations (&attr, off, &base, &start, &end, &ops, &nops)) >0 ) { -if (ops->atom != DW_OP_addr) +Dwarf_Addr addr; + +if (!die_get_location_addr (&attr, ops, &addr))continue ;if (check_allowed_ops (ops, nops) && -match_var_offset (die_mem, data, data->addr, ops->number, +match_var_offset (die_mem, data, data->addr, addr,/*is_pointer=*/ false))return DIE_FIND_CB_END ; }@@ -1777,7 +1804,7 @@ static int __die_collect_global_vars_cb(Dwarf_Die *die_mem, void *arg)Dwarf_Die type_die;int tag =dwarf_tag (die_mem);Dwarf_Attribute attr; -Dwarf_Addr base, start, end; +Dwarf_Addr base, start, end, addr;Dwarf_Op *ops;size_t nops;struct die_var_type *vt;@@ -1792,7 +1819,7 @@ static int __die_collect_global_vars_cb(Dwarf_Die *die_mem, void *arg)if (dwarf_getlocations (&attr,0 , &base, &start, &end, &ops, &nops) <=0 )return DIE_FIND_CB_SIBLING ; -if (ops->atom != DW_OP_addr) +if (!die_get_location_addr (&attr, ops, &addr))return DIE_FIND_CB_SIBLING ;if (!check_allowed_ops (ops, nops))@@ -1808,7 +1835,7 @@ static int __die_collect_global_vars_cb(Dwarf_Die *die_mem, void *arg) vt->die_off =dwarf_dieoffset (&type_die); vt->die_tag =dwarf_tag (&type_die); vt->from_alt = !die_same_file (die_mem, &type_die); - vt->addr = ops->number; + vt->addr = addr; vt->end =0 ; vt->has_range = false; vt->reg =-1 ;tools/perf/util/dwarf-aux.h +5
-0@@ -10,6 +10,11 @@#include <elfutils/libdwfl.h> #include <elfutils/version.h> +/* DWARF 5 address index, libdw's dwarf_getlocations() returns it unresolved */ +#ifndef DW_OP_addrx +#define DW_OP_addrx 0xa1 +#endif +static inline const char *die_name (Dwarf_Die *die) {return dwarf_diename (die) ?:"<unknown>" ;Signature · 1 line
2.56.0
Arnaldo Carvalho de Melo
maintainerPATCH v4 4/12 perf tests: Exercise the flexible array member path
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No test covered find_flex_array() and get_flex_array_member(). Add a flex_array workload that keeps a struct with a trailing data[] behind a global pointer, and a test that checks the accesses past the struct size are resolved and named after the flexible array member. The test skips on 32-bit PIE builds, which load globals through the GOT.
--- tools/perf/tests/builtin-test.c | 1 + .../perf/tests/shell/data_type_flex_array.sh | 70 +++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 2 + tools/perf/tests/workloads/flex_array.c | 54 ++++++++++++++ 5 files changed, 128 insertions(+) create mode 100755 tools/perf/tests/shell/data_type_flex_array.sh create mode 100644 tools/perf/tests/workloads/flex_array.c
tools/perf/tests/builtin-test.c +1 -0
@@ -200,6 +200,7 @@ static struct test_workload *workloads[] = { &workload__callchain, &workload__false_sharing, &workload__global_data, + &workload__flex_array, #ifdef HAVE_RUST_SUPPORT &workload__code_with_type,
tools/perf/tests/shell/data_type_flex_array.sh new file +70 -0
70 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -273,6 +273,7 @@ DECLARE_WORKLOAD(deterministic);DECLARE_WORKLOAD (callchain);DECLARE_WORKLOAD (false_sharing);DECLARE_WORKLOAD (global_data); +DECLARE_WORKLOAD (flex_array);#ifdef HAVE_RUST_SUPPORT DECLARE_WORKLOAD (code_with_type);
tools/perf/tests/workloads/Build +2 -0
@@ -18,6 +18,7 @@ perf-test-y += deterministic.o perf-test-y += callchain.o perf-test-y += false_sharing.o perf-test-y += global_data.o +perf-test-y += flex_array.o ifeq ($(CONFIG_RUST_SUPPORT),y) perf-test-y += code_with_type.o
@@ -37,3 +38,4 @@ CFLAGS_named_threads.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_callchain.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_false_sharing.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_global_data.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_flex_array.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE
tools/perf/tests/workloads/flex_array.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 04/12] perf tests: Exercise the flexible array member path
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
From: Arnaldo Carvalho de Melo <[email protected]>
No test covered
find_flex_array()andget_flex_array_member(). Add aflex_arrayworkload that keeps a struct with a trailing data[] behind a global pointer, and a test that checks the accesses past the struct size are resolved and named after the flexible array member. The test skips on 32-bit PIE builds, which load globals through the GOT.Reviewed-by Ian Rogers <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Arnaldo Carvalho de Melo
maintainerPATCH v4 5/12 perf annotate-data: Count flexible array accesses for the whole struct
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The per-member percentage sums the histogram entries in the member's own [offset, offset + size) range. A flexible array member is resolved past the end of its struct, so the struct row only covered its declared size and showed 0.00% while the member row showed 100.00% and the header said N samples.
Take a member's extent as the end of its last child as well, so the struct counts what was resolved past it. Union members all start at offset 0, so a plain union keeps its size; a member that is itself a struct with a flexible array extends the union too. The TUI browser accounts the members the same way, use the extent there as well.
Extend tests/shell/data_type_flex_array.sh to check that the accesses count for the struct in the percent, samples and period columns.
--- .../perf/tests/shell/data_type_flex_array.sh | 40 ++++++++++++++++++- tools/perf/ui/browsers/annotate-data.c | 7 ++-- tools/perf/util/annotate-data.c | 24 ++++++++++- tools/perf/util/annotate-data.h | 8 ++++ 4 files changed, 72 insertions(+), 7 deletions(-)
tools/perf/tests/shell/data_type_flex_array.sh +39 -1
@@ -66,5 +66,43 @@ if ! grep -Fq "# data-type: struct flex +0x4 (data)" "$perfout"; then exit 1 fi -echo "flexible array member resolved" +# The accesses to the flexible array are resolved past the end of the +# struct: they must count for the struct, not only for the member. +if ! perf annotate --data-type -i "$perfdata" --stdio > "$perfout" 2>/dev/null; then + echo "FAIL: perf annotate --data-type" + cleanup + exit 1 +fi + +if ! awk ' + $1 + 0 == 100.00 && /struct flex/ { struct_ok = 1 } + $1 + 0 == 100.00 && /char\[\]/ && /data;/ { data_ok = 1 } + $1 + 0 == 0.00 && /int/ && /len;/ { len_ok = 1 } + END { exit !(struct_ok && data_ok && len_ok) } +' <(sed -n "/^Annotate type: 'struct flex' in/,/^Annotate type: /p" "$perfout"); then + echo "FAIL: --data-type does not count the flexible array accesses" + cleanup + exit 1 +fi + +# Same with the samples and period columns, the other two display modes. +for mode in --show-nr-samples --show-total-period; do + if ! perf annotate --data-type -i "$perfdata" --stdio "$mode" > "$perfout" 2>/dev/null; then + echo "FAIL: perf annotate --data-type $mode" + cleanup + exit 1 + fi + + if ! awk ' + $1 + 0 > 0 && /struct flex/ { total = $1 + 0 } + /char\[\]/ && /data;/ { data = $1 + 0 } + END { exit !(total > 0 && total == data) } + ' <(sed -n "/^Annotate type: 'struct flex' in/,/^Annotate type: /p" "$perfout"); then + echo "FAIL: --data-type $mode does not count the flexible array accesses" + cleanup + exit 1 + fi +done + +echo "flexible array member resolved and counted" cleanup
tools/perf/ui/browsers/annotate-data.c +3 -4
@@ -53,12 +53,11 @@ static int get_member_overhead(struct annotated_data_type *adt, struct evsel *leader) {struct annotated_member *member = entry->data; -int i, k; +int i, k, end =annotated_member__extent (member); -for (i =0 ; i < member->size; i++) { +for (i = member->offset; i < end; i++) {struct type_hist *h;struct evsel *evsel; -int offset = member->offset + i; k =0 ;for_each_group_evsel (evsel, leader) {
@@ -69,7 +68,7 @@ static int get_member_overhead(struct annotated_data_type *adt,continue ; h = &adt->histograms[evsel->core.idx]; -if (hashmap__find (&h->samples, offset, &hist)) +if (hashmap__find (&h->samples, i, &hist))update_hist_entry (&entry->hists[k], hist); k++; }
tools/perf/util/annotate-data.c +22 -2
@@ -2237,6 +2237,25 @@ static void print_annotated_data_value(struct type_hist *h, u64 period, int nr_scolor_fprintf (stdout, color," %7.2f" , percent); } +/* +* A flexible array member is resolved past the end of its parent, so the +* parent's samples are not bounded by its size. +*/ +int annotated_member__extent (struct annotated_member *member) +{ +struct annotated_member *child; +int end = member->offset + member->size; + +list_for_each_entry (child, &member->children, node) { +int child_end =annotated_member__extent (child); + +if (child_end > end) + end = child_end; + } + +return end; +} +static void print_annotated_data_type (struct annotated_data_type *mem_type,struct annotated_member *member,struct evsel *evsel,int indent)
@@ -2244,6 +2263,7 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type,struct annotated_member *child;struct type_hist *h;int i, nr_events =0 , samples =0 ; +int end =annotated_member__extent (member);u64 period =0 ;int width = symbol_conf.show_total_period ?11 :7 ;struct evsel *pos;
@@ -2257,10 +2277,10 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type, samples =0 ; period =0 ; -for (i =0 ; i < member->size; i++) { +for (i = member->offset; i < end; i++) {struct type_hist_entry *entry; -if (!hashmap__find (&h->samples, member->offset + i, &entry)) +if (!hashmap__find (&h->samples, i, &entry))continue ; samples += entry->nr_samples;
tools/perf/util/annotate-data.h +8 -0
@@ -260,6 +260,9 @@ void global_var_type__tree_delete(struct rb_root *root);/* Print data type annotation (including members) on stdout */ int hist_entry__annotate_data_tty (struct hist_entry *he,struct evsel *evsel); +/* End offset of a member, including a flexible array's children */ +int annotated_member__extent (struct annotated_member *member); +/* Get name of member field at the given offset in the data type */ int annotated_data_type__get_member_name (struct annotated_data_type *adt,char *buf,size_t sz,int member_offset);
@@ -316,6 +319,11 @@ static inline int hist_entry__annotate_data_tty(struct hist_entry *he __maybe_unreturn -1 ; } +static inline int annotated_member__extent (struct annotated_member *member) +{ +return member->offset + member->size; +} + static inline int annotated_data_type__get_member_name(struct annotated_data_type *adt __maybe_unused, char *buf __maybe_unused, size_t sz __maybe_unused,
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 05/12] perf annotate-data: Count flexible array accesses for the whole struct
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines
From: Arnaldo Carvalho de Melo <[email protected]>
The per-member percentage sums the histogram entries in the member's own [offset, offset + size) range. A flexible array member is resolved past the end of its struct, so the struct row only covered its declared size and showed 0.00% while the member row showed 100.00% and the header said N samples.
Take a member's extent as the end of its last child as well, so the struct counts what was resolved past it. Union members all start at offset 0, so a plain union keeps its size; a member that is itself a struct with a flexible array extends the union too. The TUI browser accounts the members the same way, use the extent there as well.
Quoted 7 lines
Extend
tests/shell/data_type_flex_array.shto check that the accesses count for the struct in the percent, samples and period columns.Fixes aaca646915a1bb53 ("perf annotate-data: Adjust type offset for flex-array")Reviewed-by Ian Rogers <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Arnaldo Carvalho de Melo
maintainerPATCH v4 6/12 perf tests: Exercise data type resolution from a register
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
At -O2 a struct pointer lives in a register and DWARF describes it with a register location, while the unoptimized workloads the data type tests profile keep their variables on the stack.
Add a regptr workload with a noinline function that gets the pointer from a volatile global, which keeps it in a register, and check that its three member accesses are resolved from that location.
--- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/data_type_register.sh | 64 ++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 2 + tools/perf/tests/workloads/regptr.c | 60 ++++++++++++++++++ 5 files changed, 128 insertions(+) create mode 100755 tools/perf/tests/shell/data_type_register.sh create mode 100644 tools/perf/tests/workloads/regptr.c
tools/perf/tests/builtin-test.c +1 -0
@@ -201,6 +201,7 @@ static struct test_workload *workloads[] = { &workload__false_sharing, &workload__global_data, &workload__flex_array, + &workload__regptr, #ifdef HAVE_RUST_SUPPORT &workload__code_with_type,
tools/perf/tests/shell/data_type_register.sh new file +64 -0
64 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -274,6 +274,7 @@ DECLARE_WORKLOAD(callchain);DECLARE_WORKLOAD (false_sharing);DECLARE_WORKLOAD (global_data);DECLARE_WORKLOAD (flex_array); +DECLARE_WORKLOAD (regptr);#ifdef HAVE_RUST_SUPPORT DECLARE_WORKLOAD (code_with_type);
tools/perf/tests/workloads/Build +2 -0
@@ -19,6 +19,7 @@ perf-test-y += callchain.o perf-test-y += false_sharing.o perf-test-y += global_data.o perf-test-y += flex_array.o +perf-test-y += regptr.o ifeq ($(CONFIG_RUST_SUPPORT),y) perf-test-y += code_with_type.o
@@ -39,3 +40,4 @@ CFLAGS_callchain.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_false_sharing.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_global_data.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_flex_array.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_regptr.o = -g -O2
tools/perf/tests/workloads/regptr.c new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 06/12] perf tests: Exercise data type resolution from a register
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
From: Arnaldo Carvalho de Melo <[email protected]>
At -O2 a struct pointer lives in a register and DWARF describes it with a register location, while the unoptimized workloads the data type tests profile keep their variables on the stack.
Quoted 6 lines
Add a regptr workload with a noinline function that gets the pointer from a volatile global, which keeps it in a register, and check that its three member accesses are resolved from that location.
Reviewed-by Ian Rogers <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Arnaldo Carvalho de Melo
maintainerPATCH v4 7/12 perf annotate: Print the stats after the annotations
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The instruction stats are printed before the loop that accounts them, so 'perf annotate --code-with-type --insn-stat' always shows zeros. The data type counters are updated in --code-with-type mode too, but only --data-type mode accounts their total, so they are incomplete there.
Print both after the annotation loops, the data type part only with --data-type.
--- tools/perf/builtin-annotate.c | 10 ++-- tools/perf/tests/shell/annotate_stats.sh | 64 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100755 tools/perf/tests/shell/annotate_stats.sh
tools/perf/builtin-annotate.c +5 -5
@@ -414,11 +414,6 @@ static void hists__find_annotations(struct hists *hists,struct rb_node *nd =rb_first_cached (&hists->entries), *next;int key =K_RIGHT ; -if (ann->type_stat) -print_annotate_data_stat (&ann_data_stat); -if (ann->insn_stat) -print_annotate_item_stat (&ann_insn_stat,"Instruction" ); -while (nd) { struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);struct annotation *notes;
@@ -660,6 +655,11 @@ static int __cmd_annotate(struct perf_annotate *ann)hists__find_annotations (hists, pos, ann); } +if (ann->data_type && ann->type_stat) +print_annotate_data_stat (&ann_data_stat); +if (ann->insn_stat) +print_annotate_item_stat (&ann_insn_stat,"Instruction" ); +if (use_browser ==2 ) {void (*show_annotations)(void );
tools/perf/tests/shell/annotate_stats.sh new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 07/12] perf annotate: Print the stats after the annotations
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
From: Arnaldo Carvalho de Melo <[email protected]>
The instruction stats are printed before the loop that accounts them, so 'perf annotate --code-with-type --insn-stat' always shows zeros. The data type counters are updated in --code-with-type mode too, but only --data-type mode accounts their total, so they are incomplete there.
Quoted 7 lines
Print both after the annotation loops, the data type part only with --data-type.
Fixes 58824fa0087e1cb7 ("perf annotate: Add --insn-stat option for debugging")Fixes 61a9741e9f78c64c ("perf annotate: Add --type-stat option for debugging")Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Arnaldo Carvalho de Melo
maintainerPATCH v4 8/12 perf tests: Silence the libbfd probe in build-test
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
build-test evaluates the libbfd probe at parse time and the compiler's stderr isn't captured by $(shell ...), so without binutils-devel it prints "bfd.h: No such file or directory" once per tests/make invocation, five times per run.
Redirect the compiler's stderr; the empty result still skips the nondistro tests as intended.
--- tools/perf/tests/make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/make +1 -1
@@ -128,7 +128,7 @@ make_minimal += NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1 make_minimal += NO_CAPSTONE=1 # binutils 2_42 and newer have bfd_thread_init() -new_libbfd := $(shell echo '#include <bfd.h>' | $(CC) -E -x c - | grep bfd_thread_init) +new_libbfd := $(shell echo '#include <bfd.h>' | $(CC) -E -x c - 2>/dev/null | grep bfd_thread_init) # Whether libLLVM can be built, which needs the llvm-devel/llvm-dev headers and # libraries of version 13 or newer, not just llvm-config. This mirrors the
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 08/12] perf tests: Silence the libbfd probe in build-test
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Arnaldo Carvalho de Melo <[email protected]>
build-test evaluates the libbfd probe at parse time and the compiler's stderr isn't captured by $(shell ...), so without binutils-devel it prints "
bfd.h: No such file or directory" once per tests/make invocation, five times per run.
Quoted 7 lines
Redirect the compiler's stderr; the empty result still skips the nondistro tests as intended.
Fixes 523471c5163659c6 ("perf build: Skip nondistro build test if libbfd is old")Reviewed-by Ian Rogers <[email protected]>Cc James Clark <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Arnaldo Carvalho de Melo
maintainerPATCH v4 9/12 perf build: Record the display-only features in FEATURE-DUMP
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
llvm-perf and rust are in FEATURE_DISPLAY but not in FEATURE_TESTS: they can't be part of the test-all fast path, which sets every FEATURE_TESTS entry to 1 when test-all.c builds. Since FEATURE-DUMP is written from FEATURE_TESTS only, a FEATURES_DUMP= build, as used by build-test, never sees them and silently builds without libLLVM and the rust workloads.
Append the display features that aren't in FEATURE_TESTS to the dump after the regular feature checks have run.
--- tools/perf/Makefile.config | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/Makefile.config +4 -0
@@ -1310,3 +1310,7 @@ endif # tests. $(shell rm -f $(FEATURE_DUMP_FILENAME)) $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME))) +# Features only in FEATURE_DISPLAY aren't part of the test-all fast path, so +# they have to be checked explicitly and recorded here too, otherwise a +# FEATURES_DUMP= build silently disables them (llvm-perf, rust). +$(foreach feat,$(filter-out $(FEATURE_TESTS),$(FEATURE_DISPLAY)),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 09/12] perf build: Record the display-only features in FEATURE-DUMP
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
From: Arnaldo Carvalho de Melo <[email protected]>
llvm-perf and rust are in
FEATURE_DISPLAYbut not inFEATURE_TESTS: they can't be part of the test-all fast path, which sets everyFEATURE_TESTSentry to 1 whentest-all.cbuilds. Since FEATURE-DUMP is written fromFEATURE_TESTSonly, a FEATURES_DUMP= build, as used by build-test, never sees them and silently builds without libLLVM and the rust workloads.
Quoted 7 lines
Append the display features that aren't in
FEATURE_TESTSto the dump after the regular feature checks have run.Fixes 206dcfca1f5cfac3 ("perf build: Autodetect minimum required llvm-dev version")Fixes 3f5dfa472ea6771c ("tools build: Fix rust feature detection")Cc James Clark <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Arnaldo Carvalho de Melo
maintainerPATCH v4 10/12 perf tests: Fix the Intel PT virtual LBR check
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The record this check uses writes aux samples, and with the single data page the other tests ask for they are lost:
Warning: Processed 29 samples and lost 100.00%
so no branches are decoded and the check fails with "Failed with virtual lbr". Record with 4 data pages and 128 auxtrace pages: the same trace decodes 64 branches and still fits the mlock budget.
Require the python perf module to provide session, not just to be
importable: a perf whose python bindings are not found can pick up an unrelated module and fail with
Error processing events: module 'perf' has no attribute 'session'
instead of skipping the subtest.
Detected building perf on fedora:44 on the runner with Intel PT hardware, where the subtest failed with "Failed with virtual lbr" in the container, and with the python error when run as root on the same machine.
--- tools/perf/tests/shell/test_intel_pt.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
tools/perf/tests/shell/test_intel_pt.sh +5 -4
@@ -384,13 +384,14 @@ test_virtual_lbr() # shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh - if ! "$PYTHON" -c 'import perf' > /dev/null 2>&1; then - echo "SKIP: Python perf module not found" + if ! "$PYTHON" -c 'import perf; perf.session' > /dev/null 2>&1; then + echo "SKIP: Python perf module with session support not found" return 2 fi - # Check if virtual lbr is working - perf_record_no_bpf -o "${tmpfile}" --aux-sample \ + # Check if virtual lbr is working. This records aux samples, which a + # single data page overruns, so give it more room than the other tests. + perf_record_no_bpf -m 4,128 -o "${tmpfile}" --aux-sample \ -e '{intel_pt//,cycles}:u' perf test -w brstack || return 1 perf inject --itrace=L -i "${tmpfile}" -o "${perfdatafile}" || return 1 output=$("$PYTHON" "${shelldir}/lib/perf_brstack_max.py" -i "${perfdatafile}") || return 1
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 10/12] perf tests: Fix the Intel PT virtual LBR check
Sashiko has reviewed this patch and found no issues.
Quoted 19 lines
From: Arnaldo Carvalho de Melo <[email protected]>
The record this check uses writes aux samples, and with the single data page the other tests ask for they are lost:
Warning: Processed 29 samples and lost 100.00%
so no branches are decoded and the check fails with "Failed with virtual lbr". Record with 4 data pages and 128 auxtrace pages: the same trace decodes 64 branches and still fits the mlock budget.
Require the python perf module to provide session, not just to be
importable: a perf whose python bindings are not found can pick up an unrelated module and fail withError processing events: module 'perf' has no attribute 'session'
instead of skipping the subtest.
Quoted 7 lines
Detected building perf on fedora:44 on the runner with Intel PT hardware, where the subtest failed with "Failed with virtual lbr" in the container, and with the python error when run as root on the same machine.
Fixes 915d6b14dc0c ("perf test: Migrate Intel PT virtual LBR test to Python API")Reviewed-by Ian Rogers <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Arnaldo Carvalho de Melo
maintainerPATCH v4 11/12 perf test: Drop samples without an IP in the dlfilter test
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Since v7.3 the kernel zeroes PERF_SAMPLE_IP when a userspace-only event skids into kernel mode, so that kernel register state is not exposed to an unprivileged event (166f10836a653dfa "perf/core: Fix kernel register info leak via hardware skid").
The test dlfilter keeps those samples, and the check that nothing but test_loop survives then trips on their lines: the comm column reads "perf". Drop them, which is what the test wants, everything except test_loop must be filtered out.
--- tools/perf/tests/shell/script_dlfilter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/script_dlfilter.sh +1 -1
@@ -46,7 +46,7 @@ int filter_event(void *data, const struct perf_dlfilter_sample *sample, void *ct const struct perf_dlfilter_al *al; if (!sample->ip) - return 0; + return 1; al = perf_dlfilter_fns.resolve_ip(ctx); if (!al || !al->sym || strcmp(al->sym, "test_loop"))
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 11/12] perf test: Drop samples without an IP in the dlfilter test
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Since v7.3 the kernel zeroes
PERF_SAMPLE_IPwhen a userspace-only event skids into kernel mode, so that kernel register state is not exposed to an unprivileged event (166f10836a653dfa"perf/core: Fix kernel register info leak via hardware skid").The test dlfilter keeps those samples, and the check that nothing but
test_loopsurvives then trips on their lines: the comm column reads "perf". Drop them, which is what the test wants, everything excepttest_loopmust be filtered out.
Quoted 4 lines
Fixes 199d5e872a9ce737 ("perf tests script dlfilter: Add a dlfilter test")Reviewed-by Ian Rogers <[email protected]>Cc Ian Rogers <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Arnaldo Carvalho de Melo
maintainerPATCH v4 12/12 perf test: Skip the LBR inline unwinding check when unsupported
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The check only looks for the PMU's caps/branches file before recording with --call-graph lbr. AMD BRS advertises branches but only samples its own retired branches event, so the record with cycles is rejected and the test fails instead of skipping.
Probe the record and, when it fails with "Invalid argument" or "not supported", exit with status 2 so the test reports Skip, as the branch stack test does. Any other record failure still fails the test and shows the error.
--- tools/perf/tests/shell/addr2line_inlines.sh | 23 ++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
tools/perf/tests/shell/addr2line_inlines.sh +22 -1
@@ -8,6 +8,8 @@ err=0 test_dir=$(mktemp -d /tmp/perf-test-inline-addr2line.XXXXXXXXXX) perf_data="${test_dir}/perf.data" perf_script_txt="${test_dir}/perf_script.txt" +perf_record_err="${test_dir}/perf_record.err" +lbr_skipped=0 cleanup() { rm -rf "${test_dir}"
@@ -71,7 +73,22 @@ test_lbr() { fi # Record data. Currently only dwarf callchains support inlined functions. - perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- perf test -w inlineloop 1 + # Some PMUs advertise branches but reject branch sampling for cycles, e.g. + # AMD BRS, which only samples its own retired branches event. + if ! perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- \ + perf test -w inlineloop 1 2> "${perf_record_err}" + then + if grep -q -e "Invalid argument" -e "not supported" "${perf_record_err}" + then + echo "Skip: LBR not supported by the PMU" + lbr_skipped=1 + else + cat "${perf_record_err}" + echo "Inline unwinding lbr verification test [Failed to record]" + err=1 + fi + return + fi # Check output with inline (default) and srcline perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
@@ -93,4 +110,8 @@ test_dwarf test_lbr cleanup +if [ $err -eq 0 ] && [ $lbr_skipped -eq 1 ] +then + exit 2 +fi exit $err
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v4 12/12] perf test: Skip the LBR inline unwinding check when unsupported
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] perf test: test_lbr() grep misses EOPNOTSUPP branch stack error string --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] perf test: test_lbr() grep misses EOPNOTSUPP branch stack error string
--
commit 0391fa9c2628a460f3c842d979bf69a0aa07c146
Author: Arnaldo Carvalho de Melo <[email protected]>
perf test: Skip the LBR inline unwinding check when unsupported
This commit updates the addr2line_inlines shell test to check the error output from perf record --call-graph lbr and skip the test with exit status 2 when LBR recording is rejected by the PMU.
Quoted 4 lines
tools/perf/tests/shell/addr2line_inlines.sh +0
-0
[ ... ]
Quoted 11 lines
tools/perf/tests/shell/addr2line_inlines.sh +6
-1@@ -71,7 +73,22 @@ test_lbr() { fi # Record data. Currently only dwarf callchains support inlined functions. - perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- perf test -w inlineloop 1 + # Some PMUs advertise branches but reject branch sampling for cycles, e.g. + # AMD BRS, which only samples its own retired branches event. + if ! perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- \ + perf test -w inlineloop 1 2> "${perf_record_err}" + then + if grep -q -e "Invalid argument" -e "not supported" "${perf_record_err}"
tools/perf/tests/shell/addr2line_inlines.sh test_lbr() { · line 91
Quoted 10 lines
tools/perf/tests/shell/addr2line_inlines.sh +10
-0+ then + echo "Skip: LBR not supported by the PMU" + lbr_skipped=1 + else + cat "${perf_record_err}" + echo "Inline unwinding lbr verification test [Failed to record]" + err=1 + fi + return + fi
[Severity: Low]
Does this grep miss the EOPNOTSUPP error message emitted when the PMU rejects --call-graph lbr?
On CPUs that expose caps/branches but return -EOPNOTSUPP for PERF_SAMPLE_BRANCH_CALL_STACK (such as AMD Zen 4/5 with LBRv2 in amd_pmu_lbr_setup_filter()), evsel__open_strerror() formats EOPNOTSUPP with "doesn't support" rather than strerror(EOPNOTSUPP) ("Operation not supported"):
tools/perf/util/evsel.c:evsel__open_strerror() {
...
case EOPNOTSUPP:
if (evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK)
return scnprintf(msg, size,
"%s: PMU Hardware or event type doesn't support branch stack sampling.",
evsel__name(evsel));
...
}As a result, the grep does not match and test_lbr() still fails the test with err=1 instead of skipping. Matching "doesn't support" as well would handle EOPNOTSUPP.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12