auto-sync

This commit is contained in:
rusEfi 2015-04-16 19:04:30 -04:00
parent 4a7aeab33a
commit 15dba65f3e
3 changed files with 16 additions and 7 deletions

View File

@ -15,6 +15,7 @@
#include "SingleTimerExecutor.h" #include "SingleTimerExecutor.h"
#include "efitime.h" #include "efitime.h"
#include "efilib2.h"
#if EFI_PROD_CODE #if EFI_PROD_CODE
#include "microsecond_timer.h" #include "microsecond_timer.h"
@ -35,6 +36,10 @@ extern schfunc_t globalTimerCallback;
static uint64_t nextEventTimeNt = 0; static uint64_t nextEventTimeNt = 0;
static uint64_t hwAlarmTime = 0; static uint64_t hwAlarmTime = 0;
uint32_t beforeHwSetTimer;
uint32_t hwSetTimerTime;
uint32_t lastExecutionCount;
static void executorCallback(void *arg) { static void executorCallback(void *arg) {
(void)arg; (void)arg;
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "lowstck#2y"); efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "lowstck#2y");
@ -97,19 +102,22 @@ void Executor::doExecute() {
* further invocations * further invocations
*/ */
reentrantFlag = true; reentrantFlag = true;
bool shouldExecute = true; int shouldExecute = 1;
/** /**
* in real life it could be that while we executing listeners time passes and it's already time to execute * in real life it could be that while we executing listeners time passes and it's already time to execute
* next listeners. * next listeners.
* TODO: add a counter & figure out a limit of iterations? * TODO: add a counter & figure out a limit of iterations?
*/ */
while (shouldExecute) { int totalExecuted = 0;
while (shouldExecute > 0) {
/** /**
* It's worth noting that that the actions might be adding new actions into the queue * It's worth noting that that the actions might be adding new actions into the queue
*/ */
uint64_t nowNt = getTimeNowNt(); uint64_t nowNt = getTimeNowNt();
shouldExecute = queue.executeAll(nowNt); shouldExecute = queue.executeAll(nowNt);
totalExecuted += shouldExecute;
} }
lastExecutionCount = totalExecuted;
if (!isLocked()) { if (!isLocked()) {
firmwareError("Someone has stolen my lock"); firmwareError("Someone has stolen my lock");
return; return;
@ -127,7 +135,9 @@ void Executor::doExecute() {
if (nextEventTimeNt == EMPTY_QUEUE) if (nextEventTimeNt == EMPTY_QUEUE)
return; // no pending events in the queue return; // no pending events in the queue
hwAlarmTime = NT2US(nextEventTimeNt - nowNt); hwAlarmTime = NT2US(nextEventTimeNt - nowNt);
beforeHwSetTimer = GET_TIMESTAMP();
setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime); setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime);
hwSetTimerTime = GET_TIMESTAMP() - beforeHwSetTimer;
} }
/** /**

View File

@ -82,9 +82,9 @@ uint32_t lastEventQueueTime;
/** /**
* Invoke all pending actions prior to specified timestamp * Invoke all pending actions prior to specified timestamp
* @return true if at least one action was executed * @return number of executed actions
*/ */
bool EventQueue::executeAll(uint64_t now) { int EventQueue::executeAll(uint64_t now) {
scheduling_s * current, *tmp; scheduling_s * current, *tmp;
scheduling_s * executionList = NULL; scheduling_s * executionList = NULL;
@ -109,7 +109,6 @@ bool EventQueue::executeAll(uint64_t now) {
* we need safe iteration here because 'callback' might change change 'current->next' * we need safe iteration here because 'callback' might change change 'current->next'
* while re-inserting it into the queue from within the callback * while re-inserting it into the queue from within the callback
*/ */
bool result = (executionList != NULL);
LL_FOREACH_SAFE(executionList, current, tmp) LL_FOREACH_SAFE(executionList, current, tmp)
{ {
uint32_t before = GET_TIMESTAMP(); uint32_t before = GET_TIMESTAMP();
@ -123,7 +122,7 @@ bool EventQueue::executeAll(uint64_t now) {
// cost++; // cost++;
// } // }
} }
return result; return executionCounter;
} }
int EventQueue::size(void) { int EventQueue::size(void) {

View File

@ -45,7 +45,7 @@ public:
void insertTask(scheduling_s *scheduling, uint64_t timeX, schfunc_t callback, void *param); void insertTask(scheduling_s *scheduling, uint64_t timeX, schfunc_t callback, void *param);
bool executeAll(uint64_t now); int executeAll(uint64_t now);
uint64_t getNextEventTime(uint64_t nowUs); uint64_t getNextEventTime(uint64_t nowUs);
void clear(void); void clear(void);