Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1277627

Re: [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Felipe Ferreri Tonello <eu@felipetonello.com>
Newsgroups linux.kernel
Subject Re: [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests
Date Wed, 25 Nov 2015 18:30:03 +0100
Message-ID <qyM3h-RQ-11@gated-at.bofh.it> (permalink)
References <qtln3-8aF-7@gated-at.bofh.it> <qtln5-8aF-29@gated-at.bofh.it> <quin8-49R-5@gated-at.bofh.it>
X-Original-To Clemens Ladisch <clemens@ladisch.de>, linux-usb@vger.kernel.org
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=felipetonello-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type; bh=tyCrc12K8XMBvt7DsmvxDn3uD1UeeJuzwOyVzxgr9iA=; b=UStpDQArB6RR+uSYoaA68FN/GQ+P3m5S6f2DEz2VrZR6+TH6qESaknLrjpNn8e/pQ0 AiiY6iJ9QC9TV/Q3wB+a9U4KR+ZAgAmOzrNgqFRDBj3aRSlMMyfqzc3ac2zEA9Y9Twxo Y7FQsbKgY4H2VgfshKtDeLdUcXqFlmdBPFOzQJ7UtbQ3kVJS9ug+2CMVuAs0cvS7r1wG wf9T8C+fijRiSpfOP/kjz7DY/I262hHoZgVTrzEDbwUPnSLTjwG/dT3hVkforEZ6tBuV KIKZ/htQ2CEcBXStyd6TO0kCn/i7qMthjWqVx9WAcUw8CRt1Gq9Ev2vTVjlVdGALuhCk rpUQ==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type; bh=tyCrc12K8XMBvt7DsmvxDn3uD1UeeJuzwOyVzxgr9iA=; b=jtucq4ey2lXT8cDA3SMcm3oKBbxq0OR5uYr6Iw5h1JW96faFeT156lOsIHKhP/UIhN 40jIt5i1/ZPE3JRLIDNuPrvwpmvx844SyloffYErWg8Q3pAoa2j2Qhq6Ng9I5DlBHzK8 FHPjxE9jeVFVozs/TgpbskglqvgTkeFM1JZpbdPzB+/7H3H2T+bpoxF7dnWCbcZfHRzf OfogNHI6U6A1Z9mn6PRHbC4GJHkp2kr0Kj/I6FdmxXmagC3YEpL/1I4nxttGGoikQ3Vs iA2kbEjvFhARerxha/9esDmhJRG4L9A1yEu2qY87F04TYKB++3Z6Ba51KxD4sxjAZ4DZ yvUg==
X-Gm-Message-State ALoCoQlsn50tuKLuCQFki/34hgqsTe5yYGyYCYgC8Bva4O2Mi8/MjK0veui2zEcpcI1EqB7e1sJ/
X-Received by 10.28.104.197 with SMTP id d188mr6271625wmc.55.1448472178245; Wed, 25 Nov 2015 09:22:58 -0800 (PST)
X-Enigmail-Draft-Status N1111
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0
MIME-Version 1.0
Content-Type multipart/mixed; boundary="------------010104050105000604060605"
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 230
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, Felipe Balbi <balbi@ti.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Robert Baldyga <r.baldyga@samsung.com>
X-Original-Date Wed, 25 Nov 2015 17:22:56 +0000
X-Original-Message-ID <5655EE70.8040502@felipetonello.com>
X-Original-References <1447177929-22252-1-git-send-email-eu@felipetonello.com> <1447177929-22252-8-git-send-email-eu@felipetonello.com> <5645A58F.9030902@ladisch.de>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1277627

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests Felipe Ferreri Tonello <eu@felipetonello.com> - 2015-11-25 18:30 +0100
  Re: [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests Clemens Ladisch <clemens@ladisch.de> - 2015-11-27 10:10 +0100
    Re: [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests Felipe Ferreri Tonello <eu@felipetonello.com> - 2015-11-27 19:10 +0100
      Re: [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests Clemens Ladisch <clemens@ladisch.de> - 2015-11-27 21:00 +0100

csiph-web