2 Replies Latest reply: Apr 22, 2009 7:33 AM by 807557 RSS

    unexpected behavior of waitForNextPeriod()

    807557
      Hi,

      I'm running some tests with a periodic nhrt with a period of 10000ns (not changed during runtime). But somehow this period is not considered. First the release periods are random and after a while they swing into a period of nearly exact 50000ns (50 us).
      Here is how the period is set and the loop that is executed in every release:
        ...
                  pp = (PeriodicParameters) getReleaseParameters();
                  period = pp.getPeriod();
                  period.set(0, 10000);
                  pp.setDeadline(period);
                  pp.setPeriod(period);
      
                  for (int i=0; i<someCondition; i++) {
                      queue.write(b)
                      
                      // measure values.
                      queueSizes[qsCounter] = queue.size();
                      wfnpReturnValues[qsCounter] = waitForNextPeriod(); // safe the waitForNextPeriod() (wfnp) return values
                      rtClock.getTime(tmpTime);
                      releaseTimes[qsCounter] = tmpTime.getMilliseconds()*1000000 +
                              tmpTime.getNanoseconds();
                      
                      qsCounter++;
                  }
        ...
      This loop is executed about 1000 times. The measured values are then printed to a file. Here is an extract, where you can see the unexpected behavior.
      ReleasePeriod: 10000ns,     qSize: 1,     wfnp: false,     released: 1240396870746168239ns
      ReleasePeriod: 10000ns,     qSize: 2,     wfnp: false,     released: 1240396870746204565ns
      ReleasePeriod: 10000ns,     qSize: 3,     wfnp: false,     released: 1240396870746207948ns
      ReleasePeriod: 10000ns,     qSize: 4,     wfnp: false,     released: 1240396870746210642ns
      ReleasePeriod: 10000ns,     qSize: 5,     wfnp: false,     released: 1240396870746213256ns
      ReleasePeriod: 10000ns,     qSize: 6,     wfnp: false,     released: 1240396870746215926ns
      ReleasePeriod: 10000ns,     qSize: 7,     wfnp: false,     released: 1240396870746218534ns
      ReleasePeriod: 10000ns,     qSize: 8,     wfnp: false,     released: 1240396870746221151ns
      ReleasePeriod: 10000ns,     qSize: 9,     wfnp: false,     released: 1240396870746223765ns
      ReleasePeriod: 10000ns,     qSize: 10,     wfnp: false,     released: 1240396870746226391ns
      ReleasePeriod: 10000ns,     qSize: 11,     wfnp: false,     released: 1240396870746230543ns
      ReleasePeriod: 10000ns,     qSize: 12,     wfnp: true,     released: 1240396870746233344ns
      ReleasePeriod: 10000ns,     qSize: 13,     wfnp: true,     released: 1240396870746235980ns
      ReleasePeriod: 10000ns,     qSize: 14,     wfnp: true,     released: 1240396870746238607ns
      ReleasePeriod: 10000ns,     qSize: 15,     wfnp: true,     released: 1240396870746241229ns
      ReleasePeriod: 10000ns,     qSize: 16,     wfnp: true,     released: 1240396870746243850ns
      ReleasePeriod: 10000ns,     qSize: 17,     wfnp: true,     released: 1240396870746246536ns
      ReleasePeriod: 10000ns,     qSize: 18,     wfnp: true,     released: 1240396870746249353ns
      ReleasePeriod: 10000ns,     qSize: 19,     wfnp: true,     released: 1240396870746252102ns
      ReleasePeriod: 10000ns,     qSize: 20,     wfnp: true,     released: 1240396870746320104ns
      ReleasePeriod: 10000ns,     qSize: 21,     wfnp: true,     released: 1240396870746331174ns
      ReleasePeriod: 10000ns,     qSize: 22,     wfnp: true,     released: 1240396870746390410ns
      ReleasePeriod: 10000ns,     qSize: 23,     wfnp: true,     released: 1240396870746433373ns
      ReleasePeriod: 10000ns,     qSize: 24,     wfnp: true,     released: 1240396870746482881ns
      ReleasePeriod: 10000ns,     qSize: 25,     wfnp: true,     released: 1240396870746533327ns
      ReleasePeriod: 10000ns,     qSize: 26,     wfnp: true,     released: 1240396870746582095ns
      ReleasePeriod: 10000ns,     qSize: 27,     wfnp: true,     released: 1240396870746631634ns
      ReleasePeriod: 10000ns,     qSize: 28,     wfnp: true,     released: 1240396870746689020ns
      ...
      // wfnp returns true until the end
      // released values swing into a period of 50000ns (instead of 10000).
      As one can see, the periodic releases do not take place in periods of 10000ns. Although nearly every periodic release is heavily delayed and by this the periodic deadline is missed, the waitForNextPeriod() method non-stop returns true.

      The false values of the wfnp() method at the beginning are quite clear to me. It simply takes to long from starting this thread to enter the first few loops. I will change that, when the rest fits.

      Question 1: Why does the method waitForNextPeriod() return true for the rest of the runtime, although the periods and deadlines are missed?
      Question 2: How come that the period of 10000ns is ignored and a period of (nearly exactly) 50000ns swings in?

      Thanks,
      Gordon
        • 1. Re: unexpected behavior of waitForNextPeriod()
          807557
          From: http://java.sun.com/javase/technologies/realtime/reference/doc_2.1/release/JavaRTSTechInfo.html

          Minimum Period Enforced

          Java RTS enforces a minimum period for periodic release parameters that are associated with a real-time thread. Periods shorter than the minimum value are accepted but are silently raised to that minimum value to try to avoid system hangs. No errors, warnings, or exceptions are currently reported.

          This minimum period value is set by default to 50 microseconds.

          * Solaris: This value can be changed by editing the /platform/<arch>/kernel/drv/cyclic.conf file, setting the cyclic_min_interval variable to the appropriate value (expressed in nanoseconds), and rebooting your system.

          Note that lowering the value of this minimum period can potentially cause your system to hang, if an application specifies an unreasonably short period.
          ------

          David Holmes
          • 2. Re: unexpected behavior of waitForNextPeriod()
            807557
            Thanks David!

            I knew I have read something like this, but I didn't find it.