06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

to foresee the value actually returned. Let us look into a few basic aspects:<br />

• Time quantization: Waiting for the next ms does not mean waiting for<br />

1 ms. In fact, running on a 100 MHz CPU it may take only 10 nanoseconds<br />

(1 CPU cycle) until a new clock interrupt is served and the time<br />

(in software) is incremented. The real time between the readings will<br />

then be only the time to run lines 2 to 5, plus the service time for the<br />

clock interrupt, say 0.1 us giving a relative error of 1000000%! Ignoring<br />

the (quite small) computation time we see that even with the same<br />

numerical time values, the difference in real-time between two time readings<br />

(depending on when during the so called tick period each reading<br />

was done) can be up to (but not quite) two clock ticks.<br />

• Scheduling: It can on the other hand also be the case that the new clock<br />

tick causes another thread to be scheduled and the next reading takes<br />

place one second later. So even with a maximum of two ticks (2 ms)<br />

quantization error, the maximum trend error will be 0.2% Note again,<br />

the actual schedule (and thereby the returned value) is not expressed in<br />

the program; it depends on the system.<br />

• Efficiency: The longer execution is suspended between lines 3 and 4,<br />

the better the estimation of a constant trend gets 1 . The waiting for<br />

the second sampling time above was done by a so called busy wait. In<br />

rare situations this way of waiting for a condition to be fulfilled can be<br />

useful, but especially for longer delays it causes efficiency problems (and<br />

also response problems if real time is considered). A busy wait actually<br />

asks for 100% of the CPU time. A better approach would be to inform<br />

the thread scheduling that we permit other threads to run for a certain<br />

period of time. That is the purpose of the sleep method treated below.<br />

• Time-stamp deficiency: Suspended execution (and incrementing time)<br />

between lines 2 and 3, or between lines 4 and 5, also causes a bad trend<br />

error to be computed. This holds regardless of how small the time<br />

increments are, that is, even with the high resolution clock mentioned<br />

above. Also, if we swap lines 2 and 3, the program should be the same<br />

from a sequential computing point of view, but due to the System call<br />

it is not; the t can deviate in different directions which creates trend<br />

errors in different directions.<br />

The fact that we care about when an input value was sampled can be looked<br />

upon as if we would like to have a time-stamped value. That is, the value and<br />

1 For a changing input value, however, we need a short delay to get a fresh estimation.<br />

In real-time software we need to manage such trade-offs and preferably express the required<br />

execution timing in the source code, or we have to impose requirements on the run-time<br />

system. For now we only deal with time-dependent software which should not be confused<br />

with real time.<br />

3.1. Threads<br />

45

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!