Skip to contentSkip to conversation

perf coverage: A harness for perf, and the fixes it found

PATCH Superseded Arnaldo Carvalho de Melo 4 participants 25 messages Nov 13 perf events

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

v2 cover perf coverage: A harness for perf, and the fixes it found

From: Arnaldo Carvalho de Melo <[email protected]>

Hi,

Please consider merging,

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, 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 rest is what the first runs found, in the code, the build and the tests:

- clang DWARF 5 describes globals with DW_OP_addrx, which was not resolved (patch 2).
- The flexible array member had no test; one showed the struct row at

    0.00% while the member said 100.00% (patches 3-4).

- A struct pointer that -O2 keeps in a register was not resolved from its DWARF location (patch 5).
- --insn-stat was printed before the loop that accounts the samples, so --code-with-type showed zeros (patch 6).
- The libbfd probe printed a missing bfd.h error five times per build-test run (patch 7).
- FEATURE-DUMP didn't record llvm-perf and rust, disabling both in the build-test builds (patch 8).
- The Intel PT virtual LBR check lost every aux sample with a single data page (patch 9).
- The dlfilter test kept samples whose IP the kernel now zeroes on a userspace-to-kernel skid (patch 10).
- The LBR inline unwinding check failed instead of skipping when the AMD PMU rejects branch sampling (patch 11).

In a root run on this box the suite covered 49.16% of perf's 201,180 lines. The POLL_HUP tracepoint regression and the lock contention count fail in code this series does not change; the LBR inline unwinding check failed there and now skips.

The numbers above are from v1 and are slightly different here: the cs-etm patch was dropped and the issues reported in the v1 review were addressed, which changes both the tree and what the report counts.

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 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 4: the TUI browser counts flexible array accesses too.
- Patch 6: the stats test skips without libdw.
- Patches 9 and 11 (were 10 and 12): Fixes tags corrected.

Best regards,

- Arnaldo

Arnaldo Carvalho de Melo (11):
perf scripts: Add a coverage harness for perf
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                | 722 ++++++++++++++++++
 tools/perf/tests/make                         |   2 +-
 tools/perf/tests/shell/addr2line_inlines.sh   |   9 +-
 tools/perf/tests/shell/annotate_stats.sh      |  64 ++
 .../perf/tests/shell/data_type_flex_array.sh  | 142 ++++
 .../tests/shell/data_type_profiling_clang.sh  | 108 +++
 tools/perf/tests/shell/data_type_register.sh  | 120 +++
 tools/perf/tests/shell/script_dlfilter.sh     |   2 +-
 tools/perf/tests/shell/test_intel_pt.sh       |   9 +-
 tools/perf/ui/browsers/annotate-data.c        |   7 +-
 tools/perf/util/annotate-data.c               |  24 +-
 tools/perf/util/annotate-data.h               |   3 +
 tools/perf/util/dwarf-aux.c                   |  42 +-
 18 files changed, 1260 insertions(+), 24 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_profiling_clang.sh
 create mode 100755 tools/perf/tests/shell/data_type_register.sh

base-commit: cc905a18a647a8e3ad42cd1596baa0e08fba26eb
v1-head: 3f5465bea8f5a97a

Signature · 1 line
2.56.0
author maintainer
#1 lore raw

PATCH v2 1/11 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 perf, 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.

It is a maintainer tool and it already paid for itself: the first run found the clang DWARF 5 data type test failing (the DW_OP_addrx gap, fixed by the next patch), and the uncovered line list is what drove the tests in the rest of the series.

  $ scripts/coverage.sh
  ...
  Total: 67436 of 201128 lines covered (33.53%)
    largest uncovered files (>= 100 lines)
    file                                            lines     cover    missed  fn-cover
    builtin-trace.c                                  3657     4.24%      3502     0.51%
    util/intel-pt.c                                  3237     0.00%      3237     0.00%
    util/intel-pt-decoder/intel-pt-decoder.c         3208     0.00%      3208     0.00%
    builtin-sched.c                                  3737    19.72%      3000    11.35%
    ui/browsers/hists.c                              2730     0.00%      2730     0.00%
    util/probe-event.c                               2765     5.39%      2616    10.68%
    builtin-script.c                                 3212    29.98%      2249    33.06%
    ...

Report: /tmp/build/perf-coverage/cov/report.txt

The run above was unprivileged, so tests that need root are skipped or fail; the report still points at the gaps.

---
 tools/perf/.gitignore          |   1 +
 tools/perf/Makefile            |  11 +-
 tools/perf/Makefile.perf       |   4 +
 tools/perf/scripts/coverage.sh | 722 +++++++++++++++++++++++++++++++++
 4 files changed, 737 insertions(+), 1 deletion(-)
 create mode 100755 tools/perf/scripts/coverage.sh
tools/perf/.gitignore +1 -0
index 3b968c5158b822ce..9052f25597ac9489 100644
@@ -27,6 +27,7 @@ stats-*.csv
 cscope*
 config.mak
 config.mak.autogen
+.coverage-build-dir
 *-bison.*
 *-flex.*
 *.pyc
tools/perf/Makefile +10 -1
index 00baf90e5bda7123..8df8e9ed37f0a8f5 100644
@@ -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
index b74b534e1153ffcb..782929b0ba10d8f3 100644
@@ -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 +722 -0

722 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#3 lore raw

PATCH v2 2/11 perf annotate-data: Resolve DW_OP_addrx global variables

In reply to Arnaldo Carvalho de Melo

From: 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. Add a test that compiles the workload with clang -gdwarf-5 and checks that the global is annotated.

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]>
---
 .../tests/shell/data_type_profiling_clang.sh  | 108 ++++++++++++++++++
 tools/perf/util/dwarf-aux.c                   |  42 ++++++-
 2 files changed, 145 insertions(+), 5 deletions(-)
 create mode 100755 tools/perf/tests/shell/data_type_profiling_clang.sh
tools/perf/tests/shell/data_type_profiling_clang.sh new file +108 -0
new file mode 100755
index 0000000000000000..8e425952d4742a2c
@@ -0,0 +1,108 @@
+#!/bin/bash
+# perf data type profiling tests with clang DWARF 5
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+# clang describes the location of globals with DW_OP_addrx where gcc
+# uses DW_OP_addr, so the workload has to be built here to get that
+# encoding.
+
+command -v clang > /dev/null || exit 2
+
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX)
+prog=$(mktemp /tmp/__perf_test.clang.XXXXX)
+src="${prog}.c"
+
+cleanup()
+{
+	rm -f "$perfdata" "$perfout" "$prog" "$src"
+	trap - EXIT TERM INT
+}
+
+trap_cleanup()
+{
+	echo "Unexpected signal in ${FUNCNAME[1]}"
+	cleanup
+	exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+# 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
+
+cat > "$src" <<'EOF'
+#include <signal.h>
+#include <unistd.h>
+
+struct conn {
+	int saddr;
+	int daddr;
+	long bytes;
+};
+
+static volatile struct conn conn;
+static volatile sig_atomic_t done;
+
+static void stop(int sig)
+{
+	done = 1;
+}
+
+int main(void)
+{
+	unsigned long sum = 0;
+	int i = 0;
+
+	signal(SIGALRM, stop);
+	alarm(1);
+
+	while (!done) {
+		conn.saddr = i;
+		conn.daddr = i + 1;
+		sum += conn.bytes;
+		i++;
+	}
+	return sum != 0;
+}
+EOF
+
+# -fPIE keeps the accesses PC-relative on x86_64, the operand form the
+# data type resolver handles.
+if ! clang -O0 -gdwarf-5 -fPIE -pie -o "$prog" "$src"; then
+	echo "Skip: cannot build the workload with clang"
+	cleanup
+	exit 2
+fi
+
+if ! perf mem record -o "$perfdata" -- "$prog" > /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: struct conn not resolved, DW_OP_addrx not handled?"
+	cleanup
+	exit 1
+fi
+
+echo "DW_OP_addrx global resolved"
+cleanup
tools/perf/util/dwarf-aux.c +37 -5

81 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#5 lore raw

PATCH v2 3/11 perf tests: Exercise the flexible array member path

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

No test covered find_flex_array() and get_flex_array_member(). Add one that keeps a struct with a trailing data[] behind a global pointer and checks that accesses past the struct size are resolved and named after the flexible array member.

---
 .../perf/tests/shell/data_type_flex_array.sh  | 104 ++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100755 tools/perf/tests/shell/data_type_flex_array.sh
tools/perf/tests/shell/data_type_flex_array.sh new file +104 -0
new file mode 100755
index 0000000000000000..983cde2b3c7d2b29
@@ -0,0 +1,104 @@
+#!/bin/bash
+# perf data type profiling tests for flexible array members
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX)
+prog=$(mktemp /tmp/__perf_test.flex.XXXXX)
+src="${prog}.c"
+
+cleanup()
+{
+	rm -f "$perfdata" "$perfout" "$prog" "$src"
+	trap - EXIT TERM INT
+}
+
+trap_cleanup()
+{
+	echo "Unexpected signal in ${FUNCNAME[1]}"
+	cleanup
+	exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+# 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
+
+cat > "$src" <<'EOF'
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+struct flex {
+	int len;
+	char data[];
+};
+
+static struct flex *gp;
+static volatile sig_atomic_t done;
+
+static void stop(int sig)
+{
+	done = 1;
+}
+
+int main(void)
+{
+	unsigned long sum = 0;
+
+	gp = calloc(1, sizeof(*gp) + 4096);
+	if (gp == NULL)
+		return 1;
+	gp->len = 4096;
+
+	signal(SIGALRM, stop);
+	alarm(1);
+
+	while (!done) {
+		sum += gp->data[3];
+		gp->data[5] = 1;
+	}
+	return sum != 0;
+}
+EOF
+
+# -fPIE keeps the global pointer load PC-relative on x86_64, so the
+# resolver can tell the register holds a struct flex pointer.
+if ! cc -O0 -g -fPIE -pie -o "$prog" "$src" 2>/dev/null; then
+	echo "Skip: cannot build the workload"
+	cleanup
+	exit 2
+fi
+
+if ! perf mem record -o "$perfdata" -- "$prog" > /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 -Fq "# data-type: struct flex +0x4 (data)" "$perfout"; then
+	echo "FAIL: flexible array member not resolved"
+	cleanup
+	exit 1
+fi
+
+echo "flexible array member resolved"
+cleanup
Signature · 1 line
2.56.0
author maintainer
#7 lore raw

PATCH v2 4/11 perf annotate-data: Count flexible array accesses for the whole struct

In reply to Arnaldo Carvalho de Melo

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.

Extend tests/shell/data_type_flex_array.sh to 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")
Cc Namhyung Kim <[email protected]>
---
 .../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               |  3 ++
 4 files changed, 67 insertions(+), 7 deletions(-)
tools/perf/tests/shell/data_type_flex_array.sh +39 -1
index 983cde2b3c7d2b29..7a7a782320afee23 100755
@@ -100,5 +100,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
index 0f778788df4a934b..0e1e06acf2b231a7 100644
@@ -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
index dd9c1d7b2da8be8a..75a0906b4df0b9e2 100644
@@ -2233,6 +2233,25 @@ static void print_annotated_data_value(struct type_hist *h, u64 period, int nr_s
 		color_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)
@@ -2240,6 +2259,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;
@@ -2253,10 +2273,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 +3 -0
index 184262c7356213fa..880b11849a9329c7 100644
@@ -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);
Signature · 1 line
2.56.0
author maintainer
#9 lore raw

PATCH v2 5/11 perf tests: Exercise data type resolution from a register

In reply to Arnaldo Carvalho de Melo

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.

Build a 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/shell/data_type_register.sh | 120 +++++++++++++++++++
 1 file changed, 120 insertions(+)
 create mode 100755 tools/perf/tests/shell/data_type_register.sh
tools/perf/tests/shell/data_type_register.sh new file +120 -0
new file mode 100755
index 0000000000000000..e0369f076ae6f4b2
@@ -0,0 +1,120 @@
+#!/bin/bash
+# perf data type profiling tests for register variables
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX)
+prog=$(mktemp /tmp/__perf_test.regs.XXXXX)
+src="${prog}.c"
+
+cleanup()
+{
+	rm -f "$perfdata" "$perfout" "$prog" "$src"
+	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
+
+# 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
+
+cat > "$src" <<'EOF'
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+struct node {
+	long a;
+	long b;
+	long c;
+};
+
+static struct node n;
+static struct node *volatile vp;
+static volatile sig_atomic_t done;
+
+static void stop(int sig)
+{
+	done = 1;
+}
+
+__attribute__((noinline)) static long touch(struct node *p)
+{
+	long sum = 0;
+
+	sum += p->a;
+	p->b = sum;
+	sum += p->c;
+	return sum;
+}
+
+int main(void)
+{
+	unsigned long sum = 0;
+
+	vp = &n;
+	signal(SIGALRM, stop);
+	alarm(1);
+
+	while (!done)
+		sum += touch(vp);
+
+	return sum != 0;
+}
+EOF
+
+# -O2: the pointer stays in a register, so the accesses are resolved
+# from its type state instead of from a stack slot.
+if ! cc -O2 -g -fPIE -pie -o "$prog" "$src" 2>/dev/null; then
+	echo "Skip: cannot build the workload"
+	cleanup
+	exit 2
+fi
+
+if ! perf mem record -o "$perfdata" -- "$prog" > /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
+
+for member in "+0 (a)" "+0x8 (b)" "+0x10 (c)"; do
+	if ! grep -Fq "# data-type: struct node ${member}" "$perfout"; then
+		echo "FAIL: member ${member} not resolved from the register"
+		cleanup
+		exit 1
+	fi
+done
+
+echo "register held access resolved"
+
+cleanup
Signature · 1 line
2.56.0
author maintainer
#11 lore raw

PATCH v2 6/11 perf annotate: Print the stats after the annotations

In reply to Arnaldo Carvalho de Melo

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.

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]>
---
 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
index 331adbdbd635917d..973f4950abd6f917 100644
@@ -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
author maintainer
#13 lore raw

PATCH v2 7/11 perf tests: Silence the libbfd probe in build-test

In reply to Arnaldo Carvalho de Melo

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.

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")
Cc James Clark <[email protected]>
---
 tools/perf/tests/make | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/make +1 -1
index 7524de5228029e7e..e6d7ac49b5b1693d 100644
@@ -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
author maintainer
#15 lore raw

PATCH v2 8/11 perf build: Record the display-only features in FEATURE-DUMP

In reply to Arnaldo Carvalho de Melo

From: 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.

Fixes 206dcfca1f5cfac3 ("perf build: Autodetect minimum required llvm-dev version")
Fixes 3f5dfa472ea6771c ("tools build: Fix rust feature detection")
Cc James Clark <[email protected]>
---
 tools/perf/Makefile.config | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/Makefile.config +4 -0
index b4764f69f47f4d8c..1b5caa246345c9bb 100644
@@ -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
author maintainer
#17 lore raw

PATCH v2 9/11 perf tests: Fix the Intel PT virtual LBR check

In reply to Arnaldo Carvalho de Melo

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 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.

Fixes 915d6b14dc0c ("perf test: Migrate Intel PT virtual LBR test to Python API")
---
 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
index c0ecece0a8255124..511440b5956a6897 100755
@@ -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
author maintainer
#19 lore raw

PATCH v2 10/11 perf test: Drop samples without an IP in the dlfilter test

In reply to Arnaldo Carvalho de Melo

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.

Fixes 199d5e872a9ce737 ("perf tests script dlfilter: Add a dlfilter test")
Cc Ian Rogers <[email protected]>
---
 tools/perf/tests/shell/script_dlfilter.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/script_dlfilter.sh +1 -1
index 88222280f6094fd0..797cd9ae84141f64 100755
@@ -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
author maintainer
#21 lore raw

PATCH v2 11/11 perf test: Skip the LBR inline unwinding check when unsupported

In reply to Arnaldo Carvalho de Melo

From: 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 skip when it fails, as the branch stack test does.

Fixes 446c595dc0dd ("perf test addr2line_inlines: Ensure inline information shows on LBR leaves")
Cc Ian Rogers <[email protected]>
---
 tools/perf/tests/shell/addr2line_inlines.sh | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/tests/shell/addr2line_inlines.sh +8 -1
index e8754ef2d7f21ac2..6fe47909dae4f812 100755
@@ -71,7 +71,14 @@ 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>/dev/null
+    then
+        echo "Skip: LBR not supported by the PMU"
+        return
+    fi
 
     # Check output with inline (default) and srcline
     perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
Signature · 1 line
2.56.0
#14 lore raw

Re: [PATCH v2 07/11] perf tests: Silence the libbfd probe in build-test

In reply to Arnaldo Carvalho de Melo
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 6 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")
Cc James Clark <[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
#16 lore raw

Re: [PATCH v2 08/11] perf build: Record the display-only features in FEATURE-DUMP

In reply to Arnaldo Carvalho de Melo
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_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.

Quoted 7 lines

Append the display features that aren't in FEATURE_TESTS to 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]>

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#12 lore raw

Re: [PATCH v2 06/11] perf annotate: Print the stats after the annotations

In reply to Arnaldo Carvalho de Melo
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]>

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#6 lore raw

Re: [PATCH v2 03/11] perf tests: Exercise the flexible array member path

In reply to Arnaldo Carvalho de Melo
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

From: Arnaldo Carvalho de Melo <[email protected]>

No test covered find_flex_array() and get_flex_array_member(). Add one that keeps a struct with a trailing data[] behind a global pointer and checks that accesses past the struct size are resolved and named after the flexible array member.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#2 lore raw

Re: [PATCH v2 01/11] perf scripts: Add a coverage harness for perf

In reply to Arnaldo Carvalho de Melo
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 perf, 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.

Quoted 6 lines

[ ... ]

The run above was unprivileged, so tests that need root are skipped or fail; the report still points at the gaps.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#20 lore raw

Re: [PATCH v2 10/11] perf test: Drop samples without an IP in the dlfilter test

In reply to Arnaldo Carvalho de Melo
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

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.

Quoted 4 lines
Fixes 199d5e872a9ce737 ("perf tests script dlfilter: Add a dlfilter test")
Cc Ian Rogers <[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
#22 lore raw

Re: [PATCH v2 11/11] perf test: Skip the LBR inline unwinding check when unsupported

In reply to Arnaldo Carvalho de Melo
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

From: 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.

Quoted 5 lines

Probe the record and skip when it fails, as the branch stack test does.

Fixes 446c595dc0dd ("perf test addr2line_inlines: Ensure inline information shows on LBR leaves")
Cc Ian Rogers <[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
#8 lore raw

Re: [PATCH v2 04/11] perf annotate-data: Count flexible array accesses for the whole struct

In reply to Arnaldo Carvalho de Melo
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] perf annotate-data: missing stub for annotated_member_extent() without libdw --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] perf annotate-data: missing stub for annotated_member_extent() without libdw
--

commit 08cc9872c27cbef64cf4ff8273d106d1700fd31c
Author: Arnaldo Carvalho de Melo <[email protected]>

perf annotate-data: Count flexible array accesses for the whole struct

This commit introduces annotated_member_extent() to include children such as flexible array members when computing the sample range of a struct or union member in both stdio and TUI data-type annotation outputs.

Quoted 10 lines
tools/perf/ui/browsers/annotate-data.c +1 -1
index 0f778788df4a9..0e1e06acf2b23 100644
@@ -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);

[ ... ]

Quoted 5 lines
tools/perf/util/annotate-data.h +0 -0
index 184262c735621..880b11849a932 100644

tools/perf/util/annotate-data.h void global_var_type__tree_delete(struct rb_root *root); · line 268

Quoted 9 lines
tools/perf/util/annotate-data.h +3 -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);

[Severity: Medium]
Does annotated_member_extent() need a fallback stub in the #else /* HAVE_LIBDW_SUPPORT */ block (or to be defined outside the guard)?

This declaration sits inside #ifdef HAVE_LIBDW_SUPPORT and tools/perf/util/annotate-data.c is only built when CONFIG_LIBDW is enabled, whereas tools/perf/ui/browsers/annotate-data.c is built whenever CONFIG_SLANG is enabled. Building perf with TUI enabled and libdw disabled (e.g. make NO_LIBDW=1) fails in get_member_overhead() with an implicit declaration and undefined reference to annotated_member_extent().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#10 lore raw

Re: [PATCH v2 05/11] perf tests: Exercise data type resolution from a register

In reply to Arnaldo Carvalho de Melo
Sashiko has reviewed this patch and found no issues.
Quoted 11 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.

Build a 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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#4 lore raw

Re: [PATCH v2 02/11] perf annotate-data: Resolve DW_OP_addrx global variables

In reply to Arnaldo Carvalho de Melo
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines

From: 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. Add a test that compiles the workload with clang -gdwarf-5 and checks that the global is annotated.

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]>

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#18 lore raw

Re: [PATCH v2 09/11] perf tests: Fix the Intel PT virtual LBR check

In reply to Arnaldo Carvalho de Melo
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 with

Error 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")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
reviewer
#23 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 63 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Hi,

Please consider merging,

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, 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 rest is what the first runs found, in the code, the build and the tests:

- clang DWARF 5 describes globals with DW_OP_addrx, which was not resolved (patch 2).
- The flexible array member had no test; one showed the struct row at

    0.00% while the member said 100.00% (patches 3-4).

- A struct pointer that -O2 keeps in a register was not resolved from its DWARF location (patch 5).
- --insn-stat was printed before the loop that accounts the samples, so --code-with-type showed zeros (patch 6).
- The libbfd probe printed a missing bfd.h error five times per build-test run (patch 7).
- FEATURE-DUMP didn't record llvm-perf and rust, disabling both in the build-test builds (patch 8).
- The Intel PT virtual LBR check lost every aux sample with a single data page (patch 9).
- The dlfilter test kept samples whose IP the kernel now zeroes on a userspace-to-kernel skid (patch 10).
- The LBR inline unwinding check failed instead of skipping when the AMD PMU rejects branch sampling (patch 11).

In a root run on this box the suite covered 49.16% of perf's 201,180 lines. The POLL_HUP tracepoint regression and the lock contention count fail in code this series does not change; the LBR inline unwinding check failed there and now skips.

The numbers above are from v1 and are slightly different here: the cs-etm patch was dropped and the issues reported in the v1 review were addressed, which changes both the tree and what the report counts.

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 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 4: the TUI browser counts flexible array accesses too.
- Patch 6: the stats test skips without libdw.
- Patches 9 and 11 (were 10 and 12): Fixes tags corrected.

Best regards,

- Arnaldo

Quoted 12 lines

Arnaldo Carvalho de Melo (11):
perf scripts: Add a coverage harness for perf
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

Thanks for working on this! Patches 2, 3 and 5 add small C programs compiled in a shell test. These are a pain for our CI framework; could we add them as perf test workloads?

Thanks,
Ian

Quoted 31 lines
 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                | 722 ++++++++++++++++++
 tools/perf/tests/make                         |   2 +-
 tools/perf/tests/shell/addr2line_inlines.sh   |   9 +-
 tools/perf/tests/shell/annotate_stats.sh      |  64 ++
 .../perf/tests/shell/data_type_flex_array.sh  | 142 ++++
 .../tests/shell/data_type_profiling_clang.sh  | 108 +++
 tools/perf/tests/shell/data_type_register.sh  | 120 +++
 tools/perf/tests/shell/script_dlfilter.sh     |   2 +-
 tools/perf/tests/shell/test_intel_pt.sh       |   9 +-
 tools/perf/ui/browsers/annotate-data.c        |   7 +-
 tools/perf/util/annotate-data.c               |  24 +-
 tools/perf/util/annotate-data.h               |   3 +
 tools/perf/util/dwarf-aux.c                   |  42 +-
 18 files changed, 1260 insertions(+), 24 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_profiling_clang.sh
 create mode 100755 tools/perf/tests/shell/data_type_register.sh

base-commit: cc905a18a647a8e3ad42cd1596baa0e08fba26eb
v1-head: 3f5465bea8f5a97a
--
2.56.0

#24 lore raw
Quoted 3 lines · Ian Rogers

Thanks for working on this! Patches 2, 3 and 5 add small C programs compiled in a shell test. These are a pain for our CI framework; could we add them as perf test workloads?

Sure, will do in V3.

- Arnaldo