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