diff --git a/firmware/controllers/error_handling.cpp b/firmware/controllers/error_handling.cpp index 11c1252252..8bf672c4dc 100644 --- a/firmware/controllers/error_handling.cpp +++ b/firmware/controllers/error_handling.cpp @@ -155,16 +155,19 @@ char *getWarning(void) { } uint32_t lastLockTime; -uint32_t maxLockTime = 0; +/** + * Maximum time before requesting lock and releasing lock at the end of critical section + */ +uint32_t maxLockedDuration = 0; void onLockHook(void) { lastLockTime = GET_TIMESTAMP(); } void onUnlockHook(void) { - uint32_t t = GET_TIMESTAMP() - lastLockTime; - if (t > maxLockTime) { - maxLockTime = t; + uint32_t lockedDuration = GET_TIMESTAMP() - lastLockTime; + if (lockedDuration > maxLockedDuration) { + maxLockedDuration = lockedDuration; } // if (t > 2800) { // // un-comment this if you want a nice stop for a breakpoint diff --git a/firmware/controllers/system/SingleTimerExecutor.cpp b/firmware/controllers/system/SingleTimerExecutor.cpp index dfa58f0759..def902afdd 100644 --- a/firmware/controllers/system/SingleTimerExecutor.cpp +++ b/firmware/controllers/system/SingleTimerExecutor.cpp @@ -35,8 +35,7 @@ extern schfunc_t globalTimerCallback; */ static efitime_t nextEventTimeNt = 0; -uint32_t beforeHwSetTimer; -uint32_t hwSetTimerTime; +uint32_t hwSetTimerDuration; uint32_t lastExecutionCount; static void executorCallback(void *arg) { @@ -136,9 +135,9 @@ void Executor::scheduleTimerCallback() { if (nextEventTimeNt == EMPTY_QUEUE) return; // no pending events in the queue int32_t hwAlarmTime = NT2US((int32_t)nextEventTimeNt - (int32_t)nowNt); - beforeHwSetTimer = GET_TIMESTAMP(); + uint32_t beforeHwSetTimer = GET_TIMESTAMP(); setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime); - hwSetTimerTime = GET_TIMESTAMP() - beforeHwSetTimer; + hwSetTimerDuration = GET_TIMESTAMP() - beforeHwSetTimer; } /** diff --git a/firmware/controllers/system/event_queue.cpp b/firmware/controllers/system/event_queue.cpp index bcff3d9f52..914081b7ce 100644 --- a/firmware/controllers/system/event_queue.cpp +++ b/firmware/controllers/system/event_queue.cpp @@ -106,8 +106,11 @@ efitime_t EventQueue::getNextEventTime(efitime_t nowX) { } static scheduling_s * longScheduling; -uint32_t maxEventQueueTime = 0; -uint32_t lastEventQueueTime; +/** + * See also maxPrecisionCallbackDuration for total hw callback time + */ +uint32_t maxEventCallbackDuration = 0; +static uint32_t lastEventCallbackDuration; /** * Invoke all pending actions prior to specified timestamp @@ -169,12 +172,12 @@ int EventQueue::executeAll(efitime_t now) { #endif current->callback(current->param); // even with overflow it's safe to subtract here - lastEventQueueTime = GET_TIMESTAMP() - before; - if (lastEventQueueTime > maxEventQueueTime) - maxEventQueueTime = lastEventQueueTime; - if (lastEventQueueTime > 2000) { + lastEventCallbackDuration = GET_TIMESTAMP() - before; + if (lastEventCallbackDuration > maxEventCallbackDuration) + maxEventCallbackDuration = lastEventCallbackDuration; + if (lastEventCallbackDuration > 2000) { longScheduling = current; - lastEventQueueTime++; +// what is this line about? lastEventCallbackDuration++; } } return executionCounter; diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index a48479e59f..f5ac86aea9 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -386,11 +386,15 @@ void printAllTriggers() { extern PwmConfig triggerSignal; #endif /* #if EFI_PROD_CODE */ -extern uint32_t maxLockTime; -extern uint32_t maxEventQueueTime; extern uint32_t hipLastExecutionCount; -extern uint32_t hwSetTimerTime; -extern uint32_t maxPrecisionTCallbackDuration; +extern uint32_t hwSetTimerDuration; + +extern uint32_t maxLockedDuration; +extern uint32_t maxEventCallbackDuration; + +#if (EFI_PROD_CODE) || defined(__DOXYGEN__) +extern uint32_t maxPrecisionCallbackDuration; +#endif /* EFI_PROD_CODE */ extern int maxHowFarOff; extern uint32_t *cyccnt; @@ -400,9 +404,13 @@ extern int vvtEventFallCounter; void resetMaxValues() { #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) - maxEventQueueTime = triggerMaxDuration = 0; - maxPrecisionTCallbackDuration = 0; + maxEventCallbackDuration = triggerMaxDuration = 0; #endif /* EFI_PROD_CODE || EFI_SIMULATOR */ + maxLockedDuration = 0; + +#if (EFI_PROD_CODE) || defined(__DOXYGEN__) + maxPrecisionCallbackDuration = 0; +#endif /* EFI_PROD_CODE */ } void triggerInfo(void) { @@ -495,15 +503,14 @@ void triggerInfo(void) { engine->m.rpmCbTime, engine->m.mainTriggerCallbackTime); - scheduleMsg(logger, "maxLockTime=%d / maxTriggerReentraint=%d", maxLockTime, maxTriggerReentraint); - maxLockTime = 0; - scheduleMsg(logger, "maxEventQueueTime=%d", maxEventQueueTime); + scheduleMsg(logger, "maxLockedDuration=%d / maxTriggerReentraint=%d", maxLockedDuration, maxTriggerReentraint); + scheduleMsg(logger, "maxEventCallbackDuration=%d", maxEventCallbackDuration); scheduleMsg(logger, "hipLastExecutionCount=%d", hipLastExecutionCount); - scheduleMsg(logger, "hwSetTimerTime %d", hwSetTimerTime); + scheduleMsg(logger, "hwSetTimerDuration=%d", hwSetTimerDuration); scheduleMsg(logger, "totalTriggerHandlerMaxTime=%d", triggerMaxDuration); - scheduleMsg(logger, "maxPrecisionTCallbackDuration=%d", maxPrecisionTCallbackDuration); + scheduleMsg(logger, "maxPrecisionCallbackDuration=%d", maxPrecisionCallbackDuration); resetMaxValues(); #endif /* EFI_PROD_CODE */ diff --git a/firmware/hw_layer/microsecond_timer.cpp b/firmware/hw_layer/microsecond_timer.cpp index 37b3177dd5..e619fd01ce 100644 --- a/firmware/hw_layer/microsecond_timer.cpp +++ b/firmware/hw_layer/microsecond_timer.cpp @@ -21,8 +21,13 @@ #if (EFI_PROD_CODE && HAL_USE_GPT) || defined(__DOXYGEN__) #include "efilib2.h" -uint32_t maxPrecisionTCallbackDuration = 0; +/** + * Maximum duration of complete timer callback, all pending events together + * See also 'maxEventCallbackDuration' for maximum duration of one event + */ +uint32_t maxPrecisionCallbackDuration = 0; +// must be one of 32 bit times #define GPTDEVICE GPTD5 static volatile efitick_t lastSetTimerTimeNt; @@ -99,8 +104,8 @@ static void callback(GPTDriver *gptp) { uint32_t before = GET_TIMESTAMP(); globalTimerCallback(NULL); uint32_t precisionCallbackDuration = GET_TIMESTAMP() - before; - if (precisionCallbackDuration > maxPrecisionTCallbackDuration) { - maxPrecisionTCallbackDuration = precisionCallbackDuration; + if (precisionCallbackDuration > maxPrecisionCallbackDuration) { + maxPrecisionCallbackDuration = precisionCallbackDuration; } }