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