1 page.title=Measuring Component Power 2 @jd:body 3 4 <!-- 5 Copyright 2015 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 --> 19 <div id="qv-wrapper"> 20 <div id="qv"> 21 <h2>In this document</h2> 22 <ol id="auto-toc"></ol> 23 </div> 24 </div> 25 26 27 <p>You can determine individual component power consumption by comparing the current drawn by the 28 device when the component is in the desired state (on, active, scanning, etc.) and when the 29 component is off. Measure the average instantaneous current drawn on the device at a 30 nominal voltage using an external power monitor, such as a bench power supply or specialized 31 battery-monitoring tools (such as Monsoon Solution Inc. Power Monitor and Power Tool software).</p> 32 33 <p>Manufacturers often supply information about the current consumed by an individual component. 34 Use this information if it accurately represents the current drawn from the device battery in 35 practice. However, validate manufacturer-provided values before using those values in your device 36 power profile.</p> 37 38 <h2 id="control-consumption">Controlling power consumption</h2> 39 40 <p>When measuring, ensure the device does not have a connection to an external charge source, such 41 as a USB connection to a development host used when running Android Debug Bridge (adb). The device 42 under test might draw current from the host, thus lowering measurements at the battery. Avoid USB 43 On-The-Go (OTG) connections, as the OTG device might draw current from the device under test.</p> 44 45 <p>Excluding the component being measured, the system should run at a constant level of power 46 consumption to avoid inaccurate measurements caused by changes in other components. System 47 activities that can introduce unwanted changes to power measurements include:</p> 48 49 <ul> 50 <li><strong>Cellular, Wi-Fi, and Bluetooth receive, transmit, or scanning activity</strong>. When 51 not measuring cell radio power, set the device to airplane mode and enable Wi-Fi or Bluetooth as 52 appropriate.</li> 53 <li><strong>Screen on/off</strong>. Colors displayed while the screen is on can affect power draw 54 on some screen technologies. Turn the screen off when measuring values for non-screen components.</li> 55 <li><strong>System suspend/resume</strong>. A screen off state can trigger a system suspension, 56 placing parts of the device in a low-power or off state. This can affect power consumption of the 57 component being measured and introduce large variances in power readings as the system periodically 58 resumes to send alarms, etc. For details, see <a href="#control-suspend">Controlling system 59 suspend</a>.</li> 60 <li><strong>CPUs changing speed and entering/exiting low-power scheduler idle state</strong>. 61 During normal operation, the system makes frequent adjustments to CPU speeds, the number of online 62 CPU cores, and other system core states such as memory bus speed and voltages of power rails 63 associated with CPUs and memory. During testing, these adjustments affect power measurements: 64 <ul> 65 <li>CPU speed scaling operations can reduce the amount of clock and voltage scaling of memory buses 66 and other system core components.</li> 67 <li>Scheduling activity can affect the percentage of the time CPUs spend in low-power idle states. 68 For details on preventing these adjustments from occurring during testing, see 69 <a href="#control-cpu">Controlling CPU speeds</a>.</li> 70 </ul> 71 72 </li> 73 </ul> 74 75 <p>For example, Joe Droid wants to compute the <code>screen.on</code> value for a device. He 76 enables airplane mode on the device, runs the device at a stable current state, holds the CPU 77 speed constant, and uses a partial wakelock to prevent system suspend. Joe then turns the device 78 screen off and takes a measurement (200mA). Next, Joe turns the device screen on at minimum 79 brightness and takes another measurement (300mA). The <code>screen.on</code> value is 100mA (300 - 80 200).</p> 81 82 <p class="note"> 83 <strong>Note</strong>: For components that dont have a flat waveform of current consumption when 84 active (such as cellular radio or Wi-Fi), measure the average current over time using a power 85 monitoring tool.</p> 86 87 <p>When using an external power source in place of the device battery, the system might experience 88 problems due to an unconnected battery thermistor or integrated fuel gauge pins (i.e. an invalid 89 reading for battery temperature or remaining battery capacity could shut down the kernel or Android 90 system). Fake batteries can provide signals on thermistor or fuel gauge pins that mimic temperature 91 and state of charge readings for a normal system, and may also provide convenient leads for 92 connecting to external power supplies. Alternatively, you can modify the system to ignore the 93 invalid data from the missing battery.</p> 94 95 <h2 id="control-suspend">Controlling system suspend</h2> 96 97 <p>This section describes how to avoid system suspend state when you dont want it to interfere 98 with other measurements, and how to measure the power draw of system suspend state when you do 99 want to measure it.</p> 100 101 <h3 id="prevent-suspend">Preventing system suspend</h3> 102 103 <p>System suspend can introduce unwanted variance in power measurements and place system components 104 in low-power states inappropriate for measuring active power use. To prevent the system from 105 suspending while the screen is off, use a temporary partial wakelock. Using a USB cable, connect 106 the device to a development host, then issue the following command:</p> 107 108 <pre> 109 $ adb shell "echo temporary > /sys/power/wake_lock" 110 </pre> 111 112 <p>While in <code>wake_lock</code>, the screen off state does not trigger a system suspend. 113 (Remember to disconnect the USB cable from the device before measuring power consumption.)</p> 114 115 <p>To remove the wakelock:</p> 116 117 <pre> 118 $ adb shell "echo temporary > /sys/power/wake_unlock" 119 </pre> 120 121 <h3 id="measure-suspend">Measuring system suspend</h3> 122 123 <p>To measure the power draw during the system suspend state, measure the value of 124 <code>cpu.idle</code> in the power profile. Before measuring: 125 126 <ul> 127 <li>Remove existing wakelocks (as described above).</li> 128 <li>Place the device in airplane mode to avoid concurrent activity by the cellular radio, which 129 might run on a processor separate from the SoC portions controlled by the system suspend.</li> 130 <li>Ensure the system is in suspend state by: 131 <ul> 132 <li>Confirming current readings settle to a steady value. Readings should be within the expected 133 range for the power consumption of the SoC suspend state plus the power consumption of system 134 components that remain powered (such as the USB PHY).</li> 135 <li>Checking the system console output.</li> 136 <li>Watching for external indications of system status (such as an LED turning off when not in 137 suspend).</li> 138 </ul> 139 </li> 140 </ul> 141 142 <h2 id="control-cpu">Controlling CPU speeds</h2> 143 144 <p>Active CPUs can be brought online or put offline, have their clock speeds and associated 145 voltages changed (possibly also affecting memory bus speeds and other system core power states), 146 and can enter lower power idle states while in the kernel idle loop. When measuring different CPU 147 power states for the power profile, avoid the power draw variance when measuring other parameters. 148 The power profile assumes all CPUs have the same available speeds and power characteristics.</p> 149 150 <p>While measuring CPU power, or while holding CPU power constant to make other measurements, keep 151 the number of CPUs brought online constant (such as having one CPU online and the rest 152 offline/hotplugged out). Keeping all CPUs except one in scheduling idle may product acceptable 153 results. Stopping the Android framework with <code>adb shell stop</code> can reduce system 154 scheduling activity.</p> 155 156 <p>You must specify the available CPU speeds for your device in the power profile <code>cpu.speeds</code> entry. To get a list of available CPU speeds, run:</p> 157 158 <pre> 159 adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state 160 </pre> 161 162 <p>These speeds match the corresponding power measurements in value <code>cpu.active</code>.</p> 163 164 <p>For platforms where number of cores brought online significantly affects power consumption, you 165 might need to modify the cpufreq driver or governor for the platform. Most platforms support 166 controlling CPU speed using the userspace cpufreq governor and using sysfs interfaces to set the 167 speed. For example, to set speed for 200MHz on a system with only 1 CPU or all CPUs sharing a 168 common cpufreq policy, use the system console or adb shell to run the following commands:</p> 169 170 <pre> 171 echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 172 echo 200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 173 echo 200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq 174 echo 200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed 175 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 176 </pre> 177 178 <p class="note"> 179 <strong>Note</strong>: The exact commands differ depending on the platform cpufreq implementation. 180 </p> 181 182 <p>These commands ensure the new speed is not outside the allowed bounds, set the new speed, then 183 print the speed at which the CPU is actually running (for verification). If the current 184 minimum speed prior to execution is higher than 200000, you might need to reverse the order 185 of the first two lines, or execute the first line again to drop the minimum speed prior to 186 setting the maximum speed.</p> 187 188 <p>To measure current consumed by a CPU running at various speeds, use the system console to place 189 the CPU in a CPU-bound loop using the command:</p> 190 <pre> 191 # while true; do true; done 192 </pre> 193 194 <p>Take the measurement while the loop executes.</p> 195 196 <p>Some devices can limit maximum CPU speed while performing thermal throttling due to a high 197 temperature measurement (i.e. after running CPUs at high speeds for sustained periods). Watch for 198 such limiting, either using the system console output when taking measurements or by checking the 199 kernel log after measuring.</p> 200 201 <p>For the <code>cpu.awake</code> value, measure the power consumed when the system is not in 202 suspend and not executing tasks. The CPU should be in a low-power scheduler <em>idle loop 203 </em>, possibly executing an ARM Wait For Event instruction or in an SoC-specific low-power state 204 with a fast-exit latency suitable for idle use.</p> 205 206 <p>For the <code>cpu.active</code> value, measure power when the system is not in suspend mode and not executing tasks. One CPU (usually the primary CPU) should run the task while all other CPUs 207 should be in an idle state.</p> 208 209 <h2 id="screen-power">Measuring screen power</h2> 210 211 <p>When measuring screen on power, ensure that other devices normally turned on when the screen is 212 enabled are also on. For example, if the touchscreen and display backlight would normally be on 213 when the screen is on, ensure these devices are on when you measure to get a realistic example of 214 screen on power usage.</p> 215 216 <p>Some display technologies vary in power consumption according to the colors displayed, causing 217 power measurements to vary considerably depending on what is displayed on the screen at the time of 218 measurement. When measuring, ensure the screen is displaying something that has power 219 characteristics of a realistic screen. Aim between the extremes of an all-black screen (which 220 consumes the lowest power for some technologies) and an all-white screen. A common choice is a view 221 of a schedule in the calendar app, which has a mix of white background and non-white elements.</p> 222 223 <p>Measure screen on power at <em>minimum</em> and <em>maximum</em> display/backlight brightness. 224 To set minimum brightness:</p> 225 226 <ul> 227 <li><strong>Use the Android UI</strong> (not recommended). Set the Settings > Display Brightness 228 slider to the minimum display brightness. However, the Android UI allows setting brightness only to 229 a minimum of 10-20% of the possible panel/backlight brightness, and does not allow setting 230 brightness so low that the screen might not be visible without great effort.</li> 231 <li><strong>Use a sysfs file</strong> (recommended). If available, use a sysfs file to control 232 panel brightness all the way down to the minimum brightness supported by the hardware.</li> 233 </ul> 234 235 <p>Additionally, if the platform sysfs file enables turning the LCD panel, backlight, and 236 touchscreen on and off, use the file to take measurements with the screen on and off. Otherwise, 237 set a partial wakelock so the system does not suspend, then turn on and off the 238 screen with the power button.</p> 239 240 <h2 id="wifi-power">Measuring Wi-Fi power</h2> 241 242 <p>Perform Wi-Fi measurements on a relatively quiet network. Avoid introducing additional work 243 processing high volumes of broadcast traffic that is unrelated to the activity being measured.</p> 244 245 <p>The <code>wifi.on</code> value measures the power consumed when Wi-Fi is enabled but not 246 actively transmitting or receiving. This is often measured as the delta between the current draw in 247 system suspend (sleep) state with Wi-Fi enabled vs. disabled.</p> 248 249 <p>The <code>wifi.scan</code> value measures the power consumed during a Wi-Fi scan for access 250 points. Applications can trigger Wi-Fi scans using the WifiManager class 251 <a href ="http://developer.android.com/reference/android/net/wifi/WifiManager.html"> 252 <code>startScan()</code>API</a>. You can also open Settings > Wi-Fi, which performs access point 253 scans every few seconds with an apparent jump in power consumption, but you must subtract screen 254 power from these measurements.</p> 255 256 <p class="note"> 257 <strong>Note</strong>: Use a controlled setup (such as 258 <a href="http://en.wikipedia.org/wiki/Iperf">iperf</a>) to generate network receive and transmit 259 traffic.</p>