From patchwork Thu Aug 9 18:11:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matwey V. Kornilov" X-Patchwork-Id: 10561665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6345B13B4 for ; Thu, 9 Aug 2018 18:12:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F9DC2B7E6 for ; Thu, 9 Aug 2018 18:12:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4325B2B7FB; Thu, 9 Aug 2018 18:12:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BED0D2B7E6 for ; Thu, 9 Aug 2018 18:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727560AbeHIUhm (ORCPT ); Thu, 9 Aug 2018 16:37:42 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:45952 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727475AbeHIUhl (ORCPT ); Thu, 9 Aug 2018 16:37:41 -0400 Received: by mail-lf1-f66.google.com with SMTP id j143-v6so4738671lfj.12; Thu, 09 Aug 2018 11:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=L5H/UYZ5P59hCTwCDJAfmnKMChFJdMqAWNPRQDX6KkY=; b=XpRorVYuBy9IKLg9E2HVcbmrpa5dEkU3YhtYcZ7xytYeLjrEXbslMQS1T7yMmIF/ih 5dUZ+40g1MAUGflLKe+Vbdu2MrkfnEwq8sUGytmCd9mGXnve0+Nx/xAfcJdDKoTa6nMC cyZ387pLmrjs2cQOTfhW3AMbqVTl2lC9SAFB3SeJhQUf3YvltgXW85FMFs9/lSuh8OW3 1Q6elZltBTLCaec7KbdWt2uMceBqzTSltuESgGAdnV9lP5eywVRPNMXjB6ccApUVVQLU a2gUqJcTW5OSJXfNpmNLuWWKTn6VMITm0OwSg/W5U8yDMmZ1SuYcnCKd//02rc+lHTbE jSGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=L5H/UYZ5P59hCTwCDJAfmnKMChFJdMqAWNPRQDX6KkY=; b=dtEY5aEY6LcxtV+PTkqp9zPRHDDNDBNWNC32ZcWjXjyuE25sIXX+Ohp6boKNmE1m9m jNglz5zHdGYvy+c1reGYAWoYltw+C2RqFB/WleVQ08o11mBB4QdxMvIihDZhAxcZtTVg n7KsR+8a78P6v1X8cZKtVo0XNFwQiuQNeDDwWfGvPOkWfxIcMKxud/mGFo1Otn1TjH5g aNVF9LtsuTh+VMmxmjkYbV+/0M8vtA0sfKqsXF5LyrRKkEXAeH4Ohmdy636eJLpv39X5 QYGs6dHis4fIIZZGiykhf8BB7/cPGAqYwOn/bMirqxcGgWuM5YZNLNsjjr5deVQaKfPT G2aw== X-Gm-Message-State: AOUpUlFPmAzP2YQD3zg7qhUxwM5dvaHDPF9h0DAFPww+0Wx91xxfet2f FUVFothiordqTbDfXlrPeR+4IIWQweo= X-Google-Smtp-Source: AA+uWPyireFuc7OWk/bAAotnDcIUlygENij4tdwGQm1yCDzCI/ZK5t23EvpnNfwNUhnGbdjrq2gPDw== X-Received: by 2002:a19:10c4:: with SMTP id 65-v6mr2387433lfq.113.1533838297362; Thu, 09 Aug 2018 11:11:37 -0700 (PDT) Received: from localhost.localdomain ([213.87.133.10]) by smtp.gmail.com with ESMTPSA id n7-v6sm1432211lfe.87.2018.08.09.11.11.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 11:11:36 -0700 (PDT) From: "Matwey V. Kornilov" To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Matwey V. Kornilov" , tfiga@chromium.org, laurent.pinchart@ideasonboard.com, stern@rowland.harvard.edu, ezequiel@collabora.com, hdegoede@redhat.com, hverkuil@xs4all.nl, mchehab@kernel.org, rostedt@goodmis.org, mingo@redhat.com, isely@pobox.com, bhumirks@gmail.com, colin.king@canonical.com, kieran.bingham@ideasonboard.com, keiichiw@chromium.org Subject: [PATCH v4 1/2] media: usb: pwc: Introduce TRACE_EVENTs for pwc_isoc_handler() Date: Thu, 9 Aug 2018 21:11:02 +0300 Message-Id: <20180809181103.15437-2-matwey@sai.msu.ru> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180809181103.15437-1-matwey@sai.msu.ru> References: <20180809181103.15437-1-matwey@sai.msu.ru> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There were reports that PWC-based webcams don't work at some embedded ARM platforms. [1] Isochronous transfer handler seems to work too long leading to the issues in MUSB USB host subsystem. Also note, that urb->giveback() handlers are still called with disabled interrupts. In order to be able to measure performance of PWC driver, traces are introduced in URB handler section. [1] https://www.spinics.net/lists/linux-usb/msg165735.html Signed-off-by: Matwey V. Kornilov --- drivers/media/usb/pwc/pwc-if.c | 7 +++++ include/trace/events/pwc.h | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 include/trace/events/pwc.h diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c index 54b036d39c5b..72d2897a4b9f 100644 --- a/drivers/media/usb/pwc/pwc-if.c +++ b/drivers/media/usb/pwc/pwc-if.c @@ -76,6 +76,9 @@ #include "pwc-dec23.h" #include "pwc-dec1.h" +#define CREATE_TRACE_POINTS +#include + /* Function prototypes and driver templates */ /* hotplug device table support */ @@ -260,6 +263,8 @@ static void pwc_isoc_handler(struct urb *urb) int i, fst, flen; unsigned char *iso_buf = NULL; + trace_pwc_handler_enter(urb, pdev); + if (urb->status == -ENOENT || urb->status == -ECONNRESET || urb->status == -ESHUTDOWN) { PWC_DEBUG_OPEN("URB (%p) unlinked %ssynchronously.\n", @@ -348,6 +353,8 @@ static void pwc_isoc_handler(struct urb *urb) } handler_end: + trace_pwc_handler_exit(urb, pdev); + i = usb_submit_urb(urb, GFP_ATOMIC); if (i != 0) PWC_ERROR("Error (%d) re-submitting urb in pwc_isoc_handler.\n", i); diff --git a/include/trace/events/pwc.h b/include/trace/events/pwc.h new file mode 100644 index 000000000000..84807fea2217 --- /dev/null +++ b/include/trace/events/pwc.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#if !defined(_TRACE_PWC_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_PWC_H + +#include +#include + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM pwc + +TRACE_EVENT(pwc_handler_enter, + TP_PROTO(struct urb *urb, struct pwc_device *pdev), + TP_ARGS(urb, pdev), + TP_STRUCT__entry( + __field(struct urb*, urb) + __field(int, urb__status) + __field(u32, urb__actual_length) + __string(name, pdev->v4l2_dev.name) + __field(struct pwc_frame_buf*, fbuf) + __field(int, fbuf__filled) + ), + TP_fast_assign( + __entry->urb = urb; + __entry->urb__status = urb->status; + __entry->urb__actual_length = urb->actual_length; + __assign_str(name, pdev->v4l2_dev.name); + __entry->fbuf = pdev->fill_buf; + __entry->fbuf__filled = (pdev->fill_buf + ? pdev->fill_buf->filled : 0); + ), + TP_printk("dev=%s (fbuf=%p filled=%d) urb=%p (status=%d actual_length=%u)", + __get_str(name), + __entry->fbuf, + __entry->fbuf__filled, + __entry->urb, + __entry->urb__status, + __entry->urb__actual_length) +); + +TRACE_EVENT(pwc_handler_exit, + TP_PROTO(struct urb *urb, struct pwc_device *pdev), + TP_ARGS(urb, pdev), + TP_STRUCT__entry( + __field(struct urb*, urb) + __string(name, pdev->v4l2_dev.name) + __field(struct pwc_frame_buf*, fbuf) + __field(int, fbuf__filled) + ), + TP_fast_assign( + __entry->urb = urb; + __assign_str(name, pdev->v4l2_dev.name); + __entry->fbuf = pdev->fill_buf; + __entry->fbuf__filled = pdev->fill_buf->filled; + ), + TP_printk(" dev=%s (fbuf=%p filled=%d) urb=%p", + __get_str(name), + __entry->fbuf, + __entry->fbuf__filled, + __entry->urb) +); + +#endif /* _TRACE_PWC_H */ + +/* This part must be outside protection */ +#include From patchwork Thu Aug 9 18:11:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matwey V. Kornilov" X-Patchwork-Id: 10561663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B396B13BB for ; Thu, 9 Aug 2018 18:11:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DF4D2B7C5 for ; Thu, 9 Aug 2018 18:11:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90A662B7F7; Thu, 9 Aug 2018 18:11:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D9702B7C5 for ; Thu, 9 Aug 2018 18:11:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727625AbeHIUhn (ORCPT ); Thu, 9 Aug 2018 16:37:43 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:43612 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727538AbeHIUhn (ORCPT ); Thu, 9 Aug 2018 16:37:43 -0400 Received: by mail-lf1-f65.google.com with SMTP id f135-v6so4745549lfg.10; Thu, 09 Aug 2018 11:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=to8uY8hbfuZ+yD+ZvU37tf7XlezIuz6xFDBYGQhmSaE=; b=MazHHn/q9JyO8s5ii30IdWhONbmuyN6nMQih7Wr61fh1eLNpbTzAxFnosIJkCdIl6w NRwedEnkWPtsImmsGg9hwGgb2XnEddAlMidooA4l7ZEUq3jsn2p9gAlZDU2NyE7KEhWi UMMOxPFoqqNQKk3MkVYMAC7/G6OiUHmCbjFROVEtKCJ1A3oawytaXZ+k8oh7C0IBL5TJ 2hJSa58pr7b/bux+gl00bcl+cKop29nBa5BKvzVO/kr6P88n0Q2m//zKd6FXohC0yvD7 JYbHcfBbDFgoggiz4K2P1hIFGKmAQmUJbAsFIG7kzFbi0dAsVb3dmbhTKVNjUFAt1jcD x9kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=to8uY8hbfuZ+yD+ZvU37tf7XlezIuz6xFDBYGQhmSaE=; b=P0hy+uZ4VmFL4EtrlOyzbKO08fFYiSUg3AW9ZBKJvumYsaAUjkioK43J2B0T81GFaV EGTk028qZ1Sma5AcqUJmcT77ujgqkW2vjipIuddXsj7q8sHJEO8izMn/svrmkQmvzvsO 4ZKTYSOF/dOYij+umw2TFkqNO8bE6C8n9qNDdx7X4Z94t3NSEWaGOiLwZs87lfajcyLa 9G+J1f9h0CHkJBoomIgbM2vz1NhJGB110gLMZQ+eCSlLtGwGmDdJU+RxmF0+N8mr5Ddk 9TRzs7H1G+9ll9PN3z/DMIz3eZUuRWUBSQgLAxgYtfRS5ERJ7quGkMZc8B9ttES3JvfC 3XBA== X-Gm-Message-State: AOUpUlEMrgXP1Q8JlVoAze7dpJ3nGV6suGNNoVam4mJwrXc3B2IoruPg K2x4leEOgbBbowY3rTEuNu6wW4Mbk7Q= X-Google-Smtp-Source: AA+uWPzqQM3//u0Q5DN1H8GmkLNBk1qX07dgvRtyTRVD4RdMSxVshRch4E+Y2ZY4DgHrCgf2W3DuEA== X-Received: by 2002:a19:5911:: with SMTP id n17-v6mr2397323lfb.102.1533838299776; Thu, 09 Aug 2018 11:11:39 -0700 (PDT) Received: from localhost.localdomain ([213.87.133.10]) by smtp.gmail.com with ESMTPSA id n7-v6sm1432211lfe.87.2018.08.09.11.11.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 11:11:39 -0700 (PDT) From: "Matwey V. Kornilov" To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Matwey V. Kornilov" , tfiga@chromium.org, laurent.pinchart@ideasonboard.com, stern@rowland.harvard.edu, ezequiel@collabora.com, hdegoede@redhat.com, hverkuil@xs4all.nl, mchehab@kernel.org, rostedt@goodmis.org, mingo@redhat.com, isely@pobox.com, bhumirks@gmail.com, colin.king@canonical.com, kieran.bingham@ideasonboard.com, keiichiw@chromium.org Subject: [PATCH v4 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer Date: Thu, 9 Aug 2018 21:11:03 +0300 Message-Id: <20180809181103.15437-3-matwey@sai.msu.ru> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180809181103.15437-1-matwey@sai.msu.ru> References: <20180809181103.15437-1-matwey@sai.msu.ru> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP DMA cocherency slows the transfer down on systems without hardware coherent DMA. Instead we use noncocherent DMA memory and explicit sync at data receive handler. 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 = (2.0 +- 0.4) GBps time = (5.0 +- 3.0) usec * usb_alloc_coherent: rate = (3.4 +- 1.2) GBps time = (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 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 = (114 +- 5) MBps time = (84 +- 4) usec * usb_alloc_coherent: rate = (28.1 +- 0.1) MBps time = (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 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 | 56 +++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c index 72d2897a4b9f..e9c826be1ba6 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 = { /***************************************************************************/ /* Private functions */ +static void *pwc_alloc_urb_buffer(struct device *dev, + size_t size, dma_addr_t *dma_handle) +{ + void *buffer = kmalloc(size, GFP_KERNEL); + + if (!buffer) + return NULL; + + *dma_handle = dma_map_single(dev, buffer, size, DMA_FROM_DEVICE); + 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 = 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 = 0; + dma_sync_single_for_cpu(&urb->dev->dev, + urb->transfer_dma, + urb->transfer_buffer_length, + DMA_FROM_DEVICE); + /* vsync: 0 = don't copy data 1 = sync-hunt 2 = synched @@ -428,16 +459,15 @@ static int pwc_isoc_init(struct pwc_device *pdev) 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_buffer_length = ISO_BUFFER_SIZE; + urb->transfer_buffer = pwc_alloc_urb_buffer(&udev->dev, + urb->transfer_buffer_length, + &urb->transfer_dma); if (urb->transfer_buffer == NULL) { PWC_ERROR("Failed to allocate urb buffer %d\n", i); pwc_isoc_cleanup(pdev); return -ENOMEM; } - urb->transfer_buffer_length = ISO_BUFFER_SIZE; urb->complete = pwc_isoc_handler; urb->context = pdev; urb->start_frame = 0; @@ -488,15 +518,17 @@ static void pwc_iso_free(struct pwc_device *pdev) /* Freeing ISOC buffers one by one */ for (i = 0; i < MAX_ISO_BUFS; i++) { - if (pdev->urbs[i]) { + struct urb *urb = 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_buffer_length, - pdev->urbs[i]->transfer_buffer, - pdev->urbs[i]->transfer_dma); + if (urb->transfer_buffer) { + pwc_free_urb_buffer(&urb->dev->dev, + urb->transfer_buffer_length, + urb->transfer_buffer, + urb->transfer_dma); } - usb_free_urb(pdev->urbs[i]); + usb_free_urb(urb); pdev->urbs[i] = NULL; } }