DMA-heap driver hints

Christian König christian.koenig at amd.com
Mon Jan 23 16:29:18 UTC 2023


Am 23.01.23 um 14:55 schrieb Laurent Pinchart:
> Hi Christian,
>
> CC'ing James as I think this is related to his work on the unix device
> memory allocator ([1]).
>
> [1] https://lore.kernel.org/dri-devel/8b555674-1c5b-c791-4547-2ea7c16aee6c@nvidia.com/
>
> On Mon, Jan 23, 2023 at 01:37:54PM +0100, Christian König wrote:
>> Hi guys,
>>
>> this is just an RFC! The last time we discussed the DMA-buf coherency
>> problem [1] we concluded that DMA-heap first needs a better way to
>> communicate to userspace which heap to use for a certain device.
>>
>> As far as I know userspace currently just hard codes that information
>> which is certainly not desirable considering that we should have this
>> inside the kernel as well.
>>
>> So what those two patches here do is to first add some
>> dma_heap_create_device_link() and  dma_heap_remove_device_link()
>> function and then demonstrating the functionality with uvcvideo
>> driver.
>>
>> The preferred DMA-heap is represented with a symlink in sysfs between
>> the device and the virtual DMA-heap device node.
> I'll start with a few high-level comments/questions:
>
> - Instead of tying drivers to heaps, have you considered a system where
>    a driver would expose constraints, and a heap would then be selected
>    based on those constraints ? A tight coupling between heaps and
>    drivers means downstream patches to drivers in order to use
>    vendor-specific heaps, that sounds painful.

I was wondering the same thing as well, but came to the conclusion that 
just the other way around is the less painful approach.

The problem is that there are so many driver specific constrains that I 
don't even know where to start from.

>    A constraint-based system would also, I think, be easier to extend
>    with additional constraints in the future.
>
> - I assume some drivers will be able to support multiple heaps. How do
>    you envision this being implemented ?

I don't really see an use case for this.

We do have some drivers which say: for this use case you can use 
whatever you want, but for that use case you need to use specific memory 
(scan out on GPUs for example works like this).

But those specific use cases are exactly that, very specific. And 
exposing all the constrains for them inside a kernel UAPI is a futile 
effort (at least for the GPU scan out case). In those situations it's 
just better to have the allocator in userspace deal with device specific 
stuff.

What I want to do is to separate the problem. The kernel only provides 
the information where to allocate from, figuring out the details like 
how many bytes, which format, plane layout etc.. is still the job of 
userspace.

What we do have is compatibility between heaps. E.g. a CMA heap is 
usually compatible with the system heap or might even be a subset of 
another CMA heap. But I wanted to add that as next step to the heaps 
framework itself.

> - Devices could have different constraints based on particular
>    configurations. For instance, a device may require specific memory
>    layout for multi-planar YUV formats only (as in allocating the Y and C
>    planes of NV12 from different memory banks). A dynamic API may thus be
>    needed (but may also be very painful to use from userspace).

Uff, good to know. But I'm not sure how to expose stuff like that.

>> What's still missing is certainly matching userspace for this since I
>> wanted to discuss the initial kernel approach first.
> https://git.libcamera.org/libcamera/libcamera.git/ would be a good place
> to prototype userspace support :-)

Thanks for the pointer and the review,
Christian.

>
>> Please take a look and comment.
>>
>> Thanks,
>> Christian.
>>
>> [1] https://lore.kernel.org/all/11a6f97c-e45f-f24b-8a73-48d5a388a2cc@gmail.com/T/



More information about the dri-devel mailing list