set all thread priorities in the same place (#2412)

* unify thread priority

* header

* mmc
This commit is contained in:
Matthew Kennedy 2021-02-28 02:30:45 -10:00 committed by GitHub
parent f347b92f45
commit f8747a35bf
21 changed files with 74 additions and 20 deletions

View File

@ -18,6 +18,7 @@
#include "tunerstudio_io.h" #include "tunerstudio_io.h"
#include "bluetooth.h" #include "bluetooth.h"
#include "engine_configuration.h" #include "engine_configuration.h"
#include "thread_priority.h"
#if EFI_BLUETOOTH_SETUP #if EFI_BLUETOOTH_SETUP
@ -289,7 +290,7 @@ void bluetoothStart(ts_channel_s *btChan, bluetooth_module_e moduleType, const c
commands[numCommands++] = cmdPin; commands[numCommands++] = cmdPin;
// create a thread to execute these commands later // create a thread to execute these commands later
btThread = chThdCreateStatic(btThreadStack, sizeof(btThreadStack), NORMALPRIO, (tfunc_t)btThreadEntryPoint, NULL); btThread = chThdCreateStatic(btThreadStack, sizeof(btThreadStack), PRIO_CONSOLE, (tfunc_t)btThreadEntryPoint, NULL);
btProcessIsStarted = true; btProcessIsStarted = true;
} }

View File

@ -87,6 +87,7 @@
#include "status_loop.h" #include "status_loop.h"
#include "mmc_card.h" #include "mmc_card.h"
#include "perf_trace.h" #include "perf_trace.h"
#include "thread_priority.h"
#include "signature.h" #include "signature.h"
@ -907,7 +908,7 @@ void startTunerStudioConnectivity(void) {
addConsoleAction("bluetooth_cancel", bluetoothCancel); addConsoleAction("bluetooth_cancel", bluetoothCancel);
#endif /* EFI_BLUETOOTH_SETUP */ #endif /* EFI_BLUETOOTH_SETUP */
chThdCreateStatic(tunerstudioThreadStack, sizeof(tunerstudioThreadStack), NORMALPRIO, (tfunc_t)tsThreadEntryPoint, NULL); chThdCreateStatic(tunerstudioThreadStack, sizeof(tunerstudioThreadStack), PRIO_CONSOLE, (tfunc_t)tsThreadEntryPoint, NULL);
} }
#endif #endif

View File

@ -39,6 +39,7 @@
#include "os_util.h" #include "os_util.h"
#include "tunerstudio.h" #include "tunerstudio.h"
#include "connector_uart_dma.h" #include "connector_uart_dma.h"
#include "thread_priority.h"
#if EFI_SIMULATOR #if EFI_SIMULATOR
#include "rusEfiFunctionalTest.h" #include "rusEfiFunctionalTest.h"
@ -265,6 +266,6 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
#endif /* EFI_CONSOLE_SERIAL_DEVICE || EFI_CONSOLE_UART_DEVICE */ #endif /* EFI_CONSOLE_SERIAL_DEVICE || EFI_CONSOLE_UART_DEVICE */
#if !defined(EFI_CONSOLE_NO_THREAD) #if !defined(EFI_CONSOLE_NO_THREAD)
chThdCreateStatic(consoleThreadStack, sizeof(consoleThreadStack), NORMALPRIO, (tfunc_t)consoleThreadEntryPoint, NULL); chThdCreateStatic(consoleThreadStack, sizeof(consoleThreadStack), PRIO_CONSOLE, (tfunc_t)consoleThreadEntryPoint, NULL);
#endif /* EFI_CONSOLE_NO_THREAD */ #endif /* EFI_CONSOLE_NO_THREAD */
} }

View File

@ -83,6 +83,7 @@
#include "dc_motor.h" #include "dc_motor.h"
#include "dc_motors.h" #include "dc_motors.h"
#include "pid_auto_tune.h" #include "pid_auto_tune.h"
#include "thread_priority.h"
#if defined(HAS_OS_ACCESS) #if defined(HAS_OS_ACCESS)
#error "Unexpected OS ACCESS HERE" #error "Unexpected OS ACCESS HERE"
@ -651,7 +652,7 @@ struct EtbImpl final : public EtbController {
static EtbImpl etbControllers[ETB_COUNT]; static EtbImpl etbControllers[ETB_COUNT];
struct EtbThread final : public PeriodicController<512> { struct EtbThread final : public PeriodicController<512> {
EtbThread() : PeriodicController("ETB", NORMALPRIO + 3, ETB_LOOP_FREQUENCY) {} EtbThread() : PeriodicController("ETB", PRIO_ETB, ETB_LOOP_FREQUENCY) {}
void PeriodicTask(efitick_t) override { void PeriodicTask(efitick_t) override {
// Simply update all controllers // Simply update all controllers

View File

@ -16,13 +16,14 @@
#include "can_dash.h" #include "can_dash.h"
#include "obd2.h" #include "obd2.h"
#include "can_sensor.h" #include "can_sensor.h"
#include "thread_priority.h"
EXTERN_ENGINE; EXTERN_ENGINE;
extern CanSensorBase* cansensors_head; extern CanSensorBase* cansensors_head;
CanWrite::CanWrite() CanWrite::CanWrite()
: PeriodicController("CAN TX", NORMALPRIO, 50) : PeriodicController("CAN TX", PRIO_CAN_TX, 50)
{ {
} }

View File

@ -5,6 +5,7 @@
#include "perf_trace.h" #include "perf_trace.h"
#include "thread_controller.h" #include "thread_controller.h"
#include "software_knock.h" #include "software_knock.h"
#include "thread_priority.h"
#if EFI_SOFTWARE_KNOCK #if EFI_SOFTWARE_KNOCK
@ -162,7 +163,7 @@ void startKnockSampling(uint8_t cylinderIndex) {
class KnockThread : public ThreadController<256> { class KnockThread : public ThreadController<256> {
public: public:
KnockThread() : ThreadController("knock", NORMALPRIO - 10) {} KnockThread() : ThreadController("knock", PRIO_KNOCK_PROCESS) {}
void ThreadTask() override; void ThreadTask() override;
}; };

View File

@ -17,6 +17,7 @@
#include "allsensors.h" #include "allsensors.h"
#include "vehicle_speed.h" #include "vehicle_speed.h"
#include "thread_priority.h"
EXTERN_ENGINE; EXTERN_ENGINE;
@ -29,7 +30,7 @@ uint8_t sb = 0;
bool clear_ser_buffer = false; bool clear_ser_buffer = false;
SerialRead::SerialRead() SerialRead::SerialRead()
: ThreadController("AUX Serial RX", NORMALPRIO) { : ThreadController("AUX Serial RX", PRIO_AUX_SERIAL) {
} }
void SerialRead::ThreadTask() { void SerialRead::ThreadTask() {

View File

@ -0,0 +1,36 @@
/**
* @file thread_priority.h
* @brief This file sets the thread priority for the threads running on rusEFI
*
* @date February 27, 2021
* @author Matthew Kennedy, (c) 2021
*/
#pragma once
// ADC and ETB get highest priority - not much else actually runs the engine
#define PRIO_ADC (NORMALPRIO + 10)
#define PRIO_ETB (NORMALPRIO + 9)
// GPIO chips should be fast and go right back to sleep, plus can be timing sensitive
#define PRIO_GPIOCHIP (NORMALPRIO + 8)
// TX higher priority than RX because the ECU is generally the one transmitting the highest priority messages
#define PRIO_CAN_TX (NORMALPRIO + 7)
#define PRIO_CAN_RX (NORMALPRIO + 6)
// Less critical harware
#define PRIO_SERVO (NORMALPRIO + 5)
#define PRIO_STEPPER (NORMALPRIO + 5)
#define PRIO_CJ125 (NORMALPRIO + 5)
// Console thread
#define PRIO_CONSOLE (NORMALPRIO + 1)
// Less important things
#define PRIO_MMC (NORMALPRIO - 1)
// These can get starved without too much adverse effect
#define PRIO_AUX_SERIAL NORMALPRIO
#define PRIO_KNOCK_PROCESS (NORMALPRIO - 10)
#define PRIO_HIP9011 (NORMALPRIO - 10)

View File

@ -36,6 +36,7 @@
#include "engine_controller.h" #include "engine_controller.h"
#include "maf.h" #include "maf.h"
#include "perf_trace.h" #include "perf_trace.h"
#include "thread_priority.h"
static NO_CACHE adcsample_t slowAdcSampleBuf[ADC_BUF_DEPTH_SLOW * ADC_MAX_CHANNELS_COUNT]; static NO_CACHE adcsample_t slowAdcSampleBuf[ADC_BUF_DEPTH_SLOW * ADC_MAX_CHANNELS_COUNT];
static NO_CACHE adcsample_t fastAdcSampleBuf[ADC_BUF_DEPTH_FAST * ADC_MAX_CHANNELS_COUNT]; static NO_CACHE adcsample_t fastAdcSampleBuf[ADC_BUF_DEPTH_FAST * ADC_MAX_CHANNELS_COUNT];
@ -444,7 +445,7 @@ int getSlowAdcCounter() {
class SlowAdcController : public PeriodicController<256> { class SlowAdcController : public PeriodicController<256> {
public: public:
SlowAdcController() SlowAdcController()
: PeriodicController("ADC", NORMALPRIO + 5, SLOW_ADC_RATE) : PeriodicController("ADC", PRIO_ADC, SLOW_ADC_RATE)
{ {
} }

View File

@ -24,6 +24,7 @@
#include "string.h" #include "string.h"
#include "mpu_util.h" #include "mpu_util.h"
#include "engine.h" #include "engine.h"
#include "thread_priority.h"
EXTERN_ENGINE; EXTERN_ENGINE;
@ -83,7 +84,7 @@ static const CANConfig *canConfig = &canConfig500;
class CanRead final : public ThreadController<UTILITY_THREAD_STACK_SIZE> { class CanRead final : public ThreadController<UTILITY_THREAD_STACK_SIZE> {
public: public:
CanRead() CanRead()
: ThreadController("CAN RX", NORMALPRIO) : ThreadController("CAN RX", PRIO_CAN_RX)
{ {
} }

View File

@ -17,6 +17,7 @@
#include "gpio/drv8860.h" #include "gpio/drv8860.h"
#include "pin_repository.h" #include "pin_repository.h"
#include "os_util.h" #include "os_util.h"
#include "thread_priority.h"
#if (BOARD_DRV8860_COUNT > 0) #if (BOARD_DRV8860_COUNT > 0)
@ -225,7 +226,7 @@ int drv8860_init(void * data) {
if (!drv_task_ready) { if (!drv_task_ready) {
chThdCreateStatic(drv8860_thread_1_wa, sizeof(drv8860_thread_1_wa), chThdCreateStatic(drv8860_thread_1_wa, sizeof(drv8860_thread_1_wa),
NORMALPRIO + 1, drv8860_driver_thread, NULL); PRIO_GPIOCHIP, drv8860_driver_thread, NULL);
drv_task_ready = true; drv_task_ready = true;
} }

View File

@ -15,6 +15,7 @@
#include "gpio/mc33810.h" #include "gpio/mc33810.h"
#include "pin_repository.h" #include "pin_repository.h"
#include "os_util.h" #include "os_util.h"
#include "thread_priority.h"
#if (BOARD_MC33810_COUNT > 0) #if (BOARD_MC33810_COUNT > 0)
@ -498,7 +499,7 @@ int mc33810_init(void * data)
if (!drv_task_ready) { if (!drv_task_ready) {
chThdCreateStatic(mc33810_thread_1_wa, sizeof(mc33810_thread_1_wa), chThdCreateStatic(mc33810_thread_1_wa, sizeof(mc33810_thread_1_wa),
NORMALPRIO + 1, mc33810_driver_thread, NULL); PRIO_GPIOCHIP, mc33810_driver_thread, NULL);
drv_task_ready = true; drv_task_ready = true;
} }

View File

@ -18,6 +18,7 @@
#include "gpio/gpio_ext.h" #include "gpio/gpio_ext.h"
#include "gpio/mc33972.h" #include "gpio/mc33972.h"
#include "pin_repository.h" #include "pin_repository.h"
#include "thread_priority.h"
#if (BOARD_MC33972_COUNT > 0) #if (BOARD_MC33972_COUNT > 0)
@ -304,7 +305,7 @@ static int mc33972_init(void * data)
if (!drv_task_ready) { if (!drv_task_ready) {
chThdCreateStatic(mc33972_thread_1_wa, sizeof(mc33972_thread_1_wa), chThdCreateStatic(mc33972_thread_1_wa, sizeof(mc33972_thread_1_wa),
NORMALPRIO + 1, mc33972_driver_thread, NULL); PRIO_GPIOCHIP, mc33972_driver_thread, NULL);
drv_task_ready = true; drv_task_ready = true;
} }

View File

@ -25,6 +25,7 @@
#include "gpio/tle6240.h" #include "gpio/tle6240.h"
#include "pin_repository.h" #include "pin_repository.h"
#include "os_util.h" #include "os_util.h"
#include "thread_priority.h"
#if (BOARD_TLE6240_COUNT > 0) #if (BOARD_TLE6240_COUNT > 0)
@ -450,7 +451,7 @@ static int tle6240_init(void * data)
if (!drv_task_ready) { if (!drv_task_ready) {
chThdCreateStatic(tle6240_thread_1_wa, sizeof(tle6240_thread_1_wa), chThdCreateStatic(tle6240_thread_1_wa, sizeof(tle6240_thread_1_wa),
NORMALPRIO + 1, tle6240_driver_thread, NULL); PRIO_GPIOCHIP, tle6240_driver_thread, NULL);
drv_task_ready = true; drv_task_ready = true;
} }

View File

@ -41,6 +41,7 @@
#include "pin_repository.h" #include "pin_repository.h"
#include "os_util.h" #include "os_util.h"
#include "voltage.h" #include "voltage.h"
#include "thread_priority.h"
EXTERN_ENGINE_CONFIGURATION; EXTERN_ENGINE_CONFIGURATION;
@ -1199,7 +1200,7 @@ static int tle8888_init(void * data)
/* start thread */ /* start thread */
chip->thread = chThdCreateStatic(chip->thread_wa, sizeof(chip->thread_wa), chip->thread = chThdCreateStatic(chip->thread_wa, sizeof(chip->thread_wa),
NORMALPRIO + 1, tle8888_driver_thread, chip); PRIO_GPIOCHIP, tle8888_driver_thread, chip);
return 0; return 0;
} }

View File

@ -26,6 +26,7 @@
#include "status_loop.h" #include "status_loop.h"
#include "buffered_writer.h" #include "buffered_writer.h"
#include "null_device.h" #include "null_device.h"
#include "thread_priority.h"
#include "rtc_helper.h" #include "rtc_helper.h"
@ -537,7 +538,7 @@ void initMmcCard(void) {
chBSemObjectInit(&usbConnectedSemaphore, true); chBSemObjectInit(&usbConnectedSemaphore, true);
#endif #endif
chThdCreateStatic(mmcThreadStack, sizeof(mmcThreadStack), LOWPRIO, (tfunc_t)(void*) MMCmonThread, NULL); chThdCreateStatic(mmcThreadStack, sizeof(mmcThreadStack), PRIO_MMC, (tfunc_t)(void*) MMCmonThread, NULL);
addConsoleAction("sdinfo", sdStatistics); addConsoleAction("sdinfo", sdStatistics);
addConsoleActionS("ls", listDirectory); addConsoleActionS("ls", listDirectory);

View File

@ -314,7 +314,6 @@
#define STM32_USB_OTG2_IRQ_PRIORITY 14 #define STM32_USB_OTG2_IRQ_PRIORITY 14
#define STM32_USB_OTG1_RX_FIFO_SIZE 512 #define STM32_USB_OTG1_RX_FIFO_SIZE 512
#define STM32_USB_OTG2_RX_FIFO_SIZE 1024 #define STM32_USB_OTG2_RX_FIFO_SIZE 1024
#define STM32_USB_OTG_THREAD_PRIO LOWPRIO
#define STM32_USB_OTG_THREAD_STACK_SIZE 1024 #define STM32_USB_OTG_THREAD_STACK_SIZE 1024
#define STM32_USB_OTGFIFO_FILL_BASEPRI 0 #define STM32_USB_OTGFIFO_FILL_BASEPRI 0

View File

@ -18,6 +18,7 @@
#include "cj125.h" #include "cj125.h"
#include "pwm_generator_logic.h" #include "pwm_generator_logic.h"
#include "rpm_calculator.h" #include "rpm_calculator.h"
#include "thread_priority.h"
EXTERN_ENGINE; EXTERN_ENGINE;
@ -647,7 +648,7 @@ void initCJ125(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
addConsoleAction("cj125_restart", cjRestart); addConsoleAction("cj125_restart", cjRestart);
addConsoleAction("cj125_calibrate", cjStartCalibration); addConsoleAction("cj125_calibrate", cjStartCalibration);
chThdCreateStatic(cj125ThreadStack, sizeof(cj125ThreadStack), LOWPRIO, (tfunc_t)(void*) cjThread, NULL); chThdCreateStatic(cj125ThreadStack, sizeof(cj125ThreadStack), PRIO_CJ125, (tfunc_t)(void*) cjThread, NULL);
#endif /* ! EFI_UNIT_TEST */ #endif /* ! EFI_UNIT_TEST */
} }

View File

@ -43,6 +43,7 @@
#include "hip9011.h" #include "hip9011.h"
#include "adc_inputs.h" #include "adc_inputs.h"
#include "perf_trace.h" #include "perf_trace.h"
#include "thread_priority.h"
#include "engine_controller.h" #include "engine_controller.h"
@ -431,7 +432,7 @@ void initHip9011(Logging *sharedLogger) {
addConsoleActionI("set_hip_prescalerandsdo", setPrescalerAndSDO); addConsoleActionI("set_hip_prescalerandsdo", setPrescalerAndSDO);
addConsoleActionF("set_knock_threshold", setKnockThresh); addConsoleActionF("set_knock_threshold", setKnockThresh);
addConsoleActionI("set_max_knock_sub_deg", setMaxKnockSubDeg); addConsoleActionI("set_max_knock_sub_deg", setMaxKnockSubDeg);
chThdCreateStatic(hipThreadStack, sizeof(hipThreadStack), NORMALPRIO, (tfunc_t)(void*) hipThread, NULL); chThdCreateStatic(hipThreadStack, sizeof(hipThreadStack), PRIO_HIP9011, (tfunc_t)(void*) hipThread, NULL);
} }
#endif /* EFI_HIP_9011 */ #endif /* EFI_HIP_9011 */

View File

@ -17,6 +17,7 @@
#if EFI_SERVO || EFI_SIMULATOR #if EFI_SERVO || EFI_SIMULATOR
#include "servo.h" #include "servo.h"
#include "pin_repository.h" #include "pin_repository.h"
#include "thread_priority.h"
EXTERN_ENGINE; EXTERN_ENGINE;
@ -63,7 +64,7 @@ void initServo(void) {
pins[i].initPin("servo", p); pins[i].initPin("servo", p);
} }
chThdCreateStatic(servoThreadStack, sizeof(servoThreadStack), NORMALPRIO, (tfunc_t)(void*) seThread, NULL); chThdCreateStatic(servoThreadStack, sizeof(servoThreadStack), PRIO_SERVO, (tfunc_t)(void*) seThread, NULL);
} }
#endif /* EFI_SERVO */ #endif /* EFI_SERVO */

View File

@ -16,6 +16,7 @@
#include "engine_controller.h" #include "engine_controller.h"
#include "adc_inputs.h" #include "adc_inputs.h"
#include "sensor.h" #include "sensor.h"
#include "thread_priority.h"
EXTERN_ENGINE; EXTERN_ENGINE;
@ -149,7 +150,7 @@ void StepperMotor::ThreadTask() {
} }
} }
StepperMotor::StepperMotor() : ThreadController("stepper", NORMALPRIO) {} StepperMotor::StepperMotor() : ThreadController("stepper", PRIO_STEPPER) {}
int StepperMotor::getTargetPosition() const { int StepperMotor::getTargetPosition() const {
return m_targetPosition; return m_targetPosition;