2022-09-06 11:15:35

by Carsten Haitzler

[permalink] [raw]
Subject: [PATCH v8 00/13] perf: test: Add trace data quality tests for CoreSight

From: Carsten Haitzler <[email protected]>

This series adds more test cases to perf test as well as new
infrastructure for testing coresight data quality to ensure the data
coming out of the kernel via perf actually contains useful information.

Signed-off-by: Carsten Haitzler <[email protected]>


Carsten Haitzler (13):
perf test: Add CoreSight shell lib shared code for future tests
perf test: Add build infra for perf test tools for CoreSight tests
perf test: Add asm pureloop test tool
perf test: Add asm pureloop test shell script
perf test: Add git ignore for perf data generated by the CoreSight
tests
perf test: Add memcpy thread test tool
perf test: Add memcpy thread test shell script
perf test: Add thread loop test tool
perf test: Add thread loop test shell scripts
perf test: Add unroll thread test tool
perf test: Add unroll thread test shell script
perf test: Add git ignore for tmp and output files of CoreSight tests
perf test: Add relevant documentation about CoreSight testing

.../trace/coresight/coresight-perf.rst | 158 ++++++++++++++++++
MAINTAINERS | 1 +
tools/perf/.gitignore | 6 +-
.../perf/Documentation/perf-arm-coresight.txt | 5 +
tools/perf/Makefile.config | 2 +
tools/perf/Makefile.perf | 15 +-
tools/perf/tests/shell/coresight/Makefile | 30 ++++
.../tests/shell/coresight/Makefile.miniconfig | 14 ++
.../tests/shell/coresight/asm_pure_loop.sh | 18 ++
.../shell/coresight/asm_pure_loop/.gitignore | 1 +
.../shell/coresight/asm_pure_loop/Makefile | 34 ++++
.../coresight/asm_pure_loop/asm_pure_loop.S | 28 ++++
.../shell/coresight/memcpy_thread/.gitignore | 1 +
.../shell/coresight/memcpy_thread/Makefile | 33 ++++
.../coresight/memcpy_thread/memcpy_thread.c | 79 +++++++++
.../shell/coresight/memcpy_thread_16k_10.sh | 18 ++
.../shell/coresight/thread_loop/.gitignore | 1 +
.../shell/coresight/thread_loop/Makefile | 33 ++++
.../shell/coresight/thread_loop/thread_loop.c | 86 ++++++++++
.../coresight/thread_loop_check_tid_10.sh | 19 +++
.../coresight/thread_loop_check_tid_2.sh | 19 +++
.../coresight/unroll_loop_thread/.gitignore | 1 +
.../coresight/unroll_loop_thread/Makefile | 33 ++++
.../unroll_loop_thread/unroll_loop_thread.c | 74 ++++++++
.../shell/coresight/unroll_loop_thread_10.sh | 18 ++
tools/perf/tests/shell/lib/coresight.sh | 132 +++++++++++++++
26 files changed, 855 insertions(+), 4 deletions(-)
create mode 100644 Documentation/trace/coresight/coresight-perf.rst
create mode 100644 tools/perf/Documentation/perf-arm-coresight.txt
create mode 100644 tools/perf/tests/shell/coresight/Makefile
create mode 100644 tools/perf/tests/shell/coresight/Makefile.miniconfig
create mode 100755 tools/perf/tests/shell/coresight/asm_pure_loop.sh
create mode 100644 tools/perf/tests/shell/coresight/asm_pure_loop/.gitignore
create mode 100644 tools/perf/tests/shell/coresight/asm_pure_loop/Makefile
create mode 100644 tools/perf/tests/shell/coresight/asm_pure_loop/asm_pure_loop.S
create mode 100644 tools/perf/tests/shell/coresight/memcpy_thread/.gitignore
create mode 100644 tools/perf/tests/shell/coresight/memcpy_thread/Makefile
create mode 100644 tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c
create mode 100755 tools/perf/tests/shell/coresight/memcpy_thread_16k_10.sh
create mode 100644 tools/perf/tests/shell/coresight/thread_loop/.gitignore
create mode 100644 tools/perf/tests/shell/coresight/thread_loop/Makefile
create mode 100644 tools/perf/tests/shell/coresight/thread_loop/thread_loop.c
create mode 100755 tools/perf/tests/shell/coresight/thread_loop_check_tid_10.sh
create mode 100755 tools/perf/tests/shell/coresight/thread_loop_check_tid_2.sh
create mode 100644 tools/perf/tests/shell/coresight/unroll_loop_thread/.gitignore
create mode 100644 tools/perf/tests/shell/coresight/unroll_loop_thread/Makefile
create mode 100644 tools/perf/tests/shell/coresight/unroll_loop_thread/unroll_loop_thread.c
create mode 100755 tools/perf/tests/shell/coresight/unroll_loop_thread_10.sh
create mode 100644 tools/perf/tests/shell/lib/coresight.sh

--
2.32.0


2022-09-06 11:17:47

by Carsten Haitzler

[permalink] [raw]
Subject: [PATCH v8 03/13] perf test: Add asm pureloop test tool

From: Carsten Haitzler <[email protected]>

Add test tool to be driven by further test scripts. This tool is pure
arm64 ASM with no libc usage to ensure it is the same exact
binary/code every time so it can also be re-used for many uses. It
just loops for a given fixed number of loops.

Signed-off-by: Carsten Haitzler <[email protected]>
---
tools/perf/tests/shell/coresight/Makefile | 3 +-
.../shell/coresight/asm_pure_loop/.gitignore | 1 +
.../shell/coresight/asm_pure_loop/Makefile | 34 +++++++++++++++++++
.../coresight/asm_pure_loop/asm_pure_loop.S | 28 +++++++++++++++
4 files changed, 65 insertions(+), 1 deletion(-)
create mode 100644 tools/perf/tests/shell/coresight/asm_pure_loop/.gitignore
create mode 100644 tools/perf/tests/shell/coresight/asm_pure_loop/Makefile
create mode 100644 tools/perf/tests/shell/coresight/asm_pure_loop/asm_pure_loop.S

diff --git a/tools/perf/tests/shell/coresight/Makefile b/tools/perf/tests/shell/coresight/Makefile
index 3b816bb4ced3..d4f868d55773 100644
--- a/tools/perf/tests/shell/coresight/Makefile
+++ b/tools/perf/tests/shell/coresight/Makefile
@@ -4,7 +4,8 @@ include ../../../../../tools/scripts/Makefile.include
include ../../../../../tools/scripts/Makefile.arch
include ../../../../../tools/scripts/utilities.mak

-SUBDIRS =
+SUBDIRS = \
+ asm_pure_loop

all: $(SUBDIRS)
$(SUBDIRS):
diff --git a/tools/perf/tests/shell/coresight/asm_pure_loop/.gitignore b/tools/perf/tests/shell/coresight/asm_pure_loop/.gitignore
new file mode 100644
index 000000000000..468673ac32e8
--- /dev/null
+++ b/tools/perf/tests/shell/coresight/asm_pure_loop/.gitignore
@@ -0,0 +1 @@
+asm_pure_loop
diff --git a/tools/perf/tests/shell/coresight/asm_pure_loop/Makefile b/tools/perf/tests/shell/coresight/asm_pure_loop/Makefile
new file mode 100644
index 000000000000..206849e92bc9
--- /dev/null
+++ b/tools/perf/tests/shell/coresight/asm_pure_loop/Makefile
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0
+# Carsten Haitzler <[email protected]>, 2021
+
+include ../Makefile.miniconfig
+
+# Binary to produce
+BIN=asm_pure_loop
+# Any linking/libraries needed for the binary - empty if none needed
+LIB=
+
+all: $(BIN)
+
+$(BIN): $(BIN).S
+ifdef CORESIGHT
+ifeq ($(ARCH),arm64)
+# Build line - this is raw asm with no libc to have an always exact binary
+ $(Q)$(CC) $(BIN).S -nostdlib -static -o $(BIN) $(LIB)
+endif
+endif
+
+install-tests: all
+ifdef CORESIGHT
+ifeq ($(ARCH),arm64)
+# Install the test tool in the right place
+ $(call QUIET_INSTALL, tests) \
+ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$(INSTDIR_SUB)/$(BIN)'; \
+ $(INSTALL) $(BIN) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$(INSTDIR_SUB)/$(BIN)/$(BIN)'
+endif
+endif
+
+clean:
+ $(Q)$(RM) -f $(BIN)
+
+.PHONY: all clean install-tests
diff --git a/tools/perf/tests/shell/coresight/asm_pure_loop/asm_pure_loop.S b/tools/perf/tests/shell/coresight/asm_pure_loop/asm_pure_loop.S
new file mode 100644
index 000000000000..75cf084a927d
--- /dev/null
+++ b/tools/perf/tests/shell/coresight/asm_pure_loop/asm_pure_loop.S
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Tamas Zsoldos <[email protected]>, 2021 */
+
+.globl _start
+_start:
+ mov x0, 0x0000ffff
+ mov x1, xzr
+loop:
+ nop
+ nop
+ cbnz x1, noskip
+ nop
+ nop
+ adrp x2, skip
+ add x2, x2, :lo12:skip
+ br x2
+ nop
+ nop
+noskip:
+ nop
+ nop
+skip:
+ sub x0, x0, 1
+ cbnz x0, loop
+
+ mov x0, #0
+ mov x8, #93 // __NR_exit syscall
+ svc #0
--
2.32.0

2022-09-06 11:18:33

by Carsten Haitzler

[permalink] [raw]
Subject: [PATCH v8 05/13] perf test: Add git ignore for perf data generated by the CoreSight tests

From: Carsten Haitzler <[email protected]>

Ignore perf output data files generated by perf tests for cleaner
git status.

Signed-off-by: Carsten Haitzler <[email protected]>
---
tools/perf/.gitignore | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/.gitignore b/tools/perf/.gitignore
index 4b9c71faa01a..faa23b5d32f5 100644
--- a/tools/perf/.gitignore
+++ b/tools/perf/.gitignore
@@ -15,8 +15,8 @@ perf*.1
perf*.xml
perf*.html
common-cmds.h
-perf.data
-perf.data.old
+perf*.data
+perf*.data.old
output.svg
perf-archive
perf-iostat
--
2.32.0

2022-09-06 11:34:12

by Carsten Haitzler

[permalink] [raw]
Subject: [PATCH v8 01/13] perf test: Add CoreSight shell lib shared code for future tests

From: Carsten Haitzler <[email protected]>

This adds a library of shell "code" to be shared and used by future
tests that target quality testing for Arm CoreSight support in perf
and the Linux kernel.

Signed-off-by: Carsten Haitzler <[email protected]>
---
tools/perf/tests/shell/lib/coresight.sh | 132 ++++++++++++++++++++++++
1 file changed, 132 insertions(+)
create mode 100644 tools/perf/tests/shell/lib/coresight.sh

diff --git a/tools/perf/tests/shell/lib/coresight.sh b/tools/perf/tests/shell/lib/coresight.sh
new file mode 100644
index 000000000000..45a1477256b6
--- /dev/null
+++ b/tools/perf/tests/shell/lib/coresight.sh
@@ -0,0 +1,132 @@
+# SPDX-License-Identifier: GPL-2.0
+# Carsten Haitzler <[email protected]>, 2021
+
+# This is sourced from a driver script so no need for #!/bin... etc. at the
+# top - the assumption below is that it runs as part of sourcing after the
+# test sets up some basic env vars to say what it is.
+
+# This currently works with ETMv4 / ETF not any other packet types at thi
+# point. This will need changes if that changes.
+
+# perf record options for the perf tests to use
+PERFRECMEM="-m ,16M"
+PERFRECOPT="$PERFRECMEM -e cs_etm//u"
+
+TOOLS=$(dirname $0)
+DIR="$TOOLS/$TEST"
+BIN="$DIR/$TEST"
+# If the test tool/binary does not exist and is executable then skip the test
+if ! test -x "$BIN"; then exit 2; fi
+DATD="."
+# If the data dir env is set then make the data dir use that instead of ./
+if test -n "$PERF_TEST_CORESIGHT_DATADIR"; then
+ DATD="$PERF_TEST_CORESIGHT_DATADIR";
+fi
+# If the stat dir env is set then make the data dir use that instead of ./
+STATD="."
+if test -n "$PERF_TEST_CORESIGHT_STATDIR"; then
+ STATD="$PERF_TEST_CORESIGHT_STATDIR";
+fi
+
+# Called if the test fails - error code 1
+err() {
+ echo "$1"
+ exit 1
+}
+
+# Check that some statistics from our perf
+check_val_min() {
+ STATF="$4"
+ if test "$2" -lt "$3"; then
+ echo ", FAILED" >> "$STATF"
+ err "Sanity check number of $1 is too low ($2 < $3)"
+ fi
+}
+
+perf_dump_aux_verify() {
+ # Some basic checking that the AUX chunk contains some sensible data
+ # to see that we are recording something and at least a minimum
+ # amount of it. We should almost always see Fn packets in just about
+ # anything but certainly we will see some trace info and async
+ # packets
+ DUMP="$DATD/perf-tmp-aux-dump.txt"
+ perf report --stdio --dump -i "$1" | \
+ grep -o -e I_ATOM_F -e I_ASYNC -e I_TRACE_INFO > "$DUMP"
+ # Simply count how many of these packets we find to see that we are
+ # producing a reasonable amount of data - exact checks are not sane
+ # as this is a lossy process where we may lose some blocks and the
+ # compiler may produce different code depending on the compiler and
+ # optimization options, so this is rough just to see if we're
+ # either missing almost all the data or all of it
+ ATOM_FX_NUM=`grep I_ATOM_F "$DUMP" | wc -l`
+ ASYNC_NUM=`grep I_ASYNC "$DUMP" | wc -l`
+ TRACE_INFO_NUM=`grep I_TRACE_INFO "$DUMP" | wc -l`
+ rm -f "$DUMP"
+
+ # Arguments provide minimums for a pass
+ CHECK_FX_MIN="$2"
+ CHECK_ASYNC_MIN="$3"
+ CHECK_TRACE_INFO_MIN="$4"
+
+ # Write out statistics, so over time you can track results to see if
+ # there is a pattern - for example we have less "noisy" results that
+ # produce more consistent amounts of data each run, to see if over
+ # time any techinques to minimize data loss are having an effect or
+ # not
+ STATF="$STATD/stats-$TEST-$DATV.csv"
+ if ! test -f "$STATF"; then
+ echo "ATOM Fx Count, Minimum, ASYNC Count, Minimum, TRACE INFO Count, Minimum" > "$STATF"
+ fi
+ echo -n "$ATOM_FX_NUM, $CHECK_FX_MIN, $ASYNC_NUM, $CHECK_ASYNC_MIN, $TRACE_INFO_NUM, $CHECK_TRACE_INFO_MIN" >> "$STATF"
+
+ # Actually check to see if we passed or failed.
+ check_val_min "ATOM_FX" "$ATOM_FX_NUM" "$CHECK_FX_MIN" "$STATF"
+ check_val_min "ASYNC" "$ASYNC_NUM" "$CHECK_ASYNC_MIN" "$STATF"
+ check_val_min "TRACE_INFO" "$TRACE_INFO_NUM" "$CHECK_TRACE_INFO_MIN" "$STATF"
+ echo ", Ok" >> "$STATF"
+}
+
+perf_dump_aux_tid_verify() {
+ # Specifically crafted test will produce a list of Tread ID's to
+ # stdout that need to be checked to see that they have had trace
+ # info collected in AUX blocks in the perf data. This will go
+ # through all the TID's that are listed as CID=0xabcdef and see
+ # that all the Thread IDs the test tool reports are in the perf
+ # data AUX chunks
+
+ # The TID test tools will print a TID per stdout line that are being
+ # tested
+ TIDS=`cat "$2"`
+ # Scan the perf report to find the TIDs that are actually CID in hex
+ # and build a list of the ones found
+ FOUND_TIDS=`perf report --stdio --dump -i "$1" | \
+ grep -o "CID=0x[0-9a-z]\+" | sed 's/CID=//g' | \
+ uniq | sort | uniq`
+ # No CID=xxx found - maybe your kernel is reporting these as
+ # VMID=xxx so look there
+ if test -z "$FOUND_TIDS"; then
+ FOUND_TIDS=`perf report --stdio --dump -i "$1" | \
+ grep -o "VMID=0x[0-9a-z]\+" | sed 's/VMID=//g' | \
+ uniq | sort | uniq`
+ fi
+
+ # Iterate over the list of TIDs that the test says it has and find
+ # them in the TIDs found in the perf report
+ MISSING=""
+ for TID2 in $TIDS; do
+ FOUND=""
+ for TIDHEX in $FOUND_TIDS; do
+ TID=`printf "%i" $TIDHEX`
+ if test "$TID" -eq "$TID2"; then
+ FOUND="y"
+ break
+ fi
+ done
+ if test -z "$FOUND"; then
+ MISSING="$MISSING $TID"
+ fi
+ done
+ if test -n "$MISSING"; then
+ err "Thread IDs $MISSING not found in perf AUX data"
+ fi
+}
--
2.32.0