Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp453188imm; Wed, 18 Jul 2018 05:13:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfDDuMziQl6nRhVozu8ed4kJfTA5ZQ5CO26nuS9ZnHKqRHZ0ahM/slIfh18YuXqX29qZysN X-Received: by 2002:a17:902:7009:: with SMTP id y9-v6mr5798598plk.249.1531915988525; Wed, 18 Jul 2018 05:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531915988; cv=none; d=google.com; s=arc-20160816; b=hofGOAIDCav6MFrvWncTTEyyBOYeJehANXzZCZESNEFPyK15rehpyfiI/0LBZiWOn3 UKm/LzqKBm38BWN7inK5NfxeuaoCV2aP1CYMcqLw14SG+bpsMscqPDWQQHDV3wbRrbOE UnOPMv9aB6Fl3Uhaj5LQYNZVZnujWR3zAATq396mAc5RZa69a7PQe/gkKrlGLlZfYhx6 Cs1txm9WiON4cJiyW9CaEQP7JvJEgaQZgLezOufztj5K3uQybfq8qxYwJ+eM/2gVy0Hp ssuLVEj6niDdILe20JxaABdw/7vuScZcxqFSqynIwynz6tWlZAHThZWHDNzRFblE89ai j5jA== 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=vfl//XMJSMfgR/EMozlvcn702gDGdw5o78RntacClnM=; b=YGC8BvoOhIbFKKTp4X1UB/GulLB8FX1ncKhdZ2jEnPG2EAUqMDEO+3Cc4Wp8EdiyYa 6pjVhOnFTktTYjmX/gmLMpjefYJaKvkqvZaqNWVz22t3mjGTvBDBZi0xosE2HItdUW3X P8W4NU03wY4nWjjl9yAKUOxoIZcNVmLVaG0pHpMARqrnK3GljtUlmd5TS1X83D+/Cmzl 8aEs36ORzBUPetGV5LkT1CRCEjLZjRN4npgmLADrIAvavkWNK07hwiZHVYDVdslzJovD vX2tNDf6/DqBoHZ4+6k1Tah4BV2Xty+CId1u7oFtL2ajJjMGKnz6PG6GNhSQza+oU0a+ Rtpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=CCdbL0ji; 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 i4-v6si3200485pgl.435.2018.07.18.05.12.53; Wed, 18 Jul 2018 05:13:08 -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=CCdbL0ji; 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 S1730913AbeGRMse (ORCPT + 99 others); Wed, 18 Jul 2018 08:48:34 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:46427 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730220AbeGRMse (ORCPT ); Wed, 18 Jul 2018 08:48:34 -0400 Received: by mail-oi0-f67.google.com with SMTP id y207-v6so8287932oie.13; Wed, 18 Jul 2018 05:10: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=vfl//XMJSMfgR/EMozlvcn702gDGdw5o78RntacClnM=; b=CCdbL0jiRHYsBeowzgCgv9ds4RE8Wf6pyGkVCz4LG+spX+8dNt9o/kWd+fWxbbpZu6 qc3LAoxawKGYkPQAzFipqGojUqArX62Uk9VUjEw3fQp6Zo7bbU3lD5UEZdnis4A+xBb3 rlw2EPMMsBRcqR1Gr5H2ytjsE4rXaj1AQPFSnl0OJCuBF0wfwmFCRV3/gj83XAyi5lT+ z1deQg2orjM+hZQQMB3Z8abr/iCqvloDD53xEKjchBSO3l7i8kEuFDSdgqRCu1Uh7bKu dSs9/hRzNy+8uPP1SpExeJpnHp2OmclzA2ZIeCbEGDl5GABdP6sObROmxmO2B2dHPdHq SciQ== 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=vfl//XMJSMfgR/EMozlvcn702gDGdw5o78RntacClnM=; b=WgfPW5R87IQRDupHdsNGWOoHKeLvkKxvTLAFF8TWsmOfuuWCSF8jIJpJQXvigsMu1n zZufgjUH2pb1y14K+xcSZOYjI4Q5LluB5UUL5HcYWEwdUsUQh7CtbB6kn1v4+oLmgiJq dMyia5CwbqdD7WtgDhktVOHS/00d3HTgCCy3w506KKzo+bsv0IbcRjmQvVsyQkjz1+zK /6eNvV7sUels59CNoZZVlqtwlDFG9rU4ZMStUXJ6KDO2jbQg75nTnJWB/YcMgobxqX5y FncoiphT9E3fMoRQfSKpqMXPXsJcLFfwcmT2JbyML/IJlc7UfJ8Bgv5MfEhxFw6HYL1w vchQ== X-Gm-Message-State: AOUpUlEkAOKGn/W1ZgTrWs2TCTC4g44v7oqeaYGxQjcpmcUw0lgs5jYZ LhrdUfULE0lyPvONzWv+Jywa2HrQlpAbApdFPxQ= X-Received: by 2002:aca:dec6:: with SMTP id v189-v6mr6329888oig.98.1531915855438; Wed, 18 Jul 2018 05:10:55 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:734:0:0:0:0:0 with HTTP; Wed, 18 Jul 2018 05:10:35 -0700 (PDT) In-Reply-To: References: <20180617143625.32133-1-matwey@sai.msu.ru> <20180617143625.32133-2-matwey@sai.msu.ru> From: "Matwey V. Kornilov" Date: Wed, 18 Jul 2018 15:10:35 +0300 X-Google-Sender-Auth: Dr3UcSL0KNXVQwmj4-pwI-vGELc Message-ID: Subject: Re: [PATCH 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer To: Ezequiel Garcia Cc: Alan Stern , Hans de Goede , hverkuil@xs4all.nl, mchehab@kernel.org, Laurent Pinchart , Steven Rostedt , mingo@redhat.com, Mike Isely , Bhumika Goyal , Colin King , linux-media@vger.kernel.org, open 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 2018-07-17 23:10 GMT+03:00 Ezequiel Garcia : > Hi Matwey, > > First of all, sorry for the delay. > > Adding Alan and Hans. Guys, do you have any feedback here? > > See below for some feedback on my side. > > On Mon, 2018-06-18 at 10:10 +0300, Matwey V. Kornilov wrote: >> Hi Ezequiel, >> >> 2018-06-18 8:11 GMT+03:00 Ezequiel Garcia : >> > + Laurent >> > >> > On Sun, 2018-06-17 at 17:36 +0300, Matwey V. Kornilov wrote: >> > > DMA cocherency slows the transfer down on systems without hardware >> > > coherent DMA. >> > > >> > > Based on previous commit the following performance benchmarks have been >> > > carried out. Average memcpy() data transfer rate (rate) and handler >> > > completion time (time) have been measured when running video stream at >> > > 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 = (4.4 +- 1.0) GBps >> > > time = (2.4 +- 1.2) usec >> > > * usb_alloc_coherent: rate = (4.1 +- 0.9) GBps >> > > time = (2.5 +- 1.0) usec >> > > >> > > We see that the measurements agree well within error ranges in this case. >> > > So no performance downgrade is introduced. >> > > >> > > armv7l based system (TI AM335x BeagleBone Black). This platform has no >> > > hardware coherent DMA support. DMA coherence is implemented via disabled >> > > page caching that slows down memcpy() due to memory controller behaviour. >> > > >> > > * kmalloc: rate = (190 +- 30) MBps >> > > time = (50 +- 10) usec >> > > * usb_alloc_coherent: rate = (33 +- 4) MBps >> > > time = (3000 +- 400) usec >> > > >> > > Note, that quantative difference leads (this commit leads to 5 times >> > > acceleration) to qualitative behavior change in this case. As it was >> > > stated before, the video stream can not be successfully received at AM335x >> > > platforms with MUSB based USB host controller due to performance issues >> > > [1]. >> > > >> > > [1] https://www.spinics.net/lists/linux-usb/msg165735.html >> > > >> > >> > This is quite interesting! I have receive similar complaints >> > from users wanting to use stk1160 on BBB and Raspberrys, >> > without much luck on either, due to insufficient isoc bandwidth. >> > >> > I'm guessing other ARM platforms could be suffering >> > from the same issue. >> > >> > Note that stk1160 and uvcvideo drivers use kmalloc on platforms >> > where DMA_NONCOHERENT is defined, but this is not the case >> > on ARM platforms. >> >> There are some ARMv7 platforms that have coherent DMA (for instance >> Broadcome Horthstar Plus series), but the most of them don't have. It >> is defined in device tree file, and there is no way to recover this >> information at runtime in USB perepherial driver. >> >> > >> > 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. > > The only thing that bothers me with this patch is that it's not > really something specific to this driver. If this fix is valid > for pwc, then it's valid for all the drivers allocating coherent > memory. > > And also, this path won't prevent further copy-paste spread > of the coherent allocation. > > Is there any chance we can introduce a helper to allocate > isoc URBs, and then change all drivers to use it? No need > to do all of them now, but it would be good to at least have > a plan for it. Well, basically I am agree with you. However, I don't have all possible hardware to test, so I can't fix all possible drivers. Also I can not figure out how could the helper looked like. What do you think about usb_alloc() (c.f. usb_alloc_coherent()) ? > > Chances are, only a handful of platforms would care to use > coherent mappings. > >> I understand that there are cases when DMA coherence is really needed, >> for instane VirtIO VRing when we accessing same data structure in both >> directions from the both sides, but this has nothing common with our >> case. >> >> > >> > If the choice is simply platform dependent, >> > can't we somehow detect which mapping should >> > be prefered? >> >> Now, we don't have this way. >> >> > >> > > Signed-off-by: Matwey V. Kornilov >> > > --- >> > > drivers/media/usb/pwc/pwc-if.c | 12 +++--------- >> > > 1 file changed, 3 insertions(+), 9 deletions(-) >> > > >> > > diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c >> > > index 5775d1f60668..6a3cd9680a7f 100644 >> > > --- a/drivers/media/usb/pwc/pwc-if.c >> > > +++ b/drivers/media/usb/pwc/pwc-if.c >> > > @@ -427,11 +427,8 @@ static int pwc_isoc_init(struct pwc_device *pdev) >> > > urb->interval = 1; // devik >> > > urb->dev = udev; >> > > urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint); >> > > - urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; >> > > - urb->transfer_buffer = usb_alloc_coherent(udev, >> > > - ISO_BUFFER_SIZE, >> > > - GFP_KERNEL, >> > > - &urb->transfer_dma); >> > > + urb->transfer_flags = URB_ISO_ASAP; >> > > + urb->transfer_buffer = kmalloc(ISO_BUFFER_SIZE, GFP_KERNEL); >> > > if (urb->transfer_buffer == NULL) { >> > > PWC_ERROR("Failed to allocate urb buffer %d\n", i); >> > > pwc_isoc_cleanup(pdev); >> > > @@ -491,10 +488,7 @@ static void pwc_iso_free(struct pwc_device *pdev) >> > > if (pdev->urbs[i]) { >> > > PWC_DEBUG_MEMORY("Freeing URB\n"); >> > > if (pdev->urbs[i]->transfer_buffer) { >> > > - usb_free_coherent(pdev->udev, >> > > - pdev->urbs[i]->transfer_buffer_length, >> > > - pdev->urbs[i]->transfer_buffer, >> > > - pdev->urbs[i]->transfer_dma); >> > > + kfree(pdev->urbs[i]->transfer_buffer); >> > > } >> > > usb_free_urb(pdev->urbs[i]); >> > > pdev->urbs[i] = NULL; >> >> >> > -- With best regards, Matwey V. Kornilov. Sternberg Astronomical Institute, Lomonosov Moscow State University, Russia 119234, Moscow, Universitetsky pr-k 13, +7 (495) 9392382