mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 11:29:58 +03:00
Use cpu_late_10ths_percent_limit to set limit on % of late tasks in 10th of a % (#13330)
* Use cpu_late_10ths_percent_limit to set limit on % of late tasks in 10th of a % Set CPU load late limit to 1% based on testing * Update src/main/cli/settings.c Co-authored-by: Jan Post <Rm2k-Freak@web.de> * Update src/main/scheduler/scheduler.h Co-authored-by: Jan Post <Rm2k-Freak@web.de> * Update src/main/fc/core.c * Update src/test/unit/arming_prevention_unittest.cc * Update src/main/scheduler/scheduler.c --------- Co-authored-by: Mark Haslinghuis <mark@numloq.nl> Co-authored-by: Jan Post <Rm2k-Freak@web.de>
This commit is contained in:
parent
a190ed98dc
commit
e3e67b2ecb
9 changed files with 38 additions and 2 deletions
|
@ -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_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) },
|
{ "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) },
|
{ "serialmsp_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MSP_CONFIG, offsetof(mspConfig_t, halfDuplex) },
|
||||||
|
|
||||||
// PG_TIMECONFIG
|
// PG_TIMECONFIG
|
||||||
|
|
|
@ -323,11 +323,13 @@ void updateArmingStatus(void)
|
||||||
unsetArmingDisabled(ARMING_DISABLED_ANGLE);
|
unsetArmingDisabled(ARMING_DISABLED_ANGLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getAverageSystemLoadPercent() > LOAD_PERCENTAGE_ONE) {
|
#if defined(USE_LATE_TASK_STATISTICS)
|
||||||
|
if ((getCpuPercentageLate() > schedulerConfig()->cpuLatePercentageLimit)) {
|
||||||
setArmingDisabled(ARMING_DISABLED_LOAD);
|
setArmingDisabled(ARMING_DISABLED_LOAD);
|
||||||
} else {
|
} else {
|
||||||
unsetArmingDisabled(ARMING_DISABLED_LOAD);
|
unsetArmingDisabled(ARMING_DISABLED_LOAD);
|
||||||
}
|
}
|
||||||
|
#endif // USE_LATE_TASK_STATISTICS
|
||||||
|
|
||||||
if (isCalibrating()) {
|
if (isCalibrating()) {
|
||||||
setArmingDisabled(ARMING_DISABLED_CALIBRATING);
|
setArmingDisabled(ARMING_DISABLED_CALIBRATING);
|
||||||
|
|
|
@ -281,6 +281,7 @@ typedef enum {
|
||||||
OSD_WARNING_RSSI_DBM,
|
OSD_WARNING_RSSI_DBM,
|
||||||
OSD_WARNING_OVER_CAP,
|
OSD_WARNING_OVER_CAP,
|
||||||
OSD_WARNING_RSNR,
|
OSD_WARNING_RSNR,
|
||||||
|
OSD_WARNING_LOAD,
|
||||||
OSD_WARNING_COUNT // MUST BE LAST
|
OSD_WARNING_COUNT // MUST BE LAST
|
||||||
} osdWarningsFlags_e;
|
} osdWarningsFlags_e;
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,13 @@ void renderOsdWarning(char *warningText, bool *blinking, uint8_t *displayAttr)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (osdWarnGetState(OSD_WARNING_LOAD) && (getArmingDisableFlags() & ARMING_DISABLED_LOAD)) {
|
||||||
|
tfp_sprintf(warningText, "CPU OVERLOAD");
|
||||||
|
*displayAttr = DISPLAYPORT_SEVERITY_CRITICAL;
|
||||||
|
*blinking = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_GPS_RESCUE
|
#ifdef USE_GPS_RESCUE
|
||||||
if (osdWarnGetState(OSD_WARNING_GPS_RESCUE_UNAVAILABLE) &&
|
if (osdWarnGetState(OSD_WARNING_GPS_RESCUE_UNAVAILABLE) &&
|
||||||
ARMING_FLAG(ARMED) &&
|
ARMING_FLAG(ARMED) &&
|
||||||
|
|
|
@ -23,9 +23,10 @@
|
||||||
#include "pg/pg_ids.h"
|
#include "pg/pg_ids.h"
|
||||||
#include "pg/scheduler.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,
|
PG_RESET_TEMPLATE(schedulerConfig_t, schedulerConfig,
|
||||||
.rxRelaxDeterminism = SCHEDULER_RELAX_RX,
|
.rxRelaxDeterminism = SCHEDULER_RELAX_RX,
|
||||||
.osdRelaxDeterminism = SCHEDULER_RELAX_OSD,
|
.osdRelaxDeterminism = SCHEDULER_RELAX_OSD,
|
||||||
|
.cpuLatePercentageLimit = CPU_LOAD_LATE_LIMIT
|
||||||
);
|
);
|
||||||
|
|
|
@ -31,9 +31,13 @@
|
||||||
#define SCHEDULER_RELAX_OSD 25
|
#define SCHEDULER_RELAX_OSD 25
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Tenths of a % of tasks late
|
||||||
|
#define CPU_LOAD_LATE_LIMIT 10
|
||||||
|
|
||||||
typedef struct schedulerConfig_s {
|
typedef struct schedulerConfig_s {
|
||||||
uint16_t rxRelaxDeterminism;
|
uint16_t rxRelaxDeterminism;
|
||||||
uint16_t osdRelaxDeterminism;
|
uint16_t osdRelaxDeterminism;
|
||||||
|
uint16_t cpuLatePercentageLimit;
|
||||||
} schedulerConfig_t;
|
} schedulerConfig_t;
|
||||||
|
|
||||||
PG_DECLARE(schedulerConfig_t, schedulerConfig);
|
PG_DECLARE(schedulerConfig_t, schedulerConfig);
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
// 1 - Tasks late in last second
|
// 1 - Tasks late in last second
|
||||||
// 2 - Total lateness in last second in 10ths us
|
// 2 - Total lateness in last second in 10ths us
|
||||||
// 3 - Total tasks run in last second
|
// 3 - Total tasks run in last second
|
||||||
|
// 4 - 10ths % of tasks late in last second
|
||||||
|
|
||||||
extern task_t tasks[];
|
extern task_t tasks[];
|
||||||
|
|
||||||
|
@ -107,6 +108,7 @@ static uint8_t skippedOSDAttempts = 0;
|
||||||
static int16_t lateTaskCount = 0;
|
static int16_t lateTaskCount = 0;
|
||||||
static uint32_t lateTaskTotal = 0;
|
static uint32_t lateTaskTotal = 0;
|
||||||
static int16_t taskCount = 0;
|
static int16_t taskCount = 0;
|
||||||
|
static uint32_t lateTaskPercentage = 0;
|
||||||
static uint32_t nextTimingCycles;
|
static uint32_t nextTimingCycles;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -199,6 +201,15 @@ void taskSystemLoad(timeUs_t currentTimeUs)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getCpuPercentageLate(void)
|
||||||
|
{
|
||||||
|
#if defined(USE_LATE_TASK_STATISTICS)
|
||||||
|
return lateTaskPercentage;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
timeUs_t checkFuncMaxExecutionTimeUs;
|
timeUs_t checkFuncMaxExecutionTimeUs;
|
||||||
timeUs_t checkFuncTotalExecutionTimeUs;
|
timeUs_t checkFuncTotalExecutionTimeUs;
|
||||||
timeUs_t checkFuncMovingSumExecutionTimeUs;
|
timeUs_t checkFuncMovingSumExecutionTimeUs;
|
||||||
|
@ -535,6 +546,10 @@ FAST_CODE void scheduler(void)
|
||||||
// Total tasks run in last second
|
// Total tasks run in last second
|
||||||
DEBUG_SET(DEBUG_TIMING_ACCURACY, 3, taskCount);
|
DEBUG_SET(DEBUG_TIMING_ACCURACY, 3, taskCount);
|
||||||
|
|
||||||
|
lateTaskPercentage = 1000 * (uint32_t)lateTaskCount / taskCount;
|
||||||
|
// 10ths % of tasks late in last second
|
||||||
|
DEBUG_SET(DEBUG_TIMING_ACCURACY, 4, lateTaskPercentage);
|
||||||
|
|
||||||
lateTaskCount = 0;
|
lateTaskCount = 0;
|
||||||
lateTaskTotal = 0;
|
lateTaskTotal = 0;
|
||||||
taskCount = 0;
|
taskCount = 0;
|
||||||
|
|
|
@ -243,6 +243,7 @@ void schedulerInit(void);
|
||||||
void scheduler(void);
|
void scheduler(void);
|
||||||
timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTimeUs);
|
timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTimeUs);
|
||||||
void taskSystemLoad(timeUs_t currentTimeUs);
|
void taskSystemLoad(timeUs_t currentTimeUs);
|
||||||
|
uint32_t getCpuPercentageLate(void);
|
||||||
void schedulerEnableGyro(void);
|
void schedulerEnableGyro(void);
|
||||||
uint16_t getAverageSystemLoadPercent(void);
|
uint16_t getAverageSystemLoadPercent(void);
|
||||||
float schedulerGetCycleTimeMultiplier(void);
|
float schedulerGetCycleTimeMultiplier(void);
|
||||||
|
|
|
@ -1161,4 +1161,5 @@ extern "C" {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
void getRcDeflectionAbs(void) {}
|
void getRcDeflectionAbs(void) {}
|
||||||
|
uint32_t getCpuPercentageLate(void) { return 0; };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue