Skip to content

Commit aa26e16

Browse files
committed
fast_get: Enable buffer sharing when using module driver heap
Allow fast_get sram buffer sharing across multiple userspace module instances when CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP is enabled. The module driver heap is shared by all instances of a given module, so allocated buffers can safely be reused between them. Simplify checking whether a calling thread runs in userspace by verifying if the K_USER flag is set. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent f587336 commit aa26e16

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

zephyr/lib/fast-get.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ const void *fast_get(struct mod_alloc_ctx *alloc, const void *dram_ptr, size_t s
122122
alloc_align = PLATFORM_DCACHE_ALIGN;
123123
}
124124

125-
if (size > FAST_GET_MAX_COPY_SIZE || !IS_ENABLED(CONFIG_USERSPACE))
125+
/* The module driver heap is shared by all instances of a given module.
126+
* Instances can share the allocated buffer.
127+
*/
128+
if (size > FAST_GET_MAX_COPY_SIZE || !IS_ENABLED(CONFIG_USERSPACE) ||
129+
IS_ENABLED(CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP))
126130
alloc_ptr = dram_ptr;
127131
else
128132
/* When userspace is enabled only share large buffers */
@@ -164,8 +168,12 @@ const void *fast_get(struct mod_alloc_ctx *alloc, const void *dram_ptr, size_t s
164168
/*
165169
* We only get there for large buffers, since small buffers with
166170
* enabled userspace don't create fast-get entries
171+
*
172+
* We also reach this point when using the module driver heap.
173+
* Since the heap is already shared across module instances,
174+
* we skip memory domain manipulation.
167175
*/
168-
if (current_is_userspace) {
176+
if (current_is_userspace && size > FAST_GET_MAX_COPY_SIZE) {
169177
if (!fast_get_partition_exists(mdom, ret,
170178
ALIGN_UP(size, CONFIG_MM_DRV_PAGE_SIZE))) {
171179
LOG_DBG("grant access to domain %p", mdom);

0 commit comments

Comments
 (0)