1 / 35

APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development

APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development. Nima Nikzad , Octav Chipara † , and William G. Griswold nnikzad@cs.ucsd.edu Dept. of Computer Science and Engineering, UC San Diego Dept. of Computer Science, University of Iowa †.

bonnie
Download Presentation

APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development Nima Nikzad, OctavChipara†, and William G. Griswold nnikzad@cs.ucsd.edu Dept. of Computer Science and Engineering, UC San DiegoDept. of Computer Science, University of Iowa†

  2. Growth of Continuously-Running Mobile Applications • Runs in background, out of user’s sight • Periodic workloads • Often delay-tolerant • e.g., health monitoring, sports and news feeds, social networking How can we run many CRM applicationswhile minimizing impact on battery life?

  3. 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

  4. Case Study: Naïve Upload in CitiSense Thread uploadThread = new Thread(new Runnable() { while(true) { try {Thread.sleep(1200000); // Sleep 20 min. } catch(InterruptedException e) {attemptUpload(); }});uploadThread.start(); Alerts, Maps CO, NO2, O3

  5. Small Transmissions  Big Impact 6 sec. 1 W Power 12 sec. 10 mW t

  6. Piggybacking is Effective for Amortizing Cost of Communication 1 W Power 10 mW t

  7. Code is Quickly Complicated by Power-Management Policy Thread uploadThread = new Thread(new Runnable() { while(true) { Intent batt = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));intlvl = batt.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);intscl = 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();TelephonyManagerteleManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); TransListenertransListener = new TransListener(); teleManager.listen(transListener,PhoneStateListener.LISTEN_DATA_ACTIVITY);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(); } }} Thread uploadThread = new Thread(new Runnable() { while(true) { try { Thread.sleep(1200000); } catch(InterruptedException e) {attemptUpload(); }});uploadThread.start();TelephonyManagerteleManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); TransListenertransListener = new TransListener(); teleManager.listen(transListener,PhoneStateListener.LISTEN_DATA_ACTIVITY);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(); } }} Thread uploadThread = new Thread(new Runnable() { while(true) { try {Thread.sleep(1200000); } catch(InterruptedException e) {attemptUpload(); }});uploadThread.start();

  8. Building Energy-Efficient Appsis 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

  9. 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 _______”

  10. 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));intlvl = batt.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);intscl = 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();TelephonyManagerteleManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); TransListenertransListener = new TransListener(); teleManager.listen(transListener,PhoneStateListener.LISTEN_DATA_ACTIVITY);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(); } }} 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)attemptUpload(); }});uploadThread.start();

  11. Rest of this Talk while(true) {@APE_WaitUntil(“Net.Active”, MaxDelay=1200)uploadSensorData();} OR true : Net.Activity WiFi AND start NetAct OR cG ≥ 20 min : true 3G 4G

  12. The APE Policy Model Effectively Modeling Policies Using Timed Automata Clarify semantics Drive design of language and runtime

  13. 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

  14. More Complicated Policies CanFall Back to Earlier States Wait for movement using the accelerometer, then wait up to thirty seconds for driving to be detected true : Accel.Move true : GPS.Drive start cAcc ≥ 30 sec : true P = ({(Accel.Move, ∞), (GPS.Drive, 30 sec)}, ∞)

  15. 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)

  16. The APE Annotation Language Representing Power-management Policies as Annotations Expressing simple timed automata using text

  17. APE_WaitUntil:Wait For Desired Device State Wait up to 20 minutes for cellular network activity P = ({(Net.Active, ∞)}, 20 min) while(true) {@APE_WaitUntil(“Net.Active”, MaxDelay=1200PreWait=“log(‘Started waiting for activity…’)”,PostWait=“log(‘Activity detected!’)”)uploadSensorData();} while(true) {@APE_WaitUntil(“Net.Active”, MaxDelay=1200)uploadSensorData();}

  18. 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) {@APE_WaitUntil(“({accMove()},inf), ({gpsDrive()},30)”, MaxDelay=inf)downloadDriveData();}

  19. Other APE Constructs • if-else constructs • Creating new terms and saving policies while(true) { @APE_If(“Battery.Level > 70%”) @APE_WaitUntil(“Net.Active”, MaxDelay=1800) @APE_Else() @APE_WaitUntil(“WiFi.Connected”, MaxDelay=3600)uploadSensorData();} @APE_DefineTerm(“MyTerm”, “Battery.Charging AND (WiFi.Connected OR Cell.4G)”) @APE_DefinePolicy(“MyPolicy”, “(Display.Off,inf),(MyTerm,10)”)

  20. The APE Middleware Service Runtime Hardware Monitoring on Behalf of Client Apps Minimizing overhead associated with monitoring

  21. Annotations are Processed at Compile-time into Runtime Requests APE Annotation Preprocessor SourceIncluding GeneratedAPE Requests APEAnnotatedSource

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

  23. APE Returns Control to the Calling Thread Once the Request is Satisfied APE Service Client Process A Return WaitUntil(1) Data outgoingon cellular radio Android System Tell me aboutchanges incellular state A.1:Net.Active B.1:… Client Process B

  24. 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

  25. The APE Service Performs Device State Monitoring on Behalf of Clients APE Service T F T F F OR T F T F WiFi AND T F F NetAct OR T T F F F Network State Monitor 3G 4G Android System

  26. Evaluation A Case Study of Optimizing a CRM Application Using APE How complicated are policies in practice? What are the potential benefits and overhead?

  27. Case Study: CitiSense Thread uploadThread = new Thread(new Runnable() { while(true) { Intent batt = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));intlvl = batt.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);intscl = 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();TelephonyManagerteleManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); TransListenertransListener = new TransListener(); teleManager.listen(transListener,PhoneStateListener.LISTEN_DATA_ACTIVITY);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(); } }} Thread uploadThread = new Thread(new Runnable() { while(true) {@APE_If(“Battery.Level > 70%”) @APE_WaitUntil(“WiFi.Connected OR Network.Active AND (Cell.3G OR Cell.4G)”, MaxDelay=1200) @APE_Else() @APE_WaitUntil(“WiFi.Connected OR Network.Active AND (Cell.3G OR Cell.4G)”, MaxDelay=3600)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)attemptUpload(); }});uploadThread.start(); Four APE annotations versus 45 lines of Java(thread suspension/waking, new class for handling callbacks, registering for callbacks)

  28. Background Apps Can Repeatedly Wake Resources Device Power Consumption Six application instanceswith no piggybacking

  29. The Simplest of Policies Can Have a Big Impact on Power-Consumption Device Power Consumption Six application instanceswith @APE_WaitUntil(“Net.Active”, MaxDelay=120)

  30. The Simplest of Policies Can Have a Big Impact on Power-Consumption Increase of 551.06 mw (63.7%) Increase of 13.49 mw (1.6%) Increase in power consumption after first instance

  31. Overhead of Executing Each WaitUntil Call vs Hand-coded Longest Expression from CitiSense Overhead of IPC measured to be 1.71 ms

  32. 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 APE’s ease-of-use and sufficient expressibility of language

  33. Conclusion • Use of timing is widely applicable for power-management 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 easesthe implementation of policies in CitiSense and achieves dramatic power-savings

  34. Acknowledgement • This work was supported by the National Science Foundation and the Roy J. Carver Charitable Trust William Griswold UC San Diego OctavChipara Univ. of Iowa

  35. Conclusion • Use of timing is widely applicable for power-management 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 easesthe implementation of policies in CitiSense and achieves dramatic power-savings

More Related