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