sched: Fix and centralize sporadic parameter validation - #20084
Open
yushuailong wants to merge 4 commits into
Open
sched: Fix and centralize sporadic parameter validation#20084yushuailong wants to merge 4 commits into
yushuailong wants to merge 4 commits into
Conversation
yushuailong
requested review from
GUIDINGLI,
anchao,
gustavonihei,
jerpelea,
pussuw and
xiaoxiang781216
as code owners
September 7, 2026 13:41
|
Commit 2ec7d90 refactored sched_setparam() into set_sporadic_param() but moved the apply logic into the former reject branch without inverting the condition. As a result sched_setparam() rejects valid sporadic parameters (repl >= 2 * budget) with EINVAL and accepts invalid ones, tripping the DEBUGASSERT in sched_sporadic.c or wrapping the replenishment calculation. Invert the condition to match process_sporadic() in sched_setscheduler.c. Fixes: 2ec7d90 ("sched_setparam.c: coverity HIS_metric_violation: RETURN") Assisted-by: OpenAI Codex Signed-off-by: yushuailong <yyyusl@qq.com>
nxsched_set_param() applied the sporadic parameters and restarted the replenishment timer in set_sporadic_param() before nxsched_reprioritize() rejected an out-of-range priority with EINVAL, leaving stale sporadic state (e.g. a truncated hi_priority) behind on failure. Validate sched_priority up front so the error path is atomic. Assisted-by: OpenAI Codex Signed-off-by: yushuailong <yyyusl@qq.com>
yushuailong
force-pushed
the
fix/sched-sporadic
branch
from
September 8, 2026 02:17
204f225 to
d7057a4
Compare
Sporadic scheduling parameters are processed independently by sched_setparam(), sched_setscheduler(), and pthread_create(). The three paths currently validate different subsets of the parameters. In particular, pthread_create() does not validate sched_ss_max_repl and only requires the replenishment period to be greater than the budget, while the scheduler interfaces enforce the implementation's 50 percent duty-cycle limit. Add nxsched_validate_sporadic() to validate the common parameters and convert the replenishment period and budget to ticks. Use it from all paths that directly initialize or update sporadic scheduler state. Express the duty-cycle check using division to avoid overflow when doubling a clock_t value. Assisted-by: OpenAI Codex Signed-off-by: yushuailong <yyyusl@qq.com>
spawn_execattrs() discards the return value from nxsched_set_scheduler(). As a result, an invalid scheduling policy or parameter is silently ignored and the spawn operation continues with the original scheduling configuration. Store and return the result from nxsched_set_scheduler() so that the caller can tear down the child task when applying the requested scheduler attributes fails. Update the function comments to describe the existing error return behavior. Assisted-by: OpenAI Codex Signed-off-by: yushuailong <yyyusl@qq.com>
yushuailong
force-pushed
the
fix/sched-sporadic
branch
from
September 10, 2026 03:37
d7057a4 to
2963e44
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The sched_setparam() validation condition was inverted during an earlier refactoring, causing valid sporadic parameters to be rejected and invalid parameters to be applied.
The sporadic parameter checks were also duplicated across several paths and were inconsistent. In particular, pthread_create() did not validate sched_ss_max_repl and did not enforce the scheduler implementation's 50 percent duty-cycle restriction.
This change introduces nxsched_validate_sporadic() as the common validation path. It also performs validation before modifying sporadic state, preventing failed calls from leaving partially updated scheduling parameters or timers.
Impact
Bug fix only; no new features.
Testing
sim:ostestwithCONFIG_SCHED_SPORADIC=y,CONFIG_SCHED_SPORADIC_MAXREPL=3, andCONFIG_PRIORITY_INHERITANCE=y.makecompletes successfully withLD: nuttx../nuttx; all enabled OSTest subtests completed without assertions or unexpected errors.nxstyle,checkpatch, and commit-message checks pass.