diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2014-02-24 11:51:03 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-03-11 05:56:41 -0400 |
commit | b3379c6201bb3555298cdbf0aa004af260f2a6a4 (patch) | |
tree | 936271737c6bdcf27a40d0af2ad9ab0d2f5533fa /drivers/staging | |
parent | a7afcaccfab2fb012841852eaead79861dc9cb5f (diff) |
[media] vb2: only call start_streaming if sufficient buffers are queued
In commit 02f142ecd24aaf891324ffba8527284c1731b561 support was added to
start_streaming to return -ENOBUFS if insufficient buffers were queued
for the DMA engine to start. The vb2 core would attempt calling
start_streaming again if another buffer would be queued up.
Later analysis uncovered problems with the queue management if start_streaming
would return an error: the buffers are enqueued to the driver before the
start_streaming op is called, so after an error they are never returned to
the vb2 core. The solution for this is to let the driver return them to
the vb2 core in case of an error while starting the DMA engine. However,
in the case of -ENOBUFS that would be weird: it is not a real error, it
just says that more buffers are needed. Requiring start_streaming to give
them back only to have them requeued again the next time the application
calls QBUF is inefficient.
This patch changes this mechanism: it adds a 'min_buffers_needed' field
to vb2_queue that drivers can set with the minimum number of buffers
required to start the DMA engine. The start_streaming op is only called
if enough buffers are queued. The -ENOBUFS handling has been dropped in
favor of this new method.
Drivers are expected to return buffers back to vb2 core with state QUEUED
if start_streaming would return an error. The vb2 core checks for this
and produces a warning if that didn't happen and it will forcefully
reclaim such buffers to ensure that the internal vb2 core state remains
consistent and all buffer-related resources have been correctly freed
and all op calls have been balanced.
__reqbufs() has been updated to check that at least min_buffers_needed
buffers could be allocated. If fewer buffers were allocated then __reqbufs
will free what was allocated and return -ENOMEM. Based on a suggestion from
Pawel Osciak.
__create_bufs() doesn't do that check, since the use of __create_bufs
assumes some advance scenario where the user might want more control.
Instead streamon will check if enough buffers were allocated to prevent
streaming with fewer than the minimum required number of buffers.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/media/davinci_vpfe/vpfe_video.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c index 1f3b0f9a8d10..8c101cbbee97 100644 --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c | |||
@@ -1201,8 +1201,6 @@ static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count) | |||
1201 | unsigned long addr; | 1201 | unsigned long addr; |
1202 | int ret; | 1202 | int ret; |
1203 | 1203 | ||
1204 | if (count == 0) | ||
1205 | return -ENOBUFS; | ||
1206 | ret = mutex_lock_interruptible(&video->lock); | 1204 | ret = mutex_lock_interruptible(&video->lock); |
1207 | if (ret) | 1205 | if (ret) |
1208 | goto streamoff; | 1206 | goto streamoff; |
@@ -1327,6 +1325,7 @@ static int vpfe_reqbufs(struct file *file, void *priv, | |||
1327 | q->type = req_buf->type; | 1325 | q->type = req_buf->type; |
1328 | q->io_modes = VB2_MMAP | VB2_USERPTR; | 1326 | q->io_modes = VB2_MMAP | VB2_USERPTR; |
1329 | q->drv_priv = fh; | 1327 | q->drv_priv = fh; |
1328 | q->min_buffers_needed = 1; | ||
1330 | q->ops = &video_qops; | 1329 | q->ops = &video_qops; |
1331 | q->mem_ops = &vb2_dma_contig_memops; | 1330 | q->mem_ops = &vb2_dma_contig_memops; |
1332 | q->buf_struct_size = sizeof(struct vpfe_cap_buffer); | 1331 | q->buf_struct_size = sizeof(struct vpfe_cap_buffer); |