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