Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cpu_late_10ths_percent_limit to set limit on % of late tasks in 10th of a % #13330

Merged
merged 6 commits into from Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/cli/settings.c
Expand Up @@ -1720,6 +1720,10 @@ const clivalue_t valueTable[] = {
{ "scheduler_relax_rx", VAR_UINT16 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, 500 }, PG_SCHEDULER_CONFIG, PG_ARRAY_ELEMENT_OFFSET(schedulerConfig_t, 0, rxRelaxDeterminism) },
{ "scheduler_relax_osd", VAR_UINT16 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, 500 }, PG_SCHEDULER_CONFIG, PG_ARRAY_ELEMENT_OFFSET(schedulerConfig_t, 0, osdRelaxDeterminism) },

#ifdef USE_LATE_TASK_STATISTICS
{ "cpu_late_limit_permille", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_SCHEDULER_CONFIG, offsetof(schedulerConfig_t, cpuLatePercentageLimit) },
#endif

{ "serialmsp_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MSP_CONFIG, offsetof(mspConfig_t, halfDuplex) },

// PG_TIMECONFIG
Expand Down
4 changes: 3 additions & 1 deletion src/main/fc/core.c
Expand Up @@ -323,11 +323,13 @@ void updateArmingStatus(void)
unsetArmingDisabled(ARMING_DISABLED_ANGLE);
}

if (getAverageSystemLoadPercent() > LOAD_PERCENTAGE_ONE) {
#if defined(USE_LATE_TASK_STATISTICS)
if ((getCpuPercentageLate() > schedulerConfig()->cpuLatePercentageLimit)) {
setArmingDisabled(ARMING_DISABLED_LOAD);
} else {
unsetArmingDisabled(ARMING_DISABLED_LOAD);
}
#endif // USE_LATE_TASK_STATISTICS

if (isCalibrating()) {
setArmingDisabled(ARMING_DISABLED_CALIBRATING);
Expand Down
1 change: 1 addition & 0 deletions src/main/osd/osd.h
Expand Up @@ -281,6 +281,7 @@ typedef enum {
OSD_WARNING_RSSI_DBM,
OSD_WARNING_OVER_CAP,
OSD_WARNING_RSNR,
OSD_WARNING_LOAD,
OSD_WARNING_COUNT // MUST BE LAST
} osdWarningsFlags_e;

Expand Down
7 changes: 7 additions & 0 deletions src/main/osd/osd_warnings.c
Expand Up @@ -213,6 +213,13 @@ void renderOsdWarning(char *warningText, bool *blinking, uint8_t *displayAttr)
return;
}

if (osdWarnGetState(OSD_WARNING_LOAD) && (getArmingDisableFlags() & ARMING_DISABLED_LOAD)) {
tfp_sprintf(warningText, "CPU OVERLOAD");
*displayAttr = DISPLAYPORT_SEVERITY_CRITICAL;
*blinking = true;
return;
}
haslinghuis marked this conversation as resolved.
Show resolved Hide resolved

#ifdef USE_GPS_RESCUE
if (osdWarnGetState(OSD_WARNING_GPS_RESCUE_UNAVAILABLE) &&
ARMING_FLAG(ARMED) &&
Expand Down
3 changes: 2 additions & 1 deletion src/main/pg/scheduler.c
Expand Up @@ -23,9 +23,10 @@
#include "pg/pg_ids.h"
#include "pg/scheduler.h"

PG_REGISTER_WITH_RESET_TEMPLATE(schedulerConfig_t, schedulerConfig, PG_SCHEDULER_CONFIG, 0);
PG_REGISTER_WITH_RESET_TEMPLATE(schedulerConfig_t, schedulerConfig, PG_SCHEDULER_CONFIG, 1);

PG_RESET_TEMPLATE(schedulerConfig_t, schedulerConfig,
.rxRelaxDeterminism = SCHEDULER_RELAX_RX,
.osdRelaxDeterminism = SCHEDULER_RELAX_OSD,
.cpuLatePercentageLimit = CPU_LOAD_LATE_LIMIT
);
4 changes: 4 additions & 0 deletions src/main/pg/scheduler.h
Expand Up @@ -31,9 +31,13 @@
#define SCHEDULER_RELAX_OSD 25
#endif

// Tenths of a % of tasks late
#define CPU_LOAD_LATE_LIMIT 10

typedef struct schedulerConfig_s {
uint16_t rxRelaxDeterminism;
uint16_t osdRelaxDeterminism;
uint16_t cpuLatePercentageLimit;
} schedulerConfig_t;
SteveCEvans marked this conversation as resolved.
Show resolved Hide resolved

PG_DECLARE(schedulerConfig_t, schedulerConfig);
Expand Down
15 changes: 15 additions & 0 deletions src/main/scheduler/scheduler.c
Expand Up @@ -69,6 +69,7 @@
// 1 - Tasks late in last second
// 2 - Total lateness in last second in 10ths us
// 3 - Total tasks run in last second
// 4 - 10ths % of tasks late in last second

extern task_t tasks[];

Expand Down Expand Up @@ -107,6 +108,7 @@ static uint8_t skippedOSDAttempts = 0;
static int16_t lateTaskCount = 0;
static uint32_t lateTaskTotal = 0;
static int16_t taskCount = 0;
static uint32_t lateTaskPercentage = 0;
static uint32_t nextTimingCycles;
#endif

Expand Down Expand Up @@ -199,6 +201,15 @@ void taskSystemLoad(timeUs_t currentTimeUs)
#endif
}

uint32_t getCpuPercentageLate(void)
{
#if defined(USE_LATE_TASK_STATISTICS)
return lateTaskPercentage;
#else
return 0;
#endif
}

timeUs_t checkFuncMaxExecutionTimeUs;
timeUs_t checkFuncTotalExecutionTimeUs;
timeUs_t checkFuncMovingSumExecutionTimeUs;
Expand Down Expand Up @@ -535,6 +546,10 @@ FAST_CODE void scheduler(void)
// Total tasks run in last second
DEBUG_SET(DEBUG_TIMING_ACCURACY, 3, taskCount);

lateTaskPercentage = 1000 * (uint32_t)lateTaskCount / taskCount;
haslinghuis marked this conversation as resolved.
Show resolved Hide resolved
// 10ths % of tasks late in last second
DEBUG_SET(DEBUG_TIMING_ACCURACY, 4, lateTaskPercentage);

lateTaskCount = 0;
lateTaskTotal = 0;
taskCount = 0;
Expand Down
1 change: 1 addition & 0 deletions src/main/scheduler/scheduler.h
Expand Up @@ -243,6 +243,7 @@ void schedulerInit(void);
void scheduler(void);
timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTimeUs);
void taskSystemLoad(timeUs_t currentTimeUs);
uint32_t getCpuPercentageLate(void);
void schedulerEnableGyro(void);
uint16_t getAverageSystemLoadPercent(void);
float schedulerGetCycleTimeMultiplier(void);
1 change: 1 addition & 0 deletions src/test/unit/arming_prevention_unittest.cc
Expand Up @@ -1161,4 +1161,5 @@ extern "C" {
return 0.0f;
}
void getRcDeflectionAbs(void) {}
uint32_t getCpuPercentageLate(void) { return 0; };
}