Memory attributes to user space dp module#10603
Conversation
| return NULL; | ||
| } | ||
| #endif | ||
| const struct module_ext_init_data *ext_init = |
There was a problem hiding this comment.
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":
There was a problem hiding this comment.
dp_data is defined only in ipc4 headers, so I think its easiest to keep it behind #if , and keep the module_adapter_mem_alloc() arguments the way they are.
|
@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. |
43000f8 to
3d9b5c4
Compare
|
Rebased and tested against rebased thesofproject/linux#5537 . Ready for review. |
There was a problem hiding this comment.
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_bytesinstead of a fixed default. - Allow the DP module heap allocation size to be derived from IPC4
dp_datainterim/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.
| mod->priv.cfg.ext_data->dp_data->stack_bytes > 0) | ||
| stack_size = mod->priv.cfg.ext_data->dp_data->stack_bytes; | ||
|
|
There was a problem hiding this comment.
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).
| 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; | |
| } |
There was a problem hiding this comment.
Ack, I think a minimum would be good.
| static struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv, | ||
| const struct comp_ipc_config *config) | ||
| static struct processing_module * | ||
| module_adapter_mem_alloc(const struct comp_driver *drv, |
There was a problem hiding this comment.
is this needed? Would the added third argument otherwise exceed 100 characters?
There was a problem hiding this comment.
If I put "static struct processing_module * module_adapter_mem_alloc(" on the same line and, arguments on top of each other, and align them to ( , then "const struct module_ext_init_data *ext_init" goes over 100 characters. I'll put "static" on separate line, that should be enough.
kv2019i
left a comment
There was a problem hiding this comment.
A few notes inline, please check.
| mod->priv.cfg.ext_data->dp_data->stack_bytes > 0) | ||
| stack_size = mod->priv.cfg.ext_data->dp_data->stack_bytes; | ||
|
|
There was a problem hiding this comment.
Ack, I think a minimum would be good.
d2578b5 to
8b70073
Compare
|
@kv2019i I addressed your comment here. |
| /* src-lite with 8 channels has been seen allocating 14k in one go */ | ||
| /* FIXME: the size will be derived from configuration */ | ||
| const size_t buf_size = 20 * 1024; | ||
| size_t buf_size = 20 * 1024; |
|
|
||
| if (mod->priv.cfg.ext_data && mod->priv.cfg.ext_data->dp_data && | ||
| mod->priv.cfg.ext_data->dp_data->stack_bytes > 0) | ||
| stack_size = MAX(mod->priv.cfg.ext_data->dp_data->stack_bytes, 2048); |
There was a problem hiding this comment.
I would Kconfig and log this size too.
kv2019i
left a comment
There was a problem hiding this comment.
One more q inline, please check.
8b70073 to
6bd9aad
Compare
| LOG_INF("Allocating %zu byte heap (default %zu) for %#x", buf_size, | ||
| CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE, config->id); | ||
| /* Keep uncached to match the default SOF heap! */ | ||
| /* Note that 'align' argumet is ignored by vmh backend */ |
There was a problem hiding this comment.
well, kind of... I see an assertion there. And maybe the idea is, that "nobody" would ever want to have alignment > size. As long as alignment <= size, the VMH will obey that implicitly because allocations are done in (respectively aligned) buckets. But a larger alignment will fail. But I agree, that that assumption doesn't look perfectly reasonable. I might well need to allocate 100 bytes at a page boundary.
There was a problem hiding this comment.
The comment was there to explain why I simply won't put buf_size = ALIGN_UP(buf_size, PAGE_SZ) here, instead of making sure the buffer can at least fit the heap prefix.
But now that you mentioned the assert() (I new it was there, but forgot about it), I think I should remove that alignment requirement, since its likely that the asset() fires if a heap smaller than a page is requested.
| * pointers to IPC payload mailbox, so its only valid in | ||
| * functions that called from this function. This why | ||
| * the pointer is set NULL before this function exits. | ||
| * functions that called from this function. This is why |
There was a problem hiding this comment.
while at it you could also fix "that are called..."
6bd9aad to
34a2c67
Compare
a103d37 to
4b50cac
Compare
kv2019i
left a comment
There was a problem hiding this comment.
One comment/question from Guennadi in last commit, but otherwise series seems good to me and my concerns addressed.
| domain_id 0 | ||
| stack_bytes_requirement 2048 | ||
| interim_heap_bytes_requirement 20480 | ||
| lifetime_heap_bytes_requirement 4096 |
77ba618 to
362854c
Compare
|
@jsarha can you check CI and rebase. Thanks ! |
362854c to
0bb25e7
Compare
| 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 > 0)) { | ||
| if (ext_init->dp_data->lifetime_heap_bytes > 64*1024*1024 || |
|
|
||
| config ZEPHYR_DP_SCHEDULER_MIN_STACK_SIZE | ||
| int "Minimum stack size for DP processing thread" | ||
| default 512 |
There was a problem hiding this comment.
What is source of this value? Can stack be smaller than the page size?
There was a problem hiding this comment.
@softwarecki , That is just from my head when addressing this:
#10603 (comment)
and this
#10603 (comment)
Would you like to change this safetylimit value? Perhaps increase it?
| /* FIXME: the size will be derived from configuration */ | ||
| const size_t buf_size = 28 * 1024; | ||
| size_t buf_size = CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE; | ||
| size_t lifetime_size = 4096; |
There was a problem hiding this comment.
Can we move this value to Kconfig instead of hardcoding it? Is this value related to memory page size?
There was a problem hiding this comment.
The separate lifetime heap size is not needed anymore now that #10863 is merged.
|
@jsarha ping |
| /* FIXME: the size will be derived from configuration */ | ||
| const size_t buf_size = 28 * 1024; | ||
| size_t buf_size = CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE; | ||
| size_t lifetime_size = 4096; |
There was a problem hiding this comment.
The separate lifetime heap size is not needed anymore now that #10863 is merged.
0bb25e7 to
6f74d9b
Compare
|
It seems our main branch does not produce a booting binary ATM, so I could not test this rebased version. That is why I added [DNM] tag in the headline. |
6f74d9b to
a8ccee9
Compare
|
Now this works after rebasing on a version from last week, |
|
|
||
| static struct vregion *module_adapter_dp_heap_new(const struct comp_ipc_config *config, | ||
| const struct module_ext_init_data *ext_init, | ||
| size_t *heap_size) |
There was a problem hiding this comment.
@jsarha an observation: heap_size is never used. This function is called only from one location and there the third argument of this function is unused. If you have to update this series, you could add a commit here (before this one please), or if this version gets merged, a follow-up is also ok.
a8ccee9 to
81e9909
Compare
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>
Remove unused heap_size parameter from module_adapter_dp_heap_new() function. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Use IPC module init extended data (the dp_data) 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) 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>
81e9909 to
5e259b9
Compare
Add a dummy Kconfig definition for SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE so the testbench build can resolve the symbol. The testbench does not use Zephyr, where this option is normally defined, so it needs a local fallback. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
54d2201 to
55e8d71
Compare
Add posix stub headers for <zephyr/logging/log.h> and <zephyr/sys/util.h> so that firmware source files using LOG_ERR, LOG_INF, LOG_WRN, LOG_DBG, KB, or MB can compile in the testbench / posix build without modification. Remove the #ifdef __ZEPHYR__ guard around the <zephyr/logging/log.h> include in sof/trace/trace.h and the <zephyr/sys/util.h> include in sof/common.h so the posix stubs are picked up automatically. The redundant LOG_MODULE_REGISTER / LOG_MODULE_DECLARE definitions in trace.h are removed since the posix stub now provides them. Remove the macros and fix couple of format string issues. Also the tools/logger CMakeList.txt requires some tuning to find the now unconditionally included zephyr/sys/util.h. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
55e8d71 to
2a53dfe
Compare
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.