2 # Check Arm CoreSight trace data recording and synthesized samples
4 # Uses the 'perf record' to record trace data with Arm CoreSight sinks;
5 # then verify if there have any branch samples and instruction samples
6 # are generated by CoreSight with 'perf script' and 'perf report'
9 # SPDX-License-Identifier: GPL-2.0
10 # Leo Yan <leo.yan@linaro.org>, 2020
12 perfdata
=$
(mktemp
/tmp
/__perf_test.perf.data.XXXXX
)
13 file=$
(mktemp
/tmp
/temporary_file.XXXXX
)
15 skip_if_no_cs_etm_event
() {
16 perf list |
grep -q 'cs_etm//' && return 0
18 # cs_etm event doesn't exist
22 skip_if_no_cs_etm_event ||
exit 2
30 trap cleanup_files
exit
33 echo "Recording trace (only user mode) with path: CPU$2 => $1"
35 perf record
-o ${perfdata} -e cs_etm
/@
$1/u
--per-thread \
36 -- taskset
-c $2 touch $file
39 perf_script_branch_samples
() {
40 echo "Looking at perf.data file for dumping branch samples:"
42 # Below is an example of the branch samples dumping:
43 # touch 6512 1 branches:u: ffffb220824c strcmp+0xc (/lib/aarch64-linux-gnu/ld-2.27.so)
44 # touch 6512 1 branches:u: ffffb22082e0 strcmp+0xa0 (/lib/aarch64-linux-gnu/ld-2.27.so)
45 # touch 6512 1 branches:u: ffffb2208320 strcmp+0xe0 (/lib/aarch64-linux-gnu/ld-2.27.so)
46 perf
script -F,-time -i ${perfdata} | \
47 egrep " +$1 +[0-9]+ .* +branches:(.*:)? +"
50 perf_report_branch_samples
() {
51 echo "Looking at perf.data file for reporting branch samples:"
53 # Below is an example of the branch samples reporting:
54 # 73.04% 73.04% touch libc-2.27.so [.] _dl_addr
55 # 7.71% 7.71% touch libc-2.27.so [.] getenv
56 # 2.59% 2.59% touch ld-2.27.so [.] strcmp
57 perf report
--stdio -i ${perfdata} | \
58 egrep " +[0-9]+\.[0-9]+% +[0-9]+\.[0-9]+% +$1 "
61 perf_report_instruction_samples
() {
62 echo "Looking at perf.data file for instruction samples:"
64 # Below is an example of the instruction samples reporting:
65 # 68.12% touch libc-2.27.so [.] _dl_addr
66 # 5.80% touch libc-2.27.so [.] getenv
67 # 4.35% touch ld-2.27.so [.] _dl_fixup
68 perf report
--itrace=i1000i
--stdio -i ${perfdata} | \
69 egrep " +[0-9]+\.[0-9]+% +$1"
73 # If the node of "enable_sink" is existed under the device path, this
74 # means the device is a sink device. Need to exclude 'tpiu' since it
75 # cannot support perf PMU.
76 echo "$1" |
egrep -q -v "tpiu"
78 if [ $?
-eq 0 -a -e "$1/enable_sink" ]; then
80 pmu_dev
="/sys/bus/event_source/devices/cs_etm/sinks/$2"
82 # Warn if the device is not supported by PMU
83 if ! [ -f $pmu_dev ]; then
84 echo "PMU doesn't support $pmu_dev"
90 # Otherwise, it's not a sink device
94 arm_cs_iterate_devices
() {
95 for dev
in $1/connections
/out\
:*; do
97 # Skip testing if it's not a directory
98 ! [ -d $dev ] && continue;
100 # Read out its symbol link file name
101 path
=`readlink -f $dev`
103 # Extract device name from path, e.g.
104 # path = '/sys/devices/platform/20010000.etf/tmc_etf0'
105 # `> device_name = 'tmc_etf0'
106 device_name
=$
(basename $path)
108 if is_device_sink
$path $device_name; then
110 record_touch_file
$device_name $2 &&
111 perf_script_branch_samples
touch &&
112 perf_report_branch_samples
touch &&
113 perf_report_instruction_samples
touch
117 # Exit when find failure
118 [ $err != 0 ] && exit $err
121 arm_cs_iterate_devices
$dev $2
125 arm_cs_etm_traverse_path_test
() {
126 # Iterate for every ETM device
127 for dev
in /sys
/bus
/coresight
/devices
/etm
*; do
129 # Find the ETM device belonging to which CPU
135 # Use depth-first search (DFS) to iterate outputs
136 arm_cs_iterate_devices
$dev $cpu
140 arm_cs_etm_system_wide_test
() {
141 echo "Recording trace with system wide mode"
142 perf record
-o ${perfdata} -e cs_etm
// -a -- ls
144 perf_script_branch_samples perf
&&
145 perf_report_branch_samples perf
&&
146 perf_report_instruction_samples perf
150 # Exit when find failure
151 [ $err != 0 ] && exit $err
154 arm_cs_etm_snapshot_test
() {
155 echo "Recording trace with snapshot mode"
156 perf record
-o ${perfdata} -e cs_etm
// -S \
157 -- dd if=/dev
/zero of
=/dev
/null
&
160 # Wait for perf program
163 # Send signal to snapshot trace data
170 perf_script_branch_samples
dd &&
171 perf_report_branch_samples
dd &&
172 perf_report_instruction_samples
dd
176 # Exit when find failure
177 [ $err != 0 ] && exit $err
180 arm_cs_etm_traverse_path_test
181 arm_cs_etm_system_wide_test
182 arm_cs_etm_snapshot_test