-
Notifications
You must be signed in to change notification settings - Fork 349
[WIP][RFC] pipeline: move generic mem alloc to pipeline #4192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Help in testing accepted :) Recent changes in driver should create the pipeline before components -> we could store all memory pointers in 1 place i.e. pipeline that holds the components. |
|
@RanderWang please use this in your work. |
|
@lgirdwood @juimonen I want to make allocation and deallocation more simple. For audio case, we allocate memory at initializing stage and never allocate any memory dynamically when doing playback or capture. So we can allocate big block of memory based on pipeline memory information which contains all memory usage for each modules, then just increase memory used pointer for each allocation which will save memory without any container. And we just return the whole memory block to OS when pipeline is released. |
lgirdwood
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good.
src/audio/pipeline/pipeline-graph.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pass in caps here too.
In most cases this is fine, but there are some cases when we need to load new coefficients or different config data that means a runtime reallocation.
Let's be more clever here. Passing in the memory size from topology puts a lot of effort on the topology developer. The compiler can do this for us in most cases. We need to add a struct comp x {
.heap_min = align_up(sizeof(x_priv_data) + sizeof(data1) + CONFIG_X_ITEMS * sizeof(data2), cache_line_size),
.heap_max = "heap_min" + CONFIG_X_MAX_ITEM2 * sizeof(data2),
};So I think @juimonen work is the 1st stage in this work, i.e we can merge it first and then build on top. |
Actually we do memory usage calculation in driver and also depend on compiler to calculate bss size and store it in module config by rimage when analyzing fw elf file (although rimage doesn't do it now since no such module support in sof fw).
|
We need to do this for a short time, but it's not long term viable since it tightly couples the kernel to the FW and can mean kernel fixes to fix FW issues. Can you paste the calculation code here ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just confirm that this is intended and correct - before the change this was freeing one specific object, now after this change this is freeing all allocated blocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All pipeline objects will be in a block, but this does need checking here.
lyakh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general comment: in the kernel devm_ means automatic resource management. pipeline_devm_alloc() added in this PR doesn't seem to be doing that. If adding that automation is planned in the near future, maybe it's ok, but it would be even better to first add that and then implement this to make sure we don't delete the code we added a short time ago. If this isn't planned maybe it would be better not to use devm_ here
Intention this should be adding each pipeline allocation to a list and freeing when pipeline is destroyed. @juimonen will this be in subsequent patches ? @ranj063 @RanderWang fyi |
It is for CAVS FW. bss is stored in module_entry. ret = processor->get_mem_size(sdev, swidget, &ibs, &obs, &bss);
if (ret < 0)
return ret;
task_mem = SOF_IPC4_PIPELINE_OBJECT_SIZE;
task_mem += SOF_IPC4_MODULE_INSTANCE_LIST_ITEM_SIZE + bss;
if (sdev->fw_modules[module_id].type & SOF_IPC4_MODULE_LL)
{
task_mem += SOF_IPC4_FW_ROUNDUP(SOF_IPC4_LL_TASK_OBJECT_SIZE);
task_mem += SOF_IPC4_FW_MAX_QUEUE_COUNT * SOF_IPC4_MODULE_INSTANCE_LIST_ITEM_SIZE;
task_mem += SOF_IPC4_LL_TASK_LIST_ITEM_SIZE;
}
else
{
task_mem += SOF_IPC4_FW_ROUNDUP(SOF_IPC4_DP_TASK_OBJECT_SIZE);
task_mem += SOF_IPC4_DP_TASK_LIST_SIZE;
}
ibs = SOF_IPC4_FW_ROUNDUP(ibs);
queue_mem = SOF_IPC4_FW_MAX_QUEUE_COUNT * (SOF_IPC4_DATA_QUEUE_OBJECT_SIZE + 4 * ibs);
total = SOF_IPC4_FW_PAGE(task_mem + queue_mem);
if (total > SOF_IPC4_FW_MAX_PAGE_COUNT) {
dev_info(sdev->dev, "task memory usage %d, queue memory usage %d", task_mem, queue_mem);
total = SOF_IPC4_FW_MAX_PAGE_COUNT;
}
|
lyakh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks better IMHO!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pipeline_devm_alloc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
src/audio/pipeline/pipeline-graph.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rfree(container)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
src/audio/pipeline/pipeline-graph.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment isn't valid any more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will remove
|
@lyakh fyi
|
|
@RanderWang any other input from you - this will be a fist step from which we can integrate more into IPC4 code. |
Codec adapter has a devm_kzalloc type memory allocator to allocate multiple chunks of memory into a list, which can be then freed without explicit pointers in codec deletion. Move this generic mechanism to pipeline class. This is possible as recent changes in driver create the pipeline before its components. Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
|
Can I somehow tell CI to ignore this CamelCase error, which I haven't even introduced? |
Dont worry too much about the CamelCase, the doxygen and build reports are the CIs that need to be fixed. |
|
@RanderWang is this ready to merge on ipc4 branch yet ? |
@lgirdwood this is not complete. We need to replace all the memory allocation related. I can refine ipc4 layer and new ipc4 module to allocate memory from pipeline. |
| } | ||
| } | ||
|
|
||
| void *pipeline_devm_alloc(struct pipeline *pipe, uint32_t size, uint32_t alignment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need add caps for args since for ipc4 we need difference caps for different cases
|
@ranj063 fyi - needed for module API |
| return 0; | ||
|
|
||
| /* Find which container keeps this memory */ | ||
| list_for_item_safe(mem_list, _mem_list, &pipe->mem.mem_list) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for _safe - the function only deletes a single element once and returns immediately after that.
| return ptr; | ||
| } | ||
|
|
||
| int pipeline_devm_free(struct pipeline *pipe, void *ptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's never called, do we need it?
|
Can one of the admins verify this patch? |
|
Close - can re-open for integration after module API if needed. |
Codec adapter has a devm_kzalloc type memory allocator to allocate
multiple chunks of memory into a list, which can be then freed without
explicit pointers in codec deletion. Move this generic mechanism to
pipeline class. This is possible as recent changes in driver create the
pipeline before its components.
Signed-off-by: Jaska Uimonen jaska.uimonen@intel.com