From: Mateusz Sikora <ms1qaz@gmail.com>
To: Johan Hovold <johan@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Mateusz Sikora <ms1qaz@gmail.com>, Willy Tarreau <w@1wt.eu>
Subject: [PATCH 2/2] USB: serial: ch341: use more read urbs
Date: Sun, 6 Dec 2026 01:18:44 +0100 [thread overview]
Message-ID: <20261206001844.14858-3-ms1qaz@gmail.com> (raw)
In-Reply-To: <20261206001844.14858-1-ms1qaz@gmail.com>
The CH340 has 32-byte bulk endpoints so with two read urbs only 64
bytes can be in flight, which is less than 0.7 ms worth of data at
921600 baud. Characters are lost whenever the completion of a read urb
is delayed for longer than that.
This was first observed on a Raspberry Pi 4 where heavy network traffic
through a Docker bridge delayed the softirq that gives back completed
bulk-in urbs, on the CPU handling the xHCI interrupt, by up to 1.1 ms.
With six devices receiving at 921600 baud while Docker networks and
containers were created and removed in a loop for 150 seconds, the two
CH340 devices lost 392 and 398 lines of output in about 220 seconds of
recording, while a CH343 (cdc-acm) and three USB-Serial/JTAG devices on
the same hub lost nothing.
It can also be reproduced on x86 (Intel Sunrise Point xHCI) with the
same kind of load during 135 seconds of a 180 second recording. A CH340
receiving 24-byte lines then lost 335 to 436 lines per run at 921600
baud, and 681 to 703 lines at 1500000 baud. The largest gaps there
correspond to about 7 ms of data.
Using 512-byte buffers instead also avoids the loss but had to be
reverted as these devices do not send a zero-length packet when a
transfer is a multiple of the endpoint size, which could leave received
data stuck until more data arrived. See commit df7b16d1c00e ("Revert
"USB: serial: ch341: fix character loss at high transfer rates"").
Use 32 endpoint-sized read urbs instead, which gives 1 KiB of buffering
(about 11 ms at 921600 baud and 7 ms at 1500000 baud) without waiting
for short packets. This is the same amount as cdc-acm, which uses 16
urbs of twice the endpoint size.
With bursts of 32 to 128 bytes followed by a pause, 512-byte buffers
held the data back for 200 to 800 ms, until a burst ended with a short
packet, while endpoint-sized urbs delivered every burst as quickly as
the stock driver.
With this, nothing was lost in the setups above, in two runs on the
Raspberry Pi and in five runs on x86 (two at 921600 baud and three at
1500000 baud), nor in three x86 runs with continuous traffic through the
bridge at 1500000 baud. With 16 urbs the x86 setup still lost 6 to 13
lines at 921600 baud and 237 to 279 lines at 1500000 baud. Note that at
1500000 baud the buffering is about the same as the largest gaps seen,
so there is little margin left at that rate.
This patch and its description were drafted with an AI assistant
(Claude) and reviewed and tested by me.
Cc: Willy Tarreau <w@1wt.eu>
Signed-off-by: Mateusz Sikora <ms1qaz@gmail.com>
---
drivers/usb/serial/ch341.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 569f4aede..c9ac114b8 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -868,6 +868,7 @@ static struct usb_serial_driver ch341_device = {
},
.id_table = id_table,
.num_ports = 1,
+ .num_read_urbs = 32,
.open = ch341_open,
.dtr_rts = ch341_dtr_rts,
.carrier_raised = ch341_carrier_raised,
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-12-06 0:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 0:18 [PATCH 0/2] USB: serial: ch341: fix character loss at high line speeds Mateusz Sikora
2026-12-06 0:18 ` [PATCH 1/2] USB: serial: allow drivers to use more read urbs Mateusz Sikora
2026-12-06 0:18 ` Mateusz Sikora [this message]
2026-12-06 0:32 ` [PATCH 2/2] USB: serial: ch341: " sashiko-bot
2026-12-06 0:32 ` [PATCH 0/2] USB: serial: ch341: fix character loss at high line speeds sashiko-bot
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=20261206001844.14858-3-ms1qaz@gmail.com \
--to=ms1qaz@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=w@1wt.eu \
/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.