mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Added CLI option to turn off task statistics
This commit is contained in:
parent
d8faab6539
commit
c1d27b5a65
6 changed files with 45 additions and 19 deletions
|
@ -137,6 +137,7 @@ typedef struct master_s {
|
|||
pidConfig_t pidConfig;
|
||||
|
||||
uint8_t debug_mode; // Processing denominator for PID controller vs gyro sampling rate
|
||||
uint8_t task_statistics;
|
||||
|
||||
gyroConfig_t gyroConfig;
|
||||
compassConfig_t compassConfig;
|
||||
|
|
|
@ -620,6 +620,7 @@ void createDefaultConfig(master_t *config)
|
|||
config->gyroConfig.gyro_soft_notch_cutoff_2 = 100;
|
||||
|
||||
config->debug_mode = DEBUG_MODE;
|
||||
config->task_statistics = true;
|
||||
|
||||
resetAccelerometerTrims(&config->accelerometerConfig.accZero);
|
||||
|
||||
|
|
|
@ -568,6 +568,6 @@ void init(void)
|
|||
motorControlEnable = true;
|
||||
|
||||
fcTasksInit();
|
||||
schedulerSetCalulateTaskStatistics(masterConfig.task_statistics);
|
||||
systemState |= SYSTEM_STATE_READY;
|
||||
}
|
||||
|
||||
|
|
|
@ -483,6 +483,9 @@ typedef struct {
|
|||
} clivalue_t;
|
||||
|
||||
const clivalue_t valueTable[] = {
|
||||
#ifndef SKIP_TASK_STATISTICS
|
||||
{ "task_statistics", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.task_statistics, .config.lookup = { TABLE_OFF_ON } },
|
||||
#endif
|
||||
{ "mid_rc", VAR_UINT16 | MASTER_VALUE, &rxConfig()->midrc, .config.minmax = { 1200, 1700 } },
|
||||
{ "min_check", VAR_UINT16 | MASTER_VALUE, &rxConfig()->mincheck, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
|
||||
{ "max_check", VAR_UINT16 | MASTER_VALUE, &rxConfig()->maxcheck, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
|
||||
|
|
|
@ -44,6 +44,7 @@ static cfTask_t *currentTask = NULL;
|
|||
static uint32_t totalWaitingTasks;
|
||||
static uint32_t totalWaitingTasksSamples;
|
||||
|
||||
static bool calculateTaskStatistics;
|
||||
uint16_t averageSystemLoadPercent = 0;
|
||||
|
||||
|
||||
|
@ -156,8 +157,11 @@ void getTaskInfo(cfTaskId_e taskId, cfTaskInfo_t * taskInfo)
|
|||
|
||||
void rescheduleTask(cfTaskId_e taskId, uint32_t newPeriodMicros)
|
||||
{
|
||||
if (taskId == TASK_SELF || taskId < TASK_COUNT) {
|
||||
cfTask_t *task = taskId == TASK_SELF ? currentTask : &cfTasks[taskId];
|
||||
if (taskId == TASK_SELF) {
|
||||
cfTask_t *task = currentTask;
|
||||
task->desiredPeriod = MAX(SCHEDULER_DELAY_LIMIT, newPeriodMicros); // Limit delay to 100us (10 kHz) to prevent scheduler clogging
|
||||
} else if (taskId < TASK_COUNT) {
|
||||
cfTask_t *task = &cfTasks[taskId];
|
||||
task->desiredPeriod = MAX(SCHEDULER_DELAY_LIMIT, newPeriodMicros); // Limit delay to 100us (10 kHz) to prevent scheduler clogging
|
||||
}
|
||||
}
|
||||
|
@ -185,6 +189,11 @@ uint32_t getTaskDeltaTime(cfTaskId_e taskId)
|
|||
}
|
||||
}
|
||||
|
||||
void schedulerSetCalulateTaskStatistics(bool calculateTaskStatisticsToUse)
|
||||
{
|
||||
calculateTaskStatistics = calculateTaskStatisticsToUse;
|
||||
}
|
||||
|
||||
void schedulerResetTaskStatistics(cfTaskId_e taskId)
|
||||
{
|
||||
#ifdef SKIP_TASK_STATISTICS
|
||||
|
@ -204,6 +213,7 @@ void schedulerResetTaskStatistics(cfTaskId_e taskId)
|
|||
|
||||
void schedulerInit(void)
|
||||
{
|
||||
calculateTaskStatistics = true;
|
||||
queueClear();
|
||||
queueAdd(&cfTasks[TASK_SYSTEM]);
|
||||
}
|
||||
|
@ -234,24 +244,28 @@ void scheduler(void)
|
|||
uint16_t waitingTasks = 0;
|
||||
for (cfTask_t *task = queueFirst(); task != NULL; task = queueNext()) {
|
||||
// Task has checkFunc - event driven
|
||||
if (task->checkFunc != NULL) {
|
||||
if (task->checkFunc) {
|
||||
#if defined(SCHEDULER_DEBUG)
|
||||
const timeUs_t currentTimeBeforeCheckFuncCall = micros();
|
||||
#else
|
||||
const timeUs_t currentTimeBeforeCheckFuncCall = currentTimeUs;
|
||||
#endif
|
||||
// Increase priority for event driven tasks
|
||||
if (task->dynamicPriority > 0) {
|
||||
task->taskAgeCycles = 1 + ((currentTimeUs - task->lastSignaledAt) / task->desiredPeriod);
|
||||
task->dynamicPriority = 1 + task->staticPriority * task->taskAgeCycles;
|
||||
waitingTasks++;
|
||||
} else if (task->checkFunc(currentTimeBeforeCheckFuncCall, currentTimeBeforeCheckFuncCall - task->lastExecutedAt)) {
|
||||
#if defined(SCHEDULER_DEBUG) || !defined(SKIP_TASK_STATISTICS)
|
||||
const uint32_t checkFuncExecutionTime = micros() - currentTimeBeforeCheckFuncCall;
|
||||
#endif
|
||||
#if defined(SCHEDULER_DEBUG)
|
||||
DEBUG_SET(DEBUG_SCHEDULER, 3, checkFuncExecutionTime);
|
||||
DEBUG_SET(DEBUG_SCHEDULER, 3, micros() - currentTimeBeforeCheckFuncCall);
|
||||
#endif
|
||||
#ifndef SKIP_TASK_STATISTICS
|
||||
checkFuncMovingSumExecutionTime += checkFuncExecutionTime - checkFuncMovingSumExecutionTime / MOVING_SUM_COUNT;
|
||||
checkFuncTotalExecutionTime += checkFuncExecutionTime; // time consumed by scheduler + task
|
||||
checkFuncMaxExecutionTime = MAX(checkFuncMaxExecutionTime, checkFuncExecutionTime);
|
||||
if (calculateTaskStatistics) {
|
||||
const uint32_t checkFuncExecutionTime = micros() - currentTimeBeforeCheckFuncCall;
|
||||
checkFuncMovingSumExecutionTime += checkFuncExecutionTime - checkFuncMovingSumExecutionTime / MOVING_SUM_COUNT;
|
||||
checkFuncTotalExecutionTime += checkFuncExecutionTime; // time consumed by scheduler + task
|
||||
checkFuncMaxExecutionTime = MAX(checkFuncMaxExecutionTime, checkFuncExecutionTime);
|
||||
}
|
||||
#endif
|
||||
task->lastSignaledAt = currentTimeBeforeCheckFuncCall;
|
||||
task->taskAgeCycles = 1;
|
||||
|
@ -287,21 +301,27 @@ void scheduler(void)
|
|||
|
||||
currentTask = selectedTask;
|
||||
|
||||
if (selectedTask != NULL) {
|
||||
if (selectedTask) {
|
||||
// Found a task that should be run
|
||||
selectedTask->taskLatestDeltaTime = currentTimeUs - selectedTask->lastExecutedAt;
|
||||
selectedTask->lastExecutedAt = currentTimeUs;
|
||||
selectedTask->dynamicPriority = 0;
|
||||
|
||||
// Execute task
|
||||
const timeUs_t currentTimeBeforeTaskCall = micros();
|
||||
selectedTask->taskFunc(currentTimeBeforeTaskCall);
|
||||
#ifdef SKIP_TASK_STATISTICS
|
||||
selectedTask->taskFunc(currentTimeUs);
|
||||
#else
|
||||
if (calculateTaskStatistics) {
|
||||
const timeUs_t currentTimeBeforeTaskCall = micros();
|
||||
selectedTask->taskFunc(currentTimeBeforeTaskCall);
|
||||
const timeUs_t taskExecutionTime = micros() - currentTimeBeforeTaskCall;
|
||||
selectedTask->movingSumExecutionTime += taskExecutionTime - selectedTask->movingSumExecutionTime / MOVING_SUM_COUNT;
|
||||
selectedTask->totalExecutionTime += taskExecutionTime; // time consumed by scheduler + task
|
||||
selectedTask->maxExecutionTime = MAX(selectedTask->maxExecutionTime, taskExecutionTime);
|
||||
} else {
|
||||
selectedTask->taskFunc(currentTimeUs);
|
||||
}
|
||||
|
||||
#ifndef SKIP_TASK_STATISTICS
|
||||
const timeUs_t taskExecutionTime = micros() - currentTimeBeforeTaskCall;
|
||||
selectedTask->movingSumExecutionTime += taskExecutionTime - selectedTask->movingSumExecutionTime / MOVING_SUM_COUNT;
|
||||
selectedTask->totalExecutionTime += taskExecutionTime; // time consumed by scheduler + task
|
||||
selectedTask->maxExecutionTime = MAX(selectedTask->maxExecutionTime, taskExecutionTime);
|
||||
#endif
|
||||
#if defined(SCHEDULER_DEBUG)
|
||||
DEBUG_SET(DEBUG_SCHEDULER, 2, micros() - currentTimeUs - taskExecutionTime); // time spent in scheduler
|
||||
|
|
|
@ -144,6 +144,7 @@ void getTaskInfo(cfTaskId_e taskId, cfTaskInfo_t *taskInfo);
|
|||
void rescheduleTask(cfTaskId_e taskId, uint32_t newPeriodMicros);
|
||||
void setTaskEnabled(cfTaskId_e taskId, bool newEnabledState);
|
||||
uint32_t getTaskDeltaTime(cfTaskId_e taskId);
|
||||
void schedulerSetCalulateTaskStatistics(bool calculateTaskStatistics);
|
||||
void schedulerResetTaskStatistics(cfTaskId_e taskId);
|
||||
|
||||
void schedulerInit(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue