G53SRP: Real Time Threads in RTSJ (part I) - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

G53SRP: Real Time Threads in RTSJ (part I)

Description:

the logic to be run by the default run method (or over-ride run method) ... May (or may not) be enforced as maximum. May (or may not) be used for feasibility test ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 28
Provided by: csNo
Category:
Tags: g53srp | rtsj | maximum | part | real | ride | threads | time

less

Transcript and Presenter's Notes

Title: G53SRP: Real Time Threads in RTSJ (part I)


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
ltltinterfacegtgtjava.lang.Runnable
implements
java.lang.Thread

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 gt standard (1-10)
  • public int getMinPriority()
  • public int getMaxPriority() // at least min27
  • public int getNormPriority()
  • // 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 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()

10
E.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)

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
ltltabstractgtgtjavax.realtime.SchedulingParameters
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 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
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
ltltabstractgtgtjavax.realtime.ReleaseParameters
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
  • 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
Example Periodic RealtimeThread (no problems)
Process Release Time
Process
Process Completion Time Deadline met
Call to waitForNextPeriod
RT1
Actual task execution
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
Write a Comment
User Comments (0)
About PowerShow.com