Skip to contentSkip to conversation

Fixes for 6.8 PR1

PATCH Superseded Ian Rogers 2 participants 8 messages Jan 23, 2024 – Jan 24, 2024 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

cover Fixes for 6.8 PR1

Discovered some testing issues around perf list, perf script and perf daemon based on Linux 6.8-rc1. Some of the issues were discovered in the context of an Alderlake system.

Ian Rogers (5):
perf list: Switch error message to pr_err perf list: Add output file option
perf test: Workaround debug output in list test perf test: Fix script test for python being disabled perf test: Make daemon signal test less racy

 tools/perf/Documentation/perf-list.txt |   4 +
 tools/perf/builtin-list.c              | 211 +++++++++++++++----------
 tools/perf/tests/shell/daemon.sh       |  34 ++--
 tools/perf/tests/shell/list.sh         |  21 ++-
 tools/perf/tests/shell/script.sh       |   3 +-
 tools/perf/util/print-events.c         |   2 +-
 6 files changed, 177 insertions(+), 98 deletions(-)
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
author reviewer
#1 lore raw

PATCH 1/5 perf list: Switch error message to pr_err

Using printf can interrupt perf list output, use pr_err which can respect debug settings and the debug file.

---
 tools/perf/util/print-events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/print-events.c +1 -1
index b0fc48be623f..9e47712507cc 100644
@@ -66,7 +66,7 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus
 
 	put_tracing_file(events_path);
 	if (events_fd < 0) {
-		printf("Error: failed to open tracing events directory\n");
+		pr_err("Error: failed to open tracing events directory\n");
 		return;
 	}
 
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
author reviewer
#2 lore raw

PATCH 2/5 perf list: Add output file option

In reply to Ian Rogers

Add an option to write the perf list output to a specific file. This can avoid issues with debug output being written into the output stream.

---
 tools/perf/Documentation/perf-list.txt |   4 +
 tools/perf/builtin-list.c              | 211 +++++++++++++++----------
 2 files changed, 133 insertions(+), 82 deletions(-)
tools/perf/Documentation/perf-list.txt +4 -0
index 1b90575ee3c8..3b12595193c9 100644
@@ -47,6 +47,10 @@ Print PMU events and metrics limited to the specific PMU name.
 --json::
 Output in JSON format.
 
+-o::
+--output=::
+	Output file name. By default output is written to stdout.
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---------------
tools/perf/builtin-list.c +129 -82

443 lines not on this page · raw message

Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
author reviewer
#3 lore raw

PATCH 3/5 perf test: Workaround debug output in list test

In reply to Ian Rogers

Write the json output to a specific file to avoid debug output breaking it.

---
 tools/perf/tests/shell/list.sh | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
tools/perf/tests/shell/list.sh +18 -3
index 22b004f2b23e..8a868ae64560 100755
@@ -3,17 +3,32 @@
 # SPDX-License-Identifier: GPL-2.0
 
 set -e
-err=0
 
 shelldir=$(dirname "$0")
 # shellcheck source=lib/setup_python.sh
 . "${shelldir}"/lib/setup_python.sh
 
+list_output=$(mktemp /tmp/__perf_test.list_output.json.XXXXX)
+
+cleanup() {
+  rm -f "${list_output}"
+
+  trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+  cleanup
+  exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
 test_list_json() {
   echo "Json output test"
-  perf list -j | $PYTHON -m json.tool
+  perf list -j -o "${list_output}"
+  $PYTHON -m json.tool "${list_output}"
   echo "Json output test [Success]"
 }
 
 test_list_json
-exit $err
+cleanup
+exit 0
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
author reviewer
#4 lore raw

PATCH 4/5 perf test: Fix script test for python being disabled

In reply to Ian Rogers

"grep -cv" can exit with an error code that causes the "set -e" to abort the script. Switch to using the grep exit code in the if condition to avoid this.

---
 tools/perf/tests/shell/script.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/tests/shell/script.sh +1 -2
index 5ae7bd0031a8..b43077dbaf98 100755
@@ -36,8 +36,7 @@ test_db()
 	echo "DB test"
 
 	# Check if python script is supported
-	libpython=$(perf version --build-options | grep python | grep -cv OFF)
-	if [ "${libpython}" != "1" ] ; then
+        if perf version --build-options | grep python | grep -q OFF ; then
 		echo "SKIP: python scripting is not supported"
 		err=2
 		return
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
author reviewer
#5 lore raw

PATCH 5/5 perf test: Make daemon signal test less racy

In reply to Ian Rogers

The daemon signal test sends signals and then expects files to be written. It was observed on an Intel Alderlake that the signals were sent too quickly leading to the 3 expected files not appearing. To avoid this send the next signal only after the expected previous file has appeared. To avoid an infinite loop the number of retries is limited.

---
 tools/perf/tests/shell/daemon.sh | 34 ++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
tools/perf/tests/shell/daemon.sh +24 -10
index 4c598cfc5afa..de61e7898578 100755
@@ -414,16 +414,30 @@ EOF
 	# start daemon
 	daemon_start ${config} test
 
-	# send 2 signals
-	perf daemon signal --config ${config} --session test
-	perf daemon signal --config ${config}
-
-	# stop daemon
-	daemon_exit ${config}
-
-	# count is 2 perf.data for signals and 1 for perf record finished
-	count=`ls ${base}/session-test/*perf.data* | wc -l`
-	if [ ${count} -ne 3 ]; then
+        # send 2 signals then exit. Do this in a loop watching the number of
+        # files to avoid races. If the loop retries more than 600 times then
+        # give up.
+	local retries=0
+	local signals=0
+	local success=0
+	while [ ${retries} -lt 600 ] && [ ${success} -eq 0 ]; do
+		local files
+		files=`ls ${base}/session-test/*perf.data* | wc -l`
+		if [ ${signals} -eq 0 ]; then
+			perf daemon signal --config ${config} --session test
+			signals=1
+		elif [ ${signals} -eq 1 ] && [ $files -ge 1 ]; then
+			perf daemon signal --config ${config}
+			signals=2
+		elif [ ${signals} -eq 2 ] && [ $files -ge 2 ]; then
+			daemon_exit ${config}
+			signals=3
+		elif [ ${signals} -eq 3 ] && [ $files -ge 3 ]; then
+			success=1
+		fi
+		retries=$((${retries} +1))
+	done
+	if [ ${success} -eq 0 ]; then
 		error=1
 		echo "FAILED: perf data no generated"
 	fi
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
maintainer
#6 lore raw

Re: [PATCH v1 5/5] perf test: Make daemon signal test less racy

Quoted 30 lines · Ian Rogers

The daemon signal test sends signals and then expects files to be written. It was observed on an Intel Alderlake that the signals were sent too quickly leading to the 3 expected files not appearing. To avoid this send the next signal only after the expected previous file has appeared. To avoid an infinite loop the number of retries is limited.

---
 tools/perf/tests/shell/daemon.sh | 34 ++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
tools/perf/tests/shell/daemon.sh +0 -9
index 4c598cfc5afa..de61e7898578 100755
@@ -414,16 +414,30 @@ EOF
        # start daemon
        daemon_start ${config} test
 
-       # send 2 signals
-       perf daemon signal --config ${config} --session test
-       perf daemon signal --config ${config}
-
-       # stop daemon
-       daemon_exit ${config}
-
-       # count is 2 perf.data for signals and 1 for perf record finished
-       count=`ls ${base}/session-test/*perf.data* | wc -l`

tools/perf/tests/shell/daemon.sh EOF · line 425

Quoted 10 lines
tools/perf/tests/shell/daemon.sh +9 -1
-       if [ ${count} -ne 3 ]; then
+        # send 2 signals then exit. Do this in a loop watching the number of
+        # files to avoid races. If the loop retries more than 600 times then
+        # give up.
+       local retries=0
+       local signals=0
+       local success=0
+       while [ ${retries} -lt 600 ] && [ ${success} -eq 0 ]; do
+               local files
+               files=`ls ${base}/session-test/*perf.data* | wc -l`

Wouldn't it show error messages for 'file not found' for the first round? I think we can add '2> /dev/null' to suppress that.

Thanks,
Namhyung

Quoted 21 lines
tools/perf/tests/shell/daemon.sh +15 -1
+               if [ ${signals} -eq 0 ]; then
+                       perf daemon signal --config ${config} --session test
+                       signals=1
+               elif [ ${signals} -eq 1 ] && [ $files -ge 1 ]; then
+                       perf daemon signal --config ${config}
+                       signals=2
+               elif [ ${signals} -eq 2 ] && [ $files -ge 2 ]; then
+                       daemon_exit ${config}
+                       signals=3
+               elif [ ${signals} -eq 3 ] && [ $files -ge 3 ]; then
+                       success=1
+               fi
+               retries=$((${retries} +1))
+       done
+       if [ ${success} -eq 0 ]; then
                error=1
                echo "FAILED: perf data no generated"
        fi
--

2.43.0.429.g432eaa2c6b-goog

maintainer Acked-by on the v1 series
#7 lore raw
In reply to Ian Rogers

Hi Ian,

Quoted 11 lines · Ian Rogers

Discovered some testing issues around perf list, perf script and perf daemon based on Linux 6.8-rc1. Some of the issues were discovered in the context of an Alderlake system.

Ian Rogers (5):
perf list: Switch error message to pr_err perf list: Add output file option
perf test: Workaround debug output in list test perf test: Fix script test for python being disabled perf test: Make daemon signal test less racy

I only have a nitpick on patch 5.

Thanks,
Namhyung

Quoted 12 lines
 tools/perf/Documentation/perf-list.txt |   4 +
 tools/perf/builtin-list.c              | 211 +++++++++++++++----------
 tools/perf/tests/shell/daemon.sh       |  34 ++--
 tools/perf/tests/shell/list.sh         |  21 ++-
 tools/perf/tests/shell/script.sh       |   3 +-
 tools/perf/util/print-events.c         |   2 +-
 6 files changed, 177 insertions(+), 98 deletions(-)

--
2.43.0.429.g432eaa2c6b-goog