sched/sched: Fix uninitialized sporadic params returned by nxsched_get_param() - #19587
Open
yushuailong wants to merge 1 commit into
Open
sched/sched: Fix uninitialized sporadic params returned by nxsched_get_param()#19587yushuailong wants to merge 1 commit into
yushuailong wants to merge 1 commit into
Conversation
…t_param() When querying the calling task itself (pid == 0 or the caller's own pid), nxsched_get_param() only filled in sched_priority and never touched the SCHED_SPORADIC related members (sched_ss_low_priority, sched_ss_max_repl, sched_ss_repl_period and sched_ss_init_budget). With CONFIG_SCHED_SPORADIC enabled, the caller received uninitialized stack garbage in these fields, and a task running under the sporadic policy could not retrieve its own sporadic parameters. Fix this by factoring the sporadic parameter fill-in into a common helper nxsched_get_sporadic_param() shared by both the self-query and the lookup paths, so both paths now return identical information. The self-query path keeps its original fast-path behavior: no TCB lookup and a lock-free read of sched_priority. Only the read of the sporadic state is wrapped in a critical section, because tcb->sporadic may be freed concurrently, e.g. by sched_setscheduler() from another CPU switching the task away from SCHED_SPORADIC. Signed-off-by: yushuailong <yyyusl@qq.com>
xiaoxiang781216
approved these changes
Jul 31, 2026
jerpelea
approved these changes
Jul 31, 2026
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
When querying the calling task itself (pid == 0 or the caller's own pid), nxsched_get_param() only filled in sched_priority and never touched the SCHED_SPORADIC related members (sched_ss_low_priority, sched_ss_max_repl, sched_ss_repl_period and sched_ss_init_budget). With CONFIG_SCHED_SPORADIC enabled, the caller received uninitialized stack garbage in these fields, and a task running under the sporadic policy could not retrieve its own sporadic parameters.
Fix this by factoring the sporadic parameter fill-in into a common helper nxsched_get_sporadic_param() shared by both the self-query and the lookup paths, so both paths now return identical information.
The self-query path keeps its original fast-path behavior: no TCB lookup and a lock-free read of sched_priority. Only the read of the sporadic state is wrapped in a critical section, because tcb->sporadic may be freed concurrently, e.g. by sched_setscheduler() from another CPU switching the task away from SCHED_SPORADIC.
Impact
Only affects configurations with
CONFIG_SCHED_SPORADIC=y:sched_getparam()/nxsched_get_param()now returns validsched_ss_*members when a task queries itself, instead of uninitialized stack memory. The sporadic state is read inside a critical section to avoid a race with a concurrentsched_setscheduler(). No API/ABI change; no impact on build, hardware or documentation. Configurations withoutCONFIG_SCHED_SPORADICare functionally unchanged.Testing
ci test