JTRES 2012 A Real-time Extension to the Android Platform Igor Kalkov, Dominik Franke, John F. Schommer, Stefan Kowalewski 24-26 October 2012 Copenhagen, Denmark
Introduction Mobile platform by Open Handset Alliance - Supervised by Google - Open-sourced under Apache 2.0 license Android software stack: Applications Stock & user applications Application Framework Application framework Services & system managers Libraries Android runtime Dalvik virtual machine Linux Kernel SSL, media, SQLite database Adapted Linux kernel Hardware drivers, memory & process management Applications Runtime 2 / 15
Motivation Real-time support expands the field of application - Opening safety- & time-critical domains - In-field monitoring, controlling platform for home automation - Better core functionalities: speech or video processing Goals - Possibility of serving real-time requests - Keeping original functionality / backward compatibility Wide range of compatible hardware platforms - Smartphones, tablets, OMAP hardware Further applications: ereaders, TVs, Nanosatellites 3 / 15
Several proposed approaches: Related Work 4 / 15
Approach Applications System Applications 3rd Party Applications Extended Activity Manager Application Framework - Reliable execution of RT apps Activity Manager Notification Manager Package Manager - Bypassing OOM process killer Resource Manager Window Manager Modified Dalvik VM Libraries Android Runtime - Encapsulated priority selection - Explicit memory management Graphics SSL SQLite Core Libraries Dalvik Virtual Machine Improved Linux kernel v2.6.29 - Patched with PREEMPT_RT - Enabled priority scheduling Hardware Drivers Memory Management Linux Kernel Power Management Binder (IPC) Driver Process Management 5 / 15
Internal process importance Activity Manager - Depends on the application class (back- / foreground) - Reflected in OOM adjustment values adj p Built-in OOM process killer - Killing unimportant processes first - Memory thresholds mem t and corresponding levels adj t Example with mem 3 = 20 MB and adj 3 = 7 - Terminate processes with adj p 7 on mem free 20 MB RT processes must get lowest possible adj p values 6 / 15
Memory Management (1) Advantages: - Smart low memory process killer - Process-independent GC (Dalvik VM) Disadvantages: - Mark-and-sweep algorithm - Execution of all threads is suspended (up to 200 ms) No reliable prediction of process behavior Explicit allocation control 7 / 15
Memory Management (2) 8 / 15
Real-time priority Normal priority Programming Interface Introducing new class ServiceRT.java - Extends Android s native Service.java class - API for priority selection for own process - API for explicit memory deallocation Android OS Linux kernel instantiate set adj_p :ServiceRT change priority terminate 9 / 15
Evaluation Testing device: HTC Dream / Google G1 Background service based on ServiceRT class Test 1: Periodic execution - Compare scheduled & actual execution time - Period time t P = 1 ms to t P = 1 s - Running time T = 20 s to T = 1 h - Different process priorities - Idle system or high CPU load 10 / 15
Latency (ms) Latency (ms) Latencies (1) System state: idle t P = 5 ms T = 20 s Priorities: 120 (default) vs. 40 (real-time) Non-RT Process RT Process 25 25 20 20 15 15 10 10 5 5 0 0 5000 10000 15000 20000 0 0 5000 10000 15000 20000 Execution Time (ms) Execution Time (ms) 11 / 15
Latency (ms) Latency (ms) Latencies (2) System state: under load t P = 5 ms T = 20 s Priorities: 120 (default) vs. 40 (real-time) Non-RT Process RT Process 1000 2449 7780 10 800 8 600 6 400 4 200 2 0 0 5000 10000 15000 20000 0 0 5000 10000 15000 20000 Execution Time (ms) Execution Time (ms) 12 / 15
Avg. Freeing Time (ms) Memory Footprint (kb) Evaluation: Memory Management Test 2: Continuous data receiving - Over a 54 Mbit Wi-Fi connection - Count: 2000 packets - Size: ~ 1 kb each - Can be released after processing 3000 2900 2800 2700 2600 2500 2400 2300 2200 Automatic GC Manual Freeing 0 10 20 30 40 50 60 Time (s) Test 3: Explicit object deallocation - Allocate an object of a given size - Free it immediately - Measure the elapsed time - Calculate average of 10 cycles - For different sizes: 1 Byte to 8 MB 120 80 40 0 Automatic GC Manual Freeing 0 2000 4000 6000 8000 Object Size (kb) 13 / 15
New approach Conclusion - Patched Linux kernel & Android components - Handling of OOM adjustment values - Use Linux real-time priorities for Android applications - Explicit memory management Evaluation - Avoiding undesired invocations of the GC - Scheduling latency < 2 ms for real-time processes BUT: explicit memory management is not enough - Dangling pointers, background allocations 14 / 15
Future Work Automatic, non-blocking real-time GC algorithms - M. Schoeberl, W. Puffitsch Nonblocking Real-Time Garbage Collection - Y. Levanoni, E. Petrank On-The-Fly Reference-Counting Garbage Collector for Java Using RT-Linux high resolution timer for periodic tasks - Better scheduling latencies (WC 500 us) More about the project will be available soon under https://git.embedded.rwth-aachen.de/rtandroid 15 / 15
Thank you for your attention! Questions / Comments?