Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/audio/data_blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,12 @@ EXPORT_SYMBOL(comp_data_blob_get_cmd);

static void *default_alloc(size_t size)
{
return rballoc(SOF_MEM_FLAG_USER, size);
return sof_heap_alloc(sof_sys_user_heap_get(), SOF_MEM_FLAG_USER, size, 0);
}

static void default_free(void *buf)
{
rfree(buf);
sof_heap_free(sof_sys_user_heap_get(), buf);
}

struct comp_data_blob_handler *
Expand All @@ -638,13 +638,15 @@ comp_data_blob_handler_new_ext(struct comp_dev *dev, bool single_blob,
void (*free)(void *buf))
{
struct comp_data_blob_handler *handler;
struct k_heap *heap = sof_sys_user_heap_get();

comp_dbg(dev, "entry");

handler = rzalloc(SOF_MEM_FLAG_USER,
sizeof(struct comp_data_blob_handler));
handler = sof_heap_alloc(heap, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
sizeof(struct comp_data_blob_handler), 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just use sof_sys_user_heap_get() directly as in other cases. But this one also adds COHERENT - that's on purpose, right? Maybe mention in the commit message

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fixing both. Earlier version of the patch stored a heap instance, but no need for that. And COHERENT is a mistake, we should align flags. Will fix.


if (handler) {
memset(handler, 0, sizeof(*handler));
handler->dev = dev;
handler->single_blob = single_blob;
handler->alloc = alloc ? alloc : default_alloc;
Expand All @@ -662,6 +664,6 @@ void comp_data_blob_handler_free(struct comp_data_blob_handler *blob_handler)

comp_free_data_blob(blob_handler);

rfree(blob_handler);
sof_heap_free(sof_sys_user_heap_get(), blob_handler);
}
EXPORT_SYMBOL(comp_data_blob_handler_free);
22 changes: 13 additions & 9 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ int module_load_config(struct comp_dev *dev, const void *cfg, size_t size)

if (!dst->data) {
/* No space for config available yet, allocate now */
dst->data = rballoc(SOF_MEM_FLAG_USER, size);
dst->data = sof_heap_alloc(sof_sys_user_heap_get(),
SOF_MEM_FLAG_USER, size, 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, we're releasing some of VMH memory and using the standard heap here. Have you checked how big these allocations are typically and how many we switch? Do we need to reallocate some memory from VMH to the userspace heap?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, right. I don't think we should touch the virtual/direct heap mix in the same PRs as we add support for user-space LL use. And yeah, that's what I'm doing here and some of earlier rballoc(). I could use SOF_MEM_FLAG_LARGE_BUFFER to mark places where rballoc() was used, but that is hardcoded to kernel in current zephyr/alloc.c, so won't work either. But alas, some cleaner solution is needed. Sizing the VMH split is a much more complicated problem and I don't want to tackle that in these PRs...

} else if (dst->size != size) {
/* The size allocated for previous config doesn't match the new one.
* Free old container and allocate new one.
*/
rfree(dst->data);
dst->data = rballoc(SOF_MEM_FLAG_USER, size);
sof_heap_free(sof_sys_user_heap_get(), dst->data);
dst->data = sof_heap_alloc(sof_sys_user_heap_get(),
SOF_MEM_FLAG_USER, size, 0);
}
if (!dst->data) {
comp_err(dev, "failed to allocate space for setup config.");
Expand Down Expand Up @@ -538,7 +540,7 @@ int module_prepare(struct processing_module *mod,
* as it has been applied during the procedure - it is safe to
* free it.
*/
rfree(md->cfg.data);
sof_heap_free(sof_sys_user_heap_get(), md->cfg.data);

md->cfg.avail = false;
md->cfg.data = NULL;
Expand Down Expand Up @@ -673,7 +675,7 @@ int module_reset(struct processing_module *mod)

md->cfg.avail = false;
md->cfg.size = 0;
rfree(md->cfg.data);
sof_heap_free(sof_sys_user_heap_get(), md->cfg.data);
md->cfg.data = NULL;

#if CONFIG_IPC_MAJOR_3
Expand Down Expand Up @@ -724,10 +726,10 @@ int module_free(struct processing_module *mod)
/* Free all memory shared by module_adapter & module */
md->cfg.avail = false;
md->cfg.size = 0;
rfree(md->cfg.data);
sof_heap_free(sof_sys_user_heap_get(), md->cfg.data);
md->cfg.data = NULL;
if (md->runtime_params) {
rfree(md->runtime_params);
sof_heap_free(sof_sys_user_heap_get(), md->runtime_params);
md->runtime_params = NULL;
}
#if CONFIG_IPC_MAJOR_3
Expand Down Expand Up @@ -794,7 +796,9 @@ int module_set_configuration(struct processing_module *mod,
}

/* Allocate buffer for new params */
md->runtime_params = rballoc(SOF_MEM_FLAG_USER, md->new_cfg_size);
md->runtime_params = sof_heap_alloc(sof_sys_user_heap_get(),
SOF_MEM_FLAG_USER,
md->new_cfg_size, 0);
if (!md->runtime_params) {
comp_err(dev, "space allocation for new params failed");
return -ENOMEM;
Expand Down Expand Up @@ -835,7 +839,7 @@ int module_set_configuration(struct processing_module *mod,
md->new_cfg_size = 0;

if (md->runtime_params)
rfree(md->runtime_params);
sof_heap_free(sof_sys_user_heap_get(), md->runtime_params);
md->runtime_params = NULL;

return ret;
Expand Down
Loading