Skip to content

fix(cie): take 'nice' instead of 'priority' for CFS policies - #62

Merged
atsushi421 merged 2 commits into
mainfrom
fix/cie-cfs-nice-key
Aug 17, 2026
Merged

atsushi421 merged 2 commits into
mainfrom
fix/cie-cfs-nice-key

Conversation

@atsushi421

Copy link
Copy Markdown
Collaborator

Description

For SCHED_OTHER / SCHED_BATCH / SCHED_IDLE entries, the value configured under the priority key has always been applied as a nice value via setpriority(2) (the sched_priority passed to sched_setscheduler(2) is fixed to 0 for these policies). Reusing the priority key for that was misleading and error-prone:

  • For SCHED_FIFO / SCHED_RR, priority means rt_priority (1..99, higher is stronger), while nice runs the opposite way (-20..19, lower is stronger). The same key name flips its meaning depending on the policy.
  • setpriority(2) silently clamps out-of-range values to [-20, 19], so writing an rt_priority-style value (e.g. priority: 50) on a CFS entry demoted the thread to the lowest priority without any error.
  • The kernel API itself separates the two fields (sched_attr.sched_nice vs sched_attr.sched_priority).

This PR makes the scheduling-parameter key policy-dependent, porting autowarefoundation/agnocast#1529 to this repository:

  • SCHED_OTHER / SCHED_BATCH / SCHED_IDLE entries now take nice, validated against [-20, 19].
  • SCHED_FIFO / SCHED_RR entries keep priority, now validated against [1, 99] (previously unvalidated).
  • SCHED_DEADLINE entries are unchanged (runtime / period / deadline).
  • A missing key is rejected at startup with a message naming the required one; a stray key of the other policy class is simply ignored, like any other unknown key.
  • ThreadConfig mirrors the split: it now carries separate nice and priority fields instead of one field whose meaning depended on the policy.

Breaking change: there is no compatibility alias. Existing YAMLs that set priority on a SCHED_OTHER / SCHED_BATCH / SCHED_IDLE entry are rejected at startup and must rename the key to nice (the value itself is unchanged; it was always a nice value).

Other changes:

  • prerun_node now emits nice: 0 for the SCHED_OTHER entries in the generated template.
  • The README's YAML examples and the CFS section are updated to the nice key, and both range validations are documented.
  • A new unit test (test_thread_configurator_node.cpp) exercises the validation through the public ThreadConfiguratorNode constructor with the config_file parameter: acceptance across the three CFS policies and both RT policies, stray other-class keys being ignored, and rejection of missing / null / non-integer / out-of-range values including the legacy priority key on a CFS entry.

Related links

How was this PR tested?

  • colcon build --packages-select cie_thread_configurator --cmake-args -DBUILD_TESTING=ON
  • test_thread_configurator_node (12 new tests) and test_util (9 existing tests) all pass.

Notes for reviewers

Post-merge checklists

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
- Add SCHED_IDLE to the README policy list and CFS description
- Document the new validation errors in the constructor's @throws clause
- Compile thread_configurator_node.cpp once into a static library shared
  by the executable and the test, dropping the redundant include dirs

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
@atsushi421
atsushi421 marked this pull request as ready for review August 17, 2026 08:20
Copilot AI lite review requested due to automatic review settings August 17, 2026 08:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 cie_thread_configurator’s YAML scheduling configuration to use policy-appropriate keys (nice for CFS policies vs priority for RT policies), adds explicit range/type validation with clearer startup failures, and introduces a unit test that exercises this validation through the public ThreadConfiguratorNode API.

Changes:

  • Split scheduling parameters into nice (CFS) and priority (RT) with strict validation and improved error reporting.
  • Update generated YAML templates and documentation examples to use nice for CFS policies.
  • Add a new unit test suite validating acceptance/ignore/rejection cases via ThreadConfiguratorNode construction, and refactor build targets to enable linking node logic into tests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cie_thread_configurator/test/test_thread_configurator_node.cpp New unit tests covering YAML validation behavior for nice/priority across policies.
cie_thread_configurator/src/thread_configurator_node.cpp Implements policy-dependent parsing (nice vs priority) with type/range checks and applies nice via setpriority.
cie_thread_configurator/src/prerun_node.cpp Updates generated template YAML to emit nice: 0 for SCHED_OTHER.
cie_thread_configurator/README.md Updates YAML examples and scheduler documentation to reflect nice for CFS and documents validation ranges.
cie_thread_configurator/include/cie_thread_configurator/thread_configurator_node.hpp Extends ThreadConfig with separate nice and priority fields; updates constructor documentation for new validation behavior.
cie_thread_configurator/CMakeLists.txt Refactors build to introduce a core library for ThreadConfiguratorNode logic and adds the new test target.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cie_thread_configurator/CMakeLists.txt
@atsushi421
atsushi421 enabled auto-merge August 17, 2026 08:29
@atsushi421
atsushi421 merged commit a3e5102 into main Aug 17, 2026
6 checks passed
@atsushi421
atsushi421 deleted the fix/cie-cfs-nice-key branch August 17, 2026 08:32
atsushi421 added a commit to autowarefoundation/callback_isolated_executor_doc that referenced this pull request Aug 17, 2026
Reflect autowarefoundation/callback_isolated_executor#62: CFS entries
(SCHED_OTHER / SCHED_BATCH / SCHED_IDLE) now use the 'nice' key
validated against [-20, 19], while SCHED_FIFO / SCHED_RR keep
'priority' validated against [1, 99]. A missing required key is
rejected at startup; a stray key of the other policy class is ignored.

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
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.

2 participants