2022-04-18 05:46:32

by Maciej W. Rozycki

[permalink] [raw]
Subject: [PATCH v4 3/5] serial: 8250: Export ICR access helpers for internal use

Make ICR access helpers available outside 8250_port.c, however retain
them as ordinary static functions so as not to regress code generation.

This is because `serial_icr_write' is currently automatically inlined by
GCC, however `serial_icr_read' is not. Making them both static inline
would grow code produced, e.g.:

$ i386-linux-gnu-size --format=gnu 8250_port-{old,new}.o
text data bss total filename
15065 3378 0 18443 8250_port-old.o
15289 3378 0 18667 8250_port-new.o

and:

$ riscv64-linux-gnu-size --format=gnu 8250_port-{old,new}.o
text data bss total filename
16980 5306 0 22286 8250_port-old.o
17124 5306 0 22430 8250_port-new.o

while making them external would needlessly add a new module interface
and lose the benefit from `serial_icr_write' getting inlined outside
8250_port.o.

Signed-off-by: Maciej W. Rozycki <[email protected]>
---
New change in v4, factored out from 5/5.
---
drivers/tty/serial/8250/8250.h | 23 +++++++++++++++++++++++
drivers/tty/serial/8250/8250_port.c | 21 ---------------------
2 files changed, 23 insertions(+), 21 deletions(-)

linux-serial-8250-icr-access.diff
Index: linux-macro/drivers/tty/serial/8250/8250.h
===================================================================
--- linux-macro.orig/drivers/tty/serial/8250/8250.h
+++ linux-macro/drivers/tty/serial/8250/8250.h
@@ -120,6 +120,29 @@ static inline void serial_out(struct uar
up->port.serial_out(&up->port, offset, value);
}

+/*
+ * For the 16C950
+ */
+static void __maybe_unused serial_icr_write(struct uart_8250_port *up,
+ int offset, int value)
+{
+ serial_out(up, UART_SCR, offset);
+ serial_out(up, UART_ICR, value);
+}
+
+static unsigned int __maybe_unused serial_icr_read(struct uart_8250_port *up,
+ int offset)
+{
+ unsigned int value;
+
+ serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
+ serial_out(up, UART_SCR, offset);
+ value = serial_in(up, UART_ICR);
+ serial_icr_write(up, UART_ACR, up->acr);
+
+ return value;
+}
+
void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);

static inline int serial_dl_read(struct uart_8250_port *up)
Index: linux-macro/drivers/tty/serial/8250/8250_port.c
===================================================================
--- linux-macro.orig/drivers/tty/serial/8250/8250_port.c
+++ linux-macro/drivers/tty/serial/8250/8250_port.c
@@ -538,27 +538,6 @@ serial_port_out_sync(struct uart_port *p
}

/*
- * For the 16C950
- */
-static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
-{
- serial_out(up, UART_SCR, offset);
- serial_out(up, UART_ICR, value);
-}
-
-static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
-{
- unsigned int value;
-
- serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
- serial_out(up, UART_SCR, offset);
- value = serial_in(up, UART_ICR);
- serial_icr_write(up, UART_ACR, up->acr);
-
- return value;
-}
-
-/*
* FIFO support.
*/
static void serial8250_clear_fifos(struct uart_8250_port *p)


2022-04-18 14:49:18

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v4 3/5] serial: 8250: Export ICR access helpers for internal use

On Mon, Apr 18, 2022 at 2:02 AM Maciej W. Rozycki <[email protected]> wrote:
>
> Make ICR access helpers available outside 8250_port.c, however retain
> them as ordinary static functions so as not to regress code generation.
>
> This is because `serial_icr_write' is currently automatically inlined by
> GCC, however `serial_icr_read' is not. Making them both static inline
> would grow code produced, e.g.:
>
> $ i386-linux-gnu-size --format=gnu 8250_port-{old,new}.o
> text data bss total filename
> 15065 3378 0 18443 8250_port-old.o
> 15289 3378 0 18667 8250_port-new.o
>
> and:
>
> $ riscv64-linux-gnu-size --format=gnu 8250_port-{old,new}.o
> text data bss total filename
> 16980 5306 0 22286 8250_port-old.o
> 17124 5306 0 22430 8250_port-new.o
>
> while making them external would needlessly add a new module interface
> and lose the benefit from `serial_icr_write' getting inlined outside
> 8250_port.o.

Reviewed-by: Andy Shevchenko <[email protected]>
See one nit-pick below.

> Signed-off-by: Maciej W. Rozycki <[email protected]>
> ---
> New change in v4, factored out from 5/5.
> ---
> drivers/tty/serial/8250/8250.h | 23 +++++++++++++++++++++++
> drivers/tty/serial/8250/8250_port.c | 21 ---------------------
> 2 files changed, 23 insertions(+), 21 deletions(-)
>
> linux-serial-8250-icr-access.diff
> Index: linux-macro/drivers/tty/serial/8250/8250.h
> ===================================================================
> --- linux-macro.orig/drivers/tty/serial/8250/8250.h
> +++ linux-macro/drivers/tty/serial/8250/8250.h
> @@ -120,6 +120,29 @@ static inline void serial_out(struct uar
> up->port.serial_out(&up->port, offset, value);
> }
>
> +/*
> + * For the 16C950
> + */
> +static void __maybe_unused serial_icr_write(struct uart_8250_port *up,
> + int offset, int value)

I think you may drop __maybe_unused here, because it's always used by
the code below. So it will be eliminated altogether when the below
won't be used.

> +{
> + serial_out(up, UART_SCR, offset);
> + serial_out(up, UART_ICR, value);
> +}
> +
> +static unsigned int __maybe_unused serial_icr_read(struct uart_8250_port *up,
> + int offset)
> +{
> + unsigned int value;
> +
> + serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
> + serial_out(up, UART_SCR, offset);
> + value = serial_in(up, UART_ICR);
> + serial_icr_write(up, UART_ACR, up->acr);
> +
> + return value;
> +}
> +
> void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);
>
> static inline int serial_dl_read(struct uart_8250_port *up)
> Index: linux-macro/drivers/tty/serial/8250/8250_port.c
> ===================================================================
> --- linux-macro.orig/drivers/tty/serial/8250/8250_port.c
> +++ linux-macro/drivers/tty/serial/8250/8250_port.c
> @@ -538,27 +538,6 @@ serial_port_out_sync(struct uart_port *p
> }
>
> /*
> - * For the 16C950
> - */
> -static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
> -{
> - serial_out(up, UART_SCR, offset);
> - serial_out(up, UART_ICR, value);
> -}
> -
> -static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
> -{
> - unsigned int value;
> -
> - serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
> - serial_out(up, UART_SCR, offset);
> - value = serial_in(up, UART_ICR);
> - serial_icr_write(up, UART_ACR, up->acr);
> -
> - return value;
> -}
> -
> -/*
> * FIFO support.
> */
> static void serial8250_clear_fifos(struct uart_8250_port *p)



--
With Best Regards,
Andy Shevchenko

2022-04-19 10:28:01

by Maciej W. Rozycki

[permalink] [raw]
Subject: Re: [PATCH v4 3/5] serial: 8250: Export ICR access helpers for internal use

On Mon, 18 Apr 2022, Andy Shevchenko wrote:

> > Index: linux-macro/drivers/tty/serial/8250/8250.h
> > ===================================================================
> > --- linux-macro.orig/drivers/tty/serial/8250/8250.h
> > +++ linux-macro/drivers/tty/serial/8250/8250.h
> > @@ -120,6 +120,29 @@ static inline void serial_out(struct uar
> > up->port.serial_out(&up->port, offset, value);
> > }
> >
> > +/*
> > + * For the 16C950
> > + */
> > +static void __maybe_unused serial_icr_write(struct uart_8250_port *up,
> > + int offset, int value)
>
> I think you may drop __maybe_unused here, because it's always used by
> the code below. So it will be eliminated altogether when the below
> won't be used.

Right, the absence of this annotation doesn't cause GCC to complain about
sources that define this function but do not make use of it, so I have
removed the atttribute in v5.

Maciej