31.01.2014 Views

Ph.D. - geht es zur Homepage der Informatik des Fachbereiches 3 ...

Ph.D. - geht es zur Homepage der Informatik des Fachbereiches 3 ...

Ph.D. - geht es zur Homepage der Informatik des Fachbereiches 3 ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8. openETCS Domain Framework<br />

also a new asset of the C++11 specification. The time for putting the thread to sleep state<br />

is calculated in Line 105 while SAMPLE_TIME is the system constant sample time T s , which is<br />

typically in the range of milliseconds.<br />

To synchronise all threads right from the beginning, the Lin<strong>es</strong> 3 - 18 are implemented.<br />

m_Barrier is of type ::std::condition_variable and also part of the new thread library [7,<br />

Ch. 30] of the C++11 draft standard. Its wait(::std::mutex) method locks a calling thread<br />

until notify_all() is executed from any other thread. It seems that this is the b<strong>es</strong>t that<br />

can be implemented to avoid delays as in Figure 8.20 with the usage of soft real-time [77,<br />

pp. 457-504] mechanisms. Since hard real-time [77, pp. 457-504] mechanisms and interfac<strong>es</strong> are<br />

mostly platform specific, those cannot be used in the domain framework because it repr<strong>es</strong>ents<br />

the PIM. Hence, hard real-time mechanisms could only be integrated in the PSM.<br />

Unfortunately, it is crucial that no thread starts its next execution before all others are<br />

finished. Otherwise, it cannot be assured that all used CEVCTransition, CTransition, and<br />

CLevelCondition objects are already calculated and a transition to a new CEVCState or CState<br />

object is not ignored. Thus, before calculating the sleep time and putting the thread to sleep<br />

in Line 111, all parallel executed threads must be synchronised. This is done by the same<br />

construct used for the initial synchronisation (Lin<strong>es</strong> 3 - 18) but extended about the evaluation<br />

of activated transitions in Lin<strong>es</strong> 46 - 101. In the case that the thread is not the last active<br />

thread, which is determined by m_iLockedThreads == (m_Threads.size() - 1), it is simply<br />

blocked by the m_Barrier object. In contrast to the initial synchronisation, the last thread<br />

that enters the block not only notify all others via m_Barrier to proceed with the execution but<br />

also checks the stack of the m_TransitionStack with the activated CEVCTransition objects of<br />

the current cycle k. If more than one transition was activated, the one with the high<strong>es</strong>t priority<br />

is chosen and set in Line 76. A consequence is that the slow<strong>es</strong>t thread or rather the thread<br />

with the lat<strong>es</strong>t ending time point of its m_CurrentDataFlow[iIndex]->Execute() execution<br />

defin<strong>es</strong> the blocking / sleeping time for all others by the synchronisation. Although this can<br />

lead to problems if a thread is severe delayed, it is nec<strong>es</strong>sary to guarantee that CEVCTransition<br />

are always evaluated properly at the end of each execution k.<br />

At the very end of the while-loop in Line 122, the start time for each thread is calculated<br />

instead of measured as for the first execution in Line 21. This has the advantag<strong>es</strong> that global<br />

drifts in execution time are avoided and only local drifts may occur. Within a soft real-time<br />

system, the absence of drifts cannot be guaranteed because the execution of all proc<strong>es</strong>s<strong>es</strong> is<br />

managed by a global scheduler that works un<strong>der</strong> the regime of the operating system kernel.<br />

Therefore, kernel proc<strong>es</strong>s<strong>es</strong> may always block the execution of a user space proc<strong>es</strong>s or thread<br />

even if it has a high priority [77, pp. 457-504]. The difference between global and local drifts<br />

are exemplary shown for one thread in Figure 8.22.<br />

In the case of a global drift, the delay of the execution start ∆t delays all further execution<br />

about the same ∆t because the start time is measured, which includ<strong>es</strong> the delay. Even further<br />

delays would be accumulated, so that the execution would end to be completely unsynchronised<br />

with the d<strong>es</strong>ired sample time points kT s . Since the calculation of the new start time, instead<br />

of measuring it, do<strong>es</strong> not take any occurred delay ∆t into account, the next execution starts at<br />

the correct time point 2T s for the local drift.<br />

Of course, a general constraint to avoid drifts is that the minimal required execution time is<br />

not bigger than the sample time: t e ≤ T s . To this property is also referred as scheduleability [77,<br />

152

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

Saved successfully!

Ooh no, something went wrong!