Skip to content

sched/sched: Fix uninitialized sporadic params returned by nxsched_get_param() - #19587

Open
yushuailong wants to merge 1 commit into
apache:masterfrom
yushuailong:fix-sched-getparam-sporadic
Open

sched/sched: Fix uninitialized sporadic params returned by nxsched_get_param()#19587
yushuailong wants to merge 1 commit into
apache:masterfrom
yushuailong:fix-sched-getparam-sporadic

Conversation

@yushuailong

Copy link
Copy Markdown
Contributor

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 valid sched_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 concurrent sched_setscheduler(). No API/ABI change; no impact on build, hardware or documentation. Configurations without CONFIG_SCHED_SPORADIC are functionally unchanged.

Testing

ci test

…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>
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Jul 31, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants