Skip to content

Commit 9f306eb

Browse files
author
Jyri Sarha
committed
module-adapter: Size DP heap from IPC ext init data
Use IPC module init extended data (dp_data lifetime and interim heap sizes) 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 or below the dp_heap_user prefix) 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 d56ccf9 commit 9f306eb

2 files changed

Lines changed: 62 additions & 11 deletions

File tree

src/audio/module_adapter/module_adapter.c

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,55 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
5858
#endif
5959

6060
static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_config *config,
61+
const struct module_ext_init_data *ext_init,
6162
size_t *heap_size)
6263
{
64+
const size_t heap_prefix_size = ALIGN_UP(sizeof(struct dp_heap_user), 4);
6365
/* src-lite with 8 channels has been seen allocating 14k in one go */
64-
/* FIXME: the size will be derived from configuration */
65-
const size_t buf_size = 20 * 1024;
66+
size_t buf_size = CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE;
6667

68+
#if CONFIG_IPC_MAJOR_4
69+
if (config->ipc_extended_init && ext_init && ext_init->dp_data &&
70+
(ext_init->dp_data->lifetime_heap_bytes > 0 ||
71+
ext_init->dp_data->interim_heap_bytes > 0)) {
72+
if (ext_init->dp_data->lifetime_heap_bytes > 64*1024*1024 ||
73+
ext_init->dp_data->interim_heap_bytes > 64*1024*1024) {
74+
LOG_ERR("Insanely large lifetime %u or interim %u heap size for %#x",
75+
ext_init->dp_data->lifetime_heap_bytes,
76+
ext_init->dp_data->interim_heap_bytes, config->id);
77+
return NULL;
78+
}
79+
80+
/*
81+
* For the moment there is only one heap so sum up
82+
* lifetime and interim values. It is also a conscious
83+
* decision here to count the size of struct
84+
* dp_heap_user to be included into required heap
85+
* size.
86+
*/
87+
buf_size = ext_init->dp_data->lifetime_heap_bytes +
88+
ext_init->dp_data->interim_heap_bytes;
89+
LOG_DBG("%u + %u = %zu byte heap size requested in IPC for %#x",
90+
ext_init->dp_data->lifetime_heap_bytes,
91+
ext_init->dp_data->interim_heap_bytes, buf_size, config->id);
92+
}
93+
#endif
94+
if (buf_size < heap_prefix_size) {
95+
LOG_ERR("Too small heap size %zu (< %zu) for %#x", buf_size, heap_prefix_size,
96+
config->id);
97+
return NULL;
98+
}
99+
100+
LOG_INF("Allocating %zu byte heap (default %zu) for %#x", buf_size,
101+
CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE, config->id);
67102
/* Keep uncached to match the default SOF heap! */
68-
uint8_t *mod_heap_mem = rballoc_align(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
69-
buf_size, PAGE_SZ);
103+
uint8_t *mod_heap_mem = rballoc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, buf_size);
70104

71105
if (!mod_heap_mem)
72106
return NULL;
73107

74108
struct dp_heap_user *mod_heap_user = (struct dp_heap_user *)mod_heap_mem;
75109
struct k_heap *mod_heap = &mod_heap_user->heap;
76-
const size_t heap_prefix_size = ALIGN_UP(sizeof(*mod_heap_user), 4);
77110
void *mod_heap_buf = mod_heap_mem + heap_prefix_size;
78111

79112
*heap_size = buf_size - heap_prefix_size;
@@ -86,8 +119,10 @@ static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_con
86119
return mod_heap_user;
87120
}
88121

89-
static struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv,
90-
const struct comp_ipc_config *config)
122+
static
123+
struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv,
124+
const struct comp_ipc_config *config,
125+
const struct module_ext_init_data *ext_init)
91126
{
92127
struct k_heap *mod_heap;
93128
/*
@@ -104,7 +139,7 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
104139

105140
if (config->proc_domain == COMP_PROCESSING_DOMAIN_DP && IS_ENABLED(CONFIG_USERSPACE) &&
106141
!IS_ENABLED(CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP)) {
107-
mod_heap_user = module_adapter_dp_heap_new(config, &heap_size);
142+
mod_heap_user = module_adapter_dp_heap_new(config, ext_init, &heap_size);
108143
if (!mod_heap_user) {
109144
comp_cl_err(drv, "Failed to allocate DP module heap");
110145
return NULL;
@@ -220,8 +255,14 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
220255
return NULL;
221256
}
222257
#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
223264

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

226267
if (!mod)
227268
return NULL;
@@ -238,8 +279,9 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
238279
/*
239280
* NOTE: dst->ext_data points to stack variable and contains
240281
* pointers to IPC payload mailbox, so its only valid in
241-
* functions that called from this function. This why
242-
* 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.
243285
*/
244286
#if CONFIG_IPC_MAJOR_4
245287
dst->ext_data = &ext_data;

zephyr/Kconfig

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

64+
config SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE
65+
int "Default heap size for DP userspace threads"
66+
default 20480
67+
help
68+
Defines the default heap size for userspace DP processing
69+
threads. The value can be overridden with IPC module init
70+
ext_init module payload. The default is derived from what is
71+
required for SRC module to produce all supported conversions.
72+
6473
config SOF_USERSPACE_USE_SHARED_HEAP
6574
bool "Use shared heap for SOF userspace modules"
6675
depends on USERSPACE

0 commit comments

Comments
 (0)