Skip to content

Commit c59f3af

Browse files
author
Jyri Sarha
committed
module-adapter: Size DP heap from IPC ext init data
Use IPC module init extended data (the dp_data) to determine DP module heap size when available. Add Kconfig option SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE (default 20480) as fallback when extended init data is not present or does not provide heap sizes. Sanity-check the requested sizes (reject values above 64 MB) and log the allocated heap size. Also pass ext_init through module_adapter_mem_alloc() to module_adapter_dp_heap_new() and fix a minor comment typo. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 02f847a commit c59f3af

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

src/audio/module_adapter/module_adapter.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,28 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
5959
#endif
6060

6161
static struct vregion *module_adapter_dp_heap_new(const struct comp_ipc_config *config,
62+
const struct module_ext_init_data *ext_init,
6263
size_t *heap_size)
6364
{
6465
/* src-lite with 8 channels has been seen allocating 14k in one go */
65-
/* FIXME: the size will be derived from configuration */
66-
const size_t buf_size = 28 * 1024;
66+
size_t buf_size = CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE;
67+
68+
#if CONFIG_IPC_MAJOR_4
69+
if (config->ipc_extended_init && ext_init && ext_init->dp_data &&
70+
ext_init->dp_data->heap_bytes > 0) {
71+
if (ext_init->dp_data->heap_bytes > MB(64)) {
72+
LOG_ERR("Bad heap size %u bytes for %#x",
73+
ext_init->dp_data->heap_bytes, config->id);
74+
return NULL;
75+
}
76+
77+
buf_size = ext_init->dp_data->heap_bytes;
78+
79+
LOG_INF("%zu byte heap size requested in IPC for %#x", buf_size, config->id);
80+
}
81+
#endif
82+
83+
*heap_size = buf_size;
6784

6885
/*
6986
* A 1-to-1 replacement of the original heap implementation would be to
@@ -74,8 +91,10 @@ static struct vregion *module_adapter_dp_heap_new(const struct comp_ipc_config *
7491
return vregion_create(4096, buf_size - 4096);
7592
}
7693

77-
static struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv,
78-
const struct comp_ipc_config *config)
94+
static
95+
struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv,
96+
const struct comp_ipc_config *config,
97+
const struct module_ext_init_data *ext_init)
7998
{
8099
struct k_heap *mod_heap;
81100
struct vregion *mod_vreg;
@@ -94,7 +113,7 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
94113

95114
if (config->proc_domain == COMP_PROCESSING_DOMAIN_DP && IS_ENABLED(CONFIG_SOF_VREGIONS) &&
96115
IS_ENABLED(CONFIG_USERSPACE) && !IS_ENABLED(CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP)) {
97-
mod_vreg = module_adapter_dp_heap_new(config, &heap_size);
116+
mod_vreg = module_adapter_dp_heap_new(config, ext_init, &heap_size);
98117
if (!mod_vreg) {
99118
comp_cl_err(drv, "Failed to allocate DP module heap / vregion");
100119
return NULL;
@@ -236,8 +255,14 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
236255
return NULL;
237256
}
238257
#endif
258+
const struct module_ext_init_data *ext_init =
259+
#if CONFIG_IPC_MAJOR_4
260+
&ext_data;
261+
#else
262+
NULL;
263+
#endif
239264

240-
struct processing_module *mod = module_adapter_mem_alloc(drv, config);
265+
struct processing_module *mod = module_adapter_mem_alloc(drv, config, ext_init);
241266

242267
if (!mod)
243268
return NULL;
@@ -254,8 +279,9 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
254279
/*
255280
* NOTE: dst->ext_data points to stack variable and contains
256281
* pointers to IPC payload mailbox, so its only valid in
257-
* functions that called from this function. This why
258-
* the pointer is set NULL before this function exits.
282+
* functions that are called from this function. This is
283+
* why the pointer is set to NULL before this function
284+
* exits.
259285
*/
260286
#if CONFIG_IPC_MAJOR_4
261287
dst->ext_data = &ext_data;

zephyr/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ config SOF_ZEPHYR_HEAP_SIZE
6969
NOTE: Keep in mind that the heap size should not be greater than the physical
7070
memory size of the system defined in DT (and this includes baseFW text/data).
7171

72+
config SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE
73+
int "Default heap size for DP userspace threads"
74+
default 20480
75+
help
76+
Defines the default heap size for userspace DP processing
77+
threads. The value can be overridden with IPC module init
78+
ext_init module payload. The default is derived from what is
79+
required for SRC module to produce all supported conversions.
80+
7281
config SOF_USERSPACE_USE_SHARED_HEAP
7382
bool "Use shared heap for SOF userspace modules"
7483
depends on USERSPACE

0 commit comments

Comments
 (0)