Skip to content

Commit

Permalink
llext_manager: Add module instance counter
Browse files Browse the repository at this point in the history
Added a module instance counter to prevent module code allocation for each
instance.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
  • Loading branch information
softwarecki committed Mar 13, 2024
1 parent 5b860cb commit 75fa9db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/include/sof/lib_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct lib_manager_mod_ctx {
void *base_addr;
size_t segment_size[3];
struct llext *llext;
uint32_t instance_count;
};

struct ext_library {
Expand Down
2 changes: 1 addition & 1 deletion src/library_manager/lib_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ static void lib_manager_update_sof_ctx(void *base_addr, uint32_t lib_id)
{
struct ext_library *_ext_lib = ext_lib_get();
/* Never freed, will panic if fails */
struct lib_manager_mod_ctx *ctx = rmalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM,
struct lib_manager_mod_ctx *ctx = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM,
sizeof(*ctx));

ctx->base_addr = base_addr;
Expand Down
38 changes: 22 additions & 16 deletions src/library_manager/llext_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ uintptr_t llext_manager_allocate_module(struct processing_module *proc,
tr_dbg(&lib_manager_tr, "llext_manager_allocate_module(): mod_id: %#x",
ipc_config->id);


desc = lib_manager_get_library_module_desc(module_id);
if (!ctx || !desc) {
tr_err(&lib_manager_tr,
Expand All @@ -251,14 +252,16 @@ uintptr_t llext_manager_allocate_module(struct processing_module *proc,

mod = (struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(entry_index));

ret = llext_manager_link(desc, mod, module_id, &ctx->llext, buildinfo, &mod_manifest);
if (ret < 0)
return 0;
if (!ctx->llext) {
ret = llext_manager_link(desc, mod, module_id, &ctx->llext, buildinfo, &mod_manifest);
if (ret < 0)
return 0;

/* Map .text and the rest as .data */
ret = llext_manager_load_module(module_id, mod);
if (ret < 0)
return 0;
/* Map .text and the rest as .data */
ret = llext_manager_load_module(module_id, mod);
if (ret < 0)
return 0;
}

ret = llext_manager_allocate_module_bss(module_id, mod);
if (ret < 0) {
Expand All @@ -267,6 +270,7 @@ uintptr_t llext_manager_allocate_module(struct processing_module *proc,
return 0;
}

ctx->instance_count++;
return mod_manifest->module.entry_point;
}

Expand All @@ -284,22 +288,24 @@ int llext_manager_free_module(const uint32_t component_id)
desc = lib_manager_get_library_module_desc(module_id);
mod = (struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(entry_index));

ret = llext_manager_unload_module(module_id, mod);
if (ret < 0)
return ret;

ret = llext_manager_free_module_bss(module_id, mod);
if (ret < 0) {
tr_err(&lib_manager_tr,
"llext_manager_free_module(): free module bss failed: %d", ret);
return ret;
}

/*
* FIXME: I'm not sure where to place it. Call to the lib_manager_free_module for llext
* modules was skipped by the modules_free function. I belive it was a bug.
*/
llext_unload(&ctx->llext);
if (!--ctx->instance_count) {
ret = llext_manager_unload_module(module_id, mod);
if (ret < 0)
return ret;

/*
* FIXME: I'm not sure where to place it. Call to the lib_manager_free_module for llext
* modules was skipped by the modules_free function. I belive it was a bug.
*/
llext_unload(&ctx->llext);
}

return 0;
}

0 comments on commit 75fa9db

Please sign in to comment.