real-time java on jop martin schöberl. real-time java on jop2 overview rtsj – why not simple rt...

31
Real-Time Java on JOP Martin Schöberl

Upload: benedict-phelps

Post on 31-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP

Martin Schöberl

Page 2: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 2

Overview

RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Page 3: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 3

Real-Time Specification for Java

Real-time extension definition Sun JSR - standard Still not completely finished Implementations

Timesys RI Purdue OVM

Page 4: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 4

RTSJ Issues Large and complex specification

Implementation Verification

Scoped memory cumbersome Expensive longs (64 bit) for time

values J2SE library

Heap usage not documented OS functions can cause blocking

Page 5: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 5

RTSJ Subset Ravenscar Java

Name from Ravenscar Ada Based in Puschner & Wellings paper

Profile for high integrity applications RTSJ compatible No dynamic thread creation Only NHRTT Simplified scoped memory Implementation?

Page 6: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 6

Real-Time Profile

Hard real-time profile See Puschner paper

Easy to implement Low runtime overhead No RTSJ compatibility

Page 7: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 7

Real-Time Profile

Schedulable objects Periodic activities Asynchronous sporadic activities

Hardware interrupt or software event Bound to a thread

Application Initialization Mission

Page 8: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 8

Application Structure Initialization phase

Fixed number of threads Thread creation Shared objects in immortal memory

Mission Runs forever Communication via shared objects Scoped memory for temporary data

Page 9: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 9

Schedulable Objects Three types:

RtThread, HwEvent and SwEvent

Fixed priority Period or minimum

interarrival time Scoped memory per

thread Dispatched after

mission start

public class RtThread { public RtThread(int priority, int period) ... public RtThread(int priority, int period, int offset, Memory mem)

public void enterMemory() public void exitMemory()

public void run() public boolean waitForNextPeriod()

public static void startMission()}

public class HwEvent extends RtThread { public HwEvent(int priority, int minTime, Memory mem, int number) public void handle()}

public class SwEvent extends RtThread { public SwEvent(int priority, int minTime, Memory mem) public final void fire() public void handle()}

Page 10: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 10

Scheduling

Fixed priority with strict monotonic order

Priority ceiling emulation protocol Top priority for unassigned objects

Interrupts under scheduler control Priority for device drivers No additional blocking time Integration in schedulability analysis

Page 11: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 11

Memory

No GC: Heap becomes immortal memory

Scoped memory Bound to one thread at creation Constant allocation time

Cleared on creation and on exit Simple enter/exit syntax

Page 12: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 12

Restrictions of Java Only WCET analyzable language

constructs No static class initializer

Use a static init() function No finalization

Objects in immortal memory live forever Finalization complicates WCET analysis of

exit from scoped memory No dynamic class loading

Page 13: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 13

Implementation

Scheduler for a Java real-time profile Periodic and sporadic threads Preemptive Fixed priority

Microcode Java

Page 14: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 14

Low-level Functions

Access to JVM internals Exposed as special bytecodes In Java declared as native methods Translation Avoids non-standard class files

Page 15: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 15

Interrupts in JOP

Translation of JVM bytecodes to microcode

Interrupts are special bytecodes Inserted in the translation stage Call of JVM internal Java method

Page 16: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 16

Dispatching Scheduler is a

Java method Context of task is

on the stack Exchange stack Set stack pointer Simple return

private static int newSp;

public static void schedule() {

Native.wr(0, IO_INT_ENA);

RtThread th = tasks[active]; th.sp = Native.getSP(); Native.int2extMem(...);

// find ready thread and // new timer value

newSp = tasks[ready].sp; Native.int2extMem(...);

Native.wr(tim, IO_TIMER); Native.setSP(newSp); Native.wr(1, IO_INT_ENA);}

Page 17: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 17

Implementation Results

Scheduler and Dispatch in Java Only one function in microcode Test JVM in C

JOP compatible JVM Implements timer with timestamp

counter Scheduling in Java No OS needed, just a 32-bit C compiler

Page 18: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 18

User-Defined Scheduler Java is a safe OO Language

No pointers Type-safety

No kernel user space distinction Hooks for scheduling Scheduler in Java extended to a

framework Class Scheduler Class Task

Page 19: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 19

Schedule Events

Timer interrupt HW interrupt Monitor Thread blocking SW Event

Page 20: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 20

Interrupts

Hook for HW interrupts Timer interrupt results in scheduler

call Access to timer interrupt Generate interrupt for blocking SW Event is not part of the

framework

Page 21: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 21

Synchronization Part of the

language Each object can

be a monitor JVM instruction or

method declaration

synchronized void foo() { ...}

synchronized(o) { ... }

Page 22: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 22

Synchronization cont.

Called by framework: monitorEnter(Object o) monitorExit(Object o)

Attach user data to an object: attachData(Object obj, Object data) getAttachedData(Object obj)

Page 23: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 23

Services for the Scheduler

Dispatch Time Timer Interrupts

Page 24: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 24

Class Scheduler Extended for a user-defined scheduler User provides:

schedule() Monitor handling

Framework supplies: Software interrupt for blocking Dispatch function Current time Timer interrupt

Page 25: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 25

Class Task

Minimal (not j.l.Thread) Provides list of tasks Scoped memory Usually extended

Page 26: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 26

A Simple Example class Work extends Task {  private int c;  Work(int ch) { c = ch; }  public void run() {  for (;;) { Dbg.wr(c); // debug output int ts = Scheduler.getNow() + 3000; while (ts-Scheduler.getNow()>0) ; } }}

Page 27: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 27

A Simple Example cont.public class RoundRobin extends Scheduler { public void schedule() { Task t = getRunningTask().getNext(); if (t==null) t = Task.getFirstTask(); dispatch(t, getNow()+10000); }  public static void main(String[] args) {  new Work(‚a'); new Work(‚b');  RoundRobin rr = new RoundRobin();  rr.start(); }}

Page 28: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Task 1 SchedulerTask 2 JVM Hardware

block genInt

set interrupt

interrupt

schedule

dispatch

switch

resume task

Schedulingdecision

Contextswitch

wFNP

interrupt

schedule

dispatch

Schedulingdecision

Contextswitch

timer

User-defined FrameworkApplication

resume task

set timer

set timer

switch

Page 29: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 29

Summary

RTSJ is too complex System code in Java is possible No extra memory protection needed Dispatch is 20% slower in framework Missing C++ friend in Java JopVm in C

Page 30: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 30

Garbage Collection?

An essential part of Java Without GC it is a different

computing model RTSJ does not believe in real-time

GC Real-time collectors evolve Active research area

For You?

Page 31: Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling

Real-Time Java on JOP 31

Further Reading P. Puschner and A. J. Wellings. A Profile for High

Integrity Real-Time Java Programs. In 4th IEEE International Symposium on Object-oriented Real-time distributed Computing (ISORC), 2001.

M. Schoeberl, Design Rationale of a Processor Architecture for Predictable Real-Time Execution of Java Programs, In Proceedings of the 10th International Conference on Real-Time and Embedded Computing Systems and Applications (RTCSA), 2004.

M. Schoeberl, Real-Time Scheduling on a Java Processor, In Proceedings of the 10th International Conference on Real-Time and Embedded Computing Systems and Applications (RTCSA), 2004.