From 62cb1fba1ab1fb159b81ee16dbf1ed4acc52e245 Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Wed, 19 Jan 2022 21:41:13 +0000 Subject: [PATCH] Add scheduler_relax_rx and scheduler_relax_osd variables --- src/main/cli/settings.c | 4 ++++ src/main/pg/pg_ids.h | 3 ++- src/main/pg/scheduler.c | 31 +++++++++++++++++++++++++++++ src/main/pg/scheduler.h | 31 +++++++++++++++++++++++++++++ src/main/scheduler/scheduler.c | 4 ++-- src/main/scheduler/scheduler.h | 5 +++-- src/test/unit/scheduler_unittest.cc | 10 ++++++++++ 7 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/main/pg/scheduler.c create mode 100644 src/main/pg/scheduler.h diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index 9bc20771af..6ceddd6bc0 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -101,6 +101,7 @@ #include "pg/vcd.h" #include "pg/vtx_io.h" #include "pg/usb.h" +#include "pg/scheduler.h" #include "pg/sdio.h" #include "pg/rcdevice.h" #include "pg/stats.h" @@ -1682,6 +1683,9 @@ const clivalue_t valueTable[] = { { "expresslrs_model_id", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, UINT8_MAX }, PG_RX_EXPRESSLRS_SPI_CONFIG, offsetof(rxExpressLrsSpiConfig_t, modelId) }, #endif + { "scheduler_relax_rx", VAR_UINT16 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_SCHEDULER_CONFIG, PG_ARRAY_ELEMENT_OFFSET(schedulerConfig_t, 0, rxRelaxDeterminism) }, + { "scheduler_relax_osd", VAR_UINT16 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_SCHEDULER_CONFIG, PG_ARRAY_ELEMENT_OFFSET(schedulerConfig_t, 0, osdRelaxDeterminism) }, + // PG_TIMECONFIG #ifdef USE_RTC_TIME { "timezone_offset_minutes", VAR_INT16 | MASTER_VALUE, .config.minmax = { TIMEZONE_OFFSET_MINUTES_MIN, TIMEZONE_OFFSET_MINUTES_MAX }, PG_TIME_CONFIG, offsetof(timeConfig_t, tz_offsetMinutes) }, diff --git a/src/main/pg/pg_ids.h b/src/main/pg/pg_ids.h index fa770e03fd..cfe2d0613f 100644 --- a/src/main/pg/pg_ids.h +++ b/src/main/pg/pg_ids.h @@ -152,7 +152,8 @@ #define PG_MODE_ACTIVATION_CONFIG 553 #define PG_DYN_NOTCH_CONFIG 554 #define PG_RX_EXPRESSLRS_SPI_CONFIG 555 -#define PG_BETAFLIGHT_END 555 +#define PG_SCHEDULER_CONFIG 536 +#define PG_BETAFLIGHT_END 556 // OSD configuration (subject to change) diff --git a/src/main/pg/scheduler.c b/src/main/pg/scheduler.c new file mode 100644 index 0000000000..d29ce8d1bf --- /dev/null +++ b/src/main/pg/scheduler.c @@ -0,0 +1,31 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#include "platform.h" + +#include "pg/pg_ids.h" +#include "pg/scheduler.h" + +PG_REGISTER_WITH_RESET_TEMPLATE(schedulerConfig_t, schedulerConfig, PG_SCHEDULER_CONFIG, 0); + +PG_RESET_TEMPLATE(schedulerConfig_t, schedulerConfig, + .rxRelaxDeterminism = 25, + .osdRelaxDeterminism = 25, +); diff --git a/src/main/pg/scheduler.h b/src/main/pg/scheduler.h new file mode 100644 index 0000000000..d12c51de51 --- /dev/null +++ b/src/main/pg/scheduler.h @@ -0,0 +1,31 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#pragma once + +#include "pg/pg.h" + +typedef struct schedulerConfig_s { + uint16_t rxRelaxDeterminism; + uint16_t osdRelaxDeterminism; +} schedulerConfig_t; + +PG_DECLARE(schedulerConfig_t, schedulerConfig); + diff --git a/src/main/scheduler/scheduler.c b/src/main/scheduler/scheduler.c index 5e7b291a56..bdd920dfc4 100644 --- a/src/main/scheduler/scheduler.c +++ b/src/main/scheduler/scheduler.c @@ -659,9 +659,9 @@ FAST_CODE void scheduler(void) #endif // USE_LATE_TASK_STATISTICS } else if ((selectedTask->taskAgePeriods > TASK_AGE_EXPEDITE_COUNT) || #ifdef USE_OSD - (((selectedTask - tasks) == TASK_OSD) && (++skippedOSDAttempts > TASK_AGE_EXPEDITE_OSD)) || + (((selectedTask - tasks) == TASK_OSD) && (TASK_AGE_EXPEDITE_OSD != 0) && (++skippedOSDAttempts > TASK_AGE_EXPEDITE_OSD)) || #endif - (((selectedTask - tasks) == TASK_RX) && (++skippedRxAttempts > TASK_AGE_EXPEDITE_RX))) { + (((selectedTask - tasks) == TASK_RX) && (TASK_AGE_EXPEDITE_RX != 0) && (++skippedRxAttempts > TASK_AGE_EXPEDITE_RX))) { // If a task has been unable to run, then reduce it's recorded estimated run time to ensure // it's ultimate scheduling selectedTask->anticipatedExecutionTime *= TASK_AGE_EXPEDITE_SCALE; diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index d70dde4a69..f042be39cc 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -22,6 +22,7 @@ #include "common/time.h" #include "config/config.h" +#include "pg/scheduler.h" #define TASK_PERIOD_HZ(hz) (1000000 / (hz)) #define TASK_PERIOD_MS(ms) ((ms) * 1000) @@ -47,8 +48,8 @@ // Decay the estimated max task duration by 1/(1 << TASK_EXEC_TIME_SHIFT) on every invocation #define TASK_EXEC_TIME_SHIFT 7 -#define TASK_AGE_EXPEDITE_RX 25 // Make RX tasks more schedulable if it's failed to be scheduled this many times -#define TASK_AGE_EXPEDITE_OSD 25 // Make OSD tasks more schedulable if it's failed to be scheduled this many times +#define TASK_AGE_EXPEDITE_RX schedulerConfig()->rxRelaxDeterminism // Make RX tasks more schedulable if it's failed to be scheduled this many times +#define TASK_AGE_EXPEDITE_OSD schedulerConfig()->osdRelaxDeterminism // Make OSD tasks more schedulable if it's failed to be scheduled this many times #define TASK_AGE_EXPEDITE_COUNT 1 // Make aged tasks more schedulable #define TASK_AGE_EXPEDITE_SCALE 0.9 // By scaling their expected execution time diff --git a/src/test/unit/scheduler_unittest.cc b/src/test/unit/scheduler_unittest.cc index 818afeba65..291664b0d9 100644 --- a/src/test/unit/scheduler_unittest.cc +++ b/src/test/unit/scheduler_unittest.cc @@ -19,7 +19,17 @@ extern "C" { #include "platform.h" + #include "pg/pg.h" + #include "pg/pg_ids.h" + #include "pg/scheduler.h" #include "scheduler/scheduler.h" + + PG_REGISTER_WITH_RESET_TEMPLATE(schedulerConfig_t, schedulerConfig, PG_SCHEDULER_CONFIG, 0); + + PG_RESET_TEMPLATE(schedulerConfig_t, schedulerConfig, + .rxRelaxDeterminism = 25, + .osdRelaxDeterminism = 25, + ); } #include "unittest_macros.h"