Skip to content

Memory attributes to user space dp module#10603

Open
jsarha wants to merge 3 commits intothesofproject:mainfrom
jsarha:memory_attributes_to_user_space_dp_module
Open

Memory attributes to user space dp module#10603
jsarha wants to merge 3 commits intothesofproject:mainfrom
jsarha:memory_attributes_to_user_space_dp_module

Conversation

@jsarha
Copy link
Copy Markdown
Contributor

@jsarha jsarha commented Mar 5, 2026

Pass current DP memory attributes to the user-space DP thread.

This implementation does not do anything before we have thesofproject/linux#5537 merged (and before that we should merge #10544).

So quite a few conditions before CI can get any hold of this. I'll mark this as draft for now, even if the implementation is mostly complete. FYI @lyakh , @kv2019i , @lgirdwood.

return NULL;
}
#endif
const struct module_ext_init_data *ext_init =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: You could probably pass only dp_data to module_adapter_mem_alloc instead of the entire structure ext_data.
Since the ext_data is 0-initialized, the dp_data pointer is already set to NULL so you probably wouldn't need the "#if":

@lgirdwood
Copy link
Copy Markdown
Member

@jsarha ping, any update ?

@jsarha
Copy link
Copy Markdown
Contributor Author

jsarha commented Mar 31, 2026

@jsarha ping, any update ?

@lgirdwood this PR does not do anything and it can not be tested before we merge thesofproject/linux#5537 . So I rather keep this as draft until then.

Jyri Sarha added 3 commits April 15, 2026 17:17
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 module ext init dp_data to size the DP module heap when
available. Keep the default heap size fallback for cases where
extended init data is not present or does not provide a usable size.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Select DP thread stack size in pipeline_comp_dp_task_init() from
module ext init dp_data when stack_bytes is provided. Keep
TASK_DP_STACK_SIZE as the fallback default.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
@jsarha jsarha force-pushed the memory_attributes_to_user_space_dp_module branch from 43000f8 to 3d9b5c4 Compare April 15, 2026 21:00
@jsarha
Copy link
Copy Markdown
Contributor Author

jsarha commented Apr 15, 2026

Rebased and tested against rebased thesofproject/linux#5537 . Ready for review.

@jsarha jsarha marked this pull request as ready for review April 15, 2026 21:11
Copilot AI review requested due to automatic review settings April 15, 2026 21:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR propagates IPC4 DP memory requirements (stack and heap sizing) into the SOF userspace DP module initialization path, so the DP thread and per-module heap can be sized based on dp_data from the extended init payload.

Changes:

  • Allow DP task stack size to be taken from IPC4 dp_data->stack_bytes instead of a fixed default.
  • Allow the DP module heap allocation size to be derived from IPC4 dp_data interim/lifetime heap requirements.
  • Thread the decoded extended-init (ext_init) info into the module adapter memory allocation path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/audio/pipeline/pipeline-schedule.c Uses IPC4 dp_data->stack_bytes to size the DP task stack at creation time.
src/audio/module_adapter/module_adapter.c Uses IPC4 dp_data to size the per-module DP heap allocation and passes ext-init data into allocation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +68 to +81
#if CONFIG_IPC_MAJOR_4
if (config->ipc_extended_init && ext_init && ext_init->dp_data &&
(ext_init->dp_data->lifetime_heap_bytes > 0 ||
ext_init->dp_data->interim_heap_bytes)) {
/*
* For the moment there is only one heap so sum up
* lifetime and interim values. It is also a conscious
* decision here to count the size of struct
* dp_heap_user to be included into required heap
* size.
*/
buf_size = ext_init->dp_data->lifetime_heap_bytes +
ext_init->dp_data->interim_heap_bytes;
}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

DP heap size calculation appears to under-allocate and can underflow. buf_size is set to lifetime_heap_bytes + interim_heap_bytes, but later the usable heap is computed as buf_size - heap_prefix_size; if the IPC values are meant to be the required heap size (per IPC4 comments), you likely need to allocate required + heap_prefix_size so the heap has the requested capacity. Also, if the sum is smaller than heap_prefix_size, buf_size - heap_prefix_size will wrap (size_t underflow) and k_heap_init() will be called with an invalid huge size.

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +81
buf_size = ext_init->dp_data->lifetime_heap_bytes +
ext_init->dp_data->interim_heap_bytes;
}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

Potential integer overflow/wrap: lifetime_heap_bytes and interim_heap_bytes are uint32_t, so lifetime + interim is computed in 32-bit and can wrap before being assigned to size_t. Cast to size_t before adding and consider bounding the requested size to avoid pathological allocations from IPC input.

Copilot uses AI. Check for mistakes.
#if CONFIG_IPC_MAJOR_4
if (config->ipc_extended_init && ext_init && ext_init->dp_data &&
(ext_init->dp_data->lifetime_heap_bytes > 0 ||
ext_init->dp_data->interim_heap_bytes)) {
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

The condition mixes an explicit comparison with an implicit non-zero test: ... || ext_init->dp_data->interim_heap_bytes). For consistency/readability (and to avoid surprises if the type changes), compare interim_heap_bytes > 0 like the lifetime field.

Suggested change
ext_init->dp_data->interim_heap_bytes)) {
ext_init->dp_data->interim_heap_bytes > 0)) {

Copilot uses AI. Check for mistakes.
Comment on lines +408 to +410
mod->priv.cfg.ext_data->dp_data->stack_bytes > 0)
stack_size = mod->priv.cfg.ext_data->dp_data->stack_bytes;

Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

DP task stack sizing should enforce a minimum (and potentially alignment) rather than blindly accepting any positive dp_data->stack_bytes. If the IPC value is smaller than TASK_DP_STACK_SIZE (or smaller than what Zephyr requires), this can create an undersized stack and lead to runtime crashes; consider clamping with max(TASK_DP_STACK_SIZE, requested) (and/or rejecting too-small values).

Suggested change
mod->priv.cfg.ext_data->dp_data->stack_bytes > 0)
stack_size = mod->priv.cfg.ext_data->dp_data->stack_bytes;
mod->priv.cfg.ext_data->dp_data->stack_bytes > 0) {
size_t requested_stack_size = mod->priv.cfg.ext_data->dp_data->stack_bytes;
if (requested_stack_size > TASK_DP_STACK_SIZE)
stack_size = requested_stack_size;
}

Copilot uses AI. Check for mistakes.
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.

4 participants