Skip to content

Guard scheduler_tuning float clamping against NaN and add unit tests - #8202

Merged
hkaiser merged 2 commits into
TheHPXProject:masterfrom
shivansh023023:fix/scheduler-tuning-nan-and-tests
Nov 24, 2026
Merged

hkaiser merged 2 commits into
TheHPXProject:masterfrom
shivansh023023:fix/scheduler-tuning-nan-and-tests

Conversation

@shivansh023023

Copy link
Copy Markdown
Contributor

Proposed Changes

  1. Guard tuning_parameter_info::clamped<float> against NaN (scheduler_tuning.hpp)

    • std::clamp with a NaN input is undefined behavior / propagates NaN into the atomic parameter slot (for example, if a dynamic tuner divides by zero).
    • Added a std::isnan(value) check for float parameters that falls back to min_value.as<float>(), covering add(), set(), and set_all().
  2. Add unit test coverage (scheduler_tuning.cpp)

    • test_float_clamping: verifies out-of-range values, ±infinity, quiet_NaN(), and signaling_NaN() across add(), set(), and set_all().
    • test_add_setting_errors: verifies hpx::error::bad_parameter is thrown on duplicate parameter names and when exceeding max_parameters (16).
    • test_concurrent_set_all_get: verifies concurrent set_all() updates against multiple reader threads calling get<T>() without out-of-range reads or races.

Verification

  • ./build/bin/inspect --all libs/core/threading_base/ libs/core/schedulers/ — 0 issues.
  • tests.unit.modules.schedulers.scheduler_tuning — passed.
  • tests.unit.modules.threading_base.scheduling_policy_idle_step — passed.

Signed-off-by: Shivansh Singh <singhshivansh023@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Scheduler tuning values now handle NaN inputs consistently by using the configured minimum. Values outside the configured range, including infinities, are clamped to the minimum or maximum.
  • Tests
    • Added coverage for tuning value boundaries, invalid setting registrations, and concurrent updates. Tests verify that values remain finite and within range.

Float tuning values that are NaN now clamp to the configured minimum. Unit tests cover float boundaries, registration errors, and concurrent set_all and get access.

Changes: Scheduler tuning

Layer / File(s) Summary
NaN float clamping
libs/core/threading_base/include/hpx/threading_base/scheduler_tuning.hpp, libs/core/schedulers/tests/unit/scheduler_tuning.cpp
The float clamp returns the configured minimum for NaN inputs. Tests cover compile-time and runtime values, out-of-range values, and infinities. The set and set_all comments document the NaN behavior.
Registration and concurrent-access checks
libs/core/schedulers/tests/unit/scheduler_tuning.cpp
Tests check duplicate names, the 16-setting limit, and concurrent reads during set_all updates. main invokes the added tests.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to 56a61

This change makes floating-point scheduler tuning values fall back to their minimum bound when given NaN. It adds tests for clamping, registration limits and concurrent access. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: NaN guarding in scheduler_tuning float clamping. It also names the unit tests added in the same PR. The raw summary and objectives both describe a NaN fallback to the …
Description check Passed The description states the NaN guard in tuning_parameter_info::clamped, which falls back to min_value for add(), set(), and set_all(). It also lists the three new unit tests and verification co…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: NaN guarding in scheduler_tuning float clamping. It also names the unit tests added in the same PR. The raw summary and objectives both describe a NaN fallback to the minimum bound in tuning_parameter_info::clamped<float>, and the tests described match the title.

Full details: Description check

Explanation

The description states the NaN guard in tuning_parameter_info::clamped<float>, which falls back to min_value for add(), set(), and set_all(). It also lists the three new unit tests and verification commands. These match the raw summary and the objectives.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9e677ac9-ec5c-499e-b515-3f170f67c321
Commits

Reviewing files that changed from the base of the PR and between 11b2935 and 56a61aa.

Files selected for processing: 2

  • libs/core/schedulers/tests/unit/scheduler_tuning.cpp
  • libs/core/threading_base/include/hpx/threading_base/scheduler_tuning.hpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@hkaiser hkaiser 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.

Thanks, a NaN from a tuner shouldn't end up in the setting, and the tests are welcome. Two small things in clamped(): std::isnan is not constexpr before C++23, so clamped<float> can no longer be used in a constant expression; value != value does the same check and keeps it constexpr. And please mention in the doc comments of set() and set_all() that a NaN sets the setting to its minimum, since a tuner wouldn't expect that otherwise.

… NaN behavior

Signed-off-by: Shivansh Singh <singhshivansh023@gmail.com>
@shivansh023023

Copy link
Copy Markdown
Contributor Author

Thanks @hkaiser! Replaced std::isnan(value) with value != value in clamped() to keep it constexpr in C++20 (added static_assert coverage including quiet_NaN()), removed the unused / <type_traits> includes, and updated the doc comments on set() and set_all() to note that NaN sets the setting to its minimum bound.

@hkaiser hkaiser 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.

Thanks, both are done, LGTM.

@hkaiser
hkaiser merged commit 88ab4ba into TheHPXProject:master Nov 24, 2026
159 checks passed
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