Skip to content

{bp-19972} sched/sporadic: fix policy switch and cross-task setparam - #20074

Merged
xiaoxiang781216 merged 2 commits into
apache:releases/13.0from
jerpelea:bp-19972
Sep 7, 2026
Merged

{bp-19972} sched/sporadic: fix policy switch and cross-task setparam#20074
xiaoxiang781216 merged 2 commits into
apache:releases/13.0from
jerpelea:bp-19972

Conversation

@jerpelea

@jerpelea jerpelea commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes two bugs in the SCHED_SPORADIC handling of the scheduler, both found while testing sporadic policy switching:

sched_setscheduler(): The policy flag bits were cleared before the switch (policy) statement. Since TCB_FLAG_SCHED_FIFO is 0, the checks for "was the task previously SCHED_SPORADIC" inside the SCHED_FIFO/SCHED_RR cases could never be true. As a result nxsched_stop_sporadic() was never called when a sporadic task switched to another policy, leaking the sporadic state and its replenishment timers; a sporadic-to-sporadic reconfiguration ran nxsched_initialize_sporadic() instead of reset, leaking the old state. The flags are now cleared only after the previous policy has been evaluated.

sched_setparam(): set_sporadic_param() tested rtcb (the calling task) instead of tcb (the task being modified). A cross-task sched_setparam() therefore never updated the target's sporadic parameters, and if the caller was itself sporadic while the target was not, it would reset a task with no sporadic state (NULL-pointer / assertion failure) and write parameters into the caller's own sporadic state.

Impact

RELEASE

Testing

CI

…ADIC

The policy flag bits were cleared before the switch statement, so the
checks testing whether the task was previously SCHED_SPORADIC could
never be true.  As a result nxsched_stop_sporadic() was never called
when a sporadic task switched to SCHED_FIFO/SCHED_RR, leaking the
sporadic state, and a sporadic-to-sporadic reconfiguration ran
initialize instead of reset.

Clear the policy flag bits only after the previous policy has been
evaluated, right before the new policy bits are set.

Signed-off-by: yushuailong <yyyusl@qq.com>
set_sporadic_param() tested rtcb (the calling task) instead of tcb (the
task being modified).  A cross-task sched_setparam() therefore either
skipped the sporadic parameter update entirely or, when the calling
task was itself sporadic, reset a task that had no sporadic state.

Use tcb consistently and drop the now-unused rtcb argument.

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 Sep 7, 2026
@jerpelea

jerpelea commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

CI fix
apache/nuttx-apps#3775

@xiaoxiang781216
xiaoxiang781216 merged commit 0aaec9d into apache:releases/13.0 Sep 7, 2026
21 of 41 checks passed
@jerpelea
jerpelea deleted the bp-19972 branch September 7, 2026 11:38
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.

4 participants