Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1358468imm; Wed, 8 Aug 2018 15:47:26 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxOubzG/njtRB0Gv65kkmDTyFHB+S7MK//K2+RgGtvdPu5j3pfiw0qVsFCuOj0fHs4yZq1t X-Received: by 2002:a63:df04:: with SMTP id u4-v6mr4176392pgg.434.1533768446589; Wed, 08 Aug 2018 15:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533768446; cv=none; d=google.com; s=arc-20160816; b=eCwymv7G7dYMUHs1D00zBOvRlpPoD1SQ3Hnr+f5Qee32sq2qJMdn4ZEesWbeh5NfsH 5os1sS/qUrTIyvhkCXOKsSQfK/rxgmv0OArwLTS+nyze5ranV2CQAOJ/6+ldblQq1Iit wdwm9x47imQab20xdNX9tPUpHcGSJv+iQVKarp2Qyz6cqV5t+TRif3Z5cMlGTkJXKMvS KVXyhLYm/J4UEmfJlcD4AfZuoimVodxKsjTHtG1X99tZG5eSmJpU6hsl/KYXDU+EK0JN xRrAuzLRzxi+lp7uS9PKR5y40EDZS86v768dkTNX/JL4gpizfLmLADa91ZuM1XPnDtW9 26Bg== 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=5YL8V+GszyTjsq+o0hOa5zn7dDlBx6lKSHGyzvIPP08=; b=M5a9kkZjf54PBVSPGR920DrnLTlz67pgGPZhU4siY9x70l2bD85Aq8TUO0yYyI+bbi WY+vCv4TW7CVOSkp3KNRcJyL4wjFEwmwEUR5mMt2TK/66mssaRK+rJ2VxtnPDo+xwm9H IAiwr0/kGByFkGwpz4LfgrSMT98DqUsMiSOzkRzaTLlKWEK+7RxSyMv6Y7OuFdYTo/Q5 sxh0GrawjP1pfUu4pTBIzlgtze/y8Wf/rYMiBEHWkqS3fFQ6DtY/P9/D4/Jg/i1SPx62 h2Be7EE+4dgNqPity05c8BL5ZwQwPUN9N7RpxzIEsdVVZDRQkAYMRoDr1JfYvO4cqd6N ZmMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=gkxxSWAA; 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 z9-v6si5101004pfg.46.2018.08.08.15.47.11; Wed, 08 Aug 2018 15:47:26 -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=gkxxSWAA; 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 S1731029AbeHIBHf (ORCPT + 99 others); Wed, 8 Aug 2018 21:07:35 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:38806 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727530AbeHIBHe (ORCPT ); Wed, 8 Aug 2018 21:07:34 -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 E1E3CCD; Thu, 9 Aug 2018 00:45:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533768346; bh=szrNatQhqPIx3pPwp0gXhWJ6IjnP4HlhTbzwE2EBZ+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gkxxSWAAE3rYtx9Fv3g8qCV4wlj8NXcvPCD2hhY8AxA2BGnLNymZwLgotT2tM0A7R N6OGtAnIrp5+n558rRuzmnprT3K+dVscA6K/ReNUpcN2THeVFQQl9T7urA9fKk9XJq amQGNS9EVBx8OYY0Z4pFwTxYnhyQAqBRQf3CD2og= From: Laurent Pinchart To: "Matwey V. Kornilov" Cc: hverkuil@xs4all.nl, mchehab@kernel.org, rostedt@goodmis.org, mingo@redhat.com, isely@pobox.com, bhumirks@gmail.com, colin.king@canonical.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, ezequiel@collabora.com Subject: Re: [PATCH v2 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer Date: Thu, 09 Aug 2018 01:46:30 +0300 Message-ID: <2175835.YAv5WQJWxC@avalon> Organization: Ideas on Board Oy In-Reply-To: <20180622120419.7675-3-matwey@sai.msu.ru> References: <20180622120419.7675-1-matwey@sai.msu.ru> <20180622120419.7675-3-matwey@sai.msu.ru> 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, Thank you for the patch. On Friday, 22 June 2018 15:04:19 EEST 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 > > 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 72d2897a4b9f..339a285600d1 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); ISO_BUFFER_SIZE is 970 bytes, well below a page size, so this should be fine. However, for other USB camera drivers, we might require larger buffers spanning multiple pages, and kmalloc() wouldn't be a very good choice there. I thus believe we should implement a helper function, possibly in the for of usb_alloc_noncoherent(), to allow picking the right allocation mechanism based on the buffer size (and possibly other parameters). Ideally the helper and the USB core should cooperate to avoid any overhead from DMA operations when DMA is coherent on the platform (on x86 and some ARM platforms). That being said, I don't see a reason why this patch should be blocked until we get such a helper function, we can also implement it when needed for another USB webcam driver (likely uvcvideo given the recent discussions) and then use it in the pwc driver. We have also determined that performances can be further improved by keeping mappings around and using the dma_sync_* operations at runtime. That's again not a reason to block this patch, as the performance improvement is already impressive, so Reviewed-by: Laurent Pinchart But I would still like to see the above two issues addressed. If you'd like to give them a go, with or without getting v2 of this series merged first, please do so, and I'll happily review patches. > 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; -- Regards, Laurent Pinchart