Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4096216imm; Mon, 30 Jul 2018 08:36:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdQNbOayC4KdgOw3BIST0EQekQMY6xtA9ELAquzxHSECl/K47OEl6gaZVaHH1BR+DIW6TA9 X-Received: by 2002:a17:902:7c89:: with SMTP id y9-v6mr16873437pll.187.1532964977581; Mon, 30 Jul 2018 08:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532964977; cv=none; d=google.com; s=arc-20160816; b=wJV068Z3pX1q3QR8aGunG1qjhqodvveLjA0xSLA3/MzNAHVfVXwLw8RsrrfXzYT/bP lNj2b/5QPIsoqdrV9HqCC7VtBxz4Cf6DlbWKc+vaGc2qJKqGDAshdUw4VFGeND4UNLiS poD0lxvb1GG8pyZQTUxTeFAdshbJXeyh3zwKrT6BdcfFpU8GYET4nnzSv2oiKkT/EQ2x VNQf949ooBqZfD1w8KGir35aAsAI+W6RuERtfhoNNWEsVJirCiHDicZFsuQNS0ynqxR/ UjeNCZyN2bh2QorG9MM5bNCJiYZd2cQ/pb2U3Cn2p3e8scdNYotfaABGWaKwa3jiY+tu FI3w== 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:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=MwjpNsjH46tn3v/ZDQRSZp0Ff0/zej3QjjP+/VZdrzM=; b=iycHzvMzgt3Z11MHPusjWZ5UYzwKAJhVlkoECm0OHVSTvDoMesxwaROKEC/qv+C17U 8GGNdV35uZ84IeQQZLwV4f/v+qzUUzGg69XsjZq0SYwc8vSfPz3jTzUyqS/IAgnCFgpg Rewava5+bQhRYepqRQRbPHmFo2GPTRnqxpfJIcT2ub1aQ9DPqyZK6zrV2ao7B9GayPid aU9j7O2lM5J7NkT4ygtmsy5gvxwnp/tl7gQpsYwT1emKqX3/shHA5nbZYUlnKUfivcmC 5vhrKDspk3jSQA109ZNwpvjjsTyJNqZocsiug+tYB7H5bxtfpjwk2G3AeE9QVSrKLLa1 8CjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=CjoTPzcr; 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 i29-v6si11245080pgi.410.2018.07.30.08.36.03; Mon, 30 Jul 2018 08:36:17 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=CjoTPzcr; 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 S1729093AbeG3RKm (ORCPT + 99 others); Mon, 30 Jul 2018 13:10:42 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:40758 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726762AbeG3RKm (ORCPT ); Mon, 30 Jul 2018 13:10:42 -0400 Received: from avalon.localnet (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 36B111BE8; Mon, 30 Jul 2018 17:35:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1532964910; bh=v81mQXqRptK04rcULpOQ6VpSsXiiXfLfJ8X+7QbwbCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CjoTPzcrMawj3qA6a/61aDhlkmxP44uolbt06YF5pGk7PnfgPuqtcaQ6xfTkGG4ds QsHtPCMBcGK6mijYj7xhlr9W2i7CkbaILVbxQaIlT6WQDX/3mZu0RFAKAW8UEnDppb HYgxASsURvhfAS0OKftebsSVQ1VTYKc0mB0cxUBg= From: Laurent Pinchart To: "Matwey V. Kornilov" Cc: Alan Stern , Tomasz Figa , Ezequiel Garcia , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab , Steven Rostedt , mingo@redhat.com, Mike Isely , Bhumika Goyal , Colin King , Linux Media Mailing List , Linux Kernel Mailing List , Kieran Bingham , keiichiw@chromium.org Subject: Re: [PATCH 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer Date: Mon, 30 Jul 2018 18:35:48 +0300 Message-ID: <1556658.LS2rrRvGR3@avalon> Organization: Ideas on Board Oy In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit 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 Hi Matwey, On Tuesday, 24 July 2018 21:56:09 EEST Matwey V. Kornilov wrote: > 2018-07-23 21:57 GMT+03:00 Alan Stern: > > On Mon, 23 Jul 2018, Matwey V. Kornilov wrote: > >> I've tried to strategies: > >> > >> 1) Use dma_unmap and dma_map inside the handler (I suppose this is > >> similar to how USB core does when there is no URB_NO_TRANSFER_DMA_MAP) > > > > Yes. > > > >> 2) Use sync_cpu and sync_device inside the handler (and dma_map only > >> once at memory allocation) > >> > >> It is interesting that dma_unmap/dma_map pair leads to the lower > >> overhead (+1us) than sync_cpu/sync_device (+2us) at x86_64 platform. > >> At armv7l platform using dma_unmap/dma_map leads to ~50 usec in the > >> handler, and sync_cpu/sync_device - ~65 usec. > >> > >> However, I am not sure is it mandatory to call > >> dma_sync_single_for_device for FROM_DEVICE direction? > > > > According to Documentation/DMA-API-HOWTO.txt, the CPU should not write > > to a DMA_FROM_DEVICE-mapped area, so dma_sync_single_for_device() is > > not needed. > > Well, I measured the following at armv7l. The handler execution time > (URB_NO_TRANSFER_DMA_MAP is used for all cases): > > 1) coherent DMA: ~3000 usec (pwc is not functional) > 2) explicit dma_unmap and dma_map in the handler: ~52 usec > 3) explicit dma_sync_single_for_cpu (no dma_sync_single_for_device): ~56 > usec I really don't understand why the sync option is slower. Could you please investigate ? Before doing anything we need to make sure we have a full understanding of the problem. > So, I suppose that unfortunately Tomasz suggestion doesn't work. There > is no performance improvement when dma_sync_single is used. > > At x86_64 the following happens: > > 1) coherent DMA: ~2 usec What do you mean by coherent DMA for x86_64 ? Is that usb_alloc_coherent() ? Could you trace it to see how memory is allocated exactly, and how it's mapped to the CPU ? I suspect that it will end up in dma_direct_alloc() but I'd like a confirmation. > 2) explicit dma_unmap and dma_map in the handler: ~3.5 usec > 3) explicit dma_sync_single_for_cpu (no dma_sync_single_for_device): ~4 usec > > So, whats to do next? Personally, I think that DMA streaming API > introduces not so great overhead. It might not be very large, but with USB3 cameras at high resolutions and framerates, it might still become noticeable. I wouldn't degrade performances on x86, especially if we can decide which option to use based on the platform (or perhaps even better based on Kconfig options such as DMA_NONCOHERENT). > Does anybody happy with turning to streaming DMA or I'll introduce > module-level switch as Ezequiel suggested? A module-level switch isn't a good idea, it will just confuse users. We need to establish a strategy and come up with a good heuristic that can be applied at compile and/or runtime to automatically decide how to allocate buffers. -- Regards, Laurent Pinchart