Skip to contentSkip to conversation

perf test: "object code reading" test fixes

PATCH Applied James Clark 4 participants 8 messages Apr 10, 2024 perf events

lore
Share & tools
lore
#0 lore raw

v2 cover perf test: "object code reading" test fixes

A few fixes around the object code reading test. The first patch appears to be unrelated, but in this case the data symbol test is broken on Arm N1 by the second commit.

Changes since V1:
* Put data symbol test fix first so that bisecting still works on N1
* Instead of skipping "test data symbol" on N1, add some noise into the loop.
* Add a commit to replace the only usage of lscpu in the tests with uname

James Clark (4):
perf tests: Make "test data symbol" more robust on Neoverse N1 perf tests: Apply attributes to all events in object code reading test perf map: Remove kernel map before updating start and end addresses perf tests: Remove dependency on lscpu

 tools/perf/tests/code-reading.c                 | 10 +++++-----
 tools/perf/tests/shell/test_arm_callgraph_fp.sh |  4 +++-
 tools/perf/tests/workloads/datasym.c            | 16 ++++++++++++++++
 tools/perf/util/machine.c                       |  2 +-
 4 files changed, 25 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/4 perf tests: Make "test data symbol" more robust on Neoverse N1

To prevent anyone from seeing a test failure appear as a regression and thinking that it was caused by their code change, insert some noise into the loop which makes it immune to sampling bias issues (errata 1694299).

The "test data symbol" test can fail with any unrelated change that shifts the loop into an unfortunate position in the Perf binary which is almost impossible to debug as the root cause of the test failure. Ultimately it's caused by the referenced errata.

Fixes 60abedb8aa90 ("perf test: Introduce script for data symbol testing")
---
 tools/perf/tests/workloads/datasym.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tools/perf/tests/workloads/datasym.c +16 -0
index ddd40bc63448..8e08fc75a973 100644
@@ -16,6 +16,22 @@ static int datasym(int argc __maybe_unused, const char **argv __maybe_unused)
 {
 	for (;;) {
 		buf1.data1++;
+		if (buf1.data1 == 123) {
+			/*
+			 * Add some 'noise' in the loop to work around errata
+			 * 1694299 on Arm N1.
+			 *
+			 * Bias exists in SPE sampling which can cause the load
+			 * and store instructions to be skipped entirely. This
+			 * comes and goes randomly depending on the offset the
+			 * linker places the datasym loop at in the Perf binary.
+			 * With an extra branch in the middle of the loop that
+			 * isn't always taken, the instruction stream is no
+			 * longer a continuous repeating pattern that interacts
+			 * badly with the bias.
+			 */
+			buf1.data1++;
+		}
 		buf1.data2 += buf1.data1;
 	}
 	return 0;
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/4 perf tests: Apply attributes to all events in object code reading test

In reply to James Clark

PERF_PMU_CAP_EXTENDED_HW_TYPE results in multiple events being opened on heterogeneous systems. Currently this test only sets its required attributes on the first event. Not disabling enable_on_exec on the other events causes the test to fail because the forked objdump processes are sampled. No tracking event is opened so Perf only knows about its own mappings causing the objdump samples to give the following error:

  $ perf test -vvv "object code reading"

Reading object code for memory address: 0xffff9aaa55ec thread__find_map failed
---- end(-1) ----
24: Object code reading : FAILED!

Fixes 251aa040244a ("perf parse-events: Wildcard most "numeric" events")
---
 tools/perf/tests/code-reading.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/tests/code-reading.c +5 -5
index 7a3a7bbbec71..29d2f3ee4e10 100644
@@ -637,11 +637,11 @@ static int do_test_code_reading(bool try_kcore)
 
 		evlist__config(evlist, &opts, NULL);
 
-		evsel = evlist__first(evlist);
-
-		evsel->core.attr.comm = 1;
-		evsel->core.attr.disabled = 1;
-		evsel->core.attr.enable_on_exec = 0;
+		evlist__for_each_entry(evlist, evsel) {
+			evsel->core.attr.comm = 1;
+			evsel->core.attr.disabled = 1;
+			evsel->core.attr.enable_on_exec = 0;
+		}
 
 		ret = evlist__open(evlist);
 		if (ret < 0) {
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/4 perf map: Remove kernel map before updating start and end addresses

In reply to James Clark

In a debug build there is validation that mmap lists are sorted when taking a lock. In machine__update_kernel_mmap() the start and end addresses are updated resulting in an unsorted list before the map is removed from the list. When the map is removed, the lock is taken which triggers the validation and the failure:

  $ perf test "object code reading"
  --- start ---
  perf: util/maps.c:88: check_invariants: Assertion `map__start(prev) <= map__start(map)' failed.
  Aborted

Fix it by updating the addresses after removal, but before insertion. The bug depends on the ordering and type of debug info on the system and doesn't reproduce everywhere.

Fixes 659ad3492b91 ("perf maps: Switch from rbtree to lazily sorted array for addresses")
---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/machine.c +1 -1
index 5eb9044bc223..a26c8bea58d0 100644
@@ -1549,8 +1549,8 @@ static int machine__update_kernel_mmap(struct machine *machine,
 	updated = map__get(orig);
 
 	machine->vmlinux_map = updated;
-	machine__set_kernel_mmap(machine, start, end);
 	maps__remove(machine__kernel_maps(machine), orig);
+	machine__set_kernel_mmap(machine, start, end);
 	err = maps__insert(machine__kernel_maps(machine), updated);
 	map__put(orig);
 
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 4/4 perf tests: Remove dependency on lscpu

In reply to James Clark

This check can be done with uname which is more portable. At the same time re-arrange it into a standard if statement so that it's more readable.

---
 tools/perf/tests/shell/test_arm_callgraph_fp.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/tests/shell/test_arm_callgraph_fp.sh +3 -1
index 83b53591b1ea..61898e256616 100755
@@ -6,7 +6,9 @@ shelldir=$(dirname "$0")
 # shellcheck source=lib/perf_has_symbol.sh
 . "${shelldir}"/lib/perf_has_symbol.sh
 
-lscpu | grep -q "aarch64" || exit 2
+if [ "$(uname -m)" != "aarch64" ]; then
+	exit 2
+fi
 
 if perf version --build-options | grep HAVE_DWARF_UNWIND_SUPPORT | grep -q OFF
 then
Signature · 1 line
2.34.1
reviewer Reviewed-by on the v2 series
#5 lore raw
In reply to James Clark
Quoted 12 lines · James Clark

A few fixes around the object code reading test. The first patch appears to be unrelated, but in this case the data symbol test is broken on Arm N1 by the second commit.

Changes since V1:
* Put data symbol test fix first so that bisecting still works on N1
* Instead of skipping "test data symbol" on N1, add some noise into the loop.
* Add a commit to replace the only usage of lscpu in the tests with uname

Quoted 5 lines

James Clark (4):
perf tests: Make "test data symbol" more robust on Neoverse N1 perf tests: Apply attributes to all events in object code reading test perf map: Remove kernel map before updating start and end addresses perf tests: Remove dependency on lscpu

Thanks,
Ian

Quoted 9 lines
 tools/perf/tests/code-reading.c                 | 10 +++++-----
 tools/perf/tests/shell/test_arm_callgraph_fp.sh |  4 +++-
 tools/perf/tests/workloads/datasym.c            | 16 ++++++++++++++++
 tools/perf/util/machine.c                       |  2 +-
 4 files changed, 25 insertions(+), 7 deletions(-)

--
2.34.1

maintainer Applied
#6 lore raw
Quoted 13 lines · Ian Rogers
Quoted 12 lines · James Clark

A few fixes around the object code reading test. The first patch appears to be unrelated, but in this case the data symbol test is broken on Arm N1 by the second commit.

Changes since V1:
* Put data symbol test fix first so that bisecting still works on N1
* Instead of skipping "test data symbol" on N1, add some noise into the loop.
* Add a commit to replace the only usage of lscpu in the tests with uname

Quoted 7 lines
Quoted 5 lines

James Clark (4):
perf tests: Make "test data symbol" more robust on Neoverse N1 perf tests: Apply attributes to all events in object code reading test perf map: Remove kernel map before updating start and end addresses perf tests: Remove dependency on lscpu

Thanks, applied to perf-tools-next,

- Arnaldo

maintainer Acked-by on the v2 series
#7 lore raw
In reply to James Clark

Hello,

Quoted 12 lines · James Clark

A few fixes around the object code reading test. The first patch appears to be unrelated, but in this case the data symbol test is broken on Arm N1 by the second commit.

Changes since V1:
* Put data symbol test fix first so that bisecting still works on N1
* Instead of skipping "test data symbol" on N1, add some noise into the loop.
* Add a commit to replace the only usage of lscpu in the tests with uname

Quoted 5 lines

James Clark (4):
perf tests: Make "test data symbol" more robust on Neoverse N1 perf tests: Apply attributes to all events in object code reading test perf map: Remove kernel map before updating start and end addresses perf tests: Remove dependency on lscpu

Thanks,
Namhyung