Skip to content

fix(cie): always re-apply thread configuration and keep running#49

Merged
sykwer merged 4 commits intomainfrom
fix/always-reapply-thread-config
Apr 22, 2026
Merged

fix(cie): always re-apply thread configuration and keep running#49
sykwer merged 4 commits intomainfrom
fix/always-reapply-thread-config

Conversation

@atsushi421
Copy link
Copy Markdown
Collaborator

@atsushi421 atsushi421 commented Apr 18, 2026

Description

Port the "always re-apply" behavior from agnocast's fix/thread-configurator-always-reapply branch.

  • The configurator now always re-applies scheduling configuration even for already-configured callback groups, handling the case where the OS reuses thread IDs after application restarts
  • The configurator keeps running continuously via executor->spin() instead of exiting after all configurations are applied, enabling automatic re-configuration when target applications restart
  • Removed has_configured_once() and moved the unapplied guard into print_all_unapplied() itself, so main always calls it unconditionally
  • Updated README.md to reflect the new behavior (configurator stays running, SCHED_DEADLINE applied immediately with SCHED_FLAG_RESET_ON_FORK)

Related links

How was this PR tested?

  • Build the package and verify compilation succeeds
  • Run thread_configurator_node with a sample application and verify all configurations are applied
  • Restart the target application and verify the configurator re-applies configurations automatically
  • Verify the configurator does not exit after initial configuration

Notes for reviewers

The key behavioral changes are:

  1. callback_group_callback and non_ros_thread_callback no longer early-return when config->applied is true — they always re-apply the configuration
  2. on_all_configured() fires only once (guarded by configured_at_least_once_), and unapplied_num_ is only decremented on the first apply
  3. The main loop uses executor->spin() instead of spin_once() in a while loop, so the configurator node stays alive indefinitely
  4. has_configured_once() / all_applied() removed; print_all_unapplied() now self-guards with an early return when unapplied_num_ == 0
  5. The interactive "Press enter to exit" prompt for cgroup cleanup is removed; cgroups are now cleaned up in the destructor when the node is terminated

Port the "always re-apply" behavior from agnocast's
fix/thread-configurator-always-reapply branch. The configurator now:

- Always re-applies scheduling configuration when a CallbackGroupInfo
  or NonRosThreadInfo message is received, even if the callback group
  was already configured. This handles the case where the OS reuses
  thread IDs after an application restarts.
- Keeps running via executor->spin() instead of exiting after all
  configurations are applied, enabling automatic re-configuration
  when target applications restart.
- Tracks configured_at_least_once_ to report unapplied threads only
  when the configurator is terminated before any complete round.

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
Copilot AI review requested due to automatic review settings April 18, 2026 04:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the ROS 2 thread configurator to continuously run and to always re-apply thread scheduling/affinity configuration when thread info is received, so configurations are re-enforced after target applications restart (including cases where the OS reuses thread IDs).

Changes:

  • Switch the main executable to executor->spin() (continuous operation) and only report unapplied configs on shutdown if nothing was ever fully configured.
  • Always re-apply configuration even when a callback group / non-ROS thread was previously marked as applied; add “all configured” notification + has_configured_once() tracking.
  • Update the top-level README to document continuous operation and SCHED_DEADLINE behavior (SCHED_FLAG_RESET_ON_FORK).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
cie_thread_configurator/src/thread_configurator_node_main.cpp Runs executor continuously; changes shutdown reporting behavior.
cie_thread_configurator/src/thread_configurator_node.cpp Removes “skip if applied” logic and adds “all configured” tracking/logging.
cie_thread_configurator/include/cie_thread_configurator/thread_configurator_node.hpp Updates public API (removes all_applied, adds has_configured_once/state).
README.md Documents continuous-running configurator and SCHED_DEADLINE semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cie_thread_configurator/src/thread_configurator_node.cpp
Comment thread cie_thread_configurator/src/thread_configurator_node.cpp Outdated
Comment thread cie_thread_configurator/src/thread_configurator_node_main.cpp Outdated
After the first full configuration cycle, unapplied_num_ stays at 0
and all configs have applied=true. When a target app restarts and
re-sends callback info, on_all_configured() was called for every
single re-apply message because unapplied_num_==0 was always true.
Guard the call with !configured_at_least_once_ so the "all configured"
log fires only once during the initial configuration round.

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
When the YAML contains zero configured threads, call on_all_configured()
during construction so has_configured_once() returns true and the
shutdown path does not misleadingly warn about unapplied configs.

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
Move the unapplied check into print_all_unapplied() itself so main
always calls it unconditionally, and remove the now-unused
has_configured_once() method.

Upstream: autowarefoundation/agnocast#1262
Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
@atsushi421 atsushi421 requested a review from sykwer April 20, 2026 01:09
@sykwer sykwer merged commit fbca058 into main Apr 22, 2026
3 checks passed
@sykwer sykwer deleted the fix/always-reapply-thread-config branch April 22, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reentrant callback group TODOs

3 participants