Skip to contentSkip to conversation

tty: serial: imx: Add fast path when rs485 delays are 0

PATCH In review Harald Seiler 3 participants 8 messages Jan 19, 2022 – Feb 9, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty: serial: imx: Add fast path when rs485 delays are 0

Right now, even when delay_rts_before_send and delay_rts_after_send are 0, the hrtimer is triggered (with timeout 0) which can introduce a few 100us of additional overhead on slower i.MX platforms.

Implement a fast path when the delays are 0, where the RTS signal is toggled immediately instead of going through an hrtimer. This fast path behaves identical to the code before delay support was implemented.

---
 drivers/tty/serial/imx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/tty/serial/imx.c +14 -4
index df8a0c8b8b29..67bbbb69229d 100644
@@ -455,9 +455,14 @@ static void imx_uart_stop_tx(struct uart_port *port)
 	if (port->rs485.flags & SER_RS485_ENABLED) {
 		if (sport->tx_state == SEND) {
 			sport->tx_state = WAIT_AFTER_SEND;
-			start_hrtimer_ms(&sport->trigger_stop_tx,
+
+			if (port->rs485.delay_rts_after_send > 0) {
+				start_hrtimer_ms(&sport->trigger_stop_tx,
 					 port->rs485.delay_rts_after_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */
 		}
 
 		if (sport->tx_state == WAIT_AFTER_RTS ||
@@ -698,9 +703,14 @@ static void imx_uart_start_tx(struct uart_port *port)
 				imx_uart_stop_rx(port);
 
 			sport->tx_state = WAIT_AFTER_RTS;
-			start_hrtimer_ms(&sport->trigger_start_tx,
+
+			if (port->rs485.delay_rts_before_send > 0) {
+				start_hrtimer_ms(&sport->trigger_start_tx,
 					 port->rs485.delay_rts_before_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */
 		}
 
 		if (sport->tx_state == WAIT_AFTER_SEND
Signature · 1 line
2.34.1
#1 lore raw
Quoted 21 lines · Harald Seiler

Right now, even when delay_rts_before_send and delay_rts_after_send are 0, the hrtimer is triggered (with timeout 0) which can introduce a few 100us of additional overhead on slower i.MX platforms.

Implement a fast path when the delays are 0, where the RTS signal is toggled immediately instead of going through an hrtimer. This fast path behaves identical to the code before delay support was implemented.

---
 drivers/tty/serial/imx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/tty/serial/imx.c +0 -0
index df8a0c8b8b29..67bbbb69229d 100644
@@ -455,9 +455,14 @@ static void imx_uart_stop_tx(struct uart_port *port)
 	if (port->rs485.flags & SER_RS485_ENABLED) {
 		if (sport->tx_state == SEND) {
 			sport->tx_state = WAIT_AFTER_SEND;

drivers/tty/serial/imx.c static void imx_uart_stop_tx(struct uart_port *port) · line 465

Quoted 10 lines
drivers/tty/serial/imx.c +7 -2
-			start_hrtimer_ms(&sport->trigger_stop_tx,
+
+			if (port->rs485.delay_rts_after_send > 0) {
+				start_hrtimer_ms(&sport->trigger_stop_tx,
 					 port->rs485.delay_rts_after_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */

Is it right to keep the assignment sport->tx_state = WAIT_AFTER_SEND ?

Quoted 7 lines
drivers/tty/serial/imx.c +0 -0
 		}
 
 		if (sport->tx_state == WAIT_AFTER_RTS ||
@@ -698,9 +703,14 @@ static void imx_uart_start_tx(struct uart_port *port)
 				imx_uart_stop_rx(port);
 
 			sport->tx_state = WAIT_AFTER_RTS;

drivers/tty/serial/imx.c static void imx_uart_start_tx(struct uart_port *port) · line 713

Quoted 10 lines
drivers/tty/serial/imx.c +7 -2
-			start_hrtimer_ms(&sport->trigger_start_tx,
+
+			if (port->rs485.delay_rts_before_send > 0) {
+				start_hrtimer_ms(&sport->trigger_start_tx,
 					 port->rs485.delay_rts_before_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */

Here similar question here about sport->tx_state = WAIT_AFTER_RTS;

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#2 lore raw

Hi,

Quoted 26 lines · Uwe Kleine-König
Quoted 25 lines · Harald Seiler

Right now, even when delay_rts_before_send and delay_rts_after_send are 0, the hrtimer is triggered (with timeout 0) which can introduce a few 100us of additional overhead on slower i.MX platforms.

Implement a fast path when the delays are 0, where the RTS signal is toggled immediately instead of going through an hrtimer. This fast path behaves identical to the code before delay support was implemented.

---
 drivers/tty/serial/imx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/tty/serial/imx.c +3 -1
index df8a0c8b8b29..67bbbb69229d 100644
@@ -455,9 +455,14 @@ static void imx_uart_stop_tx(struct uart_port *port)
 	if (port->rs485.flags & SER_RS485_ENABLED) {
 		if (sport->tx_state == SEND) {
 			sport->tx_state = WAIT_AFTER_SEND;
-			start_hrtimer_ms(&sport->trigger_stop_tx,
+
+			if (port->rs485.delay_rts_after_send > 0) {
+				start_hrtimer_ms(&sport->trigger_stop_tx,
Quoted 8 lines

drivers/tty/serial/imx.c static void imx_uart_stop_tx(struct uart_port *port) · line 465

Quoted 6 lines
drivers/tty/serial/imx.c +4 -1
 					 port->rs485.delay_rts_after_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */

Is it right to keep the assignment sport->tx_state = WAIT_AFTER_SEND ?

I am keeping the assignment intentionally, to fall into the if(state == WAIT_AFTER_RTS) below (which then sets the state to OFF). I originally had the code structured like this:

	if (port->rs485.delay_rts_after_send > 0) {
		sport->tx_state = WAIT_AFTER_SEND;
		start_hrtimer_ms(&sport->trigger_stop_tx,
			 port->rs485.delay_rts_after_send);
		return;
	} else {
		/* continue without any delay */
		sport->tx_state = WAIT_AFTER_SEND;
	}

This is functionally identical, but maybe a bit more explicit.

Not sure what is more clear to read?

Quoted 6 lines
Quoted 6 lines
drivers/tty/serial/imx.c +0 -0
 		}
 
 		if (sport->tx_state == WAIT_AFTER_RTS ||
@@ -698,9 +703,14 @@ static void imx_uart_start_tx(struct uart_port *port)
 				imx_uart_stop_rx(port);
 
Quoted 13 lines

drivers/tty/serial/imx.c static void imx_uart_start_tx(struct uart_port *port) · line 713

Quoted 11 lines
drivers/tty/serial/imx.c +7 -2
 			sport->tx_state = WAIT_AFTER_RTS;
-			start_hrtimer_ms(&sport->trigger_start_tx,
+
+			if (port->rs485.delay_rts_before_send > 0) {
+				start_hrtimer_ms(&sport->trigger_start_tx,
 					 port->rs485.delay_rts_before_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */

Here similar question here about sport->tx_state = WAIT_AFTER_RTS;

Same as above, but with WAIT_AFTER_RTS of course...

Signature · 1 line
Harald
#3 lore raw
Quoted 52 lines · Harald Seiler

Hi,

Quoted 26 lines · Uwe Kleine-König
Quoted 25 lines · Harald Seiler

Right now, even when delay_rts_before_send and delay_rts_after_send are 0, the hrtimer is triggered (with timeout 0) which can introduce a few 100us of additional overhead on slower i.MX platforms.

Implement a fast path when the delays are 0, where the RTS signal is toggled immediately instead of going through an hrtimer. This fast path behaves identical to the code before delay support was implemented.

---
 drivers/tty/serial/imx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/tty/serial/imx.c +3 -1
index df8a0c8b8b29..67bbbb69229d 100644
@@ -455,9 +455,14 @@ static void imx_uart_stop_tx(struct uart_port *port)
 	if (port->rs485.flags & SER_RS485_ENABLED) {
 		if (sport->tx_state == SEND) {
 			sport->tx_state = WAIT_AFTER_SEND;
-			start_hrtimer_ms(&sport->trigger_stop_tx,
+
+			if (port->rs485.delay_rts_after_send > 0) {
+				start_hrtimer_ms(&sport->trigger_stop_tx,
Quoted 8 lines

drivers/tty/serial/imx.c static void imx_uart_stop_tx(struct uart_port *port) · line 465

Quoted 6 lines
drivers/tty/serial/imx.c +4 -1
 					 port->rs485.delay_rts_after_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */

Is it right to keep the assignment sport->tx_state = WAIT_AFTER_SEND ?

I am keeping the assignment intentionally, to fall into the if(state == WAIT_AFTER_RTS) below (which then sets the state to OFF). I originally had the code structured like this:

	if (port->rs485.delay_rts_after_send > 0) {
		sport->tx_state = WAIT_AFTER_SEND;
		start_hrtimer_ms(&sport->trigger_stop_tx,
			 port->rs485.delay_rts_after_send);
		return;
	} else {
		/* continue without any delay */
		sport->tx_state = WAIT_AFTER_SEND;
	}
Quoted 3 lines

This is functionally identical, but maybe a bit more explicit.

Not sure what is more clear to read?

I didn't oppose to the readability thing. With your patch you skip starting the stop_tx timer and that would usually care for calling imx_uart_stop_tx and setting sport->tx_state = OFF. This doesn't happen with your patch any more.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#4 lore raw

Hi,

Quoted 53 lines · Uwe Kleine-König
Quoted 52 lines · Harald Seiler

Hi,

Quoted 26 lines · Uwe Kleine-König
Quoted 25 lines · Harald Seiler

Right now, even when delay_rts_before_send and delay_rts_after_send are 0, the hrtimer is triggered (with timeout 0) which can introduce a few 100us of additional overhead on slower i.MX platforms.

Implement a fast path when the delays are 0, where the RTS signal is toggled immediately instead of going through an hrtimer. This fast path behaves identical to the code before delay support was implemented.

---
 drivers/tty/serial/imx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/tty/serial/imx.c +3 -1
index df8a0c8b8b29..67bbbb69229d 100644
@@ -455,9 +455,14 @@ static void imx_uart_stop_tx(struct uart_port *port)
 	if (port->rs485.flags & SER_RS485_ENABLED) {
 		if (sport->tx_state == SEND) {
 			sport->tx_state = WAIT_AFTER_SEND;
-			start_hrtimer_ms(&sport->trigger_stop_tx,
+
+			if (port->rs485.delay_rts_after_send > 0) {
+				start_hrtimer_ms(&sport->trigger_stop_tx,
Quoted 8 lines

drivers/tty/serial/imx.c static void imx_uart_stop_tx(struct uart_port *port) · line 465

Quoted 6 lines
drivers/tty/serial/imx.c +4 -1
 					 port->rs485.delay_rts_after_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */

Is it right to keep the assignment sport->tx_state = WAIT_AFTER_SEND ?

I am keeping the assignment intentionally, to fall into the if(state == WAIT_AFTER_RTS) below (which then sets the state to OFF). I originally had the code structured like this:

	if (port->rs485.delay_rts_after_send > 0) {
		sport->tx_state = WAIT_AFTER_SEND;
		start_hrtimer_ms(&sport->trigger_stop_tx,
			 port->rs485.delay_rts_after_send);
		return;
	} else {
		/* continue without any delay */
		sport->tx_state = WAIT_AFTER_SEND;
	}
Quoted 8 lines
Quoted 3 lines

This is functionally identical, but maybe a bit more explicit.

Not sure what is more clear to read?

I didn't oppose to the readability thing. With your patch you skip starting the stop_tx timer and that would usually care for calling imx_uart_stop_tx and setting sport->tx_state = OFF. This doesn't happen with your patch any more.

Not starting the timer is the entire point of the patch - instead, the code which would run inside the timer callback now runs immediately. To do this, I set the tx_state to WAIT_AFTER_SEND and _don't_ do the early return which leads into the if(tx_state == WAIT_AFTER_SEND) below. This is the code-path which normally runs later in the hrtimer callback.

I suppose it would have been good to provide more context lines in the patch... Here is the relevant bit (in the changed version now):

	if (sport->tx_state == SEND) {
		sport->tx_state = WAIT_AFTER_SEND;

		if (port->rs485.delay_rts_after_send > 0) {
			start_hrtimer_ms(&sport->trigger_stop_tx,
				 port->rs485.delay_rts_after_send);
			return;
		}

		/* continue without any delay */
	}

	if (sport->tx_state == WAIT_AFTER_RTS ||
	    sport->tx_state == WAIT_AFTER_SEND) {
		/* ... actual rts toggling ... */

		sport->tx_state = OFF;
	}

Regards,

Signature · 1 line
Harald
#5 lore raw
Quoted 84 lines · Harald Seiler

Hi,

Quoted 53 lines · Uwe Kleine-König
Quoted 52 lines · Harald Seiler

Hi,

Quoted 26 lines · Uwe Kleine-König
Quoted 25 lines · Harald Seiler

Right now, even when delay_rts_before_send and delay_rts_after_send are 0, the hrtimer is triggered (with timeout 0) which can introduce a few 100us of additional overhead on slower i.MX platforms.

Implement a fast path when the delays are 0, where the RTS signal is toggled immediately instead of going through an hrtimer. This fast path behaves identical to the code before delay support was implemented.

---
 drivers/tty/serial/imx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/tty/serial/imx.c +3 -1
index df8a0c8b8b29..67bbbb69229d 100644
@@ -455,9 +455,14 @@ static void imx_uart_stop_tx(struct uart_port *port)
 	if (port->rs485.flags & SER_RS485_ENABLED) {
 		if (sport->tx_state == SEND) {
 			sport->tx_state = WAIT_AFTER_SEND;
-			start_hrtimer_ms(&sport->trigger_stop_tx,
+
+			if (port->rs485.delay_rts_after_send > 0) {
+				start_hrtimer_ms(&sport->trigger_stop_tx,
Quoted 8 lines

drivers/tty/serial/imx.c static void imx_uart_stop_tx(struct uart_port *port) · line 465

Quoted 6 lines
drivers/tty/serial/imx.c +4 -1
 					 port->rs485.delay_rts_after_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */

Is it right to keep the assignment sport->tx_state = WAIT_AFTER_SEND ?

I am keeping the assignment intentionally, to fall into the if(state == WAIT_AFTER_RTS) below (which then sets the state to OFF). I originally had the code structured like this:

	if (port->rs485.delay_rts_after_send > 0) {
		sport->tx_state = WAIT_AFTER_SEND;
		start_hrtimer_ms(&sport->trigger_stop_tx,
			 port->rs485.delay_rts_after_send);
		return;
	} else {
		/* continue without any delay */
		sport->tx_state = WAIT_AFTER_SEND;
	}
Quoted 8 lines
Quoted 3 lines

This is functionally identical, but maybe a bit more explicit.

Not sure what is more clear to read?

I didn't oppose to the readability thing. With your patch you skip starting the stop_tx timer and that would usually care for calling imx_uart_stop_tx and setting sport->tx_state = OFF. This doesn't happen with your patch any more.

Not starting the timer is the entire point of the patch - instead, the code which would run inside the timer callback now runs immediately. To do this, I set the tx_state to WAIT_AFTER_SEND and _don't_ do the early return which leads into the if(tx_state == WAIT_AFTER_SEND) below. This is the code-path which normally runs later in the hrtimer callback.

I suppose it would have been good to provide more context lines in the patch... Here is the relevant bit (in the changed version now):

	if (sport->tx_state == SEND) {
		sport->tx_state = WAIT_AFTER_SEND;

		if (port->rs485.delay_rts_after_send > 0) {
			start_hrtimer_ms(&sport->trigger_stop_tx,
				 port->rs485.delay_rts_after_send);
			return;
		}

		/* continue without any delay */
Quoted 9 lines
	}

	if (sport->tx_state == WAIT_AFTER_RTS ||
	    sport->tx_state == WAIT_AFTER_SEND) {
		/* ... actual rts toggling ... */

		sport->tx_state = OFF;
	}

Uwe, any thoughts about if this patch should be taken or not?

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw

Hello Greg,

Quoted 89 lines · Greg Kroah-Hartman
Quoted 88 lines · Harald Seiler
Quoted 53 lines · Uwe Kleine-König
Quoted 52 lines · Harald Seiler

Hi,

Quoted 26 lines · Uwe Kleine-König
Quoted 25 lines · Harald Seiler

Right now, even when delay_rts_before_send and delay_rts_after_send are 0, the hrtimer is triggered (with timeout 0) which can introduce a few 100us of additional overhead on slower i.MX platforms.

Implement a fast path when the delays are 0, where the RTS signal is toggled immediately instead of going through an hrtimer. This fast path behaves identical to the code before delay support was implemented.

---
 drivers/tty/serial/imx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/tty/serial/imx.c +3 -1
index df8a0c8b8b29..67bbbb69229d 100644
@@ -455,9 +455,14 @@ static void imx_uart_stop_tx(struct uart_port *port)
 	if (port->rs485.flags & SER_RS485_ENABLED) {
 		if (sport->tx_state == SEND) {
 			sport->tx_state = WAIT_AFTER_SEND;
-			start_hrtimer_ms(&sport->trigger_stop_tx,
+
+			if (port->rs485.delay_rts_after_send > 0) {
+				start_hrtimer_ms(&sport->trigger_stop_tx,
Quoted 8 lines

drivers/tty/serial/imx.c static void imx_uart_stop_tx(struct uart_port *port) · line 465

Quoted 6 lines
drivers/tty/serial/imx.c +4 -1
 					 port->rs485.delay_rts_after_send);
-			return;
+				return;
+			}
+
+			/* continue without any delay */

Is it right to keep the assignment sport->tx_state = WAIT_AFTER_SEND ?

I am keeping the assignment intentionally, to fall into the if(state == WAIT_AFTER_RTS) below (which then sets the state to OFF). I originally had the code structured like this:

	if (port->rs485.delay_rts_after_send > 0) {
		sport->tx_state = WAIT_AFTER_SEND;
		start_hrtimer_ms(&sport->trigger_stop_tx,
			 port->rs485.delay_rts_after_send);
		return;
	} else {
		/* continue without any delay */
		sport->tx_state = WAIT_AFTER_SEND;
	}
Quoted 8 lines
Quoted 3 lines

This is functionally identical, but maybe a bit more explicit.

Not sure what is more clear to read?

I didn't oppose to the readability thing. With your patch you skip starting the stop_tx timer and that would usually care for calling imx_uart_stop_tx and setting sport->tx_state = OFF. This doesn't happen with your patch any more.

Not starting the timer is the entire point of the patch - instead, the code which would run inside the timer callback now runs immediately. To do this, I set the tx_state to WAIT_AFTER_SEND and _don't_ do the early return which leads into the if(tx_state == WAIT_AFTER_SEND) below. This is the code-path which normally runs later in the hrtimer callback.

I suppose it would have been good to provide more context lines in the patch... Here is the relevant bit (in the changed version now):

	if (sport->tx_state == SEND) {
		sport->tx_state = WAIT_AFTER_SEND;

		if (port->rs485.delay_rts_after_send > 0) {
			start_hrtimer_ms(&sport->trigger_stop_tx,
				 port->rs485.delay_rts_after_send);
			return;
		}

		/* continue without any delay */
	}

	if (sport->tx_state == WAIT_AFTER_RTS ||
	    sport->tx_state == WAIT_AFTER_SEND) {
		/* ... actual rts toggling ... */
Quoted 5 lines
Quoted 3 lines
		sport->tx_state = OFF;
	}

Uwe, any thoughts about if this patch should be taken or not?

I will take a deeper look later today and tell you my thoughts.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by
#7 lore raw

Hello Greg,

Quoted 4 lines · Uwe Kleine-König
Quoted 1 line · Greg Kroah-Hartman

Uwe, any thoughts about if this patch should be taken or not?

I will take a deeper look later today and tell you my thoughts.

It took a bit longer, but after looking again with the driver open in my editor I agree that patch is fine.

Thanks
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |