Skip to content

Commit 50a8690

Browse files
committed
minor thread/task priority adjustments
- SPI threads become highest priority to ensure consistent scheduling - run inner loop after SPI (for primary IMU) - adjust remaining task priorities to be consistent with PX4 work queue - replace magic priority levels with PX4 tasks defines wherever possible
1 parent 49a543e commit 50a8690

File tree

11 files changed

+46
-52
lines changed

11 files changed

+46
-52
lines changed

platforms/common/include/px4_platform_common/px4_work_queue/WorkQueueManager.hpp

+27-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (c) 2019 PX4 Development Team. All rights reserved.
3+
* Copyright (c) 2019-2020 PX4 Development Team. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -48,7 +48,7 @@ struct wq_config_t {
4848

4949
namespace wq_configurations
5050
{
51-
static constexpr wq_config_t rate_ctrl{"wq:rate_ctrl", 1664, 0}; // PX4 inner loop highest priority
51+
// SCHED_PRIORITY_MAX left open
5252

5353
static constexpr wq_config_t SPI0{"wq:SPI0", 2336, -1};
5454
static constexpr wq_config_t SPI1{"wq:SPI1", 2336, -2};
@@ -58,30 +58,33 @@ static constexpr wq_config_t SPI4{"wq:SPI4", 2336, -5};
5858
static constexpr wq_config_t SPI5{"wq:SPI5", 2336, -6};
5959
static constexpr wq_config_t SPI6{"wq:SPI6", 2336, -7};
6060

61-
static constexpr wq_config_t I2C0{"wq:I2C0", 1472, -8};
62-
static constexpr wq_config_t I2C1{"wq:I2C1", 1472, -9};
63-
static constexpr wq_config_t I2C2{"wq:I2C2", 1472, -10};
64-
static constexpr wq_config_t I2C3{"wq:I2C3", 1472, -11};
65-
static constexpr wq_config_t I2C4{"wq:I2C4", 1472, -12};
61+
// PX4 inner loop highest priority after SPI (typically the primary IMU)
62+
static constexpr wq_config_t rate_ctrl{"wq:rate_ctrl", 1664, -8};
63+
64+
static constexpr wq_config_t I2C0{"wq:I2C0", 1472, -9};
65+
static constexpr wq_config_t I2C1{"wq:I2C1", 1472, -10};
66+
static constexpr wq_config_t I2C2{"wq:I2C2", 1472, -11};
67+
static constexpr wq_config_t I2C3{"wq:I2C3", 1472, -12};
68+
static constexpr wq_config_t I2C4{"wq:I2C4", 1472, -13};
6669

6770
// PX4 att/pos controllers, highest priority after sensors.
68-
static constexpr wq_config_t attitude_ctrl{"wq:attitude_ctrl", 1632, -13};
69-
static constexpr wq_config_t nav_and_controllers{"wq:nav_and_controllers", 7200, -14};
70-
71-
static constexpr wq_config_t hp_default{"wq:hp_default", 1900, -15};
72-
73-
static constexpr wq_config_t uavcan{"wq:uavcan", 3000, -16};
74-
75-
static constexpr wq_config_t UART0{"wq:UART0", 1400, -17};
76-
static constexpr wq_config_t UART1{"wq:UART1", 1400, -18};
77-
static constexpr wq_config_t UART2{"wq:UART2", 1400, -19};
78-
static constexpr wq_config_t UART3{"wq:UART3", 1400, -20};
79-
static constexpr wq_config_t UART4{"wq:UART4", 1400, -21};
80-
static constexpr wq_config_t UART5{"wq:UART5", 1400, -22};
81-
static constexpr wq_config_t UART6{"wq:UART6", 1400, -23};
82-
static constexpr wq_config_t UART7{"wq:UART7", 1400, -24};
83-
static constexpr wq_config_t UART8{"wq:UART8", 1400, -25};
84-
static constexpr wq_config_t UART_UNKNOWN{"wq:UART_UNKNOWN", 1400, -26};
71+
static constexpr wq_config_t attitude_ctrl{"wq:attitude_ctrl", 1632, -14};
72+
static constexpr wq_config_t nav_and_controllers{"wq:nav_and_controllers", 7200, -15};
73+
74+
static constexpr wq_config_t hp_default{"wq:hp_default", 1900, -16};
75+
76+
static constexpr wq_config_t uavcan{"wq:uavcan", 3000, -17};
77+
78+
static constexpr wq_config_t UART0{"wq:UART0", 1400, -18};
79+
static constexpr wq_config_t UART1{"wq:UART1", 1400, -19};
80+
static constexpr wq_config_t UART2{"wq:UART2", 1400, -20};
81+
static constexpr wq_config_t UART3{"wq:UART3", 1400, -21};
82+
static constexpr wq_config_t UART4{"wq:UART4", 1400, -22};
83+
static constexpr wq_config_t UART5{"wq:UART5", 1400, -23};
84+
static constexpr wq_config_t UART6{"wq:UART6", 1400, -24};
85+
static constexpr wq_config_t UART7{"wq:UART7", 1400, -25};
86+
static constexpr wq_config_t UART8{"wq:UART8", 1400, -26};
87+
static constexpr wq_config_t UART_UNKNOWN{"wq:UART_UNKNOWN", 1400, -27};
8588

8689
static constexpr wq_config_t lp_default{"wq:lp_default", 1700, -50};
8790

platforms/common/include/px4_platform_common/tasks.h

+10-19
Original file line numberDiff line numberDiff line change
@@ -100,49 +100,40 @@ typedef struct {
100100
#error "No target OS defined"
101101
#endif
102102

103-
// PX4 work queue starting high priority
104-
#define PX4_WQ_HP_BASE (SCHED_PRIORITY_MAX - 15)
105-
106-
// Fast drivers - they need to run as quickly as possible to minimize control
107-
// latency.
108-
#define SCHED_PRIORITY_FAST_DRIVER (SCHED_PRIORITY_MAX - 0)
103+
// keep in sync with wq_configurations (platforms/common/include/px4_platform_common/px4_work_queue/WorkQueueManager.hpp)
104+
#define PX4_WQ_RATE_CONTROL (SCHED_PRIORITY_MAX - 8)
105+
#define PX4_WQ_ATTITUDE_CONTROL (SCHED_PRIORITY_MAX - 14)
106+
#define PX4_WQ_POSITION_CONTROL (SCHED_PRIORITY_MAX - 15)
107+
#define PX4_WQ_HP_BASE (SCHED_PRIORITY_MAX - 16)
108+
#define PX4_WQ_UART_MAX (SCHED_PRIORITY_MAX - 18)
109109

110110
// Actuator outputs should run as soon as the rate controller publishes
111111
// the actuator controls topic
112-
#define SCHED_PRIORITY_ACTUATOR_OUTPUTS (PX4_WQ_HP_BASE - 3)
112+
#define SCHED_PRIORITY_ACTUATOR_OUTPUTS (PX4_WQ_RATE_CONTROL)
113113

114114
// Attitude controllers typically are in a blocking wait on driver data
115115
// they should be the first to run on an update, using the current sensor
116116
// data and the *previous* attitude reference from the position controller
117117
// which typically runs at a slower rate
118-
#define SCHED_PRIORITY_ATTITUDE_CONTROL (PX4_WQ_HP_BASE - 4)
119-
120-
// Estimators should run after the attitude controller but before anything
121-
// else in the system. They wait on sensor data which is either coming
122-
// from the sensor hub or from a driver. Keeping this class at a higher
123-
// priority ensures that the estimator runs first if it can, but will
124-
// wait for the sensor hub if its data is coming from it.
125-
#define SCHED_PRIORITY_ESTIMATOR (PX4_WQ_HP_BASE - 5)
118+
#define SCHED_PRIORITY_ATTITUDE_CONTROL (PX4_WQ_ATTITUDE_CONTROL)
126119

127120
// Position controllers typically are in a blocking wait on estimator data
128121
// so when new sensor data is available they will run last. Keeping them
129122
// on a high priority ensures that they are the first process to be run
130123
// when the estimator updates.
131-
#define SCHED_PRIORITY_POSITION_CONTROL (PX4_WQ_HP_BASE - 7)
124+
#define SCHED_PRIORITY_POSITION_CONTROL (PX4_WQ_POSITION_CONTROL)
132125

133126
// The log capture (which stores log data into RAM) should run faster
134127
// than other components, but should not run before the control pipeline
135128
#define SCHED_PRIORITY_LOG_CAPTURE (PX4_WQ_HP_BASE - 10)
136129

137130
// Slow drivers should run at a rate where they do not impact the overall
138131
// system execution
139-
#define SCHED_PRIORITY_SLOW_DRIVER (PX4_WQ_HP_BASE - 35)
132+
#define SCHED_PRIORITY_SLOW_DRIVER (PX4_WQ_UART_MAX + 1)
140133

141134
// The navigation system needs to execute regularly but has no realtime needs
142135
#define SCHED_PRIORITY_NAVIGATION (SCHED_PRIORITY_DEFAULT + 5)
143136
// SCHED_PRIORITY_DEFAULT
144-
#define SCHED_PRIORITY_LOG_WRITER (SCHED_PRIORITY_DEFAULT - 10)
145-
#define SCHED_PRIORITY_PARAMS (SCHED_PRIORITY_DEFAULT - 15)
146137
// SCHED_PRIORITY_IDLE
147138

148139
typedef int (*px4_main_t)(int argc, char *argv[]);

src/drivers/linux_pwm_out/linux_pwm_out.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ void start()
465465
/* start the task */
466466
_task_handle = px4_task_spawn_cmd("pwm_out_main",
467467
SCHED_DEFAULT,
468-
SCHED_PRIORITY_MAX,
468+
SCHED_PRIORITY_ACTUATOR_OUTPUTS,
469469
1500,
470470
(px4_main_t)&task_main_trampoline,
471471
nullptr);

src/drivers/mkblctrl/mkblctrl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ MK::init(unsigned motors)
305305
/* start the IO interface task */
306306
_task = px4_task_spawn_cmd("mkblctrl",
307307
SCHED_DEFAULT,
308-
SCHED_PRIORITY_MAX - 20,
308+
SCHED_PRIORITY_ACTUATOR_OUTPUTS,
309309
1500,
310310
(main_t)&MK::task_main_trampoline,
311311
nullptr);

src/drivers/roboclaw/roboclaw_main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int roboclaw_main(int argc, char *argv[])
148148
RoboClaw::taskShouldExit = false;
149149
deamon_task = px4_task_spawn_cmd("roboclaw",
150150
SCHED_DEFAULT,
151-
SCHED_PRIORITY_MAX - 10,
151+
SCHED_PRIORITY_ACTUATOR_OUTPUTS,
152152
2000,
153153
roboclaw_thread_main,
154154
(char *const *)argv);

src/drivers/snapdragon_pwm_out/snapdragon_pwm_out.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void start()
485485
/* start the task */
486486
_task_handle = px4_task_spawn_cmd("snapdragon_pwm_out_main",
487487
SCHED_DEFAULT,
488-
SCHED_PRIORITY_MAX,
488+
SCHED_PRIORITY_ACTUATOR_OUTPUTS,
489489
1500,
490490
(px4_main_t)&task_main_trampoline,
491491
nullptr);

src/examples/fixedwing_control/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ int ex_fixedwing_control_main(int argc, char *argv[])
465465
thread_should_exit = false;
466466
deamon_task = px4_task_spawn_cmd("ex_fixedwing_control",
467467
SCHED_DEFAULT,
468-
SCHED_PRIORITY_MAX - 20,
468+
SCHED_PRIORITY_ATTITUDE_CONTROL,
469469
2048,
470470
fixedwing_control_thread_main,
471471
(argv) ? (char *const *)&argv[2] : (char *const *)nullptr);

src/examples/hello/hello_start.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int hello_main(int argc, char *argv[])
6969

7070
daemon_task = px4_task_spawn_cmd("hello",
7171
SCHED_DEFAULT,
72-
SCHED_PRIORITY_MAX - 5,
72+
SCHED_PRIORITY_DEFAULT,
7373
2000,
7474
PX4_MAIN,
7575
(argv) ? (char *const *)&argv[2] : (char *const *)nullptr);

src/examples/matlab_csv_serial/matlab_csv_serial.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int matlab_csv_serial_main(int argc, char *argv[])
102102
thread_should_exit = false;
103103
daemon_task = px4_task_spawn_cmd("matlab_csv_serial",
104104
SCHED_DEFAULT,
105-
SCHED_PRIORITY_MAX - 5,
105+
SCHED_PRIORITY_DEFAULT,
106106
2000,
107107
matlab_csv_serial_thread_main,
108108
(argv) ? (char *const *)&argv[2] : (char *const *)NULL);

src/examples/rover_steering_control/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ int rover_steering_control_main(int argc, char *argv[])
419419
thread_should_exit = false;
420420
deamon_task = px4_task_spawn_cmd("rover_steering_control",
421421
SCHED_DEFAULT,
422-
SCHED_PRIORITY_MAX - 20,
422+
SCHED_PRIORITY_ATTITUDE_CONTROL,
423423
2048,
424424
rover_steering_control_thread_main,
425425
(argv) ? (char *const *)&argv[2] : (char *const *)nullptr);

src/systemcmds/top/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ px4_add_module(
3434
MODULE systemcmds__top
3535
MAIN top
3636
PRIORITY
37-
"SCHED_PRIORITY_MAX - 16" # max priority below high priority WQ threads
37+
"SCHED_PRIORITY_MAX - 17" # max priority below high priority WQ threads
3838
SRCS
3939
top.c
4040
DEPENDS

0 commit comments

Comments
 (0)