Tips and Tricks: Designing low power Native and WebApps

Harita Chilukuri and Abhishek Dhanotia Acknowledgements

• William Baughman for his help with the browser analysis • Ross Burton & Thomas Wood for information on Architecture • Tom Baker, Luis “Fernando” Recalde, Raji Shunmuganathan and Yamini Nimmagadda for reviews and comments

2 tizen.org Power – Onus lies on too!

Use system resources to provide best User WEBAPPS Experience with minimum power NATIVE APPS RUNTIME

Interfaces with HW components, DRIVERS / MIDDLEWARE Independent device power management

Frequency Governors, CPU Power OS Management ACPI/RTPM

Provides features for low power HARDWARE Clock Gating, Power Gating, Sleep States

3 tizen.org Power – Onus lies on Software too!

• A single bad application can lead to exceeding power budget • Hardware and OS provide many features for low power – Apps need to use them smartly to improve power efficiency • Good understanding of underlying system can help in designing better apps

Images are properties of their respective owners 4 tizen.org Agenda

Tips for Power Tools General Low Power Q&A & Metrics guidelines Applications

5 tizen.org Estimating Power - Metrics

• CPU utilization • Memory bandwidth • CPU C and P state residencies • Device D states - For non-CPU components • S states – system sleep states • Wakeups, interrupts

Soft metrics can help tune the application for optimal power

6 tizen.org Estimating Power - Tools

• CPU utilization – Vmstat, Top – VTune, Perf for CPU cycles • Memory bandwidth – Vtune • CPU C and P states, Device D states – VTune, Powertop • Wakeups, Interrupts, Timers – Powertop, /proc stats • Tracing tool in Chrome browser ** VTune is an product and can be purchased, others are publicly available tools

* Other names and brands may be claimed as the property of others. 7 tizen.org

Tip 1: Minimize wakeups, they are expensive

8 tizen.org Tip 1: Minimize wakeups

• Classic case of a single application exhausting the power budget • Wakeups from each app add up – Even if its just 0.5 wakeups/sec

160 140

120 )

100 mW 80 60 Power ( Power 40 20 0 100wakes 80wakes 60wakes 40wakes 20wakes 10wakes 1 wakes Total system wakeups from all applications

9 tizen.org Tip 1: Minimize wakeups

Polling, Frequent I/O Timers 1400 160

1200 140

120

1000

) 100

800 mW 80 600

60 Power ( Power

400 Background Life (hrs) Battery Activity 40

200 20

0 0 168 78 40 20 17 10 8 Wakeups/sec Power Battery Life

10 tizen.org Tip 1: Minimize wakeups

• How to reduce wakeups - Polling - High frequency timers - Avoid frequent I/O + Maximize the work done when the system wakes up, batch operations + Longer sleep time is better than frequent shorter sleep times

Apps accessing data from peripheral components/sensors • GPS, Games using accelerometer etc.

Apps doing periodic updates • Push notifications instead of polling

Images are properties of their respective owners 11 tizen.org Tip 2 Use Hardware Acceleration

12 tizen.org Tip 2: Use hardware acceleration

HW Overlay and Decoding in Compositing Rendering in GPU Audio Engine in GPU 120

100

80

60 CPU C0 C0 CPU % 40

20

0 Video Playback Audio Playback HTML5 Video Webapp SW based functions HW Accelerated functions

13 tizen.org Tip 2: Use hardware acceleration

Caveats • Benefits from acceleration vary based on use case • HW Acceleration improves performance only when TIME (memcpy + work in HW) < TIME (work in SW) • Power Software Hardware Acc CPU GPU Memory

14 tizen.org Tip 2: Use hardware acceleration

• Common formats that are usually accelerated or optimized • Developers should use these when applicable

Video Audio Browser

MPEG2 MP3 GPU Accelerated Compositing

MPEG4 AAC GPU Rendering

H264 EGL

VC1

• Media apps, local playback and streaming • Games

Images are properties of their respective owners 15 tizen.org Tip 3: Don’t shoot for performance beyond what a user can perceive

16 tizen.org Tip 3: Performance Vs. Power Tradeoff

• Video playback power use with different frame rates 3

2.5 ~2.5x increase from 2 30-60 fps FPS = 15 1.5 FPS = 30 FPS = 45 1 FPS = 60

0.5

0 CPU% Power

* Power here is the difference between system idle and video playback, data normalized to 30 fps.

17 tizen.org Tip3: Performance Vs. Power Tradeoff

– Trying to maximize performance without knowledge of user expectation + Make a tradeoff

Media Apps • Videos beyond 30 fps are rarely perceivable on mobile devices • Audio bit rates beyond audio HW output capacity won’t sound better Games • Screen refresh rates are 60/120Hz, frames are dropped beyond that • 60 fps may be overkill for some applications

Images are properties of their respective owners 18 tizen.org Tip 4: Minimize Latency & JavaScript

19 tizen.org Tip 4: Minimize Latency & JavaScript 3 Server latency = 138ms

2.5 Server latency = 1.2s 2

1.5

1 SOC Power (Watts) Power SOC

0.5

0

9 1 5

37 65 93 13 17 21 25 29 33 41 45 49 53 57 61 69 73 77 81 85 89 97

101 105 109 113 117 121 125 129 133 137 141 145 149 153 157 161 165 169 173 177 181 185 189 193 197 201 205 209 213 217 221 Time Google Search Ask Search

Average SOC power for Google search is 919mW, for Ask search, its 1031mW, ~10% difference

20 tizen.org Tip 4: Minimize Latency & JavaScript 3 JavaScript, Issue more requests to different domains

2.5

2

1.5

1 SOC Power (Watts) Power SOC

0.5

0

1 5 9

45 13 17 21 25 29 33 37 41 49 53 57 61 65 69 73 77 81 85 89 93 97

141 185 101 105 109 113 117 121 125 129 133 137 145 149 153 157 161 165 169 173 177 181 189 193 197 201 205 209 213 217 221 Time Google Search Ask Search

21 tizen.org Tip 4: Minimize Latency & JavaScript 3

2.5 Receiving more data 2

1.5

1 SOC Power(Watts) SOC

0.5

0

6 1

11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96

136 171 101 106 111 116 121 126 131 141 146 151 156 161 166 176 181 186 191 196 201 206 211 216 221 Time Google Search Ask Search

22 tizen.org Tip 4: Minimize Latency & JavaScript

+ Batch requests + Cache external resources - Many sequential connections - Long latencies • Ask batches some requests, but not all.

Web Applications

Images are properties of their respective owners 23 tizen.org Tip 5: Minimize Comm. Power

24 tizen.org Tip 5: Minimize comm. power

0.8 Difference in server response latencies causes wider active time for Wifi

0.7

0.6

0.5 (watts) 0.4

Power 0.3

0.2 WiFi 0.1

0

1

12 23 34 45 56 67 78 89

111

221 232 243 254 265 100 122 133 144 155 166 177 188 199 210 276 287 298 309 320 331 342 353 364 375 386 397 408 419 430 441 452 463 474 485 496 507 Time ASK Wifi Google Wifi

25 tizen.org Tip 5: Minimize comm. power

0.8 Data Request => Active Connection => Wide Wifi Power Wakeups => More Power

0.7

0.6

0.5

0.4

Power (watts)Power 0.3

0.2 WiFi 0.1

0

1

12 23 34 45 56 67 78 89

111

221 232 243 254 265 100 122 133 144 155 166 177 188 199 210 276 287 298 309 320 331 342 353 364 375 386 397 408 419 430 441 452 463 474 485 496 507 Time ASK Wifi Google Wifi

26 tizen.org Tip 5: Minimize comm. power

• How can you reduce Wi-Fi power consumption? + Batch processing - Long latencies

Web Applications

Images are properties of their respective owners 27 tizen.org Some other general guidelines for low power • Context awareness – Minimize system resource use when not in foreground • Subscribe to screen and other system events – Free up temporary cache, files, and images • Clean idle – Use resources only when user is active – Only act on user input • does piggybacking or deferring tasks to the next system wakeup work? – The power profile of an idle app should match system idle – Idle system CPU utilization target is less than 1%

28 tizen.org Summary

• Battery life is an important selling factor • Keep power in mind from Day 0 of development • Follow our tips to make a good app-world citizen

Enjoy Developing Green Apps !

Email us at [email protected] & [email protected]

29 tizen.org