Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp21386ybv; Wed, 5 Feb 2020 00:15:30 -0800 (PST) X-Google-Smtp-Source: APXvYqzzRDXFV/kCL4mAV/h6XUjMYfkYsayd4cEsykcOAPZGpF+zq1lMjwux22ikupKIqdyxOV01 X-Received: by 2002:a9d:1928:: with SMTP id j40mr25692642ota.68.1580890529879; Wed, 05 Feb 2020 00:15:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580890529; cv=none; d=google.com; s=arc-20160816; b=VXrno73nbSCQFCLIfcdpOUXkMBMfnlaUd6k8ly1Gx11dQCwOXTF/g2adLLj1QoGP/P g5DEv0L1YHWA3FoTxV1us2cigb1KCCbsAdzkShxVc0Ky9f23Q6GaW9jzSJ48KqOvqIra LmWYpKfdZTNXpgpZtN3ePkhEvGTWNkzwx/HC9jAkXnQBpoCQ2gEXtpXbdiw4+JiTH6kq ALGT4sqoQ7kqZzzvJS9NCtDr1q1MfsyVhfxpvvcRdor4mf/G/gk933rPBOO+IxFZVcec JIAwjBXscQLlMDPODsdHmgTmeAXGo/At7D9t/+QOMNKfOHaR1S/AS64TD7Qgi1B3/CYF WKGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=9Kv2PfNZ/Q0TVvrr7RyiEmUt8JdC7LWiVIGz2BsjNHQ=; b=CtlxWQSi+FgZUG5I6EYenDrHKBlVo4MPdFfAnTW98b5iI2mApfY4xOXBgFFnbr4vzS WfdSMB3WJwJQBzgZLhbsFuqWu0BcknqUBNGQx6EYhEmwPRRLbq07f19qBTuBOixrxcKU 7gPmPwcIlZM8jV9tjgTVzIaGNXp2By+L3luhoJv092YKZEOMDh+IbmTlqoWRWbau66ph ukQSnQv1//B+eHm9UNCZ7NmhsRCmFnMJ34w8lC2uv2sMgFlD9xuRE5lGHiGQPauiuwzb kFqfftln9hLfYT4vRKcqoB7IZMQYSbzFp11lslOk1Vp9ngLONAo8XPgPKx9SlrxUoJc5 MC+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="B/+U52J+"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q26si12005567oij.38.2020.02.05.00.15.15; Wed, 05 Feb 2020 00:15:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="B/+U52J+"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728012AbgBEIN4 (ORCPT + 99 others); Wed, 5 Feb 2020 03:13:56 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43457 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727068AbgBEIN4 (ORCPT ); Wed, 5 Feb 2020 03:13:56 -0500 Received: by mail-pg1-f195.google.com with SMTP id u131so571220pgc.10 for ; Wed, 05 Feb 2020 00:13:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=9Kv2PfNZ/Q0TVvrr7RyiEmUt8JdC7LWiVIGz2BsjNHQ=; b=B/+U52J+m+NF1gTrJMaYYLbomtsbHRdQwfD9R2WT9UzF9JAwj8hL7iTffUJBnZw583 nVEEhcTy/e7i+hr5oXqyl6TRCAnn1ks7LTIfnqPngvbvi/cv+dyJY2gf236C8iHzPF0P ZomPzoRAZ86kr3ZsKjUpMM+sUJPM7TCvVqs04= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=9Kv2PfNZ/Q0TVvrr7RyiEmUt8JdC7LWiVIGz2BsjNHQ=; b=G5nXtNUHjvNl0Lw5SJjUexZp+oxVY+47FhV+7rRcJ0KlTY9uzjpx6S/NVwyk8ZY12e J7/aWKiwa0K5p1U0Tf0c/EPIzD55hS/JVlHw0sJ7l29Vv/XLGtupp57w6mBVPhRuLHlW hlP2mfWHMx8JCHZtlf0RffXHBMnw7kWpZGRfbIAweUGz3nl0PI/762a9uodPsq6jozxY qC2RwXHABZrSnVY0pR/H+q7fRAKmOUvTFcBimM3yUJrjl35TztOSP3y0nd20J4vB72JV E9RVut+Zb0KoCWYY2wRVE1FxIVV3iKqLxhneGrcTw6VWyAajw9/t2gn03X6/DgXdTulC sJJw== X-Gm-Message-State: APjAAAV2RyMr+ysqblXc2dZVwRep+/yMTM5K0dhhkcL/XkGGTOUL6UwB h2UOg910YrZBK0K6uWwEZbjERw== X-Received: by 2002:a63:36c2:: with SMTP id d185mr15733815pga.59.1580890433605; Wed, 05 Feb 2020 00:13:53 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id az9sm6415208pjb.3.2020.02.05.00.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 00:13:52 -0800 (PST) Date: Wed, 5 Feb 2020 17:13:50 +0900 From: Sergey Senozhatsky To: Sergey Senozhatsky Cc: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCHv2 02/12] videobuf2: handle V4L2 buffer cache flags Message-ID: <20200205081350.GK41358@google.com> References: <20200204025641.218376-1-senozhatsky@chromium.org> <20200204025641.218376-3-senozhatsky@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200204025641.218376-3-senozhatsky@chromium.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 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 --- .../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