* [RFC PATCH] tty: serial: core: Only invoke ->start_tx() if there is data to send
@ 2014-09-10 19:33 Sebastian Andrzej Siewior
2014-09-10 19:52 ` Peter Hurley
0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2014-09-10 19:33 UTC (permalink / raw)
To: Jiri Slaby, Peter Hurley
Cc: Greg Kroah-Hartman, linux-serial, linux-kernel,
Sebastian Andrzej Siewior
I noticed that the serial8250_tx_dma() is invoked sometimes while
uart_circ_empty() says that the buffer is empty.
I tracked one occuring down to:
n_tty_write()
=> O_OPOST(tty))
=> the while loop did something but neither tty's ->write()
nor its ->uart_put_char() callback was invoked().
=> tty->ops->flush_chars() is invoked with an empty buffer.
For the 8250 uart driver we end up with:
- DMA enabled
nothing, just return (except there is DMA_TX bug or runtime-PM then we
behave like in the no DMA case)
- no DMA
enable THRI interrupt, wait for it, disable THRI interrupt again
because there is nothing to be done.
While I don't know if it safe to drop that flush in n_tty if the buffer
is empty, it should not do any harm in serial's core part to not invoke
->start_tx() if the buffer is empty.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
drivers/tty/serial/serial_core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 5a78f6940760..e55724a911d5 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -90,7 +90,8 @@ static void __uart_start(struct tty_struct *tty)
struct uart_state *state = tty->driver_data;
struct uart_port *port = state->uart_port;
- if (!tty->stopped && !tty->hw_stopped)
+ if (!tty->stopped && !tty->hw_stopped &&
+ !uart_circ_empty(&port->state->xmit))
port->ops->start_tx(port);
}
--
2.1.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] tty: serial: core: Only invoke ->start_tx() if there is data to send
2014-09-10 19:33 [RFC PATCH] tty: serial: core: Only invoke ->start_tx() if there is data to send Sebastian Andrzej Siewior
@ 2014-09-10 19:52 ` Peter Hurley
2014-09-11 8:03 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 4+ messages in thread
From: Peter Hurley @ 2014-09-10 19:52 UTC (permalink / raw)
To: Sebastian Andrzej Siewior, Jiri Slaby
Cc: Greg Kroah-Hartman, linux-serial, linux-kernel
On 09/10/2014 03:33 PM, Sebastian Andrzej Siewior wrote:
> I noticed that the serial8250_tx_dma() is invoked sometimes while
> uart_circ_empty() says that the buffer is empty.
>
> I tracked one occuring down to:
>
> n_tty_write()
> => O_OPOST(tty))
> => the while loop did something but neither tty's ->write()
> nor its ->uart_put_char() callback was invoked().
> => tty->ops->flush_chars() is invoked with an empty buffer.
>
> For the 8250 uart driver we end up with:
> - DMA enabled
> nothing, just return (except there is DMA_TX bug or runtime-PM then we
> behave like in the no DMA case)
>
> - no DMA
> enable THRI interrupt, wait for it, disable THRI interrupt again
> because there is nothing to be done.
>
> While I don't know if it safe to drop that flush in n_tty if the buffer
> is empty, it should not do any harm in serial's core part to not invoke
> ->start_tx() if the buffer is empty.
The serial core can't assume that start_tx() does not need invoking
because hardware that can stop_tx() with data in the transmitter
won't restart if the ring buffer is empty but data is still in the
transmitter. [Note that the 16C950 port type does this in the 8250 driver.]
So this has to be handled in the 8250 driver.
What is the actual issue? Are you trying not to unnecessarily wake
the omap hardware if runtime-PM is on?
Regards,
Peter Hurley
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> drivers/tty/serial/serial_core.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 5a78f6940760..e55724a911d5 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -90,7 +90,8 @@ static void __uart_start(struct tty_struct *tty)
> struct uart_state *state = tty->driver_data;
> struct uart_port *port = state->uart_port;
>
> - if (!tty->stopped && !tty->hw_stopped)
> + if (!tty->stopped && !tty->hw_stopped &&
> + !uart_circ_empty(&port->state->xmit))
> port->ops->start_tx(port);
> }
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] tty: serial: core: Only invoke ->start_tx() if there is data to send
2014-09-10 19:52 ` Peter Hurley
@ 2014-09-11 8:03 ` Sebastian Andrzej Siewior
2014-09-11 12:48 ` Peter Hurley
0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2014-09-11 8:03 UTC (permalink / raw)
To: Peter Hurley; +Cc: Jiri Slaby, Greg Kroah-Hartman, linux-serial, linux-kernel
On 09/10/2014 09:52 PM, Peter Hurley wrote:
> The serial core can't assume that start_tx() does not need invoking
> because hardware that can stop_tx() with data in the transmitter
> won't restart if the ring buffer is empty but data is still in the
> transmitter. [Note that the 16C950 port type does this in the 8250 driver.]
oh, not sure how I missed this… But now that I look at this, it is also
that ->x_char that could be use for flow control which would have to be
sent even with an empty xmit buffer.
And 8250 in DMA mode does not look at x_char at all. But it would be
better if it would, right? However if the TX side does a 2 KiB transfer
not sure what should be done…
> So this has to be handled in the 8250 driver.
>
> What is the actual issue? Are you trying not to unnecessarily wake
> the omap hardware if runtime-PM is on?
no, it is actually the extra interrupt for no reason that looked like
not needed at all. But I guess it is only during "startup" while the
init-script do fancy things and not during "normal" operations.
> Regards,
> Peter Hurley
Sebastian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] tty: serial: core: Only invoke ->start_tx() if there is data to send
2014-09-11 8:03 ` Sebastian Andrzej Siewior
@ 2014-09-11 12:48 ` Peter Hurley
0 siblings, 0 replies; 4+ messages in thread
From: Peter Hurley @ 2014-09-11 12:48 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: Jiri Slaby, Greg Kroah-Hartman, linux-serial, linux-kernel
On 09/11/2014 04:03 AM, Sebastian Andrzej Siewior wrote:
> On 09/10/2014 09:52 PM, Peter Hurley wrote:
>> The serial core can't assume that start_tx() does not need invoking
>> because hardware that can stop_tx() with data in the transmitter
>> won't restart if the ring buffer is empty but data is still in the
>> transmitter. [Note that the 16C950 port type does this in the 8250 driver.]
>
> oh, not sure how I missed this… But now that I look at this, it is also
> that ->x_char that could be use for flow control which would have to be
> sent even with an empty xmit buffer.
> And 8250 in DMA mode does not look at x_char at all. But it would be
> better if it would, right? However if the TX side does a 2 KiB transfer
> not sure what should be done…
Yeah, 8250 dma doesn't send x_char at all; at a minimum 8250 dma should
at least send the x_char.
The preferred solution is to:
1. Stop DMA
2. Enable interrupt mode, which will automatically send the x_char
3. Restart DMA (presumably from the interrupt handler if UART_LSR_THRE)
The issue is whether 8250 dma hardware in general can stop and restart
dma without losing where the dma transfer was.
Regards,
Peter Hurley
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-09-11 12:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-10 19:33 [RFC PATCH] tty: serial: core: Only invoke ->start_tx() if there is data to send Sebastian Andrzej Siewior
2014-09-10 19:52 ` Peter Hurley
2014-09-11 8:03 ` Sebastian Andrzej Siewior
2014-09-11 12:48 ` Peter Hurley
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).