1 / 27

G53SRP: Real Time Threads in RTSJ (part I)

G53SRP: Real Time Threads in RTSJ (part I). Chris Greenhalgh School of Computer Science. Contents. Overview The Scheduler Class Fixed Priority Scheduler The RealtimeThread Class RealtimeThread properties SchedulingParameters PriorityParameters ReleaseParameters

kimdeborah
Download Presentation

G53SRP: Real Time Threads in RTSJ (part I)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. G53SRP: Real Time Threads in RTSJ (part I) Chris Greenhalgh School of Computer Science

  2. Contents • Overview • The Scheduler Class • Fixed Priority Scheduler • The RealtimeThread Class • RealtimeThread properties • SchedulingParameters • PriorityParameters • ReleaseParameters • Periodic RealtimeThreads overview • Book: Wellings 10.2.1, 10.3, 10.4.1, 10.4.2 (part), 10.4.4, 10.5, 12.1 (part), 12.3 (part)

  3. Class Overview <<interface>>java.lang.Runnable implements extends <<interface>>javax.realtime.Schedulable java.lang.Thread <<abstract>>javax.realtime.Scheduler extends implements has javax.realtime.RealtimeThread extends javax.realtime.PriorityScheduler … extends (Default) javax.realtime.NoHeapRealtimeThread

  4. Checking and setting the Scheduler package javax.realtime; public abstract class Scheduler { public static Scheduler getDefaultScheduler(); public static void setDefaultScheduler(Scheduler s); public String getPolicyName(); // other Scheduler methods … } See HelloScheduler.java

  5. The Priority-based Scheduler package javax.realtime; public class PriorityScheduler extends Scheduler { public static PriorityScheduler instance(); // Scheduler-related info: priorities // Note: all RT Priorities > standard (1-10) public intgetMinPriority(); public intgetMaxPriority(); // at least min+27 public intgetNormPriority(); // other PriorityScheduler methods … } See HelloScheduler.java

  6. The Priority-based Scheduler • Only standard scheduler specified in RTSJ • Used as initial default scheduler • Schedules realtime threads according to priority • Single fixed priority assigned to each thread • Fully pre-emptive • i.e. a higher priority thread that becomes runnable immediately pre-empts a lower priority thread • Does not time-slice threads of equal priority • Running thread may yield to allow another equal-priority thread to run

  7. The RealtimeThread class package javax.realtime; public class RealtimeThread extends java.lang.Thread implements Schedulable { public RealtimeThread( SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memory, MemoryArea area, ProcessingGroupParameters group, java.lang.Runnable logic); // partial cons. – defaults are all null public RealtimeThread(); public RealtimeThread(SchedulingParameters s); public RealtimeThread(SchedulingParameters s, ReleaseParameters release); …

  8. public static RealtimeThreadcurrentRealtimeThread(); // from Thread public void run(); // runs logic by default public void start(); public void interrupt(); // changed: see ATC public void join(); public void join(long millis); public void join(long millis, intnanos); static public void sleep(long millis); static public void sleep(long millis, intnanos); // high-res versions static void sleep(Clock clock, HighResolutionTime t); static void sleep(HighResolutionTime time); …

  9. // scheduler public Scheduler getScheduler(); public void setScheduler(Scheduler scheduler); // from Thread public void setPriority(int priority); public intgetPriority(); // getters & setters for all parameters // (release, scheduler, memory, proc.group)… … // periodic threads (see later) static booleanwaitForNextPeriod(); static booleanwaitForNextPeriodInterruptible(); public void schedulePeriodic(); public void deschedulePeriodic(); … }

  10. E.g. HelloRealtimeThread.java import javax.realtime.RealtimeThread; public class HelloRealtimeThread extends RealtimeThread { public void run() { RealtimeThreadrt = RealtimeThread.currentRealtimeThread(); System.out.println("Hello from "+rt); } public static void main(String args[]) { RealtimeThreadrt = new HelloRealtimeThread(); rt.start(); try { rt.join(); } catch (InterruptedExceptionie) { } } } Code run with realtime support

  11. RealtimeThread (Schedulable) properties • SchedulingParameters (subclass) • Scheduler-specific thread information, e.g. priority • ReleaseParameters (subclass) • Temporal characteristics of the thread, e.g. release time, period, deadline, cost • MemoryParameters • memory usage of thread, e.g. max size, max rate of allocation

  12. RealtimeThread (Schedulable) properties (cont.) • MemoryArea • type/area of memory in which new objects will be allocated by thread • ProcessingGroupParameters • optional group limits (cost per period) for a set of schedulable objects • java.lang.Runnable • the logic to be run by the default run method (or over-ride run method)

  13. SchedulingParameters classes <<abstract>>javax.realtime.SchedulingParameters Empty class extends javax.realtime.PriorityParameters extends javax.realtime.ImportanceParameters

  14. PriorityParameters class package javax.realtime; public abstract class PriorityParameters extends SchedulingParameters { public PriorityParameters(int priority); public int getPriority(); public void setPriority(int priority); } 14

  15. PriorityParameters notes • SchedulingParameters depend on Scheduler used • PriorityParameters used with (e.g.) PriorityScheduler • Equivalent to Thread get/setPriority

  16. Priority notes • Realtime Priorities > normal thread priorities • Normal priorities • 1-10 • Time-sliced – priority affects time budget • RT priorities • 11-? (at least 28) • Strict order – only highest priority runs See NRTPriority.java See RTPriority.java

  17. ImportanceParameters • Extends PriorityParameters • Adds an integer importance property • May be used by scheduler in deadline over-run situations • E.g. to identify safety-critical tasks for preferential scheduling • Optional – depends on scheduler implementation

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

  19. ReleaseParameters class package javax.realtime; public abstract class ReleaseParameters { protected ReleaseParameters( RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler); // getters & setters … } 19

  20. ReleaseParameters notes • For every type of realtime thread or other Schedulable • cost • Time units per release • May (or may not) be enforced as maximum • May (or may not) be used for feasibility test • deadline • Latest completion time after release time

  21. PeriodicParameters class Specific to Periodic tasks package javax.realtime; public class PeriodicParameters extends ReleaseParameters { public PeriodicParameters( HighResolutionTime start, RelativeTime period, RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler); // getters & setters … } 21

  22. PeriodicParameters notes • start may be AbsoluteTime or RelativeTime • Default deadline = period

  23. Periodic RealtimeThread • Follows standard code pattern: public void run() { boolean ok = true; while(ok) { // periodic task code … ok = RealtimeThread. waitForNextPeriod(); } // contingency… } See HelloPeriodicThread.java

  24. 0 1000 2000 3000 4000 5000 Example Periodic RealtimeThread (no problems) Process Release Time Process Process Completion Time Deadline met Start Period… Call to waitForNextPeriod RT1 Actual task execution waitForNextPeriod blocking Time (ms)

  25. Summary • Scheduler exposed through Scheduler abstract class • Fixed Priority Scheduler provided as default –PriorityScheduler • RealtimeThread class extends java.lang.Thread • implements Schedulable as well as Runnable (see later)

  26. Summary (2) • RealtimeThread properties • SchedulingParameters – for Scheduler • PriorityParameters – for PriorityScheduler, specifies thread priority (like Thread.get/setPriority) • ReleaseParameters • Defines thread deadline and cost • Subclassed as PeriodicParameters, AperiodicParameters & SporadicParameters

  27. Summary (3) • PeriodicParameters • Defines thread start time/delay and period • Supported by RealtimeThread.waitForNextPeriod

More Related