Skip to contentSkip to conversation

serial: core: Fix checks for tx runtime PM state

PATCH In review Tony Lindgren 4 participants 11 messages Oct 5, 2023 – Oct 18, 2023 TTY layer and serial drivers

lore
Share & tools
lore
Reviewed-by on v1 1/1
#1 lore raw
In reply to Tony Lindgren
Quoted 9 lines · Tony Lindgren

Maximilian reported that surface_serial_hub serdev tx does not work during system suspend. During system suspend, runtime PM gets disabled in __device_suspend_late(), and tx is unable to wake-up the serial core port device that we use to check if tx is safe to start. Johan summarized the regression noting that serdev tx no longer always works as earlier when the serdev device is runtime PM active.

The serdev device and the serial core controller devices are siblings of the serial port hardware device. The runtime PM usage count from serdev

I'm a bit lost in terminology here.
AFAIU there are:
1) children of the serial physical device;
2) siblings (to each other).

But may be I mistakenly deciphered the diagram from the previous discussion.

Quoted 9 lines

device does not propagate to the serial core device siblings, it only propagates to the parent.

In addition to the tx issue for suspend, testing for the serial core port device can cause an unnecessary delay in enabling tx while waiting for the serial core port device to wake-up. The serial core port device wake-up is only needed to flush pending tx when the serial port hardware device was in runtime PM suspended state.

Quoted 5 lines

To fix the regression, we need to check the runtime PM state of the parent serial port hardware device for tx instead of the serial core port device.

As the serial port device drivers may or may not implement runtime PM, we need to also add a check for pm_runtime_enabled().

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#0 lore raw

PATCH 1/1 serial: core: Fix checks for tx runtime PM state

Maximilian reported that surface_serial_hub serdev tx does not work during system suspend. During system suspend, runtime PM gets disabled in __device_suspend_late(), and tx is unable to wake-up the serial core port device that we use to check if tx is safe to start. Johan summarized the regression noting that serdev tx no longer always works as earlier when the serdev device is runtime PM active.

The serdev device and the serial core controller devices are siblings of the serial port hardware device. The runtime PM usage count from serdev device does not propagate to the serial core device siblings, it only propagates to the parent.

In addition to the tx issue for suspend, testing for the serial core port device can cause an unnecessary delay in enabling tx while waiting for the serial core port device to wake-up. The serial core port device wake-up is only needed to flush pending tx when the serial port hardware device was in runtime PM suspended state.

To fix the regression, we need to check the runtime PM state of the parent serial port hardware device for tx instead of the serial core port device.

As the serial port device drivers may or may not implement runtime PM, we need to also add a check for pm_runtime_enabled().

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
---
 drivers/tty/serial/serial_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +1 -1
@@ -156,7 +156,7 @@ static void __uart_start(struct uart_state *state)
 	 * enabled, serial_port_runtime_resume() calls start_tx() again
 	 * after enabling the device.
 	 */
-	if (pm_runtime_active(&port_dev->dev))
+	if (!pm_runtime_enabled(port->dev) || pm_runtime_active(port->dev))
 		port->ops->start_tx(port);
 	pm_runtime_mark_last_busy(&port_dev->dev);
 	pm_runtime_put_autosuspend(&port_dev->dev);
Signature · 1 line
2.42.0
Tested-by on v1 1/1
#10 lore raw
Quoted 21 lines · Tony Lindgren

Maximilian reported that surface_serial_hub serdev tx does not work during system suspend. During system suspend, runtime PM gets disabled in __device_suspend_late(), and tx is unable to wake-up the serial core port device that we use to check if tx is safe to start. Johan summarized the regression noting that serdev tx no longer always works as earlier when the serdev device is runtime PM active.

The serdev device and the serial core controller devices are siblings of the serial port hardware device. The runtime PM usage count from serdev device does not propagate to the serial core device siblings, it only propagates to the parent.

In addition to the tx issue for suspend, testing for the serial core port device can cause an unnecessary delay in enabling tx while waiting for the serial core port device to wake-up. The serial core port device wake-up is only needed to flush pending tx when the serial port hardware device was in runtime PM suspended state.

To fix the regression, we need to check the runtime PM state of the parent serial port hardware device for tx instead of the serial core port device.

Quoted 6 lines

As the serial port device drivers may or may not implement runtime PM, we need to also add a check for pm_runtime_enabled().

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")

Thanks!

Quoted 16 lines
---
  drivers/tty/serial/serial_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +1 -1
@@ -156,7 +156,7 @@ static void __uart_start(struct uart_state *state)
  	 * enabled, serial_port_runtime_resume() calls start_tx() again
  	 * after enabling the device.
  	 */
-	if (pm_runtime_active(&port_dev->dev))
+	if (!pm_runtime_enabled(port->dev) || pm_runtime_active(port->dev))
  		port->ops->start_tx(port);
  	pm_runtime_mark_last_busy(&port_dev->dev);
  	pm_runtime_put_autosuspend(&port_dev->dev);
#2 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 2 lines · Tony Lindgren

The serdev device and the serial core controller devices are siblings of the serial port hardware device. The runtime PM usage count from serdev

I'm a bit lost in terminology here.
AFAIU there are:
1) children of the serial physical device;
2) siblings (to each other).

But may be I mistakenly deciphered the diagram from the previous discussion.

You're right, so how about:

The serdev device and the serial core controller devices are children of the serial port hardware device. The runtime PM usage count from serdev device does not propagate to the serial core device siblings, it only propagates to the parent.

Regards,

Tony

#3 lore raw
Quoted 10 lines · Tony Lindgren
Quoted 9 lines · Andy Shevchenko
Quoted 2 lines · Tony Lindgren

The serdev device and the serial core controller devices are siblings of the serial port hardware device. The runtime PM usage count from serdev

I'm a bit lost in terminology here.
AFAIU there are:
1) children of the serial physical device;
2) siblings (to each other).

Quoted 8 lines
Quoted 1 line

But may be I mistakenly deciphered the diagram from the previous discussion.

You're right, so how about:

The serdev device and the serial core controller devices are children of the serial port hardware device. The runtime PM usage count from serdev device does not propagate to the serial core device siblings, it only propagates to the parent.

That's still not accurate:

- the serdev device is not a child (but a grandchild) of the serial controller
- the new serial port devices are not "siblings" (but descendants) of the serial controller
- the serdev controller ignores the power state of its children so that bit is also incorrect

You just want to describe the fact that the serdev controller runtime PM state is currently not propagated to your new "devices" that are descendants to the serial controller.

I'm still not sure why it was implemented this way, or if it is even correct, but this seems to be the state of things.

Johan

#9 lore raw
In reply to Tony Lindgren
Quoted 10 lines · Tony Lindgren
Quoted 9 lines · Andy Shevchenko
Quoted 2 lines · Tony Lindgren

The serdev device and the serial core controller devices are siblings of the serial port hardware device. The runtime PM usage count from serdev

I'm a bit lost in terminology here.
AFAIU there are:
1) children of the serial physical device;
2) siblings (to each other).

Quoted 8 lines
Quoted 1 line

But may be I mistakenly deciphered the diagram from the previous discussion.

You're right, so how about:

The serdev device and the serial core controller devices are children of the serial port hardware device. The runtime PM usage count from serdev device does not propagate to the serial core device siblings, it only propagates to the parent.

Clearer, thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Johan Hovold
Quoted 29 lines · Johan Hovold
Quoted 10 lines · Tony Lindgren
Quoted 9 lines · Andy Shevchenko
Quoted 2 lines · Tony Lindgren

The serdev device and the serial core controller devices are siblings of the serial port hardware device. The runtime PM usage count from serdev

I'm a bit lost in terminology here.
AFAIU there are:
1) children of the serial physical device;
2) siblings (to each other).

Quoted 8 lines
Quoted 1 line

But may be I mistakenly deciphered the diagram from the previous discussion.

You're right, so how about:

The serdev device and the serial core controller devices are children of the serial port hardware device. The runtime PM usage count from serdev device does not propagate to the serial core device siblings, it only propagates to the parent.

That's still not accurate:

- the serdev device is not a child (but a grandchild) of the serial controller
- the new serial port devices are not "siblings" (but descendants) of the serial controller
- the serdev controller ignores the power state of its children so that bit is also incorrect

Quoted 3 lines

You just want to describe the fact that the serdev controller runtime PM state is currently not propagated to your new "devices" that are descendants to the serial controller.

OK so let's just use:

The serdev controller runtime PM state is not currently propagated to the serial core controller port device. The runtime PM usage count only propagates to the parent device.

Quoted 2 lines

I'm still not sure why it was implemented this way, or if it is even correct, but this seems to be the state of things.

Care to clarify a bit which parts are unclear? The hierarchy of port devices, making serial core manage runtime PM in a generic way, or flushing tx?

Regards,

Tony

#5 lore raw
Quoted 23 lines · Tony Lindgren
Quoted 18 lines · Johan Hovold
Quoted 6 lines · Tony Lindgren

You're right, so how about:

The serdev device and the serial core controller devices are children of the serial port hardware device. The runtime PM usage count from serdev device does not propagate to the serial core device siblings, it only propagates to the parent.

That's still not accurate:

- the serdev device is not a child (but a grandchild) of the serial controller
- the new serial port devices are not "siblings" (but descendants) of the serial controller
- the serdev controller ignores the power state of its children so that bit is also incorrect

Quoted 3 lines

You just want to describe the fact that the serdev controller runtime PM state is currently not propagated to your new "devices" that are descendants to the serial controller.

Quoted 5 lines

OK so let's just use:

The serdev controller runtime PM state is not currently propagated to the serial core controller port device. The runtime PM usage count only propagates to the parent device.

That sounds better.

Quoted 6 lines
Quoted 2 lines

I'm still not sure why it was implemented this way, or if it is even correct, but this seems to be the state of things.

Care to clarify a bit which parts are unclear? The hierarchy of port devices, making serial core manage runtime PM in a generic way, or flushing tx?

I still don't know why you added these two new abstractions (controller and port), and that isn't really explained by the commit message either. And if these are indeed needed, then why isn't the serdev controller now a child of the "port" device, for example?

There are just a lot of questions and I worry that there are more problems lurking, but unfortunately I still don't have time to review this.

Johan

#6 lore raw
Quoted 8 lines · Johan Hovold
Quoted 5 lines · Tony Lindgren

OK so let's just use:

The serdev controller runtime PM state is not currently propagated to the serial core controller port device. The runtime PM usage count only propagates to the parent device.

That sounds better.

OK

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

I'm still not sure why it was implemented this way, or if it is even correct, but this seems to be the state of things.

Care to clarify a bit which parts are unclear? The hierarchy of port devices, making serial core manage runtime PM in a generic way, or flushing tx?

I still don't know why you added these two new abstractions (controller and port), and that isn't really explained by the commit message either.

We want serial core to do runtime PM in a generic way and have the usage count propagate to the parent serial port hardware device. This way we don't need to care much if the numerous serial port drivers implement runtime PM or not. Well, except for now we need to check the parent state for this fix :)

We also want serial core to know the serial port to serial port hardware mapping as we already have multiport devices. The serial core controller is there to group the serial ports for each serial port hardware device. We at least now have an option to support devices with multiple controllers and ports in case we ever happen to see such things.

Quoted 2 lines

And if these are indeed needed, then why isn't the serdev controller now a child of the "port" device, for example?

Yes I agree we should now move serdev controller to be a child of the serial core port device. Then this $subject patch can be reverted.

Moving serdev controller should also help serdev to deal with multiport devices I think?

In the long run serial port specific functions could live there too.

Quoted 3 lines

There are just a lot of questions and I worry that there are more problems lurking, but unfortunately I still don't have time to review this.

Well incremental steps should be easier to do now.

Regards,

Tony

#7 lore raw
Quoted 7 lines · Tony Lindgren
Quoted 6 lines · Johan Hovold
Quoted 3 lines · Tony Lindgren

Care to clarify a bit which parts are unclear? The hierarchy of port devices, making serial core manage runtime PM in a generic way, or flushing tx?

Quoted 8 lines
Quoted 2 lines

I still don't know why you added these two new abstractions (controller and port), and that isn't really explained by the commit message either.

We want serial core to do runtime PM in a generic way and have the usage count propagate to the parent serial port hardware device. This way we don't need to care much if the numerous serial port drivers implement runtime PM or not. Well, except for now we need to check the parent state for this fix :)

That sounds like a lot of complexity to avoid checking if (the single instance of) pm_runtime_get() returns -EACCESS.

Quoted 5 lines

We also want serial core to know the serial port to serial port hardware mapping as we already have multiport devices. The serial core controller is there to group the serial ports for each serial port hardware device. We at least now have an option to support devices with multiple controllers and ports in case we ever happen to see such things.

Hypothetical multiple serial controllers should be modelled as separate controllers, but yeah, perhaps we want to describe the ports.

Quoted 8 lines
Quoted 2 lines

And if these are indeed needed, then why isn't the serdev controller now a child of the "port" device, for example?

Yes I agree we should now move serdev controller to be a child of the serial core port device. Then this $subject patch can be reverted.

Moving serdev controller should also help serdev to deal with multiport devices I think?

It wouldn't help currently I think, since we already resume the controller and don't manage ports individually, but if we now have port devices then it probably should be moved.

Johan

#8 lore raw
Quoted 11 lines · Johan Hovold
Quoted 10 lines · Tony Lindgren
Quoted 8 lines · Johan Hovold
Quoted 3 lines · Tony Lindgren

Care to clarify a bit which parts are unclear? The hierarchy of port devices, making serial core manage runtime PM in a generic way, or flushing tx?

I still don't know why you added these two new abstractions (controller and port), and that isn't really explained by the commit message either.

Quoted 8 lines
Quoted 5 lines

We want serial core to do runtime PM in a generic way and have the usage count propagate to the parent serial port hardware device. This way we don't need to care much if the numerous serial port drivers implement runtime PM or not. Well, except for now we need to check the parent state for this fix :)

That sounds like a lot of complexity to avoid checking if (the single instance of) pm_runtime_get() returns -EACCESS.

Yes only one call so far. but we have the serial core generic PM patch(es) from Andy and Ilpo that are still coming.

Quoted 8 lines
Quoted 5 lines

We also want serial core to know the serial port to serial port hardware mapping as we already have multiport devices. The serial core controller is there to group the serial ports for each serial port hardware device. We at least now have an option to support devices with multiple controllers and ports in case we ever happen to see such things.

Hypothetical multiple serial controllers should be modelled as separate controllers, but yeah, perhaps we want to describe the ports.

Yes and we already have multiport controllers.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

And if these are indeed needed, then why isn't the serdev controller now a child of the "port" device, for example?

Yes I agree we should now move serdev controller to be a child of the serial core port device. Then this $subject patch can be reverted.

Quoted 6 lines
Quoted 2 lines

Moving serdev controller should also help serdev to deal with multiport devices I think?

It wouldn't help currently I think, since we already resume the controller and don't manage ports individually, but if we now have port devices then it probably should be moved.

I'll post a patch for that after some more checks.

Regards,

Tony