linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: 8250: Return early in .start_tx() if there are no chars to send
@ 2022-02-17 21:18 Uwe Kleine-König
  2022-02-22  8:20 ` Jiri Slaby
  2022-04-07 13:27 ` Tony Lindgren
  0 siblings, 2 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2022-02-17 21:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Johan Hovold
  Cc: linux-serial, kernel, Steffen Trumtrar

From: Steffen Trumtrar <s.trumtrar@pengutronix.de>

Don't start the whole chain for TX if there is no data to send. This is
mostly relevant for rs485 mode as there might be rts-before-send and
rts-after-send delays involved.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

a few other drivers have such an early exit already (imx, stm32-usart).
I wonder if it applies to all UART drivers that there is nothing to do
in .start_tx() if the circ buffer is empty and there is no x_char to
send. In this case it would be more sensible to ensure in serial_core
that .start_tx() is only ever called if there is something to do.

Best regards
Uwe

 drivers/tty/serial/8250/8250_port.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 3b12bfc1ed67..5d4668f12f71 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1657,6 +1657,9 @@ static void serial8250_start_tx(struct uart_port *port)
 
 	serial8250_rpm_get_tx(up);
 
+	if (!port->x_char && uart_circ_empty(&port->state->xmit))
+		return;
+
 	if (em485 &&
 	    em485->active_timer == &em485->start_tx_timer)
 		return;

base-commit: 754e0b0e35608ed5206d6a67a791563c631cec07
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] serial: 8250: Return early in .start_tx() if there are no chars to send
  2022-02-17 21:18 [PATCH] serial: 8250: Return early in .start_tx() if there are no chars to send Uwe Kleine-König
@ 2022-02-22  8:20 ` Jiri Slaby
  2022-04-07 13:27 ` Tony Lindgren
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2022-02-22  8:20 UTC (permalink / raw)
  To: Uwe Kleine-König, Greg Kroah-Hartman, Johan Hovold
  Cc: linux-serial, kernel, Steffen Trumtrar

On 17. 02. 22, 22:18, Uwe Kleine-König wrote:
> From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> 
> Don't start the whole chain for TX if there is no data to send. This is
> mostly relevant for rs485 mode as there might be rts-before-send and
> rts-after-send delays involved.
> 
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> a few other drivers have such an early exit already (imx, stm32-usart).
> I wonder if it applies to all UART drivers that there is nothing to do
> in .start_tx() if the circ buffer is empty and there is no x_char to
> send. In this case it would be more sensible to ensure in serial_core
> that .start_tx() is only ever called if there is something to do.

Not sure if all, but most yes. I have a series to add a TX helper which 
unifies those and removes all those cut&pasted code. It's not finished 
yet. Look at the top of:

https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/log/?h=devel

> Best regards
> Uwe
> 
>   drivers/tty/serial/8250/8250_port.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 3b12bfc1ed67..5d4668f12f71 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -1657,6 +1657,9 @@ static void serial8250_start_tx(struct uart_port *port)
>   
>   	serial8250_rpm_get_tx(up);
>   
> +	if (!port->x_char && uart_circ_empty(&port->state->xmit))
> +		return;
> +
>   	if (em485 &&
>   	    em485->active_timer == &em485->start_tx_timer)
>   		return;
> 
> base-commit: 754e0b0e35608ed5206d6a67a791563c631cec07


-- 
js
suse labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] serial: 8250: Return early in .start_tx() if there are no chars to send
  2022-02-17 21:18 [PATCH] serial: 8250: Return early in .start_tx() if there are no chars to send Uwe Kleine-König
  2022-02-22  8:20 ` Jiri Slaby
@ 2022-04-07 13:27 ` Tony Lindgren
  2022-04-11  9:56   ` Tony Lindgren
  1 sibling, 1 reply; 4+ messages in thread
From: Tony Lindgren @ 2022-04-07 13:27 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Greg Kroah-Hartman, Jiri Slaby, Johan Hovold, linux-serial,
	kernel, Steffen Trumtrar, linux-arm-kernel, linux-omap,
	regressions

Hi,

* Uwe Kleine-König <u.kleine-koenig@pengutronix.de> [700101 02:00]:
> From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> 
> Don't start the whole chain for TX if there is no data to send. This is
> mostly relevant for rs485 mode as there might be rts-before-send and
> rts-after-send delays involved.
> 
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> a few other drivers have such an early exit already (imx, stm32-usart).
> I wonder if it applies to all UART drivers that there is nothing to do
> in .start_tx() if the circ buffer is empty and there is no x_char to
> send. In this case it would be more sensible to ensure in serial_core
> that .start_tx() is only ever called if there is something to do.

This patch seems to cause a runtime PM regression in v5.18-rc1 where
8250 is never idled for omaps.

Looks like the return added here is not paired with put for the
serial8250_rpm_get_tx() call above?

Regards,

Tony

#regzbot ^introduced 932d596378b0

>  drivers/tty/serial/8250/8250_port.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 3b12bfc1ed67..5d4668f12f71 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -1657,6 +1657,9 @@ static void serial8250_start_tx(struct uart_port *port)
>  
>  	serial8250_rpm_get_tx(up);
>  
> +	if (!port->x_char && uart_circ_empty(&port->state->xmit))
> +		return;
> +
>  	if (em485 &&
>  	    em485->active_timer == &em485->start_tx_timer)
>  		return;
> 
> base-commit: 754e0b0e35608ed5206d6a67a791563c631cec07
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] serial: 8250: Return early in .start_tx() if there are no chars to send
  2022-04-07 13:27 ` Tony Lindgren
@ 2022-04-11  9:56   ` Tony Lindgren
  0 siblings, 0 replies; 4+ messages in thread
From: Tony Lindgren @ 2022-04-11  9:56 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Greg Kroah-Hartman, Jiri Slaby, Johan Hovold, linux-serial,
	kernel, Steffen Trumtrar, linux-arm-kernel, linux-omap,
	regressions

* Tony Lindgren <tony@atomide.com> [220407 13:25]:
> Hi,
> 
> * Uwe Kleine-König <u.kleine-koenig@pengutronix.de> [700101 02:00]:
> > From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> > 
> > Don't start the whole chain for TX if there is no data to send. This is
> > mostly relevant for rs485 mode as there might be rts-before-send and
> > rts-after-send delays involved.
> > 
> > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > ---
> > Hello,
> > 
> > a few other drivers have such an early exit already (imx, stm32-usart).
> > I wonder if it applies to all UART drivers that there is nothing to do
> > in .start_tx() if the circ buffer is empty and there is no x_char to
> > send. In this case it would be more sensible to ensure in serial_core
> > that .start_tx() is only ever called if there is something to do.
> 
> This patch seems to cause a runtime PM regression in v5.18-rc1 where
> 8250 is never idled for omaps.
> 
> Looks like the return added here is not paired with put for the
> serial8250_rpm_get_tx() call above?

FYI I just posted two fixes for these early return cases:

https://lore.kernel.org/linux-serial/20220411094805.45696-1-tony@atomide.com/T/#t

Regards,

Tony

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-11  9:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-17 21:18 [PATCH] serial: 8250: Return early in .start_tx() if there are no chars to send Uwe Kleine-König
2022-02-22  8:20 ` Jiri Slaby
2022-04-07 13:27 ` Tony Lindgren
2022-04-11  9:56   ` Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).