2 # SPDX-License-Identifier: GPL-2.0
6 # protect against multiple inclusion
7 if [ $FILE_GOVERNOR ]; then
19 # Find governor's directory path
20 # $1: policy, $2: governor
23 if [ -d $CPUFREQROOT/$2 ]; then
24 printf "$CPUFREQROOT/$2\n"
25 elif [ -d $CPUFREQROOT/$1/$2 ]; then
26 printf "$CPUFREQROOT/$1/$2\n"
33 find_current_governor
()
35 cat $CPUFREQROOT/$1/scaling_governor
41 CUR_GOV
=$
(find_current_governor
$1)
43 printf "Governor backup done for $1: $CUR_GOV\n"
45 if [ $CUR_GOV == "userspace" ]; then
46 CUR_FREQ
=$
(find_current_freq
$1)
47 printf "Governor frequency backup done for $1: $CUR_FREQ\n"
56 __switch_governor
$1 $CUR_GOV
58 printf "Governor restored for $1 to $CUR_GOV\n"
60 if [ $CUR_GOV == "userspace" ]; then
61 set_cpu_frequency
$1 $CUR_FREQ
62 printf "Governor frequency restored for $1: $CUR_FREQ\n"
69 # $1: policy, $2: governor
72 echo $2 > $CPUFREQROOT/$1/scaling_governor
76 # $1: cpu, $2: governor
77 __switch_governor_for_cpu
()
79 echo $2 > $CPUROOT/$1/cpufreq
/scaling_governor
84 # $1: cpu, $2: governor
87 local filepath
=$CPUFREQROOT/$1/scaling_available_governors
89 # check if governor is available
90 local found
=$
(cat $filepath |
grep $2 |
wc -l)
91 if [ $found = 0 ]; then
96 __switch_governor
$1 $2
100 # $1: policy, $2: governor
101 switch_show_governor
()
103 cur_gov
=find_current_governor
104 if [ $cur_gov == "userspace" ]; then
105 cur_freq
=find_current_freq
109 __switch_governor
$1 $2
111 printf "\nSwitched governor for $1 to $2\n\n"
113 if [ $2 == "userspace" -o $2 == "powersave" -o $2 == "performance" ]; then
114 printf "No files to read for $2 governor\n\n"
118 # show governor files
119 local govpath
=$
(find_gov_directory
$1 $2)
120 read_cpufreq_files_in_dir
$govpath
123 # $1: function to be called, $2: policy
124 call_for_each_governor
()
126 local filepath
=$CPUFREQROOT/$2/scaling_available_governors
128 # Exit if cpu isn't managed by cpufreq core
129 if [ ! -f $filepath ]; then
135 local governors
=$
(cat $filepath)
136 printf "Available governors for $2: $governors\n"
138 for governor
in $governors; do
146 shuffle_governors_for_all_cpus
()
148 printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
150 for i
in `seq 1 $1`; do
151 for_each_policy call_for_each_governor switch_show_governor
153 printf "%s\n\n" "------------------------------------------------"