From: Felipe Ferreri Tonello <eu@felipetonello.com>
To: Clemens Ladisch <clemens@ladisch.de>, linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Felipe Balbi <balbi@ti.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Robert Baldyga <r.baldyga@samsung.com>
Subject: Re: [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests
Date: Wed, 25 Nov 2015 17:22:56 +0000 [thread overview]
Message-ID: <5655EE70.8040502@felipetonello.com> (raw)
In-Reply-To: <5645A58F.9030902@ladisch.de>
[-- Attachment #1: Type: text/plain, Size: 3324 bytes --]
Hi Clemens
On 13/11/15 08:55, Clemens Ladisch wrote:
> Felipe F. Tonello wrote:
>> This patch introduces pre-allocation of IN endpoint USB requests. This
>> improves on latency (requires no usb request allocation on transmit) and avoid
>> several potential probles on allocating too many usb requests (which involves
>> DMA pool allocation problems).
>>
>> This implementation also handles better multiple MIDI Gadget ports, always
>> processing the last processed MIDI substream if the last USB request wasn't
>> enought to handle the whole stream.
>
>> ...
>> +++ b/drivers/usb/gadget/function/f_midi.c
>> @@ -88,6 +89,9 @@ struct f_midi {
>> int index;
>> char *id;
>> unsigned int buflen, qlen;
>> + DECLARE_KFIFO_PTR(in_req_fifo, struct usb_request *);
>> + unsigned int in_req_num;
>> + unsigned int in_last_port;
>
> As far as I can see, in_req_num must always have the same value as qlen.
Yes, I've removed in_req_num.
>
>> @@ -366,6 +388,20 @@ static void f_midi_disable(struct usb_function *f)
>> + while (!kfifo_is_empty(&midi->in_req_fifo)) {
>> + ...
>> + len = kfifo_get(&midi->in_req_fifo, &req);
>> + if (len == 1)
>> + free_ep_req(midi->in_ep, req);
>> + else
>> + ERROR(midi, "%s couldn't free usb request: something went wrong with kfifo\n",
>> + midi->in_ep->name);
>> + }
>
> kfifo_get() already checks for the FIFO being empty, so you can just
> drop kfifi_is_empty().
Ok. I've simplified this code. I wasn't really happy with it either.
>
>> @@ -487,57 +523,111 @@ static void f_midi_transmit_byte(struct usb_request *req,
>> ...
>> +static void f_midi_transmit(struct f_midi *midi)
>> +{
>> +...
>> + len = kfifo_peek(&midi->in_req_fifo, &req);
>> + ...
>> + if (req->length > 0) {
>> + WARNING(midi, "%s: All USB requests have been used. Current queue size "
>> + "is %u, consider increasing it.\n", __func__, midi->in_req_num);
>> + goto drop_out;
>> + }
>
> There are two cases where the in_req FIFO might overflow:
> 1) the gadget is trying to send too much data at once; or
> 2) the host does not bother to read any of the data.
>
> In case 1), the appropriate action would be to do nothing, so that the
> remaining data is sent after some currently queued packets have been
> transmitted. In case 2), the appropriate action would be to drop the
> data (even better, the _oldest_ data), and spamming the log with error
> messages would not help.
True. In this case the log will be spammed.
How would you suggest to drop the oldest data? That doesn't really seem
to be feasible.
>
> This code shows the error message for case 1), but does the action for
> case 2).
>
> I'm not quite sure if trying to detect which of these cases we have is
> possible, or worthwhile. Anyway, with a packet size of 64, the queue
> size would be 32*64 = 2KB, which should be enough for everyone. So I
> propose to ignore case 1), and to drop the error message.
Agree. It would be useful for users to know about case 1), but like you
said it is probably not worthwhile to do to so.
>
>> @@ -1130,6 +1222,12 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
>> + if (kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL))
>> + goto setup_fail;
>
> The setup_fail code expects an error code in the status variable.
Done.
Felipe
[-- Attachment #2: 0x92698E6A.asc --]
[-- Type: application/pgp-keys, Size: 7310 bytes --]
next prev parent reply other threads:[~2015-11-25 17:23 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-10 17:52 [PATCH v5 0/7] USB MIDI Gadget improvements and bug fixes Felipe F. Tonello
2015-11-10 17:52 ` [PATCH v5 1/7] usb: gadget: f_midi: Transmit data only when IN ep is enabled Felipe F. Tonello
2015-11-13 8:08 ` Robert Baldyga
2015-11-10 17:52 ` [PATCH v5 2/7] usb: gadget: f_midi: remove duplicated code Felipe F. Tonello
2015-11-13 8:09 ` Robert Baldyga
2015-11-10 17:52 ` [PATCH v5 3/7] usb: gadget: define free_ep_req as universal function Felipe F. Tonello
2015-11-13 8:11 ` Robert Baldyga
2015-11-10 17:52 ` [PATCH v5 4/7] usb: gadget: f_midi: fix leak on failed to enqueue out requests Felipe F. Tonello
2015-11-13 8:31 ` Robert Baldyga
2015-11-16 11:08 ` Felipe Ferreri Tonello
2015-11-16 11:43 ` Robert Baldyga
2015-11-25 13:02 ` Felipe Ferreri Tonello
2015-11-10 17:52 ` [PATCH v5 5/7] usb: gadget: gmidi: Cleanup legacy code Felipe F. Tonello
2015-11-13 8:34 ` Robert Baldyga
2015-11-10 17:52 ` [PATCH v5 6/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface Felipe F. Tonello
2015-11-10 18:43 ` Sergei Shtylyov
2015-11-11 9:38 ` Felipe Ferreri Tonello
2015-11-11 18:02 ` Sergei Shtylyov
2015-11-13 8:11 ` Clemens Ladisch
2015-11-16 11:41 ` Felipe Ferreri Tonello
2015-11-13 8:14 ` Clemens Ladisch
2015-11-10 17:52 ` [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests Felipe F. Tonello
2015-11-13 8:55 ` Clemens Ladisch
2015-11-25 17:22 ` Felipe Ferreri Tonello [this message]
2015-11-27 9:05 ` Clemens Ladisch
2015-11-27 18:03 ` Felipe Ferreri Tonello
2015-11-27 19:52 ` Clemens Ladisch
2015-11-13 12:38 ` Robert Baldyga
2015-11-25 16:54 ` Felipe Ferreri Tonello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5655EE70.8040502@felipetonello.com \
--to=eu@felipetonello.com \
--cc=balbi@ti.com \
--cc=clemens@ladisch.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=r.baldyga@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.