Real-time Java without RTSJ

Discussion in 'Java' started by Martin Schoeberl, Aug 12, 2003.

  1. The Real-Time Specification for Java (RTSJ) is a large and complex
    specification and perhaps too difficult to implement on small enbedded
    systems. I'm interested if there exist different specifications (besides the
    Core specification of the J Consortium) that are allready implemented and in
    use.

    And, by the way, how many implementation are actual on the way. I'm only
    aware of the Reference Implementation (RI) from time-sys, jRate on top of
    GCJ and aJile is working on it for their processors.

    Martin
     
    Martin Schoeberl, Aug 12, 2003
    #1
    1. Advertising

  2. > The Real-Time Specification for Java (RTSJ) is a large and complex
    > specification and perhaps too difficult to implement on small enbedded
    > systems. I'm interested if there exist different specifications (besides

    the
    > Core specification of the J Consortium) that are allready implemented and

    in
    > use.
    >
    > And, by the way, how many implementation are actual on the way. I'm only
    > aware of the Reference Implementation (RI) from time-sys, jRate on top of
    > GCJ and aJile is working on it for their processors.
    >


    I would like to present a small specification for discussion:

    This specification is for embedded hard real-time Java systems. It is NOT
    compatible with RTSJ. However, with an emulation layer it should be possible
    to run progams written against this specification on RTSJ (e.g. the RI under
    Linux).

    Application Structure

    Following restrictions apply to the application:
    · Initialization and mission phase.
    · Fixed number of threads.
    · Threads are created at initialization phase.
    · All shared objects are allocated at initialization.

    Threads

    Three schedulable objects are defined:

    RtThread represents a periodic task. As usual task work is coded in run()
    which gets called on missionStart(). A scoped memory object can be attached
    to a RtThread at creation.

    HwEvent represents an interrupt with a minimum interarrivel time. If the
    hardware generates more interrupts, they get lost (or delayed?).

    SwEvent represents a software-generated event. It is triggered with fire()
    and has to override handle().

    The definition of the basic classes:

    public abstract class RtTask {
    public void enterMemory()
    public void exitMemory()
    }

    public class RelativeTime {

    private RelativeTime()
    public RelativeTime(int millis)
    public RelativeTime(int millis, int micro)
    }

    public class RtThread extends RtTask {

    private RtThread()
    public RtThread(int priority,
    RelativeTime period)
    public RtThread(int priority,
    RelativeTime period,
    Memory mem)
    public void run()
    public boolean waitForNextPeriod()
    }

    public class HwEvent extends RtTask {

    private HwEvent()
    public HwEvent(int priority,
    RelativeTime minTime,
    int number)
    public void handle()
    }

    public class SwEvent extends RtTask {

    private SwEvent()
    public SwEvent(int priority,
    RelativeTime minTime)
    public final void fire()
    public void handle()
    }

    Scheduling

    The class Scheduler defines a fixed priority scheduler (with FIFO within
    priorities). Priorities are divided in three ranges:

    Thread: Usual range (1-10) for standard Java threads.
    SoftRtThread: A range above the former for soft real-time tasks.
    RtThread: This is the range for the main hard real-time application.

    Synchronized blocks are executed with priority ceiling protocol. These
    blocks are not allowed to be shared between the three thread classes (How
    can this be enforced ?).
    The scheduler does not dispatch any RtThread or SoftRtThread until
    startMission() is called. Standard Java threads are scheduled during
    initialization phase, however usage is discouraged. Scheduling in the
    mission phase can be preemptive or non preemptive.

    The class for the scheduler:

    public final class Scheduler {

    private Scheduler()
    public static void enable()
    public static void disable()
    public static void startMission(
    boolean preempt)
    public static void setCeilingPriority(
    Object o,
    int priority)

    }

    public class SoftRtThread extends RtThread {

    public SoftRtThread(int priority)
    public SoftRtThread(int priority,
    Memory mem)

    public void sleep(RelativeTime time)
    }

    To implement non real-time (or soft real-time) tasks a Thread or
    SoftRtThread is allowed to use combinations of sleep() and yield(). The
    scheduler assigns priorities according to the thread type.
    disable() stops scheduling (i.e. disables interrupts) and can be used for
    top priority blocking. This method is provided for device drivers and should
    be used with care and only where absolute necessary.
    The scheduler will be extended with methods for worst-case time measurement
    for the periodic work and the longest block between yields. These measured
    execution times can be used during development when no WCET analysis tool is
    available.

    Memory

    The profile does not support a garbage collector. All memory allocation
    should be done at initialization phase. For new objects during mission phase
    a scoped memory is provided. Every scoped memory area can be assigned to one
    RtThread or SoftRtThread. It is not allowed to share a scoped memory between
    threads. No references from the heap to scoped memory are allowed. Scoped
    memory is explicit entered and left with calls from the application logic.
    Memory areas are cleared on creation and when leaving the scope (call of
    exitMemory()) leading to a memory area with constant allocation time.

    public class Memory {

    private Memory()
    public Memory(int size)
    public Memory(int size,
    int physAddress)
    }

    Restriction of Java

    A list of some language features that should (or must) be avoided for WCET
    analyzable real-time threads and bound memory usage:
    WCET: Only analyzable language constructs are al-lowed.
    Static class initialization: Move this code to a static method (e.g. init())
    and call it in the initialization phase.
    Inheritance: Reduce usage of interfaces and overridden methods.
    String concatenation: In immortal memory scope only String concatenation
    with string literals is allowed.

    A program analysis tool can greatly help to enforce these restrictions.

    An Example shows the principle coding of a worker thread and creation of two
    real-time threads and an event handler.

    public class Worker extends RtThread {

    private SwEvent event;

    public Worker(int p, RelativeTime t,
    SwEvent ev) {

    super(p, t,
    // create a scoped memory area
    new Memory(10000)
    );
    event = ev;
    init();
    }

    private void init() {
    // all initialzation stuff
    // has to be placed here
    }

    public void run() {

    for (;;) {
    work(); // do some work
    event.fire(); // and fire an event

    // some work in scoped memory
    enterMemory();
    workWithMem();
    exitMemory();

    // wait for next period
    if (!waitForNextPeriod()) {
    missedDeadline();
    }
    }
    // should never reach this point
    }
    }

    // create an Event
    Handler h = new Handler(
    RtThread.MAX_PRIORITY,
    new RelativeTime(1, 0)
    );

    // create two worker threads with
    // priorities according to their periods
    FastWorker fw = new FastWorker(
    RtThread.MAX_PRIORITY-1,
    new RelativeTime(2, 0)
    );
    Worker w = new Worker(
    RtThread.MAX_PRIORITY-2,
    new RelativeTime(10, 0), h
    );

    // change to mission phase for all
    // periodic threads and event handler
    Scheduler.startMission(true);

    // do some non real-time work
    // and call sleep() or yield()
    for (;;) {
    watchdogBlink();
    Thread.sleep(500);
    }

    Open issues (questions)
    · Can we allow non/soft real-time threads and still meet all requirements
    for a high-integrity system?
    · Shall threads with equal priority get time sliced? Without time slicing
    priority ceiling protocol is simpler to implement.
    · What happens if an object is used as monitor for which no ceiling priority
    is set?
    · If queuing of wait() is WCET analyzable (maximum number of threads is
    bound) and the semantics of notify changed to wake up the thread with the
    highest priority, can we allow wait/notify and don't need the additional
    class SwEvent?
    · How are timeouts programmed in such a high-integrity profile?

    Basic real-time tasks:
    · Cyclic
    · Sporadic
    · Spontaneous
    · Ongoing
    Spontaneous tasks have to be avoided. Is this also true for ongoing tasks?

    Comments?

    Martin
     
    Martin Schoeberl, Aug 13, 2003
    #2
    1. Advertising

  3. Martin Schoeberl

    Michael Paus Guest

    Martin Schoeberl wrote:

    > And, by the way, how many implementation are actual on the way. I'm only
    > aware of the Reference Implementation (RI) from time-sys, jRate on top of
    > GCJ and aJile is working on it for their processors.


    You might want to have a look at http://www.aicas.com/

    Michael

    --
    --------------------------------------------------------------------------------------
    Dr. Michael Paus, Chairman of the Java User Group Stuttgart e.V. (JUGS)
    and head of the JUGS Special Interest Group (SIG) "Embedded Java".
    For more information visit http://www.jugs.de .
     
    Michael Paus, Aug 13, 2003
    #3
  4. You can find more on this issue in a working paper:
    Restrictions of Java for Embedded Real-Time Systems
    available at: http://www.jopdesign.com/doc/rtjava.pdf

    It also summaries the J2ME specifications from Sun with some (not so nice
    ;-) comments on it.

    Martin
     
    Martin Schoeberl, Aug 19, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. EKL

    RTSJ implementations

    EKL, Aug 8, 2003, in forum: Java
    Replies:
    3
    Views:
    516
    Randall R Schulz
    Aug 8, 2003
  2. Martin Schoeberl

    RI/RTSJ and TimeSys Linux

    Martin Schoeberl, Oct 10, 2003, in forum: Java
    Replies:
    1
    Views:
    480
    David Morse
    Oct 30, 2003
  3. Tim Hutcheson

    RTSJ Memory Mapping

    Tim Hutcheson, Dec 30, 2003, in forum: Java
    Replies:
    0
    Views:
    378
    Tim Hutcheson
    Dec 30, 2003
  4. flamesrock
    Replies:
    8
    Views:
    502
    Hendrik van Rooyen
    Nov 24, 2006
  5. user
    Replies:
    1
    Views:
    125
Loading...

Share This Page