Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754235AbbK0JGf (ORCPT ); Fri, 27 Nov 2015 04:06:35 -0500 Received: from dehamd003.servertools24.de ([31.47.254.18]:42857 "EHLO dehamd003.servertools24.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbbK0JG2 (ORCPT ); Fri, 27 Nov 2015 04:06:28 -0500 Subject: Re: [PATCH v5 7/7] usb: gadget: f_midi: pre-allocate IN requests To: Felipe Ferreri Tonello , linux-usb@vger.kernel.org References: <1447177929-22252-1-git-send-email-eu@felipetonello.com> <1447177929-22252-8-git-send-email-eu@felipetonello.com> <5645A58F.9030902@ladisch.de> <5655EE70.8040502@felipetonello.com> Cc: linux-kernel@vger.kernel.org, Felipe Balbi , Greg Kroah-Hartman , Robert Baldyga From: Clemens Ladisch Message-ID: <56581CC8.9080405@ladisch.de> Date: Fri, 27 Nov 2015 10:05:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <5655EE70.8040502@felipetonello.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-PPP-Message-ID: <20151127090623.972914.6245@dehamd003.servertools24.de> X-PPP-Vhost: ladisch.de Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2619 Lines: 62 Felipe Ferreri Tonello wrote: > On 13/11/15 08:55, Clemens Ladisch wrote: >> Felipe F. Tonello wrote: >>> +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. There is usb_ep_dequeue(). Its documentation warns about some hardware, but it would be possible to at least try it. >> 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. After some thought, I'm not so sure anymore -- the ability to buffer more than 2 KB of data is part of the snd_rawmidi_write() API, so this could introduce a regression. And I can imagine cases where one would actually want to transmit large amounts data. I think the safest approach would be to behave similar to the old driver, i.e., when the queue overflows, do nothing (not even dropping data), and rely on the transmit completion handler to continue. (This implies that ALSA's buffer can fill up, and that snd_rawmidi_write() can block.) It you want to dequeue outdated data, I think this should be done with a timeout, i.e., when the host did not read anything for some tens of milliseconds or so. This would be independent of the fill level of the queue, and could be done either for individual packets, or just on the entire endpoint queue. Regards, Clemens -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/