18 #include "ThreadConfig.hpp"
19 #include "Emulator.hpp"
20 #include "GlobalData.hpp"
21 #include "TimeQueue.hpp"
22 #include "TransporterRegistry.hpp"
23 #include "FastScheduler.hpp"
26 #include <GlobalSignalNumbers.h>
27 #include <BlockNumbers.h>
32 #include <WatchDog.hpp>
34 #include <EventLogger.hpp>
37 #include <signaldata/StartOrd.hpp>
39 ThreadConfig::ThreadConfig()
43 ThreadConfig::~ThreadConfig()
59 ThreadConfig::scanTimeQueue()
61 unsigned int maxCounter;
62 Uint64 currMilliSecond;
64 currMilliSecond = NdbTick_CurrentMillisecond();
65 if (currMilliSecond < globalData.internalMillisecCounter) {
71 g_eventLogger->
warning(
"Time moved backwards with %llu ms",
72 globalData.internalMillisecCounter-currMilliSecond);
73 globalData.internalMillisecCounter = currMilliSecond;
75 if (currMilliSecond > (globalData.internalMillisecCounter + 1500)) {
81 g_eventLogger->
warning(
"Time moved forward with %llu ms",
82 currMilliSecond-globalData.internalMillisecCounter);
83 globalData.internalMillisecCounter = currMilliSecond - 1000;
85 while (((currMilliSecond - globalData.internalMillisecCounter) > 0) &&
87 globalData.internalMillisecCounter++;
89 globalTimeQueue.scanTable();
107 globalEmulatorData.theConfiguration->setAllLockCPU(
true);
109 Uint32 execute_loop_constant =
110 globalEmulatorData.theConfiguration->schedulerExecutionTimer();
111 Uint32 min_spin_time =
112 globalEmulatorData.theConfiguration->schedulerSpinTimer();
115 Uint32 no_exec_loops = 0;
116 Uint32 no_extra_loops = 0;
117 Uint32 tot_exec_time = 0;
118 Uint32 tot_extra_time = 0;
119 Uint32 timeOutMillis;
120 Uint32 micros_passed;
122 bool yield_flag= FALSE;
132 globalData.internalMillisecCounter = NdbTick_CurrentMillisecond();
134 Uint32 *watchCounter = globalData.getWatchDogPtr();
135 globalEmulatorData.theWatchDog->registerWatchedThread(watchCounter, 0);
137 res1 = NdbTick_getMicroTimer(&start_micro);
138 yield_micro = statistics_start_micro = end_micro = start_micro;
145 globalData.incrementWatchDogCounter(6);
154 execute_loop_constant =
155 globalEmulatorData.theConfiguration->schedulerExecutionTimer();
157 globalEmulatorData.theConfiguration->schedulerSpinTimer();
158 globalData.incrementWatchDogCounter(5);
169 globalData.incrementWatchDogCounter(2);
172 if (LEVEL_IDLE == globalData.highestAvailablePrio)
184 if (min_spin_time && !yield_flag)
187 res2 = NdbTick_getMicroTimer(&end_micro);
191 (Uint32)NdbTick_getMicrosPassed(start_micro, end_micro);
192 if (micros_passed < min_spin_time)
197 if (spinning && timeOutMillis > 0 && i++ >= 20)
199 globalData.incrementWatchDogCounter(5);
207 globalData.incrementWatchDogCounter(7);
212 globalEmulatorData.theConfiguration->yield_main(thread_index, TRUE);
213 poll_flag= globalTransporterRegistry.pollReceive(timeOutMillis);
214 globalEmulatorData.theConfiguration->yield_main(thread_index, FALSE);
215 res3= NdbTick_getMicroTimer(&yield_micro);
218 poll_flag= globalTransporterRegistry.pollReceive(timeOutMillis);
221 globalData.incrementWatchDogCounter(8);
227 globalScheduler.postPoll();
232 }
while (LEVEL_IDLE == globalData.highestAvailablePrio);
238 res1= NdbTick_getMicroTimer(&start_micro);
240 ((Uint32)NdbTick_getMicrosPassed(start_micro, yield_micro) > 10000))
249 globalScheduler.doJob();
250 if (unlikely(globalData.theRestartFlag == perform_stop))
260 if (!execute_loop_constant && !min_spin_time)
262 res2= NdbTick_getMicroTimer(&end_micro);
265 micros_passed = (Uint32)NdbTick_getMicrosPassed(start_micro, end_micro);
266 tot_exec_time += micros_passed;
267 if (no_exec_loops++ >= 8192)
269 Uint32 expired_time =
270 (Uint32)NdbTick_getMicrosPassed(statistics_start_micro, end_micro);
271 statistics_start_micro = end_micro;
272 globalScheduler.reportThreadConfigLoop(expired_time,
273 execute_loop_constant,
286 if (micros_passed > execute_loop_constant || (exec_again > 1))
294 globalData.incrementWatchDogCounter(7);
295 if (!globalTransporterRegistry.pollReceive(0))
299 tot_extra_time += micros_passed;
300 start_micro = end_micro;
301 globalData.incrementWatchDogCounter(8);
306 globalData.incrementWatchDogCounter(6);
309 globalEmulatorData.theWatchDog->unregisterWatchedThread(0);
319 sh.theVerId_signalNumber = GSN_START_ORD;
320 sh.theReceiversBlockNumber = CMVMI;
321 sh.theSendersBlockRef = 0;
324 sh.theLength = StartOrd::SignalLength;
333 globalScheduler.execute(&sh, JBA, theData, secPtrI);