Skip to content

Commit 044274b

Browse files
committed
module-adapter: move mod_alloc() allocations to the module heap
Move mod_alloc() allocations, including the container pool, to the module local heap. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent b833e9c commit 044274b

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/audio/module_adapter/module/generic.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,20 @@ struct container_chunk {
137137
static struct module_resource *container_get(struct processing_module *mod)
138138
{
139139
struct module_resources *res = &mod->priv.resources;
140+
struct k_heap *mod_heap = res->heap;
140141
struct module_resource *container;
141142

142143
if (list_is_empty(&res->free_cont_list)) {
143-
struct container_chunk *chunk = rzalloc(SOF_MEM_FLAG_USER, sizeof(*chunk));
144+
struct container_chunk *chunk = sof_heap_alloc(mod_heap, 0, sizeof(*chunk), 0);
144145
int i;
145146

146147
if (!chunk) {
147148
comp_err(mod->dev, "allocating more containers failed");
148149
return NULL;
149150
}
150151

152+
memset(chunk, 0, sizeof(*chunk));
153+
151154
list_item_append(&chunk->chunk_list, &res->cont_chunk_list);
152155
for (i = 0; i < ARRAY_SIZE(chunk->containers); i++)
153156
list_item_append(&chunk->containers[i].list, &res->free_cont_list);
@@ -180,7 +183,6 @@ void *mod_balloc_align(struct processing_module *mod, size_t size, size_t alignm
180183
{
181184
struct module_resources *res = &mod->priv.resources;
182185
struct module_resource *container;
183-
void *ptr;
184186

185187
MEM_API_CHECK_THREAD(res);
186188

@@ -195,7 +197,7 @@ void *mod_balloc_align(struct processing_module *mod, size_t size, size_t alignm
195197
}
196198

197199
/* Allocate buffer memory for module */
198-
ptr = rballoc_align(SOF_MEM_FLAG_USER, size, alignment);
200+
void *ptr = sof_heap_alloc(res->heap, SOF_MEM_FLAG_USER, size, alignment);
199201

200202
if (!ptr) {
201203
comp_err(mod->dev, "Failed to alloc %zu bytes %zu alignment for comp %#x.",
@@ -231,7 +233,6 @@ void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,
231233
{
232234
struct module_resources *res = &mod->priv.resources;
233235
struct module_resource *container;
234-
void *ptr;
235236

236237
MEM_API_CHECK_THREAD(res);
237238

@@ -246,7 +247,7 @@ void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,
246247
}
247248

248249
/* Allocate memory for module */
249-
ptr = rmalloc_align(flags, size, alignment);
250+
void *ptr = sof_heap_alloc(res->heap, flags, size, alignment);
250251

251252
if (!ptr) {
252253
comp_err(mod->dev, "Failed to alloc %zu bytes %zu alignment for comp %#x.",
@@ -276,8 +277,7 @@ EXPORT_SYMBOL(mod_alloc_ext);
276277
* Like comp_data_blob_handler_new() but the handler is automatically freed.
277278
*/
278279
#if CONFIG_COMP_BLOB
279-
struct comp_data_blob_handler *
280-
mod_data_blob_handler_new(struct processing_module *mod)
280+
struct comp_data_blob_handler *mod_data_blob_handler_new(struct processing_module *mod)
281281
{
282282
struct module_resources *res = &mod->priv.resources;
283283
struct comp_data_blob_handler *bhp;
@@ -347,7 +347,7 @@ static int free_contents(struct processing_module *mod, struct module_resource *
347347

348348
switch (container->type) {
349349
case MOD_RES_HEAP:
350-
rfree(container->ptr);
350+
sof_heap_free(res->heap, container->ptr);
351351
res->heap_usage -= container->size;
352352
return 0;
353353
#if CONFIG_COMP_BLOB
@@ -588,6 +588,7 @@ int module_reset(struct processing_module *mod)
588588
void mod_free_all(struct processing_module *mod)
589589
{
590590
struct module_resources *res = &mod->priv.resources;
591+
struct k_heap *mod_heap = res->heap;
591592
struct list_item *list;
592593
struct list_item *_list;
593594

@@ -611,7 +612,7 @@ void mod_free_all(struct processing_module *mod)
611612
container_of(list, struct container_chunk, chunk_list);
612613

613614
list_item_del(&chunk->chunk_list);
614-
rfree(chunk);
615+
sof_heap_free(mod_heap, chunk);
615616
}
616617

617618
/* Make sure resource lists and accounting are reset */

0 commit comments

Comments
 (0)