a real-time extension to the android platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf ·...

16
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

Upload: others

Post on 11-Jul-2020

23 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

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

Page 2: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

2 / 15

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

• Services & system managers

Android runtime

• Dalvik virtual machine

• SSL, media, SQLite database

Adapted Linux kernel

• Hardware drivers, memory & process management

Runtime Libraries

Application Framework

Applications

Linux Kernel

Page 3: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

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

Page 4: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

4 / 15

Related Work

Several proposed approaches:

Page 5: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

5 / 15

Approach

Extended Activity Manager

- Reliable execution of RT apps

- Bypassing OOM process killer

Modified Dalvik VM

- Encapsulated priority selection

- Explicit memory management

Improved Linux kernel v2.6.29

- Patched with PREEMPT_RT

- Enabled priority scheduling

Applications

System Applications 3rd Party Applications

Application Framework

Activity Manager Notification

Manager Package Manager

Resource Manager … Window Manager

Graphics SQLite

… SSL

Core Libraries

Dalvik Virtual

Machine

Power

Management

Process

Management

… Binder (IPC) Driver

Linux Kernel

Libraries Android Runtime

Hardware Drivers

Memory

Management

Page 6: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

6 / 15

Activity Manager

Internal process importance

- Depends on the application class (back- / foreground)

- Reflected in OOM adjustment values 𝑎𝑑𝑗𝑝

Built-in OOM process killer

- Killing “unimportant” processes first

- Memory thresholds 𝑚𝑒𝑚𝑡 and corresponding levels 𝑎𝑑𝑗𝑡

Example with 𝑚𝑒𝑚3 = 20 𝑀𝐵 and 𝑎𝑑𝑗3 = 7

- Terminate processes with 𝑎𝑑𝑗𝑝 ≥ 7 on 𝑚𝑒𝑚𝑓𝑟𝑒𝑒 ≤ 20 𝑀𝐵

RT processes must get lowest possible 𝑎𝑑𝑗𝑝 values

Page 7: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

7 / 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

Page 8: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

8 / 15

Memory Management (2)

Page 9: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

9 / 15

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

:ServiceRT

instantiate

set adj_p

change priority

Real-tim

e

priority

No

rma

l

priority

terminate

Page 10: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

10 / 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 𝑡𝑃 = 1 𝑚𝑠 to 𝑡𝑃 = 1 𝑠

- Running time 𝑇 = 20 𝑠 to 𝑇 = 1 ℎ

- Different process priorities

- Idle system or high CPU load

Page 11: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

11 / 15

Latencies (1)

System state: idle

𝑡𝑃 = 5 𝑚𝑠

𝑇 = 20 𝑠

Priorities: 120 (default) vs. 40 (real-time)

0

5

10

15

20

25

0 5000 10000 15000 20000

Late

ncy

(m

s)

Execution Time (ms)

RT Process

0

5

10

15

20

25

0 5000 10000 15000 20000

Late

ncy

(m

s)

Execution Time (ms)

Non-RT Process

Page 12: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

12 / 15

Latencies (2)

System state: under load

𝑡𝑃 = 5 𝑚𝑠

𝑇 = 20 𝑠

Priorities: 120 (default) vs. 40 (real-time)

0

200

400

600

800

1000

0 5000 10000 15000 20000

Late

ncy

(m

s)

Execution Time (ms)

Non-RT Process

7780 2449

0

2

4

6

8

10

0 5000 10000 15000 20000

Late

ncy

(m

s)

Execution Time (ms)

RT Process

Page 13: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

13 / 15

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

2200

2300

2400

2500

2600

2700

2800

2900

3000

0 10 20 30 40 50 60

Mem

ory

Footp

rin

t (k

B)

Time (s)

Automatic GC Manual Freeing

0

40

80

120

0 2000 4000 6000 8000

Avg. F

reei

ng T

ime

(ms)

Object Size (kB)

Automatic GC Manual Freeing 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

Page 14: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

14 / 15

Conclusion

New approach

- 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

Page 15: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

15 / 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

Page 16: A Real-time Extension to the Android Platformjtres2012.imm.dtu.dk/slides/jtres12_105_kalkov.pdf · - Patched Linux kernel & Android components - Handling of OOM adjustment values

Thank you for your attention!

Questions / Comments?