Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp326196ybv; Wed, 19 Feb 2020 00:08:58 -0800 (PST) X-Google-Smtp-Source: APXvYqxMLgarJa382W7r8141N0diVGY/xZsgQOWvy8cvgKY7okpB+GTkUjH7+c1/u8ugeu5kbMxv X-Received: by 2002:aca:e106:: with SMTP id y6mr3932280oig.131.1582099738236; Wed, 19 Feb 2020 00:08:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582099738; cv=none; d=google.com; s=arc-20160816; b=peyqKZyc6TNS0qzPMzC17NqCGHfPrxgQ7qJYGgtr96gtw2o+gspPplxK4HTPEthG4q zsecQ3CC6a1SknyqBPU5XN2ALlMOx6CtFKJLJ26zVFUd5Y8SxuAOIcTwDc8qSsVdqKGt dZAm27Q6vxAJwhWQ76u1NXCEUwpW/nBHkicB3FvCLRqgZy7E4tAejNahuI6dKxOxhIPN nCIKJrEj2IKNnr8e1K+lbPvoZMM0dSHs49ubJfDETeFuRlnzGL+uiZDes/0eVF0edcg8 5Syv8BAPA8LtXXuHmxTOjqHEXwEtwdq3S4azZh+a5Bg9bC2bNRm0GZJLFoR5snJ7ObVW B3mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=4JszDvEP0ShkvbT7hmQQt4q+fEGdViCdhbC3vRlO4Zc=; b=NeFHZrQU/dwIf98bepTR9fpKxQh3j7x3RM4HWGo8eE3LBweylba+dIdjFmTqC25/CF hV71N3nFkoD/Yvl6Gfc6tQ7o2V6mUNM95XvlnYXmhOr5NSHxyCYen7aR1guO+KJgc0zD NRGjABDT1H5yn/bTdz/CHuAs5Ea0oEQTtSS1engt/xOd29ciIj5aFrPjJwpK1LuRBoG/ Wja4x9a2o4zTgen/uPeH9EemmkdGN/kpRmMMGAj9z1n7YWXv4gyO+p/5x7YyDF9eIYAL UHTO+8o/BF5TBsJwwAvbQZlt4ZeJjXDFmV8FIYpQEjgrj85DHB6EkcGfjy7ZP1GhRuxo 3WNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xs4all.nl header.s=s1 header.b=J38HY+0W; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si9337976oic.205.2020.02.19.00.08.46; Wed, 19 Feb 2020 00:08:58 -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=@xs4all.nl header.s=s1 header.b=J38HY+0W; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727283AbgBSIHS (ORCPT + 99 others); Wed, 19 Feb 2020 03:07:18 -0500 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:52911 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726645AbgBSIHR (ORCPT ); Wed, 19 Feb 2020 03:07:17 -0500 Received: from [192.168.2.10] ([46.9.235.248]) by smtp-cloud7.xs4all.net with ESMTPA id 4KO0jz8rdP9a94KO3jnHDi; Wed, 19 Feb 2020 09:07:16 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s1; t=1582099636; bh=4JszDvEP0ShkvbT7hmQQt4q+fEGdViCdhbC3vRlO4Zc=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type:From: Subject; b=J38HY+0WBneQ44VTT0ydJAh7tKoDCurI75R2Yed5X3wSgFtGJ7LOIEtbFgZ0tn3b0 Lqc3oWtItD82z1/UKatuw2brs5iUpjoZbyHfKn86OfVdKNYKkfsP7TpX+AMpB2maJ3 kz4grIBnOwVLKhXUcqeKfLJlmqhxEeOAhPNFk4xbekOB5vR/3EvNMUEHyrJ2Htstw2 RQ7Z46RMEzuAXX5H3d7o7KT9S498GjqF9ELEut+LU/iUpfD2Z/Vd6fO2TMWk1tPvxg pF1Pwm+h/96DlRZj5ar5ZOHHam1HgyOrjNVbcwwPyuvxE2ZWPHZjj0ZB/R4lyRDOxQ dv+vYxHShNnuA== Subject: Re: [RFC][PATCHv2 02/12] videobuf2: handle V4L2 buffer cache flags To: Sergey Senozhatsky , Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200204025641.218376-1-senozhatsky@chromium.org> <20200204025641.218376-3-senozhatsky@chromium.org> From: Hans Verkuil Message-ID: Date: Wed, 19 Feb 2020 09:07:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200204025641.218376-3-senozhatsky@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfDMh8ro/1Ej3uCr/B88xs9QSf1DQj6Cz3VMN0DFqayPtMFym6D6tk98LH/aCi2Bh25lrowBe6aZX7dTPe86vpCs33hxqiTaRY23yNDv1ipIaD+E93owU PdL6uUcLJA73sbKrM25qdpXV+42++eaA2z/wRCGInSmivia/wXNEW6K75Rtil9FnkP7G3q6eaFbx22n8YNeBhYIEvZATKgYBDZhG5Ng6nKEQ8Z37zKWexEJr XxKM3sMO43CXniSwceC+XIX/7c+JJmpllLk7XbGq+EEKB1cRi9JAI1i3AubHcjEdM8eWFkAylshmrHQvezK67wCh8MPGCurUlQbqXMTf7ITVvDXYdjp9rUi+ gwhe2AT6CYdI3uJU752G7+Xkug/ozKOOgL+U3G9taERMMnRbvsH1Z3VArLq2A76jpjNT6KX60BfCzL4j6RIAjHBf0UQITr5aohD/QosDOkEeG3cNEOx9awcj caSQ3XZAxqikyQefmaOvlmw+NgyKEOWX9RhQPKZ5w4A8Owp5x8XyGdJd1TRxe5fHIGj/A1CBRfj0R71b Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/4/20 3:56 AM, Sergey Senozhatsky wrote: > 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. > > Change-Id: I3bef1d1fb93a5fba290ce760eaeecdc8e7d6885a > 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..2da06a2ad6c4 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; > + } > + > + if (!q->allow_cache_hints) > + return; > + > + vb->need_cache_sync_on_prepare = 1; This needs a comment explaining why prepare is set to 1 by default. I remember we discussed this earlier, and the conclusion of that discussion needs to be documented here in a comment. Regards, Hans > + /* > + * ->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; > +} > + > 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); >