Skip to content

Conversation

@jsarha
Copy link
Contributor

@jsarha jsarha commented Aug 31, 2025

mfcc related changes

Jyri Sarha added 13 commits August 18, 2025 21:19
Do not allocate module memory containers one by one, but allocate them
in chunks.

The bookkeeping of allocated resources is done using containers that
are allocated from heap. This effectively doubles the amount of heap
allocations. This is not very efficient especially since the containers
are only 20 bytes in size.

This commit changes the allocation of containers so that they are
always allocated in chunks of 16 containers, or what is selected with
MODULE_MEMORY_API_CONTAINER_CHUNK_SIZE Kconfig option. The unused
containers are not freed when the associated resource is
freed. Instead the unused containers are kept in free containers
list. All the containers are freed when mod_free_all() is called, for
instance when the module unloads.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add heap usage high water mark to module_adapter_heap_usage() and
shell's "sof module_heap_usage" command.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add src/audio/data_blob.c to mixer cmocka test sources to fix the
dependency problem from adding comp_data_blob_handler_new_ext() to
audio/module_adapter/module/generic.c.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add mod_data_blob_handler_new() to module API. The function is
otherwise the same as comp_data_blob_handler_new(), but it takes a
module pointer as the first argument, and the blob handler is
automatically freed when the module unloads.

The handler allocated with mod_data_blob_handler_new() should not be
freed with comp_data_blob_handler_free(), mod_data_blob_handler_free()
should be used.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add module API versions of fast_get() and fast_put(). The SRAM copies
reserved with mod_fast_get() are released automatically when the
module unloads, and those SRAM copies should not be freed with the
regular fast_put().

The sram-copy allocated with mod_fast_get() should not be freed with
regular fast_put(), but mod_fast_put() should be used.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add safeguard to mod_alloc() and friends that checks that they are
always called from the same thread (e.g. no locking needed).

The checking code has to be also behind defined(__ZEPHYR__) to keep
cmocka tests working.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
…ree()

Use list_for_item() instead of list_for_item_safe() in mod_free().
There is no need for *_safe() version when loop is not continued after
an element is removed from the list.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Take mod_fast_get() and mod_fast_put() into use.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Make mod_alloc() versions of all heap using functions. The new functions
are simple copy-paste versions of the original, just using mod_alloc()
and friend instead of rmalloc() friends.

The idea is to get rid off the original versions once all the modules
are converted to module API heap usage and the cmocka math tests have
been fixed to work with mod_alloc() versions.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Allocate all memory, blob handlers, and fast_get() buffers through
module API mod_alloc() and friends and remove all redundant rfree(),
comp_data_blob_handler_free(), and fast_put() calls from module unload
functions and init error branches.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add mocks for mod_alloc(), mod_zalloc(), and mod_free(). These dummy
versions do not keep track of the allocated memory. They just forward
the calls to reqular malloc() and free().

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Convert auditory, dct, fft, and matrix math tests to use module heap
API functions instead of the old version using rmalloc() and friends
directly.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Both unit tests and modules should now use the module API heap
allocation functions, so we can now remove the directly heap using
versions.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
@jsarha jsarha changed the title Module api conversion 4 [CI TEST not for review] Module api conversion 4 Sep 1, 2025
@jsarha jsarha closed this Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant