APE: An Annotation Language and Middleware for Energy ...

APE: An Annotation Language and Middleware for Energy ...

APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development Nima Nikzad, Octav Chipara , and William G. Griswold [email protected] Dept. of Computer Science and Engineering, UC San Diego Dept. of Computer Science, University of Iowa Growth of Continuously-Running Mobile Applications Runs in background, out ofcan users sight How we run many CRM applications while Periodicminimizing workloads impact on battery life? Often delay-tolerant e.g., health monitoring, sports and news feeds, social networking 2

Low- and Application-level Optimizations are Both Needed Low-level Optimizations can only do so much DVFS, tickless kernels, radio scheduling, batched writes to flash, etc Application-level Optimizations are necessary Workload shaping, filtering, piggy-backing radio transmission, etc Take advantage of application specific behavior 3 Case Study: Nave Upload in CitiSense Thread == new Thread uploadThread uploadThread new Thread(new Thread(new Runnable() Runnable() {{ Alerts, Maps while(true) while(true) {{ try

try {{ Thread.sleep(1200000); Thread.sleep(1200000); // // Sleep Sleep 20 20 min. min. }} catch(InterruptedException catch(InterruptedException e) e) {{ attemptUpload(); attemptUpload(); }} }); }); uploadThread.start(); uploadThread.start(); CO, NO2, O3 4 Small Transmissions Big Impact Power 1W

6 sec. 12 sec. 10 mW t 5 Piggybacking is Effective for Amortizing Cost of Communication Power 1W 10 mW t 6 Code is Quickly Complicated by Power-Management Policy Thread uploadThread = new Thread(new Runnable() { Thread uploadThread = new Thread(new Runnable() {

Thread uploadThread == new Thread uploadThread new Thread(new Thread(new Runnable() Runnable() {{ while(true) {{ while(true) while(true) Intent == context.registerReceiver(null, while(true) { Intent batt batt { context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); try { new{ IntentFilter(Intent.ACTION_BATTERY_CHANGED)); try int lvl int

lvl == batt.getIntExtra(BatteryManager.EXTRA_LEVEL, batt.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); -1); Thread.sleep(1200000); Thread.sleep(1200000); int scl = batt.getIntExtra(BatteryManager.EXTRA_SCALE, -1); scl = batt.getIntExtra(BatteryManager.EXTRA_SCALE, -1); }}int catch(InterruptedException e) { catch(InterruptedException e) { float float batteryPct batteryPct == lvl lvl // (float) (float) scl; scl; attemptUpload(); attemptUpload(); try {{

try } if(batteryPct Thread.sleep(1200000); }} } if(batteryPct >> 70) 70) Thread.sleep(1200000); Thread uploadThread =={{ new Thread(new Runnable() Thread uploadThread new Thread(new Runnable() else { Thread.sleep(3600000); } }); else { Thread.sleep(3600000); } }); while(true) {{

}} catch(InterruptedException e) while(true) catch(InterruptedException e) {{ uploadThread.start(); uploadThread.start(); {{ attemptUpload(); try {attemptUpload(); try }} { TelephonyManager teleManager TelephonyManager teleManager == (TelephonyManager) (TelephonyManager) }); Thread.sleep(1200000); }); Thread.sleep(1200000); uploadThread.start(); uploadThread.start(); } catch(InterruptedException

} catch(InterruptedException e) e) {{ context.getSystemService(Context.TELEPHONY_SERVICE) context.getSystemService(Context.TELEPHONY_SERVICE) teleManager TelephonyManager teleManager == (TelephonyManager) (TelephonyManager) ;;TelephonyManager attemptUpload(); attemptUpload(); context.getSystemService(Context.TELEPHONY_SERVICE); context.getSystemService(Context.TELEPHONY_SERVICE); transListener new TransListener transListener == TransListener(); new TransListener(); TransListener(); }} TransListener TransListener TransListener transListener transListener == new new TransListener(); teleManager.listen(transListener, teleManager.listen(transListener,

teleManager.listen(transListener, }); }); teleManager.listen(transListener, PhoneStateListener.LISTEN_DATA_ACTIVITY); PhoneStateListener.LISTEN_DATA_ACTIVITY); PhoneStateListener.LISTEN_DATA_ACTIVITY); PhoneStateListener.LISTEN_DATA_ACTIVITY); uploadThread.start(); uploadThread.start(); private extends PhoneStateListener private class class TransListener extends PhoneStateListener {{ private class TransListener extends private classTransListener TransListener extends public void

onDataActivity(int act) {{ public void onDataActivity(int act) PhoneStateListener {{ PhoneStateListener if(act if(act == == TelephonyManager.DATA_ACTIVITY_IN TelephonyManager.DATA_ACTIVITY_IN public void onDataActivity(int act) public act) {{ || act TelephonyManager.DATA_ACTIVITY_OUT || void act == ==onDataActivity(int TelephonyManager.DATA_ACTIVITY_OUT if(act

== TelephonyManager.DATA_ACTIVITY_IN || TelephonyManager.DATA_ACTIVITY_INOUT) if(act ==== || act act ==TelephonyManager.DATA_ACTIVITY_IN TelephonyManager.DATA_ACTIVITY_INOUT) {{ uploadThread.interrupt(); || act == uploadThread.interrupt(); || act == TelephonyManager.DATA_ACTIVITY_OUT TelephonyManager.DATA_ACTIVITY_OUT }} || || act act == == }} TelephonyManager.DATA_ACTIVITY_INOUT) {{ TelephonyManager.DATA_ACTIVITY_INOUT) }} uploadThread.interrupt(); uploadThread.interrupt();

}} }} 7 Building Energy-Efficient Apps is Not Simple! Code for power-management tends to be complex Highly application specific Trade-off: Energy vs Timeliness and/or Accuracy Thread management, event and state change handling Optimizations should be postponed until application requirements are set Use cases and acceptable delay may change over time But Retrofitting Time + Bugs 8 What Do Energy-Management Policies Typically Look like? We examined the latest research, best-practice guides, documentation, and open-source projects Android Best Practice Guide, AT&T Research, [Wang09], [Nath12], [Nikzad12], [Musolesi10], Cyanogen Project Common thread: Timing and Device State! Wait until _______ before executing _______

9 APE is a Declarative Annotation Language and Runtime for Policies Thread uploadThread = new Thread(new Runnable() { while(true) { Intent batt = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int lvl = batt.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scl = batt.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float batteryPct = lvl / (float) scl; try { if(batteryPct > 70) { Thread.sleep(120000); } else { Thread.sleep(360000); } } catch(InterruptedException e) { attemptUpload(); } }); uploadThread.start(); Thread uploadThread = new Thread(new Runnable() { while(true) { @APE_If(Battery.Level > 70%) @APE_WaitUntil(Network.Active, MaxDelay=1200) @APE_Else() @APE_WaitUntil(Network.Active, MaxDelay=3600) TelephonyManager teleManager = (TelephonyManager) attemptUpload();

context.getSystemService(Context.TELEPHONY_SERVICE); } TransListener transListener = new TransListener(); teleManager.listen(transListener, }); PhoneStateListener.LISTEN_DATA_ACTIVITY); uploadThread.start(); private class TransListener extends PhoneStateListener { public void onDataActivity(int act) { if(act == TelephonyManager.DATA_ACTIVITY_IN || act == TelephonyManager.DATA_ACTIVITY_OUT || act == TelephonyManager.DATA_ACTIVITY_INOUT) { uploadThread.interrupt(); } } } 10 Rest of this Talk true : Net.Activity start cG 20 min : true while(true) while(true) {{ @APE_WaitUntil(Net.Active,

@APE_WaitUntil(Net.Active, MaxDelay=1200) MaxDelay=1200) uploadSensorData(); uploadSensorData(); }} OR WiFi AND NetAct OR 3G 4G 11 The APE Policy Model Effectively Modeling Policies Using Timed Automata Clarify semantics

Drive design of language and runtime 12 Many Policies Can Be Expressed Using Simple Timed Automata Wait up to 20 minutes for cellular network activity true : Net.Activity start cG 20 min : true 13 More Complicated Policies Can Fall Back to Earlier States Wait for movement using the accelerometer, then wait up to thirty seconds for driving to be detected start true : Accel.Move true : GPS.Drive cAcc 30 sec : true P = ({(Accel.Move, ), (GPS.Drive, 30 sec)}, )

14 Many Policies Can Be Expressed Using Very Simple Timed Automata Wait up to 20 minutes for cellular network activity true : Net.Activity start cG 20 min : true P = ({(Net.Active, )}, 20 min) 15 The APE Annotation Language Representing Power-management Policies as Annotations Expressing simple timed automata using text 16 APE_WaitUntil: Wait For Desired Device State Wait up to 20 minutes for cellular network activity P = ({(Net.Active, )}, 20 min) while(true)

{{ {{ while(true) while(true) while(true) @APE_WaitUntil(Net.Active, MaxDelay=1200 @APE_WaitUntil(Net.Active, MaxDelay=1200) @APE_WaitUntil(Net.Active, MaxDelay=1200 @APE_WaitUntil(Net.Active, MaxDelay=1200) PreWait=log(Started uploadSensorData(); PreWait=log(Started waiting for for activity), activity), uploadSensorData(); waiting }}PostWait=log(Activity PostWait=log(Activity detected!)) detected!)) uploadSensorData(); uploadSensorData(); }} 17 APE_WaitUntil:

Wait For Desired Device State Wait for movement using the accelerometer, then wait up to thirty seconds for driving to be detected P = ({(Accel.Move, ), (GPS.Drive, 30 sec)}, ) while(true) while(true) {{ @APE_WaitUntil(({accMove()},inf), @APE_WaitUntil(({accMove()},inf), ({gpsDrive()},30), ({gpsDrive()},30), MaxDelay=inf) MaxDelay=inf) downloadDriveData(); downloadDriveData(); }} 18 Other APE Constructs if-else constructs while(true) while(true) {{ @APE_If(Battery.Level @APE_If(Battery.Level >> 70%) 70%) @APE_WaitUntil(Net.Active, @APE_WaitUntil(Net.Active, MaxDelay=1800) MaxDelay=1800) @APE_Else()

@APE_Else() @APE_WaitUntil(WiFi.Connected, @APE_WaitUntil(WiFi.Connected, MaxDelay=3600) MaxDelay=3600) uploadSensorData(); uploadSensorData(); }} @APE_DefineTerm(MyTerm, Battery.Charging AND @APE_DefineTerm(MyTerm, Battery.Charging AND Creating new terms and saving policies (WiFi.Connected (WiFi.Connected OR OR Cell.4G)) Cell.4G)) @APE_DefinePolicy(MyPolicy, @APE_DefinePolicy(MyPolicy, (Display.Off,inf),(MyTerm,10)) (Display.Off,inf),(MyTerm,10)) 19 The APE Middleware Service

Runtime Hardware Monitoring on Behalf of Client Apps Minimizing overhead associated with monitoring 20 Annotations are Processed at Compile-time into Runtime Requests APE APE Annotated Annotated Source Source APE APE Annotation Annotation Preprocessor Preprocessor Source Source Including Including Generated Generated APE

APE Requests Requests 21 Client Process A Bind Register meWaitUntil(1) to Net.Active the APE Service as 1 APE Service A.1: Net.Active Client Process B Bind me to the APE Service Android System Clients Start Up the APE Service and Send Requests at Runtime

B.1: 22 APE Returns Control to the Calling Thread Once the Request is Satisfied Return WaitUntil(1) APE Data outgoing Service on cellular radio Tell me about changes in cellular A.1:state Net.Active Client Process B Android System Client Process A B.1:

23 Boolean Expressions Are Transformed into Expression Trees OR WiFi.Connected OR Network.Active AND (Cell.3G OR Cell.4G) WiFi AND NetAct OR 3G 4G 24 The APE Service Performs Device State Monitoring on Behalf of Clients TF F

APE Service OR WiFi TF TF NetAct TF FT F AND OR 3G T TF Network State Monitor Android System

F 4G F 25 Evaluation A Case Study of Optimizing a CRM Application Using APE How complicated are policies in practice? What are the potential benefits and overhead? 26 Case Study: CitiSense Thread uploadThread = new Thread(new Runnable() { while(true) { Intent batt = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int lvl = batt.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scl = batt.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float batteryPct = lvl / (float) scl;

try { if(batteryPct > 70) { Thread.sleep(1200000); } else { Thread.sleep(3600000); } } catch(InterruptedException e) { attemptUpload(); } }); uploadThread.start(); Thread uploadThread = new Thread(new Runnable() { while(true) { Thread uploadThread = new Thread(new Runnable() { @APE_If(Battery.Level > 70%) while(true) { @APE_WaitUntil(WiFi.Connected OR Network.Active @APE_If(Battery.Level > 70%) AND (Cell.3G OR Cell.4G), MaxDelay=1200) @APE_WaitUntil(Network.Active, MaxDelay=1200) @APE_Else() @APE_Else() @APE_WaitUntil(WiFi.Connected OR Network.Active @APE_WaitUntil(Network.Active, MaxDelay=3600) TelephonyManager teleManager = (TelephonyManager) AND (Cell.3G OR Cell.4G), MaxDelay=3600)

attemptUpload(); context.getSystemService(Context.TELEPHONY_SERVICE); attemptUpload(); TransListener transListener = new TransListener(); } teleManager.listen(transListener, } PhoneStateListener.LISTEN_DATA_ACTIVITY); }); }; uploadThread.start(); private class TransListener extends PhoneStateListener { uploadThread.start(); public void onDataActivity(int act) { if(act == TelephonyManager.DATA_ACTIVITY_IN || act == TelephonyManager.DATA_ACTIVITY_OUT || act == TelephonyManager.DATA_ACTIVITY_INOUT) { uploadThread.interrupt(); } Four APE annotations versus 45 lines of Java (thread suspension/waking, new class for handling callbacks, registering for callbacks) } } 27 Background Apps Can Repeatedly

Wake Resources Device Power Consumption Six application instances with no piggybacking 28 The Simplest of Policies Can Have a Big Impact on Power-Consumption Device Power Consumption Six application instances with @APE_WaitUntil(Net.Active, MaxDelay=120) 29 The Simplest of Policies Can Have a Big Impact on Power-Consumption APE Apps Non-APE Apps 600 Increase of 551.06 mw (63.7%) Increase in Power Consumption (mW)

500 400 300 200 Increase of 13.49 mw (1.6%) 100 0 0 1 2 3 4 5 Number of Additional Applications

Increase in power consumption after first instance 30 Overhead of Executing Each WaitUntil Call vs Hand-coded 25 Time to Resolve (ms) 20 15 Longest Expression from CitiSense 10 5 0 1 3 7 15

31 63 127 191 255 383 511 State Expression Length Overhead of IPC measured to be 1.71 ms 31 Limitations and Future Work Assumes developer is already aware of opportunities for energy savings Under Development: Automatically identifying costly operations and suggesting safe, effective policies User study to properly evaluate APEs ease-of-use

and sufficient expressibility of language 32 Conclusion Use of timing is widely applicable for powermanagement in mobile applications A simple annotation language and runtime can make this technique conveniently accessible to programmers Timed automata provide a semantic model that informs the design of language and runtime APE significantly eases the implementation of policies in CitiSense and achieves dramatic power-savings 33 Acknowledgement This work was supported by the National Science Foundation and the Roy J. Carver Charitable Trust William Griswold UC San Diego Octav Chipara Univ. of Iowa 34 Conclusion Use of timing is widely applicable for powermanagement in mobile applications

A simple annotation language and runtime can make this technique conveniently accessible to programmers Timed automata provide a semantic model that informs the design of language and runtime APE significantly eases the implementation of policies in CitiSense and achieves dramatic power-savings 35

Recently Viewed Presentations

  • French Revolution Document Gallery

    French Revolution Document Gallery

    Cause: Economic Problems . This Image shows "the people" as a chained and blindfolded man being crushed under the weight of the rich, that include both clergy and nobility.
  • CroninW_TB Epi_Genotyping_TBESC_2016

    CroninW_TB Epi_Genotyping_TBESC_2016

    Source: Population Action International. Have germs, will travel… Migrating . populations. TB Annual Update, March 22, 2016. This map show the travel has increased 4 fold from the 60s and 70s and note the heaviest arrows - most frequent paths...
  • Active workshop on reducing false alarms

    Active workshop on reducing false alarms

    Raman Chagger. Principal Consultant, Fire Safety Group, BRE. Emergency Evacuation Seminar, 3rd April 2019. Introduction Losses from false fire alarms ~£1 billion/year in the UK . ... Active workshop on reducing false alarms Last modified by:
  • Athens in the Age of Pericles

    Athens in the Age of Pericles

    Large number of citizens take an active part in voting for issues . ... Pericles Funeral Oration . Thucydides, a historian who lived during the age of Pericles . Recorded a speech by Pericles at the funeral of Athenians slayed...
  • Strategic Procurement Initiative: Maximize Your Budget & Time ...

    Strategic Procurement Initiative: Maximize Your Budget & Time ...

    Strategic Procurement Initiative Maximize Your Budget & Time Utilizing University-wide Contracts & iBuy UIC Administrative Staff Leadership Conference: Striving for Excellence
  • Agency Organization Chart_DEC_EXT

    Agency Organization Chart_DEC_EXT

    TEXAS DEPARTMENT OF INFORMATION RESOURCES (DIR)Organization Chart December 2018. GOVERNOR. DIR BOARD. INTERNAL AUDIT. Director (v) Cathy Sherwood, Interim. EXECUTIVE DIRECTOR (v)
  • "Who builds stronger than a mason, a shipwright, or a carpenter?"

    "Who builds stronger than a mason, a shipwright, or a carpenter?"

    Does it not, think thee, stand me now upon— He that hath killed my king and whored my mother, Popped in between th' election and my hopes, Killed his father and married his mother, (old news) but…. Hamlet outright says...
  • Knife Safety

    Knife Safety

    More accidents happen when using a dull knife because it may require more force. ... Serrated bread knife. Chef's Knife. Largest knife in the kitchen. Usually 8 - 10" long. Should feel comfortable and balanced in your hand. Should have...