Skip to content

Commit 7fa81f8

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 2da0845 commit 7fa81f8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

zephyr/lib/fast-get.c

Lines changed: 7 additions & 3 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+
if (size > FAST_GET_MAX_COPY_SIZE || !IS_ENABLED(CONFIG_USERSPACE) ||
154+
/* The module driver heap is shared by all instances of a given module.
155+
* Instances can share the allocated buffer.
156+
*/
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 */
@@ -183,8 +187,8 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
183187
ret = entry->sram_ptr;
184188

185189
#if CONFIG_USERSPACE
186-
/* We only get there for large buffers */
187-
if (k_current_get()->mem_domain_info.mem_domain->num_partitions > 1) {
190+
/* We only get there for large buffers or module driver heap is in use */
191+
if (k_current_get()->base.user_options & K_USER && size > FAST_GET_MAX_COPY_SIZE) {
188192
/* A userspace thread makes the request */
189193
if (k_current_get() != entry->thread &&
190194
!fast_get_domain_exists(k_current_get(), ret,

0 commit comments

Comments
 (0)