~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/cpufreq/governor.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # Test governors
  5 
  6 # protect against multiple inclusion
  7 if [ $FILE_GOVERNOR ]; then
  8         return 0
  9 else
 10         FILE_GOVERNOR=DONE
 11 fi
 12 
 13 source cpu.sh
 14 source cpufreq.sh
 15 
 16 CUR_GOV=
 17 CUR_FREQ=
 18 
 19 # Find governor's directory path
 20 # $1: policy, $2: governor
 21 find_gov_directory()
 22 {
 23         if [ -d $CPUFREQROOT/$2 ]; then
 24                 printf "$CPUFREQROOT/$2\n"
 25         elif [ -d $CPUFREQROOT/$1/$2 ]; then
 26                 printf "$CPUFREQROOT/$1/$2\n"
 27         else
 28                 printf "INVALID\n"
 29         fi
 30 }
 31 
 32 # $1: policy
 33 find_current_governor()
 34 {
 35         cat $CPUFREQROOT/$1/scaling_governor
 36 }
 37 
 38 # $1: policy
 39 backup_governor()
 40 {
 41         CUR_GOV=$(find_current_governor $1)
 42 
 43         printf "Governor backup done for $1: $CUR_GOV\n"
 44 
 45         if [ $CUR_GOV == "userspace" ]; then
 46                 CUR_FREQ=$(find_current_freq $1)
 47                 printf "Governor frequency backup done for $1: $CUR_FREQ\n"
 48         fi
 49 
 50         printf "\n"
 51 }
 52 
 53 # $1: policy
 54 restore_governor()
 55 {
 56         __switch_governor $1 $CUR_GOV
 57 
 58         printf "Governor restored for $1 to $CUR_GOV\n"
 59 
 60         if [ $CUR_GOV == "userspace" ]; then
 61                 set_cpu_frequency $1 $CUR_FREQ
 62                 printf "Governor frequency restored for $1: $CUR_FREQ\n"
 63         fi
 64 
 65         printf "\n"
 66 }
 67 
 68 # param:
 69 # $1: policy, $2: governor
 70 __switch_governor()
 71 {
 72         echo $2 > $CPUFREQROOT/$1/scaling_governor
 73 }
 74 
 75 # param:
 76 # $1: cpu, $2: governor
 77 __switch_governor_for_cpu()
 78 {
 79         echo $2 > $CPUROOT/$1/cpufreq/scaling_governor
 80 }
 81 
 82 # SWITCH GOVERNORS
 83 
 84 # $1: cpu, $2: governor
 85 switch_governor()
 86 {
 87         local filepath=$CPUFREQROOT/$1/scaling_available_governors
 88 
 89         # check if governor is available
 90         local found=$(cat $filepath | grep $2 | wc -l)
 91         if [ $found = 0 ]; then
 92                 echo 1;
 93                 return
 94         fi
 95 
 96         __switch_governor $1 $2
 97         echo 0;
 98 }
 99 
100 # $1: policy, $2: governor
101 switch_show_governor()
102 {
103         cur_gov=find_current_governor
104         if [ $cur_gov == "userspace" ]; then
105                 cur_freq=find_current_freq
106         fi
107 
108         # switch governor
109         __switch_governor $1 $2
110 
111         printf "\nSwitched governor for $1 to $2\n\n"
112 
113         if [ $2 == "userspace" -o $2 == "powersave" -o $2 == "performance" ]; then
114                 printf "No files to read for $2 governor\n\n"
115                 return
116         fi
117 
118         # show governor files
119         local govpath=$(find_gov_directory $1 $2)
120         read_cpufreq_files_in_dir $govpath
121 }
122 
123 # $1: function to be called, $2: policy
124 call_for_each_governor()
125 {
126         local filepath=$CPUFREQROOT/$2/scaling_available_governors
127 
128         # Exit if cpu isn't managed by cpufreq core
129         if [ ! -f $filepath ]; then
130                 return;
131         fi
132 
133         backup_governor $2
134 
135         local governors=$(cat $filepath)
136         printf "Available governors for $2: $governors\n"
137 
138         for governor in $governors; do
139                 $1 $2 $governor
140         done
141 
142         restore_governor $2
143 }
144 
145 # $1: loop count
146 shuffle_governors_for_all_cpus()
147 {
148         printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
149 
150         for i in `seq 1 $1`; do
151                 for_each_policy call_for_each_governor switch_show_governor
152         done
153         printf "%s\n\n" "------------------------------------------------"
154 }

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php