Skip to content

Commit f966a95

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 658944a commit f966a95

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

151-
if (size > FAST_GET_MAX_COPY_SIZE || !IS_ENABLED(CONFIG_USERSPACE))
151+
/* The module driver heap is shared by all instances of a given module.
152+
* Instances can share the allocated buffer.
153+
*/
154+
if (size > FAST_GET_MAX_COPY_SIZE || !IS_ENABLED(CONFIG_USERSPACE) ||
155+
IS_ENABLED(CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP))
152156
alloc_ptr = dram_ptr;
153157
else
154158
/* When userspace is enabled only share large buffers */
@@ -186,8 +190,12 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
186190
/*
187191
* We only get there for large buffers, since small buffers with
188192
* enabled userspace don't create fast-get entries
193+
*
194+
* We also reach this point when using the module driver heap.
195+
* Since the heap is already shared across module instances,
196+
* we skip memory domain manipulation.
189197
*/
190-
if (current_is_userspace) {
198+
if (current_is_userspace && size > FAST_GET_MAX_COPY_SIZE) {
191199
if (!fast_get_partition_exists(mdom, ret,
192200
ALIGN_UP(size, CONFIG_MM_DRV_PAGE_SIZE))) {
193201
LOG_DBG("grant access to domain %p", mdom);

0 commit comments

Comments
 (0)