Skip to content

Commit 43066e3

Browse files
Yicong Yanggregkh
authored andcommitted
serial: port: Don't suspend if the port is still busy
We accidently met the issue that the bash prompt is not shown after the previous command done and until the next input if there's only one CPU (In our issue other CPUs are isolated by isolcpus=). Further analysis shows it's because the port entering runtime suspend even if there's still pending chars in the buffer and the pending chars will only be processed in next device resuming. We are using amba-pl011 and the problematic flow is like below: Bash                                         kworker tty_write()   file_tty_write()     n_tty_write()       uart_write()         __uart_start()           pm_runtime_get() // wakeup waker             queue_work()                                     pm_runtime_work()                                                rpm_resume()                                                 status = RPM_RESUMING                                                 serial_port_runtime_resume()                                                   port->ops->start_tx()                                                     pl011_tx_chars()                                                       uart_write_wakeup()         […]         __uart_start()           pm_runtime_get() < 0 // because runtime status = RPM_RESUMING                                // later data are not commit to the port driver                                                 status = RPM_ACTIVE                                                 rpm_idle() -> rpm_suspend() This patch tries to fix this by checking the port busy before entering runtime suspending. A runtime_suspend callback is added for the port driver. When entering runtime suspend the callback is invoked, if there's still pending chars in the buffer then flush the buffer. Fixes: 84a9582 ("serial: core: Start managing serial controllers to enable runtime PM") Cc: stable <stable@kernel.org> Reviewed-by: Tony Lindgren <tony@atomide.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20240226152351.40924-1-yangyicong@huawei.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e5d6bd2 commit 43066e3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

drivers/tty/serial/serial_port.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,31 @@ static int serial_port_runtime_resume(struct device *dev)
4646
return 0;
4747
}
4848

49+
static int serial_port_runtime_suspend(struct device *dev)
50+
{
51+
struct serial_port_device *port_dev = to_serial_base_port_device(dev);
52+
struct uart_port *port = port_dev->port;
53+
unsigned long flags;
54+
bool busy;
55+
56+
if (port->flags & UPF_DEAD)
57+
return 0;
58+
59+
uart_port_lock_irqsave(port, &flags);
60+
busy = __serial_port_busy(port);
61+
if (busy)
62+
port->ops->start_tx(port);
63+
uart_port_unlock_irqrestore(port, flags);
64+
65+
if (busy)
66+
pm_runtime_mark_last_busy(dev);
67+
68+
return busy ? -EBUSY : 0;
69+
}
70+
4971
static DEFINE_RUNTIME_DEV_PM_OPS(serial_port_pm,
50-
NULL, serial_port_runtime_resume, NULL);
72+
serial_port_runtime_suspend,
73+
serial_port_runtime_resume, NULL);
5174

5275
static int serial_port_probe(struct device *dev)
5376
{

0 commit comments

Comments
 (0)