Currently, there are 7 checks for whether to enable
the internal fifo device of a 8250/16550 type uart.
Instead of checking all 7 values again whenever
we need to know whether we have the fifo device enabled,
store the result as a struct member of uart_8250_port.
This can, for example, lessen the amount
of calculations done during a write operation.
Signed-off-by: Michael Pratt <mcpratt@pm.me>
---
V1 -> V2: new commit
drivers/tty/serial/8250/8250_port.c | 2 ++
include/linux/serial_8250.h | 1 +
2 files changed, 3 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index fc9dd5d45295..5b0cfe6bc98c 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -3392,6 +3392,8 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s,
*/
!(up->port.flags & UPF_CONS_FLOW);
+ up->fifo_enable = use_fifo;
+
if (likely(use_fifo))
serial8250_console_fifo_write(up, s, count);
else
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index fd59ed2cca53..017429f0e743 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -127,6 +127,7 @@ struct uart_8250_port {
struct list_head list; /* ports on this IRQ */
u32 capabilities; /* port capabilities */
u16 bugs; /* port bugs */
+ unsigned int fifo_enable; /* fifo enabled if capable */
unsigned int tx_loadsz; /* transmit fifo load size */
unsigned char acr;
unsigned char fcr;
--
2.30.2
On Tue, Apr 16, 2024 at 06:29:56PM +0000, Michael Pratt wrote: > Currently, there are 7 checks for whether to enable > the internal fifo device of a 8250/16550 type uart. > > Instead of checking all 7 values again whenever > we need to know whether we have the fifo device enabled, > store the result as a struct member of uart_8250_port. > > This can, for example, lessen the amount > of calculations done during a write operation. ... > @@ -3392,6 +3392,8 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s, > + up->fifo_enable = use_fifo; This seems incorrect / not the only one place to assign this. What if the console not enabled at compile time? What if it's not enabled at boot time? -- With Best Regards, Andy Shevchenko
Hi Andy, On Tuesday, April 16th, 2024 at 14:55, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > > @@ -3392,6 +3392,8 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s, > > > + up->fifo_enable = use_fifo; > > > This seems incorrect / not the only one place to assign this. What if the > console not enabled at compile time? What if it's not enabled at boot time? > This is 8250 specific, and currently, it's the only place there where it's decided whether or not to use the fifo device by checking a bunch of flags and values. If you're suggesting that these checks are moved out of this function somewhere else, I would probably agree with that, but let's save that idea for the future... If you're suggesting that there could be a null pointer, I don't think that's possible in this function... (the name of the pointer being "up" might be confusing?) Sorry if I'm misunderstanding what you mean. > -- > With Best Regards, > Andy Shevchenko -- MCP
On Tue, Apr 16, 2024 at 07:09:52PM +0000, Michael Pratt wrote: > On Tuesday, April 16th, 2024 at 14:55, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > > @@ -3392,6 +3392,8 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s, > > > > > + up->fifo_enable = use_fifo; > > > > This seems incorrect / not the only one place to assign this. What if the > > console not enabled at compile time? What if it's not enabled at boot time? > > This is 8250 specific, and currently, it's the only place there > where it's decided whether or not to use the fifo device > by checking a bunch of flags and values. Exactly, as initial commit is related to the kernel console _only_. While your code, IIUC (correct me, if I'm wrong) is for any use of the port. > If you're suggesting that these checks are moved out of this function somewhere else, > I would probably agree with that, but let's save that idea for the future... Not really (again, IIUC above), as console can be not enabled, and hence serial8250_console_write() never been called and you will have false impression that there is no FIFO in use. > If you're suggesting that there could be a null pointer, I don't think that's possible > in this function... (the name of the pointer being "up" might be confusing?) > > Sorry if I'm misunderstanding what you mean. -- With Best Regards, Andy Shevchenko
Hi Andy, On Tuesday, April 16th, 2024 at 15:18, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > > On Tue, Apr 16, 2024 at 07:09:52PM +0000, Michael Pratt wrote: > > > On Tuesday, April 16th, 2024 at 14:55, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote: > > > > > @@ -3392,6 +3392,8 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s, > > > > > > > + up->fifo_enable = use_fifo; > > > > > > This seems incorrect / not the only one place to assign this. What if the > > > console not enabled at compile time? What if it's not enabled at boot time? > > > > This is 8250 specific, and currently, it's the only place there > > where it's decided whether or not to use the fifo device > > by checking a bunch of flags and values. > > > Exactly, as initial commit is related to the kernel console only. > While your code, IIUC (correct me, if I'm wrong) is for any use of the port. > > > If you're suggesting that these checks are moved out of this function somewhere else, > > I would probably agree with that, but let's save that idea for the future... > > > Not really (again, IIUC above), as console can be not enabled, and hence > serial8250_console_write() never been called and you will have false impression > that there is no FIFO in use. Ah ok, I understand now... So there are cases where the function with the checks will never be called, yet the device itself will be configured the same way and the struct member I am adding will still be instantiated with value of 0 and never be set elsewhere... and because it is declared in a major struct "uart_8250_port", it appears to apply to a larger scope compared to the way it is actually being used... (or at the very least, the name "fifo_enable" would be misleading). Thanks for pointing that out, I'll take a deeper dive into the file... > > -- > With Best Regards, > Andy Shevchenko -- MCP
© 2016 - 2025 Red Hat, Inc.