Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2092925imm; Thu, 9 Aug 2018 07:13:56 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyNhfvdtZwAI3/+CMeMxhXpXQm5h97Nkd2QimmldfiZbdG2q7VgjbUgmz2+DwwrjwKWLv7T X-Received: by 2002:a62:1f8c:: with SMTP id l12-v6mr2616592pfj.143.1533824036642; Thu, 09 Aug 2018 07:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533824036; cv=none; d=google.com; s=arc-20160816; b=Q+jgUtBKX5gnpRtITbM25QDmJK8b9z8LubEnW8DlYZN1GT2hLTzFDi7KNsCiB/+jFd EF42Y5dOcMUK7dGQwOrZqeY8c2NFlqdRnOxrsrbKyBCXng9HWitiadNHwo3r2+QWiADU A275Shs5y7zcKwMOBvbvr4x2kHFkKYXwaK7qOHPKtMpLEO+vKNo5JYxm3k167S7h6XVs kAs7cVlwW+skhYM+5S+AUjkY2+ixYWKMbjjATi7K+ICF1t5R7OukCNMNNkRDbDsNBhXD 8q+N46O3ST29U5a+vlCvPHLJIZoHcWD2yO1qNzaSiL0pKCrBP2jqPCXMZQpe06iA2ydk kXQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date:arc-authentication-results; bh=ER7Pm8WKyQRjhEv/enUmRhMxuSJ8DeyaHzdKQpPkb6Y=; b=KlvFYX4zaog4qI/53HGqD5OOD4/ZchGQw94m99p79QtM0m78YVLJpjFFOvww0tMGXI KSEmfO7+QOWNUsIEg2KEb1cQJ4eRBRlyg6PTYtTFcnZEET+m7UcAX9UN/yyrc5Fo0b7W vK0pQw7wgAyiFbrBsgfov8klQOIIG4AVA76zU0WPnyOYJZ+83g507munN2t/zM29eYCX H60m7QTjCyWSoZn5NhEKcx0rAToBTgFZV6iacOlZeXguQ3K47mrXeBUZqHFImSmjqSJH e7dSrGxshdAXbPwH0LVBBAqeoPO28OKdhqlWZ1tTKDjdRfCcDSBlc4TP8byTMgFafdKY szAw== ARC-Authentication-Results: i=1; mx.google.com; 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 u24-v6si6549390pgk.72.2018.08.09.07.13.41; Thu, 09 Aug 2018 07:13:56 -0700 (PDT) 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; 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 S1732191AbeHIQhX (ORCPT + 99 others); Thu, 9 Aug 2018 12:37:23 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:48784 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1730813AbeHIQhX (ORCPT ); Thu, 9 Aug 2018 12:37:23 -0400 Received: (qmail 1880 invoked by uid 2102); 9 Aug 2018 10:12:18 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 9 Aug 2018 10:12:18 -0400 Date: Thu, 9 Aug 2018 10:12:18 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Laurent Pinchart cc: Keiichi Watanabe , Tomasz Figa , Linux Kernel Mailing List , Mauro Carvalho Chehab , Linux Media Mailing List , , Douglas Anderson , , Subject: Re: [RFC PATCH v1] media: uvcvideo: Cache URB header data before processing In-Reply-To: <14751117.J1GmkhZxMo@avalon> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 9 Aug 2018, Laurent Pinchart wrote: > > >> There is no need to wonder. "Frequent DMA mapping/Cached memory" is > > >> always faster than "No DMA mapping/Uncached memory". > > > > > > Is it really, doesn't it depend on the CPU access pattern ? > > > > Well, if your access pattern involves transferring data in from the > > device and then throwing it away without reading it, you might get a > > different result. :-) But assuming you plan to read the data after > > transferring it, using uncached memory slows things down so much that > > the overhead of DMA mapping/unmapping is negligible by comparison. > > :-) I suppose it would also depend on the access pattern, if I only need to > access part of the buffer, performance figures may vary. In this case however > the whole buffer needs to be copied. > > > The only exception might be if you were talking about very small > > amounts of data. I don't know exactly where the crossover occurs, but > > bear in mind that Matwey's tests required ~50 us for mapping/unmapping > > and 3000 us for accessing uncached memory. He didn't say how large the > > transfers were, but that's still a pretty big difference. > > For UVC devices using bulk endpoints data buffers are typically tens of kBs. > For devices using isochronous endpoints, that goes down to possibly hundreds > of bytes for some buffers. Devices can send less data than the maximum packet > size, and mapping/unmapping would still invalidate the cache for the whole > buffer. If we keep the mappings around and use the DMA sync API, we could > possibly restrict the cache invalidation to the portion of the buffer actually > written to. Furthermore, invalidating a cache is likely to require less overhead than using non-cacheable memory. After the cache has been invalidated, it can be repopulated relatively quickly (an entire cache line at a time), whereas reading uncached memory requires a slow transaction for each individual read operation. I think adding support to the USB core for dma_sync_single_for_{cpu|device} would be a good approach. In fact, I wonder whether using coherent mappings provides any benefit at all. Alan Stern