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