[Userspace LL] module: generic: make resource locking compatible with user-space builds - #11086
[Userspace LL] module: generic: make resource locking compatible with user-space builds#11086kv2019i wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the module resource tracking/locking layer to work with Zephyr user-space LL builds by moving the resource lock out of the per-module (user-writable) struct and by making mod_free_all() available as a syscall-compatible API.
Changes:
- Remove the per-module
k_mutexfromstruct module_resourcesand use a single shared lock for resource pool bookkeeping. - Convert
mod_free_all()into a Zephyr syscall-style API (mod_free_all()/z_impl_mod_free_all()/z_vrfy_mod_free_all()), aligning it with the rest of the resource syscall wrappers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/include/sof/audio/module_adapter/module/generic.h | Removes per-module lock from module_resources and adds syscall/macro plumbing for mod_free_all(). |
| src/audio/module_adapter/module/generic.c | Introduces a shared resource mutex and routes resource operations through it; adds syscall verification + implementation split for mod_free_all(). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * kernel object serialises all pools. Contention is negligible because resource | ||
| * bookkeeping only happens at module setup/teardown, not on the processing path. | ||
| */ | ||
| static K_MUTEX_DEFINE(mod_res_lock); |
There was a problem hiding this comment.
Fixed in V2 by adding a posix wrapper for K_MUTEX_DEFINE.
module_adapter_free() runs in a user-mode thread in userspace-LL mode and calls mod_free_all(). Unlike mod_free(), mod_free_all() was a plain function, so its internal sof_heap_free() calls on the module heap went through the user-mode syscall verifier, which only permits the LL user heap and K_OOPSes on the module heap. Convert mod_free_all() to a syscall so the objpool/heap cleanup runs in supervisor context, matching mod_free(). Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Implement a wrapper for this Zephyr interface so it can be used in generic SOF code. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Replace the per-pool k_mutex embedded in struct module_resources with a single static K_MUTEX_DEFINE() shared by all module resource pools. This approach to implement locking works both in kernel and userspace SOF builds. When userspace is enabled, the resource API is only ever entered from supervisor context (the z_impl_* syscall bodies), so is it ok to have the lock only accessible from kernel. Lock contention is negligible: resource bookkeeping happens at module setup and teardown, not on the processing path, and the mutex carries priority inheritance for the rare overlap. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
922b780 to
6b6af15
Compare
|
V2 pushed:
|
There was a problem hiding this comment.
Uncached static lock for all module resources on all cores should work always. It would be interesting to collect statistics if any module will ever need to block on this lock. After all IPC is very serialized and deals with one module instances one by one.
A small series to make the locking added in #10960 compatible with user-space LL builds.
For context, this is part of #10558