fix(thread_configurator): apply scheduling to all reentrant callback group threads#39
fix(thread_configurator): apply scheduling to all reentrant callback group threads#39atsushi421 wants to merge 4 commits intomainfrom
Conversation
…estart Previously, ThreadConfiguratorNode skipped scheduling configuration for duplicate callback_group_ids. Since reentrant callback groups spawn multiple threads sharing the same callback_group_id, only the first thread received scheduling attributes. Fix by distinguishing between duplicate messages (same thread_id -> skip) and new threads (different thread_id -> re-apply). Additionally: - Make the node persistent via executor->spin() with automatic state reset, enabling re-application when target applications restart - Store SCHED_DEADLINE configs by value so each thread's tid is preserved independently - Apply SCHED_DEADLINE configs automatically when unapplied_num_ reaches 0, removing the interactive stdin prompt Signed-off-by: Atsushi Watanabe <atsushi.w@autoware.org> Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
8edce51 to
bc99a1c
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates thread_configurator_node to correctly (re-)apply scheduling/affinity settings for reentrant callback groups that publish multiple thread IDs under the same callback group ID, and to keep the configurator running persistently so configurations can be re-applied when the target application restarts.
Changes:
- Distinguish duplicate thread notifications (same
thread_id) from new threads (differentthread_id) and re-apply configuration for newly detected threads. - Make the configurator run persistently (
executor->spin()), remove interactivestdinprompts, and auto-applySCHED_DEADLINEonce registration completes. - Store
SCHED_DEADLINEconfigs by value to preserve per-threadthread_id, and reset internal state after applying.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| README.md | Updates user-facing behavior docs (auto-apply SCHED_DEADLINE, persistent node, Ctrl+C exit). |
| cie_thread_configurator/src/thread_configurator_node.cpp | Implements per-thread reapplication logic, value-stored deadline configs, auto-apply + state reset. |
| cie_thread_configurator/src/main.cpp | Switches to persistent spinning and updates shutdown-time reporting. |
| cie_thread_configurator/include/cie_thread_configurator/thread_configurator_node.hpp | Updates public API (remove old apply/all_applied helpers, add has_configured_once, change deadline storage type). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Reset for re-application when target applications restart | ||
| unapplied_num_ = thread_configs_.size(); | ||
| for (auto &config : thread_configs_) { | ||
| config.applied = false; | ||
| } |
There was a problem hiding this comment.
apply_deadline_configs() resets unapplied_num_ and clears all config.applied immediately after the first time unapplied_num_ reaches 0. Because ROS messages are processed sequentially, it’s possible to hit 0 and reset while additional CallbackGroupInfo/NonRosThreadInfo messages are still queued (e.g., reentrant callback groups publishing multiple thread IDs). Those later messages will start a new “cycle”, and if the other callback groups don’t republish, unapplied_num_ may never reach 0 again—leaving newly queued SCHED_DEADLINE configs unapplied. It also re-enables re-applying configs for duplicate messages with the same thread_id after a cycle completes (since applied is forced back to false).
Consider separating “cycle reset” from apply_deadline_configs() (e.g., debounce deadline application, reset only on confirmed app restart, or keep a per-(id,thread_id) configured set so duplicates are skipped across cycles) so late-arriving thread notifications still get configured.
| // Reset for re-application when target applications restart | |
| unapplied_num_ = thread_configs_.size(); | |
| for (auto &config : thread_configs_) { | |
| config.applied = false; | |
| } |
- Apply SCHED_DEADLINE immediately after first cycle for late-arriving reentrant threads, avoiding configs stuck in deferred queue when other groups won't re-report - Track failures in apply_deadline_configs() and log accurate success/failure message instead of unconditional "Success" - Clarify README that cgroup cleanup on exit is best-effort and may require manual removal if target app threads are still attached Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
This reverts commit 6be14fb.
Accept PR review suggestion: cgroup removal on exit only succeeds if the target application has already stopped and no threads remain attached. Users may need to stop the app first or manually remove remaining cgroups. Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
Description
Previously,
ThreadConfiguratorNodehad two issues with reentrant callback groups:callback_group_id. The node skipped subsequent threads as "already configured".This PR fixes both by:
thread_id→ skip) and new threads (differentthread_id→ re-apply)executor->spin()with automatic state reset after all configs are appliedSCHED_DEADLINEconfigs by value (not pointer) so each thread'stidis preserved independentlySCHED_DEADLINEconfigs whenunapplied_num_reaches 0, removing the interactivestdinpromptRelated links
How was this PR tested?
Ran
thread_configurator_nodewith a YAML config (SCHED_OTHER, nice=5) alongsidereentrant_node_main(4 reentrant threads). Verified:nicevalues confirmed via/proc/<tid>/statfor all threadsNotes for reviewers
Thread configurator behavior changes