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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/cpufreq/cpufreq.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 ] ~

Diff markup

Differences between /tools/testing/selftests/cpufreq/cpufreq.sh (Version linux-6.12-rc7) and /tools/testing/selftests/cpufreq/cpufreq.sh (Version linux-4.13.16)


  1 #!/bin/bash                                         1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0             << 
  3                                                     2 
  4 # protect against multiple inclusion                3 # protect against multiple inclusion
  5 if [ $FILE_CPUFREQ ]; then                          4 if [ $FILE_CPUFREQ ]; then
  6         return 0                                    5         return 0
  7 else                                                6 else
  8         FILE_CPUFREQ=DONE                           7         FILE_CPUFREQ=DONE
  9 fi                                                  8 fi
 10                                                     9 
 11 source cpu.sh                                      10 source cpu.sh
 12                                                    11 
 13                                                    12 
 14 # $1: cpu                                          13 # $1: cpu
 15 cpu_should_have_cpufreq_directory()                14 cpu_should_have_cpufreq_directory()
 16 {                                                  15 {
 17         if [ ! -d $CPUROOT/$1/cpufreq ]; then      16         if [ ! -d $CPUROOT/$1/cpufreq ]; then
 18                 printf "Warning: No cpufreq di     17                 printf "Warning: No cpufreq directory present for $1\n"
 19         fi                                         18         fi
 20 }                                                  19 }
 21                                                    20 
 22 cpu_should_not_have_cpufreq_directory()            21 cpu_should_not_have_cpufreq_directory()
 23 {                                                  22 {
 24         if [ -d $CPUROOT/$1/cpufreq ]; then        23         if [ -d $CPUROOT/$1/cpufreq ]; then
 25                 printf "Warning: cpufreq direc     24                 printf "Warning: cpufreq directory present for $1\n"
 26         fi                                         25         fi
 27 }                                                  26 }
 28                                                    27 
 29 for_each_policy()                                  28 for_each_policy()
 30 {                                                  29 {
 31         policies=$(ls $CPUFREQROOT| grep "poli     30         policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
 32         for policy in $policies; do                31         for policy in $policies; do
 33                 $@ $policy                         32                 $@ $policy
 34         done                                       33         done
 35 }                                                  34 }
 36                                                    35 
 37 for_each_policy_concurrent()                       36 for_each_policy_concurrent()
 38 {                                                  37 {
 39         policies=$(ls $CPUFREQROOT| grep "poli     38         policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
 40         for policy in $policies; do                39         for policy in $policies; do
 41                 $@ $policy &                       40                 $@ $policy &
 42         done                                       41         done
 43 }                                                  42 }
 44                                                    43 
 45 # $1: Path                                         44 # $1: Path
 46 read_cpufreq_files_in_dir()                        45 read_cpufreq_files_in_dir()
 47 {                                                  46 {
 48         local files=`ls $1`                        47         local files=`ls $1`
 49                                                    48 
 50         printf "Printing directory: $1\n\n"        49         printf "Printing directory: $1\n\n"
 51                                                    50 
 52         for file in $files; do                     51         for file in $files; do
 53                 if [ -f $1/$file ]; then           52                 if [ -f $1/$file ]; then
 54                         printf "$file:"            53                         printf "$file:"
 55                         cat $1/$file               54                         cat $1/$file
 56                 else                               55                 else
 57                         printf "\n"                56                         printf "\n"
 58                         read_cpufreq_files_in_     57                         read_cpufreq_files_in_dir "$1/$file"
 59                 fi                                 58                 fi
 60         done                                       59         done
 61         printf "\n"                                60         printf "\n"
 62 }                                                  61 }
 63                                                    62 
 64                                                    63 
 65 read_all_cpufreq_files()                           64 read_all_cpufreq_files()
 66 {                                                  65 {
 67         printf "** Test: Running ${FUNCNAME[0]     66         printf "** Test: Running ${FUNCNAME[0]} **\n\n"
 68                                                    67 
 69         read_cpufreq_files_in_dir $CPUFREQROOT     68         read_cpufreq_files_in_dir $CPUFREQROOT
 70                                                    69 
 71         printf "%s\n\n" "---------------------     70         printf "%s\n\n" "------------------------------------------------"
 72 }                                                  71 }
 73                                                    72 
 74                                                    73 
 75 # UPDATE CPUFREQ FILES                             74 # UPDATE CPUFREQ FILES
 76                                                    75 
 77 # $1: directory path                               76 # $1: directory path
 78 update_cpufreq_files_in_dir()                      77 update_cpufreq_files_in_dir()
 79 {                                                  78 {
 80         local files=`ls $1`                        79         local files=`ls $1`
 81                                                    80 
 82         printf "Updating directory: $1\n\n"        81         printf "Updating directory: $1\n\n"
 83                                                    82 
 84         for file in $files; do                     83         for file in $files; do
 85                 if [ -f $1/$file ]; then           84                 if [ -f $1/$file ]; then
 86                         # file is writable ?       85                         # file is writable ?
 87                         local wfile=$(ls -l $1     86                         local wfile=$(ls -l $1/$file | awk '$1 ~ /^.*w.*/ { print $NF; }')
 88                                                    87 
 89                         if [ ! -z $wfile ]; th     88                         if [ ! -z $wfile ]; then
 90                                 # scaling_sets     89                                 # scaling_setspeed is a special file and we
 91                                 # should skip      90                                 # should skip updating it
 92                                 if [ $file !=      91                                 if [ $file != "scaling_setspeed" ]; then
 93                                         local      92                                         local val=$(cat $1/$file)
 94                                         printf     93                                         printf "Writing $val to: $file\n"
 95                                         echo $     94                                         echo $val > $1/$file
 96                                 fi                 95                                 fi
 97                         fi                         96                         fi
 98                 else                               97                 else
 99                         printf "\n"                98                         printf "\n"
100                         update_cpufreq_files_i     99                         update_cpufreq_files_in_dir "$1/$file"
101                 fi                                100                 fi
102         done                                      101         done
103                                                   102 
104         printf "\n"                               103         printf "\n"
105 }                                                 104 }
106                                                   105 
107 # Update all writable files with their existin    106 # Update all writable files with their existing values
108 update_all_cpufreq_files()                        107 update_all_cpufreq_files()
109 {                                                 108 {
110         printf "** Test: Running ${FUNCNAME[0]    109         printf "** Test: Running ${FUNCNAME[0]} **\n\n"
111                                                   110 
112         update_cpufreq_files_in_dir $CPUFREQRO    111         update_cpufreq_files_in_dir $CPUFREQROOT
113                                                   112 
114         printf "%s\n\n" "---------------------    113         printf "%s\n\n" "------------------------------------------------"
115 }                                                 114 }
116                                                   115 
117                                                   116 
118 # CHANGE CPU FREQUENCIES                          117 # CHANGE CPU FREQUENCIES
119                                                   118 
120 # $1: policy                                      119 # $1: policy
121 find_current_freq()                               120 find_current_freq()
122 {                                                 121 {
123         cat $CPUFREQROOT/$1/scaling_cur_freq      122         cat $CPUFREQROOT/$1/scaling_cur_freq
124 }                                                 123 }
125                                                   124 
126 # $1: policy                                      125 # $1: policy
127 # $2: frequency                                   126 # $2: frequency
128 set_cpu_frequency()                               127 set_cpu_frequency()
129 {                                                 128 {
130         printf "Change frequency for $1 to $2\    129         printf "Change frequency for $1 to $2\n"
131         echo $2 > $CPUFREQROOT/$1/scaling_sets    130         echo $2 > $CPUFREQROOT/$1/scaling_setspeed
132 }                                                 131 }
133                                                   132 
134 # $1: policy                                      133 # $1: policy
135 test_all_frequencies()                            134 test_all_frequencies()
136 {                                                 135 {
137         local filepath="$CPUFREQROOT/$1"          136         local filepath="$CPUFREQROOT/$1"
138                                                   137 
139         backup_governor $1                        138         backup_governor $1
140                                                   139 
141         local found=$(switch_governor $1 "user    140         local found=$(switch_governor $1 "userspace")
142         if [ $found = 1 ]; then                   141         if [ $found = 1 ]; then
143                 printf "${FUNCNAME[0]}: usersp    142                 printf "${FUNCNAME[0]}: userspace governor not available for: $1\n"
144                 return;                           143                 return;
145         fi                                        144         fi
146                                                   145 
147         printf "Switched governor for $1 to us    146         printf "Switched governor for $1 to userspace\n\n"
148                                                   147 
149         local freqs=$(cat $filepath/scaling_av    148         local freqs=$(cat $filepath/scaling_available_frequencies)
150         printf "Available frequencies for $1:     149         printf "Available frequencies for $1: $freqs\n\n"
151                                                   150 
152         # Set all frequencies one-by-one          151         # Set all frequencies one-by-one
153         for freq in $freqs; do                    152         for freq in $freqs; do
154                 set_cpu_frequency $1 $freq        153                 set_cpu_frequency $1 $freq
155         done                                      154         done
156                                                   155 
157         printf "\n"                               156         printf "\n"
158                                                   157 
159         restore_governor $1                       158         restore_governor $1
160 }                                                 159 }
161                                                   160 
162 # $1: loop count                                  161 # $1: loop count
163 shuffle_frequency_for_all_cpus()                  162 shuffle_frequency_for_all_cpus()
164 {                                                 163 {
165         printf "** Test: Running ${FUNCNAME[0]    164         printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
166                                                   165 
167         for i in `seq 1 $1`; do                   166         for i in `seq 1 $1`; do
168                 for_each_policy test_all_frequ    167                 for_each_policy test_all_frequencies
169         done                                      168         done
170         printf "\n%s\n\n" "-------------------    169         printf "\n%s\n\n" "------------------------------------------------"
171 }                                                 170 }
172                                                   171 
173 # Basic cpufreq tests                             172 # Basic cpufreq tests
174 cpufreq_basic_tests()                             173 cpufreq_basic_tests()
175 {                                                 174 {
176         printf "*** RUNNING CPUFREQ SANITY TES    175         printf "*** RUNNING CPUFREQ SANITY TESTS ***\n"
177         printf "==============================    176         printf "====================================\n\n"
178                                                   177 
179         count=$(count_cpufreq_managed_cpus)       178         count=$(count_cpufreq_managed_cpus)
180         if [ $count = 0 ]; then                   179         if [ $count = 0 ]; then
181                 ktap_exit_fail_msg "No cpu is  !! 180                 printf "No cpu is managed by cpufreq core, exiting\n"
                                                   >> 181                 exit;
182         else                                      182         else
183                 printf "CPUFreq manages: $coun    183                 printf "CPUFreq manages: $count CPUs\n\n"
184         fi                                        184         fi
185                                                   185 
186         # Detect & print which CPUs are not ma    186         # Detect & print which CPUs are not managed by cpufreq
187         print_unmanaged_cpus                      187         print_unmanaged_cpus
188                                                   188 
189         # read/update all cpufreq files           189         # read/update all cpufreq files
190         read_all_cpufreq_files                    190         read_all_cpufreq_files
191         update_all_cpufreq_files                  191         update_all_cpufreq_files
192                                                   192 
193         # hotplug cpus                            193         # hotplug cpus
194         reboot_cpus 5                             194         reboot_cpus 5
195                                                   195 
196         # Test all frequencies                    196         # Test all frequencies
197         shuffle_frequency_for_all_cpus 2          197         shuffle_frequency_for_all_cpus 2
198                                                   198 
199         # Test all governors                      199         # Test all governors
200         shuffle_governors_for_all_cpus 1          200         shuffle_governors_for_all_cpus 1
201 }                                                 201 }
202                                                   202 
203 # Suspend/resume                                  203 # Suspend/resume
204 # $1: "suspend" or "hibernate", $2: loop count    204 # $1: "suspend" or "hibernate", $2: loop count
205 do_suspend()                                      205 do_suspend()
206 {                                                 206 {
207         printf "** Test: Running ${FUNCNAME[0]    207         printf "** Test: Running ${FUNCNAME[0]}: Trying $1 for $2 loops **\n\n"
208                                                   208 
209         # Is the directory available              209         # Is the directory available
210         if [ ! -d $SYSFS/power/ -o ! -f $SYSFS    210         if [ ! -d $SYSFS/power/ -o ! -f $SYSFS/power/state ]; then
211                 printf "$SYSFS/power/state not    211                 printf "$SYSFS/power/state not available\n"
212                 return 1                          212                 return 1
213         fi                                        213         fi
214                                                   214 
215         if [ $1 = "suspend" ]; then               215         if [ $1 = "suspend" ]; then
216                 filename="mem"                    216                 filename="mem"
217         elif [ $1 = "hibernate" ]; then           217         elif [ $1 = "hibernate" ]; then
218                 filename="disk"                   218                 filename="disk"
219         else                                      219         else
220                 printf "$1 is not a valid opti    220                 printf "$1 is not a valid option\n"
221                 return 1                          221                 return 1
222         fi                                        222         fi
223                                                   223 
224         if [ -n $filename ]; then                 224         if [ -n $filename ]; then
225                 present=$(cat $SYSFS/power/sta    225                 present=$(cat $SYSFS/power/state | grep $filename)
226                                                   226 
227                 if [ -z "$present" ]; then        227                 if [ -z "$present" ]; then
228                         printf "Tried to $1 bu    228                         printf "Tried to $1 but $filename isn't present in $SYSFS/power/state\n"
229                         return 1;                 229                         return 1;
230                 fi                                230                 fi
231                                                   231 
232                 for i in `seq 1 $2`; do           232                 for i in `seq 1 $2`; do
233                         printf "Starting $1\n"    233                         printf "Starting $1\n"
234                                                << 
235                         if [ "$3" = "rtc" ]; t << 
236                                 if ! command - << 
237                                         printf << 
238                                         return << 
239                                 fi             << 
240                                                << 
241                                 rtcwake -m $fi << 
242                                                << 
243                                 if [ $? -ne 0  << 
244                                         printf << 
245                                         return << 
246                                 fi             << 
247                         fi                     << 
248                                                << 
249                         echo $filename > $SYSF    234                         echo $filename > $SYSFS/power/state
250                         printf "Came out of $1    235                         printf "Came out of $1\n"
251                                                   236 
252                         printf "Do basic tests    237                         printf "Do basic tests after finishing $1 to verify cpufreq state\n\n"
253                         cpufreq_basic_tests       238                         cpufreq_basic_tests
254                 done                              239                 done
255         fi                                        240         fi
256 }                                                 241 }
                                                      

~ [ 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