Skip to content

Commit b81a5f4

Browse files
committed
fast-get: add support for vregion allocations
When userspace modules use fast-get to access smaller buffers, their copies should be allocated on module's vregion, if available, not on the global SOF heap. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 759d07c commit b81a5f4

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

zephyr/lib/fast-get.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <sof/audio/module_adapter/module/generic.h>
1212
#include <sof/lib/fast-get.h>
13+
#include <sof/lib/vregion.h>
1314
#include <rtos/alloc.h>
1415
#include <rtos/cache.h>
1516
#include <rtos/kernel.h>
@@ -216,12 +217,12 @@ const void *fast_get(struct mod_alloc_ctx *alloc, const void *dram_ptr, size_t s
216217
goto out;
217218
}
218219

219-
/*
220-
* If a userspace threads is the first user to fast-get the buffer, an
221-
* SRAM copy will be allocated on its own heap, so it will have access
222-
* to it
223-
*/
224-
ret = sof_heap_alloc(alloc->heap, alloc_flags, alloc_size, alloc_align);
220+
if (alloc->vreg && size <= FAST_GET_MAX_COPY_SIZE)
221+
/* A userspace allocation, that won't be shared */
222+
ret = vregion_alloc_align(alloc->vreg, VREGION_MEM_TYPE_INTERIM, alloc_size,
223+
alloc_align);
224+
else
225+
ret = sof_heap_alloc(alloc->heap, alloc_flags, alloc_size, alloc_align);
225226
if (!ret)
226227
goto out;
227228

@@ -284,7 +285,10 @@ void fast_put(struct mod_alloc_ctx *alloc, struct k_mem_domain *mdom, const void
284285

285286
if (!entry->refcount) {
286287
LOG_DBG("freeing buffer %p", sram_ptr);
287-
sof_heap_free(alloc->heap, entry->sram_ptr);
288+
if (alloc->vreg && entry->size <= FAST_GET_MAX_COPY_SIZE)
289+
vregion_free(alloc->vreg, entry->sram_ptr);
290+
else
291+
sof_heap_free(alloc->heap, entry->sram_ptr);
288292
}
289293

290294
#if CONFIG_USERSPACE

0 commit comments

Comments
 (0)