serial: amba-pl011: drop redundant BUSY wait from earlycon pl011_putc()
PATCH 1/1 serial: amba-pl011: drop redundant BUSY wait from earlycon pl011_putc()
pl011_putc(), used exclusively by the pl011 earlycon (pl011_early_write() -> uart_console_write()), waits for UART01x_FR_TXFF to clear before writing a character (correct: don't overrun the TX FIFO) and then *also* busy-waits for UART01x_FR_BUSY to clear before returning, i.e. it waits for the character to be fully shifted out on the wire before the next character in the string can even be considered.
This second wait is not required for correctness and is inconsistent with the rest of this same driver: both pl011_console_putchar() (the regular, always-built console write path used by every printk() once the full driver is up) and pl011_put_poll_char() (kgdb/kdb polling I/O) only wait for TXFF before writing and never wait for BUSY afterwards. pl011_putc() is the only one of the three that serializes on BUSY, and it is the one exercised the most heavily, since it backs earlycon and therefore every line printed during early boot before the real console takes over.
Waiting for BUSY defeats the TX FIFO: instead of letting the UART buffer several queued bytes and transmit them back to back, every single character printed through earlycon is forced to wait for that character's own complete transmission (a full UART bit-time at the configured baud rate) before the driver will even look at writing the next one. This is wasted time on real hardware, and it is much worse under virtualization: each read of UARTFR and each write to UARTDR is an MMIO access that traps to the hypervisor, so removing the extra poll removes one entire VM-exit/entry round trip per character printed through earlycon.
This is easy to see, and to prove, in a fast-booting VMM. Using a small KVM-based VMM that boots Linux guests directly on arm64 (no firmware), booting an otherwise-identical 7.2.0-rc1 kernel (single vCPU, 512MB guest, direct PL011 MMIO with no interrupt-driven UART - i.e. earlycon is the only console active) up to the (expected, rootfs-less) "Unable to mount root fs" panic, with 20 boot samples per kernel per configuration:
cmdline: console=ttyAMA0 earlycon=pl011,0x09000000 ignore_loglevel
initcall_debug printk.time=1 (~99KB printed over earlycon)
before: min 466.3ms avg 471.4ms max 480.3ms (n=20)
after: min 429.5ms avg 433.3ms max 442.6ms (n=19)
-> ~38ms / ~8% faster, non-overlapping distributionscmdline: <the VMM's actual default, quiet, earlycon=pl011,0x09000000>
before: min 74.3ms avg 76.5ms max 82.2ms (n=20)
after: min 53.6ms avg 55.4ms max 60.7ms (n=20)
-> ~21ms / ~28% faster, non-overlapping distributionsThe second measurement uses the VMM's real default boot configuration (not a synthetic debug cmdline), so this is representative of ordinary boots, not just verbose-logging ones. Console content was diffed (timestamps and per-initcall "returned 0 after N usecs" numbers excluded) between before/after runs and is byte-for-byte identical
line-for-line: this change is a pure removal of unnecessary polling, with no functional or ordering change.
--- drivers/tty/serial/amba-pl011.c | 2 -- 1 file changed, 2 deletions(-)
drivers/tty/serial/amba-pl011.c +0 -2
@@ -2741,8 +2741,6 @@ static void pl011_putc(struct uart_port *port, unsigned char c)writel (c, port->membase + UART01x_DR); else writeb(c, port->membase + UART01x_DR); -while (readl (port->membase + UART01x_FR) & UART01x_FR_BUSY) -cpu_relax (); }static void pl011_early_write (struct console *con,const char *s,unsigned int n)
Signature · 1 line
2.54.0
PATCH v2 1/1 serial: amba-pl011: don't wait for BUSY after every earlycon character
pl011_putc(), used exclusively by the pl011 earlycon (pl011_early_write() -> uart_console_write()), waits for UART01x_FR_TXFF to clear before writing a character (correct: don't overrun the TX FIFO) and then *also* busy-waited for UART01x_FR_BUSY to clear before returning, i.e. it waited for the character to be fully shifted out on the wire before the next character in the string could even be considered.
Waiting for BUSY per character defeats the TX FIFO: instead of letting the UART buffer several queued bytes and transmit them back to back, every single character printed through earlycon was forced to wait for that character's own complete transmission (a full UART bit-time at the configured baud rate) before the driver would even look at writing the next one. This is wasted time on real hardware, and it is much worse under virtualization: each read of UARTFR and each write to UARTDR is an MMIO access that traps to the hypervisor, so every extra poll is a full VM-exit/entry round trip.
git blame on this function is unhelpful (this tree's history stops at a shallow-clone boundary), but the equivalent history is available from the upstream patch that added the QDF2400 erratum 44 workaround:
commit d8a4995bcea1 ("tty: pl011: Work around QDF2400 E44 stuck BUSY bit"):
That patch added a *separate* qdf2400_e44_putc() for hardware where BUSY can get stuck at 1, rather than touching pl011_putc() itself, and it left pl011_putc()'s per-character BUSY wait in place. So there is precedent for "waiting on BUSY is fragile on some hardware", but no indication that pl011_putc()'s per-character wait was ever intentional for standard hardware as opposed to simply mirroring the already-present final-drain wait used elsewhere in this same file.
Both pl011_console_putchar() and pl011_put_poll_char() (the regular, always-built console write path and the kgdb/kdb polling path) only wait for TXFF before writing, never for BUSY. The regular console path still gets a full-drain guarantee, but correctly obtains it only *once*, after the whole buffer has been written: pl011_console_write_atomic() and pl011_console_write_thread() each call uart_console_write() with pl011_console_putchar (no per-character BUSY wait), then separately wait for BUSY exactly once, after the loop, before restoring the CR register.
pl011_early_write() had no equivalent single final wait, so simply deleting the wait from pl011_putc() would drop the "the UART has actually finished transmitting by the time this function returns" guarantee that earlycon currently provides, e.g. right before a panic message is followed immediately by a reboot/poweroff. Instead, move the same "wait for BUSY" out of the per-character pl011_putc() and place it once in pl011_early_write(), after uart_console_write() completes, mirroring the pattern already used by pl011_console_write_atomic()/ _thread(). This keeps the flush guarantee while turning an O(n) wait (once per character) into an O(1) wait (once per earlycon write call).
This is easy to see, and to prove, in a fast-booting VMM. Using a small KVM-based VMM that boots Linux guests directly on arm64 (no firmware), booting an otherwise-identical 7.2.0-rc1 kernel (single vCPU, 512MB guest, direct PL011 MMIO with no interrupt-driven UART - i.e. earlycon is the only console active) up to the (expected, rootfs-less) "Unable to mount root fs" panic, with 20 boot samples per kernel per configuration:
cmdline: console=ttyAMA0 earlycon=pl011,0x09000000 ignore_loglevel
initcall_debug printk.time=1 (~99KB printed over earlycon)
before: min 466.3ms avg 471.4ms max 480.3ms (n=20)
after: min 429.4ms avg 435.3ms max 449.0ms (n=20)
-> ~36ms / ~7.7% faster, non-overlapping distributionscmdline: <the VMM's actual default, quiet, earlycon=pl011,0x09000000>
before: min 74.3ms avg 76.5ms max 82.2ms (n=20)
after: min 53.8ms avg 56.8ms max 74.9ms (n=20)
-> ~20ms / ~25.8% fasterThe second measurement uses the VMM's real default boot configuration (not a synthetic debug cmdline), so this is representative of ordinary boots, not just verbose-logging ones. Console content was diffed (timestamps and per-initcall "returned 0 after N usecs" numbers excluded) between before/after runs and is identical line-for-line:
this change does not drop, reorder, or corrupt any output.
---
v2: Rather than simply deleting the wait, move it out of the
per-character pl011_putc() and into pl011_early_write(), done once after the whole buffer is written (mirroring the existing pattern in pl011_console_write_atomic()/_thread()), so earlycon keeps its "fully transmitted by the time this call returns" guarantee. Also added the QDF2400 erratum 44 history as context for why the BUSY wait existed, and re-measured with the revised patch (numbers updated accordingly, same conclusion).
drivers/tty/serial/amba-pl011.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/tty/serial/amba-pl011.c +14 -2
@@ -2741,8 +2741,6 @@ static void pl011_putc(struct uart_port *port, unsigned char c)writel (c, port->membase + UART01x_DR); else writeb(c, port->membase + UART01x_DR); -while (readl (port->membase + UART01x_FR) & UART01x_FR_BUSY) -cpu_relax (); }static void pl011_early_write (struct console *con,const char *s,unsigned int n)
@@ -2750,6 +2748,20 @@ static void pl011_early_write(struct console *con, const char *s, unsigned int nstruct earlycon_device *dev = con->data;uart_console_write (&dev->port, s, n, pl011_putc); + +/* +* Wait for the last character to be fully transmitted before +* returning, same as pl011_console_write_atomic()/_thread() do for +* the non-early console. There is no need to do this after every +* character in pl011_putc(): checking TXFF there already prevents +* overrunning the FIFO, and waiting for BUSY per character forces +* the UART to be drained serially instead of letting it buffer +* queued bytes, which is needlessly slow, especially so under +* virtualization where each poll of UARTFR/UARTDR is a trapped MMIO +* access. +*/ +while (readl (dev->port.membase + UART01x_FR) & UART01x_FR_BUSY) +cpu_relax (); }#ifdef CONFIG_CONSOLE_POLL
Signature · 1 line
2.54.0
Greg Kroah-Hartman
maintainerRe: [PATCH v2] serial: amba-pl011: don't wait for BUSY after every earlycon character
Quoted 17 lines · Eric Curtin
pl011_putc(), used exclusively by the pl011 earlycon (pl011_early_write()->uart_console_write()), waits forUART01x_FR_TXFFto clear before writing a character (correct: don't overrun the TX FIFO) and then *also* busy-waited forUART01x_FR_BUSYto clear before returning, i.e. it waited for the character to be fully shifted out on the wire before the next character in the string could even be considered.Waiting for BUSY per character defeats the TX FIFO: instead of letting the UART buffer several queued bytes and transmit them back to back, every single character printed through earlycon was forced to wait for that character's own complete transmission (a full UART bit-time at the configured baud rate) before the driver would even look at writing the next one. This is wasted time on real hardware, and it is much worse under virtualization: each read of UARTFR and each write to UARTDR is an MMIO access that traps to the hypervisor, so every extra poll is a full VM-exit/entry round trip.
Quoted 3 lines
git blame on this function is unhelpful (this tree's history stops at a shallow-clone boundary), but the equivalent history is available from the upstream patch that added the QDF2400 erratum 44 workaround:
So this was generated by a LLM, right? Otherwise why can't you find where this changed by NOT doing a shallow clone?
When using a LLM, you must document that.
thanks,
greg k-h
PATCH v3 1/1 serial: amba-pl011: don't wait for BUSY after every earlycon character
pl011_putc(), used exclusively by the pl011 earlycon (pl011_early_write() -> uart_console_write()), waits for UART01x_FR_TXFF to clear before writing a character (correct: don't overrun the TX FIFO) and then *also* busy-waited for UART01x_FR_BUSY to clear before returning, i.e. it waited for the character to be fully shifted out on the wire before the next character in the string could even be considered.
Waiting for BUSY per character defeats the TX FIFO: instead of letting the UART buffer several queued bytes and transmit them back to back, every single character printed through earlycon was forced to wait for that character's own complete transmission (a full UART bit-time at the configured baud rate) before the driver would even look at writing the next one. This is wasted time on real hardware, and it is much worse under virtualization: each read of UARTFR and each write to UARTDR is an MMIO access that traps to the hypervisor, so every extra poll is a full VM-exit/entry round trip.
The regular (non-early) console path already gets this right: it waits for TXFF per character while filling the FIFO, then waits for BUSY only once, after the whole string has been written (see the tail of pl011_console_write_atomic()). The QDF2400 erratum 44 earlycon path (qdf2400_e44_putc()) is intentionally different because that erratum requires waiting for the stuck BUSY bit workaround per character, and is left untouched by this change.
This patch was written with the assistance of an AI coding tool (OpenCode CLI, using Claude as the backing model). The tool was given the observation that earlycon output was slower than expected under virtualization and asked to locate the cause and propose a fix; it identified the redundant per-character BUSY wait in pl011_putc() shown above and produced the one-line removal in this patch. The analysis and diff were reviewed by hand against the driver's other console write paths (pl011_console_write_atomic()/qdf2400_e44_putc()) to confirm the change is safe and does not affect the QDF2400 erratum workaround. Testing was done by booting a VM with a pl011 earlycon console with and without this change and comparing boot log timing.
--- drivers/tty/serial/amba-pl011.c | 2 -- 1 file changed, 2 deletions(-)
drivers/tty/serial/amba-pl011.c +0 -2
@@ -2741,8 +2741,6 @@ static void pl011_putc(struct uart_port *port, unsigned char c)writel (c, port->membase + UART01x_DR); else writeb(c, port->membase + UART01x_DR); -while (readl (port->membase + UART01x_FR) & UART01x_FR_BUSY) -cpu_relax (); }static void pl011_early_write (struct console *con,const char *s,unsigned int n)
Signature · 1 line
2.54.0
PATCH v4 1/1 serial: amba-pl011: don't wait for BUSY after every earlycon character
In reply to Greg Kroah-Hartmanpl011_putc(), used exclusively by the pl011 earlycon (pl011_early_write() -> uart_console_write()), waits for UART01x_FR_TXFF to clear before writing a character (correct: don't overrun the TX FIFO) and then *also* busy-waited for UART01x_FR_BUSY to clear before returning, i.e. it waited for the character to be fully shifted out on the wire before the next character in the string could even be considered.
Waiting for BUSY per character defeats the TX FIFO: instead of letting the UART buffer several queued bytes and transmit them back to back, every single character printed through earlycon was forced to wait for that character's own complete transmission (a full UART bit-time at the configured baud rate) before the driver would even look at writing the next one. This is wasted time on real hardware, and it is much worse under virtualization: each read of UARTFR and each write to UARTDR is an MMIO access that traps to the hypervisor, so every extra poll is a full VM-exit/entry round trip.
git blame on this function is unhelpful (this tree's history stops at a shallow-clone boundary), but the equivalent history is available from the upstream patch that added the QDF2400 erratum 44 workaround:
commit d8a4995bcea1 ("tty: pl011: Work around QDF2400 E44 stuck BUSY bit"):
That patch added a *separate* qdf2400_e44_putc() for hardware where BUSY can get stuck at 1, rather than touching pl011_putc() itself, and it left pl011_putc()'s per-character BUSY wait in place. So there is precedent for "waiting on BUSY is fragile on some hardware", but no indication that pl011_putc()'s per-character wait was ever intentional for standard hardware as opposed to simply mirroring the already-present final-drain wait used elsewhere in this same file.
Both pl011_console_putchar() and pl011_put_poll_char() (the regular, always-built console write path and the kgdb/kdb polling path) only wait for TXFF before writing, never for BUSY. The regular console path still gets a full-drain guarantee, but correctly obtains it only *once*, after the whole buffer has been written: pl011_console_write_atomic() and pl011_console_write_thread() each call uart_console_write() with pl011_console_putchar (no per-character BUSY wait), then separately wait for BUSY exactly once, after the loop, before restoring the CR register.
pl011_early_write() had no equivalent single final wait, so simply deleting the wait from pl011_putc() would drop the "the UART has actually finished transmitting by the time this function returns" guarantee that earlycon currently provides, e.g. right before a panic message is followed immediately by a reboot/poweroff. Instead, move the same "wait for BUSY" out of the per-character pl011_putc() and place it once in pl011_early_write(), after uart_console_write() completes, mirroring the pattern already used by pl011_console_write_atomic()/ _thread(). This keeps the flush guarantee while turning an O(n) wait (once per character) into an O(1) wait (once per earlycon write call).
This is easy to see, and to prove, in a fast-booting VMM. Using a small KVM-based VMM that boots Linux guests directly on arm64 (no firmware), booting an otherwise-identical 7.2.0-rc1 kernel (single vCPU, 512MB guest, direct PL011 MMIO with no interrupt-driven UART - i.e. earlycon is the only console active) up to the (expected, rootfs-less) "Unable to mount root fs" panic, with 20 boot samples per kernel per configuration:
cmdline: console=ttyAMA0 earlycon=pl011,0x09000000 ignore_loglevel
initcall_debug printk.time=1 (~99KB printed over earlycon)
before: min 466.3ms avg 471.4ms max 480.3ms (n=20)
after: min 429.4ms avg 435.3ms max 449.0ms (n=20)
-> ~36ms / ~7.7% faster, non-overlapping distributionscmdline: <the VMM's actual default, quiet, earlycon=pl011,0x09000000>
before: min 74.3ms avg 76.5ms max 82.2ms (n=20)
after: min 53.8ms avg 56.8ms max 74.9ms (n=20)
-> ~20ms / ~25.8% fasterThe second measurement uses the VMM's real default boot configuration (not a synthetic debug cmdline), so this is representative of ordinary boots, not just verbose-logging ones. Console content was diffed (timestamps and per-initcall "returned 0 after N usecs" numbers excluded) between before/after runs and is identical line-for-line:
this change does not drop, reorder, or corrupt any output.
An AI coding tool (OpenCode CLI, using Claude as the backing model) was used in preparing this patch. It was given the observation that earlycon output was slower than expected under virtualization and asked to locate the cause and propose a fix; it identified the per-character BUSY wait in pl011_putc() and, after being pointed at pl011_console_write_atomic()/_thread() as the existing precedent for a single final drain, produced the code that moves the wait into pl011_early_write(). It also helped research the QDF2400 erratum 44 history cited above and draft this changelog. All of the above was reviewed by hand against the driver's other console write paths to confirm correctness. The boot-timing measurements and the line-for-line console diff were run and captured by hand on the VMM described above; they were not produced by the tool.
---
v4: v3 mistakenly replaced this patch's actual fix (moving the BUSY
wait to run once in pl011_early_write(), preserving the "fully drained on return" guarantee) with a plain deletion of the wait, which would have been a functional regression (e.g. for panic output immediately followed by reboot/poweroff). This reverts to the v2 fix, keeps the real, measured boot-timing numbers, and adds the explicit disclosure of AI-tool assistance that was missing from v2, per Documentation/process/generated-content.rst.
v3: (erroneous, superseded by the above; sent by mistake)
v2: Rather than simply deleting the wait, move it out of the
per-character pl011_putc() and into pl011_early_write(), done once after the whole buffer is written (mirroring the existing pattern in pl011_console_write_atomic()/_thread()), so earlycon keeps its "fully transmitted by the time this call returns" guarantee. Also added the QDF2400 erratum 44 history as context for why the BUSY wait existed, and re-measured with the revised patch (numbers updated accordingly, same conclusion).
drivers/tty/serial/amba-pl011.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/tty/serial/amba-pl011.c +14 -2
@@ -2741,8 +2741,6 @@ static void pl011_putc(struct uart_port *port, unsigned char c)writel (c, port->membase + UART01x_DR); else writeb(c, port->membase + UART01x_DR); -while (readl (port->membase + UART01x_FR) & UART01x_FR_BUSY) -cpu_relax (); }static void pl011_early_write (struct console *con,const char *s,unsigned int n)
@@ -2750,6 +2748,20 @@ static void pl011_early_write(struct console *con, const char *s, unsigned int nstruct earlycon_device *dev = con->data;uart_console_write (&dev->port, s, n, pl011_putc); + +/* +* Wait for the last character to be fully transmitted before +* returning, same as pl011_console_write_atomic()/_thread() do for +* the non-early console. There is no need to do this after every +* character in pl011_putc(): checking TXFF there already prevents +* overrunning the FIFO, and waiting for BUSY per character forces +* the UART to be drained serially instead of letting it buffer +* queued bytes, which is needlessly slow, especially so under +* virtualization where each poll of UARTFR/UARTDR is a trapped MMIO +* access. +*/ +while (readl (dev->port.membase + UART01x_FR) & UART01x_FR_BUSY) +cpu_relax (); }#ifdef CONFIG_CONSOLE_POLL
Signature · 1 line
2.54.0
RE: [PATCH v4] serial: amba-pl011: don't wait for BUSY after every earlycon character
From: Eric Curtin <[email protected]> Sent: Monday, July 20, 2026 5:27 AM
Quoted 72 lines
pl011_putc(), used exclusively by the pl011 earlycon (pl011_early_write()->uart_console_write()), waits forUART01x_FR_TXFFto clear before writing a character (correct: don't overrun the TX FIFO) and then *also* busy-waited forUART01x_FR_BUSYto clear before returning, i.e. it waited for the character to be fully shifted out on the wire before the next character in the string could even be considered.Waiting for BUSY per character defeats the TX FIFO: instead of letting the UART buffer several queued bytes and transmit them back to back, every single character printed through earlycon was forced to wait for that character's own complete transmission (a full UART bit-time at the configured baud rate) before the driver would even look at writing the next one. This is wasted time on real hardware, and it is much worse under virtualization: each read of UARTFR and each write to UARTDR is an MMIO access that traps to the hypervisor, so every extra poll is a full VM-exit/entry round trip.
git blame on this function is unhelpful (this tree's history stops at a shallow-clone boundary), but the equivalent history is available from the upstream patch that added the QDF2400 erratum 44 workaround:
commit
d8a4995bcea1("tty: pl011: Work around QDF2400 E44 stuck BUSY bit"):That patch added a *separate*
qdf2400_e44_putc()for hardware where BUSY can get stuck at 1, rather than touchingpl011_putc()itself, and it left pl011_putc()'s per-character BUSY wait in place. So there is precedent for "waiting on BUSY is fragile on some hardware", but no indication that pl011_putc()'s per-character wait was ever intentional for standard hardware as opposed to simply mirroring the already-present final-drain wait used elsewhere in this same file.Both
pl011_console_putchar()andpl011_put_poll_char()(the regular, always-built console write path and the kgdb/kdb polling path) only wait for TXFF before writing, never for BUSY. The regular console path still gets a full-drain guarantee, but correctly obtains it only *once*, after the whole buffer has been written:pl011_console_write_atomic()andpl011_console_write_thread()each calluart_console_write()withpl011_console_putchar(no per-character BUSY wait), then separately wait for BUSY exactly once, after the loop, before restoring the CR register.
pl011_early_write()had no equivalent single final wait, so simply deleting the wait frompl011_putc()would drop the "the UART has actually finished transmitting by the time this function returns" guarantee that earlycon currently provides, e.g. right before a panic message is followed immediately by a reboot/poweroff. Instead, move the same "wait for BUSY" out of the per-characterpl011_putc()and place it once inpl011_early_write(), afteruart_console_write()completes, mirroring the pattern already used by pl011_console_write_atomic()/_thread(). This keeps the flush guarantee while turning an O(n) wait (once per character) into an O(1) wait (once per earlycon write call).This is easy to see, and to prove, in a fast-booting VMM. Using a small KVM-based VMM that boots Linux guests directly on arm64 (no firmware), booting an otherwise-identical 7.2.0-rc1 kernel (single vCPU, 512MB guest, direct PL011 MMIO with no interrupt-driven UART - i.e. earlycon is the only console active) up to the (expected, rootfs-less) "Unable to mount root fs" panic, with 20 boot samples per kernel per configuration:
cmdline: console=ttyAMA0 earlycon=pl011,0x09000000
ignore_loglevelinitcall_debug printk.time=1 (~99KB printed over earlycon) before: min 466.3ms avg 471.4ms max 480.3ms (n=20) after: min 429.4ms avg 435.3ms max 449.0ms (n=20) -> ~36ms / ~7.7% faster, non-overlapping distributionscmdline: <the VMM's actual default, quiet, earlycon=pl011,0x09000000>
before: min 74.3ms avg 76.5ms max 82.2ms (n=20) after: min 53.8ms avg 56.8ms max 74.9ms (n=20) -> ~20ms / ~25.8% faster
Quoted 7 lines
The second measurement uses the VMM's real default boot configuration (not a synthetic debug cmdline), so this is representative of ordinary boots, not just verbose-logging ones. Console content was diffed (timestamps and per-initcall "returned 0 after N usecs" numbers excluded) between before/after runs and is identical line-for-line:
this change does not drop, reorder, or corrupt any output.
I tested this patch in two VMs running on Hyper-V in the Azure public cloud. Hyper-V provides an emulated PL011 to ARM64 guests, but the emulation has some quirks. I wanted to verify that the quirks didn't cause any issues. All my basic smoke testing passed, which is great.
From a performance standpoint, the older Dp_v5 series VM saved an average of 196 milliseconds in boot time up to the point that the regular PL011 driver took over. The newer Dp_v6 series VM, which has a faster physical processor, saved an average of 158 ms. Both values are an average of 4 runs of an unmodified linux-next20260721 kernel vs. the same kernel with your patch. That's a nice win!
Greg KH
maintainerRe: [PATCH v4] serial: amba-pl011: don't wait for BUSY after every earlycon character
In reply to Eric CurtinQuoted 5 lines · Eric Curtin
An AI coding tool (OpenCode CLI, using Claude as the backing model) was used in preparing this patch. It was given the observation that earlycon output was slower than expected under virtualization and asked to locate the cause and propose a fix; it identified the per-character BUSY wait in
pl011_putc()and, after being pointed at
Quoted 8 lines
pl011_console_write_atomic()/_thread() as the existing precedent for a single final drain, produced the code that moves the wait into
pl011_early_write(). It also helped research the QDF2400 erratum 44 history cited above and draft this changelog. All of the above was reviewed by hand against the driver's other console write paths to confirm correctness. The boot-timing measurements and the line-for-line console diff were run and captured by hand on the VMM described above; they were not produced by the tool.
This means an Assisted-by line should be added.
Also, your changelog should be a lot smaller, LLMs love to talk a lot...
Quoted 43 lines
Signed-off-by Eric Curtin <[email protected]>---
v4: v3 mistakenly replaced this patch's actual fix (moving the BUSY
wait to run once inpl011_early_write(), preserving the "fully drained on return" guarantee) with a plain deletion of the wait, which would have been a functional regression (e.g. for panic output immediately followed by reboot/poweroff). This reverts to the v2 fix, keeps the real, measured boot-timing numbers, and adds the explicit disclosure of AI-tool assistance that was missing from v2, perDocumentation/process/generated-content.rst.
v3: (erroneous, superseded by the above; sent by mistake)
v2: Rather than simply deleting the wait, move it out of the
per-characterpl011_putc()and intopl011_early_write(), done once after the whole buffer is written (mirroring the existing pattern in pl011_console_write_atomic()/_thread()), so earlycon keeps its "fully transmitted by the time this call returns" guarantee. Also added the QDF2400 erratum 44 history as context for why the BUSY wait existed, and re-measured with the revised patch (numbers updated accordingly, same conclusion).drivers/tty/serial/amba-pl011.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/tty/serial/amba-pl011.c +2
-2@@ -2741,8 +2741,6 @@ static void pl011_putc(struct uart_port *port, unsigned char c)writel (c, port->membase + UART01x_DR); else writeb(c, port->membase + UART01x_DR); -while (readl (port->membase + UART01x_FR) & UART01x_FR_BUSY) -cpu_relax (); }static void pl011_early_write (struct console *con,const char *s,unsigned int n)@@ -2750,6 +2748,20 @@ static void pl011_early_write(struct console *con, const char *s, unsigned int nstruct earlycon_device *dev = con->data;uart_console_write (&dev->port, s, n, pl011_putc); + +/*
drivers/tty/serial/amba-pl011.c static void pl011_early_write(struct console *con, const char *s, unsigned int n · line 2762
Quoted 10 lines
drivers/tty/serial/amba-pl011.c +10
-0+* Wait for the last character to be fully transmitted before +* returning, same as pl011_console_write_atomic()/_thread() do for +* the non-early console. There is no need to do this after every +* character in pl011_putc(): checking TXFF there already prevents +* overrunning the FIFO, and waiting for BUSY per character forces +* the UART to be drained serially instead of letting it buffer +* queued bytes, which is needlessly slow, especially so under +* virtualization where each poll of UARTFR/UARTDR is a trapped MMIO +* access. +*/
And this comment is also really not needed, right?
thanks,
greg k-h