Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # perf stat --bpf-counters test
0003 # SPDX-License-Identifier: GPL-2.0
0004 
0005 set -e
0006 
0007 # check whether $2 is within +/- 10% of $1
0008 compare_number()
0009 {
0010        first_num=$1
0011        second_num=$2
0012 
0013        # upper bound is first_num * 110%
0014        upper=$(expr $first_num + $first_num / 10 )
0015        # lower bound is first_num * 90%
0016        lower=$(expr $first_num - $first_num / 10 )
0017 
0018        if [ $second_num -gt $upper ] || [ $second_num -lt $lower ]; then
0019                echo "The difference between $first_num and $second_num are greater than 10%."
0020                exit 1
0021        fi
0022 }
0023 
0024 # skip if --bpf-counters is not supported
0025 if ! perf stat --bpf-counters true > /dev/null 2>&1; then
0026         if [ "$1" = "-v" ]; then
0027                 echo "Skipping: --bpf-counters not supported"
0028                 perf --no-pager stat --bpf-counters true || true
0029         fi
0030         exit 2
0031 fi
0032 
0033 base_cycles=$(perf stat --no-big-num -e cycles -- perf bench sched messaging -g 1 -l 100 -t 2>&1 | awk '/cycles/ {print $1}')
0034 if [ "$base_cycles" == "<not" ]; then
0035         echo "Skipping: cycles event not counted"
0036         exit 2
0037 fi
0038 bpf_cycles=$(perf stat --no-big-num --bpf-counters -e cycles -- perf bench sched messaging -g 1 -l 100 -t 2>&1 | awk '/cycles/ {print $1}')
0039 if [ "$bpf_cycles" == "<not" ]; then
0040         echo "Failed: cycles not counted with --bpf-counters"
0041         exit 1
0042 fi
0043 
0044 compare_number $base_cycles $bpf_cycles
0045 exit 0