Skip to content

Add thread renaming for components - #3482

Open
Nibanovic wants to merge 2 commits into
ros-controls:masterfrom
b-robotized-forks:feat/async-thread-name
Open

Add thread renaming for components#3482
Nibanovic wants to merge 2 commits into
ros-controls:masterfrom
b-robotized-forks:feat/async-thread-name

Conversation

@Nibanovic

@Nibanovic Nibanovic commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Description

Note: Requires fix #3481 to be merged, so we can use async parameters on controllers properly.

Note: Requires this PR on realtime_tools to be merged as well

I was working on distributing ros2 control processing on different cores, and It was nice to rename the threads spawned by async_function_handler, as we can see them more easily in top output.

In this PR, by default we rename the thread spawned to the component name, truncated to 15 chars. Alternatively, we can give the thing a name we want.

Demo:

image

These are the configs for controllers/hardware and the output they produce:

This config for controllers

example_controller:
  ros__parameters:
      type: joint_trajectory_controller/JointTrajectoryController
      is_async: true
      async_parameters:
        scheduling_policy: detached
        thread_priority: 70
        cpu_affinity: [2, 3]
        thread_name: ros_ctrl_jtc

gives these logs:

[INFO] [1784294876.480348261] [controller_manager]: Configuring controller: 'example_controller'
[INFO] [1784294876.480464686] [controller_manager]: Linked async controller 'example_controller' update() to follow async hardware 'maurob_cell_robot' read().
[INFO] [1784294876.480486086] [example_controller]: Starting async handler with scheduler priority: 70
[INFO] [1784294876.480578392] [AsyncFunctionHandler]: Thread name: ros_ctrl_jtc
[INFO] [1784294876.480659950] [example_controller]: No specific joint names are used for command interfaces. Using 'joints' parameter.
[WARN] [1784294876.480661020] [AsyncFunctionHandler]: Async worker thread is successfully pinned to the requested CPU cores! 

And this config for hardware:

<async 
            scheduling_policy="${scheduling_policy}" 
            print_warnings="true" 
            affinity="[2,3]" 
            thread_priority="70"
            thread_name="ros_hw_kuka"
        />

gives these logs:

[INFO] [1784294875.544887049] [controller_manager]: Initialize hardware 'my_kuka_robot'
[INFO] [1784294875.544901150] [controller_manager.hardware_component.system.my_kuka_robot]: Starting async handler with scheduler priority: 70 and policy : detached
[INFO] [1784294875.545115477] [controller_manager.hardware_component.system.my_kuka_robot]: Thread name: ros_hw_kuka
[WARN] [1784294875.545272045] [controller_manager.hardware_component.system.my_kuka_robot]: Async worker thread is successfully pinned to the requested CPU cores!
[INFO] [1784294875.548283067] [controller_manager]: Successful initialization of hardware 'my_kuka_robot' 

Is this user-facing behavior change?

yes, if you muddle around with threads and real-time stuff

Did you use Generative AI?

nah

@destogl

destogl commented Jul 17, 2026

Copy link
Copy Markdown
Member

Can we also update this line to get output to which cores is pinned?

[WARN] [1784294875.545272045] [controller_manager.hardware_component.system.my_kuka_robot]: Async worker thread is successfully pinned to the requested CPU cores!

auto_declare<bool>("is_async", false);
auto_declare<int>("thread_priority", -100);

auto_declare<int>("async_parameters.thread_priority", 50);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For others, this is added in #3481, so ignore it here!

@Nibanovic

Copy link
Copy Markdown
Contributor Author

Can we also update this line to get output to which cores is pinned?

Yeah, but that is on realtime_tools. Opened a PR

@Nibanovic

Copy link
Copy Markdown
Contributor Author

Overview of related PRs:

As per this comment, moved parameter declaraion to realtime_tools/async_function_handler_params.hpp

To sum up, this is the merging order:

  1. declare missing Async parameters realtime_tools#556, to declare the parameters
  2. Add missing controller async parameter declarations #3481, to call the declaration function from controller_interface_base.cpp
  3. finally, this MR, to parameterize renaming of threads

Nice to have, on this topic:

Printing CPU cores we pin threads on PR: ros-controls/realtime_tools#551

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-jazzy Triggers PR backport to ROS 2 jazzy. backport-kilted Triggers PR backport to ROS 2 kilted.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants