Skip to content

Commit df7ff53

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 07a7ee7 commit df7ff53

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/component.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>
@@ -217,12 +218,12 @@ const void *fast_get(struct mod_alloc_ctx *alloc, const void *dram_ptr, size_t s
217218
goto out;
218219
}
219220

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

@@ -286,7 +287,10 @@ void fast_put(struct mod_alloc_ctx *alloc, struct k_mem_domain *mdom, const void
286287

287288
if (!entry->refcount) {
288289
LOG_DBG("freeing buffer %p", sram_ptr);
289-
sof_heap_free(heap, entry->sram_ptr);
290+
if (alloc && alloc->vreg && entry->size <= FAST_GET_MAX_COPY_SIZE)
291+
vregion_free(alloc->vreg, entry->sram_ptr);
292+
else
293+
sof_heap_free(heap, entry->sram_ptr);
290294
}
291295

292296
#if CONFIG_USERSPACE

0 commit comments

Comments
 (0)