Prepare for cache coherency changes in videobuf2
PATCH 1/3 vb2: Rename confusingly named internal buffer preparation functions
In reply to Sakari AilusRename __qbuf_*() functions which are specific to a buffer type as __prepare_*() which matches with what they do. The naming was there for historical reasons; the purpose of the functions was changed without renaming them.
--- drivers/media/v4l2-core/videobuf2-core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/media/v4l2-core/videobuf2-core.c +9 -9
@@ -956,9 +956,9 @@ void vb2_discard_done(struct vb2_queue *q)EXPORT_SYMBOL_GPL (vb2_discard_done);/** -* __qbuf_mmap() - handle qbuf of an MMAP buffer +* __prepare_mmap() - prepare an MMAP buffer */ -static int __qbuf_mmap (struct vb2_buffer *vb,const void *pb) +static int __prepare_mmap (struct vb2_buffer *vb,const void *pb) {int ret =0 ;
@@ -969,9 +969,9 @@ static int __qbuf_mmap(struct vb2_buffer *vb, const void *pb) }/** -* __qbuf_userptr() - handle qbuf of a USERPTR buffer +* __prepare_userptr() - prepare a USERPTR buffer */ -static int __qbuf_userptr (struct vb2_buffer *vb,const void *pb) +static int __prepare_userptr (struct vb2_buffer *vb,const void *pb) {struct vb2_plane planes[VB2_MAX_PLANES ];struct vb2_queue *q = vb->vb2_queue;
@@ -1087,9 +1087,9 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const void *pb) }/** -* __qbuf_dmabuf() - handle qbuf of a DMABUF buffer +* __prepare_dmabuf() - prepare a DMABUF buffer */ -static int __qbuf_dmabuf (struct vb2_buffer *vb,const void *pb) +static int __prepare_dmabuf (struct vb2_buffer *vb,const void *pb) {struct vb2_plane planes[VB2_MAX_PLANES ];struct vb2_queue *q = vb->vb2_queue;
@@ -1255,13 +1255,13 @@ static int __buf_prepare(struct vb2_buffer *vb, const void *pb)switch (q->memory) {case VB2_MEMORY_MMAP : - ret =__qbuf_mmap (vb, pb); + ret =__prepare_mmap (vb, pb);break ;case VB2_MEMORY_USERPTR : - ret =__qbuf_userptr (vb, pb); + ret =__prepare_userptr (vb, pb);break ;case VB2_MEMORY_DMABUF : - ret =__qbuf_dmabuf (vb, pb); + ret =__prepare_dmabuf (vb, pb);break ;default :WARN (1 ,"Invalid queue type\n" );
Signature · 1 line
2.7.4
cover Prepare for cache coherency changes in videobuf2
Hello everyone,
I split off these three patches from another set ("vb2: Handle user cache hints, allow drivers to choose cache coherency"):
<URL:http://www.spinics.net/lists/linux-media/msg115401.html>
The reason is that the rest of the set requires further work in order to be mergeable. For now, just three patches. The functional change will be moving the cache operations where they should have been all along.
Signature · 2 lines
Kind regards, Sakari
PATCH 2/3 vb2: Move buffer cache synchronisation to prepare from queue
The buffer cache should be synchronised in buffer preparation, not when the buffer is queued to the device. Fix this.
Mmap buffers do not need cache synchronisation since they are always coherent.
--- drivers/media/v4l2-core/videobuf2-core.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/media/v4l2-core/videobuf2-core.c +12 -8
@@ -1227,23 +1227,19 @@ static int __prepare_dmabuf(struct vb2_buffer *vb, const void *pb)static void __enqueue_in_driver (struct vb2_buffer *vb) {struct vb2_queue *q = vb->vb2_queue; -unsigned int plane; vb->state =VB2_BUF_STATE_ACTIVE ;atomic_inc (&q->owned_by_drv_count);trace_vb2_buf_queue (q, vb); -/* sync buffers */ -for (plane =0 ; plane < vb->num_planes; ++plane) -call_void_memop (vb, prepare, vb->planes[plane].mem_priv); -call_void_vb_qop (vb, buf_queue, vb); }static int __buf_prepare (struct vb2_buffer *vb,const void *pb) {struct vb2_queue *q = vb->vb2_queue; +unsigned int plane;int ret;if (q->error) {
@@ -1268,11 +1264,19 @@ static int __buf_prepare(struct vb2_buffer *vb, const void *pb) ret = -EINVAL ; } -if (ret) +if (ret) {dprintk (1 ,"buffer preparation failed: %d\n" , ret); - vb->state = ret ?VB2_BUF_STATE_DEQUEUED :VB2_BUF_STATE_PREPARED ; + vb->state =VB2_BUF_STATE_DEQUEUED ; +return ret; + } -return ret; +/* sync buffers */ +for (plane =0 ; plane < vb->num_planes; ++plane) +call_void_memop (vb, prepare, vb->planes[plane].mem_priv); + + vb->state =VB2_BUF_STATE_PREPARED ; + +return 0 ; }int vb2_core_prepare_buf (struct vb2_queue *q,unsigned int index,void *pb)
Signature · 1 line
2.7.4
PATCH 3/3 vb2: Move cache synchronisation from buffer done to dqbuf handler
In reply to Sakari AilusThe cache synchronisation may be a time consuming operation and thus not best performed in an interrupt which is a typical context for vb2_buffer_done() calls. This may consume up to tens of ms on some machines, depending on the buffer size.
--- drivers/media/v4l2-core/videobuf2-core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/videobuf2-core.c +4 -5
@@ -889,7 +889,6 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) {struct vb2_queue *q = vb->vb2_queue;unsigned long flags; -unsigned int plane;if (WARN_ON (vb->state !=VB2_BUF_STATE_ACTIVE ))return ;
@@ -910,10 +909,6 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)dprintk (4 ,"done processing on buffer %d, state: %d\n" , vb->index, state); -/* sync buffers */ -for (plane =0 ; plane < vb->num_planes; ++plane) -call_void_memop (vb, finish, vb->planes[plane].mem_priv); -spin_lock_irqsave (&q->done_lock, flags);if (state ==VB2_BUF_STATE_QUEUED || state ==VB2_BUF_STATE_REQUEUEING ) {
@@ -1573,6 +1568,10 @@ static void __vb2_dqbuf(struct vb2_buffer *vb) vb->state =VB2_BUF_STATE_DEQUEUED ; +/* sync buffers */ +for (i =0 ; i < vb->num_planes; ++i) +call_void_memop (vb, finish, vb->planes[i].mem_priv); +/* unmap DMABUF buffer */ if (q->memory ==VB2_MEMORY_DMABUF )for (i =0 ; i < vb->num_planes; ++i) {
Signature · 1 line
2.7.4