1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 # protect against multiple inclusion 4 # protect against multiple inclusion 5 if [ $FILE_MAIN ]; then 5 if [ $FILE_MAIN ]; then 6 return 0 6 return 0 7 else 7 else 8 FILE_MAIN=DONE 8 FILE_MAIN=DONE 9 fi 9 fi 10 10 11 SCRIPTDIR=`dirname "$0"` 11 SCRIPTDIR=`dirname "$0"` 12 TRACER=$SCRIPTDIR/../../../power/x86/amd_pstat 12 TRACER=$SCRIPTDIR/../../../power/x86/amd_pstate_tracer/amd_pstate_trace.py 13 13 14 source $SCRIPTDIR/basic.sh 14 source $SCRIPTDIR/basic.sh 15 source $SCRIPTDIR/tbench.sh 15 source $SCRIPTDIR/tbench.sh 16 source $SCRIPTDIR/gitsource.sh 16 source $SCRIPTDIR/gitsource.sh 17 17 18 # amd-pstate-ut only run on x86/x86_64 AMD sys 18 # amd-pstate-ut only run on x86/x86_64 AMD systems. 19 ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x 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 20 VENDOR=$(cat /proc/cpuinfo | grep -m 1 'vendor_id' | awk '{print $NF}') 21 21 22 msg="Skip all tests:" 22 msg="Skip all tests:" 23 FUNC=all 23 FUNC=all 24 OUTFILE=selftest 24 OUTFILE=selftest 25 OUTFILE_TBENCH="$OUTFILE.tbench" 25 OUTFILE_TBENCH="$OUTFILE.tbench" 26 OUTFILE_GIT="$OUTFILE.gitsource" 26 OUTFILE_GIT="$OUTFILE.gitsource" 27 27 28 PERF=/usr/bin/perf 28 PERF=/usr/bin/perf 29 SYSFS= 29 SYSFS= 30 CPUROOT= 30 CPUROOT= 31 CPUFREQROOT= 31 CPUFREQROOT= 32 MAKE_CPUS= 32 MAKE_CPUS= 33 33 34 TIME_LIMIT=100 34 TIME_LIMIT=100 35 PROCESS_NUM=128 35 PROCESS_NUM=128 36 LOOP_TIMES=3 36 LOOP_TIMES=3 37 TRACER_INTERVAL=10 37 TRACER_INTERVAL=10 38 CURRENT_TEST=amd-pstate 38 CURRENT_TEST=amd-pstate 39 COMPARATIVE_TEST= 39 COMPARATIVE_TEST= 40 40 41 # Kselftest framework requirement - SKIP code 41 # Kselftest framework requirement - SKIP code is 4. 42 ksft_skip=4 42 ksft_skip=4 43 all_scaling_names=("acpi-cpufreq" "amd-pstate" 43 all_scaling_names=("acpi-cpufreq" "amd-pstate") 44 44 45 # Get current cpufreq scaling driver name 45 # Get current cpufreq scaling driver name 46 scaling_name() 46 scaling_name() 47 { 47 { 48 if [ "$COMPARATIVE_TEST" = "" ]; then 48 if [ "$COMPARATIVE_TEST" = "" ]; then 49 echo "$CURRENT_TEST" 49 echo "$CURRENT_TEST" 50 else 50 else 51 echo "$COMPARATIVE_TEST" 51 echo "$COMPARATIVE_TEST" 52 fi 52 fi 53 } 53 } 54 54 55 # Counts CPUs with cpufreq directories 55 # Counts CPUs with cpufreq directories 56 count_cpus() 56 count_cpus() 57 { 57 { 58 count=0; 58 count=0; 59 59 60 for cpu in `ls $CPUROOT | grep "cpu[0- 60 for cpu in `ls $CPUROOT | grep "cpu[0-9].*"`; do 61 if [ -d $CPUROOT/$cpu/cpufreq 61 if [ -d $CPUROOT/$cpu/cpufreq ]; then 62 let count=count+1; 62 let count=count+1; 63 fi 63 fi 64 done 64 done 65 65 66 echo $count; 66 echo $count; 67 } 67 } 68 68 69 # $1: policy 69 # $1: policy 70 find_current_governor() 70 find_current_governor() 71 { 71 { 72 cat $CPUFREQROOT/$1/scaling_governor 72 cat $CPUFREQROOT/$1/scaling_governor 73 } 73 } 74 74 75 backup_governor() 75 backup_governor() 76 { 76 { 77 policies=$(ls $CPUFREQROOT| grep "poli 77 policies=$(ls $CPUFREQROOT| grep "policy[0-9].*") 78 for policy in $policies; do 78 for policy in $policies; do 79 cur_gov=$(find_current_governo 79 cur_gov=$(find_current_governor $policy) 80 echo "$policy $cur_gov" >> $OU 80 echo "$policy $cur_gov" >> $OUTFILE.backup_governor.log 81 done 81 done 82 82 83 printf "Governor $cur_gov backup done. 83 printf "Governor $cur_gov backup done.\n" 84 } 84 } 85 85 86 restore_governor() 86 restore_governor() 87 { 87 { 88 i=0; 88 i=0; 89 89 90 policies=$(awk '{print $1}' $OUTFILE.b 90 policies=$(awk '{print $1}' $OUTFILE.backup_governor.log) 91 for policy in $policies; do 91 for policy in $policies; do 92 let i++; 92 let i++; 93 governor=$(sed -n ''$i'p' $OUT 93 governor=$(sed -n ''$i'p' $OUTFILE.backup_governor.log | awk '{print $2}') 94 94 95 # switch governor 95 # switch governor 96 echo $governor > $CPUFREQROOT/ 96 echo $governor > $CPUFREQROOT/$policy/scaling_governor 97 done 97 done 98 98 99 printf "Governor restored to $governor 99 printf "Governor restored to $governor.\n" 100 } 100 } 101 101 102 # $1: governor 102 # $1: governor 103 switch_governor() 103 switch_governor() 104 { 104 { 105 policies=$(ls $CPUFREQROOT| grep "poli 105 policies=$(ls $CPUFREQROOT| grep "policy[0-9].*") 106 for policy in $policies; do 106 for policy in $policies; do 107 filepath=$CPUFREQROOT/$policy/ 107 filepath=$CPUFREQROOT/$policy/scaling_available_governors 108 108 109 # Exit if cpu isn't managed by 109 # Exit if cpu isn't managed by cpufreq core 110 if [ ! -f $filepath ]; then 110 if [ ! -f $filepath ]; then 111 return; 111 return; 112 fi 112 fi 113 113 114 echo $1 > $CPUFREQROOT/$policy 114 echo $1 > $CPUFREQROOT/$policy/scaling_governor 115 done 115 done 116 116 117 printf "Switched governor to $1.\n" 117 printf "Switched governor to $1.\n" 118 } 118 } 119 119 120 # All amd-pstate tests 120 # All amd-pstate tests 121 amd_pstate_all() 121 amd_pstate_all() 122 { 122 { 123 printf "\n============================ 123 printf "\n=============================================\n" 124 printf "***** Running AMD P-state Sani 124 printf "***** Running AMD P-state Sanity Tests *****\n" 125 printf "============================== 125 printf "=============================================\n\n" 126 126 127 count=$(count_cpus) 127 count=$(count_cpus) 128 if [ $count = 0 ]; then 128 if [ $count = 0 ]; then 129 printf "No cpu is managed by c 129 printf "No cpu is managed by cpufreq core, exiting\n" 130 exit; 130 exit; 131 else 131 else 132 printf "AMD P-state manages: $ 132 printf "AMD P-state manages: $count CPUs\n" 133 fi 133 fi 134 134 135 # unit test for amd-pstate kernel driv 135 # unit test for amd-pstate kernel driver 136 amd_pstate_basic 136 amd_pstate_basic 137 137 138 # tbench 138 # tbench 139 amd_pstate_tbench 139 amd_pstate_tbench 140 140 141 # gitsource 141 # gitsource 142 amd_pstate_gitsource 142 amd_pstate_gitsource 143 } 143 } 144 144 145 help() 145 help() 146 { 146 { 147 printf "Usage: $0 [OPTION...] 147 printf "Usage: $0 [OPTION...] 148 [-h <help>] 148 [-h <help>] 149 [-o <output-file-for-dump>] 149 [-o <output-file-for-dump>] 150 [-c <all: All testing, 150 [-c <all: All testing, 151 basic: Basic testing, 151 basic: Basic testing, 152 tbench: Tbench testing, 152 tbench: Tbench testing, 153 gitsource: Gitsource testing.>] 153 gitsource: Gitsource testing.>] 154 [-t <tbench time limit>] 154 [-t <tbench time limit>] 155 [-p <tbench process number>] 155 [-p <tbench process number>] 156 [-l <loop times for tbench>] 156 [-l <loop times for tbench>] 157 [-i <amd tracer interval>] 157 [-i <amd tracer interval>] 158 [-b <perf binary>] 158 [-b <perf binary>] 159 [-m <comparative test: acpi-cpufreq>] 159 [-m <comparative test: acpi-cpufreq>] 160 \n" 160 \n" 161 exit 2 161 exit 2 162 } 162 } 163 163 164 parse_arguments() 164 parse_arguments() 165 { 165 { 166 while getopts ho:c:t:p:l:i:b:m: arg 166 while getopts ho:c:t:p:l:i:b:m: arg 167 do 167 do 168 case $arg in 168 case $arg in 169 h) # --help 169 h) # --help 170 help 170 help 171 ;; 171 ;; 172 172 173 c) # --func_type (Func 173 c) # --func_type (Function to perform: basic, tbench, gitsource (default: all)) 174 FUNC=$OPTARG 174 FUNC=$OPTARG 175 ;; 175 ;; 176 176 177 o) # --output-file (Ou 177 o) # --output-file (Output file to store dumps) 178 OUTFILE=$OPTAR 178 OUTFILE=$OPTARG 179 ;; 179 ;; 180 180 181 t) # --tbench-time-lim 181 t) # --tbench-time-limit 182 TIME_LIMIT=$OP 182 TIME_LIMIT=$OPTARG 183 ;; 183 ;; 184 184 185 p) # --tbench-process- 185 p) # --tbench-process-number 186 PROCESS_NUM=$O 186 PROCESS_NUM=$OPTARG 187 ;; 187 ;; 188 188 189 l) # --tbench/gitsourc 189 l) # --tbench/gitsource-loop-times 190 LOOP_TIMES=$OP 190 LOOP_TIMES=$OPTARG 191 ;; 191 ;; 192 192 193 i) # --amd-tracer-inte 193 i) # --amd-tracer-interval 194 TRACER_INTERVA 194 TRACER_INTERVAL=$OPTARG 195 ;; 195 ;; 196 196 197 b) # --perf-binary 197 b) # --perf-binary 198 PERF=`realpath 198 PERF=`realpath $OPTARG` 199 ;; 199 ;; 200 200 201 m) # --comparative-tes 201 m) # --comparative-test 202 COMPARATIVE_TE 202 COMPARATIVE_TEST=$OPTARG 203 ;; 203 ;; 204 204 205 *) 205 *) 206 help 206 help 207 ;; 207 ;; 208 esac 208 esac 209 done 209 done 210 } 210 } 211 211 212 command_perf() 212 command_perf() 213 { 213 { 214 if ! $PERF -v; then 214 if ! $PERF -v; then 215 echo $msg please install perf 215 echo $msg please install perf or provide perf binary path as argument >&2 216 exit $ksft_skip 216 exit $ksft_skip 217 fi 217 fi 218 } 218 } 219 219 220 command_tbench() 220 command_tbench() 221 { 221 { 222 if ! command -v tbench > /dev/null; th 222 if ! command -v tbench > /dev/null; then 223 if apt policy dbench > /dev/nu 223 if apt policy dbench > /dev/null 2>&1; then 224 echo $msg apt install 224 echo $msg apt install dbench >&2 225 exit $ksft_skip 225 exit $ksft_skip 226 elif yum list available | grep 226 elif yum list available | grep dbench > /dev/null 2>&1; then 227 echo $msg yum install 227 echo $msg yum install dbench >&2 228 exit $ksft_skip 228 exit $ksft_skip 229 fi 229 fi 230 fi 230 fi 231 231 232 if ! command -v tbench > /dev/null; th 232 if ! command -v tbench > /dev/null; then 233 echo $msg please install tbenc 233 echo $msg please install tbench. >&2 234 exit $ksft_skip 234 exit $ksft_skip 235 fi 235 fi 236 } 236 } 237 237 238 prerequisite() 238 prerequisite() 239 { 239 { 240 if ! echo "$ARCH" | grep -q x86; then 240 if ! echo "$ARCH" | grep -q x86; then 241 echo "$0 # Skipped: Test can o 241 echo "$0 # Skipped: Test can only run on x86 architectures." 242 exit $ksft_skip 242 exit $ksft_skip 243 fi 243 fi 244 244 245 if ! echo "$VENDOR" | grep -iq amd; th 245 if ! echo "$VENDOR" | grep -iq amd; then 246 echo "$0 # Skipped: Test can o 246 echo "$0 # Skipped: Test can only run on AMD CPU." 247 echo "$0 # Current cpu vendor 247 echo "$0 # Current cpu vendor is $VENDOR." 248 exit $ksft_skip 248 exit $ksft_skip 249 fi 249 fi 250 250 251 scaling_driver=$(cat /sys/devices/syst 251 scaling_driver=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_driver) 252 if [ "$COMPARATIVE_TEST" = "" ]; then 252 if [ "$COMPARATIVE_TEST" = "" ]; then 253 if [ "$scaling_driver" != "$CU 253 if [ "$scaling_driver" != "$CURRENT_TEST" ]; then 254 echo "$0 # Skipped: Te 254 echo "$0 # Skipped: Test can only run on $CURRENT_TEST driver or run comparative test." 255 echo "$0 # Please set 255 echo "$0 # Please set X86_AMD_PSTATE enabled or run comparative test." 256 echo "$0 # Current cpu 256 echo "$0 # Current cpufreq scaling driver is $scaling_driver." 257 exit $ksft_skip 257 exit $ksft_skip 258 fi 258 fi 259 else 259 else 260 case "$FUNC" in 260 case "$FUNC" in 261 "tbench" | "gitsource" 261 "tbench" | "gitsource") 262 if [ "$scaling 262 if [ "$scaling_driver" != "$COMPARATIVE_TEST" ]; then 263 echo " 263 echo "$0 # Skipped: Comparison test can only run on $COMPARISON_TEST driver." 264 echo " 264 echo "$0 # Current cpufreq scaling driver is $scaling_driver." 265 exit $ 265 exit $ksft_skip 266 fi 266 fi 267 ;; 267 ;; 268 268 269 *) 269 *) 270 echo "$0 # Ski 270 echo "$0 # Skipped: Comparison test are only for tbench or gitsource." 271 echo "$0 # Cur 271 echo "$0 # Current comparative test is for $FUNC." 272 exit $ksft_ski 272 exit $ksft_skip 273 ;; 273 ;; 274 esac 274 esac 275 fi 275 fi 276 276 277 if [ ! -w /dev ]; then 277 if [ ! -w /dev ]; then 278 echo $msg please run this as r 278 echo $msg please run this as root >&2 279 exit $ksft_skip 279 exit $ksft_skip 280 fi 280 fi 281 281 282 case "$FUNC" in 282 case "$FUNC" in 283 "all") 283 "all") 284 command_perf 284 command_perf 285 command_tbench 285 command_tbench 286 ;; 286 ;; 287 287 288 "tbench") 288 "tbench") 289 command_perf 289 command_perf 290 command_tbench 290 command_tbench 291 ;; 291 ;; 292 292 293 "gitsource") 293 "gitsource") 294 command_perf 294 command_perf 295 ;; 295 ;; 296 esac 296 esac 297 297 298 SYSFS=`mount -t sysfs | head -1 | awk 298 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` 299 299 300 if [ ! -d "$SYSFS" ]; then 300 if [ ! -d "$SYSFS" ]; then 301 echo $msg sysfs is not mounted 301 echo $msg sysfs is not mounted >&2 302 exit 2 302 exit 2 303 fi 303 fi 304 304 305 CPUROOT=$SYSFS/devices/system/cpu 305 CPUROOT=$SYSFS/devices/system/cpu 306 CPUFREQROOT="$CPUROOT/cpufreq" 306 CPUFREQROOT="$CPUROOT/cpufreq" 307 307 308 if ! ls $CPUROOT/cpu* > /dev/null 2>&1 308 if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then 309 echo $msg cpus not available i 309 echo $msg cpus not available in sysfs >&2 310 exit 2 310 exit 2 311 fi 311 fi 312 312 313 if ! ls $CPUROOT/cpufreq > /dev/null 2 313 if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then 314 echo $msg cpufreq directory no 314 echo $msg cpufreq directory not available in sysfs >&2 315 exit 2 315 exit 2 316 fi 316 fi 317 } 317 } 318 318 319 do_test() 319 do_test() 320 { 320 { 321 # Check if CPUs are managed by cpufreq 321 # Check if CPUs are managed by cpufreq or not 322 count=$(count_cpus) 322 count=$(count_cpus) 323 MAKE_CPUS=$((count*2)) 323 MAKE_CPUS=$((count*2)) 324 324 325 if [ $count = 0 ]; then 325 if [ $count = 0 ]; then 326 echo "No cpu is managed by cpu 326 echo "No cpu is managed by cpufreq core, exiting" 327 exit 2; 327 exit 2; 328 fi 328 fi 329 329 330 case "$FUNC" in 330 case "$FUNC" in 331 "all") 331 "all") 332 amd_pstate_all 332 amd_pstate_all 333 ;; 333 ;; 334 334 335 "basic") 335 "basic") 336 amd_pstate_basic 336 amd_pstate_basic 337 ;; 337 ;; 338 338 339 "tbench") 339 "tbench") 340 amd_pstate_tbench 340 amd_pstate_tbench 341 ;; 341 ;; 342 342 343 "gitsource") 343 "gitsource") 344 amd_pstate_gitsource 344 amd_pstate_gitsource 345 ;; 345 ;; 346 346 347 *) 347 *) 348 echo "Invalid [-f] fun 348 echo "Invalid [-f] function type" 349 help 349 help 350 ;; 350 ;; 351 esac 351 esac 352 } 352 } 353 353 354 # clear dumps 354 # clear dumps 355 pre_clear_dumps() 355 pre_clear_dumps() 356 { 356 { 357 case "$FUNC" in 357 case "$FUNC" in 358 "all") 358 "all") 359 rm -rf $OUTFILE.log 359 rm -rf $OUTFILE.log 360 rm -rf $OUTFILE.backup 360 rm -rf $OUTFILE.backup_governor.log 361 rm -rf *.png 361 rm -rf *.png 362 ;; 362 ;; 363 363 364 "tbench") 364 "tbench") 365 rm -rf $OUTFILE.log 365 rm -rf $OUTFILE.log 366 rm -rf $OUTFILE.backup 366 rm -rf $OUTFILE.backup_governor.log 367 rm -rf tbench_*.png 367 rm -rf tbench_*.png 368 ;; 368 ;; 369 369 370 "gitsource") 370 "gitsource") 371 rm -rf $OUTFILE.log 371 rm -rf $OUTFILE.log 372 rm -rf $OUTFILE.backup 372 rm -rf $OUTFILE.backup_governor.log 373 rm -rf gitsource_*.png 373 rm -rf gitsource_*.png 374 ;; 374 ;; 375 375 376 *) 376 *) 377 ;; 377 ;; 378 esac 378 esac 379 } 379 } 380 380 381 post_clear_dumps() 381 post_clear_dumps() 382 { 382 { 383 rm -rf $OUTFILE.log 383 rm -rf $OUTFILE.log 384 rm -rf $OUTFILE.backup_governor.log 384 rm -rf $OUTFILE.backup_governor.log 385 } 385 } 386 386 387 # Parse arguments 387 # Parse arguments 388 parse_arguments $@ 388 parse_arguments $@ 389 389 390 # Make sure all requirements are met 390 # Make sure all requirements are met 391 prerequisite 391 prerequisite 392 392 393 # Run requested functions 393 # Run requested functions 394 pre_clear_dumps 394 pre_clear_dumps 395 do_test | tee -a $OUTFILE.log 395 do_test | tee -a $OUTFILE.log 396 post_clear_dumps 396 post_clear_dumps
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.