brintos

brintos / linux-shallow public Read only

0
0
Text · 5.7 KiB · 3302ea0 Raw
215 lines · bash
1#!/bin/sh2# Check Arm CoreSight trace data recording and synthesized samples3 4# Uses the 'perf record' to record trace data with Arm CoreSight sinks;5# then verify if there have any branch samples and instruction samples6# are generated by CoreSight with 'perf script' and 'perf report'7# commands.8 9# SPDX-License-Identifier: GPL-2.010# Leo Yan <leo.yan@linaro.org>, 202011 12glb_err=013 14skip_if_no_cs_etm_event() {15	perf list | grep -q 'cs_etm//' && return 016 17	# cs_etm event doesn't exist18	return 219}20 21skip_if_no_cs_etm_event || exit 222 23perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)24file=$(mktemp /tmp/temporary_file.XXXXX)25 26cleanup_files()27{28	rm -f ${perfdata}29	rm -f ${file}30	rm -f "${perfdata}.old"31	trap - EXIT TERM INT32	exit $glb_err33}34 35trap cleanup_files EXIT TERM INT36 37record_touch_file() {38	echo "Recording trace (only user mode) with path: CPU$2 => $1"39	rm -f $file40	perf record -o ${perfdata} -e cs_etm/@$1/u --per-thread \41		-- taskset -c $2 touch $file > /dev/null 2>&142}43 44perf_script_branch_samples() {45	echo "Looking at perf.data file for dumping branch samples:"46 47	# Below is an example of the branch samples dumping:48	#   touch  6512          1         branches:u:      ffffb220824c strcmp+0xc (/lib/aarch64-linux-gnu/ld-2.27.so)49	#   touch  6512          1         branches:u:      ffffb22082e0 strcmp+0xa0 (/lib/aarch64-linux-gnu/ld-2.27.so)50	#   touch  6512          1         branches:u:      ffffb2208320 strcmp+0xe0 (/lib/aarch64-linux-gnu/ld-2.27.so)51	perf script -F,-time -i ${perfdata} 2>&1 | \52		grep -E " +$1 +[0-9]+ .* +branches:(.*:)? +" > /dev/null 2>&153}54 55perf_report_branch_samples() {56	echo "Looking at perf.data file for reporting branch samples:"57 58	# Below is an example of the branch samples reporting:59	#   73.04%    73.04%  touch    libc-2.27.so      [.] _dl_addr60	#    7.71%     7.71%  touch    libc-2.27.so      [.] getenv61	#    2.59%     2.59%  touch    ld-2.27.so        [.] strcmp62	perf report --stdio -i ${perfdata} 2>&1 | \63		grep -E " +[0-9]+\.[0-9]+% +[0-9]+\.[0-9]+% +$1 " > /dev/null 2>&164}65 66perf_report_instruction_samples() {67	echo "Looking at perf.data file for instruction samples:"68 69	# Below is an example of the instruction samples reporting:70	#   68.12%  touch    libc-2.27.so   [.] _dl_addr71	#    5.80%  touch    libc-2.27.so   [.] getenv72	#    4.35%  touch    ld-2.27.so     [.] _dl_fixup73	perf report --itrace=i20i --stdio -i ${perfdata} 2>&1 | \74		grep -E " +[0-9]+\.[0-9]+% +$1" > /dev/null 2>&175}76 77arm_cs_report() {78	if [ $2 != 0 ]; then79		echo "$1: FAIL"80		glb_err=$281	else82		echo "$1: PASS"83	fi84}85 86is_device_sink() {87	# If the node of "enable_sink" is existed under the device path, this88	# means the device is a sink device.  Need to exclude 'tpiu' since it89	# cannot support perf PMU.90	echo "$1" | grep -E -q -v "tpiu"91 92	if [ $? -eq 0 ] && [ -e "$1/enable_sink" ]; then93 94		pmu_dev="/sys/bus/event_source/devices/cs_etm/sinks/$2"95 96		# Warn if the device is not supported by PMU97		if ! [ -f $pmu_dev ]; then98			echo "PMU doesn't support $pmu_dev"99		fi100 101		return 0102	fi103 104	# Otherwise, it's not a sink device105	return 1106}107 108arm_cs_iterate_devices() {109	for dev in $1/connections/out\:*; do110 111		# Skip testing if it's not a directory112		! [ -d $dev ] && continue;113 114		# Read out its symbol link file name115		path=`readlink -f $dev`116 117		# Extract device name from path, e.g.118		#   path = '/sys/devices/platform/20010000.etf/tmc_etf0'119		#     `> device_name = 'tmc_etf0'120		device_name=$(basename $path)121 122		if is_device_sink $path $device_name; then123 124			record_touch_file $device_name $2 &&125			perf_script_branch_samples touch &&126			perf_report_branch_samples touch &&127			perf_report_instruction_samples touch128 129			err=$?130			arm_cs_report "CoreSight path testing (CPU$2 -> $device_name)" $err131		fi132 133		arm_cs_iterate_devices $dev $2134	done135}136 137arm_cs_etm_traverse_path_test() {138	# Iterate for every ETM device139	for dev in /sys/bus/event_source/devices/cs_etm/cpu*; do140		# Canonicalize the path141		dev=`readlink -f $dev`142 143		# Find the ETM device belonging to which CPU144		cpu=`cat $dev/cpu`145 146		# Use depth-first search (DFS) to iterate outputs147		arm_cs_iterate_devices $dev $cpu148	done149}150 151arm_cs_etm_system_wide_test() {152	echo "Recording trace with system wide mode"153	perf record -o ${perfdata} -e cs_etm// -a -- ls > /dev/null 2>&1154 155	# System-wide mode should include perf samples so test for that156	# instead of ls157	perf_script_branch_samples perf &&158	perf_report_branch_samples perf &&159	perf_report_instruction_samples perf160 161	err=$?162	arm_cs_report "CoreSight system wide testing" $err163}164 165arm_cs_etm_snapshot_test() {166	echo "Recording trace with snapshot mode"167	perf record -o ${perfdata} -e cs_etm// -S \168		-- dd if=/dev/zero of=/dev/null > /dev/null 2>&1 &169	PERFPID=$!170 171	# Wait for perf program172	sleep 1173 174	# Send signal to snapshot trace data175	kill -USR2 $PERFPID176 177	# Stop perf program178	kill $PERFPID179	wait $PERFPID180 181	perf_script_branch_samples dd &&182	perf_report_branch_samples dd &&183	perf_report_instruction_samples dd184 185	err=$?186	arm_cs_report "CoreSight snapshot testing" $err187}188 189arm_cs_etm_basic_test() {190	echo "Recording trace with '$*'"191	perf record -o ${perfdata} "$@" -m,8M -- ls > /dev/null 2>&1192 193	perf_script_branch_samples ls &&194	perf_report_branch_samples ls &&195	perf_report_instruction_samples ls196 197	err=$?198	arm_cs_report "CoreSight basic testing with '$*'" $err199}200 201arm_cs_etm_traverse_path_test202arm_cs_etm_system_wide_test203arm_cs_etm_snapshot_test204 205# Test all combinations of per-thread, system-wide and normal mode with206# and without timestamps207arm_cs_etm_basic_test -e cs_etm/timestamp=0/ --per-thread208arm_cs_etm_basic_test -e cs_etm/timestamp=1/ --per-thread209arm_cs_etm_basic_test -e cs_etm/timestamp=0/ -a210arm_cs_etm_basic_test -e cs_etm/timestamp=1/ -a211arm_cs_etm_basic_test -e cs_etm/timestamp=0/212arm_cs_etm_basic_test -e cs_etm/timestamp=1/213 214exit $glb_err215