Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # Check Arm SPE trace data recording and synthesized samples
0003 
0004 # Uses the 'perf record' to record trace data of Arm SPE events;
0005 # then verify if any SPE event samples are generated by SPE with
0006 # 'perf script' and 'perf report' commands.
0007 
0008 # SPDX-License-Identifier: GPL-2.0
0009 # German Gomez <german.gomez@arm.com>, 2021
0010 
0011 skip_if_no_arm_spe_event() {
0012         perf list | egrep -q 'arm_spe_[0-9]+//' && return 0
0013 
0014         # arm_spe event doesn't exist
0015         return 2
0016 }
0017 
0018 skip_if_no_arm_spe_event || exit 2
0019 
0020 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
0021 glb_err=0
0022 
0023 cleanup_files()
0024 {
0025         rm -f ${perfdata}
0026         rm -f ${perfdata}.old
0027         exit $glb_err
0028 }
0029 
0030 trap cleanup_files exit term int
0031 
0032 arm_spe_report() {
0033         if [ $2 = 0 ]; then
0034                 echo "$1: PASS"
0035         elif [ $2 = 2 ]; then
0036                 echo "$1: SKIPPED"
0037         else
0038                 echo "$1: FAIL"
0039                 glb_err=$2
0040         fi
0041 }
0042 
0043 perf_script_samples() {
0044         echo "Looking at perf.data file for dumping samples:"
0045 
0046         # from arm-spe.c/arm_spe_synth_events()
0047         events="(ld1-miss|ld1-access|llc-miss|lld-access|tlb-miss|tlb-access|branch-miss|remote-access|memory)"
0048 
0049         # Below is an example of the samples dumping:
0050         #       dd  3048 [002]          1    l1d-access:      ffffaa64999c __GI___libc_write+0x3c (/lib/aarch64-linux-gnu/libc-2.27.so)
0051         #       dd  3048 [002]          1    tlb-access:      ffffaa64999c __GI___libc_write+0x3c (/lib/aarch64-linux-gnu/libc-2.27.so)
0052         #       dd  3048 [002]          1        memory:      ffffaa64999c __GI___libc_write+0x3c (/lib/aarch64-linux-gnu/libc-2.27.so)
0053         perf script -F,-time -i ${perfdata} 2>&1 | \
0054                 egrep " +$1 +[0-9]+ .* +${events}:(.*:)? +" > /dev/null 2>&1
0055 }
0056 
0057 perf_report_samples() {
0058         echo "Looking at perf.data file for reporting samples:"
0059 
0060         # Below is an example of the samples reporting:
0061         #   73.04%    73.04%  dd    libc-2.27.so      [.] _dl_addr
0062         #    7.71%     7.71%  dd    libc-2.27.so      [.] getenv
0063         #    2.59%     2.59%  dd    ld-2.27.so        [.] strcmp
0064         perf report --stdio -i ${perfdata} 2>&1 | \
0065                 egrep " +[0-9]+\.[0-9]+% +[0-9]+\.[0-9]+% +$1 " > /dev/null 2>&1
0066 }
0067 
0068 arm_spe_snapshot_test() {
0069         echo "Recording trace with snapshot mode $perfdata"
0070         perf record -o ${perfdata} -e arm_spe// -S \
0071                 -- dd if=/dev/zero of=/dev/null > /dev/null 2>&1 &
0072         PERFPID=$!
0073 
0074         # Wait for perf program
0075         sleep 1
0076 
0077         # Send signal to snapshot trace data
0078         kill -USR2 $PERFPID
0079 
0080         # Stop perf program
0081         kill $PERFPID
0082         wait $PERFPID
0083 
0084         perf_script_samples dd &&
0085         perf_report_samples dd
0086 
0087         err=$?
0088         arm_spe_report "SPE snapshot testing" $err
0089 }
0090 
0091 arm_spe_system_wide_test() {
0092         echo "Recording trace with system-wide mode $perfdata"
0093 
0094         perf record -o - -e dummy -a -B true > /dev/null 2>&1
0095         if [ $? != 0 ]; then
0096                 arm_spe_report "SPE system-wide testing" 2
0097                 return
0098         fi
0099 
0100         perf record -o ${perfdata} -e arm_spe// -a --no-bpf-event \
0101                 -- dd if=/dev/zero of=/dev/null count=100000 > /dev/null 2>&1
0102 
0103         perf_script_samples dd &&
0104         perf_report_samples dd
0105 
0106         err=$?
0107         arm_spe_report "SPE system-wide testing" $err
0108 }
0109 
0110 arm_spe_snapshot_test
0111 arm_spe_system_wide_test
0112 
0113 exit $glb_err