<p dir="ltr"></p>
<p dir="ltr">2013/6/22 Jerome Glisse <<a href="mailto:j.glisse@gmail.com">j.glisse@gmail.com</a>>:<br>
> On Fri, Jun 21, 2013 at 12:55 PM, Inki Dae <<a href="mailto:daeinki@gmail.com">daeinki@gmail.com</a>> wrote:<br>
>> 2013/6/21 Lucas Stach <<a href="mailto:l.stach@pengutronix.de">l.stach@pengutronix.de</a>>:<br>
>>> Hi Inki,<br>
>>><br>
>>> please refrain from sending HTML Mails, it makes proper quoting without<br>
>>> messing up the layout everywhere pretty hard.<br>
>>><br>
>><br>
>> Sorry about that. I should have used text mode.<br>
>><br>
>>> Am Freitag, den 21.06.2013, 20:01 +0900 schrieb Inki Dae:<br>
>>> [...]<br>
>>><br>
>>>> Yeah, you'll some knowledge and understanding about the API<br>
>>>> you are<br>
>>>> working with to get things right. But I think it's not an<br>
>>>> unreasonable<br>
>>>> thing to expect the programmer working directly with kernel<br>
>>>> interfaces<br>
>>>> to read up on how things work.<br>
>>>><br>
>>>> Second thing: I'll rather have *one* consistent API for every<br>
>>>> subsystem,<br>
>>>> even if they differ from each other than having to implement<br>
>>>> this<br>
>>>> syncpoint thing in every subsystem. Remember: a single execbuf<br>
>>>> in DRM<br>
>>>> might reference both GEM objects backed by dma-buf as well<br>
>>>> native SHM or<br>
>>>> CMA backed objects. The dma-buf-mgr proposal already allows<br>
>>>> you to<br>
>>>> handle dma-bufs much the same way during validation than<br>
>>>> native GEM<br>
>>>> objects.<br>
>>>><br>
>>>> Actually, at first I had implemented a fence helper framework based on<br>
>>>> reservation and dma fence to provide easy-use-interface for device<br>
>>>> drivers. However, that was wrong implemention: I had not only<br>
>>>> customized the dma fence but also not considered dead lock issue.<br>
>>>> After that, I have reimplemented it as dmabuf sync to solve dead<br>
>>>> issue, and at that time, I realized that we first need to concentrate<br>
>>>> on the most basic thing: the fact CPU and CPU, CPU and DMA, or DMA and<br>
>>>> DMA can access a same buffer, And the fact simple is the best, and the<br>
>>>> fact we need not only kernel side but also user side interfaces. After<br>
>>>> that, I collected what is the common part for all subsystems, and I<br>
>>>> have devised this dmabuf sync framework for it. I'm not really<br>
>>>> specialist in Desktop world. So question. isn't the execbuf used only<br>
>>>> for the GPU? the gpu has dedicated video memory(VRAM) so it needs<br>
>>>> migration mechanism between system memory and the dedicated video<br>
>>>> memory, and also to consider ordering issue while be migrated.<br>
>>>><br>
>>><br>
>>> Yeah, execbuf is pretty GPU specific, but I don't see how this matters<br>
>>> for this discussion. Also I don't see a big difference between embedded<br>
>>> and desktop GPUs. Buffer migration is more of a detail here. Both take<br>
>>> command stream that potentially reference other buffers, which might be<br>
>>> native GEM or dma-buf backed objects. Both have to make sure the buffers<br>
>>> are in the right domain (caches cleaned and address mappings set up) and<br>
>>> are available for the desired operation, meaning you have to sync with<br>
>>> other DMA engines and maybe also with CPU.<br>
>><br>
>> Yeah, right. Then, in case of desktop gpu, does't it need additional<br>
>> something to do when a buffer/s is/are migrated from system memory to<br>
>> video memory domain, or from video memory to system memory domain? I<br>
>> guess the below members does similar thing, and all other DMA devices<br>
>> would not need them:<br>
>> struct fence {<br>
>> ...<br>
>> unsigned int context, seqno;<br>
>> ...<br>
>> };<br>
>><br>
>> And,<br>
>> struct seqno_fence {<br>
>> ...<br>
>> uint32_t seqno_ofs;<br>
>> ...<br>
>> };<br>
>><br>
>>><br>
>>> The only case where sync isn't clearly defined right now by the current<br>
>>> API entrypoints is when you access memory through the dma-buf fallback<br>
>>> mmap support, which might happen with some software processing element<br>
>>> in a video pipeline or something. I agree that we will need a userspace<br>
>>> interface here, but I think this shouldn't be yet another sync object,<br>
>>> but rather more a prepare/fini_cpu_access ioctl on the dma-buf which<br>
>>> hooks into the existing dma-fence and reservation stuff.<br>
>><br>
>> I think we don't need addition ioctl commands for that. I am thinking<br>
>> of using existing resources as possible. My idea also is similar in<br>
>> using the reservation stuff to your idea because my approach also<br>
>> should use the dma-buf resource. However, My idea is that a user<br>
>> process, that wants buffer synchronization with the other, sees a sync<br>
>> object as a file descriptor like dma-buf does. The below shows simple<br>
>> my idea about it:<br>
>><br>
>> ioctl(dmabuf_fd, DMA_BUF_IOC_OPEN_SYNC, &sync);<br>
>><br>
>> flock(sync->fd, LOCK_SH); <- LOCK_SH means a shared lock.<br>
>> CPU access for read<br>
>> flock(sync->fd, LOCK_UN);<br>
>><br>
>> Or<br>
>><br>
>> flock(sync->fd, LOCK_EX); <- LOCK_EX means an exclusive lock<br>
>> CPU access for write<br>
>> flock(sync->fd, LOCK_UN);<br>
>><br>
>> close(sync->fd);<br>
>><br>
>> As you know, that's similar to dmabuf export feature.<br>
>><br>
>> In addition, a more simple idea,<br>
>> flock(dmabuf_fd, LOCK_SH/EX);<br>
>> CPU access for read/write<br>
>> flock(dmabuf_fd, LOCK_UN);<br>
>><br>
>> However, I'm not sure that the above examples could be worked well,<br>
>> and there are no problems yet: actually, I don't fully understand<br>
>> flock mechanism, so looking into it.<br>
>><br>
>>><br>
>>>><br>
>>>> And to get back to my original point: if you have more than<br>
>>>> one task<br>
>>>> operating together on a buffer you absolutely need some kind<br>
>>>> of real IPC<br>
>>>> to sync them up and do something useful. Both you syncpoints<br>
>>>> and the<br>
>>>> proposed dma-fences only protect the buffer accesses to make<br>
>>>> sure<br>
>>>> different task don't stomp on each other. There is nothing in<br>
>>>> there to<br>
>>>> make sure that the output of your pipeline is valid. You have<br>
>>>> to take<br>
>>>> care of that yourself in userspace. I'll reuse your example to<br>
>>>> make it<br>
>>>> clear what I mean:<br>
>>>><br>
>>>> Task A Task B<br>
>>>> ------ -------<br>
>>>> dma_buf_sync_lock(buf1)<br>
>>>> CPU write buf1<br>
>>>> dma_buf_sync_unlock(buf1)<br>
>>>> ---------schedule Task A again-------<br>
>>>> dma_buf_sync_lock(buf1)<br>
>>>> CPU write buf1<br>
>>>> dma_buf_sync_unlock(buf1)<br>
>>>> ---------schedule Task B---------<br>
>>>> qbuf(buf1)<br>
>>>><br>
>>>> dma_buf_sync_lock(buf1)<br>
>>>> ....<br>
>>>><br>
>>>> This is what can happen if you don't take care of proper<br>
>>>> syncing. Task A<br>
>>>> writes something to the buffer in expectation that Task B will<br>
>>>> take care<br>
>>>> of it, but before Task B even gets scheduled Task A overwrites<br>
>>>> the<br>
>>>> buffer again. Not what you wanted, isn't it?<br>
>>>><br>
>>>> Exactly wrong example. I had already mentioned about that. "In case<br>
>>>> that data flow goes from A to B, it needs some kind of IPC between the<br>
>>>> two tasks every time" So again, your example would have no any<br>
>>>> problem in case that *two tasks share the same buffer but these tasks<br>
>>>> access the buffer(buf1) as write, and data of the buffer(buf1) isn't<br>
>>>> needed to be shared*. They just need to use the buffer as *storage*.<br>
>>>> So All they want is to avoid stomping on the buffer in this case.<br>
>>>><br>
>>> Sorry, but I don't see the point. If no one is interested in the data of<br>
>>> the buffer, why are you sharing it in the first place?<br>
>>><br>
>><br>
>> Just used as a storage. i.e., Task A fills the buffer with "AAAAAA"<br>
>> using CPU, And Task B fills the buffer with "BBBBBB" using DMA. They<br>
>> don't share data of the buffer, but they share *memory region* of the<br>
>> buffer. That would be very useful for the embedded systems with very<br>
>> small size system memory.<br>
><br>
> Just so i understand. You want to share backing memory, you don't want<br>
> to share content ie you want to do memory management in userspace.<br>
> This sounds wrong on so many level (not even considering the security<br>
> implication).<br>
><br>
> If Task A need memory and then can release it for Task B usage that<br>
> should be the role of kernel memory management which of course needs<br>
> synchronization btw A and B. But in no case this should be done using<br>
> dma-buf. dma-buf is for sharing content btw different devices not<br>
> sharing resources.<br>
></p>
<p dir="ltr">Just simply let's think of the case that a user process doesn't want for anyone, other CPU or DMA, to access a shared buffer while he is accessing the shared buffer. In this case, useful.</p>
<p dir="ltr">Thanks,<br>
Inki Dae</p>
<p dir="ltr">><br>
> Also don't over complicate the vram case, just consider desktop gpu as<br>
> using system memory directly. They can do it and they do it. Migration<br>
> to vram is orthogonal to all this, it's an optimization so to speak.<br>
><br>
> Cheers,<br>
> Jerome.  </p>