Received: by 10.223.164.202 with SMTP id h10csp828140wrb; Wed, 15 Nov 2017 08:32:56 -0800 (PST) X-Google-Smtp-Source: AGs4zMbCu/O1RXOZoxRIMJpddLt0IewqjUia7HQ8R2IjMsLtOujjBRRERUi7sWy97/HISvhETPFo X-Received: by 10.99.164.81 with SMTP id c17mr3655143pgp.206.1510763576268; Wed, 15 Nov 2017 08:32:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510763576; cv=none; d=google.com; s=arc-20160816; b=ZwVlpy51+6/DS69MyA4fboLQlwzn9M4ZtaISrAtlc2gunBUtOhlLzjtF8vBQBeEqpJ 9FjEol9F+H6Ix0l9WeLvJZG9IXzulHsN1kvo38L2Ffeu3PJB1dxgBaxbbeOQUKsN/f4h AZj8OxLKwTTusnYWYxf3s9WZ5sMNW90m3xQD3SMfEY5ifnCQ/YYz0+JgEApaS17FxKJW OtoeSUp1+KRq8xUws0D1mHeuTtl4JoRoFqk/B6U1SOIgWYZldVS3X023wDqIZB7OFqgV RtOOn6AgBjQhtBiWBwiL6v75IJ7M7mdnyaP7AWpkkIsZhl9jpWRrZXaJFlhTXAY5MBwX ejnQ== 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=BPttfK/zI3yTzSbn4L7yM843E0xMXGOnYUBPJz/VMuA=; b=juXsLHhU4/s+FIBbWDCRAJ6lpdzbJYngQ1klfjYnu215/26np4VjP1L5n11vTfkDp9 cQof0JadCKfLi5BMiZEkMAF0YnU3xoElxvyYAX26H5NhJo5jlSNFIKbzdQ0orfLQHGXP bxRKcV0JfmvXFvBw/INZvVSAeqc3PR9k7T5zsHB3NpnsScPTR4wIzBisl/MdcegFPU/B q3vL/MlpsDeVmFDKSFsAuUUirmrenD92S6EJWlqGtfmDzWB+x9JBWMX/abR36UxLUpzn wP/tBRidX6HzjZq96/xvv4NvjiFJZLqev805o8sN/wBArV75mtcw8go91O0ydMpwnjO0 iVFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=icwb6qh8; 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 o135si19617431pfg.240.2017.11.15.08.32.43; Wed, 15 Nov 2017 08:32:56 -0800 (PST) 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=icwb6qh8; 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 S932309AbdKOPT6 (ORCPT + 89 others); Wed, 15 Nov 2017 10:19:58 -0500 Received: from mail-ot0-f196.google.com ([74.125.82.196]:51612 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757593AbdKOPTb (ORCPT ); Wed, 15 Nov 2017 10:19:31 -0500 Received: by mail-ot0-f196.google.com with SMTP id b54so7732358otd.8; Wed, 15 Nov 2017 07:19:30 -0800 (PST) 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=BPttfK/zI3yTzSbn4L7yM843E0xMXGOnYUBPJz/VMuA=; b=icwb6qh8Qv6JGJGh9GHssQ6ybiC/rV6DFGXdUsa2t6zUZC7aAavnnE6NR51+iug5Zi 052NFwcCCl3vJWKWK7AYSOy8ebiob2mifvMFLFvpJqiNfxYqUAUDuz0vNsuulWqaVNAP fcNO8xP8ODNMRz1EwomFZWLACoMXXZv7pECxsX/hed3bVK6DvU3mBI9WDyOFlrpdBgO7 a4iB9AmXXTVK+czOHr/E5J0sPJE0nUuJIdkflOt8zibDOkyOd3F4L/YEh340zM/+X+me B8T7xt83fKP7/tTsElapQZrhvvhPqJ09MG4WiDlWYRMSvf23GBRAF5UmxlaFkudq2SN/ 0o4g== 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=BPttfK/zI3yTzSbn4L7yM843E0xMXGOnYUBPJz/VMuA=; b=rMdTqsojsJZWli0UuF40tt6iM3BJ60EAwFxHlM6EJbUzAN9Amwk3Qtb/YLOKgLgLmo HGdstBj25iZA3U52QDqyyFT7gXk8nGjkBLbkn4TjkoLrQDSLLISfpcHJxmZ6xioFv/Cu 2FVqgWOMkOeUvOKSlh/3QwX2zCAIjapYtQnaj3ImKZEDRWnRi59tZybYrZ1doKUEPyMM tqCbekJtg/4Fm/VO+gcg072DEt1ULZlN75BOJdVARbvwz3wrpbeQHkTuaydPL7QRBpw8 4hmzwxgV1nu6vXYXiS1GHSyfQs8Els5k8ieebgmVWy13MDNzbfw9XHvjYwoXOh8/2LKE YaLw== X-Gm-Message-State: AJaThX4i5q7B6CR/rnI5CrJSAoYxkoEiErIvKwHaOQTwVKLn7lPhcmbS MJUsfSnLw8UqDApiq4973cm0H/IAL2/Z/wqySG8= X-Received: by 10.157.0.105 with SMTP id 96mr10704745ota.160.1510759169163; Wed, 15 Nov 2017 07:19:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.64.133 with HTTP; Wed, 15 Nov 2017 07:19:08 -0800 (PST) In-Reply-To: References: <20170427102033.5500-1-matwey@sai.msu.ru> From: "Matwey V. Kornilov" Date: Wed, 15 Nov 2017 18:19:08 +0300 X-Google-Sender-Auth: fpt-46FIxIJhmvNNX6seUw0hOB0 Message-ID: Subject: Re: [PATCH] usb: musb: musb_host: Introduce postponed URB giveback To: Bin Liu , Greg KH Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Matwey V. Kornilov" 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 The issue is also present in 4.9.60-ti-r75 2017-11-04 17:05 GMT+03:00 Matwey V. Kornilov : > Hi Bin, > > I've just checked that the issue is still present in 4.13.10. > > 2017-04-27 13:20 GMT+03:00 Matwey V. Kornilov : >> This commit changes the order of actions undertaken in >> musb_advance_schedule() in order to overcome issue with broken >> isochronous transfer [1]. >> >> There is no harm to split musb_giveback into two pieces. The first >> unlinks finished urb, the second givebacks it. The issue here that >> givebacking may be quite time-consuming due to urb->complete() call. >> As it happens in case of pwc-driven web cameras. It may take about 0.5 >> ms to call __musb_giveback() that calls urb->callback() internally. >> Under specific circumstances setting MUSB_RXCSR_H_REQPKT in subsequent >> musb_start_urb() for the next urb will be too late to produce physical >> IN packet. Since auto req is not used by this module the exchange >> would be as the following: >> >> [ ] 7.220456 d= 0.000997 [182 + 3.667] [ 3] IN : 4.5 >> [ T ] 7.220459 d= 0.000003 [182 + 7.000] [800] DATA0: [skipped] >> [ ] 7.222456 d= 0.001997 [184 + 3.667] [ 3] IN : 4.5 >> [ ] 7.222459 d= 0.000003 [184 + 7.000] [ 3] DATA0: 00 00 >> >> It is known that missed IN in isochronous mode makes some >> perepherial broken. For instance, pwc-driven or uvc-driven >> web cameras. >> In order to workaround this issue we postpone calling >> urb->callback() after setting MUSB_RXCSR_H_REQPKT for the >> next urb if there is the next urb pending in queue. >> >> [1] https://www.spinics.net/lists/linux-usb/msg145747.html >> >> Fixes: f551e1352983 ("Revert "usb: musb: musb_host: Enable HCD_BH flag to handle urb return in bottom half"") >> Signed-off-by: Matwey V. Kornilov >> --- >> drivers/usb/musb/musb_host.c | 54 +++++++++++++++++++++++++++++++++++++------- >> 1 file changed, 46 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c >> index ac3a4952abb4..b590c2555dab 100644 >> --- a/drivers/usb/musb/musb_host.c >> +++ b/drivers/usb/musb/musb_host.c >> @@ -299,19 +299,24 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh) >> } >> } >> >> -/* Context: caller owns controller lock, IRQs are blocked */ >> -static void musb_giveback(struct musb *musb, struct urb *urb, int status) >> +static void __musb_giveback(struct musb *musb, struct urb *urb, int status) >> __releases(musb->lock) >> __acquires(musb->lock) >> { >> - trace_musb_urb_gb(musb, urb); >> - >> - usb_hcd_unlink_urb_from_ep(musb->hcd, urb); >> spin_unlock(&musb->lock); >> usb_hcd_giveback_urb(musb->hcd, urb, status); >> spin_lock(&musb->lock); >> } >> >> +/* Context: caller owns controller lock, IRQs are blocked */ >> +static void musb_giveback(struct musb *musb, struct urb *urb, int status) >> +{ >> + trace_musb_urb_gb(musb, urb); >> + >> + usb_hcd_unlink_urb_from_ep(musb->hcd, urb); >> + __musb_giveback(musb, urb, status); >> +} >> + >> /* For bulk/interrupt endpoints only */ >> static inline void musb_save_toggle(struct musb_qh *qh, int is_in, >> struct urb *urb) >> @@ -346,6 +351,7 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb, >> struct musb_hw_ep *ep = qh->hw_ep; >> int ready = qh->is_ready; >> int status; >> + int postponed_giveback = 0; >> >> status = (urb->status == -EINPROGRESS) ? 0 : urb->status; >> >> @@ -361,9 +367,35 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb, >> break; >> } >> >> - qh->is_ready = 0; >> - musb_giveback(musb, urb, status); >> - qh->is_ready = ready; >> + usb_hcd_unlink_urb_from_ep(musb->hcd, urb); >> + >> + /* It may take about 0.5 ms to call __musb_giveback() that >> + * calls urb->callback() internally. Under specific circumstances >> + * setting MUSB_RXCSR_H_REQPKT in subsequent musb_start_urb() for the >> + * next urb will be too late to produce physical IN packet. Since >> + * auto req is not used by this module the exchange would be as the >> + * following: >> + * >> + * [ ] 7.220456 d= 0.000997 [182 + 3.667] [ 3] IN : 4.5 >> + * [ T ] 7.220459 d= 0.000003 [182 + 7.000] [800] DATA0: [skipped] >> + * [ ] 7.222456 d= 0.001997 [184 + 3.667] [ 3] IN : 4.5 >> + * [ ] 7.222459 d= 0.000003 [184 + 7.000] [ 3] DATA0: 00 00 >> + * >> + * It is known that missed IN in isochronous mode makes some >> + * perepherial broken. For instance, pwc-driven or uvc-driven >> + * web cameras. >> + * In order to workaround this issue we postpone calling >> + * urb->callback() after setting MUSB_RXCSR_H_REQPKT for the >> + * next urb if there is the next urb pending in queue. >> + */ >> + if (is_in && qh->type == USB_ENDPOINT_XFER_ISOC >> + && !list_empty(&qh->hep->urb_list)) { >> + postponed_giveback = 1; >> + } else { >> + qh->is_ready = 0; >> + __musb_giveback(musb, urb, status); >> + qh->is_ready = ready; >> + } >> >> /* reclaim resources (and bandwidth) ASAP; deschedule it, and >> * invalidate qh as soon as list_empty(&hep->urb_list) >> @@ -428,6 +460,12 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb, >> hw_ep->epnum, is_in ? 'R' : 'T', next_urb(qh)); >> musb_start_urb(musb, is_in, qh); >> } >> + >> + if (postponed_giveback) { >> + qh->is_ready = 0; >> + __musb_giveback(musb, urb, status); >> + qh->is_ready = ready; >> + } >> } >> >> static u16 musb_h_flush_rxfifo(struct musb_hw_ep *hw_ep, u16 csr) >> -- >> 2.12.0 >> > > > > -- > 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 From 1583144674052621439@xxx Sat Nov 04 14:06:54 +0000 2017 X-GM-THRID: 1583144674052621439 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread