From 33741dce750cb33616cbdcdb95479204c4f1b467 Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Fri, 11 Jan 2019 13:29:25 +0100 Subject: [PATCH 1/8] Add option for scheduling policy targeting constant average task rates --- src/main/fc/config.c | 4 ++++ src/main/fc/config.h | 6 ++++++ src/main/interface/cli.c | 2 +- src/main/interface/settings.c | 7 +++++++ src/main/interface/settings.h | 1 + src/main/scheduler/scheduler.c | 28 +++++++++++++++++++++++++--- src/main/scheduler/scheduler.h | 5 +++++ src/test/unit/scheduler_unittest.cc | 3 +++ 8 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 3d95fadc24..ee3d596d5c 100644 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -62,6 +62,8 @@ #include "sensors/battery.h" #include "sensors/gyro.h" +#include "scheduler/scheduler.h" + pidProfile_t *currentPidProfile; #ifndef RX_SPI_DEFAULT_PROTOCOL @@ -88,6 +90,7 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig, .boardIdentifier = TARGET_BOARD_IDENTIFIER, .hseMhz = SYSTEM_HSE_VALUE, // Not used for non-F4 targets .configured = false, + .schedulerPolicy = SCHEDULER_POLICY_PRIORITIZE_PERIOD, ); uint8_t getCurrentPidProfileIndex(void) @@ -121,6 +124,7 @@ void resetConfigs(void) static void activateConfig(void) { + schedulerSetPolicy(systemConfig()->schedulerPolicy); loadPidProfile(); loadControlRateProfile(); diff --git a/src/main/fc/config.h b/src/main/fc/config.h index 168b52c5e8..ace1eaf9fb 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -33,6 +33,11 @@ typedef struct pilotConfig_s { PG_DECLARE(pilotConfig_t, pilotConfig); +typedef enum { + SCHEDULER_POLICY_PRIORITIZE_PERIOD, + SCHEDULER_POLICY_PRIORITIZE_AVERAGE_RATE, +} schedulerPolicy_e; + typedef struct systemConfig_s { uint8_t pidProfileIndex; uint8_t activeRateProfile; @@ -44,6 +49,7 @@ typedef struct systemConfig_s { char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER) + 1]; uint8_t hseMhz; // Not used for non-F4 targets uint8_t configured; + uint8_t schedulerPolicy; } systemConfig_t; PG_DECLARE(systemConfig_t, systemConfig); diff --git a/src/main/interface/cli.c b/src/main/interface/cli.c index df78f5f3a3..da5cadf9fd 100644 --- a/src/main/interface/cli.c +++ b/src/main/interface/cli.c @@ -3766,7 +3766,7 @@ static void cliTasks(char *cmdline) int taskFrequency; int subTaskFrequency = 0; if (taskId == TASK_GYROPID) { - subTaskFrequency = taskInfo.latestDeltaTime == 0 ? 0 : (int)(1000000.0f / ((float)taskInfo.latestDeltaTime)); + subTaskFrequency = taskInfo.movingAverageCycleTime == 0.0f ? 0.0f : (int)(1000000.0f / (taskInfo.movingAverageCycleTime)); taskFrequency = subTaskFrequency / pidConfig()->pid_process_denom; if (pidConfig()->pid_process_denom > 1) { cliPrintf("%02d - (%15s) ", taskId, taskInfo.taskName); diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index faff329899..230773d2cb 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -423,6 +423,11 @@ static const char * const lookupTableTpaMode[] = { }; #endif +static const char* const lookupTableSchedulerPolicy[] = { + "PERIOD", "RATE" +}; + + #define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) } const lookupTableEntry_t lookupTables[] = { @@ -531,6 +536,7 @@ const lookupTableEntry_t lookupTables[] = { #ifdef USE_TPA_MODE LOOKUP_TABLE_ENTRY(lookupTableTpaMode), #endif + LOOKUP_TABLE_ENTRY(lookupTableSchedulerPolicy) }; #undef LOOKUP_TABLE_ENTRY @@ -1175,6 +1181,7 @@ const clivalue_t valueTable[] = { { "cpu_overclock", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OVERCLOCK }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, cpu_overclock) }, #endif { "pwr_on_arm_grace", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 30 }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, powerOnArmingGraceTime) }, + { "scheduler_policy", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_SCHEDULER_POLICY }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, schedulerPolicy) }, // PG_VTX_CONFIG #ifdef USE_VTX_COMMON diff --git a/src/main/interface/settings.h b/src/main/interface/settings.h index 801a90a937..75645c9b16 100644 --- a/src/main/interface/settings.h +++ b/src/main/interface/settings.h @@ -131,6 +131,7 @@ typedef enum { #ifdef USE_TPA_MODE TABLE_TPA_MODE, #endif + TABLE_SCHEDULER_POLICY, LOOKUP_TABLE_COUNT } lookupTableIndex_e; diff --git a/src/main/scheduler/scheduler.c b/src/main/scheduler/scheduler.c index e665eeb9e8..01cc68dd32 100644 --- a/src/main/scheduler/scheduler.c +++ b/src/main/scheduler/scheduler.c @@ -53,10 +53,12 @@ static FAST_RAM_ZERO_INIT uint32_t totalWaitingTasksSamples; static FAST_RAM_ZERO_INIT bool calculateTaskStatistics; FAST_RAM_ZERO_INIT uint16_t averageSystemLoadPercent = 0; - static FAST_RAM_ZERO_INIT int taskQueuePos = 0; STATIC_UNIT_TESTED FAST_RAM_ZERO_INIT int taskQueueSize = 0; +static FAST_RAM_ZERO_INIT schedulerPolicy_e policy; +static FAST_RAM_ZERO_INIT int periodCalculationBasisOffset = offsetof(cfTask_t, lastExecutedAt); + // No need for a linked list for the queue, since items are only inserted at startup STATIC_UNIT_TESTED FAST_RAM_ZERO_INIT cfTask_t* taskQueueArray[TASK_COUNT + 1]; // extra item for NULL pointer at end of queue @@ -164,6 +166,7 @@ void getTaskInfo(cfTaskId_e taskId, cfTaskInfo_t * taskInfo) taskInfo->totalExecutionTime = cfTasks[taskId].totalExecutionTime; taskInfo->averageExecutionTime = cfTasks[taskId].movingSumExecutionTime / MOVING_SUM_COUNT; taskInfo->latestDeltaTime = cfTasks[taskId].taskLatestDeltaTime; + taskInfo->movingAverageCycleTime = cfTasks[taskId].movingAverageCycleTime; #endif } @@ -243,6 +246,22 @@ void schedulerInit(void) queueAdd(&cfTasks[TASK_SYSTEM]); } +void schedulerSetPolicy(schedulerPolicy_e newPolicy) +{ + policy = newPolicy; + if (policy == SCHEDULER_POLICY_PRIORITIZE_AVERAGE_RATE) { + periodCalculationBasisOffset = offsetof(cfTask_t, lastDesiredAt); + } else + { + periodCalculationBasisOffset = offsetof(cfTask_t, lastExecutedAt); + } +} + +inline static timeUs_t getPeriodCalculationBasis(const cfTask_t* task) +{ + return *(timeUs_t*)((uint8_t*)task + periodCalculationBasisOffset); +} + FAST_CODE void scheduler(void) { // Cache currentTime @@ -251,7 +270,7 @@ FAST_CODE void scheduler(void) // Check for realtime tasks bool outsideRealtimeGuardInterval = true; for (const cfTask_t *task = queueFirst(); task != NULL && task->staticPriority >= TASK_PRIORITY_REALTIME; task = queueNext()) { - const timeUs_t nextExecuteAt = task->lastExecutedAt + task->desiredPeriod; + const timeUs_t nextExecuteAt = getPeriodCalculationBasis(task) + task->desiredPeriod; if ((timeDelta_t)(currentTimeUs - nextExecuteAt) >= 0) { outsideRealtimeGuardInterval = false; break; @@ -299,7 +318,7 @@ FAST_CODE void scheduler(void) } else { // Task is time-driven, dynamicPriority is last execution age (measured in desiredPeriods) // Task age is calculated from last execution - task->taskAgeCycles = ((currentTimeUs - task->lastExecutedAt) / task->desiredPeriod); + task->taskAgeCycles = ((currentTimeUs - getPeriodCalculationBasis(task)) / task->desiredPeriod); if (task->taskAgeCycles > 0) { task->dynamicPriority = 1 + task->staticPriority * task->taskAgeCycles; waitingTasks++; @@ -326,7 +345,9 @@ FAST_CODE void scheduler(void) if (selectedTask) { // Found a task that should be run selectedTask->taskLatestDeltaTime = currentTimeUs - selectedTask->lastExecutedAt; + float period = currentTimeUs - selectedTask->lastExecutedAt; selectedTask->lastExecutedAt = currentTimeUs; + selectedTask->lastDesiredAt += (cmpTimeUs(currentTimeUs,selectedTask->lastDesiredAt) / selectedTask->desiredPeriod) * selectedTask->desiredPeriod; selectedTask->dynamicPriority = 0; // Execute task @@ -338,6 +359,7 @@ FAST_CODE void scheduler(void) selectedTask->movingSumExecutionTime += taskExecutionTime - selectedTask->movingSumExecutionTime / MOVING_SUM_COUNT; selectedTask->totalExecutionTime += taskExecutionTime; // time consumed by scheduler + task selectedTask->maxExecutionTime = MAX(selectedTask->maxExecutionTime, taskExecutionTime); + selectedTask->movingAverageCycleTime += 0.05f * (period - selectedTask->movingAverageCycleTime); } else #endif { diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index c7de1b7145..3cc76640c0 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -21,6 +21,7 @@ #pragma once #include "common/time.h" +#include "fc/config.h" #define TASK_PERIOD_HZ(hz) (1000000 / (hz)) #define TASK_PERIOD_MS(ms) ((ms) * 1000) @@ -53,6 +54,7 @@ typedef struct { timeUs_t maxExecutionTime; timeUs_t totalExecutionTime; timeUs_t averageExecutionTime; + float movingAverageCycleTime; } cfTaskInfo_t; typedef enum { @@ -157,9 +159,11 @@ typedef struct { timeDelta_t taskLatestDeltaTime; timeUs_t lastExecutedAt; // last time of invocation timeUs_t lastSignaledAt; // time of invocation event for event-driven tasks + timeUs_t lastDesiredAt; // time of last desired execution #if defined(USE_TASK_STATISTICS) // Statistics + float movingAverageCycleTime; timeUs_t movingSumExecutionTime; // moving sum over 32 samples timeUs_t maxExecutionTime; timeUs_t totalExecutionTime; // total time consumed by task since boot @@ -181,6 +185,7 @@ void schedulerResetTaskMaxExecutionTime(cfTaskId_e taskId); void schedulerInit(void); void scheduler(void); void taskSystemLoad(timeUs_t currentTime); +void schedulerSetPolicy(schedulerPolicy_e policy); #define LOAD_PERCENTAGE_ONE 100 diff --git a/src/test/unit/scheduler_unittest.cc b/src/test/unit/scheduler_unittest.cc index a4a51e85e6..932b2c519e 100644 --- a/src/test/unit/scheduler_unittest.cc +++ b/src/test/unit/scheduler_unittest.cc @@ -389,6 +389,9 @@ TEST(SchedulerUnittest, TestTwoTasks) // of the two TASK_GYROPID should run first scheduler(); EXPECT_EQ(&cfTasks[TASK_GYROPID], unittest_scheduler_selectedTask); + // of the two TASK_GYROPID should run again + scheduler(); + EXPECT_EQ(&cfTasks[TASK_GYROPID], unittest_scheduler_selectedTask); // and finally TASK_ACCEL should now run scheduler(); EXPECT_EQ(&cfTasks[TASK_ACCEL], unittest_scheduler_selectedTask); From d9cd6f2cda31a90e8742d51033298eff871bf134 Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Fri, 11 Jan 2019 14:33:12 +0100 Subject: [PATCH 2/8] fix FAST_RAM_ZERO_INIT --- src/main/scheduler/scheduler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scheduler/scheduler.c b/src/main/scheduler/scheduler.c index 01cc68dd32..4167da54e2 100644 --- a/src/main/scheduler/scheduler.c +++ b/src/main/scheduler/scheduler.c @@ -57,7 +57,7 @@ static FAST_RAM_ZERO_INIT int taskQueuePos = 0; STATIC_UNIT_TESTED FAST_RAM_ZERO_INIT int taskQueueSize = 0; static FAST_RAM_ZERO_INIT schedulerPolicy_e policy; -static FAST_RAM_ZERO_INIT int periodCalculationBasisOffset = offsetof(cfTask_t, lastExecutedAt); +static FAST_RAM int periodCalculationBasisOffset = offsetof(cfTask_t, lastExecutedAt); // No need for a linked list for the queue, since items are only inserted at startup From 006749a66c1f36165926e1b2b41e5a6261cbe094 Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Fri, 11 Jan 2019 17:08:38 +0100 Subject: [PATCH 3/8] reverse unit test change --- src/test/unit/scheduler_unittest.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/unit/scheduler_unittest.cc b/src/test/unit/scheduler_unittest.cc index 932b2c519e..a4a51e85e6 100644 --- a/src/test/unit/scheduler_unittest.cc +++ b/src/test/unit/scheduler_unittest.cc @@ -389,9 +389,6 @@ TEST(SchedulerUnittest, TestTwoTasks) // of the two TASK_GYROPID should run first scheduler(); EXPECT_EQ(&cfTasks[TASK_GYROPID], unittest_scheduler_selectedTask); - // of the two TASK_GYROPID should run again - scheduler(); - EXPECT_EQ(&cfTasks[TASK_GYROPID], unittest_scheduler_selectedTask); // and finally TASK_ACCEL should now run scheduler(); EXPECT_EQ(&cfTasks[TASK_ACCEL], unittest_scheduler_selectedTask); From d90ef1224853fa919f926c9983c29c3edb3eb365 Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Sat, 12 Jan 2019 12:45:36 +0100 Subject: [PATCH 4/8] address review feedback --- src/main/interface/settings.c | 8 +------- src/main/interface/settings.h | 1 - src/main/scheduler/scheduler.c | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 230773d2cb..8ae45d9197 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -423,11 +423,6 @@ static const char * const lookupTableTpaMode[] = { }; #endif -static const char* const lookupTableSchedulerPolicy[] = { - "PERIOD", "RATE" -}; - - #define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) } const lookupTableEntry_t lookupTables[] = { @@ -536,7 +531,6 @@ const lookupTableEntry_t lookupTables[] = { #ifdef USE_TPA_MODE LOOKUP_TABLE_ENTRY(lookupTableTpaMode), #endif - LOOKUP_TABLE_ENTRY(lookupTableSchedulerPolicy) }; #undef LOOKUP_TABLE_ENTRY @@ -1181,7 +1175,7 @@ const clivalue_t valueTable[] = { { "cpu_overclock", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OVERCLOCK }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, cpu_overclock) }, #endif { "pwr_on_arm_grace", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 30 }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, powerOnArmingGraceTime) }, - { "scheduler_policy", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_SCHEDULER_POLICY }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, schedulerPolicy) }, + { "scheduler_optimize_rate", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, schedulerPolicy) }, // PG_VTX_CONFIG #ifdef USE_VTX_COMMON diff --git a/src/main/interface/settings.h b/src/main/interface/settings.h index 75645c9b16..801a90a937 100644 --- a/src/main/interface/settings.h +++ b/src/main/interface/settings.h @@ -131,7 +131,6 @@ typedef enum { #ifdef USE_TPA_MODE TABLE_TPA_MODE, #endif - TABLE_SCHEDULER_POLICY, LOOKUP_TABLE_COUNT } lookupTableIndex_e; diff --git a/src/main/scheduler/scheduler.c b/src/main/scheduler/scheduler.c index 4167da54e2..971e42f9c0 100644 --- a/src/main/scheduler/scheduler.c +++ b/src/main/scheduler/scheduler.c @@ -347,7 +347,7 @@ FAST_CODE void scheduler(void) selectedTask->taskLatestDeltaTime = currentTimeUs - selectedTask->lastExecutedAt; float period = currentTimeUs - selectedTask->lastExecutedAt; selectedTask->lastExecutedAt = currentTimeUs; - selectedTask->lastDesiredAt += (cmpTimeUs(currentTimeUs,selectedTask->lastDesiredAt) / selectedTask->desiredPeriod) * selectedTask->desiredPeriod; + selectedTask->lastDesiredAt += (cmpTimeUs(currentTimeUs, selectedTask->lastDesiredAt) / selectedTask->desiredPeriod) * selectedTask->desiredPeriod; selectedTask->dynamicPriority = 0; // Execute task From 6e46f05e7d26840f74ea0ae69e05d57aeb004613 Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Sat, 12 Jan 2019 14:45:45 +0100 Subject: [PATCH 5/8] remove smart_feedforward at 128mb to make room for scheduler_fix --- src/main/target/common_pre.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/target/common_pre.h b/src/main/target/common_pre.h index 8c39d23106..182d7037e6 100644 --- a/src/main/target/common_pre.h +++ b/src/main/target/common_pre.h @@ -231,6 +231,7 @@ #define USE_OSD_ADJUSTMENTS #define USE_SENSOR_NAMES #define USE_SERIALRX_JETIEXBUS +#define USE_SMART_FEEDFORWARD #define USE_TELEMETRY_IBUS #define USE_TELEMETRY_IBUS_EXTENDED #define USE_TELEMETRY_JETIEXBUS From d441955391253d73a9091b8ba7dbb2fe8be93443 Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Sun, 13 Jan 2019 17:12:44 +0100 Subject: [PATCH 6/8] more renaming to accomodate review feedback --- src/main/fc/config.c | 4 ++-- src/main/fc/config.h | 7 +------ src/main/interface/settings.c | 2 +- src/main/scheduler/scheduler.c | 11 ++--------- src/main/scheduler/scheduler.h | 2 +- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/main/fc/config.c b/src/main/fc/config.c index ee3d596d5c..758027b940 100644 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -90,7 +90,7 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig, .boardIdentifier = TARGET_BOARD_IDENTIFIER, .hseMhz = SYSTEM_HSE_VALUE, // Not used for non-F4 targets .configured = false, - .schedulerPolicy = SCHEDULER_POLICY_PRIORITIZE_PERIOD, + .schedulerOptimizeRate = false, ); uint8_t getCurrentPidProfileIndex(void) @@ -124,7 +124,7 @@ void resetConfigs(void) static void activateConfig(void) { - schedulerSetPolicy(systemConfig()->schedulerPolicy); + schedulerOptimizeRate(systemConfig()->schedulerOptimizeRate); loadPidProfile(); loadControlRateProfile(); diff --git a/src/main/fc/config.h b/src/main/fc/config.h index ace1eaf9fb..8413f38dd6 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -33,11 +33,6 @@ typedef struct pilotConfig_s { PG_DECLARE(pilotConfig_t, pilotConfig); -typedef enum { - SCHEDULER_POLICY_PRIORITIZE_PERIOD, - SCHEDULER_POLICY_PRIORITIZE_AVERAGE_RATE, -} schedulerPolicy_e; - typedef struct systemConfig_s { uint8_t pidProfileIndex; uint8_t activeRateProfile; @@ -49,7 +44,7 @@ typedef struct systemConfig_s { char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER) + 1]; uint8_t hseMhz; // Not used for non-F4 targets uint8_t configured; - uint8_t schedulerPolicy; + uint8_t schedulerOptimizeRate; } systemConfig_t; PG_DECLARE(systemConfig_t, systemConfig); diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 8ae45d9197..b6b8d26f2d 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -1175,7 +1175,7 @@ const clivalue_t valueTable[] = { { "cpu_overclock", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OVERCLOCK }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, cpu_overclock) }, #endif { "pwr_on_arm_grace", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 30 }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, powerOnArmingGraceTime) }, - { "scheduler_optimize_rate", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, schedulerPolicy) }, + { "scheduler_optimize_rate", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, schedulerOptimizeRate) }, // PG_VTX_CONFIG #ifdef USE_VTX_COMMON diff --git a/src/main/scheduler/scheduler.c b/src/main/scheduler/scheduler.c index 971e42f9c0..d7308b5be2 100644 --- a/src/main/scheduler/scheduler.c +++ b/src/main/scheduler/scheduler.c @@ -56,7 +56,6 @@ FAST_RAM_ZERO_INIT uint16_t averageSystemLoadPercent = 0; static FAST_RAM_ZERO_INIT int taskQueuePos = 0; STATIC_UNIT_TESTED FAST_RAM_ZERO_INIT int taskQueueSize = 0; -static FAST_RAM_ZERO_INIT schedulerPolicy_e policy; static FAST_RAM int periodCalculationBasisOffset = offsetof(cfTask_t, lastExecutedAt); // No need for a linked list for the queue, since items are only inserted at startup @@ -246,15 +245,9 @@ void schedulerInit(void) queueAdd(&cfTasks[TASK_SYSTEM]); } -void schedulerSetPolicy(schedulerPolicy_e newPolicy) +void schedulerOptimizeRate(bool optimizeRate) { - policy = newPolicy; - if (policy == SCHEDULER_POLICY_PRIORITIZE_AVERAGE_RATE) { - periodCalculationBasisOffset = offsetof(cfTask_t, lastDesiredAt); - } else - { - periodCalculationBasisOffset = offsetof(cfTask_t, lastExecutedAt); - } + periodCalculationBasisOffset = optimizeRate ? offsetof(cfTask_t, lastDesiredAt) : offsetof(cfTask_t, lastExecutedAt); } inline static timeUs_t getPeriodCalculationBasis(const cfTask_t* task) diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index 3cc76640c0..2260c903ed 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -185,7 +185,7 @@ void schedulerResetTaskMaxExecutionTime(cfTaskId_e taskId); void schedulerInit(void); void scheduler(void); void taskSystemLoad(timeUs_t currentTime); -void schedulerSetPolicy(schedulerPolicy_e policy); +void schedulerOptimizeRate(bool optimizeRate); #define LOAD_PERCENTAGE_ONE 100 From 96e33e6c181628f11e3f05f86c2c5288558c5f17 Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Mon, 14 Jan 2019 09:51:23 +0100 Subject: [PATCH 7/8] manage space of f3 targets --- src/main/target/BETAFLIGHTF3/target.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/target/BETAFLIGHTF3/target.h b/src/main/target/BETAFLIGHTF3/target.h index 78afb00f98..6f986fac98 100644 --- a/src/main/target/BETAFLIGHTF3/target.h +++ b/src/main/target/BETAFLIGHTF3/target.h @@ -36,6 +36,7 @@ #undef USE_ITERM_RELAX #undef USE_RC_SMOOTHING_FILTER +#undef USE_THRUST_LINEARIZATION #undef USE_HUFFMAN #undef USE_PINIO From a95980ef093794600f532d35d0d02783edc6da50 Mon Sep 17 00:00:00 2001 From: mikeller Date: Tue, 15 Jan 2019 22:09:29 +1300 Subject: [PATCH 8/8] Undo move of USE_SMART_FEEDFORWARD, as it's been done in #7391 already. --- src/main/target/BETAFLIGHTF3/target.h | 1 - src/main/target/common_pre.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/target/BETAFLIGHTF3/target.h b/src/main/target/BETAFLIGHTF3/target.h index 6f986fac98..78afb00f98 100644 --- a/src/main/target/BETAFLIGHTF3/target.h +++ b/src/main/target/BETAFLIGHTF3/target.h @@ -36,7 +36,6 @@ #undef USE_ITERM_RELAX #undef USE_RC_SMOOTHING_FILTER -#undef USE_THRUST_LINEARIZATION #undef USE_HUFFMAN #undef USE_PINIO diff --git a/src/main/target/common_pre.h b/src/main/target/common_pre.h index 182d7037e6..8c39d23106 100644 --- a/src/main/target/common_pre.h +++ b/src/main/target/common_pre.h @@ -231,7 +231,6 @@ #define USE_OSD_ADJUSTMENTS #define USE_SENSOR_NAMES #define USE_SERIALRX_JETIEXBUS -#define USE_SMART_FEEDFORWARD #define USE_TELEMETRY_IBUS #define USE_TELEMETRY_IBUS_EXTENDED #define USE_TELEMETRY_JETIEXBUS