Skip to content

Commit e2386cc

Browse files
committed
userspace: Add option to toggle driver heap for userspace modules
Introduce a configuration option to control heap sharing between userspace module instances. When enabled, instances of the same module type share a private heap allocated for the module driver. When disabled, each instance maintains its own independent heap. Rename DRV_HEAP_SIZE to more meaningful name USER_MOD_HEAP_SIZE. This allows fine-grained control over memory isolation and resource sharing in userspace modules. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent ea1fccd commit e2386cc

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/include/sof/audio/component.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ bool comp_update_performance_data(struct comp_dev *dev, uint32_t cycles_used);
12141214

12151215
static inline int user_get_buffer_memory_region(const struct comp_driver *drv)
12161216
{
1217-
#if CONFIG_USERSPACE
1217+
#if CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP
12181218
return drv->user_heap ? SOF_MEM_FLAG_USER_SHARED_BUFFER : SOF_MEM_FLAG_USER;
12191219
#else
12201220
return SOF_MEM_FLAG_USER;

zephyr/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ config SOF_ZEPHYR_VIRTUAL_HEAP_REGION_SIZE
6767
help
6868
This config defines size of virtual heap region shared between all cores
6969

70+
config SOF_USERSPACE_USE_DRIVER_HEAP
71+
bool "Use driver heap for SOF userspace modules"
72+
depends on USERSPACE
73+
help
74+
When selected, multiple instances of the same userspace module will share
75+
a private heap created for that module's driver. Otherwise, each module
76+
instance will have its own independent private heap.
77+
7078
config SOF_ZEPHYR_USERSPACE_MODULE_HEAP_SIZE
7179
hex "Size of the private heap created for each userspace module"
7280
default 0x1000

zephyr/include/rtos/userspace_helper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
#include <zephyr/app_memory/app_memdomain.h>
2121

22-
#define DRV_HEAP_SIZE ALIGN_UP(CONFIG_SOF_ZEPHYR_USERSPACE_MODULE_HEAP_SIZE, \
23-
CONFIG_MM_DRV_PAGE_SIZE)
22+
#define USER_MOD_HEAP_SIZE ALIGN_UP(CONFIG_SOF_ZEPHYR_USERSPACE_MODULE_HEAP_SIZE, \
23+
CONFIG_MM_DRV_PAGE_SIZE)
2424
#define APP_TASK_BSS K_APP_BMEM(common_partition)
2525
#define APP_TASK_DATA K_APP_DMEM(common_partition)
2626

zephyr/lib/userspace_helper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ struct sys_heap *module_driver_heap_init(void)
3636
if (!mod_drv_heap)
3737
return NULL;
3838

39-
void *mem = rballoc_align(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, DRV_HEAP_SIZE,
39+
void *mem = rballoc_align(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, USER_MOD_HEAP_SIZE,
4040
CONFIG_MM_DRV_PAGE_SIZE);
4141
if (!mem) {
4242
rfree(mod_drv_heap);
4343
return NULL;
4444
}
4545

46-
sys_heap_init(mod_drv_heap, mem, DRV_HEAP_SIZE);
46+
sys_heap_init(mod_drv_heap, mem, USER_MOD_HEAP_SIZE);
4747
mod_drv_heap->init_mem = mem;
48-
mod_drv_heap->init_bytes = DRV_HEAP_SIZE;
48+
mod_drv_heap->init_bytes = USER_MOD_HEAP_SIZE;
4949

5050
return mod_drv_heap;
5151
}

0 commit comments

Comments
 (0)