Lisa Nguyen | adf9df9 | 2015-01-25 18:16:45 -0800 | [diff] [blame] | 1 | #!/bin/sh |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 2 | # |
Daniel Lezcano | 35fb172 | 2011-10-03 13:56:11 +0200 | [diff] [blame] | 3 | # PM-QA validation test suite for the power management on Linux |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 4 | # |
| 5 | # Copyright (C) 2011, Linaro Limited. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or |
| 8 | # modify it under the terms of the GNU General Public License |
| 9 | # as published by the Free Software Foundation; either version 2 |
| 10 | # of the License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program; if not, write to the Free Software |
| 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | # |
| 21 | # Contributors: |
| 22 | # Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation) |
| 23 | # - initial API and implementation |
| 24 | # |
| 25 | |
Lisa Nguyen | adf9df9 | 2015-01-25 18:16:45 -0800 | [diff] [blame] | 26 | . ../Switches.sh |
Hongbo Zhang | 974802b | 2013-02-04 19:22:58 +0800 | [diff] [blame] | 27 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 28 | CPU_PATH="/sys/devices/system/cpu" |
| 29 | TEST_NAME=$(basename ${0%.sh}) |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 30 | PREFIX=$TEST_NAME |
| 31 | INC=0 |
Lisa Nguyen | 523e8d9 | 2014-09-04 17:26:03 -0700 | [diff] [blame] | 32 | cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 33 | pass_count=0 |
| 34 | fail_count=0 |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 35 | skip_count=0 |
| 36 | test_script_status="pass" |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 37 | |
| 38 | test_status_show() { |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 39 | if [ $fail_count -ne 0 ]; then |
| 40 | test_script_status="fail" |
| 41 | else |
| 42 | if [ $skip_count -ne 0 ]; then |
| 43 | if [ $pass_count -ne 0 ]; then |
| 44 | test_script_status="pass" |
| 45 | else |
| 46 | test_script_status="skip" |
| 47 | fi |
| 48 | fi |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 49 | fi |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 50 | |
| 51 | echo " " |
Lisa Nguyen | d1e0be9 | 2015-01-27 13:57:02 -0800 | [diff] [blame] | 52 | if [ "$test_script_status" = "fail" ]; then |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 53 | echo "$TEST_NAME: fail" |
Lisa Nguyen | d1e0be9 | 2015-01-27 13:57:02 -0800 | [diff] [blame] | 54 | elif [ "$test_script_status" = "skip" ]; then |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 55 | echo "$TEST_NAME: skip" |
| 56 | else |
| 57 | echo "$TEST_NAME: pass" |
| 58 | fi |
| 59 | echo " " |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 60 | } |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 61 | |
Lisa Nguyen | d713d63 | 2014-08-20 17:26:04 -0700 | [diff] [blame] | 62 | skip_tests() { |
| 63 | dir=$1 |
| 64 | |
| 65 | test_script_list=$(ls ../$1/*.sh | grep -v 'sanity.sh$' | grep -v '00.sh$') |
| 66 | |
| 67 | for test_script in $test_script_list; do |
| 68 | test_case=$(basename $test_script .sh) |
| 69 | echo "$test_case: skip" |
| 70 | done |
| 71 | } |
| 72 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 73 | log_begin() { |
Daniel Lezcano | 994f6f1 | 2011-08-16 13:28:33 +0200 | [diff] [blame] | 74 | printf "%-76s" "$TEST_NAME.$INC$CPU: $@... " |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 75 | INC=$(($INC+1)) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | log_end() { |
| 79 | printf "$*\n" |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 80 | |
Lisa Nguyen | d1e0be9 | 2015-01-27 13:57:02 -0800 | [diff] [blame] | 81 | if [ "$*" = "Err" ]; then |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 82 | fail_count=$((fail_count + 1)) |
Lisa Nguyen | d1e0be9 | 2015-01-27 13:57:02 -0800 | [diff] [blame] | 83 | elif [ "$*" = "skip" ]; then |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 84 | skip_count=$((skip_count + 1)) |
| 85 | else |
| 86 | pass_count=$((pass_count + 1)) |
| 87 | fi |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | log_skip() { |
| 91 | log_begin "$@" |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame] | 92 | log_end "skip" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | for_each_cpu() { |
| 96 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 97 | func=$1 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 98 | shift 1 |
| 99 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 100 | for cpu in $cpus; do |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 101 | INC=0 |
| 102 | CPU=/$cpu |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 103 | $func $cpu $@ |
| 104 | done |
| 105 | |
| 106 | return 0 |
| 107 | } |
| 108 | |
| 109 | for_each_governor() { |
| 110 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 111 | cpu=$1 |
| 112 | func=$2 |
| 113 | dirpath=$CPU_PATH/$cpu/cpufreq |
| 114 | governors=$(cat $dirpath/scaling_available_governors) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 115 | shift 2 |
| 116 | |
| 117 | for governor in $governors; do |
| 118 | $func $cpu $governor $@ |
| 119 | done |
| 120 | |
| 121 | return 0 |
| 122 | } |
| 123 | |
| 124 | for_each_frequency() { |
| 125 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 126 | cpu=$1 |
| 127 | func=$2 |
| 128 | dirpath=$CPU_PATH/$cpu/cpufreq |
| 129 | frequencies=$(cat $dirpath/scaling_available_frequencies) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 130 | shift 2 |
| 131 | |
| 132 | for frequency in $frequencies; do |
| 133 | $func $cpu $frequency $@ |
| 134 | done |
| 135 | |
| 136 | return 0 |
| 137 | } |
| 138 | |
| 139 | set_governor() { |
| 140 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 141 | cpu=$1 |
| 142 | dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor |
| 143 | newgov=$2 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 144 | |
| 145 | echo $newgov > $dirpath |
| 146 | } |
| 147 | |
| 148 | get_governor() { |
| 149 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 150 | cpu=$1 |
| 151 | dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 152 | |
| 153 | cat $dirpath |
| 154 | } |
| 155 | |
| 156 | wait_latency() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 157 | cpu=$1 |
| 158 | dirpath=$CPU_PATH/$cpu/cpufreq |
| 159 | gov=$(cat $dirpath/scaling_governor) |
Sanjay Singh Rawat | e5726c1 | 2014-08-05 13:39:06 +0530 | [diff] [blame] | 160 | |
| 161 | # consider per-policy governor case |
| 162 | if [ -e $CPU_PATH/$cpu/cpufreq/$gov ]; then |
| 163 | sampling_rate=$(cat $CPU_PATH/$cpu/cpufreq/$gov/sampling_rate) |
| 164 | else |
| 165 | sampling_rate=$(cat $CPU_PATH/cpufreq/$gov/sampling_rate) |
| 166 | fi |
| 167 | sampling_rate=$((sampling_rate * 1000)) # unit nsec |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 168 | |
| 169 | latency=$(cat $dirpath/cpuinfo_transition_latency) |
Sanjay Singh Rawat | c7af87b | 2013-12-15 13:30:37 +0530 | [diff] [blame] | 170 | if [ $? -ne 0 ]; then |
Daniel Lezcano | 0b90d41 | 2011-09-20 08:31:04 +0200 | [diff] [blame] | 171 | return 1 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 172 | fi |
| 173 | |
| 174 | nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w) |
Sanjay Singh Rawat | c7af87b | 2013-12-15 13:30:37 +0530 | [diff] [blame] | 175 | if [ $? -ne 0 ]; then |
Daniel Lezcano | 0b90d41 | 2011-09-20 08:31:04 +0200 | [diff] [blame] | 176 | return 1 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 177 | fi |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 178 | |
| 179 | nrfreq=$((nrfreq + 1)) |
Sanjay Singh Rawat | e5726c1 | 2014-08-05 13:39:06 +0530 | [diff] [blame] | 180 | |
| 181 | sleep_time=$(($latency + $sampling_rate)) |
| 182 | |
| 183 | ../utils/nanosleep $(($nrfreq * $sleep_time)) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | frequnit() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 187 | freq=$1 |
| 188 | ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) |
| 189 | mhz=$(echo "scale=1;($freq / 1000)" | bc -l) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 190 | |
| 191 | res=$(echo "($ghz > 1.0)" | bc -l) |
| 192 | if [ "$res" = "1" ]; then |
| 193 | echo $ghz GHz |
| 194 | return 0 |
| 195 | fi |
| 196 | |
| 197 | res=$(echo "($mhz > 1.0)" | bc -l) |
| 198 | if [ "$res" = "1" ];then |
| 199 | echo $mhz MHz |
| 200 | return 0 |
| 201 | fi |
| 202 | |
| 203 | echo $freq KHz |
| 204 | } |
| 205 | |
| 206 | set_frequency() { |
| 207 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 208 | cpu=$1 |
| 209 | dirpath=$CPU_PATH/$cpu/cpufreq |
| 210 | newfreq=$2 |
| 211 | setfreqpath=$dirpath/scaling_setspeed |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 212 | |
| 213 | echo $newfreq > $setfreqpath |
| 214 | wait_latency $cpu |
| 215 | } |
| 216 | |
| 217 | get_frequency() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 218 | cpu=$1 |
| 219 | dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 220 | cat $dirpath |
| 221 | } |
| 222 | |
| 223 | get_max_frequency() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 224 | cpu=$1 |
| 225 | dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 226 | cat $dirpath |
| 227 | } |
| 228 | |
| 229 | get_min_frequency() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 230 | cpu=$1 |
| 231 | dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 232 | cat $dirpath |
| 233 | } |
| 234 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 235 | set_online() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 236 | cpu=$1 |
| 237 | dirpath=$CPU_PATH/$cpu |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 238 | |
Daniel Lezcano | 3dd53ee | 2012-04-05 14:03:08 +0200 | [diff] [blame] | 239 | if [ "$cpu" = "cpu0" ]; then |
| 240 | return 0 |
| 241 | fi |
| 242 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 243 | echo 1 > $dirpath/online |
| 244 | } |
| 245 | |
| 246 | set_offline() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 247 | cpu=$1 |
| 248 | dirpath=$CPU_PATH/$cpu |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 249 | |
Daniel Lezcano | 3dd53ee | 2012-04-05 14:03:08 +0200 | [diff] [blame] | 250 | if [ "$cpu" = "cpu0" ]; then |
| 251 | return 0 |
| 252 | fi |
| 253 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 254 | echo 0 > $dirpath/online |
| 255 | } |
| 256 | |
| 257 | get_online() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 258 | cpu=$1 |
| 259 | dirpath=$CPU_PATH/$cpu |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 260 | |
| 261 | cat $dirpath/online |
| 262 | } |
| 263 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 264 | check() { |
| 265 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 266 | descr=$1 |
| 267 | func=$2 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 268 | shift 2; |
| 269 | |
| 270 | log_begin "checking $descr" |
| 271 | |
| 272 | $func $@ |
Sanjay Singh Rawat | c7af87b | 2013-12-15 13:30:37 +0530 | [diff] [blame] | 273 | if [ $? -ne 0 ]; then |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 274 | log_end "Err" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 275 | return 1 |
| 276 | fi |
| 277 | |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 278 | log_end "Ok" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 279 | |
| 280 | return 0 |
| 281 | } |
| 282 | |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 283 | check_file() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 284 | file=$1 |
| 285 | dir=$2 |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 286 | |
Sanjay Singh Rawat | 8b6ad7c | 2014-07-08 16:35:36 +0200 | [diff] [blame] | 287 | check "'$file' exists in '$dir'" "test -f" $dir/$file |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 288 | } |
| 289 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 290 | check_cpufreq_files() { |
| 291 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 292 | dirpath=$CPU_PATH/$1/cpufreq |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 293 | shift 1 |
| 294 | |
| 295 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 296 | check_file $i $dirpath || return 1 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 297 | done |
| 298 | |
| 299 | return 0 |
| 300 | } |
| 301 | |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 302 | check_sched_mc_files() { |
| 303 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 304 | dirpath=$CPU_PATH |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 305 | |
| 306 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 307 | check_file $i $dirpath || return 1 |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 308 | done |
| 309 | |
| 310 | return 0 |
| 311 | } |
| 312 | |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 313 | check_topology_files() { |
| 314 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 315 | dirpath=$CPU_PATH/$1/topology |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 316 | shift 1 |
| 317 | |
| 318 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 319 | check_file $i $dirpath || return 1 |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 320 | done |
| 321 | |
| 322 | return 0 |
| 323 | } |
| 324 | |
Daniel Lezcano | b10475e | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 325 | check_cpuhotplug_files() { |
| 326 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 327 | dirpath=$CPU_PATH/$1 |
Daniel Lezcano | b10475e | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 328 | shift 1 |
| 329 | |
| 330 | for i in $@; do |
Lisa Nguyen | e232318 | 2014-07-04 10:24:30 +0530 | [diff] [blame] | 331 | if [ `echo $dirpath | grep -c "cpu0"` -eq 1 ]; then |
| 332 | if [ $hotplug_allow_cpu0 -eq 0 ]; then |
| 333 | continue |
| 334 | fi |
| 335 | fi |
| 336 | |
Daniel Lezcano | b10475e | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 337 | check_file $i $dirpath || return 1 |
| 338 | done |
| 339 | |
| 340 | return 0 |
| 341 | } |
| 342 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 343 | save_governors() { |
| 344 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 345 | index=0 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 346 | |
Lisa Nguyen | 188ca9a | 2014-08-11 12:21:08 -0700 | [diff] [blame] | 347 | for cpu in $cpus; do |
| 348 | governors_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 349 | index=$((index + 1)) |
| 350 | done |
| 351 | } |
| 352 | |
| 353 | restore_governors() { |
| 354 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 355 | index=0 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 356 | |
Lisa Nguyen | 188ca9a | 2014-08-11 12:21:08 -0700 | [diff] [blame] | 357 | for cpu in $cpus; do |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 358 | oldgov=${governors_backup[$index]} |
Lisa Nguyen | 188ca9a | 2014-08-11 12:21:08 -0700 | [diff] [blame] | 359 | echo $oldgov > $CPU_PATH/$cpu/cpufreq/scaling_governor |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 360 | index=$((index + 1)) |
| 361 | done |
| 362 | } |
| 363 | |
| 364 | save_frequencies() { |
| 365 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 366 | index=0 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 367 | |
| 368 | for cpu in $cpus; do |
| 369 | frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) |
| 370 | index=$((index + 1)) |
| 371 | done |
| 372 | } |
| 373 | |
| 374 | restore_frequencies() { |
| 375 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 376 | index=0 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 377 | |
| 378 | for cpu in $cpus; do |
| 379 | oldfreq=${frequencies_backup[$index]} |
| 380 | echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed |
| 381 | index=$((index + 1)) |
| 382 | done |
| 383 | } |
| 384 | |
| 385 | sigtrap() { |
| 386 | exit 255 |
Daniel Lezcano | 18e22b5 | 2011-08-06 02:52:02 +0200 | [diff] [blame] | 387 | } |
Sanjay Singh Rawat | d5963e5 | 2014-02-05 18:12:17 +0530 | [diff] [blame] | 388 | |
| 389 | # currently we support ubuntu and android |
| 390 | get_os() { |
| 391 | lsb_release -a 2>&1 | grep -i ubuntu > /dev/null |
| 392 | if [ $? -eq 0 ]; then |
| 393 | # for ubuntu |
| 394 | return 1 |
| 395 | else |
| 396 | # for android (if needed can look for build.prop) |
| 397 | return 2 |
| 398 | fi |
| 399 | } |
| 400 | |
| 401 | is_root() { |
Sanjay Singh Rawat | d5963e5 | 2014-02-05 18:12:17 +0530 | [diff] [blame] | 402 | get_os |
| 403 | if [ $? -eq 1 ]; then |
| 404 | # for ubuntu |
| 405 | ret=$(id -u) |
| 406 | else |
| 407 | # for android |
| 408 | ret=$(id | sed -n 's/uid=//p' | sed -n 's/(root) [a-z]*=[0-9]*(log)//p') |
| 409 | fi |
| 410 | return $ret |
| 411 | } |
Lisa Nguyen | e232318 | 2014-07-04 10:24:30 +0530 | [diff] [blame] | 412 | |
| 413 | is_cpu0_hotplug_allowed() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame^] | 414 | status=$1 |
Lisa Nguyen | e232318 | 2014-07-04 10:24:30 +0530 | [diff] [blame] | 415 | |
| 416 | if [ $status -eq 1 ]; then |
| 417 | return 0 |
| 418 | else |
| 419 | return 1 |
| 420 | fi |
| 421 | } |