Real-Time Java Real-Time Systems Anders P. Ravn Aalborg University March 2008.

Slides:



Advertisements
Similar presentations
Real-Time Systems and Programming Languages © Alan Burns and Andy Wellings Chapter 12: Programming Schedulable Systems.
Advertisements

© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
Real-Time Systems and Programming Languages © Alan Burns and Andy Wellings Chapter 9: Real-Time Facilities.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Scheduling Theory ITV Real-Time Systems Anders P. Ravn Aalborg University March 2007.
RTS - Implementation ITV Real-Time Systems Anders P. Ravn Aalborg University February 2006.
Software Engineering Lecture 5 Multiprogramming and Scheduling ASPI8-4 Anders P. Ravn March 2004.
Programming R-T Abstractions TSW November 2009 Anders P. Ravn Aalborg University.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Real-Time Systems Specification and Analysis ITV Mutiprogramming and Real-Time Programs Anders P. Ravn Aalborg University May 2009.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Scheduling Theory ITV Multiprogramming and Real-Time Programs Anders P. Ravn Aalborg University May 2009.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Real-Time Systems Specification and Analysis ITV Real-Time Systems Anders P. Ravn Aalborg University February 2006.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
1 Predictable Java Java Objekt 2, 19 August 2009 Anders P. Ravn and Hans Søndergaard Overview Implementations Next steps.
© Andy Wellings, 2003 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Low-level Programming TSW November 2009 Anders P. Ravn Aalborg University.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Real-Time Systems Specification and Analysis ITV Real-Time Systems Anders P. Ravn Aalborg University February 2009.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
© Alan Burns and Andy Wellings, 2001 Characteristics of a RTS Large and complex Concurrent control of separate system components Facilities to interact.
The Real-Time Java Profile ITV Real-Time Systems Anders P. Ravn Aalborg University February 2006.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Real-Time Java Martin Schöberl. Real Time Java2 Overview What are real-time systems Real-time specification for Java RTSJ issues, subset Real-time profile.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
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 Systems Design1 Priority Inversion When a low-priority task blocks a higher-priority one, a priority inversion is said to occur Assume that priorities:
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Enhancements to Java for Real Time Systems Theresa Dsena CSE Fall 2006 Prof. Ganesan.
CS333 Intro to Operating Systems Jonathan Walpole.
11 G53SRP: Clocks and Times in RTSJ Chris Greenhalgh School of Computer Science.
EEL The Real-Time Specification for Java (1)
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
11 G53SRP: Deadline misses and cost over-runs in RTSJ Chris Greenhalgh School of Computer Science.
EEL Real-time Java part 2. EEL Acknowledgements All the lecture slides were adopted from the slides of Andy Wellings.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Multithreading in JAVA
Java Thread and Memory Model
111 G53SRP: RTSJ Memory Areas Chris Greenhalgh School of Computer Science.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
Thread Scheduling and Dispatching Maung Aung Han Marc E. Loy Jihua Zhong CIS 642: Seminar in Real-time Systems Instructor: Professor Insup Lee.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University Mar. 14, 2005 FOAL Workshop with AOSD’05.
Multithreading & Synchronized Algoritma Pemrograman 3 Sistem Komputer – S1 Universitas Gunadarma 1.
11 G53SRP: Feasibility analysis Chris Greenhalgh School of Computer Science.
© Andy Wellings, 2004 Thread Priorities I  Although priorities can be given to Java threads, they are only used as a guide to the underlying scheduler.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Processes and threads.
Multi Threading.
Java Programming Language
G53SRP: Real Time Threads in RTSJ (part I)
Multithreading in Java
G53SRP: Asynchronous Events in RTSJ
Multithreaded Programming
Threads Chapter 4.
Real Time Java : Synchronization
Threads and concurrency / Safety
Presentation transcript:

Real-Time Java Real-Time Systems Anders P. Ravn Aalborg University March 2008

Time HighResolutionTime AbsoluteTime RelativeTime RationalTime

RTSJ HighResolutionTime public abstract class HighResolutionTime implements java.lang.Comparable { public abstract AbsoluteTime absolute(Clock clock, AbsoluteTime destination); public abstract RelativeTimeTime relative(Clock clock, RelativeTime destination);... public boolean equals(HighResolutionTime time); public final long getMilliseconds(); public final int getNanoseconds(); public void set(HighResolutionTime time); public void set(long millis); public void set(long millis, int nanos); }

public class AbsoluteTime extends HighResolutionTime { // various constructor methods including public AbsoluteTime(AbsoluteTime T); public AbsoluteTime(long millis, int nanos); public AbsoluteTime absolute(Clock clock, AbsoluteTime dest);... public final AbsoluteTime add(RelativeTime time);... public final RelativeTime subtract(AbsoluteTime time); public final AbsoluteTime subtract(RelativeTime time);... public void set(java.util.Date date) } RTSJ AbsoluteTime

Clocks in Java Similar to those in Ada java.lang. System.currentTimeMillis returns the number of milliseconds since 1/1/1970 GMT and is used by java.util.Date

public class RelativeTime extends HighResolutio { // various constructor methods including public RelativeTime(long millis, int nanos); public RelativeTime(RelativeTime time); public AbsoluteTime absolute(Clock clock, AbsoluteTime destination); public final RelativeTime add(RelativeTime time); public final RelativeTime subtract(RelativeTime time); } RTSJ RelativeTime

public class RationalTime extends RelativeTime Deprecated. As of RTSJ An object that represents a time interval milliseconds/ nanoseconds/10 9 seconds long that is divided into subintervals by some frequency. This is generally used in periodic events, threads, and feasibility analysis to specify periods where there is a basic period that must be adhered to strictly (the interval), but within that interval the periodic events are supposed to happen frequency times, as uniformly spaced as possible, but clock and scheduling jitter is moderately acceptable. Caution: This class is explicitly unsafe in multithreaded situations when it is being changed. No synchronization is done. It is assumed that users of this class who are mutating instances will be doing their own synchronization at a higher level. RTSJ RationalTime

RTSJ Clock public abstract class Clock { public Clock(); public static Clock getRealtimeClock(); public abstract RelativeTime getEpochOffset(); public abstract RelativeTime getResolution(); public AbsoluteTime getTime(); public abstract void getTime(AbsoluteTime time); public abstract void setResolution(RelativeTime resolution); }

RTSJ Timer Timer OneShotTimerPeriodicTimer AsyncEvent

RTSJ AsyncEvent public class AsyncEvent { public AsyncEvent(); public void addHandler(AsyncEventHandler handler);... } An asynchronous event can have a set of handlers associated with it, and when the event occurs, the fireCount of each handler is incremented, and the handlers are released.

RTSJ Timer public abstract class Timer { protected Timer(HighResolutionTime time, Clock clock, AsyncEventHandler handler);... public void enable(); public void disable();... public AbsoluteTime getFireTime(AbsoluteTime dest); public void fire(); Should not be called. The fire method is reserved for the use of the timer. }

RTSJ ReleaseParameters ReleaseParameters PeriodicParameters AperiodicParameters SporadicParameters

RTSJ ReleaseParameters public abstract class ReleaseParameters { protected ReleaseParameters( RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler);... public RelativeTime getCost(); public AsyncEventHandler getCostOverrunHandler(); public RelativeTime getDeadline(); public AsyncEventHandler getDeadlineMissHandler(); // methods for setting the above }

public class PeriodicParameters extends ReleaseParameters { public PeriodicParameters( HighResolutionTime start, RelativeTime period, RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler); public RelativeTime getPeriod(); public HighResolutionTime getStart(); public void setPeriod(RelativeTime period); public void setStart(HighResolutionTime start); } RTSJ Periodic Parameters

RTSJ Aperiodic- and SporadicParameters public class AperiodicParameters extends ReleaseParameters { public AperiodicParameters(RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler); } public class SporadicParameters extends AperiodicParameters { public SporadicParameters(RelativeTime minInterarrival, RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler); public RelativeTime getMinimumInterarrival(); public void setMinimumInterarrival(RelativeTime minimum); }

RTSJ SchedulingParameters SchedulingParameters PriorityParameters ImportanceParameters

RTSJ SchedulingParameters public class PriorityParameters { public PriorityParameters(int priority);... } public class ImportanceParameters { public PriorityParameters(int priority, int importance);... } Importance is an additional scheduling metric that may be used by some priority-based scheduling algorithms during overload conditions to differentiate execution order among threads of the same priority.

RTSJ Scheduler Scheduler PriorityScheduler Class which represents the required (by the RTSJ) priority-based scheduler. The default instance is the base scheduler which does fixed priority, preemptive scheduling.

RTSJ PriorityScheduler public class PriorityScheduler extends Scheduler { public static PriorityScheduler instance();... protected boolean addToFeasibility(Schedulable schedulable); public boolean isFeasible(); public boolean SetIfFeasible( Schedulable schedulable, ReleaseParameters release, MemoryParameters memory); }

RTSJ Schedulable «interface» Schedulable AsyncEventHandler RealTimeThread BoundAsyncEventHandlerNoHeapRealTimeThread

RTSJ AsyncEventHandler public class AsyncEventHandler extends java.lang.Object implements Schedulable { public AsyncEventHandler( SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memory, MemoryArea area, boolean nonheap);... public void handleAsyncEvent(); // the program to be executed... protected int getAndClearPendingFireCount(); }

RTSJ RealTimeThread public class RealtimeThread extends java.lang.Thread implements Schedulable { public RealtimeThread(SchedulingParameters s, ReleaseParameters r);... // methods for implementing the Schedulable interface public synchronized void addToFeasibility();... public static RealtimeThread currentRealtimeThread(); public synchronized void schedulePeriodic(); // add the thread to the list of schedulable objects public synchronized void deschedulePeriodic(); // remove the thread from the list of schedulable object // when it next issues a waitForNextPeriod public boolean waitForNextPeriod() throws...; public synchronized void interrupt(); // overrides java.lang.Thread.interrupt() public static void sleep(Clock c, HighResolutionTime time) throws...; }

RTSJ Periodic public class Periodic extends RealtimeThread { public Periodic( PriorityParameters PP, PeriodicParameters P) {... }; public void run() { while(true) { // code to be run each period... waitForNextPeriod(); }

RTSJ Periodic Example { AbsoluteTime A = new AbsoluteTime(...); PeriodicParameters P = new PeriodicParameters( A, new RelativeTime(10,0), new RelativeTime(1,0), new RelativeTime(5,0), null, null ); PriorityParameters PP = new PriorityParameters(...); Periodic ourThread = new Periodic(PP, P); //create thread ourThread.start(); // release it }

RTSJ Memory Management MemoryArea «singleton» HeapMemory ScopedMemory ImmortalMemory LTMemory ImmortalPhysicalMemory VTMemory

RTSJ MemoryArea public abstract class MemoryArea { protected MemoryArea(long sizeInBytes); public void enter(java.lang.Runnable logic); // associate this memory area to the current thread // for the duration of the logic.run method public static MemoryArea getMemoryArea( java.lang. Object object); // get the memory area associated with the object public long memoryConsumed(); // number of bytes consumed in this memory area public long memoryRemaining(); // number of bytes remaining... public synchronized java.lang.Object newInstance( java.lang.Class type)throws IllegalAccessException, InstantiationException, OutOfMemoryError; // allocate an object public long size(); // the size of the memory area }

Immortal Memory Immortal memory is shared among all threads in an application Objects created in immortal memory are never subject to garbage collection and are freed only when the program terminates public final class ImmortalMemory extends MemoryArea { public static ImmortalMemory instance(); } There is also a class called ImmortalPhysicalMemory which has the same characteristics as immortal memory but allows objects to be allocated from within a range of physical addresses

Scoped Memory A memory area where objects which have a well-defined lifetime May be entered explicitly (by the use of the enter method) or implicitly by attaching it to a RealtimeThread at thread creation time Associated with each scoped memory is a reference count which incremented for every call to enter and at every associated thread creation It is decremented when the enter method returns and at every associated thread exit When the reference count reaches 0, all objects resident in the scoped memory have their finalization method executed and the memory is reclaimed Scoped memory can be nested by nested calls to enter

Scoped Memory public abstract class ScopedMemory extends MemoryArea { public ScopedMemory(long size); public void enter(java.lang.Runnable logic); public int getMaximumSize(); public MemoryArea getOuterScope(); public java.lang.Object getPortal(); public void setPortal(java.lang.Object object); }

Scoped Memory The ScopedMemory class which has several subclasses –VTMemory : allocations may take variable amounts of time –LTMemory : allocations occur in linear time (related to the size of the object) –ScopedPhysicalMemory : allowing objects to be allocated at physical memory locations To avoid the possibility of dangling pointers, a set of access restrictions are placed on the use of the various memory areas –Heap objects -- can reference other heap objects and objects in immortal memory only (i.e. it cannot access scoped memory) –Immortal objects -- can reference heap objects and immortal memory objects only; –Scoped objects -- can reference heaped objects, immortal objects and objects in the same scope or an outer scope only

Example import javax.realtime.*; public class ThreadCode implements Runnable { private void computation() { final int min = 1*1024; final int max = 1*1024; final LTMemory myMem = new LTMemory(min, max); myMem.enter(new Runnable() { public void run() { // code here which requires access // to temporary memory } } ); }

Example The thread can now be created; note, no parameters other than the memory area and the Runnable are given public void run() {... computation();... } ThreadCode code = new ThreadCode(); RealtimeThread myThread = new RealtimeThread( null, null, null, ImmortalMemory.instance(), null, code);

Stack Management Embedded programmers also have to be concerned with stack size Specifying the stack size of a task/thread requires trivial support (for example, in Ada it is via the Storage_Size attribute applied to a task; in POSIX it is via pthread attributes) Calculating the stack size is more difficult; as tasks enter blocks and execute procedures their stacks grow To estimate the maximum extent of this growth requires knowledge of the execution behaviour of each task This knowledge is similar to that required to undertake WCET analysis WCET and worst-case stack usage bounds can be obtained from control flow analysis of the task's code

RTSJ Memory Access RTSJ allows access to memory mapped device registers via the concept of raw memory An implementation is allowed to support a range of memory types, e.g. DMA, shared memory, IO_Page

public class RawMemoryAccess { protected RawMemoryAccess(long base, long size); protected RawMemoryAccess(RawMemoryAccess memory, long base, long size); public static RawMemoryAccess create( java.lang.Object type, long size) throws SecurityException, OffsetOutOfBoundsException, SizeOutOfBoundsException, UnsupportedPhysicalMemoryException; public static RawMemoryAccess create( java.lang.Object type, long base, long size) throws SecurityException, OffsetOutOfBoundsException, SizeOutOfBoundsException, UnsupportedPhysicalMemoryException; public byte getByte(long offset) throws SizeOutOfBoundsException, OffsetOutOfBoundsException; // similarly for integers, long integers, etc public void setByte(long offset, byte value) throwsSizeOutOfBoundsException, OffsetOutOfBoundsException; // similarly for integers, long integers etc }

Control and Status Register Example public class ControlAndStatusRegister { RawMemoryAccess rawMemory; public ControlAndStatusRegister(long base, long size) { rawMemory = RawMemoryAccess.create(IO_Page, base, size); } public void setControlWord(short value) { rawMemory.setShort(0, value); } };

Using the CSR { byte shadow, channel; final byte start = 01; final byte enable = 040; final long csrAddress = ; final long csrSize = 2; ControlAndStatusRegister csr = new ControlAndStatusRegister(csrAddress, csrSize); channel = 6; shadow = (channel << 8) | start | enable; csr.setControlWord(shadow); }

Interrupt Handling RTJ views an interrupt as an asynchronous event The interrupt is equivalent to a call of the fire method The association between the interrupt and the event is achieved via the bindTo method in the AsyncEven t class The parameter is of string type, and this is used in an implementation-dependent manner — one approach might be to pass the address of the interrupt vector When the interrupt occurs, the appropriate handler's fire method is called Now, it is possible to associate the handler with a schedulable object and give it an appropriate priority and release parameters

Interrupt Handling AsyncEvent Interrupt = new AsyncEvent(); AsyncEventHandler InterruptHandler = new BoundAsyncEventHandler( priParams, releaseParams, null, null, null); Interrupt.addHandler(InterruptHandler); Interrupt.bindTo(” ");

Ravenscar Periodic Thread

Asynchronous Event and Handler