Report task rate/Hz based on execution of whole state machine, not individual states where appropriate
This commit is contained in:
parent
07c32e7302
commit
3087d10f53
|
@ -170,18 +170,20 @@ bool taskUpdateRxMainInProgress()
|
|||
|
||||
static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
||||
{
|
||||
// Where we are using a state machine call ignoreTaskTime() for all states bar one
|
||||
if (rxState != MODES) {
|
||||
ignoreTaskTime();
|
||||
}
|
||||
|
||||
switch (rxState) {
|
||||
default:
|
||||
case CHECK:
|
||||
ignoreTaskTime();
|
||||
rxState = PROCESS;
|
||||
break;
|
||||
|
||||
case PROCESS:
|
||||
ignoreTaskTime();
|
||||
if (!processRx(currentTimeUs)) {
|
||||
rxState = CHECK;
|
||||
|
||||
break;
|
||||
}
|
||||
rxState = MODES;
|
||||
|
@ -193,7 +195,6 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
|||
break;
|
||||
|
||||
case UPDATE:
|
||||
ignoreTaskTime();
|
||||
// updateRcCommands sets rcCommand, which is needed by updateAltHoldState and updateSonarAltHoldState
|
||||
updateRcCommands();
|
||||
updateArmingStatus();
|
||||
|
|
|
@ -299,7 +299,6 @@ FAST_CODE timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTi
|
|||
if (selectedTask) {
|
||||
currentTask = selectedTask;
|
||||
ignoreCurrentTaskTime = false;
|
||||
selectedTask->taskLatestDeltaTimeUs = cmpTimeUs(currentTimeUs, selectedTask->lastExecutedAtUs);
|
||||
#if defined(USE_TASK_STATISTICS)
|
||||
float period = currentTimeUs - selectedTask->lastExecutedAtUs;
|
||||
#endif
|
||||
|
@ -314,6 +313,8 @@ FAST_CODE timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTi
|
|||
selectedTask->taskFunc(currentTimeBeforeTaskCallUs);
|
||||
taskExecutionTimeUs = micros() - currentTimeBeforeTaskCallUs;
|
||||
if (!ignoreCurrentTaskTime) {
|
||||
selectedTask->taskLatestDeltaTimeUs = cmpTimeUs(currentTimeUs, selectedTask->lastStatsAtUs);
|
||||
selectedTask->lastStatsAtUs = currentTimeUs;
|
||||
selectedTask->movingSumExecutionTimeUs += taskExecutionTimeUs - selectedTask->movingSumExecutionTimeUs / TASK_STATS_MOVING_SUM_COUNT;
|
||||
selectedTask->movingSumDeltaTimeUs += selectedTask->taskLatestDeltaTimeUs - selectedTask->movingSumDeltaTimeUs / TASK_STATS_MOVING_SUM_COUNT;
|
||||
selectedTask->maxExecutionTimeUs = MAX(selectedTask->maxExecutionTimeUs, taskExecutionTimeUs);
|
||||
|
@ -326,6 +327,7 @@ FAST_CODE timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTi
|
|||
} else
|
||||
#endif
|
||||
{
|
||||
selectedTask->taskLatestDeltaTimeUs = cmpTimeUs(currentTimeUs, selectedTask->lastExecutedAtUs);
|
||||
selectedTask->taskFunc(currentTimeUs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,24 +170,25 @@ typedef struct {
|
|||
#endif
|
||||
bool (*checkFunc)(timeUs_t currentTimeUs, timeDelta_t currentDeltaTimeUs);
|
||||
void (*taskFunc)(timeUs_t currentTimeUs);
|
||||
timeDelta_t desiredPeriodUs; // target period of execution
|
||||
const int8_t staticPriority; // dynamicPriority grows in steps of this size
|
||||
timeDelta_t desiredPeriodUs; // target period of execution
|
||||
const int8_t staticPriority; // dynamicPriority grows in steps of this size
|
||||
|
||||
// Scheduling
|
||||
uint16_t dynamicPriority; // measurement of how old task was last executed, used to avoid task starvation
|
||||
uint16_t dynamicPriority; // measurement of how old task was last executed, used to avoid task starvation
|
||||
uint16_t taskAgeCycles;
|
||||
timeDelta_t taskLatestDeltaTimeUs;
|
||||
timeUs_t lastExecutedAtUs; // last time of invocation
|
||||
timeUs_t lastSignaledAtUs; // time of invocation event for event-driven tasks
|
||||
timeUs_t lastDesiredAt; // time of last desired execution
|
||||
timeUs_t lastExecutedAtUs; // last time of invocation
|
||||
timeUs_t lastSignaledAtUs; // time of invocation event for event-driven tasks
|
||||
timeUs_t lastDesiredAt; // time of last desired execution
|
||||
|
||||
#if defined(USE_TASK_STATISTICS)
|
||||
// Statistics
|
||||
float movingAverageCycleTimeUs;
|
||||
timeUs_t movingSumExecutionTimeUs; // moving sum over 32 samples
|
||||
timeUs_t movingSumDeltaTimeUs; // moving sum over 32 samples
|
||||
timeUs_t movingSumDeltaTimeUs; // moving sum over 32 samples
|
||||
timeUs_t maxExecutionTimeUs;
|
||||
timeUs_t totalExecutionTimeUs; // total time consumed by task since boot
|
||||
timeUs_t totalExecutionTimeUs; // total time consumed by task since boot
|
||||
timeUs_t lastStatsAtUs; // time of last stats gathering for rate calculation
|
||||
#if defined(USE_LATE_TASK_STATISTICS)
|
||||
uint32_t runCount;
|
||||
uint32_t lateCount;
|
||||
|
|
|
@ -353,6 +353,7 @@ TEST(SchedulerUnittest, TestSingleTask)
|
|||
}
|
||||
setTaskEnabled(TASK_ACCEL, true);
|
||||
tasks[TASK_ACCEL].lastExecutedAtUs = 1000;
|
||||
tasks[TASK_ACCEL].lastStatsAtUs = 1000;
|
||||
simulatedTime = 2050;
|
||||
// run the scheduler and check the task has executed
|
||||
scheduler();
|
||||
|
|
Loading…
Reference in New Issue