We need a simple method to test Perf with Arm CoreSight drivers, this could be used for smoke testing when new patch is coming for perf or CoreSight drivers, and we also can use the test to confirm if the CoreSight has been enabled successfully on new platforms.
This patch introduces the shell script record+script_arm_cs_etm.sh, it's under the 'pert test' framework. Simply to say, the testing rationale is source oriented testing, it traverses every source (now only refers to ETM device) and test its all possible sinks. To search the complete paths from one specific source to its sinks, this patch relies on the sysfs '/sys/bus/coresight/devices/devX/out:Y' for depth-first search (DFS) for iteration connected device nodes, if the output device is detected as one of ETR, ETF, or ETB types it will verify trace data recording and decoding.
If any device fails for the testing, the test will report failure and directly exit with error. This test will be only applied on the platform with PMU event 'cs_etm//', otherwise will skip the testing.
Below is detailed usage for it:
# cd $linux/tools/perf -> This is important so can use shell script # perf test list
[...]
61: Check open filename arg using perf trace + vfs_getname 62: Check Arm CoreSight trace data recording and branch samples 63: Add vfs_getname probe to get syscall args filenames 64: Use vfs_getname probe to get syscall args filenames
# perf test 62
62: Check Arm CoreSight trace data recording and branch samples: Ok
Signed-off-by: Leo Yan leo.yan@linaro.org --- .../tests/shell/record+script_arm_cs_etm.sh | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 tools/perf/tests/shell/record+script_arm_cs_etm.sh
diff --git a/tools/perf/tests/shell/record+script_arm_cs_etm.sh b/tools/perf/tests/shell/record+script_arm_cs_etm.sh new file mode 100755 index 000000000000..108604984867 --- /dev/null +++ b/tools/perf/tests/shell/record+script_arm_cs_etm.sh @@ -0,0 +1,81 @@ +#!/bin/sh +# Check Arm CoreSight trace data recording and branch samples + +# Uses the 'perf record' to record trace data with Arm CoreSight ETR as the +# output, then checks if there have any branch samples are generated by +# CoreSight with 'perf script' command. + +# Leo Yan leo.yan@linaro.org, 2019 + +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) +file=$(mktemp /tmp/temporary_file.XXXXX) + +skip_if_no_cs_etm_event() { + perf list | grep -q 'cs_etm//' && return 0 + + # cs_etm event doesn't exist + return 2 +} + +skip_if_no_cs_etm_event || exit 2 + +record_touch_file() { + echo "Recording trace with path: CPU$2 => $1" + perf record -o ${perfdata} -e cs_etm/@$1/ --per-thread \ + -- taskset -c $2 touch $file +} + +perf_script_branch_samples() { + echo "Looking at perf.data file for dumping branch samples:" + perf script -F,-time -i ${perfdata} | \ + egrep " +touch +[0-9]+ .* +branches: +" +} + +arm_cs_iterate_devices() { + for dev in $1/out:*; do + + # Skip testing if it's not a directory + ! [ -d $dev ] && continue; + + # Read out its symbol link file name + path=`readlink -f $dev` + + # Extract device name from path, e.g. + # path = '/sys/devices/platform/20010000.etf/tmc_etf0' + # `> device_name = '20010000.etf' + device_name=`echo $path | awk -F/ '{print $(NF-1)}'` + + echo $device_name | egrep -q "etr|etb|etf" + + # Only test if the output device is ETR/ETB/ETF + if [ $? -eq 0 ]; then + record_touch_file $device_name $2 && + perf_script_branch_samples + + err=$? + + rm -f ${perfdata} + rm -f ${file} + + # Exit when find failure + [ $err != 0 ] && exit $err + fi + + arm_cs_iterate_devices $dev $2 + done +} + +arm_cs_etm_test() { + # Iterate for every ETM device + for dev in /sys/bus/coresight/devices/etm*; do + + # Find the ETM device belonging to which CPU + cpu=`cat $dev/cpu` + + # Use depth-first search (DFS) to iterate outputs + arm_cs_iterate_devices $dev $cpu + done +} + +arm_cs_etm_test +exit 0