All of lore.kernel.org
 help / color / mirror / Atom feed
From: carsten.haitzler@foss.arm.com
To: linux-perf-users@vger.kernel.org
Subject: [PATCH 04/12] perf test: Add beginning of test infra + test to exercise coresight
Date: Wed, 15 Dec 2021 16:22:42 +0000	[thread overview]
Message-ID: <20211215162250.70322-4-carsten.haitzler@foss.arm.com> (raw)
In-Reply-To: <20211215162250.70322-1-carsten.haitzler@foss.arm.com>

From: Carsten Haitzler <carsten.haitzler@arm.com>

This adds the initial test harness to run perf record and examine the
resuling output when coresight is enabled on arm64 and check the
resulting quality of the output as part of perf test.

Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
---
 MAINTAINERS                                   |   3 +
 tools/perf/Makefile.perf                      |  14 +-
 .../tests/shell/coresight_asm_pure_loop.sh    |  18 +++
 tools/perf/tests/shell/lib/coresight.sh       | 130 ++++++++++++++++++
 tools/perf/tests/shell/tools/Makefile         |  26 ++++
 .../perf/tests/shell/tools/coresight/Makefile |  27 ++++
 .../shell/tools/coresight/Makefile.miniconfig |  23 ++++
 .../tools/coresight/asm_pure_loop/Makefile    |  30 ++++
 .../coresight/asm_pure_loop/asm_pure_loop.S   |  28 ++++
 9 files changed, 297 insertions(+), 2 deletions(-)
 create mode 100755 tools/perf/tests/shell/coresight_asm_pure_loop.sh
 create mode 100644 tools/perf/tests/shell/lib/coresight.sh
 create mode 100644 tools/perf/tests/shell/tools/Makefile
 create mode 100644 tools/perf/tests/shell/tools/coresight/Makefile
 create mode 100644 tools/perf/tests/shell/tools/coresight/Makefile.miniconfig
 create mode 100644 tools/perf/tests/shell/tools/coresight/asm_pure_loop/Makefile
 create mode 100644 tools/perf/tests/shell/tools/coresight/asm_pure_loop/asm_pure_loop.S

diff --git a/MAINTAINERS b/MAINTAINERS
index 13f9a84a617e..d46e8469c467 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1894,6 +1894,9 @@ F:	tools/perf/arch/arm/util/auxtrace.c
 F:	tools/perf/arch/arm/util/cs-etm.c
 F:	tools/perf/arch/arm/util/cs-etm.h
 F:	tools/perf/arch/arm/util/pmu.c
+F:	tools/perf/tests/shell/coresight_*
+F:	tools/perf/tests/shell/tools/Makefile
+F:	tools/perf/tests/shell/tools/coresight/*
 F:	tools/perf/util/cs-etm-decoder/*
 F:	tools/perf/util/cs-etm.*
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 80522bcfafe0..26467a2c71f4 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -630,7 +630,15 @@ sync_file_range_tbls := $(srctree)/tools/perf/trace/beauty/sync_file_range.sh
 $(sync_file_range_arrays): $(linux_uapi_dir)/fs.h $(sync_file_range_tbls)
 	$(Q)$(SHELL) '$(sync_file_range_tbls)' $(linux_uapi_dir) > $@
 
-all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS)
+TESTS_TOOLS_DIR := $(srctree)/tools/perf/tests/shell/tools
+
+tests-tools-targets: FORCE
+	$(Q)$(MAKE) -C $(TESTS_TOOLS_DIR)
+
+tests-tools-targets-clean:
+	$(Q)$(MAKE) -C $(TESTS_TOOLS_DIR) clean
+
+all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) tests-tools-targets
 
 # Create python binding output directory if not already present
 _dummy := $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python')
@@ -1020,6 +1028,7 @@ install-tests: all install-gtk
 		$(INSTALL) tests/shell/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
 		$(INSTALL) tests/shell/lib/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'
+	$(Q)$(MAKE) -C tests/shell/tools install-tests
 
 install-bin: install-tools install-tests install-traceevent-plugins
 
@@ -1088,7 +1097,7 @@ endif # BUILD_BPF_SKEL
 bpf-skel-clean:
 	$(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS)
 
-clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean
+clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-tools-targets-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf-iostat $(LANG_BINDINGS)
 	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
@@ -1155,5 +1164,6 @@ FORCE:
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
 .PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope FORCE prepare
 .PHONY: libtraceevent_plugins archheaders
+.PHONY: $(TESTS_TOOLS_TARGETS)
 
 endif # force_fixdep
diff --git a/tools/perf/tests/shell/coresight_asm_pure_loop.sh b/tools/perf/tests/shell/coresight_asm_pure_loop.sh
new file mode 100755
index 000000000000..542d4a37e349
--- /dev/null
+++ b/tools/perf/tests/shell/coresight_asm_pure_loop.sh
@@ -0,0 +1,18 @@
+#!/bin/sh -e
+# Coresight / ASM Pure Loop
+
+# SPDX-License-Identifier: GPL-2.0
+# Carsten Haitzler <carsten.haitzler@arm.com>, 2021
+
+TEST="asm_pure_loop"
+. $(dirname $0)/lib/coresight.sh
+ARGS=""
+DATV="out"
+DATA="$DATD/perf-$TEST-$DATV.data"
+
+perf record $PERFRECOPT -o "$DATA" "$BIN" $ARGS
+
+perf_dump_aux_verify "$DATA" 2601 334 334
+
+err=$?
+exit $err
diff --git a/tools/perf/tests/shell/lib/coresight.sh b/tools/perf/tests/shell/lib/coresight.sh
new file mode 100644
index 000000000000..cd6c1283e6f5
--- /dev/null
+++ b/tools/perf/tests/shell/lib/coresight.sh
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: GPL-2.0
+# Carsten Haitzler <carsten.haitzler@arm.com>, 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.
+
+# perf record options for the perf tests to use
+PERFRECMEM="-m ,128M"
+PERFRECOPT="$PERFRECMEM -e cs_etm//u"
+
+# These tests need to be run as root or coresight won't allow large buffers
+# and will not collect proper data
+UID=`id -u`
+if test "$UID" -ne 0; then
+	echo "Not running as root... skip"
+	exit 2
+fi
+
+TOOLS=$(dirname $0)/tools
+DIR="$TOOLS/coresight/$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 2
+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 F3 atoms in just about
+	# anything but certainly we will see some trace info and async atom
+	# chunks.
+	DUMP="$DATD/perf-tmp-aux-dump.txt"
+	perf report --stdio --dump -i "$1" | \
+		grep -o -e I_ATOM_F3 -e I_ASYNC -e I_TRACE_INFO > "$DUMP"
+	# Simply count how many of these atoms 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_F3_NUM=`grep I_ATOM_F3 "$DUMP" | wc -l`
+	ATOM_ASYNC_NUM=`grep I_ASYNC "$DUMP" | wc -l`
+	ATOM_TRACE_INFO_NUM=`grep I_TRACE_INFO "$DUMP" | wc -l`
+	rm -f "$DUMP"
+
+	# Arguments provide minimums for a pass
+	CHECK_F3_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 F3 Count, Minimum, ATOM ASYNC Count, Minimum, TRACE INFO Count, Minimum" > "$STATF"
+	fi
+	echo -n "$ATOM_F3_NUM, $CHECK_F3_MIN, $ATOM_ASYNC_NUM, $CHECK_ASYNC_MIN, $ATOM_TRACE_INFO_NUM, $CHECK_TRACE_INFO_MIN" >> "$STATF"
+
+	# Actually check to see if we passed or failed.
+	check_val_min "ATOM_F3" "$ATOM_F3_NUM" "$CHECK_F3_MIN" "$STATF"
+	check_val_min "ASYNC" "$ATOM_ASYNC_NUM" "$CHECK_ASYNC_MIN" "$STATF"
+	check_val_min "TRACE_INFO" "$ATOM_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`
+
+	# 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
+}
diff --git a/tools/perf/tests/shell/tools/Makefile b/tools/perf/tests/shell/tools/Makefile
new file mode 100644
index 000000000000..c7ada20922fd
--- /dev/null
+++ b/tools/perf/tests/shell/tools/Makefile
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Carsten Haitzler <carsten.haitzler@arm.com>, 2021
+include ../../../../../tools/scripts/Makefile.include
+include ../../../../../tools/scripts/Makefile.arch
+include ../../../../../tools/scripts/utilities.mak
+
+SUBDIRS = \
+	coresight
+
+all: $(SUBDIRS)
+$(SUBDIRS):
+	$(Q)$(MAKE) -C $@
+
+INSTALLDIRS = $(SUBDIRS:%=install-%)
+
+install-tests: all $(INSTALLDIRS)
+$(INSTALLDIRS):
+	$(Q)$(MAKE) -C $(@:install-%=%) install-tests
+
+CLEANDIRS = $(SUBDIRS:%=clean-%)
+
+clean: $(CLEANDIRS)
+$(CLEANDIRS):
+	$(Q)$(MAKE) -C $(@:clean-%=%) O=$(OUTPUT) clean >/dev/null
+
+.PHONY: all clean install-tests $(SUBDIRS) $(CLEANDIRS) $(INSTALLDIRS)
diff --git a/tools/perf/tests/shell/tools/coresight/Makefile b/tools/perf/tests/shell/tools/coresight/Makefile
new file mode 100644
index 000000000000..723006ea827c
--- /dev/null
+++ b/tools/perf/tests/shell/tools/coresight/Makefile
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Carsten Haitzler <carsten.haitzler@arm.com>, 2021
+include ../../../../../../tools/scripts/Makefile.include
+include ../../../../../../tools/scripts/Makefile.arch
+include ../../../../../../tools/scripts/utilities.mak
+
+SUBDIRS = \
+	asm_pure_loop
+
+all: $(SUBDIRS)
+$(SUBDIRS):
+	$(Q)$(MAKE) -C $@
+
+INSTALLDIRS = $(SUBDIRS:%=install-%)
+
+install-tests: $(INSTALLDIRS)
+$(INSTALLDIRS):
+	$(Q)$(MAKE) -C $(@:install-%=%) install-tests
+
+CLEANDIRS = $(SUBDIRS:%=clean-%)
+
+clean: $(CLEANDIRS)
+$(CLEANDIRS):
+	$(Q)$(MAKE) -C $(@:clean-%=%) clean >/dev/null
+
+.PHONY: all clean $(SUBDIRS) $(CLEANDIRS) $(INSTALLDIRS)
+
diff --git a/tools/perf/tests/shell/tools/coresight/Makefile.miniconfig b/tools/perf/tests/shell/tools/coresight/Makefile.miniconfig
new file mode 100644
index 000000000000..cedd26c6a0eb
--- /dev/null
+++ b/tools/perf/tests/shell/tools/coresight/Makefile.miniconfig
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Carsten Haitzler <carsten.haitzler@arm.com>, 2021
+
+ifndef DESTDIR
+prefix ?= $(HOME)
+endif
+
+DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
+perfexecdir = libexec/perf-core
+perfexec_instdir = $(perfexecdir)
+
+ifneq ($(filter /%,$(firstword $(perfexecdir))),)
+perfexec_instdir = $(perfexecdir)
+else
+perfexec_instdir = $(prefix)/$(perfexecdir)
+endif
+
+perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
+INSTALL = install
+
+include ../../../../../../scripts/Makefile.include
+include ../../../../../../scripts/Makefile.arch
+include ../../../../../../scripts/utilities.mak
diff --git a/tools/perf/tests/shell/tools/coresight/asm_pure_loop/Makefile b/tools/perf/tests/shell/tools/coresight/asm_pure_loop/Makefile
new file mode 100644
index 000000000000..10c5a60cb71c
--- /dev/null
+++ b/tools/perf/tests/shell/tools/coresight/asm_pure_loop/Makefile
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: GPL-2.0
+# Carsten Haitzler <carsten.haitzler@arm.com>, 2021
+
+include ../Makefile.miniconfig
+
+BIN=asm_pure_loop
+LIB=
+
+all: $(BIN)
+
+$(BIN): $(BIN).S
+ifdef CORESIGHT
+ifeq ($(ARCH),arm64)
+	$(Q)$(CC) $(BIN).S -nostdlib -static -o $(BIN) $(LIB)
+endif
+endif
+
+install-tests: all
+ifdef CORESIGHT
+ifeq ($(ARCH),arm64)
+	$(call QUIET_INSTALL, tests) \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/tools/$(BIN)'; \
+		$(INSTALL) $(BIN) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/tools/$(BIN)/$(BIN)'
+endif
+endif
+
+clean:
+	$(Q)$(RM) -f $(BIN)
+
+.PHONY: all clean install-tests
diff --git a/tools/perf/tests/shell/tools/coresight/asm_pure_loop/asm_pure_loop.S b/tools/perf/tests/shell/tools/coresight/asm_pure_loop/asm_pure_loop.S
new file mode 100644
index 000000000000..262876451021
--- /dev/null
+++ b/tools/perf/tests/shell/tools/coresight/asm_pure_loop/asm_pure_loop.S
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Tamas Zsoldos <tamas.zsoldos@arm.com>, 2021 */
+
+.globl _start
+_start:
+	mov	x0, 0x000fffff
+	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


  parent reply	other threads:[~2021-12-15 16:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15 16:22 [PATCH 01/12] perf test: Shell - Limit to only run executable scripts in tests carsten.haitzler
2021-12-15 16:22 ` [PATCH 02/12] perf test: Shell - only run .sh shell files to skip other files carsten.haitzler
2021-12-15 16:22 ` [PATCH 03/12] perf test: Use 3 digits for test numbering now we can have more tests carsten.haitzler
2021-12-15 16:22 ` carsten.haitzler [this message]
2021-12-15 16:22 ` [PATCH 05/12] perf test: Add coresight test to check all threads get some data logged carsten.haitzler
2021-12-15 16:22 ` [PATCH 06/12] perf test: Add tests to re-use the thread loop test to check aux data carsten.haitzler
2021-12-15 16:22 ` [PATCH 07/12] perf test: Add simple bubblesort test for coresight " carsten.haitzler
2021-12-15 16:22 ` [PATCH 09/12] perf test: Add add memcpy test for coresight quality checking carsten.haitzler
2021-12-15 16:22 ` [PATCH 10/12] perf test: Add threaded memcpy tests to check coresight aux data carsten.haitzler
2021-12-15 16:22 ` [PATCH 11/12] perf test: Add unrolled loop tests for " carsten.haitzler
2021-12-15 16:22 ` [PATCH 12/12] perf test: Add docs for coresight and related tests carsten.haitzler
  -- strict thread matches above, loose matches on Subject: below --
2021-12-15 16:03 [PATCH 01/12] perf test: Shell - Limit to only run executable scripts in tests carsten.haitzler
2021-12-15 16:03 ` [PATCH 04/12] perf test: Add beginning of test infra + test to exercise coresight carsten.haitzler
2021-12-21 15:03   ` Leo Yan
2021-12-21 20:40     ` Arnaldo Carvalho de Melo
2022-01-04 15:15       ` Carsten Haitzler
2022-01-04 15:14     ` Carsten Haitzler
2022-01-19 16:58   ` James Clark
2022-02-04 10:21   ` Mike Leach
2021-12-15 12:53 [PATCH 01/12] perf test: Shell - Limit to only run executable scripts in tests carsten.haitzler
2021-12-15 12:54 ` [PATCH 04/12] perf test: Add beginning of test infra + test to exercise coresight carsten.haitzler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211215162250.70322-4-carsten.haitzler@foss.arm.com \
    --to=carsten.haitzler@foss.arm.com \
    --cc=linux-perf-users@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.