brintos

brintos / linux-shallow public Read only

0
0
Text · 2.9 KiB · 03d5c7d Raw
114 lines · bash
1#!/bin/sh2# Check Arm SPE trace data recording and synthesized samples3 4# Uses the 'perf record' to record trace data of Arm SPE events;5# then verify if any SPE event samples are generated by SPE with6# 'perf script' and 'perf report' commands.7 8# SPDX-License-Identifier: GPL-2.09# German Gomez <german.gomez@arm.com>, 202110 11skip_if_no_arm_spe_event() {12	perf list | grep -E -q 'arm_spe_[0-9]+//' && return 013 14	# arm_spe event doesn't exist15	return 216}17 18skip_if_no_arm_spe_event || exit 219 20perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)21glb_err=022 23cleanup_files()24{25	rm -f ${perfdata}26	rm -f ${perfdata}.old27	exit $glb_err28}29 30trap cleanup_files EXIT TERM INT31 32arm_spe_report() {33	if [ $2 = 0 ]; then34		echo "$1: PASS"35	elif [ $2 = 2 ]; then36		echo "$1: SKIPPED"37	else38		echo "$1: FAIL"39		glb_err=$240	fi41}42 43perf_script_samples() {44	echo "Looking at perf.data file for dumping samples:"45 46	# from arm-spe.c/arm_spe_synth_events()47	events="(ld1-miss|ld1-access|llc-miss|lld-access|tlb-miss|tlb-access|branch-miss|remote-access|memory)"48 49	# Below is an example of the samples dumping:50	#	dd  3048 [002]          1    l1d-access:      ffffaa64999c __GI___libc_write+0x3c (/lib/aarch64-linux-gnu/libc-2.27.so)51	#	dd  3048 [002]          1    tlb-access:      ffffaa64999c __GI___libc_write+0x3c (/lib/aarch64-linux-gnu/libc-2.27.so)52	#	dd  3048 [002]          1        memory:      ffffaa64999c __GI___libc_write+0x3c (/lib/aarch64-linux-gnu/libc-2.27.so)53	perf script -F,-time -i ${perfdata} 2>&1 | \54		grep -E " +$1 +[0-9]+ .* +${events}:(.*:)? +" > /dev/null 2>&155}56 57perf_report_samples() {58	echo "Looking at perf.data file for reporting samples:"59 60	# Below is an example of the samples reporting:61	#   73.04%    73.04%  dd    libc-2.27.so      [.] _dl_addr62	#    7.71%     7.71%  dd    libc-2.27.so      [.] getenv63	#    2.59%     2.59%  dd    ld-2.27.so        [.] strcmp64	perf report --stdio -i ${perfdata} 2>&1 | \65		grep -E " +[0-9]+\.[0-9]+% +[0-9]+\.[0-9]+% +$1 " > /dev/null 2>&166}67 68arm_spe_snapshot_test() {69	echo "Recording trace with snapshot mode $perfdata"70	perf record -o ${perfdata} -e arm_spe// -S \71		-- dd if=/dev/zero of=/dev/null > /dev/null 2>&1 &72	PERFPID=$!73 74	# Wait for perf program75	sleep 176 77	# Send signal to snapshot trace data78	kill -USR2 $PERFPID79 80	# Stop perf program81	kill $PERFPID82	wait $PERFPID83 84	perf_script_samples dd &&85	perf_report_samples dd86 87	err=$?88	arm_spe_report "SPE snapshot testing" $err89}90 91arm_spe_system_wide_test() {92	echo "Recording trace with system-wide mode $perfdata"93 94	perf record -o - -e dummy -a -B true > /dev/null 2>&195	if [ $? != 0 ]; then96		arm_spe_report "SPE system-wide testing" 297		return98	fi99 100	perf record -o ${perfdata} -e arm_spe// -a --no-bpf-event \101		-- dd if=/dev/zero of=/dev/null count=100000 > /dev/null 2>&1102 103	perf_script_samples dd &&104	perf_report_samples dd105 106	err=$?107	arm_spe_report "SPE system-wide testing" $err108}109 110arm_spe_snapshot_test111arm_spe_system_wide_test112 113exit $glb_err114