Title: G53SRP: Real Time Threads in RTSJ (part I)
1G53SRP Real Time Threads in RTSJ (part I)
- Chris Greenhalgh
- School of Computer Science
2Contents
- 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)
3Class Overview
ltltinterfacegtgtjava.lang.Runnable
implements
java.lang.Thread
4Checking 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
5The Priority-based Scheduler
- package javax.realtime
- public class PriorityScheduler extends Scheduler
- public static PriorityScheduler instance()
- // Scheduler-related info priorities
- // Note all RT Priorities gt standard (1-10)
- public int getMinPriority()
- public int getMaxPriority() // at least min27
- public int getNormPriority()
- // other PriorityScheduler methods
-
See HelloScheduler.java
6The 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
7The 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 RealtimeThread currentRealtimeThre
ad() - // 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, int nanos)
- static public void sleep(long millis)
- static public void sleep(long millis, int
nanos) - // 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 int getPriority()
- // getters setters for all parameters
- // (release, scheduler, memory, proc.group)
-
- // periodic threads (see later)
- static boolean waitForNextPeriod()
- static boolean waitForNextPeriodInterruptible()
- public void schedulePeriodic()
- public void deschedulePeriodic()
-
-
10E.g. HelloRealtimeThread.java
- import javax.realtime.RealtimeThread
- public class HelloRealtimeThread extends
RealtimeThread -
- public void run()
- RealtimeThread rt
- RealtimeThread.currentRealtimeThread()
- System.out.println("Hello from "rt)
-
- public static void main(String args)
- RealtimeThread rt new HelloRealtimeThread()
- rt.start()
- try rt.join()
- catch (InterruptedException ie)
-
-
11RealtimeThread (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
12RealtimeThread (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)
13SchedulingParameters classes
ltltabstractgtgtjavax.realtime.SchedulingParameters
14PriorityParameters class
- package javax.realtime
- public abstract class PriorityParameters
- extends SchedulingParameters
- public PriorityParameters(int priority)
- public int getPriority()
- public void setPriority(int priority)
14
15PriorityParameters notes
- SchedulingParameters depend on Scheduler used
- PriorityParameters used with (e.g.)
PriorityScheduler - Equivalent to Thread get/setPriority
16Priority notes
- Realtime Priorities gt 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
17ImportanceParameters
- 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
18ReleaseParameters classes
ltltabstractgtgtjavax.realtime.ReleaseParameters
19ReleaseParameters class
- package javax.realtime
- public abstract class ReleaseParameters
- protected ReleaseParameters(
- RelativeTime cost,
- RelativeTime deadline,
- AsyncEventHandler overrunHandler,
- AsyncEventHandler missHandler)
- // getters setters
-
19
20ReleaseParameters 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
21PeriodicParameters class
- 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
22PeriodicParameters notes
- start may be AbsoluteTime or RelativeTime
- Default deadline period
23Periodic RealtimeThread
- Follows standard code pattern
- public void run()
- boolean ok true
- while(ok)
- // periodic task code
-
- ok RealtimeThread.
- waitForNextPeriod()
-
- // contingency
See HelloPeriodicThread.java
24Example Periodic RealtimeThread (no problems)
Process Release Time
Process
Process Completion Time Deadline met
Call to waitForNextPeriod
RT1
Actual task execution
Time (ms)
25Summary
- 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)
26Summary (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
27Summary (3)
- PeriodicParameters
- Defines thread start time/delay and period
- Supported by RealtimeThread.waitForNextPeriod