vregions phase II: Actually use the lifetime allocations and make the memory division between lifetime and interim dynamic#10783
Draft
jsarha wants to merge 15 commits into
Draft
Conversation
added 15 commits
May 18, 2026 15:55
Move pipeline_comp_dp_task_init() call after module private data initializations so that the struct module_config is available already at pipeline_comp_dp_task_init() init time. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Use IPC module init extended data (dp_data lifetime and interim heap sizes) to determine DP module heap size when available. Add Kconfig option SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE (default 20480) as fallback when extended init data is not present or does not provide heap sizes. Sanity-check the requested sizes (reject values above 64 MB or below the dp_heap_user prefix) and log the allocated heap size. Also pass ext_init through module_adapter_mem_alloc() to module_adapter_dp_heap_new() and fix a minor comment typo. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Use IPC module init extended data (dp_data stack_bytes) to set the DP processing thread stack size when available. Fall back to TASK_DP_STACK_SIZE when ext init data is not present or does not provide a stack size. Add Kconfig option ZEPHYR_DP_SCHEDULER_MIN_STACK_SIZE (default 2048) to enforce a minimum stack size regardless of what the IPC payload requests. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Name DP threads using k_thread_name_set() with the component ID in hex. This makes it easier to identify DP threads in debug tools and Zephyr shell thread listings. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
The widget specific stack requirement works in such a way that all components in a pipeline have their stack requirements, and the pipeline stack size will be the highest of those values. I am not sure if this is actually the best method. I am not sure what factors affect the required stack size for a pipeline, but for now this will have to do. So 4k is not enough for all pipelines, and these generic numbers are here to guarantee that everything works until we have fine tuned values for all the modules. So increase the number to 8k to guarantee functionality. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Fine tune SRC DP memory requirements to values that should satisfy all use-cases, without using too much memory. For now the biggest memory consumers, the SRAM copy of the filter coefficients, and the filter memory, are not allocated in init phase, but in prepare. That is why the interim requirement is so high and lifetime requirement so low. This can be changed but it needs changes in SRC processing module code. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Ring buffers at LL/DP boundaries are created during pipeline_connect and persist until module free. They are never freed and reallocated across prepare/reset cycles, so they belong in the lifetime partition rather than interim. This allows DP modules to use a smaller interim partition since the ring buffer struct and data buffer no longer consume interim space. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Refactor the vregion memory layout to use a single contiguous buffer instead of two separately page-aligned partitions. The vregion struct is placed at the base, followed by lifetime allocations growing upward. The interim k_heap is created lazily on the first interim allocation from whatever space remains after lifetime allocations. This eliminates the rigid partition boundary that previously wasted memory when lifetime usage was smaller or larger than pre-configured. The interim heap creation is deferred until actually needed, at which point the lifetime region is sealed and any further lifetime allocation requests are redirected to the interim heap with a warning. Key changes: - vregion_create(): Sum lifetime+interim into one buffer, no k_heap init at creation time - New interim_heap_init(): Called lazily, page-aligns interim start, logs lifetime used and interim available at INFO level - lifetime_alloc(): Falls back to interim with warning if called after interim is initialized - interim_alloc(): Triggers interim_heap_init() on first call - vregion_free(): Guards interim pointer range check with interim_initialized flag Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add a third memory type that uses lifetime before the interim heap is initialized and interim after, without triggering interim heap creation or logging a warning. This is suitable for small metadata allocations that do not care which partition they reside in. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Object pool metadata does not need to reside in a specific partition. Use INDIFFERENT so pool blocks go to lifetime before the interim heap is created and to interim afterwards, without triggering premature interim heap initialization. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add a vregion_type field to struct mod_alloc_ctx to track the current vregion allocation mode for each module. Initialize it to VREGION_MEM_TYPE_LIFETIME during module_adapter_mem_alloc() so that all allocations during module creation and init use the lifetime partition. Switch it to VREGION_MEM_TYPE_INTERIM at the start of module_adapter_prepare() so that runtime allocations use the interim partition. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Use vregion_type from strcut mod_alloc_ctx, when vregion is available, for buffer allocations. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Get mod_alloc() vregions vregion_mem_type from struct mod_alloc_ctx. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Use vregion_type from struct mod_alloc_ctx to control which vregion memory type fast_get() uses for allocations. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Refactor SRC and SRC-lite so that filter stage setup and delay line allocation happen during the module init callback instead of prepare. This ensures the bulk of SRC memory allocation occurs while the vregion allocator is still in its lifetime phase, before the interim heap is created. The allocations then persist across prepare/reset cycles without needing to be re-allocated each time. A new setup_stages() callback is added to struct comp_data, set by each variant (src.c, src_lite.c) to point at its own coefficient tables. The common src_allocate_delay_lines() is factored out of the old prepare path into src_common.c. For IPC4, src_init_stages() calls setup_stages() and src_allocate_delay_lines() at init time. The prepare path (src_prepare_do) only validates rates and sets downstream params. For IPC3, src_init_stages() is a no-op and src_prepare_do() retains the original behavior of doing full setup at prepare time, since IPC3 cannot be tested at this time. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is now more like a proof of concept, rather than a proper mergeable implementation.
For the time being the vregions is only used for DP modules, but if I have understood the plans correctly, eventually the LL pipelines should have their own vregions context that is used for all allocation related to the pipeline and modules in it (except the DP modules).
Before this PR the vregions lifetime memory is really not used at all. The only place where it could be used is an SRC DP module (SRC being the only DP capable module we have) , and this PR moves throws the balance of lifetime and interim allocs to the other end. After this PR all the allocations for DP SRC module is made from lifetime heap. SRC and DP infrastucture uses heap only for allocating memory for things that are needed for the whole lifetime of the module, and no interim memory is needed.
The things that I still plan to do for DP case:
As a follow up, take vregions also into use for complete LL pipelines. But before even starting this work we'd better get userspace LL merged.
FYI @lgirdwood , @lyakh , @kv2019i