* [PATCH] serial: rsci: Clear TDRE once per TX FIFO refill
@ 2026-11-27 13:40 Diogo Ivo
2026-11-27 13:47 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Diogo Ivo @ 2026-11-27 13:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Cosmin Tanislav, linux-kernel, linux-serial, linux-renesas-soc,
Diogo Ivo
rsci_transmit_chars() clears TDRE before each write to TDR, going
against what is stated in Figure 7.3-17 of section 7.3.3.8 (Serial
Data Transmission (Asynchronous Mode)), FIFO mode, of the RZ/G3L
hardware manual:
To continue serial transmission, write all transmit data to
the transmit FIFO (TDR) by using a TXI interrupt and clear
TDRE flag to 0.
This leads to two problems: (a) up to (FIFO_SIZE - 1) unnecessary MMIO
writes to clear TDRE that take a significant amount of time in interrupt
context and (b) a second TXI interrupt is generated while the first is
being handled. This is described in the RZ/G3L hardware manual in section
7.3.2.2.18 (Common Status Register), under the TDRE bit,
When the condition which becomes 1b and the condition which becomes 0b
were formed at the same time, TDRE flag will be 0b. After that, when the
number of data stored in transmit FIFO is judged, and if that is equal to
or less than TTRG value, TDRE is set to 1b after 1b RSCI_m_PCLK.
meaning that if we clear TDRE while the FIFO is still empty TDRE can
reassert and trigger another TXI. This was observed on a test on RZ/G3L:
clearing TDRE with an empty FIFO made another TXI pending.
Fix both issues by writing the batch to TDR before clearing TDRE. If no
bytes were written leave TDRE alone.
A test on an RZ/G3L platform (FIFO_SIZE = 32) sending 64KiB of data led
to 4096 TXIs and around 159 ms spent servicing them without this patch.
With the patch the number of TXIs went down to the expected
(64KiB / 32) = 2048 which took around 86 ms in total.
Signed-off-by: Diogo Ivo <diogo.ivo.sx@renesas.com>
---
drivers/tty/serial/rsci.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c
index 80087be11808..e4704cb3b6c7 100644
--- a/drivers/tty/serial/rsci.c
+++ b/drivers/tty/serial/rsci.c
@@ -432,16 +432,16 @@ static void rsci_transmit_chars(struct uart_port *port)
{
unsigned int stopped = uart_tx_stopped(port);
struct tty_port *tport = &port->state->port;
+ unsigned int sent, room;
u32 status;
- int count;
status = rsci_serial_in(port, CSR);
if (!(status & CSR_TDRE))
return;
- count = rsci_txroom(port);
+ room = rsci_txroom(port);
- do {
+ for (sent = 0; sent < room; sent++) {
unsigned char c;
if (port->x_char) {
@@ -451,11 +451,13 @@ static void rsci_transmit_chars(struct uart_port *port)
break;
}
- rsci_clear_CFC(port, CFCLR_TDREC);
rsci_serial_out(port, TDR, c);
+ }
- port->icount.tx++;
- } while (--count > 0);
+ if (sent) {
+ rsci_clear_CFC(port, CFCLR_TDREC);
+ port->icount.tx += sent;
+ }
if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
uart_write_wakeup(port);
---
base-commit: 3d229ce89862b8e82d71a9e11d6f840ca272a6d6
change-id: 20261127-divo-ssgrlpcsrc-2996-rsci-txi-f8d8e461bde9
prerequisite-change-id: 20261020-g2ul_sci-b610606ea5b5:v5
prerequisite-patch-id: ed5f3ae4090037e6b4c6126e86b3a5ef1c6c1b44
prerequisite-patch-id: bec547271f9d220883db537de4c595fb9734d5ce
prerequisite-patch-id: fd136809f0c9d90c66f23b5165f59d3e50117928
prerequisite-patch-id: 498b88618f0dd6fcc63f671fde36edaf5cd0c811
prerequisite-patch-id: da7a159d3cd6376a17a9ab5edb91eb283574243b
prerequisite-patch-id: fd9ac71ffbbcc1aa106be6f923583a39342c7296
prerequisite-patch-id: 988f616382a3b4aedf191e097cc829b7be0546e1
Best regards,
--
Diogo Ivo <diogo.ivo.sx@renesas.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] serial: rsci: Clear TDRE once per TX FIFO refill
2026-11-27 13:40 [PATCH] serial: rsci: Clear TDRE once per TX FIFO refill Diogo Ivo
@ 2026-11-27 13:47 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-27 13:47 UTC (permalink / raw)
To: Diogo Ivo; +Cc: linux-serial
> rsci_transmit_chars() clears TDRE before each write to TDR, going
> against what is stated in Figure 7.3-17 of section 7.3.3.8 (Serial
> Data Transmission (Asynchronous Mode)), FIFO mode, of the RZ/G3L
> hardware manual:
>
> To continue serial transmission, write all transmit data to
> the transmit FIFO (TDR) by using a TXI interrupt and clear
> TDRE flag to 0.
>
> This leads to two problems: (a) up to (FIFO_SIZE - 1) unnecessary MMIO
> writes to clear TDRE that take a significant amount of time in interrupt
> context and (b) a second TXI interrupt is generated while the first is
> being handled. This is described in the RZ/G3L hardware manual in section
> 7.3.2.2.18 (Common Status Register), under the TDRE bit,
>
> [ ... ]
> to 4096 TXIs and around 159 ms spent servicing them without this patch.
> With the patch the number of TXIs went down to the expected
> (64KiB / 32) = 2048 which took around 86 ms in total.
>
> Signed-off-by: Diogo Ivo <diogo.ivo.sx@renesas.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-divo-ssgrlpcsrc-2996-rsci-txi-v1-1-88e1614ea0b8@renesas.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 13:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 13:40 [PATCH] serial: rsci: Clear TDRE once per TX FIFO refill Diogo Ivo
2026-11-27 13:47 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox