This discussion is archived
10 Replies Latest reply: Apr 30, 2009 4:53 AM by 807557 RSS

waitForNextPeriod() returning after deadline miss

807557 Newbie
Currently Being Moderated
Hi,

let's pretend we have a periodic RealtimeThread which has a period of 1000ns (this is the value of the periodic release parameter AND the deadline value). The cyclic_min_interval in solaris is changed to 500ns, so that periods > 500ns are handled right by the method waitForNextPeriod() (wfnp).

Now we have the following loop in this RealtimeThread.
while(someCondition) {
  doSomething(); // takes 1200ns
  waitForNextPeriod();
}
The method doSomething() requires 1200ns to finish (so longer than one period). If we pretend that this loop is executed 3 times and the first time the loop starts it is exactly in time (calling doSomething() at t=0), when will this loop be executed the second time?

The problem is, in the first loop waitForNextPeriod() is called at t=1200ns, missing the deadline and the next release time (both at t=1000ns). So will calling wfnp() return immediately, at about 1200ns, or will it return at the next release point (beginning of the 3rd loop, at about t=2000ns)?

Thanks,
Gordon
  • 1. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    Gordon,

    If you call waitForNextPeriod when you have missed a deadline, and you have no deadline-miss handler installed, then wfnp will return immediately with the value "false".

    However, if you have set your periods and deadlines so small that the process of setting/checking for deadline misses itself takes longer than the period (or is very close), things are likely to become unstable.

    David
  • 2. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    Thanks David.

    This is also written in Andy Wellings book "Concurrent and Real-Time Programming in Java". But the corresponding figure 12.3 on page 252 tells something else. Although a deadline is missed and no deadline miss handler exists, wfnp() does not return immediately.

    I have one further question:
    If a nhrt has a loop like this:
    while(true) {
      doSomething(); // takes only 2ns
    }
    Is there any parameter like cyclic_min_interval that controlls the minimum possible loop-time?

    I have an application with a similar loop in a nhrt and I'm measuring the time every loop takes. Mostly the loop takes about 1800ns (this is as expected). But then suddenly for 300 loops the time is nearly exactly 10000ns. During 30000 loops this happens about 5 times.

    Regards,
    Gordon
  • 3. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    Gordon_Realtime wrote:
    Is there any parameter like cyclic_min_interval that controlls the minimum possible loop-time?
    No - there is no parameter/flag that controls this.
    I have an application with a similar loop in a nhrt and I'm measuring the time every loop takes. Mostly the loop takes about 1800ns (this is as expected). But then suddenly for 300 loops the time is nearly exactly 10000ns. During 30000 loops this happens about 5 times.
    I'm wondering how you measure the loop time - the cost of the calls to do that could be on a par with the size of your loop.

    When you are working with such small numbers you need to be using CPU isolation and interrupt shielding to try and avoid OS interference.

    But there are still "synchronization" points within the VM that can impact the NHRT. Do you have background activity triggerring GC?

    I've forgotten if you're using Solaris or Linux?

    David
  • 4. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    David,

    I'm using Solaris. I also have some background activity: one JLT running with priority 6 on heap. The other running thread is a nhrt with priority 55.

    This is the loop inside the nhrt:
    while(30000times) {
     queue.write(oneByte);
     queueSizes[counter] = queue.size();
     
     rtClock.getTime(time);
     releaseTimes[counter] = time.getMilliseconds() * 1000000 + time.getNanoseconds();
    
     counter++;
    }
    It is executed without any pause, so the JLT doesn't get any CPU-time to trigger the garbage collection so many times. And even if the garbage collection was activated, the nhrt running in scopedMemory should hopefully preempt it. Can the garbage collection be the reason for loop execution times between 1800ns and 10000ns with the given priorities?

    Thanks,
    Gordon
  • 5. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    David,

    you're right. Without the JLT the loop execution times stay stable at about 1800ns. No more outliers of 10000ns.

    Thanks a lot!

    Gordon
  • 6. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    There are shared resources within the VM (and the OS!) that can introduce latencies. Latencies on the order of a few tens of microseconds are within our expected operating range.

    You're really pushing the envelope at this level :)

    David
  • 7. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    Hi,

    Let's pretend we have Releases at 0ms, 1ms, 2ms, 3ms, ... every ms. Our Deadlines are set at 0,5ms. So Deadlines appear at 0,5ms, 1,5ms, 2,5ms, ... . Furthermore we have no deadline-miss handler installed.

    If we have a method, that needs 0,6ms and is released at 0ms. Then it will miss the first Deadline at 0,5ms. wfnp() will be called at about 0,6ms, when the method is finished. With this fact:
    If you call waitForNextPeriod when you have missed a deadline, and you have no deadline-miss handler installed, then wfnp will return immediately with the value "false".
    wfnp() had return immediately, at about 0,6ms (maybe a little bit later, because wfnp() needs some constant time, too). That would be before the second release time, which is 1ms. Or will it be released again at 1 ms, wfnp() not returning immediately, although a deadline miss occured?

    Thanks,
    Gordon
  • 8. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    Gordon,

    At the risk of repeating myself :) If you have missed a deadline, and no deadline-miss handler is installed, then a call to waitForNextPeriod should return immediately with the value false.

    This is semantic 5.h.i under "Periodic Release of Real-time Threads" in the "Scheduling" chapter of the RTSJ.

    David
  • 9. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    Thanks David,

    I just wanted to be sure, because this seems anti-intuitive.



    Is there any other possibility to pause a RealtimeThread for an exact Period of time beside waitForNextPeriod() or RealtimeThread.sleep() ?

    Regards,
    Gordon
  • 10. Re: waitForNextPeriod() returning after deadline miss
    807557 Newbie
    Currently Being Moderated
    Gordon_Realtime wrote:
    I just wanted to be sure, because this seems anti-intuitive.
    The return of false is the only way to report that a deadline was missed (in the absence of a handler). By returning immediately it allows the thread to try and take corrective action before the next release is due (for deadline < period anyway).
    Is there any other possibility to pause a RealtimeThread for an exact Period of time beside waitForNextPeriod() or RealtimeThread.sleep() ?
    waitForNextPeriod() does not pause for an exact period of time, it blocks until a pre-determined absolute release time is reached. The length of time you "pause" depends on how far ahead of that release time you called it. (This is scheduling at fixed rate.)

    RealtimeThread.sleep() can pause for an "exact" interval (scheduling at fixed interval), or until a given absolute time.

    What else are you looking for?

    David