diff --git a/docs/index.md b/docs/index.md index d36244d..55cae8c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -36,10 +36,19 @@ This package continues the development of [`sykwer/callback_isolated_executor`]( | Category | Supported Versions / Notes | |----------|----------------------------| -| ROS 2 | Humble (only with the `rclcpp` client library) | -| Linux Distribution | Ubuntu 22.04 (Jammy Jellyfish) | +| ROS 2 | Humble, Jazzy (only with the `rclcpp` client library) | +| Linux Distribution | Ubuntu 22.04 (Jammy Jellyfish), Ubuntu 24.04 (Noble Numbat) | -This reflects the current status; support is expected to expand in the future. +## Install + +The packages are released on the ROS 2 build farm (Humble binaries are available; for Jazzy, build from +source until the binaries are published): + +```bash +sudo apt install ros-$ROS_DISTRO-callback-isolated-executor +``` + +See the [Integration Guide](integration-guide.md) for building from source and for the remaining steps. ## Pages diff --git a/docs/integration-guide.md b/docs/integration-guide.md index cf984b8..eaaef82 100644 --- a/docs/integration-guide.md +++ b/docs/integration-guide.md @@ -2,21 +2,57 @@ ## Overview -1. **Build and install** the `callback_isolated_executor` packages -2. **Switch the executor** in your application code or launch file -3. **Set up the thread configurator** (one-time system configuration) -4. **Generate a YAML template** by running the configurator in prerun mode -5. **Edit the YAML** to assign scheduling policies, priorities, and CPU affinities -6. **Launch the configurator** with your config file, then start your application +- **Step 0 (Optional): Separate CallbackGroups** so that every callback whose scheduling you want to control gets its own thread +- **Step 1: Install** the `callback_isolated_executor` packages +- **Step 2: Switch the executor** in your application code or launch file +- **Step 3: Generate a YAML template** by running the configurator in prerun mode +- **Step 4: Edit the YAML** to assign scheduling policies, priorities, and CPU affinities +- **Step 5: Grant `CAP_SYS_NICE`** to the thread configurator (one-time system configuration) +- **Step 6: Launch the configurator** with your config file, then start your application See the [Tutorial](tutorial.md) for a concrete walkthrough with the sample application. -## Step 1: Build and Install +## Step 0 (Optional): Separate CallbackGroups + +`CallbackIsolatedExecutor` assigns one OS thread per CallbackGroup, so the CallbackGroup is the unit of +scheduling: callbacks in the same group share a thread and therefore share scheduling parameters. Give +every callback whose scheduling you want to control its own dedicated CallbackGroup: + +```cpp +timer_group_ = create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive); +timer_ = create_wall_timer(100ms, std::bind(&MyNode::on_timer, this), timer_group_); + +sub_group_ = create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive); +rclcpp::SubscriptionOptions sub_options; +sub_options.callback_group = sub_group_; +subscription_ = create_subscription("topic", 10, callback, sub_options); +``` + +If callbacks were placed in one `MutuallyExclusive` group only to serialize access to shared state, +move them into separate groups and protect the shared state with a mutex instead (see +[Concurrency](#notes-on-adoption)). + +## Step 1: Install + +### Option A: apt + +`callback_isolated_executor` is released on the ROS 2 build farm. Binaries are available for Humble; +Jazzy is registered but its binaries may not be on `packages.ros.org` yet: + +```bash +sudo apt install ros-$ROS_DISTRO-callback-isolated-executor +# Optional: the sample application used in the Tutorial +sudo apt install ros-$ROS_DISTRO-cie-sample-application +``` + +If `apt` cannot find the package for your distribution, build from source (Option B). + +### Option B: Build from source ```bash git clone https://github.com/autowarefoundation/callback_isolated_executor.git cd callback_isolated_executor -source /opt/ros/humble/setup.bash +source /opt/ros/$ROS_DISTRO/setup.bash colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release source install/setup.bash ``` @@ -98,30 +134,110 @@ Alternatively, load a node into an existing container: If you modify application source code (Option 1), rebuild before continuing. -## Step 3: Set Up the Thread Configurator +## Step 3: Generate a YAML Template -The `cie_thread_configurator` applies the scheduling parameters from your YAML file to each -CallbackGroup's thread. It needs the `CAP_SYS_NICE` capability to issue syscalls such as -`sched_setscheduler(2)`. +Open two terminals. In the first, start the `prerun` node **before** launching your application; in the +second, launch your application. The prerun node does not need any special privileges. -### Grant capabilities +```bash +# Terminal 1: start the prerun node first +ros2 run cie_thread_configurator prerun_node +# or: ros2 launch cie_thread_configurator thread_configurator.launch.xml prerun:=true + +# Terminal 2: then launch your application +ros2 launch your_package your_launch.xml +``` + +As the application starts, the prerun node logs one entry per CallbackGroup, each showing the +CallbackGroup ID and its OS thread ID. Once all nodes are up and the log output settles, press +`Ctrl+C` in the prerun terminal. A `template.yaml` is created in the current directory. Then stop the +target application. + +The template captures hardware information from the system (CPU details via `lscpu`) under +`hardware_info`. This is used to validate compatibility when the configuration is later loaded. See the +[YAML Specification](yaml-specification.md) for the full format. + +## Step 4: Edit the YAML + +Rename and edit the template to configure each CallbackGroup: ```bash -sudo setcap cap_sys_nice+ep ./build/cie_thread_configurator/thread_configurator_node +mv template.yaml your_config.yaml ``` -### Configure library paths +For CallbackGroups that do not require configuration, either delete the entry or leave it unchanged — +the defaults in `template.yaml` use the standard CFS scheduler with the default nice value and no +affinity. See the [YAML Specification](yaml-specification.md) for every available option. + +## Step 5: Grant CAP_SYS_NICE to the Thread Configurator + +The `cie_thread_configurator` applies the scheduling parameters from your YAML file to the threads of +other processes through `sched_setscheduler(2)`, `sched_setattr(2)`, `setpriority(2)`, and +`sched_setaffinity(2)`. These calls require the `CAP_SYS_NICE` capability. There are two ways to grant +it. + +### Option 1: systemd service with AmbientCapabilities (easiest) + +Ambient capabilities are inherited across `execve`, so `ros2 run` and the node binary receive +`CAP_SYS_NICE` without modifying the binary and without the dynamic-linker restrictions described in +Option 2. + +Create `/etc/systemd/system/thread_configurator.service`: + +```ini +[Unit] +Description=CIE thread configurator + +[Service] +User= +AmbientCapabilities=CAP_SYS_NICE +# Match the target application's ROS environment. If these differ, discovery fails silently and the +# configurator never receives any CallbackGroup. +# Environment=ROS_DOMAIN_ID=0 +# Environment=RMW_IMPLEMENTATION=rmw_cyclonedds_cpp +# Environment=ROS_LOCALHOST_ONLY=1 # Humble; ROS_AUTOMATIC_DISCOVERY_RANGE on Jazzy +ExecStart=/bin/bash -c 'source /opt/ros//setup.bash && exec ros2 run cie_thread_configurator thread_configurator_node --ros-args -p config_file:=/absolute/path/to/your_config.yaml' + +[Install] +WantedBy=multi-user.target +``` + +Replace `` with your ROS 2 distribution (`humble` or `jazzy`); a unit file cannot expand +`$ROS_DISTRO`. For a source build, source your workspace's `install/setup.bash` instead. Then load and +start the service: + +```bash +sudo systemctl daemon-reload +sudo systemctl start thread_configurator # or: sudo systemctl enable --now thread_configurator +journalctl -u thread_configurator -f # follow the configurator's log +``` + +### Option 2: setcap on the binary + +```bash +sudo setcap cap_sys_nice+ep \ + $(ros2 pkg prefix cie_thread_configurator)/lib/cie_thread_configurator/thread_configurator_node +``` + +File capabilities are attached to the binary itself, so re-run this after every rebuild or package +upgrade. + +#### Configure library paths After `setcap`, the dynamic linker ignores `LD_PRELOAD` and `LD_LIBRARY_PATH` for security reasons. Register the required library directories explicitly by creating a file under `/etc/ld.so.conf.d/` whose name ends in `.conf` — for example `/etc/ld.so.conf.d/callback-isolated-executor.conf`: ```text -/opt/ros/humble/lib -/opt/ros/humble/lib/x86_64-linux-gnu -/path/to/callback_isolated_executor/install/cie_config_msgs/lib +/opt/ros//lib +/opt/ros//lib/-linux-gnu ``` +Replace `` with your ROS 2 distribution and `` with your architecture (`x86_64` or +`aarch64`; check with `ls /opt/ros/$ROS_DISTRO/lib | grep linux-gnu`). For a source build, also add the +`lib` directory of `cie_config_msgs` in your install space, for example +`/path/to/callback_isolated_executor/install/cie_config_msgs/lib`. + Apply the change: ```bash @@ -153,44 +269,11 @@ sudo update-grub sudo reboot ``` -## Step 4: Generate a YAML Template - -Open two terminals. In the first, start the `prerun` node **before** launching your application; in the -second, launch your application. - -```bash -# Terminal 1: start the prerun node first -ros2 run cie_thread_configurator prerun_node -# or: ros2 launch cie_thread_configurator thread_configurator.launch.xml prerun:=true - -# Terminal 2: then launch your application -ros2 launch your_package your_launch.xml -``` - -As the application starts, the prerun node logs one entry per CallbackGroup, each showing the -CallbackGroup ID and its OS thread ID. Once all nodes are up and the log output settles, press -`Ctrl+C` in the prerun terminal. A `template.yaml` is created in the current directory, then stop the -target application. - -The template captures hardware information from the system (CPU details via `lscpu`) under -`hardware_info`. This is used to validate compatibility when the configuration is later loaded. See the -[YAML Specification](yaml-specification.md) for the full format. - -## Step 5: Edit the YAML - -Rename and edit the template to configure each CallbackGroup: - -```bash -mv template.yaml your_config.yaml -``` - -For CallbackGroups that do not require configuration, either delete the entry or leave it unchanged — -the defaults in `template.yaml` use the standard CFS scheduler with the default nice value and no -affinity. See the [YAML Specification](yaml-specification.md) for every available option. - ## Step 6: Launch with the Scheduler Configuration -Start the configurator node with your config file **before** launching the target application: +Start the configurator node with your config file **before** launching the target application. If you +created the systemd service in Step 5, `systemctl start thread_configurator` already does this; +otherwise run: ```bash ros2 run cie_thread_configurator thread_configurator_node --ros-args -p config_file:=your_config.yaml @@ -218,8 +301,9 @@ configurator node is terminated. !!! note "SCHED_DEADLINE requires root" A thread cannot be set to `SCHED_DEADLINE` with capabilities alone, so if any CallbackGroup uses - `SCHED_DEADLINE`, the configurator must run as **root**. If the target application runs under a - specific `ROS_DOMAIN_ID`, the configurator must use the same domain ID: + `SCHED_DEADLINE`, the configurator must run as **root** (with the systemd service, omit `User=`). + If the target application runs under a specific `ROS_DOMAIN_ID`, the configurator must use the same + domain ID: ```bash sudo bash -c "export ROS_DOMAIN_ID=[app domain id]; \ diff --git a/docs/tutorial.md b/docs/tutorial.md index fc800b6..c0b4b7c 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -4,9 +4,17 @@ This tutorial walks through the full workflow with the `cie_sample_application` application under `CallbackIsolatedExecutor`, generate a thread configuration template, apply scheduling parameters, and verify the result. -It assumes you have already completed [Build and Install](integration-guide.md#step-1-build-and-install) -and the [thread configurator setup](integration-guide.md#step-3-set-up-the-thread-configurator) (granting -capabilities and configuring library paths). +It assumes you have already [installed the packages](integration-guide.md#step-1-install) and +[granted `CAP_SYS_NICE`](integration-guide.md#step-5-grant-cap_sys_nice-to-the-thread-configurator) to +the thread configurator. The sample application is available from apt: + +```bash +sudo apt install ros-$ROS_DISTRO-cie-sample-application +``` + +The configurator is run interactively in a terminal below, which corresponds to the `setcap` option. If +you set it up as a systemd service instead, start the service in place of the Terminal 1 command in +Step 4. ## Sample Application @@ -49,22 +57,22 @@ abbreviated here): ```yaml hardware_info: - model_name: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz cpu_family: 6 - model: 85 - threads_per_core: 1 - frequency_boost: enabled cpu_max_mhz: 2101.0000 cpu_min_mhz: 800.0000 + frequency_boost: enabled + model: 85 + model_name: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz + threads_per_core: 1 callback_groups: - # default group: /parameter_events + parameter services (full id generated by prerun) - - id: /sample_space/sample_subspace/sample_node@Subscription(/parameter_events)@Service(...) + # default group: parameter services + /parameter_events (full id generated by prerun) + - id: /sample_space/sample_subspace/sample_node@Service(.../describe_parameters)@Service(...)@Subscription(/parameter_events) affinity: ~ policy: SCHED_OTHER nice: 0 - - id: /sample_space/sample_subspace/sample_node@Timer(3000000000) + - id: /sample_space/sample_subspace/sample_node@Subscription(/sample_space/sample_subspace/topic_in) affinity: ~ policy: SCHED_OTHER nice: 0 @@ -74,7 +82,7 @@ callback_groups: policy: SCHED_OTHER nice: 0 - - id: /sample_space/sample_subspace/sample_node@Subscription(/sample_space/sample_subspace/topic_in) + - id: /sample_space/sample_subspace/sample_node@Timer(3000000000) affinity: ~ policy: SCHED_OTHER nice: 0 diff --git a/docs/yaml-specification.md b/docs/yaml-specification.md index 5f64f4d..5290002 100644 --- a/docs/yaml-specification.md +++ b/docs/yaml-specification.md @@ -138,10 +138,18 @@ callback contained in the CallbackGroup. There are four callback types: - `Client()` - `Timer()` -For example: +The callback entries within an ID are sorted alphabetically, so an ID does not depend on the order in +which the callbacks were created; prerun also writes the `callback_groups` list sorted by ID. For +example, the default CallbackGroup of `/sample_node` (parameter services plus the +`/parameter_events` subscription) and two user-defined groups look like this: ```yaml callback_groups: + - id: /sample_node@Service(/sample_node/describe_parameters)@Service(/sample_node/get_parameter_types)@Service(/sample_node/get_parameters)@Service(/sample_node/list_parameters)@Service(/sample_node/set_parameters)@Service(/sample_node/set_parameters_atomically)@Subscription(/parameter_events) + affinity: ~ + policy: SCHED_OTHER + nice: 0 + - id: /sample_node@Subscription(/topic_in) affinity: ~ policy: SCHED_OTHER @@ -163,17 +171,10 @@ callback_groups: ## non_ros_threads -Threads that are not part of any ROS 2 executor can also be configured. The fields match -`callback_groups` except that `id` is the thread name (see [Non-ROS Threads](non-ros-threads.md) for -how to create such threads): - -| Field | Required | Description | -|-------|----------|-------------| -| `id` | Yes | Thread name (must match the name passed to `spawn_non_ros2_thread`) | -| `policy` | Yes | Scheduling policy (same options as `callback_groups`) | -| `nice` | CFS policies only | Nice value, `-20` … `19` | -| `priority` | `SCHED_FIFO` / `SCHED_RR` only | Real-time priority, `1` … `99` | -| `affinity` | No | List of CPU cores | +Threads that are not part of any ROS 2 executor can also be configured. The fields are identical to +[`callback_groups`](#callback_groups), including the `SCHED_DEADLINE` parameters, except that `id` is +the thread name passed to `spawn_non_ros2_thread` (see [Non-ROS Threads](non-ros-threads.md) for how +to create such threads): ```yaml non_ros_threads: @@ -204,13 +205,13 @@ section automatically. ```yaml hardware_info: - model_name: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz cpu_family: 6 - model: 85 - threads_per_core: 1 - frequency_boost: enabled cpu_max_mhz: 2101.0000 cpu_min_mhz: 800.0000 + frequency_boost: enabled + model: 85 + model_name: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz + threads_per_core: 1 callback_groups: - id: /camera_node@Subscription(/camera/image) diff --git a/mkdocs.yaml b/mkdocs.yaml index f8efc74..ef4fcc3 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -7,6 +7,8 @@ site_url: https://autowarefoundation.github.io/callback_isolated_executor_doc repo_url: https://github.com/autowarefoundation/callback_isolated_executor repo_name: autowarefoundation/callback_isolated_executor docs_dir: docs +validation: + anchors: warn copyright: Copyright © 2026 The Autoware Foundation theme: