2 # SPDX-License-Identifier: GPL-2.0
4 # protect against multiple inclusion
5 if [ $FILE_MAIN ]; then
11 SCRIPTDIR
=`dirname "$0"`
12 TRACER
=$SCRIPTDIR/..
/..
/..
/power
/x86
/amd_pstate_tracer
/amd_pstate_trace.py
14 source $SCRIPTDIR/basic.sh
15 source $SCRIPTDIR/tbench.sh
16 source $SCRIPTDIR/gitsource.sh
18 # amd-pstate-ut only run on x86/x86_64 AMD systems.
19 ARCH
=$
(uname
-m 2>/dev
/null |
sed -e 's/i.86/x86/' -e 's/x86_64/x86/')
20 VENDOR
=$
(cat /proc
/cpuinfo |
grep -m 1 'vendor_id' |
awk '{print $NF}')
25 OUTFILE_TBENCH
="$OUTFILE.tbench"
26 OUTFILE_GIT
="$OUTFILE.gitsource"
38 CURRENT_TEST
=amd-pstate
41 # Kselftest framework requirement - SKIP code is 4.
43 all_scaling_names
=("acpi-cpufreq" "amd-pstate")
45 # Get current cpufreq scaling driver name
48 if [ "$COMPARATIVE_TEST" = "" ]; then
51 echo "$COMPARATIVE_TEST"
55 # Counts CPUs with cpufreq directories
60 for cpu
in `ls $CPUROOT | grep "cpu[0-9].*"`; do
61 if [ -d $CPUROOT/$cpu/cpufreq
]; then
70 find_current_governor
()
72 cat $CPUFREQROOT/$1/scaling_governor
77 policies
=$
(ls $CPUFREQROOT|
grep "policy[0-9].*")
78 for policy
in $policies; do
79 cur_gov
=$
(find_current_governor
$policy)
80 echo "$policy $cur_gov" >> $OUTFILE.backup_governor.log
83 printf "Governor $cur_gov backup done.\n"
90 policies
=$
(awk '{print $1}' $OUTFILE.backup_governor.log
)
91 for policy
in $policies; do
93 governor
=$
(sed -n ''$i'p' $OUTFILE.backup_governor.log |
awk '{print $2}')
96 echo $governor > $CPUFREQROOT/$policy/scaling_governor
99 printf "Governor restored to $governor.\n"
105 policies
=$
(ls $CPUFREQROOT|
grep "policy[0-9].*")
106 for policy
in $policies; do
107 filepath
=$CPUFREQROOT/$policy/scaling_available_governors
109 # Exit if cpu isn't managed by cpufreq core
110 if [ ! -f $filepath ]; then
114 echo $1 > $CPUFREQROOT/$policy/scaling_governor
117 printf "Switched governor to $1.\n"
120 # All amd-pstate tests
123 printf "\n=============================================\n"
124 printf "***** Running AMD P-state Sanity Tests *****\n"
125 printf "=============================================\n\n"
128 if [ $count = 0 ]; then
129 printf "No cpu is managed by cpufreq core, exiting\n"
132 printf "AMD P-state manages: $count CPUs\n"
135 # unit test for amd-pstate kernel driver
147 printf "Usage: $0 [OPTION...]
149 [-o <output-file-for-dump>]
150 [-c <all: All testing,
151 basic: Basic testing,
152 tbench: Tbench testing,
153 gitsource: Gitsource testing.>]
154 [-t <tbench time limit>]
155 [-p <tbench process number>]
156 [-l <loop times for tbench>]
157 [-i <amd tracer interval>]
159 [-m <comparative test: acpi-cpufreq>]
166 while getopts ho
:c
:t
:p
:l
:i
:b
:m
: arg
173 c
) # --func_type (Function to perform: basic, tbench, gitsource (default: all))
177 o
) # --output-file (Output file to store dumps)
181 t
) # --tbench-time-limit
185 p
) # --tbench-process-number
189 l
) # --tbench/gitsource-loop-times
193 i
) # --amd-tracer-interval
194 TRACER_INTERVAL
=$OPTARG
198 PERF
=`realpath $OPTARG`
201 m
) # --comparative-test
202 COMPARATIVE_TEST
=$OPTARG
215 echo $msg please
install perf or provide perf binary path as argument
>&2
222 if ! command -v tbench
> /dev
/null
; then
223 if apt policy dbench
> /dev
/null
2>&1; then
224 echo $msg apt
install dbench
>&2
226 elif yum list available |
grep dbench
> /dev
/null
2>&1; then
227 echo $msg yum
install dbench
>&2
232 if ! command -v tbench
> /dev
/null
; then
233 echo $msg please
install tbench.
>&2
240 if ! echo "$ARCH" |
grep -q x86
; then
241 echo "$0 # Skipped: Test can only run on x86 architectures."
245 if ! echo "$VENDOR" |
grep -iq amd
; then
246 echo "$0 # Skipped: Test can only run on AMD CPU."
247 echo "$0 # Current cpu vendor is $VENDOR."
251 scaling_driver
=$
(cat /sys
/devices
/system
/cpu
/cpufreq
/policy
0/scaling_driver
)
252 if [ "$COMPARATIVE_TEST" = "" ]; then
253 if [ "$scaling_driver" != "$CURRENT_TEST" ]; then
254 echo "$0 # Skipped: Test can only run on $CURRENT_TEST driver or run comparative test."
255 echo "$0 # Please set X86_AMD_PSTATE enabled or run comparative test."
256 echo "$0 # Current cpufreq scaling driver is $scaling_driver."
261 "tbench" |
"gitsource")
262 if [ "$scaling_driver" != "$COMPARATIVE_TEST" ]; then
263 echo "$0 # Skipped: Comparison test can only run on $COMPARISON_TEST driver."
264 echo "$0 # Current cpufreq scaling driver is $scaling_driver."
270 echo "$0 # Skipped: Comparison test are only for tbench or gitsource."
271 echo "$0 # Current comparative test is for $FUNC."
277 if [ ! -w /dev
]; then
278 echo $msg please run this as root
>&2
298 SYSFS
=`mount -t sysfs | head -1 | awk '{ print $3 }'`
300 if [ ! -d "$SYSFS" ]; then
301 echo $msg sysfs is not mounted
>&2
305 CPUROOT
=$SYSFS/devices
/system
/cpu
306 CPUFREQROOT
="$CPUROOT/cpufreq"
308 if ! ls $CPUROOT/cpu
* > /dev
/null
2>&1; then
309 echo $msg cpus not available
in sysfs
>&2
313 if ! ls $CPUROOT/cpufreq
> /dev
/null
2>&1; then
314 echo $msg cpufreq directory not available
in sysfs
>&2
321 # Check if CPUs are managed by cpufreq or not
323 MAKE_CPUS
=$
((count
*2))
325 if [ $count = 0 ]; then
326 echo "No cpu is managed by cpufreq core, exiting"
348 echo "Invalid [-f] function type"
360 rm -rf $OUTFILE.backup_governor.log
366 rm -rf $OUTFILE.backup_governor.log
372 rm -rf $OUTFILE.backup_governor.log
373 rm -rf gitsource_
*.png
384 rm -rf $OUTFILE.backup_governor.log
390 # Make sure all requirements are met
393 # Run requested functions
395 do_test |
tee -a $OUTFILE.log