From 4bb9762e2e962d46f5d51b9f2b7df73efdb24b33 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 31 Jan 2021 22:41:17 -0500 Subject: [PATCH] extracting runtime state from trigger central --- firmware/controllers/algo/algo.mk | 1 + firmware/controllers/algo/runtime_state.cpp | 69 +++++++++++++++++++ firmware/controllers/algo/runtime_state.h | 10 +++ firmware/controllers/flash_main.cpp | 3 +- .../controllers/system/timer/event_queue.cpp | 2 - .../controllers/trigger/trigger_central.cpp | 51 +------------- .../controllers/trigger/trigger_central.h | 1 - 7 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 firmware/controllers/algo/runtime_state.cpp create mode 100644 firmware/controllers/algo/runtime_state.h diff --git a/firmware/controllers/algo/algo.mk b/firmware/controllers/algo/algo.mk index aa231740c3..dac0741496 100644 --- a/firmware/controllers/algo/algo.mk +++ b/firmware/controllers/algo/algo.mk @@ -7,6 +7,7 @@ CONTROLLERS_ALGO_SRC_CPP = $(PROJECT_DIR)/controllers/algo/advance_map.cpp \ $(PROJECT_DIR)/controllers/algo/accel_enrichment.cpp \ $(PROJECT_DIR)/controllers/algo/launch_control.cpp \ $(PROJECT_DIR)/controllers/algo/dynoview.cpp \ + $(PROJECT_DIR)/controllers/algo/runtime_state.cpp \ $(PROJECT_DIR)/controllers/algo/engine_configuration.cpp \ $(PROJECT_DIR)/controllers/algo/engine.cpp \ $(PROJECT_DIR)/controllers/algo/engine2.cpp \ diff --git a/firmware/controllers/algo/runtime_state.cpp b/firmware/controllers/algo/runtime_state.cpp new file mode 100644 index 0000000000..6c3bce5bf1 --- /dev/null +++ b/firmware/controllers/algo/runtime_state.cpp @@ -0,0 +1,69 @@ +/* + * runtime_state.cpp + * + * Created on: Jan 31, 2021 + * @author Andrey Belomutskiy, (c) 2012-2021 + */ + +#include "global.h" +#include "runtime_state.h" + +// todo: revive implementation! we shall measure how far is actual execution timestamp from desired execution timestamp +uint32_t maxSchedulingPrecisionLoss = 0; + + +extern uint32_t hipLastExecutionCount; + +extern uint32_t maxLockedDuration; +extern uint32_t maxEventCallbackDuration; +extern uint32_t triggerMaxDuration; +extern int perSecondIrqDuration; +extern int perSecondIrqCounter; + +#if EFI_PROD_CODE +extern uint32_t maxPrecisionCallbackDuration; +#endif /* EFI_PROD_CODE */ + +extern uint32_t maxSchedulingPrecisionLoss; +extern uint32_t *cyccnt; + +void resetMaxValues() { +#if EFI_PROD_CODE || EFI_SIMULATOR + maxEventCallbackDuration = triggerMaxDuration = 0; +#endif /* EFI_PROD_CODE || EFI_SIMULATOR */ + + maxSchedulingPrecisionLoss = 0; + +#if EFI_CLOCK_LOCKS + maxLockedDuration = 0; +#endif /* EFI_CLOCK_LOCKS */ + +#if EFI_PROD_CODE + maxPrecisionCallbackDuration = 0; +#endif /* EFI_PROD_CODE */ +} + +extern LoggingWithStorage sharedLogger; + + +void printRuntimeStats(void) { + Logging *logger = &sharedLogger; + + scheduleMsg(logger, "maxSchedulingPrecisionLoss=%d", maxSchedulingPrecisionLoss); + +#if EFI_CLOCK_LOCKS + scheduleMsg(logger, "maxLockedDuration=%d / maxTriggerReentraint=%d", maxLockedDuration, maxTriggerReentraint); + + scheduleMsg(logger, "perSecondIrqDuration=%d ticks / perSecondIrqCounter=%d", perSecondIrqDuration, perSecondIrqCounter); + scheduleMsg(logger, "IRQ CPU utilization %f%%", perSecondIrqDuration / (float)CORE_CLOCK * 100); + +#endif /* EFI_CLOCK_LOCKS */ + + scheduleMsg(logger, "maxEventCallbackDuration=%d", maxEventCallbackDuration); + +#if EFI_HIP_9011 + scheduleMsg(logger, "hipLastExecutionCount=%d", hipLastExecutionCount); +#endif /* EFI_HIP_9011 */ + + +} diff --git a/firmware/controllers/algo/runtime_state.h b/firmware/controllers/algo/runtime_state.h new file mode 100644 index 0000000000..85ed7b3865 --- /dev/null +++ b/firmware/controllers/algo/runtime_state.h @@ -0,0 +1,10 @@ +/* + * runtime_state.h + * + * Created on: Jan 31, 2021 + * @author Andrey Belomutskiy, (c) 2012-2021 + */ + +#pragma once + +void resetMaxValues(); diff --git a/firmware/controllers/flash_main.cpp b/firmware/controllers/flash_main.cpp index c079461962..ba72908b82 100644 --- a/firmware/controllers/flash_main.cpp +++ b/firmware/controllers/flash_main.cpp @@ -20,6 +20,7 @@ #include "tunerstudio.h" #endif +#include "runtime_state.h" #include "engine_controller.h" @@ -92,9 +93,7 @@ void writeToFlashNow(void) { } assertEngineReference(); -#if EFI_SHAFT_POSITION_INPUT resetMaxValues(); -#endif } static bool isValidCrc(persistent_config_container_s *state) { diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index cd2ec71ce4..f73f7da454 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -23,8 +23,6 @@ extern int timeNowUs; extern bool verboseMode; #endif /* EFI_UNIT_TEST */ -uint32_t maxSchedulingPrecisionLoss = 0; - /** * @return true if inserted into the head of the list diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 7082670a98..bf513e324c 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -348,8 +348,7 @@ void hwHandleShaftSignal(trigger_event_e signal, efitick_t timestamp) { triggerReentraint--; triggerDuration = getTimeNowLowerNt() - triggerHandlerEntryTime; - if (triggerDuration > triggerMaxDuration) - triggerMaxDuration = triggerDuration; + triggerMaxDuration = maxI(triggerMaxDuration, triggerDuration); } #endif /* EFI_PROD_CODE */ @@ -562,37 +561,6 @@ static void triggerShapeInfo(void) { extern PwmConfig triggerSignal; #endif /* #if EFI_PROD_CODE */ -extern uint32_t hipLastExecutionCount; - -extern uint32_t maxLockedDuration; -extern uint32_t maxEventCallbackDuration; - -extern int perSecondIrqDuration; -extern int perSecondIrqCounter; - -#if EFI_PROD_CODE -extern uint32_t maxPrecisionCallbackDuration; -#endif /* EFI_PROD_CODE */ - -extern uint32_t maxSchedulingPrecisionLoss; -extern uint32_t *cyccnt; - -void resetMaxValues() { -#if EFI_PROD_CODE || EFI_SIMULATOR - maxEventCallbackDuration = triggerMaxDuration = 0; -#endif /* EFI_PROD_CODE || EFI_SIMULATOR */ - - maxSchedulingPrecisionLoss = 0; - -#if EFI_CLOCK_LOCKS - maxLockedDuration = 0; -#endif /* EFI_CLOCK_LOCKS */ - -#if EFI_PROD_CODE - maxPrecisionCallbackDuration = 0; -#endif /* EFI_PROD_CODE */ -} - #if HAL_USE_ICU == TRUE extern int icuRisingCallbackCounter; extern int icuFallingCallbackCounter; @@ -681,25 +649,8 @@ void triggerInfo(void) { scheduleMsg(logger, "primary logic input: %s", hwPortname(CONFIG(logicAnalyzerPins)[0])); scheduleMsg(logger, "secondary logic input: %s", hwPortname(CONFIG(logicAnalyzerPins)[1])); - scheduleMsg(logger, "maxSchedulingPrecisionLoss=%d", maxSchedulingPrecisionLoss); - -#if EFI_CLOCK_LOCKS - scheduleMsg(logger, "maxLockedDuration=%d / maxTriggerReentraint=%d", maxLockedDuration, maxTriggerReentraint); - - scheduleMsg(logger, "perSecondIrqDuration=%d ticks / perSecondIrqCounter=%d", perSecondIrqDuration, perSecondIrqCounter); - scheduleMsg(logger, "IRQ CPU utilization %f%%", perSecondIrqDuration / (float)CORE_CLOCK * 100); - -#endif /* EFI_CLOCK_LOCKS */ - - scheduleMsg(logger, "maxEventCallbackDuration=%d", maxEventCallbackDuration); - -#if EFI_HIP_9011 - scheduleMsg(logger, "hipLastExecutionCount=%d", hipLastExecutionCount); -#endif /* EFI_HIP_9011 */ scheduleMsg(logger, "totalTriggerHandlerMaxTime=%d", triggerMaxDuration); - scheduleMsg(logger, "maxPrecisionCallbackDuration=%d", maxPrecisionCallbackDuration); - resetMaxValues(); #endif /* EFI_PROD_CODE */ } diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 173dd29930..f96399e8cc 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -88,7 +88,6 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t timestamp, int index void initTriggerCentral(Logging *sharedLogger); int isSignalDecoderError(void); -void resetMaxValues(); void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE); bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);