diff mbox series

[PATCHv2] media: vb2: set buffer cache sync hints during initialisation

Message ID 20201127164353.1207871-1-sergey.senozhatsky@gmail.com (mailing list archive)
State New, archived
Headers show
Series [PATCHv2] media: vb2: set buffer cache sync hints during initialisation | expand

Commit Message

Sergey Senozhatsky Nov. 27, 2020, 4:43 p.m. UTC
We need to set ->need_cache_sync_on_prepare and
->need_cache_sync_on_finish when we initialize vb2 buffer.

Currently these flags are set/adjusted only in V4L2's
vb2_queue_or_prepare_buf(), which means that for the code
paths that don't use V4L2 vb2 will always tell videobuf2
core to skip ->prepare() and ->finish() cache syncs/flushes.

This is a quick solution that should do the trick. The
proper fix, however, is much more complicated and requires
a rather big videobuf2 refactoring - we need to move cache
sync/flush decision making out of core videobuf2 to the
allocators.

Fixes: f5f5fa73fbfb ("media: videobuf2: handle V4L2 buffer cache flags")
Reported-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---

v2: add a comment and set cache sync flags only for specific buffers (Hans)

 drivers/media/common/videobuf2/videobuf2-core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 5499013cf82e..da777c3c5d69 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -414,6 +414,18 @@  static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory,
 		vb->index = q->num_buffers + buffer;
 		vb->type = q->type;
 		vb->memory = memory;
+		/*
+		 * A workaround fix. We need to set these flags here so that
+		 * videobuf2 core will call ->prepare()/->finish() cache
+		 * sync/flush on vb2 buffers when appropriate. Otherwise, for
+		 * backends that don't rely on V4L2 (perhaps dvb) these flags
+		 * will always be false and, hence, videobuf2 core will skip
+		 * cache sync/flush operations.
+		 */
+		if (!q->allow_cache_hints && q->memory != VB2_MEMORY_DMABUF) {
+			vb->need_cache_sync_on_prepare = 1;
+			vb->need_cache_sync_on_finish = 1;
+		}
 		for (plane = 0; plane < num_planes; ++plane) {
 			vb->planes[plane].length = plane_sizes[plane];
 			vb->planes[plane].min_length = plane_sizes[plane];