From: Hans Verkuil <hverkuil@xs4all.nl>
To: Ran Shalit <ranshalit@gmail.com>
Cc: linux-media@vger.kernel.org
Subject: Re: cobalt & dma
Date: Fri, 20 Nov 2015 15:55:39 +0100 [thread overview]
Message-ID: <564F346B.3090504@xs4all.nl> (raw)
In-Reply-To: <CAJ2oMhKX4uq=Wd02=ZN7YUEVHuo_rjFi3VNkbfQDxL0O+_YmOA@mail.gmail.com>
On 11/20/2015 03:49 PM, Ran Shalit wrote:
> Hello,
>
>
>
>>
>> No. All video capture/output devices all use DMA since it would be prohibitively
>> expensive for the CPU to do otherwise. So just dig in and implement it.
>
> I am trying to better understand how read() operation actually use the
> dma, but I can't yet understand it from code.
>
>>
>> No. The vmalloc variant is typically used for USB devices. For PCI(e) you'll
>> use videobuf2-dma-contig if the DMA engine requires physically contiguous DMA,
>> or videobuf2-dma-sg if the DMA engine supports scatter-gather DMA. You can
>> start with dma-contig since the DMA code tends to be simpler, but it is
>> harder to get the required physically contiguous memory if memory fragmentation
>> takes place. So you may not be able to allocate the buffers. dma-sg works much
>> better with virtual memory.
>>
>>
>
>
> 1. I tried to understand the code implementation of videobuf2 with
> regards to read():
> read() ->
> vb2_read() ->
> __vb2_perform_fileio()->
> vb2_internal_dqbuf() & copy_to_user()
>
> Where is the actual allocation of dma contiguous memory ? Is done with
> the userspace calloc() call in userspace (as shown in the v4l2 API
> example) ? As I understand the calloc/malloc are not guaranteed to be
> contiguous.
> How do I know if the try to allocate contigious memory has failed or not ?
The actual allocation happens in videobuf2-vmalloc/dma-contig/dma-sg depending
on the flavor of buffers you want (virtual memory, DMA into physically contiguous
memory or DMA into scatter-gather memory). The alloc operation is the one that
allocates the memory.
>
>
> 2. Is the call to copy_to_user results is performance degredation of
> read() in compare to mmap() method ?
Correct. But if you use the vb2 framework then you get stream I/O and the
read/write operations for free. vb2_read() sits on top of the stream I/O
implementation. It basically requests buffers and loops while queuing and
dequeuing buffers and calling copy_to_user() to copy the data into the
read() buffer.
This is (very) inefficient and applications should use the V4L2 stream I/O
mechanism directly.
Regards,
Hans
next prev parent reply other threads:[~2015-11-20 14:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-17 7:39 cobalt & dma Ran Shalit
2015-11-17 7:53 ` Hans Verkuil
2015-11-17 13:15 ` Ran Shalit
2015-11-17 13:32 ` Steven Toth
2015-11-17 13:54 ` Hans Verkuil
2015-11-17 21:43 ` Ran Shalit
2015-11-20 14:49 ` Ran Shalit
2015-11-20 14:55 ` Hans Verkuil [this message]
2015-11-20 16:14 ` Ran Shalit
2015-11-20 16:25 ` Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=564F346B.3090504@xs4all.nl \
--to=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=ranshalit@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox