diff --git a/components/rtps/CMakeLists.txt b/components/rtps/CMakeLists.txt index 2b453eb699..33fdeb9d11 100644 --- a/components/rtps/CMakeLists.txt +++ b/components/rtps/CMakeLists.txt @@ -91,6 +91,16 @@ foreach(knob ${RTPS_LIMIT_KNOBS}) endif() endforeach() +# Transport task priority (Kconfig "Transport task priority"): a nonzero value +# overrides the selected profile's THREAD_POOL_READER_PRIO, which the transport +# gives its worker pool and reactor tasks. 0 keeps the profile's value. +if(DEFINED CONFIG_RTPS_THREAD_POOL_READER_PRIO + AND NOT "${CONFIG_RTPS_THREAD_POOL_READER_PRIO}" STREQUAL "" + AND NOT "${CONFIG_RTPS_THREAD_POOL_READER_PRIO}" STREQUAL "0") + target_compile_definitions(${COMPONENT_LIB} PUBLIC + "RTPS_CFG_THREAD_POOL_READER_PRIO=${CONFIG_RTPS_THREAD_POOL_READER_PRIO}") +endif() + # Cross-limit capacity check (mirrors lib/espp.cmake): every participant # consumes 1 stateless writer/reader + 2 stateful writers/readers from the # GLOBAL pools for its builtin discovery endpoints. Effective value = the diff --git a/components/rtps/Kconfig b/components/rtps/Kconfig index fde2777580..31b542553d 100644 --- a/components/rtps/Kconfig +++ b/components/rtps/Kconfig @@ -178,6 +178,29 @@ menu "RTPS" endmenu + menu "Transport task priority (advanced)" + config RTPS_THREAD_POOL_READER_PRIO + int "THREAD_POOL_READER_PRIO: worker pool and reactor (0 = profile default)" + default 0 + range 0 24 + help + FreeRTOS priority of the transport's tasks: the worker pool + ("rtps_worker_"), which sends and receives all RTPS traffic + (publish() only queues a sample; a worker sends it) and runs + every reader and matched callback, and the reactor + ("rtps_reactor"), the select() loop that hands received + datagrams to the pool. 0 keeps the selected profile's value + (5 on the embedded profile, 3 on the host profiles). + + Raise it when a busy task of higher priority (a UI renderer, a + long computation) can run on the same core as these tasks: + until it yields, nothing is sent or received. Bands (QosBand) + order work inside the pool and cannot help when the pool's + tasks are not scheduled. The callbacks then run at this + priority too, so keep them short. + + endmenu + config RTPS_STORAGE_DYNAMIC bool "Use dynamic (heap) history/queue storage" default n diff --git a/components/rtps/README.md b/components/rtps/README.md index 92a7c87a22..65b48b185f 100644 --- a/components/rtps/README.md +++ b/components/rtps/README.md @@ -164,6 +164,7 @@ via `include/rtps/config.hpp`. | `RTPS_STORAGE_DYNAMIC` | off on ESP32 / on host | Static `std::array` history (zero-heap, drop-oldest) vs heap-backed `std::deque` (grows). Orthogonal to the profile. | | `RTPS_ENABLE_FRAGMENTATION` | off on ESP32 / on host | DATA_FRAG for samples > ~64 KB (interoperates with FastDDS/ROS 2). | | `RTPS_ENABLE_RPC` | on (default) | Compile in services + actions (RMI/AMI). Disable to drop that code + its threads on a pure-pub/sub device. | +| `RTPS_THREAD_POOL_READER_PRIO` | 0 = profile default (5 on ESP32) | FreeRTOS priority of the transport's worker pool and reactor tasks, which send and receive all traffic (see [Priority scheduling](#priority-scheduling-bands-dedicated-ports-dscp)). | The domain id, announcement/heartbeat periods, and pool sizes live in the profile headers. @@ -251,6 +252,15 @@ of its underlying service/topic endpoints (note a ROS action server is ~8 endpoints — more than the default ration, so most fall back to deferred dispatch unless the cap is raised). +Bands order work *inside* the transport's worker pool. The pool's tasks +themselves (`rtps_worker_`, plus the `rtps_reactor` `select()` loop) run at +the profile's `THREAD_POOL_READER_PRIO` (5 on ESP32) on no particular core. +Every send and receive goes through them (`publish()` only queues the sample), +so a busy task of higher priority on their core stalls all traffic until it +yields. On ESP-IDF, menuconfig `RTPS -> Transport task priority (advanced)` +sets their priority; `0` keeps the profile default. The reader and matched +callbacks then run at that priority too, so keep them short. + --- ## ESPP component dependencies diff --git a/components/rtps/include/rtps/config_desktop.hpp b/components/rtps/include/rtps/config_desktop.hpp index 0411fc2b24..1b2e6c8513 100644 --- a/components/rtps/include/rtps/config_desktop.hpp +++ b/components/rtps/include/rtps/config_desktop.hpp @@ -188,7 +188,12 @@ const int MAX_NUM_UDP_CONNECTIONS = RTPS_CFG_MAX_NUM_UDP_CONNECTIONS; const int THREAD_POOL_NUM_WRITERS = 2; const int THREAD_POOL_NUM_READERS = 2; const int THREAD_POOL_WRITER_PRIO = 3; -const int THREAD_POOL_READER_PRIO = 3; +// The transport's worker pool and reactor tasks (EsppTransport). On ESP-IDF, +// menuconfig RTPS -> Transport task priority overrides it. +#ifndef RTPS_CFG_THREAD_POOL_READER_PRIO +#define RTPS_CFG_THREAD_POOL_READER_PRIO 3 +#endif +const int THREAD_POOL_READER_PRIO = RTPS_CFG_THREAD_POOL_READER_PRIO; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH_USERTRAFFIC = 32; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH_METATRAFFIC = 32; diff --git a/components/rtps/include/rtps/config_esp32.hpp b/components/rtps/include/rtps/config_esp32.hpp index da01a1e116..53208b1498 100644 --- a/components/rtps/include/rtps/config_esp32.hpp +++ b/components/rtps/include/rtps/config_esp32.hpp @@ -163,7 +163,12 @@ const int MAX_NUM_UDP_CONNECTIONS = RTPS_CFG_MAX_NUM_UDP_CONNECTIONS; const int THREAD_POOL_NUM_WRITERS = 2; const int THREAD_POOL_NUM_READERS = 2; const int THREAD_POOL_WRITER_PRIO = 5; -const int THREAD_POOL_READER_PRIO = 5; +// The transport's worker pool and reactor tasks (EsppTransport). On ESP-IDF, +// menuconfig RTPS -> Transport task priority overrides it. +#ifndef RTPS_CFG_THREAD_POOL_READER_PRIO +#define RTPS_CFG_THREAD_POOL_READER_PRIO 5 +#endif +const int THREAD_POOL_READER_PRIO = RTPS_CFG_THREAD_POOL_READER_PRIO; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH_USERTRAFFIC = 60; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH_METATRAFFIC = 60; diff --git a/components/rtps/include/rtps/config_host_large.hpp b/components/rtps/include/rtps/config_host_large.hpp index 4312dee815..743f29bcc3 100644 --- a/components/rtps/include/rtps/config_host_large.hpp +++ b/components/rtps/include/rtps/config_host_large.hpp @@ -182,7 +182,12 @@ const int MAX_NUM_UDP_CONNECTIONS = RTPS_CFG_MAX_NUM_UDP_CONNECTIONS; const int THREAD_POOL_NUM_WRITERS = 2; const int THREAD_POOL_NUM_READERS = 2; const int THREAD_POOL_WRITER_PRIO = 3; -const int THREAD_POOL_READER_PRIO = 3; +// The transport's worker pool and reactor tasks (EsppTransport). On ESP-IDF, +// menuconfig RTPS -> Transport task priority overrides it. +#ifndef RTPS_CFG_THREAD_POOL_READER_PRIO +#define RTPS_CFG_THREAD_POOL_READER_PRIO 3 +#endif +const int THREAD_POOL_READER_PRIO = RTPS_CFG_THREAD_POOL_READER_PRIO; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH_USERTRAFFIC = 64; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH_METATRAFFIC = 64;