Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp110001ybl; Mon, 27 Jan 2020 23:21:26 -0800 (PST) X-Google-Smtp-Source: APXvYqx5ap1H2qQy3d3kjdDCPXLVUyEMTMGJK6Zg1iWEfxfFhQOKOhNtFDUJUF45unIJjAKOABiP X-Received: by 2002:aca:ea43:: with SMTP id i64mr2005413oih.30.1580196086790; Mon, 27 Jan 2020 23:21:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580196086; cv=none; d=google.com; s=arc-20160816; b=nSS4RjJCa8Me7sQIzYln2H2m20ptvzmXU7MdtmUYCyjqEgNavK1CRMU5rTGbx4I6Y2 eeMLlZ2eLKks50YublC7aR/WmdSYE6PfuickjX2TRWWWRoPPhNyaUjFmOXllOn6/LldQ slVuUCyhGj3k9ZEgoikYtpKw5AijENwQmG8mdrXxHG32LHqgTUmp694WQ4eZ26Cfb83H AWnVQDDbQ4OViNFWv9X+IlCpJF5iONjhQb9sQpEkznBzBsSii/x+8uOL6mmJSBQPF9Ur IUfpyi2Ylt5K2xEZAXhbsfMVDFX0svjz4QZqRs96nFR2ULPCBAkS6HDvIF5s+A4DSvla iK1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Sb+8J/7DuRGfGudhsScfamBXEMs+Mce/hybB6WnCHb0=; b=h4Rd6dmXp8pBk5+rTOaAIo0eK6fnFn2OnggAHThu8ad0QGL3LFzIL2wxWrc8C0NZQx k1gTOfW4CJ7mG6bGBZnQwyvCY34uCGmyiO4pw++R5kvtkm8zKyu0uFg306d7hxQ4ja7X HPThllEXocLkIM6RtLYVAbfDTEfmcXWptv0Hhz4z8CNeQq4blJiZom4OZyaP6qhmbId2 oNduGIc6YbFjJBL0i7Vbj23jQS0zs78WAzTvUyyvEL7W2BTE34X/a6RFI1BvdH28AYIF LrF0WYbv6iZ1WhyQnfkBWF93peq4Zxxi6Yq6fZGJOgV7daz+LeyxRwoTxIOOwiq5GWBS 5gNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cBBOlTfY; 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 i3si7997132otc.272.2020.01.27.23.21.14; Mon, 27 Jan 2020 23:21:26 -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=cBBOlTfY; 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 S1725912AbgA1HUH (ORCPT + 99 others); Tue, 28 Jan 2020 02:20:07 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:36101 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbgA1HUH (ORCPT ); Tue, 28 Jan 2020 02:20:07 -0500 Received: by mail-ed1-f68.google.com with SMTP id j17so13616866edp.3 for ; Mon, 27 Jan 2020 23:20:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Sb+8J/7DuRGfGudhsScfamBXEMs+Mce/hybB6WnCHb0=; b=cBBOlTfYKE9YToJ7LwFQXUs38A+ojqRBnM0kt+rHMyNahEoDFA6easCZ0aFYOPtke3 92ch4PzsGSCY5aLRhqTT/Efcfd4whgm9Naygy4kaj/kYGeA0+wOB21kgR8n0MWKNEDG5 1uI51gw21EMHkPLWo/gWWMfXNCjXDlc2AC+1s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Sb+8J/7DuRGfGudhsScfamBXEMs+Mce/hybB6WnCHb0=; b=b06Ee+0mojvBns3jSBeKEbVOzPtWHcW7IxsH82PG3yhMbBIzEuFxU3QKvIg7ajhJun QXAWgT27SM4Eyoi5UwQl603aQ9GkGRS050taOlQhOVzrxBzWbSsxvCEdtia46bXwUcEg wQQgM3wHh3yZBFeXKE9yfS1WDfwEnSRKFetLR7rojKRps7x7679JDeMx1Zfoj4wB2aSw tyYzaqs5Rf1z6LxHjsiIEhHTgESvVLjXDrowD/jPt8ED/snN8e1muf6RpOGC9Lu/UCZv PED1RDHYqbns8x+f4F9AcaUevrqKziExghMiAutaowWlxb/CvnbU27fAREQ5qmQcAlUw 86fA== X-Gm-Message-State: APjAAAXeCeixzMUAeYAgE0rPhBCDghbLV4JO6UQmZ9DnhWWkQsK8fxNu oHb5mJ0nCytp6IaB/wfgnahx58RZSR3IAg== X-Received: by 2002:a05:6402:74a:: with SMTP id p10mr1943618edy.377.1580196004421; Mon, 27 Jan 2020 23:20:04 -0800 (PST) Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com. [209.85.128.41]) by smtp.gmail.com with ESMTPSA id qh18sm339052ejb.23.2020.01.27.23.20.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jan 2020 23:20:02 -0800 (PST) Received: by mail-wm1-f41.google.com with SMTP id t14so1282224wmi.5 for ; Mon, 27 Jan 2020 23:20:01 -0800 (PST) X-Received: by 2002:a05:600c:294a:: with SMTP id n10mr3195790wmd.11.1580196001394; Mon, 27 Jan 2020 23:20:01 -0800 (PST) MIME-Version: 1.0 References: <20191217032034.54897-1-senozhatsky@chromium.org> <20191217032034.54897-14-senozhatsky@chromium.org> <2d0e1a9b-6c5e-ff70-9862-32c8b8aaf65f@xs4all.nl> <20200122050515.GB49953@google.com> <57f711a0-6183-74f6-ab24-ebe414cb6881@xs4all.nl> In-Reply-To: <57f711a0-6183-74f6-ab24-ebe414cb6881@xs4all.nl> From: Tomasz Figa Date: Tue, 28 Jan 2020 16:19:50 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC][PATCH 13/15] videobuf2: do not sync buffers for DMABUF queues To: Hans Verkuil Cc: Sergey Senozhatsky , Hans Verkuil , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , Linux Media Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 23, 2020 at 8:35 PM Hans Verkuil wrote: > > On 1/22/20 6:05 AM, Sergey Senozhatsky wrote: > > On (20/01/10 11:30), Hans Verkuil wrote: > > [..] > >>> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c > >>> index 1762849288ae..2b9d3318e6fb 100644 > >>> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c > >>> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c > >>> @@ -341,8 +341,22 @@ static void set_buffer_cache_hints(struct vb2_queue *q, > >>> struct vb2_buffer *vb, > >>> struct v4l2_buffer *b) > >>> { > >>> - vb->need_cache_sync_on_prepare = 1; > >>> + /* > >>> + * DMA exporter should take care of cache syncs, so we can avoid > >>> + * explicit ->prepare()/->finish() syncs. > >>> + */ > >>> + if (q->memory == VB2_MEMORY_DMABUF) { > >>> + vb->need_cache_sync_on_finish = 0; > >>> + vb->need_cache_sync_on_prepare = 0; > >>> + return; > >>> + } > >>> > >>> + /* > >>> + * For other ->memory types we always need ->prepare() cache > >>> + * sync. ->finish() cache sync, however, can be avoided when queue > >>> + * direction is TO_DEVICE. > >>> + */ > >>> + vb->need_cache_sync_on_prepare = 1; > >> > >> I'm trying to remember: what needs to be done in prepare() > >> for a capture buffer? I thought that for capture you only > >> needed to invalidate the cache in finish(), but nothing needs > >> to be done in the prepare(). > > > > Hmm. Not sure. A precaution in case if user-space wrote to that buffer? > > But whatever was written in the buffer is going to be overwritten anyway. > > Unless I am mistaken the current situation is that the cache syncs are done > in both prepare and finish, regardless of the DMA direction. > > I would keep that behavior to avoid introducing any unexpected regressions. > It wouldn't be surprising if the buffer was first filled with default values (e.g. all zeroes) on the CPU. That would make the cache lines dirty and they could overwrite what the device writes. So we need to flush (aka clean) the write-back caches on prepare for CAPTURE buffers. > Then, if q->allow_cache_hint is set, then default to a cache sync (cache clean) > in the prepare for OUTPUT buffers and a cache sync (cache invalidate) in the > finish for CAPTURE buffers. I'd still default to the existing behavior even if allow_cache_hint is set, because of what I wrote above. Then if the userspace doesn't ever write to the buffers, it can request no flush/clean by setting the V4L2_BUF_FLAG_NO_CACHE_CLEAN flag when queuing the buffer. > > This also means that any drivers that want to access a buffer in between the > prepare...finish calls will need to do a begin/end_cpu_access. But that's a > separate matter. AFAIR with current design of the series, the drivers can opt-in for userspace cache sync hints, so by default even if the userspace requests sync to be skipped, it wouldn't have any effect unless the driver allows so. Then I'd imagine migrating all the drivers to request clean/invalidate explicitly. Note that the DMA-buf begin/end_cpu_access isn't enough here. We'd need something like vb2_begin/end_cpu_access() which also takes care of syncing inconsistent MMAP and USERPTR buffers. > > Regards, > > Hans > > > > > + if (q->dma_dir == DMA_FROM_DEVICE) > > + q->need_cache_sync_on_prepare = 0; > > > > ? > > > > -ss > > >