-
Notifications
You must be signed in to change notification settings - Fork 341
Revert changing the DMA allocator via public API and use environment variables #1344
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
62acb6c to
5dc525a
Compare
|
As I said in the original PR:
Originally posted by @rgetz in #1264 (comment) I think this is still the same. |
local-dmabuf.c
Outdated
| * Environment variable format: | ||
| * - LIBIIO_DMA_HEAP_PATH=heap_name (applies to all devices) | ||
| * - LIBIIO_DMA_HEAP_PATH=heap_name:device1 (applies only to device1) | ||
| * - LIBIIO_DMA_HEAP_PATH=heap_name:device1,device2 (applies to device1 and device2) |
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.
Hmm, I would make this way more simple for now. I guess the ENV var is ok (even though I would likely go for the compile time option) but make it simple. Meaning, just give in the allocator name. For now this is a system thing and we don't really need to have a per device setting. Let's deal with this when we really have an use case for that.
The above is one of the reasons why I would likely go with a build option. ATM, this is kind of a system level decision and the build option would be the simpler approach for that. But as I said, I guess I can live with the env var (even though that brings a runtime penalty - but not when streaming at least).
Unfortunately, there's no way in the kernel to do that (AFAIK) and I feel it would not be trivial to abstract what every device needs in terms of DMA mappings (and it would be for sure time consuming). We know we have users needing something like this so I feel this PR is a good compromise (As I said, I was also not convinced with what we previously had). And as I said before, this is really no different than what we already had (I mean, assuming that we always want the "system" heap). |
|
I mean, for peace of mind, @dNechita you can also try to look at some v4l2/media userspace tools in github and search for the dmabuf path . Some of these devices are also using dmabufs so we might see if they are doing something more clever. (if handling this at all in userspace). |
8291539 ("task: Implement iio_buffer_params struct and make CMA selectable at runtime") implemented iio_buffer_params, replacing idx with a struct. In the python binding, the change broke usage since dropped optional idx with required params. Define the struct in python, defaulting .idx to 0 and .dma_allocator = IIO_DMA_ALLOCATOR_SYSTEM, and make optional, to restore compatibility with legacy code (idx was hardly set). In case #1344 does not revert iio_buffer_params. Signed-off-by: Jorge Marques <[email protected]>
In libcamera there's a list of predefined paths and code can try to use one or a combination of paths. In a dmabuf v4l2 demo, it attempts to first open "linux,cma" and then "linux,reserved": I haven't found anything that does an automated detection other than having a hardcoded list of DMA paths and trying them one by one. |
Seems to be we should also try linux,reserved as that is also CMA (just renamed in a different way).
yeah, that was my feeling already. It goes along with what I was thinking in here: So, I think cameras are a very typical case where CMA memory is used but I think we could still have the same logic. Just try to open one of this (by the given order): In the future (if needed), we can still add some ENV variable to opt out from the above behavior. Meaning, to explicitly select one type of backing memory. |
c4cd63a to
0578731
Compare
0578731 to
4342d0e
Compare
nunojsa
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 the below could actually make sense (taking inspiration from libcamera):
But I guess that can be implemented aftwerwards
4342d0e to
cda2eea
Compare
nunojsa
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.
Just some minor stuff from me
local-dmabuf.c
Outdated
| "linux,cma", | ||
| "default-pool" | ||
| }; | ||
| static const size_t num_accepted_heaps = sizeof(accepted_heaps) / sizeof(accepted_heaps[0]); |
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 would imagine libiio defines somewhere ARRAY_SIZE(). If we have it, use it. Also there's no point in making it const and more important static. Why keeping that memory around after the call?
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 found ARRAY_SIZE() definition. Also, I removed the const and static.
local-dmabuf.c
Outdated
| "\"reserved\", \"linux,cma\", \"default-pool\". " | ||
| "Defaulting to \"system\"\n", env_value); | ||
|
|
||
| return "system"; |
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.
Not sure if this should not be an error given that the user indeed made an error and given that this happens locally one cannot easily realize what's the issue.
That said, up to you
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.
If I were the user, I would like to get an error instead of the library doing some else silently.
Updated.
| /* Determine DMA heap path from global environment variable */ | ||
| heap_name = get_dma_heap_name(); | ||
|
|
||
| ret = snprintf(dma_heap_path, sizeof(dma_heap_path), "/dev/dma_heap/%s", heap_name); |
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.
If we go the path of defaulting to "system" in case of error, you can just call get_dma_heap_name() inline in snprintf()
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.
Not applicable anymore.
This feature is targeted for users who experiment with or require alternative DMA allocators. It is to be determined if the feature becomes popular enough to be exposed through the public API or not. Signed-off-by: Dan Nechita <[email protected]>
Describe the LIBIIO_DMA_HEAP_PATH environment variable and provide an usage example. Signed-off-by: Dan Nechita <[email protected]>
cda2eea to
8f82357
Compare
|
I really like the precision and effort you put into such issues. High quality there - looking forward to test this. Thanks! |
Thank you! |
PR Description
"This reverts the functionality that allowed users to change the DMA allocator type through the public API. The use case is niche and rarely needed at present. The existing functionality supported two options: the default 'system' and 'cma,linux'—the latter being non-standard and system-dependent (see #1329), often requiring a custom string. Supporting this through the public API adds unnecessary complexity and risks future breakage. Instead, I am introducing an alternative approach for changing the DMA allocator that avoids impacting the API.
PR Type
PR Checklist