schedule: zephyr_ll: protect against a race in task free - #11104
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Zephyr LL scheduler task teardown path to add a defensive validation after waiting in zephyr_ll_task_free(), aiming to avoid a rare race observed during stress tests (user-space LL + chain DMA) where a task can be freed while still active.
Changes:
- Captures the return value of
k_sem_take()inzephyr_ll_task_free()and adds a warning path when the wait result/state is unexpected. - Attempts to force-complete a task during free when the wait result indicates an abnormal condition.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (wait_ret && task->state != SOF_TASK_STATE_FREE) { | ||
| tr_warn(&ll_tr, "task %p still active on free (state %d, semret %d)", | ||
| task, task->state, wait_ret); | ||
| zephyr_ll_task_done(sch, task); | ||
| } |
Add a check to ensure task state is what is expected after k_sem_take() returns in zephyr_ll_task_free(). This is needed to avoid a rare error hit when running stress tests with chain DMA in user-space LL builds. Issue is hard to reproduce, but similar error signature can be created by passing K_NO_WAIT to k_sem_take() and running a test with chain-dma pipeline. Add defensive code that handles this scenario and prints out a warning when unexpected return occurs. Tested with a custom build with K_NO_WAIT passed to k_sem_take(). Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
9c640a2 to
7f69e94
Compare
|
V2:
|
There was a problem hiding this comment.
sorry, I'd really like to know a bit more about how this error occurs. I know, that it's hard to reproduce, but at least we can trigger when this occurs and perform a post-mortem on the thread. Let's see if we can bring a bit more clarity to this. E.g. IIUC currently in userspace mode the chain DMA task is running on the standard kernel work queue. Maybe we should have a separate work queue (per core?) for them with suitable priorities.
Add a check to ensure task state is what is expected after k_sem_take() returns in zephyr_ll_task_free().
This is needed to avoid a rare error hit when running stress tests with chain DMA in user-space LL builds. Issue is hard to reproduce, but similar error signature can be created by passing K_NO_WAIT to k_sem_take() and running a test with chain-dma pipeline.
Add defensive code that handles this scenario and prints out a warning when unexpected return occurs. Tested with a custom build with K_NO_WAIT passed to k_sem_take().