2 # SPDX-License-Identifier: GPL-2.0
4 # protect against multiple inclusion
5 if [ $FILE_MAIN ]; then
15 # amd-pstate-ut only run on x86/x86_64 AMD systems.
16 ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x86/' -e 's/x86_64/x86/')
17 VENDOR=$(cat /proc/cpuinfo | grep -m 1 'vendor_id' | awk '{print $NF}')
22 OUTFILE_TBENCH="$OUTFILE.tbench"
23 OUTFILE_GIT="$OUTFILE.gitsource"
34 CURRENT_TEST=amd-pstate
37 # Kselftest framework requirement - SKIP code is 4.
39 all_scaling_names=("acpi-cpufreq" "amd-pstate")
41 # Get current cpufreq scaling driver name
44 if [ "$COMPARATIVE_TEST" = "" ]; then
47 echo "$COMPARATIVE_TEST"
51 # Counts CPUs with cpufreq directories
56 for cpu in `ls $CPUROOT | grep "cpu[0-9].*"`; do
57 if [ -d $CPUROOT/$cpu/cpufreq ]; then
66 find_current_governor()
68 cat $CPUFREQROOT/$1/scaling_governor
73 policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
74 for policy in $policies; do
75 cur_gov=$(find_current_governor $policy)
76 echo "$policy $cur_gov" >> $OUTFILE.backup_governor.log
79 printf "Governor $cur_gov backup done.\n"
86 policies=$(awk '{print $1}' $OUTFILE.backup_governor.log)
87 for policy in $policies; do
89 governor=$(sed -n ''$i'p' $OUTFILE.backup_governor.log | awk '{print $2}')
92 echo $governor > $CPUFREQROOT/$policy/scaling_governor
95 printf "Governor restored to $governor.\n"
101 policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
102 for policy in $policies; do
103 filepath=$CPUFREQROOT/$policy/scaling_available_governors
105 # Exit if cpu isn't managed by cpufreq core
106 if [ ! -f $filepath ]; then
110 echo $1 > $CPUFREQROOT/$policy/scaling_governor
113 printf "Switched governor to $1.\n"
116 # All amd-pstate tests
119 printf "\n=============================================\n"
120 printf "***** Running AMD P-state Sanity Tests *****\n"
121 printf "=============================================\n\n"
124 if [ $count = 0 ]; then
125 printf "No cpu is managed by cpufreq core, exiting\n"
128 printf "AMD P-state manages: $count CPUs\n"
131 # unit test for amd-pstate kernel driver
143 printf "Usage: $0 [OPTION...]
145 [-o <output-file-for-dump>]
146 [-c <all: All testing,
147 basic: Basic testing,
148 tbench: Tbench testing,
149 gitsource: Gitsource testing.>]
150 [-t <tbench time limit>]
151 [-p <tbench process number>]
152 [-l <loop times for tbench>]
153 [-i <amd tracer interval>]
154 [-m <comparative test: acpi-cpufreq>]
161 while getopts ho:c:t:p:l:i:m: arg
168 c) # --func_type (Function to perform: basic, tbench, gitsource (default: all))
172 o) # --output-file (Output file to store dumps)
176 t) # --tbench-time-limit
180 p) # --tbench-process-number
184 l) # --tbench/gitsource-loop-times
188 i) # --amd-tracer-interval
189 TRACER_INTERVAL=$OPTARG
192 m) # --comparative-test
193 COMPARATIVE_TEST=$OPTARG
205 if ! command -v perf > /dev/null; then
206 echo $msg please install perf. >&2
213 if ! command -v tbench > /dev/null; then
214 if apt policy dbench > /dev/null 2>&1; then
215 echo $msg apt install dbench >&2
217 elif yum list available | grep dbench > /dev/null 2>&1; then
218 echo $msg yum install dbench >&2
223 if ! command -v tbench > /dev/null; then
224 echo $msg please install tbench. >&2
231 if ! echo "$ARCH" | grep -q x86; then
232 echo "$0 # Skipped: Test can only run on x86 architectures."
236 if ! echo "$VENDOR" | grep -iq amd; then
237 echo "$0 # Skipped: Test can only run on AMD CPU."
238 echo "$0 # Current cpu vendor is $VENDOR."
242 scaling_driver=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_driver)
243 if [ "$COMPARATIVE_TEST" = "" ]; then
244 if [ "$scaling_driver" != "$CURRENT_TEST" ]; then
245 echo "$0 # Skipped: Test can only run on $CURRENT_TEST driver or run comparative test."
246 echo "$0 # Please set X86_AMD_PSTATE enabled or run comparative test."
247 echo "$0 # Current cpufreq scaling driver is $scaling_driver."
252 "tbench" | "gitsource")
253 if [ "$scaling_driver" != "$COMPARATIVE_TEST" ]; then
254 echo "$0 # Skipped: Comparison test can only run on $COMPARISON_TEST driver."
255 echo "$0 # Current cpufreq scaling driver is $scaling_driver."
261 echo "$0 # Skipped: Comparison test are only for tbench or gitsource."
262 echo "$0 # Current comparative test is for $FUNC."
268 if [ ! -w /dev ]; then
269 echo $msg please run this as root >&2
289 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
291 if [ ! -d "$SYSFS" ]; then
292 echo $msg sysfs is not mounted >&2
296 CPUROOT=$SYSFS/devices/system/cpu
297 CPUFREQROOT="$CPUROOT/cpufreq"
299 if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
300 echo $msg cpus not available in sysfs >&2
304 if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
305 echo $msg cpufreq directory not available in sysfs >&2
312 # Check if CPUs are managed by cpufreq or not
314 MAKE_CPUS=$((count*2))
316 if [ $count = 0 ]; then
317 echo "No cpu is managed by cpufreq core, exiting"
339 echo "Invalid [-f] function type"
351 rm -rf $OUTFILE.backup_governor.log
357 rm -rf $OUTFILE.backup_governor.log
363 rm -rf $OUTFILE.backup_governor.log
364 rm -rf gitsource_*.png
375 rm -rf $OUTFILE.backup_governor.log
381 # Make sure all requirements are met
384 # Run requested functions
386 do_test | tee -a $OUTFILE.log