Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6027577imm; Mon, 23 Jul 2018 10:06:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfWClrycc0X1mWcHfbLxUSGKuPr3PzxpYZ8iYexqmjtErPWCNZeks2eMkyfmJ8noJWN4EYq X-Received: by 2002:a62:4b48:: with SMTP id y69-v6mr14053568pfa.93.1532365604370; Mon, 23 Jul 2018 10:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532365604; cv=none; d=google.com; s=arc-20160816; b=uvYTyA4MQAZ5eaXSJ9cGCNLCGdcsuEgOQQbBFKeQhFbcgmL5tEcqgmnGiP4nmri/Wn S3dcJWt6X+RyQOPIWbM2fthzoPpqi3uvaq3nmJdv4d2Yez0WlRjYxdKLmehOmhoearXh G5EqNw5cDPm0HtBa++D6MjWVG7yHEM7p+ht5XJ4sfA1h75YL5fT1oHFCrkNNkY7JgHUW BCAr8e1a2gbDd92psVEXhdbMEodMH7b8q0jada6ZWINrSiH1I/iYK0tiuZaC+PpIkg7W xpsfC89YGNmzHdQTnCirg4YpM/Q1Ize/2ZElYjVLAcvgNjvl6OInx0zW2FdKAqNtATMC wrKA== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=1FxgqwTP7tsl/P3Fa2qlPq0QWhmqQ9kUvdHI2KGRw2E=; b=C8r2PGT+Z71VFAOUsxeFlv76KH0x51wnYdJ9yMWyQdj6VtfLwEsikxT7e4IgWHMeEP 3CxPJt0e6DI40a7FDaYgdr9c5k0KqNJbLexcsPA9UkUXsepwwRm1dNKJENzD2sPC5bTI WlCgLH3w/z3t/W13UxIBTXU1h8MKpdapguFDR79g6tVQctM6h6oT12uueYb0UDcLyv51 2J/UACDBOvF7Ze3/f4sTwYXlCZW+xVrlwN/fZlg/8QqBxPy20vDJgilci57oZxYdGbi6 mvpR6i53AsfVinimfS/GdViZ2A7HYzXCkxU4TRNaDS44E6826Jqf6xeupUwlc+MAsn2R CSWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hUfua1iq; 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 j184-v6si9068758pge.607.2018.07.23.10.06.29; Mon, 23 Jul 2018 10:06:44 -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=fail header.i=@gmail.com header.s=20161025 header.b=hUfua1iq; 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 S2388786AbeGWSHF (ORCPT + 99 others); Mon, 23 Jul 2018 14:07:05 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:40468 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388200AbeGWSHF (ORCPT ); Mon, 23 Jul 2018 14:07:05 -0400 Received: by mail-oi0-f65.google.com with SMTP id w126-v6so2416588oie.7; Mon, 23 Jul 2018 10:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=1FxgqwTP7tsl/P3Fa2qlPq0QWhmqQ9kUvdHI2KGRw2E=; b=hUfua1iqm3fZvBPW6NE9kDGDs59nkOatre6K5do2iaTOLYWhaX/wImrGUEpzmJRcGq 1T7oTQctaHxSDm8TXuEFdN0lUS6jlvszpD3AyPWlOt6WGbSAVFPN/2pG+JVXstK8VeG4 ZWTPCDSuY2PE3exSm/8lHzSpHl3Tz/kdB0FJO9JJnzXLoF4l2Wns3hJAQ8qc6730IAe1 oewOPT2g+o9d+J+LhMyIUDZ6P9Fbum4HlwXHbFNWv9aCfg2IrpnCtEYyMp0TDg5jXsOC gqyEG/M8hrO7sgDlihwlqK44INUIAaOdOvzYh6Pf+6ZCBL2yTyGwBuE/CmlxFkRectRQ 1UOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=1FxgqwTP7tsl/P3Fa2qlPq0QWhmqQ9kUvdHI2KGRw2E=; b=mFSHLiNEW4IOu+UPv+oDgJCxfKhzl6+5xbPscQ5jVO6ijF19apcVWEu0gkZY1WYsNH mSvavvAqRIv+kHO8jzp6Gf0EZV001zC58ddQxI+1OPGAKY5G5L9jP8glhXeAx9XtWZ82 5wPrXTQztO81C1d9MJDdRg3ZA/PwkI2cDbTljBjoiEvaUnM77KMAlyAf8bMx54x2fHNC cywUJW+l9dWYEguomwRc9y5q1V+QPcrDD5grYF7AeWb1UBrBarY7NmM2jHm6gIPINMbD MHlaD6kLCGYEQsiJOrBm5BZrUyL1d6wDLuF/hCH8tQcxgMylwhCmD/8pW4wIulIxDRsb r4Zg== X-Gm-Message-State: AOUpUlEyxaiVIL9/k/22mJnkqLTjFqyICoWXQc5bxJOU3Z6JKdufR+h8 q9qhkiTkgRO/piXoAriPBE0uI6wKCknZY7Y+igklDsFw X-Received: by 2002:aca:c514:: with SMTP id v20-v6mr9866596oif.153.1532365495848; Mon, 23 Jul 2018 10:04:55 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:734:0:0:0:0:0 with HTTP; Mon, 23 Jul 2018 10:04:35 -0700 (PDT) In-Reply-To: References: From: "Matwey V. Kornilov" Date: Mon, 23 Jul 2018 20:04:35 +0300 X-Google-Sender-Auth: e6uJXE1tJEvWvZU_RnMsXcAFyHA Message-ID: Subject: Re: [PATCH 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer To: Tomasz Figa Cc: Alan Stern , Ezequiel Garcia , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab , Laurent Pinchart , Steven Rostedt , mingo@redhat.com, Mike Isely , Bhumika Goyal , Colin King , Linux Media Mailing List , Linux Kernel Mailing List , Kieran Bingham , keiichiw@chromium.org 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 2018-07-20 14:57 GMT+03:00 Matwey V. Kornilov : > 2018-07-20 14:33 GMT+03:00 Tomasz Figa : >> On Fri, Jul 20, 2018 at 8:23 PM Matwey V. Kornilov wrote: >>> >>> 2018-07-20 13:55 GMT+03:00 Tomasz Figa : >>> > On Wed, Jul 18, 2018 at 5:51 AM Alan Stern wrote: >>> >> >>> >> On Tue, 17 Jul 2018, Ezequiel Garcia wrote: >>> >> >>> >> > Hi Matwey, >>> >> > >>> >> > First of all, sorry for the delay. >>> >> > >>> >> > Adding Alan and Hans. Guys, do you have any feedback here? >>> >> >>> >> ... >>> >> >>> >> > > > So, what is the benefit of using consistent >>> >> > > > for these URBs, as opposed to streaming? >>> >> > > >>> >> > > I don't know, I think there is no real benefit and all we see is a >>> >> > > consequence of copy-pasta when some webcam drivers were inspired by >>> >> > > others and development priparily was going at x86 platforms. >>> >> > >>> >> > You are probably right about the copy-pasta. >>> >> > >>> >> > > It would >>> >> > > be great if somebody corrected me here. DMA Coherence is quite strong >>> >> > > property and I cannot figure out how can it help when streaming video. >>> >> > > The CPU host always reads from the buffer and never writes to. >>> >> > > Hardware perepherial always writes to and never reads from. Moreover, >>> >> > > buffer access is mutually exclusive and separated in time by Interrupt >>> >> > > fireing and URB starting (when we reuse existing URB for new request). >>> >> > > Only single one memory barrier is really required here. >>> >> > > >>> >> > >>> >> > Yeah, and not setting URB_NO_TRANSFER_DMA_MAP makes the USB core >>> >> > create DMA mappings and use the streaming API. Which makes more >>> >> > sense in hardware without hardware coherency. >>> >> >>> >> As far as I know, the _only_ advantage to using coherent DMA in this >>> >> situation is that you then do not have to pay the overhead of >>> >> constantly setting up and tearing down the streaming mappings. So it >>> >> depends very much on the platform: If coherent buffers are cached then >>> >> it's a slight win and otherwise it's a big lose. >>> > >>> > Isn't it about usb_alloc_coherent() being backed by DMA coherent API >>> > (dma_alloc_coherent/attrs()) and ending up allocating uncached (or >>> > write-combine) memory for devices with non-coherent DMAs? I'm not sure >>> >>> Yes, this is what exactly happens at armv7l platforms. >> >> Okay, thanks. So this seems to be exactly the same thing that is >> happening in the UVC driver. There is quite a bit of random accesses >> to extract some header fields and then a big memcpy into VB2 buffer to >> assemble final frame. >> >> If we don't want to pay the cost of creating and destroying the >> streaming mapping, we could map (dma_map_single()) once, set >> transfer_dma of URB and URB_NO_TRANSFER_DMA_MAP and then just >> synchronize the caches (dma_sync_single()) before submitting/after >> completing the URB. > > Thank you. Now it is becoming clearer to me. Please allow me some time > to try to sketch the implementation. 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) 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? > >> >> Best regards, >> Tomasz >> > > > > -- > With best regards, > Matwey V. Kornilov. > Sternberg Astronomical Institute, Lomonosov Moscow State University, Russia > 119234, Moscow, Universitetsky pr-k 13, +7 (495) 9392382 -- With best regards, Matwey V. Kornilov. Sternberg Astronomical Institute, Lomonosov Moscow State University, Russia 119234, Moscow, Universitetsky pr-k 13, +7 (495) 9392382