fdcavalcanti opened a new pull request, #17969:
URL: https://github.com/apache/nuttx/pull/17969
- sched/sched_roundrobin.c: fix round-robin scheduling in SMP mode
In SMP mode, running tasks are in g_assignedtasks[cpu], not the ready-to-run
list, so tcb->flink is NULL. When a round-robin timeslice expires, checking
tcb->flink fails to find the next task.
Fix by calling nxsched_switch_running() directly in SMP mode when the
timeslice expires, which properly finds the next eligible task from the
ready-to-run list.
## Summary
This fixes #17828 and ESP32 `ostest` errors on `rr_test`.
In NuttX SMP, when a round-robin task’s timeslice expires, the code tried to
find the next task by checking `tcb->flink` (the next task in the ready-to-run
list). In SMP, running tasks are stored in `g_assignedtasks[cpu]`, not in the
ready-to-run list, so `tcb->flink` is NULL. This prevented finding the next
task and caused the round-robin test to fail.
### Fixing
Instead of checking `tcb->flink`, we call `nxsched_switch_running()`
directly. This function:
- Looks in the ready-to-run list for the next eligible task
- Handles SMP-specific logic
- Returns true if a switch should occur
### Main changes
Before (broken):
```c
if (tcb->flink && tcb->flink->sched_priority >= tcb->sched_priority)
{
// Switch to next task
}
```
This failed because `tcb->flink` was NULL in SMP mode.
After (fixed):
```c
else if (nxsched_switch_running(tcb->cpu, true))
{
up_switch_context(this_task(), rtcb);
}
```
This directly uses the scheduler function that knows how to find the next
task in SMP mode.
## Impact
Impact on user: Round-robin scheduling (SCHED_RR) works correctly in SMP
mode. Applications using round-robin scheduling will now properly alternate
between tasks of the same priority.
<!-- Does it impact user's applications? How? -->
Impact on build: No.
<!-- Does it impact on building NuttX? How? (please describe the required
changes on the build system) -->
Impact on hardware: Only affects SMP-capable hardware. No hardware changes
required.
<!-- Does it impact a specific hardware supported by NuttX? -->
Impact on documentation: No.
<!-- Does it impact the existing documentation? Please provide additional
documentation to reflect that -->
Impact on security: No.
<!-- Does it impact NuttX's security? -->
Impact on compatibility: No.
<!-- Does it impact compatibility between previous and current versions? Is
this a breaking change? -->
## Testing
`ostest` is passing on SMP ESP32 and ESP32S3.
Internal CI shows no errors regarding scheduler.
Fixes issues on network when SMP is enabled (getting stuck on downloads).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]