From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Hans Verkuil <hans.verkuil@cisco.com>,
Tomasz Figa <tfiga@chromium.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Kyungmin Park <kyungmin.park@samsung.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Sakari Ailus <sakari.ailus@iki.fi>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Pawel Osciak <posciak@chromium.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCHv2 02/12] videobuf2: handle V4L2 buffer cache flags
Date: Wed, 5 Feb 2020 17:13:50 +0900 [thread overview]
Message-ID: <20200205081350.GK41358@google.com> (raw)
In-Reply-To: <20200204025641.218376-3-senozhatsky@chromium.org>
On (20/02/04 11:56), Sergey Senozhatsky wrote:
> +static void set_buffer_cache_hints(struct vb2_queue *q,
> + struct vb2_buffer *vb,
> + struct v4l2_buffer *b)
> +{
> + /*
> + * DMA exporter should take care of cache syncs, so we can avoid
> + * explicit ->prepare()/->finish() syncs. For other ->memory types
> + * we always need ->prepare() or/and ->finish() cache sync.
> + */
> + if (q->memory == VB2_MEMORY_DMABUF) {
> + vb->need_cache_sync_on_finish = 0;
> + vb->need_cache_sync_on_prepare = 0;
> + return;
> + }
> +
> + if (!q->allow_cache_hints)
> + return;
> +
> + vb->need_cache_sync_on_prepare = 1;
> + /*
> + * ->finish() cache sync can be avoided when queue direction is
> + * TO_DEVICE.
> + */
> + if (q->dma_dir != DMA_TO_DEVICE)
> + vb->need_cache_sync_on_finish = 1;
> + else
> + vb->need_cache_sync_on_finish = 0;
> +
> + if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE)
> + vb->need_cache_sync_on_finish = 0;
> +
> + if (b->flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN)
> + vb->need_cache_sync_on_prepare = 0;
> +}
Last minute changes (tm), sorry. This is not right.
====8<====8<====
From: Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: [PATCH] videobuf2: handle V4L2 buffer cache flags
Set video buffer cache management flags corresponding to V4L2 cache
flags.
Both ->prepare() and ->finish() cache management hints should be
passed during this stage (buffer preparation), because there is no
other way for user-space to skip ->finish() cache flush.
There are two possible alternative approaches:
- The first one is to move cache sync from ->finish() to dqbuf().
But this breaks some drivers, that need to fix-up buffers before
dequeueing them.
- The second one is to move ->finish() call from ->done() to dqbuf.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
.../media/common/videobuf2/videobuf2-v4l2.c | 36 +++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index eb5d5db96552..8ef57496b34a 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -337,6 +337,41 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b
return 0;
}
+static void set_buffer_cache_hints(struct vb2_queue *q,
+ struct vb2_buffer *vb,
+ struct v4l2_buffer *b)
+{
+ /*
+ * DMA exporter should take care of cache syncs, so we can avoid
+ * explicit ->prepare()/->finish() syncs. For other ->memory types
+ * we always need ->prepare() or/and ->finish() cache sync.
+ */
+ if (q->memory == VB2_MEMORY_DMABUF) {
+ vb->need_cache_sync_on_finish = 0;
+ vb->need_cache_sync_on_prepare = 0;
+ return;
+ }
+
+ vb->need_cache_sync_on_prepare = 1;
+ vb->need_cache_sync_on_finish = 1;
+
+ if (!q->allow_cache_hints)
+ return;
+
+ /*
+ * ->finish() cache sync can be avoided when queue direction is
+ * TO_DEVICE.
+ */
+ if (q->dma_dir == DMA_TO_DEVICE)
+ vb->need_cache_sync_on_finish = 0;
+
+ if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE)
+ vb->need_cache_sync_on_finish = 0;
+
+ if (b->flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN)
+ vb->need_cache_sync_on_prepare = 0;
+}
+
static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *mdev,
struct v4l2_buffer *b, bool is_prepare,
struct media_request **p_req)
@@ -381,6 +416,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md
}
if (!vb->prepared) {
+ set_buffer_cache_hints(q, vb, b);
/* Copy relevant information provided by the userspace */
memset(vbuf->planes, 0,
sizeof(vbuf->planes[0]) * vb->num_planes);
--
2.25.0.341.g760bfbb309-goog
next prev parent reply other threads:[~2020-02-05 8:13 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-04 2:56 [RFC][PATCHv2 00/12] Implement V4L2_BUF_FLAG_NO_CACHE_* flags Sergey Senozhatsky
2020-02-04 2:56 ` [RFC][PATCHv2 01/12] videobuf2: add cache management members Sergey Senozhatsky
2020-02-19 8:05 ` Hans Verkuil
2020-02-19 8:16 ` Sergey Senozhatsky
2020-02-19 8:27 ` Hans Verkuil
2020-02-04 2:56 ` [RFC][PATCHv2 02/12] videobuf2: handle V4L2 buffer cache flags Sergey Senozhatsky
2020-02-05 8:13 ` Sergey Senozhatsky [this message]
2020-02-19 8:07 ` Hans Verkuil
2020-02-19 8:13 ` Sergey Senozhatsky
2020-02-19 8:25 ` Hans Verkuil
2020-02-19 8:46 ` Hans Verkuil
2020-02-04 2:56 ` [RFC][PATCHv2 03/12] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Sergey Senozhatsky
2020-02-13 7:08 ` Tomasz Figa
2020-02-19 8:19 ` Hans Verkuil
2020-02-19 8:56 ` Hans Verkuil
2020-02-25 7:45 ` Sergey Senozhatsky
2020-02-04 2:56 ` [RFC][PATCHv2 04/12] videobuf2: add queue memory consistency parameter Sergey Senozhatsky
2020-02-04 2:56 ` [RFC][PATCHv2 05/12] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT flag Sergey Senozhatsky
2020-02-19 8:25 ` Hans Verkuil
2020-02-19 8:59 ` Sergey Senozhatsky
2020-02-19 9:04 ` Hans Verkuil
2020-02-19 8:48 ` Hans Verkuil
2020-02-19 9:05 ` Sergey Senozhatsky
2020-02-19 9:11 ` Hans Verkuil
2020-02-04 2:56 ` [RFC][PATCHv2 06/12] videobuf2: factor out planes prepare/finish functions Sergey Senozhatsky
2020-02-04 2:56 ` [RFC][PATCHv2 07/12] videobuf2: do not sync caches when we are allowed not to Sergey Senozhatsky
2020-02-04 2:56 ` [RFC][PATCHv2 08/12] videobuf2: check ->synced flag in prepare() and finish() Sergey Senozhatsky
2020-02-04 2:56 ` [RFC][PATCHv2 09/12] videobuf2: let user-space know if driver supports cache hints Sergey Senozhatsky
2020-02-19 8:33 ` Hans Verkuil
2020-02-19 8:45 ` Sergey Senozhatsky
2020-02-19 8:56 ` Hans Verkuil
2020-02-04 2:56 ` [RFC][PATCHv2 10/12] videobuf2: add begin/end cpu_access callbacks to dma-contig Sergey Senozhatsky
2020-02-04 2:56 ` [RFC][PATCHv2 11/12] videobuf2: add begin/end cpu_access callbacks to dma-sg Sergey Senozhatsky
2020-02-19 8:35 ` Hans Verkuil
2020-02-19 8:42 ` Sergey Senozhatsky
2020-02-04 2:56 ` [RFC][PATCHv2 12/12] videobuf2: don't test db_attach in dma-contig prepare and finish Sergey Senozhatsky
2020-02-19 8:53 ` [RFC][PATCHv2 00/12] Implement V4L2_BUF_FLAG_NO_CACHE_* flags Hans Verkuil
2020-02-26 11:20 ` Sergey Senozhatsky
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=20200205081350.GK41358@google.com \
--to=senozhatsky@chromium.org \
--cc=hans.verkuil@cisco.com \
--cc=kyungmin.park@samsung.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=posciak@chromium.org \
--cc=sakari.ailus@iki.fi \
--cc=tfiga@chromium.org \
/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;
as well as URLs for NNTP newsgroup(s).