APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development
description
Transcript of APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development
![Page 1: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/1.jpg)
APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development
Nima Nikzad, Octav Chipara†, and William G. Griswold
[email protected]. of Computer Science and Engineering, UC San Diego
Dept. of Computer Science, University of Iowa†
![Page 2: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/2.jpg)
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?
![Page 3: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/3.jpg)
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
![Page 4: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/4.jpg)
4
Thread uploadThread = new Thread(new Runnable() { while(true) { try { Thread.sleep(1200000); // Sleep 20 min. } catch(InterruptedException e) { attemptUpload(); }});uploadThread.start();
Case Study: Naïve Upload in CitiSense
CO, NO2, O3
Alerts, Maps
![Page 5: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/5.jpg)
5
Small Transmissions Big Impact
t
Pow
er
6 sec.
12 sec.
1 W
10 mW
![Page 6: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/6.jpg)
6
t
Pow
er
Piggybacking is Effective for Amortizing Cost of Communication
1 W
10 mW
![Page 7: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/7.jpg)
7
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();
TelephonyManager teleManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);TransListener transListener = 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(); } }}
Code is Quickly Complicated by Power-Management Policy
Thread uploadThread = new Thread(new Runnable() { while(true) { try { Thread.sleep(1200000); } catch(InterruptedException e) { attemptUpload(); }});uploadThread.start();
Thread uploadThread = new Thread(new Runnable() { while(true) { try { Thread.sleep(1200000); } catch(InterruptedException e) { attemptUpload(); }});uploadThread.start();
TelephonyManager teleManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);TransListener transListener = 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(); } }}
![Page 8: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/8.jpg)
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
![Page 9: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/9.jpg)
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 _______”
![Page 10: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/10.jpg)
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)); 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();
TelephonyManager teleManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);TransListener transListener = 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();
![Page 11: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/11.jpg)
11
Rest of this Talk
cG ≥ 20 min : truestart
true : Net.Activity
while(true) { @APE_WaitUntil(“Net.Active”, MaxDelay=1200) uploadSensorData();}
OR
WiFi AND
ORNetAct
3G 4G
![Page 12: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/12.jpg)
12
The APE Policy ModelEffectively Modeling Policies Using Timed Automata• Clarify semantics
• Drive design of language and runtime
![Page 13: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/13.jpg)
13
Many Policies Can Be Expressed Using Simple Timed Automata
Wait up to 20 minutes for cellular network activity
cG ≥ 20 min : truestart
true : Net.Activity
![Page 14: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/14.jpg)
14
P = ({(Accel.Move, ∞), (GPS.Drive, 30 sec)}, ∞)
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
cAcc ≥ 30 sec : truetrue : GPS.Drivestart
![Page 15: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/15.jpg)
15
Many Policies Can Be Expressed Using Very Simple Timed Automata
Wait up to 20 minutes for cellular network activity
P = ({(Net.Active, ∞)}, 20 min)
cG ≥ 20 min : truestart
true : Net.Activity
![Page 16: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/16.jpg)
16
The APE Annotation LanguageRepresenting Power-management Policies as Annotations• Expressing simple timed automata using text
![Page 17: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/17.jpg)
17
while(true) { @APE_WaitUntil(“Net.Active”, MaxDelay=1200 PreWait=“log(‘Started waiting for activity…’)”, PostWait=“log(‘Activity detected!’)”) uploadSensorData();}
while(true) { @APE_WaitUntil(“Net.Active”, MaxDelay=1200) uploadSensorData();}
APE_WaitUntil:Wait For Desired Device State
P = ({(Net.Active, ∞)}, 20 min)
Wait up to 20 minutes for cellular network activity
![Page 18: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/18.jpg)
18
APE_WaitUntil:Wait For Desired Device State
P = ({(Accel.Move, ∞), (GPS.Drive, 30 sec)}, ∞)
while(true) { @APE_WaitUntil(“({accMove()},inf), ({gpsDrive()},30)”, MaxDelay=inf) downloadDriveData();}
Wait for movement using the accelerometer, then wait up to thirty seconds for driving to be detected
![Page 19: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/19.jpg)
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)”)
![Page 20: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/20.jpg)
20
The APE Middleware ServiceRuntime Hardware Monitoring on Behalf of Client Apps• Minimizing overhead associated with monitoring
![Page 21: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/21.jpg)
21
Annotations are Processed at Compile-time into Runtime Requests
APEAnnotated
Source
SourceIncluding
GeneratedAPE
Requests
APE AnnotationPreprocessor
![Page 22: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/22.jpg)
22
Clients Start Up the APE Service and Send Requests at Runtime
Client Process A
Andr
oid
Syst
em
Bind me to the APE Service APE Service
Client Process BBind me to the APE Service
WaitUntil(1)
A.1:Net.Active
B.1:…
A.1:Net.Active
Register “Net.Active” as 1
![Page 23: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/23.jpg)
23
APE Service
A.1:Net.Active
B.1:…
APE Returns Control to the Calling Thread Once the Request is Satisfied
Andr
oid
Syst
em
Client Process A
Client Process B
Tell me aboutchanges in
cellular state
Data outgoingon cellular radio
Return WaitUntil(1)
![Page 24: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/24.jpg)
24
Boolean Expressions Are Transformed into Expression Trees
WiFi.Connected OR Network.Active AND (Cell.3G OR Cell.4G)OR
WiFi AND
ORNetAct
3G 4G
![Page 25: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/25.jpg)
25
APE Service
The APE Service Performs Device State Monitoring on Behalf of Clients
OR
WiFi AND
ORNetAct
3G 4G
Network State Monitor
Android System
F
F F
F F
F F
F F T F
T
T
T
T
T
T
![Page 26: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/26.jpg)
26
EvaluationA Case Study of Optimizing a CRM Application Using APE• How complicated are policies in practice?
• What are the potential benefits and overhead?
![Page 27: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/27.jpg)
27
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();
TelephonyManager teleManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);TransListener transListener = 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();
Case Study: CitiSense
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();
Four APE annotations versus 45 lines of Java(thread suspension/waking, new class for handling callbacks, registering for callbacks)
![Page 28: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/28.jpg)
28
Device Power Consumption
Background Apps Can Repeatedly Wake Resources
Six application instanceswith no piggybacking
![Page 29: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/29.jpg)
29
The Simplest of Policies Can Have a Big Impact on Power-Consumption
Six application instanceswith @APE_WaitUntil(“Net.Active”, MaxDelay=120)
Device Power Consumption
![Page 30: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/30.jpg)
30
0 1 2 3 4 50
100
200
300
400
500
600
APE Apps Non-APE Apps
Number of Additional Applications
Incr
ease
in P
ower
Con
sum
ption
(mW
)
Increase in power consumption after first instance
The Simplest of Policies Can Have a Big Impact on Power-Consumption
Increase of 13.49 mw (1.6%)
Increase of 551.06 mw (63.7%)
![Page 31: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/31.jpg)
31
Overhead of Executing Each WaitUntil Call vs Hand-coded
1 3 7 15 31 63 127 191 255 383 5110
5
10
15
20
25
State Expression Length
Tim
e to
Res
olve
(ms)
Overhead of IPC measured to be 1.71 ms
Longest Expression from CitiSense
![Page 32: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/32.jpg)
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
![Page 33: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/33.jpg)
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 eases the implementation of policies in CitiSense and achieves dramatic power-savings
![Page 34: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/34.jpg)
34
Acknowledgement• This work was supported by the National Science
Foundation and the Roy J. Carver Charitable Trust
William GriswoldUC San Diego
Octav ChiparaUniv. of Iowa
![Page 35: APE: An Annotation Language and Middleware for Energy-Efficient Mobile Application Development](https://reader034.fdocuments.us/reader034/viewer/2022052512/56814916550346895db64c87/html5/thumbnails/35.jpg)
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 eases the implementation of policies in CitiSense and achieves dramatic power-savings