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 | # |
Lisa Nguyen | 3ab9ffd | 2016-01-25 12:16:18 -0800 | [diff] [blame] | 5 | # Copyright (C) 2008-2009 Canonical Ltd. |
| 6 | # Copyright (C) 2011-2016, Linaro Limited. |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 7 | # |
| 8 | # This program is free software; you can redistribute it and/or |
| 9 | # modify it under the terms of the GNU General Public License |
| 10 | # as published by the Free Software Foundation; either version 2 |
| 11 | # of the License, or (at your option) any later version. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program; if not, write to the Free Software |
| 20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | # |
| 22 | # Contributors: |
| 23 | # Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation) |
| 24 | # - initial API and implementation |
Lisa Nguyen | 3ab9ffd | 2016-01-25 12:16:18 -0800 | [diff] [blame] | 25 | # Michael Frey <michael.frey@canonical.com> |
| 26 | # - initial suspend/resume functions |
| 27 | # Andy Whitcroft <apw@canonical.com> |
| 28 | # - initial suspend/resume functions |
| 29 | # Hongbo Zhang <hongbo.zhang@linaro.org> |
| 30 | # - updated suspend/resume functions |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 31 | # |
| 32 | |
Lisa Nguyen | a06e5bf | 2015-02-18 13:47:59 -0800 | [diff] [blame] | 33 | . ../Switches/Switches.sh |
Hongbo Zhang | 974802b | 2013-02-04 19:22:58 +0800 | [diff] [blame] | 34 | |
Lisa Nguyen | 3ab9ffd | 2016-01-25 12:16:18 -0800 | [diff] [blame] | 35 | LOGDIR='/var/lib/pm-utils' |
| 36 | LOGFILE="$LOGDIR/stress.log" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 37 | CPU_PATH="/sys/devices/system/cpu" |
| 38 | TEST_NAME=$(basename ${0%.sh}) |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 39 | PREFIX=$TEST_NAME |
| 40 | INC=0 |
Lisa Nguyen | 523e8d9 | 2014-09-04 17:26:03 -0700 | [diff] [blame] | 41 | cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 42 | pass_count=0 |
| 43 | fail_count=0 |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 44 | skip_count=0 |
| 45 | test_script_status="pass" |
Lisa Nguyen | f62f354 | 2015-01-26 17:33:03 -0800 | [diff] [blame] | 46 | NANOSLEEP="../utils/nanosleep" |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 47 | gov_array="governors_backup" |
| 48 | freq_array="frequencies_backup" |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 49 | THERMAL_PATH="/sys/devices/virtual/thermal" |
| 50 | MAX_ZONE=0-12 |
| 51 | MAX_CDEV=0-50 |
| 52 | scaling_freq_array="scaling_freq" |
| 53 | mode_array="mode_list" |
| 54 | thermal_gov_array="thermal_governor_backup" |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 55 | |
Lisa Nguyen | 3ab9ffd | 2016-01-25 12:16:18 -0800 | [diff] [blame] | 56 | # config options for suspend/resume |
| 57 | dry=0 |
| 58 | auto=1 |
| 59 | pm_trace=1 |
| 60 | timer_sleep=20 |
| 61 | |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 62 | test_status_show() { |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 63 | if [ $fail_count -ne 0 ]; then |
| 64 | test_script_status="fail" |
| 65 | else |
| 66 | if [ $skip_count -ne 0 ]; then |
| 67 | if [ $pass_count -ne 0 ]; then |
| 68 | test_script_status="pass" |
| 69 | else |
| 70 | test_script_status="skip" |
| 71 | fi |
| 72 | fi |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 73 | fi |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 74 | |
| 75 | echo " " |
Lisa Nguyen | d1e0be9 | 2015-01-27 13:57:02 -0800 | [diff] [blame] | 76 | if [ "$test_script_status" = "fail" ]; then |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 77 | echo "$TEST_NAME: fail" |
Lisa Nguyen | d1e0be9 | 2015-01-27 13:57:02 -0800 | [diff] [blame] | 78 | elif [ "$test_script_status" = "skip" ]; then |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 79 | echo "$TEST_NAME: skip" |
| 80 | else |
| 81 | echo "$TEST_NAME: pass" |
| 82 | fi |
| 83 | echo " " |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 84 | } |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 85 | |
Lisa Nguyen | d713d63 | 2014-08-20 17:26:04 -0700 | [diff] [blame] | 86 | skip_tests() { |
| 87 | dir=$1 |
| 88 | |
| 89 | test_script_list=$(ls ../$1/*.sh | grep -v 'sanity.sh$' | grep -v '00.sh$') |
| 90 | |
| 91 | for test_script in $test_script_list; do |
| 92 | test_case=$(basename $test_script .sh) |
| 93 | echo "$test_case: skip" |
| 94 | done |
| 95 | } |
| 96 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 97 | log_begin() { |
Daniel Lezcano | 994f6f1 | 2011-08-16 13:28:33 +0200 | [diff] [blame] | 98 | printf "%-76s" "$TEST_NAME.$INC$CPU: $@... " |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 99 | INC=$(($INC+1)) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | log_end() { |
| 103 | printf "$*\n" |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 104 | |
Lisa Nguyen | d1e0be9 | 2015-01-27 13:57:02 -0800 | [diff] [blame] | 105 | if [ "$*" = "Err" ]; then |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 106 | fail_count=$((fail_count + 1)) |
Lisa Nguyen | d1e0be9 | 2015-01-27 13:57:02 -0800 | [diff] [blame] | 107 | elif [ "$*" = "skip" ]; then |
Lisa Nguyen | e2877d5 | 2014-08-04 12:30:43 -0700 | [diff] [blame] | 108 | skip_count=$((skip_count + 1)) |
| 109 | else |
| 110 | pass_count=$((pass_count + 1)) |
| 111 | fi |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | log_skip() { |
| 115 | log_begin "$@" |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame] | 116 | log_end "skip" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | for_each_cpu() { |
| 120 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 121 | cpu_func=$1 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 122 | shift 1 |
| 123 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 124 | for cpu in $cpus; do |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 125 | INC=0 |
| 126 | CPU=/$cpu |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 127 | $cpu_func $cpu $@ |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 128 | done |
| 129 | |
| 130 | return 0 |
| 131 | } |
| 132 | |
| 133 | for_each_governor() { |
| 134 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 135 | gov_cpu=$1 |
| 136 | gov_func=$2 |
| 137 | cpufreq_dirpath=$CPU_PATH/$gov_cpu/cpufreq |
| 138 | governors=$(cat $cpufreq_dirpath/scaling_available_governors) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 139 | shift 2 |
| 140 | |
| 141 | for governor in $governors; do |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 142 | $gov_func $gov_cpu $governor $@ |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 143 | done |
| 144 | |
| 145 | return 0 |
| 146 | } |
| 147 | |
| 148 | for_each_frequency() { |
| 149 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 150 | freq_cpu=$1 |
| 151 | freq_func=$2 |
| 152 | cpufreq_dirpath=$CPU_PATH/$freq_cpu/cpufreq |
| 153 | frequencies=$(cat $cpufreq_dirpath/scaling_available_frequencies) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 154 | shift 2 |
| 155 | |
| 156 | for frequency in $frequencies; do |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 157 | $freq_func $freq_cpu $frequency $@ |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 158 | done |
| 159 | |
| 160 | return 0 |
| 161 | } |
| 162 | |
| 163 | set_governor() { |
| 164 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 165 | gov_cpu=$1 |
| 166 | scaling_gov_dirpath=$CPU_PATH/$gov_cpu/cpufreq/scaling_governor |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 167 | newgov=$2 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 168 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 169 | echo $newgov > $scaling_gov_dirpath |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | get_governor() { |
| 173 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 174 | gov_cpu=$1 |
| 175 | scaling_gov_dirpath=$CPU_PATH/$gov_cpu/cpufreq/scaling_governor |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 176 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 177 | cat $scaling_gov_dirpath |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | wait_latency() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 181 | wait_latency_cpu=$1 |
| 182 | cpufreq_dirpath=$CPU_PATH/$wait_latency_cpu/cpufreq |
| 183 | gov=$(cat $cpufreq_dirpath/scaling_governor) |
Sanjay Singh Rawat | e5726c1 | 2014-08-05 13:39:06 +0530 | [diff] [blame] | 184 | |
| 185 | # consider per-policy governor case |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 186 | if [ -e $CPU_PATH/$wait_latency_cpu/cpufreq/$gov ]; then |
Lisa Nguyen | e714553 | 2015-11-17 17:24:28 -0800 | [diff] [blame] | 187 | #try one path to see if the sampling_rate can be found |
| 188 | if [ -e $CPU_PATH/$wait_latency_cpu/cpufreq/$gov/sampling_rate ]; then |
| 189 | sampling_rate=$(cat $CPU_PATH/$wait_latency_cpu/cpufreq/$gov/sampling_rate) |
| 190 | else |
| 191 | # try another path to get the sampling_rate |
| 192 | if [ -e $CPU_PATH/cpufreq/$gov/sampling_rate ]; then |
| 193 | sampling_rate=$(cat $CPU_PATH/cpufreq/$gov/sampling_rate) |
| 194 | else |
| 195 | return 1 |
| 196 | fi |
| 197 | fi |
Sanjay Singh Rawat | e5726c1 | 2014-08-05 13:39:06 +0530 | [diff] [blame] | 198 | else |
Lisa Nguyen | e714553 | 2015-11-17 17:24:28 -0800 | [diff] [blame] | 199 | return 1 |
Sanjay Singh Rawat | e5726c1 | 2014-08-05 13:39:06 +0530 | [diff] [blame] | 200 | fi |
| 201 | sampling_rate=$((sampling_rate * 1000)) # unit nsec |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 202 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 203 | latency=$(cat $cpufreq_dirpath/cpuinfo_transition_latency) |
Sanjay Singh Rawat | c7af87b | 2013-12-15 13:30:37 +0530 | [diff] [blame] | 204 | if [ $? -ne 0 ]; then |
Lisa Nguyen | e714553 | 2015-11-17 17:24:28 -0800 | [diff] [blame] | 205 | return 1 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 206 | fi |
| 207 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 208 | nrfreq=$(cat $cpufreq_dirpath/scaling_available_frequencies | wc -w) |
Sanjay Singh Rawat | c7af87b | 2013-12-15 13:30:37 +0530 | [diff] [blame] | 209 | if [ $? -ne 0 ]; then |
Lisa Nguyen | e714553 | 2015-11-17 17:24:28 -0800 | [diff] [blame] | 210 | return 1 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 211 | fi |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 212 | |
| 213 | nrfreq=$((nrfreq + 1)) |
Sanjay Singh Rawat | e5726c1 | 2014-08-05 13:39:06 +0530 | [diff] [blame] | 214 | |
| 215 | sleep_time=$(($latency + $sampling_rate)) |
| 216 | |
Lisa Nguyen | f62f354 | 2015-01-26 17:33:03 -0800 | [diff] [blame] | 217 | $NANOSLEEP $(($nrfreq * $sleep_time)) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | frequnit() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 221 | freq=$1 |
Lisa Nguyen | 374c1b5 | 2015-10-21 17:57:04 -0700 | [diff] [blame] | 222 | ghz=$(echo $freq | awk '{printf "%.1f", ($1 / 1000000)}') |
| 223 | mhz=$(echo $freq | awk '{printf "%.1f", ($1 / 1000)}') |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 224 | |
Lisa Nguyen | 374c1b5 | 2015-10-21 17:57:04 -0700 | [diff] [blame] | 225 | ghz_value=$(echo $ghz | awk '{printf "%f", ($1 > 1.0)}') |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 226 | if [ "$ghz_value" = "1" ]; then |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 227 | echo $ghz GHz |
| 228 | return 0 |
| 229 | fi |
| 230 | |
Lisa Nguyen | 374c1b5 | 2015-10-21 17:57:04 -0700 | [diff] [blame] | 231 | mhz_value=$(echo $mhz | awk '{printf "%f", ($1 > 1.0)}') |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 232 | if [ "$mhz_value" = "1" ];then |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 233 | echo $mhz MHz |
| 234 | return 0 |
| 235 | fi |
| 236 | |
| 237 | echo $freq KHz |
| 238 | } |
| 239 | |
| 240 | set_frequency() { |
| 241 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 242 | freq_cpu=$1 |
| 243 | cpufreq_dirpath=$CPU_PATH/$freq_cpu/cpufreq |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 244 | newfreq=$2 |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 245 | setfreqpath=$cpufreq_dirpath/scaling_setspeed |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 246 | |
| 247 | echo $newfreq > $setfreqpath |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 248 | wait_latency $freq_cpu |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | get_frequency() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 252 | freq_cpu=$1 |
| 253 | scaling_cur_freq=$CPU_PATH/$freq_cpu/cpufreq/scaling_cur_freq |
| 254 | cat $scaling_cur_freq |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | get_max_frequency() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 258 | freq_cpu=$1 |
| 259 | scaling_max_freq=$CPU_PATH/$freq_cpu/cpufreq/scaling_max_freq |
| 260 | cat $scaling_max_freq |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | get_min_frequency() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 264 | freq_cpu=$1 |
| 265 | scaling_min_freq=$CPU_PATH/$freq_cpu/cpufreq/scaling_min_freq |
| 266 | cat $scaling_min_freq |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 269 | set_online() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 270 | current_cpu=$1 |
| 271 | current_cpu_path=$CPU_PATH/$current_cpu |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 272 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 273 | if [ "$current_cpu" = "cpu0" ]; then |
Daniel Lezcano | 3dd53ee | 2012-04-05 14:03:08 +0200 | [diff] [blame] | 274 | return 0 |
| 275 | fi |
| 276 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 277 | echo 1 > $current_cpu_path/online |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | set_offline() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 281 | current_cpu=$1 |
| 282 | current_cpu_path=$CPU_PATH/$current_cpu |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 283 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 284 | if [ "$current_cpu" = "cpu0" ]; then |
Daniel Lezcano | 3dd53ee | 2012-04-05 14:03:08 +0200 | [diff] [blame] | 285 | return 0 |
| 286 | fi |
| 287 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 288 | echo 0 > $current_cpu_path/online |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | get_online() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 292 | current_cpu=$1 |
| 293 | current_cpu_path=$CPU_PATH/$current_cpu |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 294 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 295 | cat $current_cpu_path/online |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 298 | check() { |
| 299 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 300 | check_descr=$1 |
| 301 | check_func=$2 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 302 | shift 2; |
| 303 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 304 | log_begin "checking $check_descr" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 305 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 306 | $check_func $@ |
Sanjay Singh Rawat | c7af87b | 2013-12-15 13:30:37 +0530 | [diff] [blame] | 307 | if [ $? -ne 0 ]; then |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 308 | log_end "Err" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 309 | return 1 |
| 310 | fi |
| 311 | |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 312 | log_end "Ok" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 313 | |
| 314 | return 0 |
| 315 | } |
| 316 | |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 317 | check_file() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 318 | file=$1 |
| 319 | dir=$2 |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 320 | |
Sanjay Singh Rawat | 8b6ad7c | 2014-07-08 16:35:36 +0200 | [diff] [blame] | 321 | check "'$file' exists in '$dir'" "test -f" $dir/$file |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 324 | check_cpufreq_files() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 325 | cpu_id=$1 |
| 326 | cpufreq_files_dir=$CPU_PATH/$cpu_id/cpufreq |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 327 | shift 1 |
| 328 | |
| 329 | for i in $@; do |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 330 | check_file $i $cpufreq_files_dir || return 1 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 331 | done |
| 332 | |
| 333 | return 0 |
| 334 | } |
| 335 | |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 336 | check_sched_mc_files() { |
| 337 | |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 338 | for i in $@; do |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 339 | check_file $i $CPU_PATH || return 1 |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 340 | done |
| 341 | |
| 342 | return 0 |
| 343 | } |
| 344 | |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 345 | check_topology_files() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 346 | cpu=$1 |
| 347 | topology_files_dir=$CPU_PATH/$cpu/topology |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 348 | shift 1 |
| 349 | |
| 350 | for i in $@; do |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 351 | check_file $i $topology_files_dir || return 1 |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 352 | done |
| 353 | |
| 354 | return 0 |
| 355 | } |
| 356 | |
Daniel Lezcano | b10475e | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 357 | check_cpuhotplug_files() { |
| 358 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 359 | cpuhotplug_files_dir=$CPU_PATH/$1 |
Daniel Lezcano | b10475e | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 360 | shift 1 |
| 361 | |
| 362 | for i in $@; do |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 363 | if [ `echo $cpuhotplug_files_dir | grep -c "cpu0"` -eq 1 ]; then |
Lisa Nguyen | e232318 | 2014-07-04 10:24:30 +0530 | [diff] [blame] | 364 | if [ $hotplug_allow_cpu0 -eq 0 ]; then |
| 365 | continue |
| 366 | fi |
| 367 | fi |
| 368 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame] | 369 | check_file $i $cpuhotplug_files_dir || return 1 |
Daniel Lezcano | b10475e | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 370 | done |
| 371 | |
| 372 | return 0 |
| 373 | } |
| 374 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 375 | save_governors() { |
| 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 | |
Lisa Nguyen | 188ca9a | 2014-08-11 12:21:08 -0700 | [diff] [blame] | 379 | for cpu in $cpus; do |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 380 | scaling_gov_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) |
| 381 | eval $gov_array$index=$scaling_gov_value |
| 382 | eval export $gov_array$index |
Lisa Nguyen | 2af35fa | 2016-06-10 17:49:21 -0700 | [diff] [blame] | 383 | index=$((index + 1)) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 384 | done |
| 385 | } |
| 386 | |
| 387 | restore_governors() { |
| 388 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 389 | index=0 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 390 | |
Lisa Nguyen | 188ca9a | 2014-08-11 12:21:08 -0700 | [diff] [blame] | 391 | for cpu in $cpus; do |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 392 | oldgov=$(eval echo \$$gov_array$index) |
| 393 | echo $oldgov > $CPU_PATH/$cpu/cpufreq/scaling_governor |
| 394 | index=$((index + 1)) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 395 | done |
| 396 | } |
| 397 | |
| 398 | save_frequencies() { |
| 399 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 400 | index=0 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 401 | |
| 402 | for cpu in $cpus; do |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 403 | freq_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) |
| 404 | eval $freq_array$index=$freq_value |
| 405 | eval export $freq_array$index |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 406 | done |
| 407 | } |
| 408 | |
| 409 | restore_frequencies() { |
| 410 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 411 | index=0 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 412 | |
| 413 | for cpu in $cpus; do |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 414 | oldfreq=$(eval echo \$$freq_array$index) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 415 | echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed |
| 416 | index=$((index + 1)) |
| 417 | done |
| 418 | } |
| 419 | |
| 420 | sigtrap() { |
| 421 | exit 255 |
Daniel Lezcano | 18e22b5 | 2011-08-06 02:52:02 +0200 | [diff] [blame] | 422 | } |
Sanjay Singh Rawat | d5963e5 | 2014-02-05 18:12:17 +0530 | [diff] [blame] | 423 | |
| 424 | # currently we support ubuntu and android |
| 425 | get_os() { |
Lisa Nguyen | 43ec86a | 2016-07-25 19:00:29 -0700 | [diff] [blame] | 426 | build_prop_file="\system\build.prop" |
| 427 | |
| 428 | if [ -e "$build_prop_file" ]; then |
Sanjay Singh Rawat | d5963e5 | 2014-02-05 18:12:17 +0530 | [diff] [blame] | 429 | # for ubuntu |
| 430 | return 1 |
Lisa Nguyen | 43ec86a | 2016-07-25 19:00:29 -0700 | [diff] [blame] | 431 | else |
| 432 | # for android |
Sanjay Singh Rawat | d5963e5 | 2014-02-05 18:12:17 +0530 | [diff] [blame] | 433 | return 2 |
Lisa Nguyen | 43ec86a | 2016-07-25 19:00:29 -0700 | [diff] [blame] | 434 | fi |
Sanjay Singh Rawat | d5963e5 | 2014-02-05 18:12:17 +0530 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | is_root() { |
Sanjay Singh Rawat | d5963e5 | 2014-02-05 18:12:17 +0530 | [diff] [blame] | 438 | get_os |
| 439 | if [ $? -eq 1 ]; then |
| 440 | # for ubuntu |
| 441 | ret=$(id -u) |
| 442 | else |
| 443 | # for android |
Lisa Nguyen | 46f76f8 | 2015-11-06 19:34:38 -0800 | [diff] [blame] | 444 | 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] | 445 | fi |
| 446 | return $ret |
| 447 | } |
Lisa Nguyen | e232318 | 2014-07-04 10:24:30 +0530 | [diff] [blame] | 448 | |
| 449 | is_cpu0_hotplug_allowed() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 450 | status=$1 |
Lisa Nguyen | e232318 | 2014-07-04 10:24:30 +0530 | [diff] [blame] | 451 | |
| 452 | if [ $status -eq 1 ]; then |
| 453 | return 0 |
| 454 | else |
| 455 | return 1 |
| 456 | fi |
| 457 | } |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 458 | |
| 459 | check_valid_temp() { |
| 460 | file=$1 |
| 461 | zone_name=$2 |
| 462 | dir=$THERMAL_PATH/$zone_name |
| 463 | |
| 464 | temp_file=$dir/$file |
| 465 | shift 2; |
| 466 | |
| 467 | temp_val=$(cat $temp_file) |
| 468 | descr="'$zone_name'/'$file' ='$temp_val'" |
| 469 | log_begin "checking $descr" |
| 470 | |
| 471 | if [ $temp_val -gt 0 ]; then |
| 472 | log_end "Ok" |
| 473 | return 0 |
| 474 | fi |
| 475 | |
| 476 | log_end "Err" |
| 477 | |
| 478 | return 1 |
| 479 | } |
| 480 | |
| 481 | for_each_thermal_zone() { |
Lisa Nguyen | bab54c0 | 2015-11-17 17:03:02 -0800 | [diff] [blame] | 482 | thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 483 | thermal_func=$1 |
| 484 | shift 1 |
| 485 | |
| 486 | for thermal_zone in $thermal_zones; do |
Lisa Nguyen | bab54c0 | 2015-11-17 17:03:02 -0800 | [diff] [blame] | 487 | INC=0 |
| 488 | $thermal_func $thermal_zone $@ |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 489 | done |
| 490 | |
| 491 | return 0 |
| 492 | } |
| 493 | |
| 494 | get_total_trip_point_of_zone() { |
| 495 | zone=$1 |
| 496 | zone_path=$THERMAL_PATH/$zone |
| 497 | count=0 |
| 498 | shift 1 |
| 499 | trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") |
| 500 | for trip in $trips; do |
| 501 | count=$((count + 1)) |
| 502 | done |
| 503 | return $count |
| 504 | } |
| 505 | |
| 506 | for_each_trip_point_of_zone() { |
| 507 | |
| 508 | zone_path=$THERMAL_PATH/$1 |
| 509 | count=0 |
| 510 | func=$2 |
| 511 | zone_name=$1 |
| 512 | shift 2 |
| 513 | trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") |
| 514 | for trip in $trips; do |
| 515 | $func $zone_name $count |
| 516 | count=$((count + 1)) |
| 517 | done |
| 518 | return 0 |
| 519 | } |
| 520 | |
| 521 | for_each_binding_of_zone() { |
| 522 | |
| 523 | zone_path=$THERMAL_PATH/$1 |
| 524 | count=0 |
| 525 | func=$2 |
| 526 | zone_name=$1 |
| 527 | shift 2 |
| 528 | trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point") |
| 529 | for trip in $trips; do |
| 530 | $func $zone_name $count |
| 531 | count=$((count + 1)) |
| 532 | done |
| 533 | |
| 534 | return 0 |
| 535 | |
| 536 | } |
| 537 | |
| 538 | check_valid_binding() { |
| 539 | trip_point=$1 |
| 540 | zone_name=$2 |
| 541 | dirpath=$THERMAL_PATH/$zone_name |
| 542 | temp_file=$zone_name/$trip_point |
| 543 | trip_point_val=$(cat $dirpath/$trip_point) |
| 544 | get_total_trip_point_of_zone $zone_name |
| 545 | trip_point_max=$? |
| 546 | descr="'$temp_file' valid binding" |
| 547 | shift 2 |
| 548 | |
| 549 | log_begin "checking $descr" |
| 550 | if [ $trip_point_val -ge $trip_point_max ]; then |
| 551 | log_end "Err" |
| 552 | return 1 |
| 553 | fi |
| 554 | |
| 555 | log_end "Ok" |
| 556 | return 0 |
| 557 | } |
| 558 | |
| 559 | validate_trip_bindings() { |
| 560 | zone_name=$1 |
| 561 | bind_no=$2 |
| 562 | dirpath=$THERMAL_PATH/$zone_name |
| 563 | trip_point=cdev"$bind_no"_trip_point |
| 564 | shift 2 |
| 565 | |
| 566 | check_file $trip_point $dirpath || return 1 |
| 567 | check_valid_binding $trip_point $zone_name || return 1 |
| 568 | } |
| 569 | |
| 570 | validate_trip_level() { |
| 571 | zone_name=$1 |
| 572 | trip_no=$2 |
| 573 | dirpath=$THERMAL_PATH/$zone_name |
| 574 | trip_temp=trip_point_"$trip_no"_temp |
| 575 | trip_type=trip_point_"$trip_no"_type |
| 576 | shift 2 |
| 577 | |
| 578 | check_file $trip_temp $dirpath || return 1 |
| 579 | check_file $trip_type $dirpath || return 1 |
| 580 | check_valid_temp $trip_temp $zone_name || return 1 |
| 581 | } |
| 582 | |
| 583 | for_each_cooling_device() { |
| 584 | |
| 585 | cdev_func=$1 |
| 586 | shift 1 |
| 587 | |
| 588 | cooling_devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']") |
| 589 | if [ "$cooling_devices" = "" ]; then |
| 590 | log_skip "no cooling devices" |
| 591 | return 0 |
| 592 | fi |
| 593 | |
| 594 | for cooling_device in $cooling_devices; do |
| 595 | INC=0 |
| 596 | $cdev_func $cooling_device $@ |
| 597 | done |
| 598 | |
| 599 | return 0 |
| 600 | } |
| 601 | check_scaling_freq() { |
| 602 | |
| 603 | before_freq_list=$1 |
| 604 | after_freq_list=$2 |
| 605 | shift 2 |
| 606 | index=0 |
| 607 | |
| 608 | flag=0 |
| 609 | for cpu in $cpus; do |
| 610 | after_freq=$(eval echo \$$after_freq_list$index) |
| 611 | before_freq=$(eval echo \$$before_freq_list$index) |
| 612 | |
| 613 | if [ $after_freq -ne $before_freq ]; then |
| 614 | flag=1 |
| 615 | fi |
| 616 | |
| 617 | index=$((index + 1)) |
| 618 | done |
| 619 | |
| 620 | return $flag |
| 621 | } |
| 622 | |
| 623 | store_scaling_maxfreq() { |
| 624 | index=0 |
| 625 | |
| 626 | for cpu in $cpus; do |
| 627 | scaling_freq_max_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) |
| 628 | eval $scaling_freq_array$index=$scaling_freq_max_value |
Lisa Nguyen | 002f481 | 2016-07-25 19:06:41 -0700 | [diff] [blame] | 629 | eval export $scaling_freq_array$index |
| 630 | |
| 631 | index=$((index + 1)) |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 632 | done |
| 633 | |
| 634 | return 0 |
| 635 | } |
| 636 | |
| 637 | get_trip_id() { |
| 638 | |
| 639 | trip_name=$1 |
| 640 | shift 1 |
| 641 | |
| 642 | id1=$(echo $trip_name|cut -c12) |
| 643 | id2=$(echo $trip_name|cut -c13) |
| 644 | if [ $id2 != "_" ]; then |
| 645 | id1=$(($id2 + 10*$id1)) |
| 646 | fi |
| 647 | return $id1 |
| 648 | } |
| 649 | |
| 650 | disable_all_thermal_zones() { |
Lisa Nguyen | bab54c0 | 2015-11-17 17:03:02 -0800 | [diff] [blame] | 651 | thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 652 | index=0 |
| 653 | |
| 654 | for thermal_zone in $thermal_zones; do |
| 655 | mode=$(cat $THERMAL_PATH/$thermal_zone/mode) |
| 656 | eval $mode_array$index=$mode |
| 657 | eval export $mode_array$index |
| 658 | index=$((index + 1)) |
| 659 | echo -n "disabled" > $THERMAL_PATH/$thermal_zone/mode |
| 660 | done |
| 661 | |
| 662 | return 0 |
| 663 | } |
| 664 | |
| 665 | enable_all_thermal_zones() { |
Lisa Nguyen | bab54c0 | 2015-11-17 17:03:02 -0800 | [diff] [blame] | 666 | thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 667 | index=0 |
| 668 | |
| 669 | for thermal_zone in $thermal_zones; do |
| 670 | mode=$(eval echo \$$mode_array$index) |
| 671 | echo $mode > $THERMAL_PATH/$thermal_zone/mode |
| 672 | index=$((index + 1)) |
| 673 | done |
| 674 | |
| 675 | return 0 |
| 676 | } |
| 677 | |
| 678 | GPU_HEAT_BIN=/usr/bin/glmark2 |
| 679 | gpu_pid=0 |
| 680 | |
Lisa Nguyen | cca3b38 | 2016-09-11 21:19:54 -0700 | [diff] [blame] | 681 | check_for_glmark2() { |
| 682 | glmark2_found=$(which glmark2) |
| 683 | |
| 684 | if [ $? -ne 0 ]; then |
| 685 | return 1 |
| 686 | else |
| 687 | return 0 |
| 688 | fi |
| 689 | } |
| 690 | |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 691 | start_glmark2() { |
| 692 | if [ -n "$ANDROID" ]; then |
| 693 | am start org.linaro.glmark2/.Glmark2Activity |
| 694 | return |
| 695 | fi |
| 696 | |
| 697 | if [ -x $GPU_HEAT_BIN ]; then |
| 698 | $GPU_HEAT_BIN & |
| 699 | gpu_pid=$(pidof $GPU_HEAT_BIN) |
| 700 | # Starting X application from serial console needs this |
| 701 | if [ -z "$gpu_pid" ]; then |
| 702 | cp /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.bk |
| 703 | echo "autologin-user=root" >> /etc/lightdm/lightdm.conf |
| 704 | export DISPLAY=localhost:0.0 |
| 705 | restart lightdm |
| 706 | sleep 5 |
| 707 | mv /etc/lightdm/lightdm.conf.bk /etc/lightdm/lightdm.conf |
| 708 | $GPU_HEAT_BIN & |
| 709 | gpu_pid=$(pidof $GPU_HEAT_BIN) |
| 710 | fi |
| 711 | test -z "$gpu_pid" && cpu_pid=0 |
| 712 | echo "start gpu heat binary $gpu_pid" |
| 713 | else |
| 714 | echo "glmark2 not found." 1>&2 |
| 715 | fi |
| 716 | } |
| 717 | |
| 718 | kill_glmark2() { |
| 719 | if [ -n "$ANDROID" ]; then |
| 720 | am kill org.linaro.glmark2 |
| 721 | return |
| 722 | fi |
| 723 | |
| 724 | if [ "$gpu_pid" -ne 0 ]; then |
| 725 | kill -9 $gpu_pid |
| 726 | fi |
| 727 | } |
| 728 | |
| 729 | set_thermal_governors() { |
Lisa Nguyen | bab54c0 | 2015-11-17 17:03:02 -0800 | [diff] [blame] | 730 | thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 731 | gov=$1 |
| 732 | index=0 |
| 733 | |
| 734 | for thermal_zone in $thermal_zones; do |
| 735 | policy=$(cat $THERMAL_PATH/$thermal_zone/policy) |
| 736 | eval $thermal_gov_array$index=$policy |
| 737 | eval export $thermal_gov_array$index |
| 738 | index=$((index + 1)) |
| 739 | echo $gov > $THERMAL_PATH/$thermal_zone/policy |
| 740 | done |
| 741 | |
| 742 | return 0 |
| 743 | } |
| 744 | |
| 745 | restore_thermal_governors() { |
Lisa Nguyen | bab54c0 | 2015-11-17 17:03:02 -0800 | [diff] [blame] | 746 | thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Lisa Nguyen | d39d0bb | 2015-11-16 22:39:25 -0800 | [diff] [blame] | 747 | index=0 |
| 748 | |
| 749 | for thermal_zone in $thermal_zones; do |
| 750 | old_policy=$(eval echo \$$thermal_gov_array$index) |
| 751 | echo $old_policy > $THERMAL_PATH/$thermal_zone/policy |
| 752 | index=$((index + 1)) |
| 753 | done |
| 754 | |
| 755 | return 0 |
| 756 | } |
Lisa Nguyen | ddd07af | 2015-11-17 23:15:22 -0800 | [diff] [blame] | 757 | |
| 758 | check_for_thermal_zones() |
| 759 | { |
| 760 | thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']" 2>/dev/null) |
| 761 | if [ ! -z "$thermal_zones" ]; then |
| 762 | return 0 |
| 763 | else |
| 764 | return 1 |
| 765 | fi |
| 766 | } |
Lisa Nguyen | 3ab9ffd | 2016-01-25 12:16:18 -0800 | [diff] [blame] | 767 | |
| 768 | check_logdir() |
| 769 | { |
| 770 | if [ ! -f $LOGDIR ]; then |
| 771 | mkdir -p $LOGDIR |
| 772 | fi |
| 773 | } |
| 774 | |
| 775 | setup_wakeup_timer () |
| 776 | { |
| 777 | timeout="$1" |
| 778 | |
| 779 | # Request wakeup from the RTC or ACPI alarm timers. Set the timeout |
| 780 | # at 'now' + $timeout seconds. |
| 781 | ctl='/sys/class/rtc/rtc0/wakealarm' |
| 782 | if [ -f "$ctl" ]; then |
| 783 | # Cancel any outstanding timers. |
| 784 | echo "0" >"$ctl" |
| 785 | # rtcN/wakealarm can use relative time in seconds |
| 786 | echo "+$timeout" >"$ctl" |
| 787 | return 0 |
| 788 | fi |
| 789 | ctl='/proc/acpi/alarm' |
| 790 | if [ -f "$ctl" ]; then |
| 791 | echo `date '+%F %H:%M:%S' -d '+ '$timeout' seconds'` >"$ctl" |
| 792 | return 0 |
| 793 | fi |
| 794 | |
| 795 | echo "no method to awaken machine automatically" 1>&2 |
| 796 | exit 1 |
| 797 | } |
| 798 | |
| 799 | suspend_system () |
| 800 | { |
| 801 | if [ "$dry" -eq 1 ]; then |
| 802 | echo "DRY-RUN: suspend machine for $timer_sleep" |
| 803 | sleep 1 |
| 804 | return |
| 805 | fi |
| 806 | |
| 807 | setup_wakeup_timer "$timer_sleep" |
| 808 | |
| 809 | dmesg >"$LOGFILE.dmesg.A" |
| 810 | |
| 811 | # Initiate suspend in different ways. |
| 812 | case "$1" in |
| 813 | dbus) |
| 814 | dbus-send --session --type=method_call \ |
| 815 | --dest=org.freedesktop.PowerManagement \ |
| 816 | /org/freedesktop/PowerManagement \ |
| 817 | org.freedesktop.PowerManagement.Suspend \ |
| 818 | >> "$LOGFILE" || { |
| 819 | ECHO "FAILED: dbus suspend failed" 1>&2 |
| 820 | return 1 |
| 821 | } |
| 822 | ;; |
| 823 | pmsuspend) |
| 824 | pm-suspend >> "$LOGFILE" |
| 825 | ;; |
| 826 | mem) |
| 827 | `echo "mem" > /sys/power/state` >> "$LOGFILE" |
| 828 | ;; |
| 829 | esac |
| 830 | |
| 831 | # Wait on the machine coming back up -- pulling the dmesg over. |
| 832 | echo "v---" >>"$LOGFILE" |
| 833 | retry=30 |
| 834 | while [ "$retry" -gt 0 ]; do |
| 835 | retry=$((retry - 1)) |
| 836 | |
| 837 | # Accumulate the dmesg delta. |
| 838 | dmesg >"$LOGFILE.dmesg.B" |
| 839 | diff "$LOGFILE.dmesg.A" "$LOGFILE.dmesg.B" | \ |
| 840 | grep '^>' >"$LOGFILE.dmesg" |
| 841 | mv "$LOGFILE.dmesg.B" "$LOGFILE.dmesg.A" |
| 842 | |
| 843 | echo "Waiting for suspend to complete $retry to go ..." \ |
| 844 | >> "$LOGFILE" |
| 845 | cat "$LOGFILE.dmesg" >> "$LOGFILE" |
| 846 | |
| 847 | if [ "`grep -c 'Back to C!' $LOGFILE.dmesg`" -ne 0 ]; then |
| 848 | break; |
| 849 | fi |
| 850 | sleep 1 |
| 851 | done |
| 852 | echo "^---" >>"$LOGFILE" |
| 853 | rm -f "$LOGFILE.dmesg"* |
| 854 | if [ "$retry" -eq 0 ]; then |
| 855 | ECHO "SUSPEND FAILED, did not go to sleep" 1>&2 |
| 856 | return 1 |
| 857 | fi |
| 858 | } |
| 859 | |
| 860 | ECHO () |
| 861 | { |
| 862 | echo "$@" | tee -a "$LOGFILE" |
| 863 | } |
| 864 | |
| 865 | enable_trace() |
| 866 | { |
| 867 | if [ -w /sys/power/pm_trace ]; then |
| 868 | echo 1 > '/sys/power/pm_trace' |
| 869 | fi |
| 870 | } |
| 871 | |
| 872 | disable_trace() |
| 873 | { |
| 874 | if [ -w /sys/power/pm_trace ]; then |
| 875 | echo 0 > '/sys/power/pm_trace' |
| 876 | fi |
| 877 | } |
| 878 | |
| 879 | trace_state=-1 |
| 880 | |
| 881 | save_trace() |
| 882 | { |
| 883 | if [ -r /sys/power/pm_trace ]; then |
| 884 | trace_state=`cat /sys/power/pm_trace` |
| 885 | fi |
| 886 | } |
| 887 | |
| 888 | restore_trace() |
| 889 | { |
| 890 | if [ "$trace_state" -ne -1 -a -w /sys/power/pm_trace ]; then |
| 891 | echo "$trace_state" > '/sys/power/pm_trace' |
| 892 | fi |
| 893 | } |
| 894 | |
| 895 | battery_count() |
| 896 | { |
| 897 | cat /proc/acpi/battery/*/state 2>/dev/null | \ |
| 898 | awk ' |
| 899 | BEGIN { total = 0 } |
| 900 | /present:.*yes/ { total += 1 } |
| 901 | END { print total } |
| 902 | ' |
| 903 | } |
| 904 | |
| 905 | battery_capacity() |
| 906 | { |
| 907 | cat /proc/acpi/battery/*/state 2>/dev/null | \ |
| 908 | awk ' |
| 909 | BEGIN { total = 0 } |
| 910 | /remaining capacity:/ { total += $3 } |
| 911 | END { print total } |
| 912 | ' |
| 913 | } |
| 914 | |
| 915 | ac_needed=-1 |
| 916 | ac_is=-1 |
| 917 | ac_becomes=-1 |
| 918 | |
| 919 | ac_required() |
| 920 | { |
| 921 | ac_check |
| 922 | |
| 923 | ac_needed="$1" |
| 924 | ac_becomes="$1" |
| 925 | } |
| 926 | |
| 927 | ac_transitions() |
| 928 | { |
| 929 | ac_check |
| 930 | |
| 931 | ac_needed="$1" |
| 932 | ac_becomes="$2" |
| 933 | } |
| 934 | |
| 935 | ac_online() |
| 936 | { |
| 937 | cat /proc/acpi/ac_adapter/*/state 2>/dev/null | \ |
| 938 | awk ' |
| 939 | BEGIN { online = 0; offline = 0 } |
| 940 | /on-line/ { online = 1 } |
| 941 | /off-line/ { offline = 1 } |
| 942 | END { |
| 943 | if (online) { |
| 944 | print "1" |
| 945 | } else if (offline) { |
| 946 | print "0" |
| 947 | } else { |
| 948 | print "-1" |
| 949 | } |
| 950 | } |
| 951 | ' |
| 952 | } |
| 953 | |
| 954 | ac_check() |
| 955 | { |
| 956 | ac_current=`ac_online` |
| 957 | |
| 958 | if [ "$ac_becomes" -ne -1 -a "$ac_current" -ne -1 -a \ |
| 959 | "$ac_current" -ne "$ac_becomes" ]; then |
| 960 | ECHO "*** WARNING: AC power not in expected state" \ |
| 961 | "($ac_becomes) after test" |
| 962 | fi |
| 963 | ac_is="$ac_becomes" |
| 964 | } |
| 965 | |
| 966 | phase=0 |
| 967 | phase_first=1 |
| 968 | phase_interactive=1 |
| 969 | |
| 970 | phase() |
| 971 | { |
| 972 | phase=$((phase + 1)) |
| 973 | |
| 974 | if [ "$ac_needed" -ne "$ac_is" ]; then |
| 975 | case "$ac_needed" in |
| 976 | 0) echo "*** please ensure your AC cord is detached" ;; |
| 977 | 1) echo "*** please ensure your AC cord is attached" ;; |
| 978 | esac |
| 979 | ac_is="$ac_needed" |
| 980 | fi |
| 981 | |
| 982 | if [ "$timer_sleep" -gt 60 ]; then |
| 983 | sleep="$timer_sleep / 60" |
| 984 | sleep="$sleep minutes" |
| 985 | else |
| 986 | sleep="$timer_sleep seconds" |
| 987 | fi |
| 988 | echo "*** machine will suspend for $sleep" |
| 989 | |
| 990 | if [ "$auto" -eq 1 ]; then |
| 991 | : |
| 992 | elif [ "$phase_interactive" -eq 1 ]; then |
| 993 | echo "*** press return when ready" |
| 994 | read x |
| 995 | |
| 996 | elif [ "$phase_first" -eq 1 ]; then |
| 997 | echo "*** NOTE: there will be no further user interaction from this point" |
| 998 | echo "*** press return when ready" |
| 999 | phase_first=0 |
| 1000 | read x |
| 1001 | fi |
| 1002 | } |
| 1003 | |
| 1004 | save_trace |
| 1005 | |
| 1006 | if [ "$pm_trace" -eq 1 ]; then |
| 1007 | enable_trace |
| 1008 | else |
| 1009 | disable_trace |
| 1010 | fi |