Skip to content

zephyr: wrapper: Abort failing ll thread and release held resources - #11502

Draft
adityaganeshintel2k wants to merge 4 commits into
thesofproject:mainfrom
adityaganeshintel2k:gain-core1-fault-inject
Draft

adityaganeshintel2k wants to merge 4 commits into
thesofproject:mainfrom
adityaganeshintel2k:gain-core1-fault-inject

Conversation

@adityaganeshintel2k

Copy link
Copy Markdown

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

adityaganeshintel2k and others added 4 commits November 19, 2026 13:29
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>
@sofci

sofci commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants