Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # This test runs on Intel x86 based hardware which support the intel_pstate
0005 # driver.  The test checks the frequency settings from the maximum turbo
0006 # state to the minimum supported frequency, in decrements of 100MHz.  The
0007 # test runs the aperf.c program to put load on each processor.
0008 #
0009 # The results are displayed in a table which indicate the "Target" state,
0010 # or the requested frequency in MHz, the Actual frequency, as read from
0011 # /proc/cpuinfo, the difference between the Target and Actual frequencies,
0012 # and the value of MSR 0x199 (MSR_IA32_PERF_CTL) which indicates what
0013 # pstate the cpu is in, and the value of
0014 # /sys/devices/system/cpu/intel_pstate/max_perf_pct X maximum turbo state
0015 #
0016 # Notes: In some cases several frequency values may be placed in the
0017 # /tmp/result.X files.  This is done on purpose in order to catch cases
0018 # where the pstate driver may not be working at all.  There is the case
0019 # where, for example, several "similar" frequencies are in the file:
0020 #
0021 #
0022 #/tmp/result.3100:1:cpu MHz              : 2899.980
0023 #/tmp/result.3100:2:cpu MHz              : 2900.000
0024 #/tmp/result.3100:3:msr 0x199: 0x1e00
0025 #/tmp/result.3100:4:max_perf_pct 94
0026 #
0027 # and the test will error out in those cases.  The result.X file can be checked
0028 # for consistency and modified to remove the extra MHz values.  The result.X
0029 # files can be re-evaluated by setting EVALUATE_ONLY to 1 below.
0030 
0031 EVALUATE_ONLY=0
0032 
0033 # Kselftest framework requirement - SKIP code is 4.
0034 ksft_skip=4
0035 
0036 if ! uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ | grep -q x86; then
0037         echo "$0 # Skipped: Test can only run on x86 architectures."
0038         exit $ksft_skip
0039 fi
0040 
0041 msg="skip all tests:"
0042 if [ $UID != 0 ] && [ $EVALUATE_ONLY == 0 ]; then
0043     echo $msg please run this as root >&2
0044     exit $ksft_skip
0045 fi
0046 
0047 max_cpus=$(($(nproc)-1))
0048 
0049 function run_test () {
0050 
0051         file_ext=$1
0052         for cpu in `seq 0 $max_cpus`
0053         do
0054                 echo "launching aperf load on $cpu"
0055                 ./aperf $cpu &
0056         done
0057 
0058         echo "sleeping for 5 seconds"
0059         sleep 5
0060         grep MHz /proc/cpuinfo | sort -u > /tmp/result.freqs
0061         num_freqs=$(wc -l /tmp/result.freqs | awk ' { print $1 } ')
0062         if [ $num_freqs -ge 2 ]; then
0063                 tail -n 1 /tmp/result.freqs > /tmp/result.$1
0064         else
0065                 cp /tmp/result.freqs /tmp/result.$1
0066         fi
0067         ./msr 0 >> /tmp/result.$1
0068 
0069         max_perf_pct=$(cat /sys/devices/system/cpu/intel_pstate/max_perf_pct)
0070         echo "max_perf_pct $max_perf_pct" >> /tmp/result.$1
0071 
0072         for job in `jobs -p`
0073         do
0074                 echo "waiting for job id $job"
0075                 wait $job
0076         done
0077 }
0078 
0079 #
0080 # MAIN (ALL UNITS IN MHZ)
0081 #
0082 
0083 # Get the marketing frequency
0084 _mkt_freq=$(cat /proc/cpuinfo | grep -m 1 "model name" | awk '{print $NF}')
0085 _mkt_freq=$(echo $_mkt_freq | tr -d [:alpha:][:punct:])
0086 mkt_freq=${_mkt_freq}0
0087 
0088 # Get the ranges from cpupower
0089 _min_freq=$(cpupower frequency-info -l | tail -1 | awk ' { print $1 } ')
0090 min_freq=$(($_min_freq / 1000))
0091 _max_freq=$(cpupower frequency-info -l | tail -1 | awk ' { print $2 } ')
0092 max_freq=$(($_max_freq / 1000))
0093 
0094 
0095 [ $EVALUATE_ONLY -eq 0 ] && for freq in `seq $max_freq -100 $min_freq`
0096 do
0097         echo "Setting maximum frequency to $freq"
0098         cpupower frequency-set -g powersave --max=${freq}MHz >& /dev/null
0099         run_test $freq
0100 done
0101 
0102 [ $EVALUATE_ONLY -eq 0 ] && cpupower frequency-set -g powersave --max=${max_freq}MHz >& /dev/null
0103 
0104 echo "========================================================================"
0105 echo "The marketing frequency of the cpu is $mkt_freq MHz"
0106 echo "The maximum frequency of the cpu is $max_freq MHz"
0107 echo "The minimum frequency of the cpu is $min_freq MHz"
0108 
0109 # make a pretty table
0110 echo "Target Actual Difference MSR(0x199) max_perf_pct" | tr " " "\n" > /tmp/result.tab
0111 for freq in `seq $max_freq -100 $min_freq`
0112 do
0113         result_freq=$(cat /tmp/result.${freq} | grep "cpu MHz" | awk ' { print $4 } ' | awk -F "." ' { print $1 } ')
0114         msr=$(cat /tmp/result.${freq} | grep "msr" | awk ' { print $3 } ')
0115         max_perf_pct=$(cat /tmp/result.${freq} | grep "max_perf_pct" | awk ' { print $2 } ' )
0116         cat >> /tmp/result.tab << EOF
0117 $freq
0118 $result_freq
0119 $((result_freq - freq))
0120 $msr
0121 $((max_perf_pct * max_freq))
0122 EOF
0123 done
0124 
0125 # print the table
0126 pr -aTt -5 < /tmp/result.tab
0127 
0128 exit 0