Presentation is loading. Please wait.

Presentation is loading. Please wait.

G53SRP: Asynchronous Events in RTSJ

Similar presentations


Presentation on theme: "G53SRP: Asynchronous Events in RTSJ"— Presentation transcript:

1 G53SRP: Asynchronous Events in RTSJ
Async EventsReal Time Scheduling Real Time Scheduling 20/11/2018 20/11/2018 G53SRP: Asynchronous Events in RTSJ Chris Greenhalgh School of Computer Science 1 G53SRP G53SRPG53SRP 1

2 Contents Overview AsyncEvent class AsyncEventHandler class
Aperiodic events and AperiodicParameters Sporadic events and SporadicParameters Timers and timer-based events POSIX Signals Summary Book: Wellings chapter 11, , 2

3 Class Overview <<interface>> java.lang. Runnable
<<interface>> javax.realtime. Schedulable extends <<abstract>> javax.realtime. Scheduler has javax.realtime. PriorityScheduler (Default) Class Overview javax.realtime. AsyncEvent implements javax.realtime. AsyncEventHandler has javax.realtime. Timer extends javax.realtime. BoundAsyncEventHandler extends javax.realtime. OneShotTimer extends javax.realtime. PeriodicTimer

4 Overview Asynchronous events are data-less occurrences
Fired by program, triggered by environment (interrupts, signals) AsyncEvent instances represent the event AsyncEventHandler instances can be registered with an AsyncEvent instance Implements Schedulable c.f. RealtimeThread The handler is released when the event fires

5 Async EventsReal Time Scheduling
20/11/2018 AsyncEvent An AsyncEvent may be triggered by Another part of the application calling fire() A low-level system event (such as an interrupt) to which “happening” it is bound using bindTo Not supported in demonstration RTSJ RI The passage of time For OneShotTimer or PeriodicTimer subclasses POSIX (UNIX) signals can be handled but do any AsyncEvent object is not visible See POSIXSignalHandler G53SRPG53SRP

6 AsyncEvent class (i) Set of current handlers to release
package javax.realtime; public class AsyncEvent { public AsyncEvent(); // set of handlers public void addHandler(AsyncEventHandler h); public void removeHandler(AsyncEventHandler h); public void setHandler(AsyncEventHandler h); public boolean handledBy(AsyncEventHandler h); public ReleaseParameters createReleaseParameters(); Set of current handlers to release (each handler in list at most once) Default ReleaseParameters for event (if needed by handler) - probably AperiodicParameters

7 AsyncEvent class (ii) Set of implementation- Specific “happenings”
that will fire this event e.g. interrupt, signal public void bindTo(String happening); // throws UnknownHappeningException public void unBindTo(String happening); public void fire(); // throws MITViolationException, // ArrivalTimeQueueOverflowException } Explicit firing of event by program See later (Sporadic)

8 AsyncEventHandler Specifies the code to run to handle an event
Associated with an AsyncEvent using addHandler or setHandler Any “arguments” for the handler must be passed via (e.g.) a shared variable or data value queue But note that a version of fire with an argument is being added to later version(s) of RTSJ

9 AsyncEventHandler class (i)
package javax.realtime; public class AsyncEventHandler implements Schedulable { public AsyncEventHandler(); // various other constructor options (with defaults)… public AsyncEventHandler( SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memory, MemoryArea area, ProcessingGroupParameters group, boolean nonheap, Runnable logic);

10 AsyncEventHandler parameters
See RealtimeThread Part of common Schedulable interface / abstraction SchedulingParameters, ReleaseParameters, MemoryParameters, MemoryArea, ProcessingGroupParameters noheap throws IllegalParameterException if event handler or parameters are on heap (GC issue) logic optional Runnable for handler, run by default handleAsyncEvent method [not run]

11 AsyncEventHandler class (ii)
// various parameter getters and setters // from Schedulable (see RealtimeThread) // various Feasibility-testing methods // from Schedulable (see later notes)

12 AsyncEventHandler class (iii)
public final void run(); // event handling public void handleAsyncEvent(); // event/release count protected int getAndClearPendingFireCount(); protected int getAndDecrementPendingFireCount(); protected int getAndIncrementPendingFireCount(); protected int getPendingFireCount(); }

13 AsyncEventHandler notes (i)
Each AsyncEventHandler has its own “Arrival Time Queue” = Release time queue Each time the associated event is fired, that time is added to the arrival time queue Subject to arrival time queue and minimum inter-arrival time behaviour (see later) E.g. [T1][T2][] = Releases at T1 and T2

14 AsyncEventHandler notes (ii)
The system will schedule a call to handleAsyncEvent() for each time in the queue Each with its own deadline & cost Specify code to run by Overriding handleAsyncEvent() Or passing a Runnable to constructor (called by default handleAsyncEvent()) (run() is defined by EventHandler super-class and cannot be overriden) See HelloAsyncEventHandler.java and HelloAsyncEventHandler2.java

15 AsyncEventHandler notes (iii)
The number of times in the queue is visible in the API as “fire count” I.e. how many times the event has been fired and not yet handled, including any currently running release Event handler code can check and manipulate the queue, e.g. to remove additional release(s) See getPendingFireCount() etc. See SlowAsyncEventHandler.java

16 “Periodic”, “aperiodic” and “sporadic” events
Irrespective of its actual cause or nature, a realtime event can be classified as Periodic – occurring at some fixed interval Aperiodic – occurring with no temporal pattern Sporadic – occurring from time to time but not “too” often See later notes on Minimum Inter-arrival Time This must be known to assess the system’s schedulability Using the AsyncEventHandler’s ReleaseParameters…

17 ReleaseParameters classes
<<abstract>> javax.realtime. ReleaseParameters extends javax.realtime. PeriodicParameters javax.realtime. AperiodicParameters javax.realtime. SporadicParameters extends

18 Aperiodic events An aperiodic event can occur at any time
Successive releases may occur arbitrary closely together => CPU requirement potentially infinite => can never guarantee to meet deadlines with aperiodic events Releases occurring before the previous release completes are queued The release time is recorded Various queue behaviours are possible…

19 AperiodicParameters class (i)
Package javax.realtime; public class AperiodicParameters extends ReleaseParameters { // parameters as per ReleaseParameters public AperiodicParameters(); public AperiodicPamameters( RelativeCost cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler);

20 AperiodicParameters class (ii)
// arrival queue public int getInitialArrivalTimeQueueLength(); public void setInitialArrivalTimeQueueLength(int initial); public String getArrivalTimeQueueOverflowBehavior(); public void setArrivalTimeQueueOverflowBehavior( String behvaviour); // behavior constants public static final String arrivalTimeQueueOverflowExcept; public static final String arrivalTimeQueueOverflowIgnore; public static final String arrivalTimeQueueOverflowReplace; public static final String arrivalTimeQueueOverflowSave; }

21 Arrival Time Queue Length
EventHandler arrival time queue has initial length specified by AperiodicParameters Note: queue includes current release So queue length 0 with queue behaviour EXCEPT, IGNORE or REPLACE will never fire New firings are added to empty slots in the queue If queue is full then depends on arrival time queue behaviour…

22 Arrival Time Queue Behaviors
E.g. queue length 3, first release (T) running… [T][T+4][T+6] Event fired again: EXCEPT – throw ArrivalTimeQueueOverflowException from fire() like ignore if caused by external happening IGNORE – ignore firing; queue unchanged REPLACE – replace the last time in the queue E.g. [T][T+4][T+10] (affects last release deadline) SAVE – extend the queue (default) E.g. [T][T+4][T+6][T+10] See AperiodicAsyncEventHandler.java

23 Sporadic events Sporadic events are similar to aperiodic events but also have a minimum inter-arrival time (MIT) Equivalently, a maximum rate MIT used for analysis and scheduling Worst-case equivalent is a periodic event with MIT as period Checked at run-time Has an arrival time queue From AperiodicParameters super-class, including queue length and associated queue-full behaviour Plus additional constraints…

24 SporadicParameters class (i)
Package javax.realtime; public class SporadicParameters extends AperiodicParameters { // parameters as per ReleaseParameters, plus… public AperiodicParameters( RelativeTime minInterarrival); public AperiodicPamameters( RelativeTime minInterarrival, RelativeCost cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler);

25 SporadicParameters class (ii)
public RelativeTime getMinimumInterarrival(); public void setMinimumInterarrival( RelativeTime minInterarrival); // MIT violation… public String getMitViolationBehavior(); public void setMitViolationBehavior(String behavior); // behavior options public static final String mitViolationExcept; public static final String mitViolationIgnore; public static final String mitViolationReplace; public static final String mitViolationSave; }

26 Minimal Interarrival Behaviors
E.g. queue length 3, MIT=3… [T][T+3][] Event fired again at T+4 – MIT violation!: EXCEPT – throw MITViolationException from fire() like ignore if caused by external happening IGNORE – ignore firing; queue unchanged REPLACE – replace the last time in the queue E.g. [T][T+4][] (no effect if last already released) SAVE – add to queue (extend if required) (default) E.g. [T][T+3][T+6] Note: time from last release increased to MIT for starting handler but NOT deadline checking See SporadicAsyncEventHandler.java

27 Timer overview Comparable to java.util.Timer/ TimerTask, but…
Realtime Timer extends AsyncEvent OneShotTimer and PeriodicTimer extend Timer for one-shot or periodic use  So Threading is handled by realtime VM or BoundAsyncEventHandler (see later) Realtime equivalent of TimerTask is a regular realtime AsyncEventHandler

28 Timer class (i) Package javax.realtime; public abstract class Timer
extends AsyncEvent { protected Timer(HighResolutionTime time, Clock clock, AsyncEventHandler handler); // parameters protected ReleaseParameters createReleaseParameters(); public Clock getClock(); // state… public void destroy();

29 Fires when time reached?
Timer class (ii) public void start(); public void start(boolean disabled); public void stop(); public void enable(); public void disable(); public void reschedule(HighReslutionTime time); public AbsoluteTime getFireTime(); public boolean isRunning(); public void fire(); } Timer active, i.e. “clock” running? Fires when time reached? (default to true) (next) fire time active & enabled?

30 OneShotTimer class (i)
Package javax.realtime; public class OneShotTimer extends Timer { // default clock is system realtime clock protected OneShotTimer(HighResolutionTime fireTime, Clock clock, AsyncEventHandler handler); }

31 OneShotTimer notes Fires once fireTime may be
RelativeTime – absolute fireTime determined in start() AbsoluteTime – specifies fireTime directly If in past then fires immediately After firing becomes inactive (and disabled) Can be fired again by reschule(time) then start() See HelloOneShotTimer.java, HelloOneShotTimer2.java

32 PeriodicTimer class (i)
Package javax.realtime; public class PeriodicTimer extends Timer { // default clock is system realtime clock protected PeriodicTimer(HighResolutionTime start, RelativeTime interval, Clock clock, AsyncEventHandler handler); // from Timer… protected ReleaseParameters createReleaseParameters(); public AbsoluteTime getFireTime(); // properties public RelativeTime getInterval(); public void setInterval(RelativeTime interval); }

33 PeriodicTimer notes (i)
Fires repeatedly at interval until stopped fireTime as per OneShotTimer Note: if disabled then intervals still pass but fire is not called (fireTime shows next possible fire) E.g. due to fire at 10, 20, 30, …; disabled at 19, re-enabled at 21 => fire at 10, (not 20) 30 See HelloPeriodicTimer.java, HelloPeriodicTimer2.java DisablePeriodicTimer.java

34 PeriodicTimer notes (ii)
Initialised with RelativeTime fireTime: When start() is called the (next) absolute fireTime is calculated from initial relative fireTime and the current time Initialised with AbsoluteTime fireTime: When time start() is called if fireTime has passed one* fire is done immediately But ignored if disabled Can stop and re-start a timer but generally wouldn’t * Updates to RTSJ should allow a range of “catch-up” options

35 BoundAsyncEventHandler
Extends AsyncEventHandler Same constructor arguments Permanently associated with a RealtimeThread Avoids any additional delay in assigning a fired AsyncEventHandler to a system RealtimeThread (normally the realtime VM provides/creates realtime threads to run AsyncEventHandlers as needed)

36 BoundAsyncEventHandler class
package javax.realtime; public class BoundAsyncEventHandler extends AsyncEventHandler { // as per AsyncEventHandler… public BoundAsyncEventHandler(); public BoundAsyncEventHandler( SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memory, MemoryArea area, ProcessingGroupParameters group, boolean nonheap, Runnable logic); }

37 POSIXSignalHandler Required on POSIX platforms (only)
Standard way to register handlers for POSIX signals C.f. AsyncEvent bound to corresponding happening (platform-dependent) But note that there is not a (visible) AsyncEvent for any POSIX signals See HelloPOSIXSignalHandler.java HelloBoundAsyncEvent.java

38 POSIXSignalHandler class
package javax.realtime; public class POSIXSignalHandler { // signals… public static final int SIGABRT; public static final int SIGINT; public static void addHandler(int signal, AsyncEventHandler handler); public static void removeHandler(int signal, public static void setHandler(int signal, }

39 Summary (i) AsyncEvent instances represent asynchronous events
Fired by program or bound to external signals or interrupts AsyncEventHandler handles firing of event Implements Schedulable Same realtime parameters as RealtimeThread Calls handleAsyncEvent or Runnable logic Aperiodic events have no known arrival pattern Described by AperiodicParameters ReleaseParameters Can be (partially) managed via Arrival Time Queue

40 Summary (ii) Sporadic events have a minimum interarrival time
Described by SporadicParameters MIT violations detected and responded to, e.g. ignore, save Timed events supported by concrete Timer subclasses OneShotTimer – fires once PeriodicTimer – fires repeatedly with specified period States include in/active, dis/en-abled, relative/absolute POSIX Signals exposed to handlers via POSIXSignalHandler


Download ppt "G53SRP: Asynchronous Events in RTSJ"

Similar presentations


Ads by Google