Added CLI option to turn off task statistics
This commit is contained in:
parent
d8faab6539
commit
c1d27b5a65
|
@ -137,6 +137,7 @@ typedef struct master_s {
|
||||||
pidConfig_t pidConfig;
|
pidConfig_t pidConfig;
|
||||||
|
|
||||||
uint8_t debug_mode; // Processing denominator for PID controller vs gyro sampling rate
|
uint8_t debug_mode; // Processing denominator for PID controller vs gyro sampling rate
|
||||||
|
uint8_t task_statistics;
|
||||||
|
|
||||||
gyroConfig_t gyroConfig;
|
gyroConfig_t gyroConfig;
|
||||||
compassConfig_t compassConfig;
|
compassConfig_t compassConfig;
|
||||||
|
|
|
@ -620,6 +620,7 @@ void createDefaultConfig(master_t *config)
|
||||||
config->gyroConfig.gyro_soft_notch_cutoff_2 = 100;
|
config->gyroConfig.gyro_soft_notch_cutoff_2 = 100;
|
||||||
|
|
||||||
config->debug_mode = DEBUG_MODE;
|
config->debug_mode = DEBUG_MODE;
|
||||||
|
config->task_statistics = true;
|
||||||
|
|
||||||
resetAccelerometerTrims(&config->accelerometerConfig.accZero);
|
resetAccelerometerTrims(&config->accelerometerConfig.accZero);
|
||||||
|
|
||||||
|
|
|
@ -568,6 +568,6 @@ void init(void)
|
||||||
motorControlEnable = true;
|
motorControlEnable = true;
|
||||||
|
|
||||||
fcTasksInit();
|
fcTasksInit();
|
||||||
|
schedulerSetCalulateTaskStatistics(masterConfig.task_statistics);
|
||||||
systemState |= SYSTEM_STATE_READY;
|
systemState |= SYSTEM_STATE_READY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -483,6 +483,9 @@ typedef struct {
|
||||||
} clivalue_t;
|
} clivalue_t;
|
||||||
|
|
||||||
const clivalue_t valueTable[] = {
|
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 } },
|
{ "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 } },
|
{ "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 } },
|
{ "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 totalWaitingTasks;
|
||||||
static uint32_t totalWaitingTasksSamples;
|
static uint32_t totalWaitingTasksSamples;
|
||||||
|
|
||||||
|
static bool calculateTaskStatistics;
|
||||||
uint16_t averageSystemLoadPercent = 0;
|
uint16_t averageSystemLoadPercent = 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,8 +157,11 @@ void getTaskInfo(cfTaskId_e taskId, cfTaskInfo_t * taskInfo)
|
||||||
|
|
||||||
void rescheduleTask(cfTaskId_e taskId, uint32_t newPeriodMicros)
|
void rescheduleTask(cfTaskId_e taskId, uint32_t newPeriodMicros)
|
||||||
{
|
{
|
||||||
if (taskId == TASK_SELF || taskId < TASK_COUNT) {
|
if (taskId == TASK_SELF) {
|
||||||
cfTask_t *task = taskId == TASK_SELF ? currentTask : &cfTasks[taskId];
|
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
|
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)
|
void schedulerResetTaskStatistics(cfTaskId_e taskId)
|
||||||
{
|
{
|
||||||
#ifdef SKIP_TASK_STATISTICS
|
#ifdef SKIP_TASK_STATISTICS
|
||||||
|
@ -204,6 +213,7 @@ void schedulerResetTaskStatistics(cfTaskId_e taskId)
|
||||||
|
|
||||||
void schedulerInit(void)
|
void schedulerInit(void)
|
||||||
{
|
{
|
||||||
|
calculateTaskStatistics = true;
|
||||||
queueClear();
|
queueClear();
|
||||||
queueAdd(&cfTasks[TASK_SYSTEM]);
|
queueAdd(&cfTasks[TASK_SYSTEM]);
|
||||||
}
|
}
|
||||||
|
@ -234,24 +244,28 @@ void scheduler(void)
|
||||||
uint16_t waitingTasks = 0;
|
uint16_t waitingTasks = 0;
|
||||||
for (cfTask_t *task = queueFirst(); task != NULL; task = queueNext()) {
|
for (cfTask_t *task = queueFirst(); task != NULL; task = queueNext()) {
|
||||||
// Task has checkFunc - event driven
|
// Task has checkFunc - event driven
|
||||||
if (task->checkFunc != NULL) {
|
if (task->checkFunc) {
|
||||||
|
#if defined(SCHEDULER_DEBUG)
|
||||||
const timeUs_t currentTimeBeforeCheckFuncCall = micros();
|
const timeUs_t currentTimeBeforeCheckFuncCall = micros();
|
||||||
|
#else
|
||||||
|
const timeUs_t currentTimeBeforeCheckFuncCall = currentTimeUs;
|
||||||
|
#endif
|
||||||
// Increase priority for event driven tasks
|
// Increase priority for event driven tasks
|
||||||
if (task->dynamicPriority > 0) {
|
if (task->dynamicPriority > 0) {
|
||||||
task->taskAgeCycles = 1 + ((currentTimeUs - task->lastSignaledAt) / task->desiredPeriod);
|
task->taskAgeCycles = 1 + ((currentTimeUs - task->lastSignaledAt) / task->desiredPeriod);
|
||||||
task->dynamicPriority = 1 + task->staticPriority * task->taskAgeCycles;
|
task->dynamicPriority = 1 + task->staticPriority * task->taskAgeCycles;
|
||||||
waitingTasks++;
|
waitingTasks++;
|
||||||
} else if (task->checkFunc(currentTimeBeforeCheckFuncCall, currentTimeBeforeCheckFuncCall - task->lastExecutedAt)) {
|
} 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)
|
#if defined(SCHEDULER_DEBUG)
|
||||||
DEBUG_SET(DEBUG_SCHEDULER, 3, checkFuncExecutionTime);
|
DEBUG_SET(DEBUG_SCHEDULER, 3, micros() - currentTimeBeforeCheckFuncCall);
|
||||||
#endif
|
#endif
|
||||||
#ifndef SKIP_TASK_STATISTICS
|
#ifndef SKIP_TASK_STATISTICS
|
||||||
checkFuncMovingSumExecutionTime += checkFuncExecutionTime - checkFuncMovingSumExecutionTime / MOVING_SUM_COUNT;
|
if (calculateTaskStatistics) {
|
||||||
checkFuncTotalExecutionTime += checkFuncExecutionTime; // time consumed by scheduler + task
|
const uint32_t checkFuncExecutionTime = micros() - currentTimeBeforeCheckFuncCall;
|
||||||
checkFuncMaxExecutionTime = MAX(checkFuncMaxExecutionTime, checkFuncExecutionTime);
|
checkFuncMovingSumExecutionTime += checkFuncExecutionTime - checkFuncMovingSumExecutionTime / MOVING_SUM_COUNT;
|
||||||
|
checkFuncTotalExecutionTime += checkFuncExecutionTime; // time consumed by scheduler + task
|
||||||
|
checkFuncMaxExecutionTime = MAX(checkFuncMaxExecutionTime, checkFuncExecutionTime);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
task->lastSignaledAt = currentTimeBeforeCheckFuncCall;
|
task->lastSignaledAt = currentTimeBeforeCheckFuncCall;
|
||||||
task->taskAgeCycles = 1;
|
task->taskAgeCycles = 1;
|
||||||
|
@ -287,21 +301,27 @@ void scheduler(void)
|
||||||
|
|
||||||
currentTask = selectedTask;
|
currentTask = selectedTask;
|
||||||
|
|
||||||
if (selectedTask != NULL) {
|
if (selectedTask) {
|
||||||
// Found a task that should be run
|
// Found a task that should be run
|
||||||
selectedTask->taskLatestDeltaTime = currentTimeUs - selectedTask->lastExecutedAt;
|
selectedTask->taskLatestDeltaTime = currentTimeUs - selectedTask->lastExecutedAt;
|
||||||
selectedTask->lastExecutedAt = currentTimeUs;
|
selectedTask->lastExecutedAt = currentTimeUs;
|
||||||
selectedTask->dynamicPriority = 0;
|
selectedTask->dynamicPriority = 0;
|
||||||
|
|
||||||
// Execute task
|
// Execute task
|
||||||
const timeUs_t currentTimeBeforeTaskCall = micros();
|
#ifdef SKIP_TASK_STATISTICS
|
||||||
selectedTask->taskFunc(currentTimeBeforeTaskCall);
|
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
|
#endif
|
||||||
#if defined(SCHEDULER_DEBUG)
|
#if defined(SCHEDULER_DEBUG)
|
||||||
DEBUG_SET(DEBUG_SCHEDULER, 2, micros() - currentTimeUs - taskExecutionTime); // time spent in scheduler
|
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 rescheduleTask(cfTaskId_e taskId, uint32_t newPeriodMicros);
|
||||||
void setTaskEnabled(cfTaskId_e taskId, bool newEnabledState);
|
void setTaskEnabled(cfTaskId_e taskId, bool newEnabledState);
|
||||||
uint32_t getTaskDeltaTime(cfTaskId_e taskId);
|
uint32_t getTaskDeltaTime(cfTaskId_e taskId);
|
||||||
|
void schedulerSetCalulateTaskStatistics(bool calculateTaskStatistics);
|
||||||
void schedulerResetTaskStatistics(cfTaskId_e taskId);
|
void schedulerResetTaskStatistics(cfTaskId_e taskId);
|
||||||
|
|
||||||
void schedulerInit(void);
|
void schedulerInit(void);
|
||||||
|
|
Loading…
Reference in New Issue