Skip to contentSkip to conversation

ns16550: ensure polling timer is disarmed

PATCH In review [email protected] 3 participants 9 messages Jul 30, 2025 – Aug 6, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ns16550: ensure polling timer is disarmed

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

---
 xen/drivers/char/ns16550.c | 4 ++++
 1 file changed, 4 insertions(+)
xen/drivers/char/ns16550.c +4 -0
index df7fff7f81df..299773d80065 100644
@@ -191,6 +191,10 @@ static void cf_check ns16550_interrupt(int irq, void *dev_id)
     struct serial_port *port = dev_id;
     struct ns16550 *uart = port->uart;
 
+    /* Ensure polling timer is disarmed and removed from the timer list. */
+    if ( !uart->intr_works )
+        kill_timer(&uart->timer);
+
     uart->intr_works = 1;
 
     while ( !(ns_read_reg(uart, UART_IIR) & UART_IIR_NOINT) )
Signature · 1 line
2.34.1
#1 lore raw
Quoted 9 lines · On 30.07.2025 05:13, [email protected] wrote:

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

Wasn't it Andrew(?) who suggested something along these lines? That would want reflecting by a tag then.

Also, what's the real problem you want to solve here? The timer function would be run one more time after ->intr_works is set, and then the timer will be permanently inactive (up to a possible S3 resume). Is it being on an inactive list an actual problem? (IOW I'd like to understand if the change is merely cosmetic, or if there is some actual benefit.)

Jan

#2 lore raw
Quoted 6 lines · Jan Beulich
Quoted 5 lines · On 30.07.2025 05:13, [email protected] wrote:

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Quoted 7 lines
Quoted 4 lines

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

Wasn't it Andrew(?) who suggested something along these lines? That would want reflecting by a tag then.

Yes, indeed.

Quoted 6 lines

Also, what's the real problem you want to solve here? The timer function would be run one more time after ->intr_works is set, and then the timer will be permanently inactive (up to a possible S3 resume). Is it being on an inactive list an actual problem? (IOW I'd like to understand if the change is merely cosmetic, or if there is some actual benefit.)

My understanding is running polling timer one more time after the interrupts are enabled is the issue: if there's a pending timer when it is known the timer not needed, then the timer should be canceled.

Quoted 2 lines

Jan

#3 lore raw
Quoted 24 lines · On 30.07.2025 20:31, [email protected] wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines · On 30.07.2025 05:13, [email protected] wrote:

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Quoted 7 lines
Quoted 4 lines

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

Wasn't it Andrew(?) who suggested something along these lines? That would want reflecting by a tag then.

Yes, indeed.

Quoted 6 lines

Also, what's the real problem you want to solve here? The timer function would be run one more time after ->intr_works is set, and then the timer will be permanently inactive (up to a possible S3 resume). Is it being on an inactive list an actual problem? (IOW I'd like to understand if the change is merely cosmetic, or if there is some actual benefit.)

Quoted 3 lines

My understanding is running polling timer one more time after the interrupts are enabled is the issue: if there's a pending timer when it is known the timer not needed, then the timer should be canceled.

And the effort of canceling outweighs the one extra running of the timer?

Jan

#4 lore raw
Quoted 25 lines · Jan Beulich
Quoted 24 lines · On 30.07.2025 20:31, [email protected] wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines · On 30.07.2025 05:13, [email protected] wrote:

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Quoted 7 lines
Quoted 4 lines

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

Wasn't it Andrew(?) who suggested something along these lines? That would want reflecting by a tag then.

Yes, indeed.

Quoted 6 lines

Also, what's the real problem you want to solve here? The timer function would be run one more time after ->intr_works is set, and then the timer will be permanently inactive (up to a possible S3 resume). Is it being on an inactive list an actual problem? (IOW I'd like to understand if the change is merely cosmetic, or if there is some actual benefit.)

Quoted 5 lines
Quoted 3 lines

My understanding is running polling timer one more time after the interrupts are enabled is the issue: if there's a pending timer when it is known the timer not needed, then the timer should be canceled.

And the effort of canceling outweighs the one extra running of the timer?

I think so, because intr_works will not flip at run-time once set. If so, no need to keep the timer ready to be rearmed.

Quoted 2 lines

Jan

#5 lore raw
Quoted 26 lines · On 31.07.2025 23:42, [email protected] wrote:
Quoted 25 lines · Jan Beulich
Quoted 24 lines · On 30.07.2025 20:31, [email protected] wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines · On 30.07.2025 05:13, [email protected] wrote:

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Quoted 7 lines
Quoted 4 lines

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

Wasn't it Andrew(?) who suggested something along these lines? That would want reflecting by a tag then.

Yes, indeed.

Quoted 6 lines

Also, what's the real problem you want to solve here? The timer function would be run one more time after ->intr_works is set, and then the timer will be permanently inactive (up to a possible S3 resume). Is it being on an inactive list an actual problem? (IOW I'd like to understand if the change is merely cosmetic, or if there is some actual benefit.)

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

My understanding is running polling timer one more time after the interrupts are enabled is the issue: if there's a pending timer when it is known the timer not needed, then the timer should be canceled.

And the effort of canceling outweighs the one extra running of the timer?

I think so, because intr_works will not flip at run-time once set. If so, no need to keep the timer ready to be rearmed.

Well, to me it looks like a code size increase with extremely limited benefit. Hence while likely I wouldn't outright NAK such a change, I also wouldn't ACK it.

Jan

#6 lore raw
Quoted 31 lines · Jan Beulich
Quoted 30 lines · On 31.07.2025 23:42, [email protected] wrote:
Quoted 29 lines · Jan Beulich
Quoted 27 lines · On 30.07.2025 20:31, [email protected] wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines · On 30.07.2025 05:13, [email protected] wrote:

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Quoted 7 lines
Quoted 4 lines

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

Wasn't it Andrew(?) who suggested something along these lines? That would want reflecting by a tag then.

Yes, indeed.

Quoted 6 lines

Also, what's the real problem you want to solve here? The timer function would be run one more time after ->intr_works is set, and then the timer will be permanently inactive (up to a possible S3 resume). Is it being on an inactive list an actual problem? (IOW I'd like to understand if the change is merely cosmetic, or if there is some actual benefit.)

My understanding is running polling timer one more time after the interrupts are enabled is the issue: if there's a pending timer when it is known the timer not needed, then the timer should be canceled.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

And the effort of canceling outweighs the one extra running of the timer?

I think so, because intr_works will not flip at run-time once set. If so, no need to keep the timer ready to be rearmed.

Well, to me it looks like a code size increase with extremely limited benefit. Hence while likely I wouldn't outright NAK such a change, I also wouldn't ACK it.

Hm, indeed the net win of this is dubious, as the extra polling interrupt would only happen once. Using stop_timer() would be less heavyweight than kill_timer().

Overall I think it needs justification in the commit message, as the timer cannot be removed from the list of timers, otherwise it's usage on resume from suspension will trigger an ASSERT, so part of the commit message is stale.

Thanks, Roger.

#7 lore raw
Quoted 41 lines · Roger Pau Monné
Quoted 31 lines · Jan Beulich
Quoted 30 lines · On 31.07.2025 23:42, [email protected] wrote:
Quoted 29 lines · Jan Beulich
Quoted 27 lines · On 30.07.2025 20:31, [email protected] wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines · On 30.07.2025 05:13, [email protected] wrote:

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Quoted 7 lines
Quoted 4 lines

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

Wasn't it Andrew(?) who suggested something along these lines? That would want reflecting by a tag then.

Yes, indeed.

Quoted 6 lines

Also, what's the real problem you want to solve here? The timer function would be run one more time after ->intr_works is set, and then the timer will be permanently inactive (up to a possible S3 resume). Is it being on an inactive list an actual problem? (IOW I'd like to understand if the change is merely cosmetic, or if there is some actual benefit.)

My understanding is running polling timer one more time after the interrupts are enabled is the issue: if there's a pending timer when it is known the timer not needed, then the timer should be canceled.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

And the effort of canceling outweighs the one extra running of the timer?

I think so, because intr_works will not flip at run-time once set. If so, no need to keep the timer ready to be rearmed.

Well, to me it looks like a code size increase with extremely limited benefit. Hence while likely I wouldn't outright NAK such a change, I also wouldn't ACK it.

Quoted 8 lines

Hm, indeed the net win of this is dubious, as the extra polling interrupt would only happen once. Using stop_timer() would be less heavyweight than kill_timer().

Overall I think it needs justification in the commit message, as the timer cannot be removed from the list of timers, otherwise it's usage on resume from suspension will trigger an ASSERT, so part of the commit message is stale.

That could be compensated by another init_timer(), though. (In fact when originally looking at the patch, I [wrongly] thought that path was taken on resume, so didn't comment on that aspect.)

Jan

#8 lore raw
In reply to [email protected]
Quoted 18 lines · On Wed, Jul 30, 2025 at 03:13:31AM +0000, [email protected] wrote:

From: Denis Mukhin <[email protected]>

As it stands, polling timer is kept in the list of timers even after the interrupts have been enabled / polling disabled on ns16550-compatible UART.

Ensure polling timer is removed from the timer list once UART interrupts are enabled.

---
 xen/drivers/char/ns16550.c | 4 ++++
 1 file changed, 4 insertions(+)
xen/drivers/char/ns16550.c +0 -0
index df7fff7f81df..299773d80065 100644

xen/drivers/char/ns16550.c static void cf_check ns16550_interrupt(int irq, void *dev_id) · line 196

Quoted 6 lines
xen/drivers/char/ns16550.c +3 -0
@@ -191,6 +191,10 @@ static void cf_check ns16550_interrupt(int irq, void *dev_id)
     struct serial_port *port = dev_id;
     struct ns16550 *uart = port->uart;
 
+    /* Ensure polling timer is disarmed and removed from the timer list. */
+    if ( !uart->intr_works )
+        kill_timer(&uart->timer);

I think if anything you should issue a stop_timer() call, but not a kill_timer() one, otherwise the uart code will hit an ASSERT when calling set_timer() from ns16550_setup_postirq()? (that's from _ns16550_resume()).

Thanks, Roger.