Skip to content

Commit 62fea34

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 1b4bf74 commit 62fea34

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
@@ -150,7 +150,11 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
150150
alloc_align = PLATFORM_DCACHE_ALIGN;
151151
}
152152

153-
if (size > FAST_GET_MAX_COPY_SIZE || !IS_ENABLED(CONFIG_USERSPACE))
153+
/* The module driver heap is shared by all instances of a given module.
154+
* Instances can share the allocated buffer.
155+
*/
156+
if (size > FAST_GET_MAX_COPY_SIZE || !IS_ENABLED(CONFIG_USERSPACE) ||
157+
IS_ENABLED(CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP))
154158
alloc_ptr = dram_ptr;
155159
else
156160
/* When userspace is enabled only share large buffers */
@@ -188,8 +192,12 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
188192
/*
189193
* We only get there for large buffers, since small buffers with
190194
* enabled userspace don't create fast-get entries
195+
*
196+
* We also reach this point when using the module driver heap.
197+
* Since the heap is already shared across module instances,
198+
* we skip memory domain manipulation.
191199
*/
192-
if (mdom->num_partitions > 1) {
200+
if (k_current_get()->base.user_options & K_USER && size > FAST_GET_MAX_COPY_SIZE) {
193201
/* A userspace thread makes the request */
194202
if (mdom != entry->mdom &&
195203
!fast_get_partition_exists(k_current_get(), ret,

0 commit comments

Comments
 (0)