Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1411874imm; Wed, 10 Oct 2018 14:14:39 -0700 (PDT) X-Google-Smtp-Source: ACcGV60lTpQ+z02PoMFXCp07AfEsloR0fHMwXh9Y1m+1/bK1gvK9R1m59MIl8fe6eOjWAEOgcpFJ X-Received: by 2002:a17:902:16a4:: with SMTP id h33-v6mr26829068plh.3.1539206079182; Wed, 10 Oct 2018 14:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539206079; cv=none; d=google.com; s=arc-20160816; b=JEXQyj7XlACvkp6MRzKAZFGhY/AHNbPLCfOX4TMT5l1DfpELoE7cuZYOhReBnDblnM wq7dEAsjUTTAZq1OkCKWbiGXhlASTX18rvK4giZ1ZUQSj2QOhe68eXHGOwFw+qToHBI7 YRhZogWshWI1zcuwFeCmjrBdfJUSQjUPRz4G5KPmbdLSOeGlqB3Rr/kobh4R6x8bZH6b cfmfP6JUui1dR7GYxqQbgdih/urYPUPaiMeBWLrhU2HGqT/9/CXW+uJK79LK4DjLJ4cL o9YixTmMfO7kuO1rS6DWhCTnclsH0WBt/4tsyST18g9PhCuSIn14WjmpnUwcXB5+nMiH JRnQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=sV/fBlFx8kl36BM//8wj6UifIbLSOZmhcU+hYFcY/Ts=; b=akN+9XSPzsCOmhOtGN71PdgXhBv2f3cNH7W6QQ172Q5KM1gNCMT+hT9uRRaTnvyTNq +x5sy4v/KPX8MiRdIj8j17/iosA2aZfjGXr4mDMUBL0QdVp3xRLqb9+QrDpub1nG9x2P q3S59hNcH3Ztv3uC6mV1bnzSGDfsy7i9fHrcqP6sueunwApIN5oAQ0IZ+vSnB8davnkF PaWagfgjiFS/cmtYVJGZxSvfUMZDhnnYQjdrc8mA9QhAsouUCsTK0+vy6Uld62C9L8V0 xbqGyF4P6rOIrE7wnCucwPQC0jg6jguKNocgLq6FZ9j5G5r5kDtyNwIXcMzOAmUutQTs WxlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eIlQET9w; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 129-v6si27964380pfd.201.2018.10.10.14.14.24; Wed, 10 Oct 2018 14:14:39 -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 header.i=@gmail.com header.s=20161025 header.b=eIlQET9w; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726054AbeJKEhj (ORCPT + 99 others); Thu, 11 Oct 2018 00:37:39 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:33056 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbeJKEhj (ORCPT ); Thu, 11 Oct 2018 00:37:39 -0400 Received: by mail-ot1-f68.google.com with SMTP id q50so6842704otd.0; Wed, 10 Oct 2018 14:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=sV/fBlFx8kl36BM//8wj6UifIbLSOZmhcU+hYFcY/Ts=; b=eIlQET9wQBxFx+VrJ0+N1LJQDxOv0TBt8w37mUYx0yIjoQQe3eto8GNbP5wSG33XrT /9lgr4wRv1DsJVqiWFVYZmYjCqeIqChQXRQWveSwENGOYhXQ4zO35ttYWOlFv4kVPVik 6ilo9TMMriUUkFAydaHmQmvstluDqMCe9WyitLQtoRApEJurHt5sLC9NI0jHr66T5l5T siFzoz3Y1xjboSgUYtf4biMKqKqLNdydrR3iuF9C5by8ZEHtn6lazALTDVFre+bJSEPK nBMDFepqHjZPwrxTAgskZG+Rx8Ph0vt1tZSiZvBMflJ9Z+wu8MJ9jEZk4chOf1cBP105 f1Vw== 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:content-transfer-encoding; bh=sV/fBlFx8kl36BM//8wj6UifIbLSOZmhcU+hYFcY/Ts=; b=tQXoUpQRDPwpUKLzGJmKAn4IKPm4sffvfsjxjU0cs+Lw1Gpe7gjMzG7Hr42z6QIfNu Gylf+E9mQaS6mcw4St4l/geK0Gc78ezPxi8XidwQBlG4FfMSGkazduXNvP/vtcYID7XS hV67gYbNJXzZF1yja13fkliJuIbZDirSYlcGTGZRwPPe6pfkIVAjkPoLEWHT0C2rFHsr BJRiHctmZ2m9roPbRKPQdwstkw2xz9k7BPiljU859DIx8wkF53xz5U9pccFh7Cx1MgXn w+tYYW9YCJKOLa1DN4ipNnmDvKL4PQ9lw3XrqOrzoKhvZE8z2kwE3UwMSsftUUbyCjzU 5oBg== X-Gm-Message-State: ABuFfogkH2EG79yooXd6fDcIbUvjTVDIVASdfKzX8ZLdfM95QitoFiDH XU7zxw6RLmQSZ6MFqmisI3xXGVrwSdg9xhapGNJj140n X-Received: by 2002:a9d:5d02:: with SMTP id b2-v6mr15642624oti.237.1539206020436; Wed, 10 Oct 2018 14:13:40 -0700 (PDT) MIME-Version: 1.0 References: <20180821170629.18408-1-matwey@sai.msu.ru> <20180821170629.18408-3-matwey@sai.msu.ru> In-Reply-To: From: "Matwey V. Kornilov" Date: Thu, 11 Oct 2018 00:13:28 +0300 Message-ID: Subject: Re: [PATCH v5 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer To: Linux Media Mailing List , open list Cc: Tomasz Figa , Laurent Pinchart , Alan Stern , Ezequiel Garcia , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab , Steven Rostedt , mingo@redhat.com, Mike Isely , Bhumika Goyal , Colin King , Kieran Bingham , keiichiw@chromium.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =D0=B2=D1=82, 11 =D1=81=D0=B5=D0=BD=D1=82. 2018 =D0=B3. =D0=B2 21:58, Matwe= y V. Kornilov : > > =D0=B2=D1=82, 28 =D0=B0=D0=B2=D0=B3. 2018 =D0=B3. =D0=B2 10:17, Matwey V.= Kornilov : > > > > =D0=B2=D1=82, 21 =D0=B0=D0=B2=D0=B3. 2018 =D0=B3. =D0=B2 20:06, Matwey = V. Kornilov : > > > > > > DMA cocherency slows the transfer down on systems without hardware > > > coherent DMA. > > > Instead we use noncocherent DMA memory and explicit sync at data rece= ive > > > handler. > > > > > > Based on previous commit the following performance benchmarks have be= en > > > carried out. Average memcpy() data transfer rate (rate) and handler > > > completion time (time) have been measured when running video stream a= t > > > 640x480 resolution at 10fps. > > > > > > x86_64 based system (Intel Core i5-3470). This platform has hardware > > > coherent DMA support and proposed change doesn't make big difference = here. > > > > > > * kmalloc: rate =3D (2.0 +- 0.4) GBps > > > time =3D (5.0 +- 3.0) usec > > > * usb_alloc_coherent: rate =3D (3.4 +- 1.2) GBps > > > time =3D (3.5 +- 3.0) usec > > > > > > We see that the measurements agree within error ranges in this case. > > > So theoretically predicted performance downgrade cannot be reliably > > > measured here. > > > > > > armv7l based system (TI AM335x BeagleBone Black @ 300MHz). This platf= orm > > > has no hardware coherent DMA support. DMA coherence is implemented vi= a > > > disabled page caching that slows down memcpy() due to memory controll= er > > > behaviour. > > > > > > * kmalloc: rate =3D (114 +- 5) MBps > > > time =3D (84 +- 4) usec > > > * usb_alloc_coherent: rate =3D (28.1 +- 0.1) MBps > > > time =3D (341 +- 2) usec > > > > > > Note, that quantative difference leads (this commit leads to 4 times > > > acceleration) to qualitative behavior change in this case. As it was > > > stated before, the video stream cannot be successfully received at AM= 335x > > > platforms with MUSB based USB host controller due to performance issu= es > > > [1]. > > > > > > [1] https://www.spinics.net/lists/linux-usb/msg165735.html > > > > > > Signed-off-by: Matwey V. Kornilov > > > > Ping > > > > Ping > Ping > > > --- > > > drivers/media/usb/pwc/pwc-if.c | 57 ++++++++++++++++++++++++++++++++= ---------- > > > 1 file changed, 44 insertions(+), 13 deletions(-) > > > > > > diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/p= wc-if.c > > > index 72d2897a4b9f..1360722ab423 100644 > > > --- a/drivers/media/usb/pwc/pwc-if.c > > > +++ b/drivers/media/usb/pwc/pwc-if.c > > > @@ -159,6 +159,32 @@ static const struct video_device pwc_template = =3D { > > > /*******************************************************************= ********/ > > > /* Private functions */ > > > > > > +static void *pwc_alloc_urb_buffer(struct device *dev, > > > + size_t size, dma_addr_t *dma_handle= ) > > > +{ > > > + void *buffer =3D kmalloc(size, GFP_KERNEL); > > > + > > > + if (!buffer) > > > + return NULL; > > > + > > > + *dma_handle =3D dma_map_single(dev, buffer, size, DMA_FROM_DE= VICE); > > > + if (dma_mapping_error(dev, *dma_handle)) { > > > + kfree(buffer); > > > + return NULL; > > > + } > > > + > > > + return buffer; > > > +} > > > + > > > +static void pwc_free_urb_buffer(struct device *dev, > > > + size_t size, > > > + void *buffer, > > > + dma_addr_t dma_handle) > > > +{ > > > + dma_unmap_single(dev, dma_handle, size, DMA_FROM_DEVICE); > > > + kfree(buffer); > > > +} > > > + > > > static struct pwc_frame_buf *pwc_get_next_fill_buf(struct pwc_device= *pdev) > > > { > > > unsigned long flags =3D 0; > > > @@ -306,6 +332,11 @@ static void pwc_isoc_handler(struct urb *urb) > > > /* Reset ISOC error counter. We did get here, after all. */ > > > pdev->visoc_errors =3D 0; > > > > > > + dma_sync_single_for_cpu(&urb->dev->dev, > > > + urb->transfer_dma, > > > + urb->transfer_buffer_length, > > > + DMA_FROM_DEVICE); > > > + > > > /* vsync: 0 =3D don't copy data > > > 1 =3D sync-hunt > > > 2 =3D synched > > > @@ -428,16 +459,15 @@ static int pwc_isoc_init(struct pwc_device *pde= v) > > > urb->dev =3D udev; > > > urb->pipe =3D usb_rcvisocpipe(udev, pdev->vendpoint); > > > urb->transfer_flags =3D URB_ISO_ASAP | URB_NO_TRANSFE= R_DMA_MAP; > > > - urb->transfer_buffer =3D usb_alloc_coherent(udev, > > > - ISO_BUFFER_= SIZE, > > > - GFP_KERNEL, > > > - &urb->trans= fer_dma); > > > + urb->transfer_buffer_length =3D ISO_BUFFER_SIZE; > > > + urb->transfer_buffer =3D pwc_alloc_urb_buffer(&udev->= dev, > > > + urb->tran= sfer_buffer_length, > > > + &urb->tra= nsfer_dma); > > > if (urb->transfer_buffer =3D=3D NULL) { > > > PWC_ERROR("Failed to allocate urb buffer %d\n= ", i); > > > pwc_isoc_cleanup(pdev); > > > return -ENOMEM; > > > } > > > - urb->transfer_buffer_length =3D ISO_BUFFER_SIZE; > > > urb->complete =3D pwc_isoc_handler; > > > urb->context =3D pdev; > > > urb->start_frame =3D 0; > > > @@ -488,15 +518,16 @@ static void pwc_iso_free(struct pwc_device *pde= v) > > > > > > /* Freeing ISOC buffers one by one */ > > > for (i =3D 0; i < MAX_ISO_BUFS; i++) { > > > - if (pdev->urbs[i]) { > > > + struct urb *urb =3D pdev->urbs[i]; > > > + > > > + if (urb) { > > > PWC_DEBUG_MEMORY("Freeing URB\n"); > > > - if (pdev->urbs[i]->transfer_buffer) { > > > - usb_free_coherent(pdev->udev, > > > - pdev->urbs[i]->transfer_buffe= r_length, > > > - pdev->urbs[i]->transfer_buffe= r, > > > - pdev->urbs[i]->transfer_dma); > > > - } > > > - usb_free_urb(pdev->urbs[i]); > > > + if (urb->transfer_buffer) > > > + pwc_free_urb_buffer(&urb->dev->dev, > > > + urb->transfer_buf= fer_length, > > > + urb->transfer_buf= fer, > > > + urb->transfer_dma= ); > > > + usb_free_urb(urb); > > > pdev->urbs[i] =3D NULL; > > > } > > > } > > > -- > > > 2.16.4 > > > > > > > > > -- > > With best regards, > > Matwey V. Kornilov > > > > -- > With best regards, > Matwey V. Kornilov --=20 With best regards, Matwey V. Kornilov