Skip to contentSkip to conversation

vb2: Only requeue buffers immediately once streaming is started

PATCH Superseded Sakari Ailus 2 participants 5 messages Jul 3, 2015

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vb2: Only requeue buffers immediately once streaming is started

Buffers can be returned back to videobuf2 in driver's streamon handler. In this case vb2_buffer_done() with buffer state VB2_BUF_STATE_QUEUED will cause the driver's buf_queue vb2 operation to be called, queueing the same buffer again only to be returned to videobuf2 using vb2_buffer_done() and so on.

Add a new buffer state VB2_BUF_STATE_REQUEUEING which, when used as the state argument to vb2_buffer_done(), will result in buffers queued to the driver. Using VB2_BUF_STATE_QUEUED will leave the buffer to videobuf2, as it was before "[media] vb2: allow requeuing buffers while streaming".

Fixes ce0eff016f72 ("[media] vb2: allow requeuing buffers while streaming")
Cc [email protected] # for v4.1

---
since v1:

- Instead of relying on q->start_streaming_called and q->streaming, add a new buffer state VB2_BUF_STATE_REQUEUEING, as suggested by Hans. The cobalt driver will need the new flag as it returns the buffer back to the driver's queue, the rest will continue using VB2_BUF_STATE_QUEUED.

 drivers/media/pci/cobalt/cobalt-irq.c    |  2 +-
 drivers/media/v4l2-core/videobuf2-core.c | 15 +++++++++++----
 include/media/videobuf2-core.h           |  2 ++
 3 files changed, 14 insertions(+), 5 deletions(-)
drivers/media/pci/cobalt/cobalt-irq.c +1 -1
index e18f49e..2687cb0 100644
@@ -134,7 +134,7 @@ done:
 	   also know about dropped frames. */
 	cb->vb.v4l2_buf.sequence = s->sequence++;
 	vb2_buffer_done(&cb->vb, (skip || s->unstable_frame) ?
-			VB2_BUF_STATE_QUEUED : VB2_BUF_STATE_DONE);
+			VB2_BUF_STATE_REQUEUEING : VB2_BUF_STATE_DONE);
 }
 
 irqreturn_t cobalt_irq_handler(int irq, void *dev_id)
drivers/media/v4l2-core/videobuf2-core.c +11 -4
index 1a096a6..ca8c041 100644
@@ -1182,7 +1182,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 
 	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
 		    state != VB2_BUF_STATE_ERROR &&
-		    state != VB2_BUF_STATE_QUEUED))
+		    state != VB2_BUF_STATE_QUEUED &&
+		    state != VB2_BUF_STATE_REQUEUEING))
 		state = VB2_BUF_STATE_ERROR;
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1199,15 +1200,21 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 	for (plane = 0; plane < vb->num_planes; ++plane)
 		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
 
-	/* Add the buffer to the done buffers list */
 	spin_lock_irqsave(&q->done_lock, flags);
-	vb->state = state;
-	if (state != VB2_BUF_STATE_QUEUED)
+	if (state == VB2_BUF_STATE_QUEUED ||
+	    state == VB2_BUF_STATE_REQUEUEING) {
+		vb->state = VB2_BUF_STATE_QUEUED;
+	} else {
+		/* Add the buffer to the done buffers list */
 		list_add_tail(&vb->done_entry, &q->done_list);
+		vb->state = state;
+	}
 	atomic_dec(&q->owned_by_drv_count);
 	spin_unlock_irqrestore(&q->done_lock, flags);
 
 	if (state == VB2_BUF_STATE_QUEUED) {
+		return;
+	} else if (state == VB2_BUF_STATE_REQUEUEING) {
 		if (q->start_streaming_called)
 			__enqueue_in_driver(vb);
 		return;
include/media/videobuf2-core.h +2 -0
index 22a44c2..c192e1b 100644
@@ -139,6 +139,7 @@ enum vb2_io_modes {
  * @VB2_BUF_STATE_PREPARING:	buffer is being prepared in videobuf
  * @VB2_BUF_STATE_PREPARED:	buffer prepared in videobuf and by the driver
  * @VB2_BUF_STATE_QUEUED:	buffer queued in videobuf, but not in driver
+ * @VB2_BUF_STATE_REQUEUEING:	re-queue a buffer to the driver
  * @VB2_BUF_STATE_ACTIVE:	buffer queued in driver and possibly used
  *				in a hardware operation
  * @VB2_BUF_STATE_DONE:		buffer returned from driver to videobuf, but
@@ -152,6 +153,7 @@ enum vb2_buffer_state {
 	VB2_BUF_STATE_PREPARING,
 	VB2_BUF_STATE_PREPARED,
 	VB2_BUF_STATE_QUEUED,
+	VB2_BUF_STATE_REQUEUEING,
 	VB2_BUF_STATE_ACTIVE,
 	VB2_BUF_STATE_DONE,
 	VB2_BUF_STATE_ERROR,
Signature · 1 line
2.1.4
#1 lore raw
Quoted 7 lines · Sakari Ailus

Buffers can be returned back to videobuf2 in driver's streamon handler. In this case vb2_buffer_done() with buffer state VB2_BUF_STATE_QUEUED will cause the driver's buf_queue vb2 operation to be called, queueing the same buffer again only to be returned to videobuf2 using vb2_buffer_done() and so on.

Add a new buffer state VB2_BUF_STATE_REQUEUEING which, when used as the

It's spelled as requeuing (no e). The verb is 'to queue', but the -ing form is queuing. Check the dictionary: http://dictionary.reference.com/browse/queuing

Quoted 59 lines

state argument to vb2_buffer_done(), will result in buffers queued to the driver. Using VB2_BUF_STATE_QUEUED will leave the buffer to videobuf2, as it was before "[media] vb2: allow requeuing buffers while streaming".

Fixes ce0eff016f72 ("[media] vb2: allow requeuing buffers while streaming")
Cc [email protected] # for v4.1

---
since v1:

- Instead of relying on q->start_streaming_called and q->streaming, add a new buffer state VB2_BUF_STATE_REQUEUEING, as suggested by Hans. The cobalt driver will need the new flag as it returns the buffer back to the driver's queue, the rest will continue using VB2_BUF_STATE_QUEUED.

 drivers/media/pci/cobalt/cobalt-irq.c    |  2 +-
 drivers/media/v4l2-core/videobuf2-core.c | 15 +++++++++++----
 include/media/videobuf2-core.h           |  2 ++
 3 files changed, 14 insertions(+), 5 deletions(-)
drivers/media/pci/cobalt/cobalt-irq.c +1 -1
index e18f49e..2687cb0 100644
@@ -134,7 +134,7 @@ done:
 	   also know about dropped frames. */
 	cb->vb.v4l2_buf.sequence = s->sequence++;
 	vb2_buffer_done(&cb->vb, (skip || s->unstable_frame) ?
-			VB2_BUF_STATE_QUEUED : VB2_BUF_STATE_DONE);
+			VB2_BUF_STATE_REQUEUEING : VB2_BUF_STATE_DONE);
 }
 
 irqreturn_t cobalt_irq_handler(int irq, void *dev_id)
drivers/media/v4l2-core/videobuf2-core.c +6 -4
index 1a096a6..ca8c041 100644
@@ -1182,7 +1182,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 
 	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
 		    state != VB2_BUF_STATE_ERROR &&
-		    state != VB2_BUF_STATE_QUEUED))
+		    state != VB2_BUF_STATE_QUEUED &&
+		    state != VB2_BUF_STATE_REQUEUEING))
 		state = VB2_BUF_STATE_ERROR;
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1199,15 +1200,21 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 	for (plane = 0; plane < vb->num_planes; ++plane)
 		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
 
-	/* Add the buffer to the done buffers list */
 	spin_lock_irqsave(&q->done_lock, flags);
-	vb->state = state;
-	if (state != VB2_BUF_STATE_QUEUED)
+	if (state == VB2_BUF_STATE_QUEUED ||
+	    state == VB2_BUF_STATE_REQUEUEING) {
+		vb->state = VB2_BUF_STATE_QUEUED;
+	} else {

drivers/media/v4l2-core/videobuf2-core.c void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) · line 1217

Quoted 10 lines
drivers/media/v4l2-core/videobuf2-core.c +5 -0
+		/* Add the buffer to the done buffers list */
 		list_add_tail(&vb->done_entry, &q->done_list);
+		vb->state = state;
+	}
 	atomic_dec(&q->owned_by_drv_count);
 	spin_unlock_irqrestore(&q->done_lock, flags);
 
 	if (state == VB2_BUF_STATE_QUEUED) {
+		return;
+	} else if (state == VB2_BUF_STATE_REQUEUEING) {

No 'else' is needed here since the 'if' just returns.

Regards,

Hans

Quoted 24 lines
drivers/media/v4l2-core/videobuf2-core.c +0 -0
 		if (q->start_streaming_called)
 			__enqueue_in_driver(vb);
 		return;
include/media/videobuf2-core.h +2 -0
index 22a44c2..c192e1b 100644
@@ -139,6 +139,7 @@ enum vb2_io_modes {
  * @VB2_BUF_STATE_PREPARING:	buffer is being prepared in videobuf
  * @VB2_BUF_STATE_PREPARED:	buffer prepared in videobuf and by the driver
  * @VB2_BUF_STATE_QUEUED:	buffer queued in videobuf, but not in driver
+ * @VB2_BUF_STATE_REQUEUEING:	re-queue a buffer to the driver
  * @VB2_BUF_STATE_ACTIVE:	buffer queued in driver and possibly used
  *				in a hardware operation
  * @VB2_BUF_STATE_DONE:		buffer returned from driver to videobuf, but
@@ -152,6 +153,7 @@ enum vb2_buffer_state {
 	VB2_BUF_STATE_PREPARING,
 	VB2_BUF_STATE_PREPARED,
 	VB2_BUF_STATE_QUEUED,
+	VB2_BUF_STATE_REQUEUEING,
 	VB2_BUF_STATE_ACTIVE,
 	VB2_BUF_STATE_DONE,
 	VB2_BUF_STATE_ERROR,
#2 lore raw

Hi Hans,

Quoted 11 lines · Hans Verkuil
Quoted 7 lines · Sakari Ailus

Buffers can be returned back to videobuf2 in driver's streamon handler. In this case vb2_buffer_done() with buffer state VB2_BUF_STATE_QUEUED will cause the driver's buf_queue vb2 operation to be called, queueing the same buffer again only to be returned to videobuf2 using vb2_buffer_done() and so on.

Add a new buffer state VB2_BUF_STATE_REQUEUEING which, when used as the

It's spelled as requeuing (no e). The verb is 'to queue', but the -ing form is queuing. Check the dictionary: http://dictionary.reference.com/browse/queuing

My dictionary disagrees with yours. :-)

http://dictionary.cambridge.org/dictionary/british/queue?q=queueing

Quoted 67 lines
Quoted 67 lines

state argument to vb2_buffer_done(), will result in buffers queued to the driver. Using VB2_BUF_STATE_QUEUED will leave the buffer to videobuf2, as it was before "[media] vb2: allow requeuing buffers while streaming".

Fixes ce0eff016f72 ("[media] vb2: allow requeuing buffers while streaming")
Cc [email protected] # for v4.1

---
since v1:

- Instead of relying on q->start_streaming_called and q->streaming, add a new buffer state VB2_BUF_STATE_REQUEUEING, as suggested by Hans. The cobalt driver will need the new flag as it returns the buffer back to the driver's queue, the rest will continue using VB2_BUF_STATE_QUEUED.

  drivers/media/pci/cobalt/cobalt-irq.c    |  2 +-
  drivers/media/v4l2-core/videobuf2-core.c | 15 +++++++++++----
  include/media/videobuf2-core.h           |  2 ++
  3 files changed, 14 insertions(+), 5 deletions(-)
drivers/media/pci/cobalt/cobalt-irq.c +1 -1
index e18f49e..2687cb0 100644
@@ -134,7 +134,7 @@ done:
  	   also know about dropped frames. */
  	cb->vb.v4l2_buf.sequence = s->sequence++;
  	vb2_buffer_done(&cb->vb, (skip || s->unstable_frame) ?
-			VB2_BUF_STATE_QUEUED : VB2_BUF_STATE_DONE);
+			VB2_BUF_STATE_REQUEUEING : VB2_BUF_STATE_DONE);
  }
 
  irqreturn_t cobalt_irq_handler(int irq, void *dev_id)
drivers/media/v4l2-core/videobuf2-core.c +9 -4
index 1a096a6..ca8c041 100644
@@ -1182,7 +1182,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 
  	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
  		    state != VB2_BUF_STATE_ERROR &&
-		    state != VB2_BUF_STATE_QUEUED))
+		    state != VB2_BUF_STATE_QUEUED &&
+		    state != VB2_BUF_STATE_REQUEUEING))
  		state = VB2_BUF_STATE_ERROR;
 
  #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1199,15 +1200,21 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
  	for (plane = 0; plane < vb->num_planes; ++plane)
  		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
 
-	/* Add the buffer to the done buffers list */
  	spin_lock_irqsave(&q->done_lock, flags);
-	vb->state = state;
-	if (state != VB2_BUF_STATE_QUEUED)
+	if (state == VB2_BUF_STATE_QUEUED ||
+	    state == VB2_BUF_STATE_REQUEUEING) {
+		vb->state = VB2_BUF_STATE_QUEUED;
+	} else {
+		/* Add the buffer to the done buffers list */
  		list_add_tail(&vb->done_entry, &q->done_list);
+		vb->state = state;
+	}
  	atomic_dec(&q->owned_by_drv_count);
  	spin_unlock_irqrestore(&q->done_lock, flags);
 
Quoted 5 lines

drivers/media/v4l2-core/videobuf2-core.c void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) · line 1217

Quoted 3 lines
drivers/media/v4l2-core/videobuf2-core.c +2 -0
  	if (state == VB2_BUF_STATE_QUEUED) {
+		return;
+	} else if (state == VB2_BUF_STATE_REQUEUEING) {

No 'else' is needed here since the 'if' just returns.

Will fix.

Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
#3 lore raw
Quoted 10 lines · Sakari Ailus

Hi Hans,

Quoted 7 lines · Hans Verkuil
Quoted 6 lines · Sakari Ailus

Buffers can be returned back to videobuf2 in driver's streamon handler. In this case vb2_buffer_done() with buffer state VB2_BUF_STATE_QUEUED will cause the driver's buf_queue vb2 operation to be called, queueing the same buffer again only to be returned to videobuf2 using vb2_buffer_done() and so on.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Add a new buffer state VB2_BUF_STATE_REQUEUEING which, when used as the

It's spelled as requeuing (no e). The verb is 'to queue', but the -ing form is queuing. Check the dictionary: http://dictionary.reference.com/browse/queuing

My dictionary disagrees with yours. :-)

http://dictionary.cambridge.org/dictionary/british/queue?q=queueing

$ git grep -i queueing|wc
    655    5660   54709
$ git grep -i queuing|wc
    650    5623   55249

That's not helpful either...

On the other hand:

$ git grep -i queuing drivers/media/|wc
     19     200    1846
$ git grep -i queueing drivers/media/|wc
      2      25     203

Within drivers/media there seems to be a clear preference for queuing :-)

But yes, both spellings are OK, but for me queueing has way too many vowels! And interestingly, my spellchecker thinks queueing is wrong.

Quoted 68 lines
Quoted 68 lines
Quoted 68 lines

state argument to vb2_buffer_done(), will result in buffers queued to the driver. Using VB2_BUF_STATE_QUEUED will leave the buffer to videobuf2, as it was before "[media] vb2: allow requeuing buffers while streaming".

Fixes ce0eff016f72 ("[media] vb2: allow requeuing buffers while streaming")
Cc [email protected] # for v4.1

---
since v1:

- Instead of relying on q->start_streaming_called and q->streaming, add a new buffer state VB2_BUF_STATE_REQUEUEING, as suggested by Hans. The cobalt driver will need the new flag as it returns the buffer back to the driver's queue, the rest will continue using VB2_BUF_STATE_QUEUED.

  drivers/media/pci/cobalt/cobalt-irq.c    |  2 +-
  drivers/media/v4l2-core/videobuf2-core.c | 15 +++++++++++----
  include/media/videobuf2-core.h           |  2 ++
  3 files changed, 14 insertions(+), 5 deletions(-)
drivers/media/pci/cobalt/cobalt-irq.c +1 -1
index e18f49e..2687cb0 100644
@@ -134,7 +134,7 @@ done:
  	   also know about dropped frames. */
  	cb->vb.v4l2_buf.sequence = s->sequence++;
  	vb2_buffer_done(&cb->vb, (skip || s->unstable_frame) ?
-			VB2_BUF_STATE_QUEUED : VB2_BUF_STATE_DONE);
+			VB2_BUF_STATE_REQUEUEING : VB2_BUF_STATE_DONE);
  }
 
  irqreturn_t cobalt_irq_handler(int irq, void *dev_id)
drivers/media/v4l2-core/videobuf2-core.c +9 -4
index 1a096a6..ca8c041 100644
@@ -1182,7 +1182,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 
  	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
  		    state != VB2_BUF_STATE_ERROR &&
-		    state != VB2_BUF_STATE_QUEUED))
+		    state != VB2_BUF_STATE_QUEUED &&
+		    state != VB2_BUF_STATE_REQUEUEING))
  		state = VB2_BUF_STATE_ERROR;
 
  #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1199,15 +1200,21 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
  	for (plane = 0; plane < vb->num_planes; ++plane)
  		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
 
-	/* Add the buffer to the done buffers list */
  	spin_lock_irqsave(&q->done_lock, flags);
-	vb->state = state;
-	if (state != VB2_BUF_STATE_QUEUED)
+	if (state == VB2_BUF_STATE_QUEUED ||
+	    state == VB2_BUF_STATE_REQUEUEING) {
+		vb->state = VB2_BUF_STATE_QUEUED;
+	} else {
+		/* Add the buffer to the done buffers list */
  		list_add_tail(&vb->done_entry, &q->done_list);
+		vb->state = state;
+	}
  	atomic_dec(&q->owned_by_drv_count);
  	spin_unlock_irqrestore(&q->done_lock, flags);
 
Quoted 8 lines
Quoted 5 lines

drivers/media/v4l2-core/videobuf2-core.c void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) · line 1217

Quoted 3 lines
drivers/media/v4l2-core/videobuf2-core.c +2 -0
  	if (state == VB2_BUF_STATE_QUEUED) {
+		return;
+	} else if (state == VB2_BUF_STATE_REQUEUEING) {

No 'else' is needed here since the 'if' just returns.

Will fix.

Regards,

Hans

#4 lore raw

Hi Hans,

Quoted 27 lines · Hans Verkuil
Quoted 10 lines · Sakari Ailus

Hi Hans,

Quoted 7 lines · Hans Verkuil
Quoted 6 lines · Sakari Ailus

Buffers can be returned back to videobuf2 in driver's streamon handler. In this case vb2_buffer_done() with buffer state VB2_BUF_STATE_QUEUED will cause the driver's buf_queue vb2 operation to be called, queueing the same buffer again only to be returned to videobuf2 using vb2_buffer_done() and so on.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Add a new buffer state VB2_BUF_STATE_REQUEUEING which, when used as the

It's spelled as requeuing (no e). The verb is 'to queue', but the -ing form is queuing. Check the dictionary: http://dictionary.reference.com/browse/queuing

My dictionary disagrees with yours. :-)

http://dictionary.cambridge.org/dictionary/british/queue?q=queueing

$ git grep -i queueing|wc
     655    5660   54709
$ git grep -i queuing|wc
     650    5623   55249

That's not helpful either...

Quoted 8 lines

On the other hand:

$ git grep -i queuing drivers/media/|wc
      19     200    1846
$ git grep -i queueing drivers/media/|wc
       2      25     203

Within drivers/media there seems to be a clear preference for queuing :-)

The rest of the kernel apparently prefers "queueing" with a slight margin, if you don't consider V4L2. And who do you think might have added those lines containing "queuing" in V4L2? :-D

The matter was discussed long time ago and my understanding was in case of multiple possible spellings both should be allowed.

I'll post v3, replacing the if's at the end by a single switch. I think it's cleaner that way.

Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]