Repository navigation
zephyr: wrapper: Abort failing ll thread and release held resources - #11502
adityaganeshintel2k wants to merge 4 commits into
Conversation
DEBUG ONLY - not for upstream. Add COMP_GAIN_FAULT_INJECT (default y), COMP_GAIN_FAULT_INJECT_CORE (default 1) and COMP_GAIN_FAULT_INJECT_PERIODS (default 1000). When enabled, the GAIN module uses gain_process(), a wrapper around volume_process(). On gain instances whose IPC4 core_id equals COMP_GAIN_FAULT_INJECT_CORE, after COMP_GAIN_FAULT_INJECT_PERIODS process() calls (about 1 s at a 1 ms LL period) it logs a "FAULT INJECT" error and executes "ill", raising an Xtensa IllegalInstruction exception (EXCCAUSE 0) from the LL thread of that core. The core is taken from dev->ipc_config.core instead of being read from the CPU, so the check is valid in user-space LL threads. __builtin_trap() is not used because Xtensa GCC emits "break 1, 15" (a debug exception) for it. The PEAKVOL module keeps calling volume_process() directly and is not affected. The per-instance counter lives in struct vol_data, which is zero-allocated, so no shared global is touched from user space. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er() k_sys_fatal_error_handler() calls xtensa_exception_is_user() on Xtensa builds with CONFIG_USERSPACE, but the declaration lives in Zephyr's arch-internal header xtensa_internal.h, which was not included. This breaks the build with -Werror=implicit-function-declaration. Include the header under the same CONFIG_XTENSA && CONFIG_USERSPACE guard as the caller. zephyr/arch/xtensa/include is already on the include path. This restores the include added by 1e8d83b on ag-userspace-handler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Xtensa userspace builds, a CPU exception or a kernel oops raised by a user thread is the fault of that thread: return from k_sys_fatal_error_handler() so that z_fatal_error() aborts only the faulting thread instead of halting the whole DSP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Ganesh, Aditya <aditya.ganesh@intel.com>
In user-space LL builds zephyr_ll_run() keeps the per-core LL scheduler mutex locked while running the tasks. When a module faults in the LL thread, k_sys_fatal_error_handler() returns and z_fatal_error() aborts only that thread, but Zephyr does not release mutexes of aborted threads. The lock stays owned by the dead thread and the next user_ll_lock_sched() on that core pends forever. E.g. the IPC user thread triggering a pipeline stop blocks, and all further IPCs for that core time out with -EAGAIN in ipc_user_forward_cmd(). Add zephyr_ll_release_locks_of_current(), called from the fatal error handler while _current is still the faulting thread and owner of the lock. It looks the locks up in the kernel-only zephyr_ll_klocks[] copy, resets the shadow owner tracking and unlocks every recursion level, handing the lock over to the first waiter. Rescheduling is deferred until the exception returns. This only unblocks the waiters. The scheduler state is not repaired: the tasks run in the interrupted tick stay on the dead thread's temporary list and no further LL ticks happen on that core. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Ganesh, Aditya <aditya.ganesh@intel.com>
|
Can one of the admins verify this patch?
|
| k_thread_access_grant(thread, zephyr_ll_klocks[core]); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
@adityaganeshintel2k so once locks are freed, we should then be able to free vregions and vpages in the app and restart the LL infra ? OR are there other thing required before recovery ?
There was a problem hiding this comment.
@lgirdwood Discussed this with @adityaganeshintel2k and there are some complications on recovery:
- the LL thread owns lot of resources (mutex, semaphores, heap memory, device handles) we can add tracking of each but this will add to cost,
- DP thread is potentially an easier starting point as it won't have any device handles and all memory allocation is via the module heap,
- FW doesn't keep track of IPCs used to build up pipelines, so it cannot recreate crashed state on its own (unless it starts tracking) -> assumption to take, FW raises error to host and it's upto host to create state
I think we could approach recovery in stages:
- level1: ability to terminate a user thread, but keep kernel and IPC running for debugging (new IPC to host, possibility to e.g. fire up Zephyr shell, or drain logs preceding the user crash)
- level2: ability to terminate one use-case but keep other use-cases running (e.g. DP crash would not bring down LL playback, or crash of LL playback on core1 would not bring down playback on core0)
- level3: like previous, but all resources of crashed thread can be reliably recovered (host can start the crashes use-case multiple times and not run out of memory)
There was a problem hiding this comment.
Just to add to this level1 should be possible because now we can abort the failing ll thread . I will write a PR which kills only the failing ll thread and we can discuss on a new IPC to host for this
There was a problem hiding this comment.
Lets do DP 1st, then for LL its the whole openmodules infra that comes down. i.e. FW needs restored to a clean state like after BaseFW has just booted and before openmodules userspace entry point (this does not need to be clean as we nuke and then bleach userspace here).
This injects a exception in the process function of gain module when running on core 1. When the exception is raised it would kill the low latency thread that is running the process function every ms and would also release the shared resources between low latency thread and the ipc user thread attached to the same core