Preemptible Atomics
Jan Vitek
Jason Baker, Antonio Cunei, Jeremy Manson, Marek Prochazka, Bin Xin Suresh Jagannathan, Jan Vitek
NSF grant CCF-0341304 and DARPA PCES.
Preemptible Atomics Jan Vitek Jason Baker, Antonio Cunei, Jeremy - - PowerPoint PPT Presentation
Preemptible Atomics Jan Vitek Jason Baker, Antonio Cunei, Jeremy Manson, Marek Prochazka, Bin Xin Suresh Jagannathan, Jan Vitek NSF grant CCF-0341304 and DARPA PCES. Why not Lock-based Synchronization? Challenges of programming with mutual
Jason Baker, Antonio Cunei, Jeremy Manson, Marek Prochazka, Bin Xin Suresh Jagannathan, Jan Vitek
NSF grant CCF-0341304 and DARPA PCES.
(c) Jan Vitek 2006
(c) Jan Vitek 2006
(c) Jan Vitek 2006
class ThreadPoolLane { 1 synchronized leaderExec(Request task) { 2 if (borrowThreadAndExec(task)) 3 synchronized(rQueue) { 4 rQueue.enqueue(task); 5 numBuffered++; } ... } class Queue { 7 final Object sObject = new Object(); 8 void enqueue(Object data) { 9 QueueNode node=getNode(); 10 node.value=data; 11 synchronized(sObject) { 12 // enqueue the object } } from the UCI Zen real-time ORB
(c) Jan Vitek 2006
class ThreadPoolLane { 1 @Atomic leaderExec(final Request task) { 2 if (borrowThreadAndExec(task)) 3 4 rQueue.enqueue(task); 5 numBuffered++; } ... } class Queue { 8 @Atomic void enqueue(final Object data) { 9 QueueNode node=getNode(); 10 node.value=data; 12 // enqueue the object }
(c) Jan Vitek 2006
Bershad, Redell, Ellis. Fast Mutual Exclusion for Uniprocessors, ASPLOS, 1992.
Anderson, Ramamurthy, Jeffay, Real-time Computing with Lock-Free Shared Objects, RTSS, 1995.
Herlihy+, Harris+, Welc+, Software Transactional Memory, 2003--2005.
Ringenburg, Grossman, AtomCaml First-Class Atomicity with Rollback, ICFP, 2005.
(c) Jan Vitek 2006
(c) Jan Vitek 2006
HP MP LP a b b b a a a b
HP MP LP
undo undo
(c) Jan Vitek 2006
Theorem 1 A set of n periodic tasks τi, 0 ≤ i < n is schedulable in RM, iff ∀i ≤ n, ∃Ri : Ri ≤ pi Ri = Ci + max
j∈lp(i) Uj +
Ri pj
(c) Jan Vitek 2006
Priority Inheritance Protocol: A HPT may block for multiple LPT Deadlock and data races Non-real-time LPTs may cause unbounded blocking programmer error, but an easy one to make. Priority Ceiling Protocol: HPTs may still have to wait for completion of a LPT Hard to assign ceilings with libraries, changing thread priorities Preemptible Atomic Region: HPTs only block for higher-level tasks. At most one abort per context switch. no dead-locks & no live-locks if schedulable
(c) Jan Vitek 2006
public class Vector extends AbstractList ... { @Atomic public void insertElementAt(Object o ... @Atomic public int size() { ...
(c) Jan Vitek 2006
(c) Jan Vitek 2006
(c) Jan Vitek 2006
A method “@Atomic f(){ x++; B(); }” is translated to:
while (true) { try{ try { Transaction.start(); log(x); x++ B_T(); } finally { Transaction.commit(); break; } } catch(Retry _) { } // undo performed by aborting thread }
finally implemented by catching all subclasses of Throwable Retry not a subclass of Throwable,not get caught by finally
(c) Jan Vitek 2006
I/O - How do you undo a write to the screen? You don’t. Could support buffering of output/replay of input or using compensations Garbage collection - Addresses stored in log need to be updated. GC must be preemptible and cannot preempt RT task. Now - Rollback the Atomic if a GC is triggered. Dynamic class loading - Could generate transactional versions of methods
Reflection - Methods invoked reflectively from an Atomic must be
Regions - Memory allocated within a region must be returned on abort to avoid leaks. Asynchronous Transfer of control - Defer until interruptible, then abort.
(c) Jan Vitek 2006
@Atomic m() => @Uninterruptible m()
(c) Jan Vitek 2006
(c) Jan Vitek 2006
(c) Jan Vitek 2006
0.0 0.5 1.0 1.5 2.0 c
p r e s s j e s s d b j a v a c m p e g a u d i
t r t j a c k
Time, relative to Ovm Ovm 1.01 RTSJ Ovm 1.01 GCJ 4.0.2 HotSpot1.5.0.06 jTime 1.0 5.6 2.2 12.2 4.4
Ovm performance is competitive.
AMD Athlon XP1900+, 1.6GHz, 1GB RTLinux, 2.4.7-timesys-3.1.214
(c) Jan Vitek 2006
2 threads, performing mix of get/put ops into a HashMap 300Mhz PPC, 256MB memory, Embedded Planet Linux Ovm RTSJ VM, AOT, priority preemptive, PIP locks
80% Reads, 20% Writes
250 300 350 400 450 500 550 600 650 700 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 Frames Response Time [!s]
PAR-based HashMap Synchronized HashMap
20% Reads, 80% Writes
250 300 350 400 450 500 550 600 650 700 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 Frames Response Time [!s]
(c) Jan Vitek 2006
5 10 15 20 25 30 35 40 45 50 1 21 41 61 81 101 121 141 161 181 201 221 241 261 281 5 10 15 20 25 30 35 40 45 50 1 21 41 61 81 101 121 141 161 181 201 221 241 261 281
Response time [ms] Frames Frames
Synchronized Preemptible
Low priority High priority
Figure 6.
RT-Zen Results. Comparing the response time for a game server running on top of a Real-time Java CORBA im-
application code to process the request. Lower is better.
30 HPT/70 LPT. Measure time to process a request
AMD Athlon XP1900+, 1.6GHz, 1GB RTLinux
(c) Jan Vitek 2006
(c) Jan Vitek 2006
High responsiveness, small workloads
300Mhz PPC, 256MB memory, Embedded Planet Linux Ovm RTSJ VM, AOT, priority preemptive, PIP locks
0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 1 21 41 61 81 101 121 141 161 181 201 221 241 261 281 301 321 341 361 381
5Hz 20Hz 1Hz
0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 1 21 41 61 81 101 121 141 161 181 201 221 241 261 281 301 321 341 361 381
Atomics (aborts): 3'180 (0) Reads Max (median): 514 (6) Writes Max (media): 115 (3) Monitor inflated: 1338
(c) Jan Vitek 2006
Large workloads
300Mhz PPC, 256MB memory, Embedded Planet Linux Ovm RTSJ VM, AOT, priority preemptive, PIP locks
0.1 0.2 0.3 0.4 0.5 0.6 0.7 1 21 41 61 81 101 121 141 161 181 201 221 241 261 281 301 321 341 361 381
Infrastructure 5Hz 20Hz 1Hz
0.1 0.2 0.3 0.4 0.5 0.6 0.7 1 21 41 61 81 101 121 141 161 181 201 221 241 261 281 301 321 341 361
Atomics (aborts): 151'438 (5) Reads Max (median): 5'399 (3) Writes Max (median): 1'158 (0)
(c) Jan Vitek 2006
source code at http://ovmj.org
[Manson+. Preemptible Atomic Regions for Real-time Java. RTSS’05] [Baker+. A Real-time Java Virtual Machine for Avionics. RTAS’06]