public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Toby Gray <toby.gray@realvnc.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Oliver Neukum <oliver@neukum.name>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] USB: cdc-acm: Prevent loss of data when filling tty buffer
Date: Wed, 08 Jun 2011 18:08:42 +0100	[thread overview]
Message-ID: <4DEFAC9A.9030106@realvnc.com> (raw)
In-Reply-To: <20110608164626.22bc893c@lxorguk.ukuu.org.uk>

On 08/06/2011 16:46, Alan Cox wrote:
>> This patch adds checking for how many bytes have been inserted into the tty
>> buffer and places data which hasn't been inserted into a pending buffer list.
>> The pending buffer list is pushed to the tty buffer when the tty unthrottles
> I don't think this is the way to tackle it.
Fair enough. I wasn't 100% sure that adding what is really an extra 
layer of buffering in the driver was the best solution.
> If the kernel tty buffer code is shedding data then not only have we
> asserted a throttle but 64K has been accumulated or the system is out of
> memory.
>
> So the questions to me are:
>
> a) Why is your setup filling 64K in the time it takes the throttle
> response to occur
The setup is a Nokia mobile phone sending some application data over a 
USB connection. Applications running on Nokia's Symbian based mobile 
phones which wish to communicate with a PC over USB are offered a 
virtual COM port on the mobile phone side. This COM port appears as a 
second cdc-acm device to the PC.

In this particular instance the device is sending a large quantity of 
data (about 1MB) down the COM port. This communication is one way, so 
the device keeps sending the data as fast as the PC requests more USB 
bulk transfers.

If it hasn't been told to throttle then the cdc-acm code will issue more 
bulk reads as soon as the last one has completed. This means that it's 
possible for the tty to not have a chance to be throttle by 
flush_to_ldisc before too much data has been received over USB.
> b) Do we care (is the right thing to do to lose bits anyway at that point)
The cdc-acm driver which Nokia provide for Windows doesn't drop data 
when transferring large volumes of data, so most application making use 
of the mobile phone to PC USB connection won't have implemented any form 
of error correction or retransmission. If we don't care about data loss 
on Linux then it will force the application layer to implement some way 
of detecting these losses and to then retransmit the data.

> c) What should we do about it in the *general* case
> It seems to me either its a cdc-acm specific problem with throttle
> response behaviour, or its a general case at very high speed (which seems
> more likely). In neither case is adding an extra queue to paper over it
> the right solution.
Agreed. I'm not sure about how specific to cdc-acm it is though. I think 
the reason that I'm seeing this problem is due to the high data rate of 
USB combined with the protocol that is being used over the cdc-acm 
channel not having any flow control or acknowledgements. I have no idea 
how specialist this situation is though.

I think a possible alternative solution for the cdc-acm would be for it 
to make sure that tty_buffer_request_room returns enough space for any 
pending URB requests. However I think I originally dismissed this as a 
possibility as I couldn't think of an easy way for the cdc-acm driver to 
be told that more buffer room has been made available.

Regards,

Toby


      reply	other threads:[~2011-06-08 17:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-08 15:38 [PATCH] USB: cdc-acm: Prevent loss of data when filling tty buffer Toby Gray
2011-06-08 15:46 ` Alan Cox
2011-06-08 17:08   ` Toby Gray [this message]

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=4DEFAC9A.9030106@realvnc.com \
    --to=toby.gray@realvnc.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oliver@neukum.name \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox