Skip to content

Commit f18c87f

Browse files
Jyri Sarhakv2019i
authored andcommitted
module-adapter: Size DP heap from IPC ext init data
Use IPC module init extended data (the dp_data) to determine DP module vregions heap size, when the data is available. Add Kconfig option SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE (default 20480) as a 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. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 69ea468 commit f18c87f

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

src/audio/module_adapter/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ menu "Processing modules"
1313
containers to allocate at once is selected by this
1414
config option.
1515

16+
config SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE
17+
int "Default heap size for DP userspace threads"
18+
default 20480
19+
help
20+
Defines the default heap size for userspace DP processing
21+
threads. The value can be overridden with IPC module init
22+
ext_init module payload. The default is derived from what is
23+
required for SRC module to produce all supported conversions.
24+
1625
config CADENCE_CODEC
1726
bool "Cadence codec"
1827
help

src/audio/module_adapter/module_adapter.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,33 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
5151
return module_adapter_new_ext(drv, config, spec, NULL, NULL, NULL);
5252
}
5353

54-
static struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv,
55-
const struct comp_ipc_config *config)
54+
static struct vregion *module_adapter_dp_heap_new(const struct comp_ipc_config *config,
55+
const struct module_ext_init_data *ext_init)
56+
{
57+
size_t buf_size = CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE;
58+
uintptr_t vreg_start;
59+
60+
#if CONFIG_IPC_MAJOR_4
61+
if (config->ipc_extended_init && ext_init && ext_init->dp_data &&
62+
ext_init->dp_data->heap_bytes > 0) {
63+
if (ext_init->dp_data->heap_bytes > MB(64)) {
64+
LOG_ERR("Bad heap size %u bytes for %#x",
65+
ext_init->dp_data->heap_bytes, config->id);
66+
return NULL;
67+
}
68+
69+
buf_size = ext_init->dp_data->heap_bytes;
70+
71+
LOG_INF("%zu byte heap size requested in IPC for %#x", buf_size, config->id);
72+
}
73+
#endif
74+
return vregion_create_map(&vreg_start, &buf_size);
75+
}
76+
77+
static
78+
struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv,
79+
const struct comp_ipc_config *config,
80+
const struct module_ext_init_data *ext_init)
5681
{
5782
struct k_heap *mod_heap;
5883
struct vregion *mod_vreg;
@@ -67,15 +92,10 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
6792
*/
6893
uint32_t flags = config->proc_domain == COMP_PROCESSING_DOMAIN_DP ?
6994
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT : SOF_MEM_FLAG_USER;
70-
size_t vreg_size;
71-
uintptr_t vreg_start;
7295

7396
if (config->proc_domain == COMP_PROCESSING_DOMAIN_DP && IS_ENABLED(CONFIG_SOF_VREGIONS) &&
7497
IS_ENABLED(CONFIG_USERSPACE) && !IS_ENABLED(CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP)) {
75-
/* src-lite with 8 channels has been seen allocating 14k in one go */
76-
/* FIXME: the size will be derived from configuration */
77-
vreg_size = 28 * 1024;
78-
mod_vreg = vregion_create_map(&vreg_start, &vreg_size);
98+
mod_vreg = module_adapter_dp_heap_new(config, ext_init);
7999
if (!mod_vreg) {
80100
comp_cl_err(drv, "Failed to allocate DP module heap / vregion");
81101
return NULL;
@@ -92,8 +112,6 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
92112
#else
93113
mod_heap = drv->user_heap;
94114
#endif
95-
vreg_size = 0;
96-
vreg_start = 0;
97115
mod_vreg = NULL;
98116
}
99117

@@ -223,8 +241,14 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
223241
return NULL;
224242
}
225243
#endif
244+
const struct module_ext_init_data *ext_init =
245+
#if CONFIG_IPC_MAJOR_4
246+
&ext_data;
247+
#else
248+
NULL;
249+
#endif
226250

227-
struct processing_module *mod = module_adapter_mem_alloc(drv, config);
251+
struct processing_module *mod = module_adapter_mem_alloc(drv, config, ext_init);
228252

229253
if (!mod)
230254
return NULL;

0 commit comments

Comments
 (0)