1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 << 3 # 2 # 4 # CPU helpers 3 # CPU helpers 5 4 6 # protect against multiple inclusion 5 # protect against multiple inclusion 7 if [ $FILE_CPU ]; then 6 if [ $FILE_CPU ]; then 8 return 0 7 return 0 9 else 8 else 10 FILE_CPU=DONE 9 FILE_CPU=DONE 11 fi 10 fi 12 11 13 source cpufreq.sh 12 source cpufreq.sh 14 13 15 for_each_cpu() 14 for_each_cpu() 16 { 15 { 17 cpus=$(ls $CPUROOT | grep "cpu[0-9].*" 16 cpus=$(ls $CPUROOT | grep "cpu[0-9].*") 18 for cpu in $cpus; do 17 for cpu in $cpus; do 19 $@ $cpu 18 $@ $cpu 20 done 19 done 21 } 20 } 22 21 23 for_each_non_boot_cpu() 22 for_each_non_boot_cpu() 24 { 23 { 25 cpus=$(ls $CPUROOT | grep "cpu[1-9].*" 24 cpus=$(ls $CPUROOT | grep "cpu[1-9].*") 26 for cpu in $cpus; do 25 for cpu in $cpus; do 27 $@ $cpu 26 $@ $cpu 28 done 27 done 29 } 28 } 30 29 31 #$1: cpu 30 #$1: cpu 32 offline_cpu() 31 offline_cpu() 33 { 32 { 34 printf "Offline $1\n" 33 printf "Offline $1\n" 35 echo 0 > $CPUROOT/$1/online 34 echo 0 > $CPUROOT/$1/online 36 } 35 } 37 36 38 #$1: cpu 37 #$1: cpu 39 online_cpu() 38 online_cpu() 40 { 39 { 41 printf "Online $1\n" 40 printf "Online $1\n" 42 echo 1 > $CPUROOT/$1/online 41 echo 1 > $CPUROOT/$1/online 43 } 42 } 44 43 45 #$1: cpu 44 #$1: cpu 46 reboot_cpu() 45 reboot_cpu() 47 { 46 { 48 offline_cpu $1 47 offline_cpu $1 49 online_cpu $1 48 online_cpu $1 50 } 49 } 51 50 52 # Reboot CPUs 51 # Reboot CPUs 53 # param: number of times we want to run the lo 52 # param: number of times we want to run the loop 54 reboot_cpus() 53 reboot_cpus() 55 { 54 { 56 printf "** Test: Running ${FUNCNAME[0] 55 printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n" 57 56 58 for i in `seq 1 $1`; do 57 for i in `seq 1 $1`; do 59 for_each_non_boot_cpu offline_ 58 for_each_non_boot_cpu offline_cpu 60 for_each_non_boot_cpu online_c 59 for_each_non_boot_cpu online_cpu 61 printf "\n" 60 printf "\n" 62 done 61 done 63 62 64 printf "\n%s\n\n" "------------------- 63 printf "\n%s\n\n" "------------------------------------------------" 65 } 64 } 66 65 67 # Prints warning for all CPUs with missing cpu 66 # Prints warning for all CPUs with missing cpufreq directory 68 print_unmanaged_cpus() 67 print_unmanaged_cpus() 69 { 68 { 70 for_each_cpu cpu_should_have_cpufreq_d 69 for_each_cpu cpu_should_have_cpufreq_directory 71 } 70 } 72 71 73 # Counts CPUs with cpufreq directories 72 # Counts CPUs with cpufreq directories 74 count_cpufreq_managed_cpus() 73 count_cpufreq_managed_cpus() 75 { 74 { 76 count=0; 75 count=0; 77 76 78 for cpu in `ls $CPUROOT | grep "cpu[0- 77 for cpu in `ls $CPUROOT | grep "cpu[0-9].*"`; do 79 if [ -d $CPUROOT/$cpu/cpufreq 78 if [ -d $CPUROOT/$cpu/cpufreq ]; then 80 let count=count+1; 79 let count=count+1; 81 fi 80 fi 82 done 81 done 83 82 84 echo $count; 83 echo $count; 85 } 84 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.