1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

Use averageDeltaTime when calculating CPU load

This commit is contained in:
SteveCEvans 2019-01-23 19:50:33 +00:00
parent a4ce8b5600
commit faf33d1130
3 changed files with 11 additions and 1 deletions

View file

@ -3775,7 +3775,7 @@ static void cliTasks(char *cmdline)
cliPrintf("%02d - (%11s/%3s) ", taskId, taskInfo.subTaskName, taskInfo.taskName); cliPrintf("%02d - (%11s/%3s) ", taskId, taskInfo.subTaskName, taskInfo.taskName);
} }
} else { } else {
taskFrequency = taskInfo.latestDeltaTime == 0 ? 0 : (int)(1000000.0f / ((float)taskInfo.latestDeltaTime)); taskFrequency = taskInfo.averageDeltaTime == 0 ? 0 : (int)(1000000.0f / ((float)taskInfo.averageDeltaTime));
cliPrintf("%02d - (%15s) ", taskId, taskInfo.taskName); cliPrintf("%02d - (%15s) ", taskId, taskInfo.taskName);
} }
const int maxLoad = taskInfo.maxExecutionTime == 0 ? 0 :(taskInfo.maxExecutionTime * taskFrequency + 5000) / 1000; const int maxLoad = taskInfo.maxExecutionTime == 0 ? 0 :(taskInfo.maxExecutionTime * taskFrequency + 5000) / 1000;

View file

@ -144,12 +144,14 @@ void taskSystemLoad(timeUs_t currentTimeUs)
timeUs_t checkFuncMaxExecutionTime; timeUs_t checkFuncMaxExecutionTime;
timeUs_t checkFuncTotalExecutionTime; timeUs_t checkFuncTotalExecutionTime;
timeUs_t checkFuncMovingSumExecutionTime; timeUs_t checkFuncMovingSumExecutionTime;
timeUs_t checkFuncMovingSumDeltaTime;
void getCheckFuncInfo(cfCheckFuncInfo_t *checkFuncInfo) void getCheckFuncInfo(cfCheckFuncInfo_t *checkFuncInfo)
{ {
checkFuncInfo->maxExecutionTime = checkFuncMaxExecutionTime; checkFuncInfo->maxExecutionTime = checkFuncMaxExecutionTime;
checkFuncInfo->totalExecutionTime = checkFuncTotalExecutionTime; checkFuncInfo->totalExecutionTime = checkFuncTotalExecutionTime;
checkFuncInfo->averageExecutionTime = checkFuncMovingSumExecutionTime / MOVING_SUM_COUNT; checkFuncInfo->averageExecutionTime = checkFuncMovingSumExecutionTime / MOVING_SUM_COUNT;
checkFuncInfo->averageDeltaTime = checkFuncMovingSumDeltaTime / MOVING_SUM_COUNT;
} }
#endif #endif
@ -164,6 +166,7 @@ void getTaskInfo(cfTaskId_e taskId, cfTaskInfo_t * taskInfo)
taskInfo->maxExecutionTime = cfTasks[taskId].maxExecutionTime; taskInfo->maxExecutionTime = cfTasks[taskId].maxExecutionTime;
taskInfo->totalExecutionTime = cfTasks[taskId].totalExecutionTime; taskInfo->totalExecutionTime = cfTasks[taskId].totalExecutionTime;
taskInfo->averageExecutionTime = cfTasks[taskId].movingSumExecutionTime / MOVING_SUM_COUNT; taskInfo->averageExecutionTime = cfTasks[taskId].movingSumExecutionTime / MOVING_SUM_COUNT;
taskInfo->averageDeltaTime = cfTasks[taskId].movingSumDeltaTime / MOVING_SUM_COUNT;
taskInfo->latestDeltaTime = cfTasks[taskId].taskLatestDeltaTime; taskInfo->latestDeltaTime = cfTasks[taskId].taskLatestDeltaTime;
taskInfo->movingAverageCycleTime = cfTasks[taskId].movingAverageCycleTime; taskInfo->movingAverageCycleTime = cfTasks[taskId].movingAverageCycleTime;
#endif #endif
@ -213,10 +216,12 @@ void schedulerResetTaskStatistics(cfTaskId_e taskId)
#if defined(USE_TASK_STATISTICS) #if defined(USE_TASK_STATISTICS)
if (taskId == TASK_SELF) { if (taskId == TASK_SELF) {
currentTask->movingSumExecutionTime = 0; currentTask->movingSumExecutionTime = 0;
currentTask->movingSumDeltaTime = 0;
currentTask->totalExecutionTime = 0; currentTask->totalExecutionTime = 0;
currentTask->maxExecutionTime = 0; currentTask->maxExecutionTime = 0;
} else if (taskId < TASK_COUNT) { } else if (taskId < TASK_COUNT) {
cfTasks[taskId].movingSumExecutionTime = 0; cfTasks[taskId].movingSumExecutionTime = 0;
cfTasks[taskId].movingSumDeltaTime = 0;
cfTasks[taskId].totalExecutionTime = 0; cfTasks[taskId].totalExecutionTime = 0;
cfTasks[taskId].maxExecutionTime = 0; cfTasks[taskId].maxExecutionTime = 0;
} }
@ -297,6 +302,7 @@ FAST_CODE void scheduler(void)
if (calculateTaskStatistics) { if (calculateTaskStatistics) {
const uint32_t checkFuncExecutionTime = micros() - currentTimeBeforeCheckFuncCall; const uint32_t checkFuncExecutionTime = micros() - currentTimeBeforeCheckFuncCall;
checkFuncMovingSumExecutionTime += checkFuncExecutionTime - checkFuncMovingSumExecutionTime / MOVING_SUM_COUNT; checkFuncMovingSumExecutionTime += checkFuncExecutionTime - checkFuncMovingSumExecutionTime / MOVING_SUM_COUNT;
checkFuncMovingSumDeltaTime += task->taskLatestDeltaTime - checkFuncMovingSumDeltaTime / MOVING_SUM_COUNT;
checkFuncTotalExecutionTime += checkFuncExecutionTime; // time consumed by scheduler + task checkFuncTotalExecutionTime += checkFuncExecutionTime; // time consumed by scheduler + task
checkFuncMaxExecutionTime = MAX(checkFuncMaxExecutionTime, checkFuncExecutionTime); checkFuncMaxExecutionTime = MAX(checkFuncMaxExecutionTime, checkFuncExecutionTime);
} }
@ -350,6 +356,7 @@ FAST_CODE void scheduler(void)
selectedTask->taskFunc(currentTimeBeforeTaskCall); selectedTask->taskFunc(currentTimeBeforeTaskCall);
const timeUs_t taskExecutionTime = micros() - currentTimeBeforeTaskCall; const timeUs_t taskExecutionTime = micros() - currentTimeBeforeTaskCall;
selectedTask->movingSumExecutionTime += taskExecutionTime - selectedTask->movingSumExecutionTime / MOVING_SUM_COUNT; selectedTask->movingSumExecutionTime += taskExecutionTime - selectedTask->movingSumExecutionTime / MOVING_SUM_COUNT;
selectedTask->movingSumDeltaTime += selectedTask->taskLatestDeltaTime - selectedTask->movingSumDeltaTime / MOVING_SUM_COUNT;
selectedTask->totalExecutionTime += taskExecutionTime; // time consumed by scheduler + task selectedTask->totalExecutionTime += taskExecutionTime; // time consumed by scheduler + task
selectedTask->maxExecutionTime = MAX(selectedTask->maxExecutionTime, taskExecutionTime); selectedTask->maxExecutionTime = MAX(selectedTask->maxExecutionTime, taskExecutionTime);
selectedTask->movingAverageCycleTime += 0.05f * (period - selectedTask->movingAverageCycleTime); selectedTask->movingAverageCycleTime += 0.05f * (period - selectedTask->movingAverageCycleTime);

View file

@ -42,6 +42,7 @@ typedef struct {
timeUs_t maxExecutionTime; timeUs_t maxExecutionTime;
timeUs_t totalExecutionTime; timeUs_t totalExecutionTime;
timeUs_t averageExecutionTime; timeUs_t averageExecutionTime;
timeUs_t averageDeltaTime;
} cfCheckFuncInfo_t; } cfCheckFuncInfo_t;
typedef struct { typedef struct {
@ -54,6 +55,7 @@ typedef struct {
timeUs_t maxExecutionTime; timeUs_t maxExecutionTime;
timeUs_t totalExecutionTime; timeUs_t totalExecutionTime;
timeUs_t averageExecutionTime; timeUs_t averageExecutionTime;
timeUs_t averageDeltaTime;
float movingAverageCycleTime; float movingAverageCycleTime;
} cfTaskInfo_t; } cfTaskInfo_t;
@ -165,6 +167,7 @@ typedef struct {
// Statistics // Statistics
float movingAverageCycleTime; float movingAverageCycleTime;
timeUs_t movingSumExecutionTime; // moving sum over 32 samples timeUs_t movingSumExecutionTime; // moving sum over 32 samples
timeUs_t movingSumDeltaTime; // moving sum over 32 samples
timeUs_t maxExecutionTime; timeUs_t maxExecutionTime;
timeUs_t totalExecutionTime; // total time consumed by task since boot timeUs_t totalExecutionTime; // total time consumed by task since boot
#endif #endif