Skip to contentSkip to conversation

driver core: disable device's runtime pm during shutdown

PATCH In review Peter Chen 7 participants 30 messages Nov 14, 2011 – Dec 6, 2011 Driver core

lore
Share & tools
lore

Peter Chen

author
#0 lore raw

PATCH 1/1 driver core: disable device's runtime pm during shutdown

There may be an issue when the user issue "reboot/shutdown" command, then the device has shut down its hardware, after that, this runtime-pm featured device's driver will probably be scheduled to do its suspend routine, and at its suspend routine, it may access hardware, but the device has already shutdown physically, then the system hang may be occurred.

I ran out this issue using an auto-suspend supported USB devices, like 3G modem, keyboard. The usb runtime suspend routine may be scheduled after the usb controller has been shut down, and the usb runtime suspend routine will try to suspend its roothub(controller), it will access register, then the system hang occurs as the controller is shutdown.

---
 drivers/base/core.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/base/core.c +3 -0
index bc8729d..78445f4 100644
@@ -22,6 +22,7 @@
 #include <linux/kallsyms.h>
 #include <linux/mutex.h>
 #include <linux/async.h>
+#include <linux/pm_runtime.h>
 
 #include "base.h"
 #include "power/power.h"
@@ -1742,6 +1743,8 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
+		/* Disable all device's runtime power management */
+		pm_runtime_disable(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");
Signature · 1 line
1.7.1
#1 lore raw

Hi,

Quoted 6 lines · Peter Chen

There may be an issue when the user issue "reboot/shutdown" command, then the device has shut down its hardware, after that, this runtime-pm featured device's driver will probably be scheduled to do its suspend routine, and at its suspend routine, it may access hardware, but the device has already shutdown physically, then the system hang may be occurred.

Quoted 6 lines

I ran out this issue using an auto-suspend supported USB devices, like 3G modem, keyboard. The usb runtime suspend routine may be scheduled after the usb controller has been shut down, and the usb runtime suspend routine will try to suspend its roothub(controller), it will access register, then the system hang occurs as the controller is shutdown.

This patch should make many guys happy about shutdown/reboot function, at least fix the reboot issue on my panda board, maybe CC [email protected] is needed, :-)

Quoted 29 lines

---
 drivers/base/core.c |    3 +++

 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/base/core.c +3 -1
index bc8729d..78445f4 100644
@@ -22,6 +22,7 @@
  #include <linux/kallsyms.h>
  #include <linux/mutex.h>
  #include <linux/async.h>
+#include <linux/pm_runtime.h>
 
  #include "base.h"
  #include "power/power.h"
@@ -1742,6 +1743,8 @@ void device_shutdown(void)
                 */
                list_del_init(&dev->kobj.entry);
                spin_unlock(&devices_kset->list_lock);
+               /* Disable all device's runtime power management */
+               pm_runtime_disable(dev);
 
                if (dev->bus && dev->bus->shutdown) {
                        dev_dbg(dev, "shutdown\n");
--

1.7.1

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

thanks,

Signature · 1 line
Ming Lei
#2 lore raw
Quoted 16 lines · Ming Lei

Hi,

Quoted 6 lines · Peter Chen

There may be an issue when the user issue "reboot/shutdown" command, then the device has shut down its hardware, after that, this runtime-pm featured device's driver will probably be scheduled to do its suspend routine, and at its suspend routine, it may access hardware, but the device has already shutdown physically, then the system hang may be occurred.

Quoted 6 lines

I ran out this issue using an auto-suspend supported USB devices, like 3G modem, keyboard. The usb runtime suspend routine may be scheduled after the usb controller has been shut down, and the usb runtime suspend routine will try to suspend its roothub(controller), it will access register, then the system hang occurs as the controller is shutdown.

Quoted 3 lines

This patch should make many guys happy about shutdown/reboot function, at least fix the reboot issue on my panda board, maybe CC [email protected] is needed, :-)

I'm taking this as an ACK.

Rafael

Quoted 37 lines
Quoted 29 lines
---
 drivers/base/core.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/base/core.c +3 -1
index bc8729d..78445f4 100644
@@ -22,6 +22,7 @@
 #include <linux/kallsyms.h>
 #include <linux/mutex.h>
 #include <linux/async.h>
+#include <linux/pm_runtime.h>
 
 #include "base.h"
 #include "power/power.h"
@@ -1742,6 +1743,8 @@ void device_shutdown(void)
                */
               list_del_init(&dev->kobj.entry);
               spin_unlock(&devices_kset->list_lock);
+               /* Disable all device's runtime power management */
+               pm_runtime_disable(dev);
 
               if (dev->bus && dev->bus->shutdown) {
                       dev_dbg(dev, "shutdown\n");
--

1.7.1

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

thanks,

#3 lore raw
In reply to Peter Chen
Quoted 6 lines · Peter Chen

There may be an issue when the user issue "reboot/shutdown" command, then the device has shut down its hardware, after that, this runtime-pm featured device's driver will probably be scheduled to do its suspend routine, and at its suspend routine, it may access hardware, but the device has already shutdown physically, then the system hang may be occurred.

Quoted 6 lines

I ran out this issue using an auto-suspend supported USB devices, like 3G modem, keyboard. The usb runtime suspend routine may be scheduled after the usb controller has been shut down, and the usb runtime suspend routine will try to suspend its roothub(controller), it will access register, then the system hang occurs as the controller is shutdown.

Greg, do you want me to take this one?

Rafael

Quoted 26 lines
---
 drivers/base/core.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/base/core.c +3 -0
index bc8729d..78445f4 100644
@@ -22,6 +22,7 @@
 #include <linux/kallsyms.h>
 #include <linux/mutex.h>
 #include <linux/async.h>
+#include <linux/pm_runtime.h>
 
 #include "base.h"
 #include "power/power.h"
@@ -1742,6 +1743,8 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
+		/* Disable all device's runtime power management */
+		pm_runtime_disable(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");
Acked-by Greg Kroah-Hartman
#4 lore raw
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Peter Chen

There may be an issue when the user issue "reboot/shutdown" command, then the device has shut down its hardware, after that, this runtime-pm featured device's driver will probably be scheduled to do its suspend routine, and at its suspend routine, it may access hardware, but the device has already shutdown physically, then the system hang may be occurred.

Quoted 8 lines
Quoted 6 lines

I ran out this issue using an auto-suspend supported USB devices, like 3G modem, keyboard. The usb runtime suspend routine may be scheduled after the usb controller has been shut down, and the usb runtime suspend routine will try to suspend its roothub(controller), it will access register, then the system hang occurs as the controller is shutdown.

Greg, do you want me to take this one?

Please do:

thanks,

greg k-h

#5 lore raw
Quoted 15 lines · Greg KH
Quoted 14 lines · Rafael J. Wysocki
Quoted 12 lines · Peter Chen

There may be an issue when the user issue "reboot/shutdown" command, then the device has shut down its hardware, after that, this runtime-pm featured device's driver will probably be scheduled to do its suspend routine, and at its suspend routine, it may access hardware, but the device has already shutdown physically, then the system hang may be occurred.

I ran out this issue using an auto-suspend supported USB devices, like 3G modem, keyboard. The usb runtime suspend routine may be scheduled after the usb controller has been shut down, and the usb runtime suspend routine will try to suspend its roothub(controller), it will access register, then the system hang occurs as the controller is shutdown.

Quoted 4 lines
Quoted 1 line

Greg, do you want me to take this one?

Please do:

Done, thanks!

Rafael

#6 lore raw
Quoted 16 lines · On Wed, 16 Nov 2011 00:16:08 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 15 lines · Greg KH
Quoted 14 lines · Rafael J. Wysocki
Quoted 12 lines · Peter Chen

There may be an issue when the user issue "reboot/shutdown" command, then the device has shut down its hardware, after that, this runtime-pm featured device's driver will probably be scheduled to do its suspend routine, and at its suspend routine, it may access hardware, but the device has already shutdown physically, then the system hang may be occurred.

I ran out this issue using an auto-suspend supported USB devices, like 3G modem, keyboard. The usb runtime suspend routine may be scheduled after the usb controller has been shut down, and the usb runtime suspend routine will try to suspend its roothub(controller), it will access register, then the system hang occurs as the controller is shutdown.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Greg, do you want me to take this one?

Please do:

Done, thanks!

Hi,
this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses twl4030 for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend mode. When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake it up, performs the transfer, then calls pm_runtime_put to let it go back to sleep.

So it is asleep when the new pm_runtime_disable() call is made, so it stays asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and the system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.
I don't fully understand the problem scenario described above but it seems to me that if the auto-suspend timer can fire after the hardware has been shut down, then maybe the hardware-shutdown should be disabling that timer. Maybe?

Suggestions?

Thanks,
NeilBrown

#7 lore raw
Quoted 6 lines · NeilBrown

Hi,
this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses twl4030 for power control on an omap3 processor.

Quoted 8 lines

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend mode. When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake it up, performs the transfer, then calls pm_runtime_put to let it go back to sleep.

So it is asleep when the new pm_runtime_disable() call is made, so it stays asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and the system doesn't get powered off.

In other words, to perform the system shutdown you need to send a command over the i2c bus after the bus controller's shutdown routine has been called?

Quoted 1 line

So here is a device that should *not* have pm disabled at shutdown.

Or maybe it shouldn't be shut down at all.

Quoted 4 lines

So I feel this fix is a little too heavy-handed.
I don't fully understand the problem scenario described above but it seems to me that if the auto-suspend timer can fire after the hardware has been shut down, then maybe the hardware-shutdown should be disabling that timer. Maybe?

That's not robust. The timer can be restarted, and there are other ways of initiating runtime PM besides the timer.

Quoted 1 line

Suggestions?

Can the shutdown routine for the i2c controller simply call pm_runtime_enable()?

Alan Stern

#8 lore raw
Quoted 13 lines · On Sun, 4 Dec 2011 21:42:02 -0500 (EST) Alan Stern <[email protected]>…
Quoted 11 lines · NeilBrown

Hi,
this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses twl4030 for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend mode. When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake it up, performs the transfer, then calls pm_runtime_put to let it go back to sleep.

Quoted 7 lines
Quoted 3 lines

So it is asleep when the new pm_runtime_disable() call is made, so it stays asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and the system doesn't get powered off.

In other words, to perform the system shutdown you need to send a command over the i2c bus after the bus controller's shutdown routine has been called?

Correct.
Though in this case the i2c bus doesn't have a shutdown routine so it doesn't cause a problem. It is only the inability to pm_resume that is a problem.

Quoted 4 lines
Quoted 2 lines

So here is a device that should *not* have pm disabled at shutdown.

Or maybe it shouldn't be shut down at all.

Maybe not. Current 'device_shutdown()' shuts down every device. I guess having a "don't shutdown at power-off" flag could be used to solve the problem.

Quoted 8 lines
Quoted 5 lines

So I feel this fix is a little too heavy-handed.
I don't fully understand the problem scenario described above but it seems to me that if the auto-suspend timer can fire after the hardware has been shut down, then maybe the hardware-shutdown should be disabling that timer. Maybe?

That's not robust. The timer can be restarted, and there are other ways of initiating runtime PM besides the timer.

Still, shouldn't they notice that the hardware has been shutdown and so not do anything?

Quoted 5 lines
Quoted 2 lines

Suggestions?

Can the shutdown routine for the i2c controller simply call pm_runtime_enable()?

No.
The shutdown routine is in drivers/mfd/twl4030-power.c (not in mainline currently but there are various patches floating around that add twl4030_poweroff, and this is the obviously-correct place for the code). It has a 'struct i2c_adapter' device.
The device that needs to have pm_runtime_enable called on it is a 'struct platform_device' that is linked through the dev_data of the i2c_adapter.

i.e. only omap-i2c specific code knows how to find the device that needs to be enabled. The twl4030 code doesn't.

So even if we had a used_for_shutdown flag in dev_pm_info I don't know how we would manage to set it for the right device.... unless we had a dev_pm_ops method to ask a device to set it on all devices it depends on. Sounds messy.

Thanks,
NeilBrown

#9 lore raw
In reply to NeilBrown

Hi,

Quoted 12 lines · NeilBrown

Hi,
 this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses twl4030 for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend mode. When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake it up, performs the transfer, then calls pm_runtime_put to let it go back to sleep.

Quoted 7 lines

So it is asleep when the new pm_runtime_disable() call is made, so it stays asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and the system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

drivers/base/core.c +4 -2
index d8b3d89..ca30659 100644
@@ -1743,14 +1743,16 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
 
+		/* Disable the device's runtime power management if
+		 * it is to be shutdown*/
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");
+			pm_runtime_disable(dev);
 			dev->bus->shutdown(dev);
 		} else if (dev->driver && dev->driver->shutdown) {
 			dev_dbg(dev, "shutdown\n");
+			pm_runtime_disable(dev);
 			dev->driver->shutdown(dev);
 		}
 		put_device(dev);
Quoted 8 lines

I don't fully understand the problem scenario described above but it seems to me that if the auto-suspend timer can fire after the hardware has been shut down, then maybe the hardware-shutdown should be disabling that timer.  Maybe?

Suggestions?

Thanks,
NeilBrown

thanks,

Signature · 1 line
Ming Lei
#10 lore raw
Quoted 44 lines
Quoted 5 lines

 this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses

twl4030

Quoted 4 lines

for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend

mode.

Quoted 1 line

When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake

it up,

Quoted 1 line

performs the transfer, then calls pm_runtime_put to let it go back to

sleep.

Quoted 2 lines

So it is asleep when the new pm_runtime_disable() call is made, so it

stays

Quoted 1 line

asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and

the

Quoted 5 lines

system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

drivers/base/core.c +2 -2
index d8b3d89..ca30659 100644
@@ -1743,14 +1743,16 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
 
+		/* Disable the device's runtime power management if
+		 * it is to be shutdown*/

drivers/base/core.c void device_shutdown(void) · line 1758

Quoted 10 lines
drivers/base/core.c +2 -0
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");
+			pm_runtime_disable(dev);
 			dev->bus->shutdown(dev);
 		} else if (dev->driver && dev->driver->shutdown) {
 			dev_dbg(dev, "shutdown\n");
+			pm_runtime_disable(dev);
 			dev->driver->shutdown(dev);
 		}
 		put_device(dev);

Yes, it is the solution for Neil's case, but I am not sure for all. Is it possible to resume driver's itself at driver's shutdown?

Quoted 16 lines
Quoted 1 line

I don't fully understand the problem scenario described above but it

seems to

Quoted 1 line

me that if the auto-suspend timer can fire after the hardware has been

shut

Quoted 1 line

down, then maybe the hardware-shutdown should be disabling that

timer.  Maybe?

Quoted 5 lines

Suggestions?

Thanks,
NeilBrown

thanks,
--
Ming Lei

#11 lore raw

Hi,

Quoted 40 lines · On Mon, Dec 5, 2011 at 12:42 PM, Chen Peter-B29397 <[email protected]> wrote:
Quoted 40 lines
Quoted 5 lines

 this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses

twl4030

Quoted 4 lines

for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend

mode.

Quoted 1 line

When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake

it up,

Quoted 1 line

performs the transfer, then calls pm_runtime_put to let it go back to

sleep.

Quoted 2 lines

So it is asleep when the new pm_runtime_disable() call is made, so it

stays

Quoted 1 line

asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and

the

Quoted 5 lines

system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

drivers/base/core.c +0 -2
index d8b3d89..ca30659 100644
@@ -1743,14 +1743,16 @@ void device_shutdown(void)
                */
               list_del_init(&dev->kobj.entry);
               spin_unlock(&devices_kset->list_lock);
-             /* Disable all device's runtime power management */
-             pm_runtime_disable(dev);
 
Quoted 16 lines
Quoted 4 lines
drivers/base/core.c +2 -0
+             /* Disable the device's runtime power management if
+              * it is to be shutdown*/

drivers/base/core.c void device_shutdown(void) · line 1758

Quoted 10 lines
drivers/base/core.c +2 -0
               if (dev->bus && dev->bus->shutdown) {
                       dev_dbg(dev, "shutdown\n");
+                     pm_runtime_disable(dev);
                       dev->bus->shutdown(dev);
               } else if (dev->driver && dev->driver->shutdown) {
                       dev_dbg(dev, "shutdown\n");
+                     pm_runtime_disable(dev);
                       dev->driver->shutdown(dev);
               }
               put_device(dev);

Yes, it is the solution for Neil's case, but I am not sure for all. Is it possible to resume driver's itself at driver's shutdown?

Looks like this way is still not good. Maybe we should put all device into active state first, then set its runtime pm as disabled.

thanks,

Signature · 1 line
Ming Lei
#12 lore raw

Hi,

Quoted 60 lines · Ming Lei

Hi,

Quoted 40 lines · On Mon, Dec 5, 2011 at 12:42 PM, Chen Peter-B29397 <[email protected]> wrote:
Quoted 40 lines
Quoted 5 lines

 this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses

twl4030

Quoted 4 lines

for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend

mode.

Quoted 1 line

When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake

it up,

Quoted 1 line

performs the transfer, then calls pm_runtime_put to let it go back to

sleep.

Quoted 2 lines

So it is asleep when the new pm_runtime_disable() call is made, so it

stays

Quoted 1 line

asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and

the

Quoted 5 lines

system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

drivers/base/core.c +0 -2
index d8b3d89..ca30659 100644
@@ -1743,14 +1743,16 @@ void device_shutdown(void)
                */
               list_del_init(&dev->kobj.entry);
               spin_unlock(&devices_kset->list_lock);
-             /* Disable all device's runtime power management */
-             pm_runtime_disable(dev);
 
Quoted 16 lines
Quoted 4 lines
drivers/base/core.c +2 -0
+             /* Disable the device's runtime power management if
+              * it is to be shutdown*/

drivers/base/core.c void device_shutdown(void) · line 1758

Quoted 10 lines
drivers/base/core.c +2 -0
               if (dev->bus && dev->bus->shutdown) {
                       dev_dbg(dev, "shutdown\n");
+                     pm_runtime_disable(dev);
                       dev->bus->shutdown(dev);
               } else if (dev->driver && dev->driver->shutdown) {
                       dev_dbg(dev, "shutdown\n");
+                     pm_runtime_disable(dev);
                       dev->driver->shutdown(dev);
               }
               put_device(dev);

Yes, it is the solution for Neil's case, but I am not sure for all. Is it possible to resume driver's itself at driver's shutdown?

Quoted 2 lines

Looks like this way is still not good. Maybe we should put all device into active state first, then set its runtime pm as disabled.

Below patch should a simple fix on the issue, but it may prolong shutdown/reboot time.

drivers/base/core.cindex renamed from drivers/base/core.c +0 -0

d8b3d89..96b266c 100644--- a/drivers/base/core.c+++ b/drivers/base/core.c@@ -1743,8 +1743,9 @@ void device_shutdown(void)

		 */ 		list_del_init(&dev->kobj.entry);
		spin_unlock(&devices_kset->list_lock);-		/* Disable all device's
runtime power management */-		pm_runtime_disable(dev);++		/* put
device into active state and forbid runtime pm
*/+		pm_runtime_forbid(dev);  		if (dev->bus && dev->bus->shutdown) {
			dev_dbg(dev, "shutdown\n");

thanks,

Signature · 1 line
Ming Lei
#13 lore raw

Hi,

Quoted 65 lines · Ming Lei
Quoted 57 lines
Quoted 40 lines
Quoted 40 lines
Quoted 5 lines

 this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses

twl4030

Quoted 4 lines

for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend

mode.

Quoted 1 line

When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake

it up,

Quoted 1 line

performs the transfer, then calls pm_runtime_put to let it go back to

sleep.

Quoted 2 lines

So it is asleep when the new pm_runtime_disable() call is made, so it

stays

Quoted 1 line

asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and

the

Quoted 5 lines

system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

drivers/base/core.c +0 -2
index d8b3d89..ca30659 100644
@@ -1743,14 +1743,16 @@ void device_shutdown(void)
                */
               list_del_init(&dev->kobj.entry);
               spin_unlock(&devices_kset->list_lock);
-             /* Disable all device's runtime power management */
-             pm_runtime_disable(dev);
 
Quoted 16 lines
Quoted 4 lines
drivers/base/core.c +2 -0
+             /* Disable the device's runtime power management if
+              * it is to be shutdown*/

drivers/base/core.c void device_shutdown(void) · line 1758

Quoted 10 lines
drivers/base/core.c +2 -0
               if (dev->bus && dev->bus->shutdown) {
                       dev_dbg(dev, "shutdown\n");
+                     pm_runtime_disable(dev);
                       dev->bus->shutdown(dev);
               } else if (dev->driver && dev->driver->shutdown) {
                       dev_dbg(dev, "shutdown\n");
+                     pm_runtime_disable(dev);
                       dev->driver->shutdown(dev);
               }
               put_device(dev);

Yes, it is the solution for Neil's case, but I am not sure for all. Is it possible to resume driver's itself at driver's shutdown?

Quoted 2 lines

Looks like this way is still not good. Maybe we should put all device into active state first, then set its runtime pm as disabled.

Below patch should a simple fix on the issue, but it may prolong shutdown/reboot time.

drivers/base/core.cindex renamed from drivers/base/core.c +0 -0
Quoted 8 lines

d8b3d89..96b266c 100644--- a/drivers/base/core.c+++
b/drivers/base/core.c@@ -1743,8 +1743,9 @@ void device_shutdown(void)
                */             list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock);-         /* Disable all device's runtime power management */-            pm_runtime_disable(dev);++              /* put device into active state and forbid runtime pm
*/+             pm_runtime_forbid(dev);                 if (dev->bus && dev->bus->shutdown) { dev_dbg(dev, "shutdown\n");

,
Sorry, the above is line wrapped badly, see the below:

drivers/base/core.c +3 -2
index d8b3d89..96b266c 100644
@@ -1743,8 +1743,9 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
+
+		/* put device into active state and forbit runtime pm */
+		pm_runtime_forbid(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");

thanks,

Signature · 1 line
Ming Lei
#14 lore raw
Quoted 8 lines · Ming Lei

Sorry, the above is line wrapped badly, see the below:

drivers/base/core.c +0 -0
index d8b3d89..96b266c 100644
@@ -1743,8 +1743,9 @@ void device_shutdown(void)
 		 */

drivers/base/core.c void device_shutdown(void) · line 1751

Quoted 10 lines
drivers/base/core.c +3 -2
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
+
+		/* put device into active state and forbit runtime pm */
+		pm_runtime_forbid(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");

We don't want to put devices into the active state when it's not necessary. A better approach would be:

		/* Don't allow any more runtime suspends */
		pm_runtime_get_noresume(dev);
		pm_runtime_barrier(dev);

Alan Stern

#15 lore raw
Quoted 24 lines · On Mon, 5 Dec 2011 11:02:38 -0500 (EST) Alan Stern <[email protected]>…
Quoted 8 lines · Ming Lei

Sorry, the above is line wrapped badly, see the below:

drivers/base/core.c +0 -0
index d8b3d89..96b266c 100644
@@ -1743,8 +1743,9 @@ void device_shutdown(void)
 		 */

drivers/base/core.c void device_shutdown(void) · line 1751

Quoted 10 lines
drivers/base/core.c +3 -2
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
+
+		/* put device into active state and forbit runtime pm */
+		pm_runtime_forbid(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");

We don't want to put devices into the active state when it's not necessary. A better approach would be:

Quoted 5 lines
		/* Don't allow any more runtime suspends */
		pm_runtime_get_noresume(dev);
		pm_runtime_barrier(dev);

Alan Stern

That sounds like a reasonable approach if we really need to do something at this level. But is this the only place that ->shutdown methods are called from? If they are called from elsewhere, would those places need the same pm_runtime protection?

BTW I was wrong when I said that only calling pm_runtime_disable if there was a ->shutdown function would not work for me. i.e. the following patch does solve my particular issue (though I'm not sure it is "right").
I was getting confused by the two different devices: the i2c device and the platform device.
The i2c device has a ->shutdown which does nothing, but doesn't need to wake up.
The platform device is the one which needs to wake up, but it doesn't have a ->shutdown function is this patch causes it not have pm_runtime disabled.

Thanks,
NeilBrown

drivers/base/core.c +2 -2
index d8b3d89..b9aa5d2 100644
@@ -1743,13 +1743,13 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
+			pm_runtime_disable(dev);
 			dev_dbg(dev, "shutdown\n");
 			dev->bus->shutdown(dev);
 		} else if (dev->driver && dev->driver->shutdown) {
+			pm_runtime_disable(dev);
 			dev_dbg(dev, "shutdown\n");
 			dev->driver->shutdown(dev);
 		}
#16 lore raw
Quoted 7 lines · NeilBrown
Quoted 7 lines

We don't want to put devices into the active state when it's not necessary. A better approach would be:

		/* Don't allow any more runtime suspends */
		pm_runtime_get_noresume(dev);
		pm_runtime_barrier(dev);
Quoted 6 lines
Quoted 1 line

Alan Stern

That sounds like a reasonable approach if we really need to do something at this level. But is this the only place that ->shutdown methods are called from? If they are called from elsewhere, would those places need the same pm_runtime protection?

I don't know if shutdown methods are called from anywhere else, but they shouldn't be. The kerneldoc for struct bus_type plainly says:

* @shutdown: Called at shut-down time to quiesce the device.

Quoted 23 lines

BTW I was wrong when I said that only calling pm_runtime_disable if there was a ->shutdown function would not work for me. i.e. the following patch does solve my particular issue (though I'm not sure it is "right").
I was getting confused by the two different devices: the i2c device and the platform device.
The i2c device has a ->shutdown which does nothing, but doesn't need to wake up.
The platform device is the one which needs to wake up, but it doesn't have a ->shutdown function is this patch causes it not have pm_runtime disabled.

Thanks,
NeilBrown

drivers/base/core.c +0 -2
index d8b3d89..b9aa5d2 100644
@@ -1743,13 +1743,13 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);

drivers/base/core.c void device_shutdown(void) · line 1755

Quoted 10 lines
drivers/base/core.c +2 -0
 
 		if (dev->bus && dev->bus->shutdown) {
+			pm_runtime_disable(dev);
 			dev_dbg(dev, "shutdown\n");
 			dev->bus->shutdown(dev);
 		} else if (dev->driver && dev->driver->shutdown) {
+			pm_runtime_disable(dev);
 			dev_dbg(dev, "shutdown\n");
 			dev->driver->shutdown(dev);
 		}

Still, it's quite conceivable that a shutdown routine might want to resume a device that had been runtime-suspended. Disabling runtime PM for that device would prevent the routine from doing its work.

The original problem the $SUBJECT patch was meant to solve was that a runtime-PM suspend method was called after the shutdown routine had run. Doing a runtime_pm_get_noresume() ought to solve this.

There still remains the possibility of a runtime resume method being called after the shutdown routine. So far nobody has complained about that happening except you -- and your complaint was that it didn't work, not that it shouldn't happen. But if necessary, individual drivers could add pm_runtime_disable() calls to their shutdown routines.

Alan Stern

#17 lore raw
Quoted 8 lines · Alan Stern
Quoted 6 lines · NeilBrown
Quoted 6 lines

We don't want to put devices into the active state when it's not necessary. A better approach would be:

		/* Don't allow any more runtime suspends */
		pm_runtime_get_noresume(dev);
		pm_runtime_barrier(dev);

That's exactly what we do during system suspend and I _really_ think it's not a good idea to do anything different (given that the original "disable" idea didn't work), because that may result in serious amount of confusion.

Quoted 3 lines
Quoted 3 lines

That sounds like a reasonable approach if we really need to do something at this level.

We do.

Quoted 8 lines
Quoted 3 lines

But is this the only place that ->shutdown methods are called from? If they are called from elsewhere, would those places need the same pm_runtime protection?

I don't know if shutdown methods are called from anywhere else, but they shouldn't be. The kerneldoc for struct bus_type plainly says:

* @shutdown: Called at shut-down time to quiesce the device.

It's a bug to run the shutdown callback in any other situation.

Quoted 38 lines
Quoted 23 lines

BTW I was wrong when I said that only calling pm_runtime_disable if there was a ->shutdown function would not work for me. i.e. the following patch does solve my particular issue (though I'm not sure it is "right").
I was getting confused by the two different devices: the i2c device and the platform device.
The i2c device has a ->shutdown which does nothing, but doesn't need to wake up.
The platform device is the one which needs to wake up, but it doesn't have a ->shutdown function is this patch causes it not have pm_runtime disabled.

Thanks,
NeilBrown

drivers/base/core.c +0 -2
index d8b3d89..b9aa5d2 100644
@@ -1743,13 +1743,13 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);

drivers/base/core.c void device_shutdown(void) · line 1755

Quoted 10 lines
drivers/base/core.c +2 -0
 
 		if (dev->bus && dev->bus->shutdown) {
+			pm_runtime_disable(dev);
 			dev_dbg(dev, "shutdown\n");
 			dev->bus->shutdown(dev);
 		} else if (dev->driver && dev->driver->shutdown) {
+			pm_runtime_disable(dev);
 			dev_dbg(dev, "shutdown\n");
 			dev->driver->shutdown(dev);
 		}

Still, it's quite conceivable that a shutdown routine might want to resume a device that had been runtime-suspended. Disabling runtime PM for that device would prevent the routine from doing its work.

Quoted 3 lines

The original problem the $SUBJECT patch was meant to solve was that a runtime-PM suspend method was called after the shutdown routine had run. Doing a runtime_pm_get_noresume() ought to solve this.

That's correct.

Quoted 6 lines

There still remains the possibility of a runtime resume method being called after the shutdown routine. So far nobody has complained about that happening except you -- and your complaint was that it didn't work, not that it shouldn't happen. But if necessary, individual drivers could add pm_runtime_disable() calls to their shutdown routines.

I agree.

The whole problem is that .shutdown() had been there before the PM callbacks were added (let alone runtime PM) and it pretty much duplicates .pm->poweroff(). Also, it doesn't handle the case when the _noirq() callbacks are necessary (although it's very hard to trigger in practice, if possible at all).

Anyway, since .shutdown() is quite analogous to .pm->poweroff(), the core should treat them both consistently and do the same to synchronize with runtime PM before calling them. Whatever is needed beyond that, should be done by drivers and subsystems.

So, Alan, can you please post a patch implementing your proposed approach against the current Linus' tree?

Rafael

#18 lore raw

PATCH 1/1 Driver core: leave runtime PM enabled during system shutdown

Disabling all runtime PM during system shutdown turns out not to be a good idea, because some devices may need to be woken up from a low-power state at that time.

The whole point of disabling runtime PM for system shutdown was to prevent untimely runtime-suspend method calls. This patch (as1504) accomplishes the same result by incrementing the usage count for each device and waiting for ongoing runtime-PM callbacks to finish. This is what we already do during system suspend and hibernation, which makes sense since the shutdown method is pretty much a legacy analog of the pm->poweroff method.

This fixes a regression on some OMAP systems.

---

 drivers/base/core.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/base/core.c +4 -2
Index: usb-3.2/drivers/base/core.c
===================================================================
@@ -1743,8 +1743,10 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
+
+		/* Don't allow any more runtime suspends */
+		pm_runtime_get_noresume(dev);
+		pm_runtime_barrier(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");
Tested-by on v1 1/1
#19 lore raw

Re: [PATCH] Driver core: leave runtime PM enabled during system shutdown

Quoted 30 lines · On Tue, 6 Dec 2011 10:26:14 -0500 (EST) Alan Stern <[email protected]>…

Disabling all runtime PM during system shutdown turns out not to be a good idea, because some devices may need to be woken up from a low-power state at that time.

The whole point of disabling runtime PM for system shutdown was to prevent untimely runtime-suspend method calls. This patch (as1504) accomplishes the same result by incrementing the usage count for each device and waiting for ongoing runtime-PM callbacks to finish. This is what we already do during system suspend and hibernation, which makes sense since the shutdown method is pretty much a legacy analog of the pm->poweroff method.

This fixes a regression on some OMAP systems.

---

 drivers/base/core.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: usb-3.2/drivers/base/core.c
===================================================================

drivers/base/core.c +0 -0
@@ -1743,8 +1743,10 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);

drivers/base/core.c void device_shutdown(void) · line 1752

Quoted 10 lines
drivers/base/core.c +4 -2
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
+
+		/* Don't allow any more runtime suspends */
+		pm_runtime_get_noresume(dev);
+		pm_runtime_barrier(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");

Thanks a lot.
I can confirm that this definitely fixes my problem.

Thanks for your help!

NeilBrown

Acked-by Greg Kroah-Hartman on v1 1/1
#20 lore raw

Re: [PATCH] Driver core: leave runtime PM enabled during system shutdown

In reply to Alan Stern
Quoted 12 lines · Alan Stern

Disabling all runtime PM during system shutdown turns out not to be a good idea, because some devices may need to be woken up from a low-power state at that time.

The whole point of disabling runtime PM for system shutdown was to prevent untimely runtime-suspend method calls. This patch (as1504) accomplishes the same result by incrementing the usage count for each device and waiting for ongoing runtime-PM callbacks to finish. This is what we already do during system suspend and hibernation, which makes sense since the shutdown method is pretty much a legacy analog of the pm->poweroff method.

Quoted 5 lines

This fixes a regression on some OMAP systems.

Rafael, you will take this in your tree, right?

#21 lore raw

Re: [PATCH] Driver core: leave runtime PM enabled during system shutdown

Quoted 15 lines · Greg KH
Quoted 14 lines · Alan Stern

Disabling all runtime PM during system shutdown turns out not to be a good idea, because some devices may need to be woken up from a low-power state at that time.

The whole point of disabling runtime PM for system shutdown was to prevent untimely runtime-suspend method calls. This patch (as1504) accomplishes the same result by incrementing the usage count for each device and waiting for ongoing runtime-PM callbacks to finish. This is what we already do during system suspend and hibernation, which makes sense since the shutdown method is pretty much a legacy analog of the pm->poweroff method.

This fixes a regression on some OMAP systems.

Quoted 7 lines
Quoted 3 lines

Rafael, you will take this in your tree, right?

Yes, I will, thanks!

#22 lore raw

Re: [PATCH] Driver core: leave runtime PM enabled during system shutdown

In reply to Alan Stern
Quoted 12 lines · Alan Stern

Disabling all runtime PM during system shutdown turns out not to be a good idea, because some devices may need to be woken up from a low-power state at that time.

The whole point of disabling runtime PM for system shutdown was to prevent untimely runtime-suspend method calls. This patch (as1504) accomplishes the same result by incrementing the usage count for each device and waiting for ongoing runtime-PM callbacks to finish. This is what we already do during system suspend and hibernation, which makes sense since the shutdown method is pretty much a legacy analog of the pm->poweroff method.

Quoted 5 lines

This fixes a regression on some OMAP systems.

Greg, do you have any objections against this patch and, if you don't, would you mind if I took it (it fixes one that went in through my tree).

Thanks,
Rafael

Quoted 29 lines

---

 drivers/base/core.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: usb-3.2/drivers/base/core.c
===================================================================

drivers/base/core.c +4 -3
@@ -1743,8 +1743,10 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
+
+		/* Don't allow any more runtime suspends */
+		pm_runtime_get_noresume(dev);
+		pm_runtime_barrier(dev);
 
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");
 
--

To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#23 lore raw
In reply to Ming Lei
Quoted 19 lines · On Mon, 5 Dec 2011 11:26:40 +0800 Ming Lei <[email protected]> wrote:

Hi,

Quoted 16 lines · NeilBrown

Hi,
 this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses twl4030 for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend mode. When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake it up, performs the transfer, then calls pm_runtime_put to let it go back to sleep.

So it is asleep when the new pm_runtime_disable() call is made, so it stays asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and the system doesn't get powered off.

Quoted 6 lines
Quoted 3 lines

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

Thanks, but that won't actually help.

dev->bus->shutdown is i2c_device_shutdown so there is a shutdown method. However i2c_device_shutdown just finds the driver can calls driver->shutdown(), and that is the 'shutdown' that is NULL.

Thanks,
NeilBrown

Quoted 37 lines
drivers/base/core.c +4 -2
index d8b3d89..ca30659 100644
@@ -1743,14 +1743,16 @@ void device_shutdown(void)
 		 */
 		list_del_init(&dev->kobj.entry);
 		spin_unlock(&devices_kset->list_lock);
-		/* Disable all device's runtime power management */
-		pm_runtime_disable(dev);
 
+		/* Disable the device's runtime power management if
+		 * it is to be shutdown*/
 		if (dev->bus && dev->bus->shutdown) {
 			dev_dbg(dev, "shutdown\n");
+			pm_runtime_disable(dev);
 			dev->bus->shutdown(dev);
 		} else if (dev->driver && dev->driver->shutdown) {
 			dev_dbg(dev, "shutdown\n");
+			pm_runtime_disable(dev);
 			dev->driver->shutdown(dev);
 		}
 		put_device(dev);
Quoted 10 lines

I don't fully understand the problem scenario described above but it seems to me that if the auto-suspend timer can fire after the hardware has been shut down, then maybe the hardware-shutdown should be disabling that timer.  Maybe?

Suggestions?

Thanks,
NeilBrown

thanks,

#24 lore raw
Quoted 12 lines
Quoted 3 lines
Quoted 3 lines

So it is asleep when the new pm_runtime_disable() call is made, so it

stays

Quoted 1 line
Quoted 1 line

asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and

the

Quoted 6 lines
Quoted 5 lines

system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.

Quoted 9 lines
Quoted 2 lines

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

Thanks, but that won't actually help.

dev->bus->shutdown is i2c_device_shutdown so there is a shutdown method. However i2c_device_shutdown just finds the driver can calls driver->shutdown(), and that is the 'shutdown' that is NULL.

Then, i2c should be registered before than twl4030 as a platform device, since twl4030 is an i2c device. Just let i2c shut down later than twl4030's.

Quoted 5 lines

Thanks,
NeilBrown

#25 lore raw
Quoted 15 lines · On Mon, 5 Dec 2011 05:53:27 +0000 Chen Peter-B29397 <[email protected]>…
Quoted 15 lines
Quoted 3 lines
Quoted 3 lines

So it is asleep when the new pm_runtime_disable() call is made, so it

stays

Quoted 1 line
Quoted 1 line

asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and

the

Quoted 8 lines
Quoted 5 lines

system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

Quoted 8 lines
Quoted 6 lines

Thanks, but that won't actually help.

dev->bus->shutdown is i2c_device_shutdown so there is a shutdown method. However i2c_device_shutdown just finds the driver can calls driver->shutdown(), and that is the 'shutdown' that is NULL.

Then, i2c should be registered before than twl4030 as a platform device, since twl4030 is an i2c device. Just let i2c shut down later than twl4030's.

It almost certainly is, but that is totally irrelevant.

The problem has nothing to do with ordering and nothing much to do with ->shutdown() being called.

The problem is simply that pm_runtime_disable() is being called on all devices, and that stops devices that are asleep from waking up.

I think the intention of putting that call in was to stop devices that are awake from going to sleep, and maybe that is justified. But stopping devices that are asleep from waking up isn't.

NeilBrown

Quoted 6 lines
Quoted 6 lines

Thanks,
NeilBrown

#26 lore raw
Quoted 26 lines
Quoted 3 lines
Quoted 3 lines

stays

Quoted 1 line
Quoted 1 line

asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen

and

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines

system doesn't get powered off.

So here is a device that should *not* have pm disabled at

shutdown.

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

Thanks, but that won't actually help.

dev->bus->shutdown is i2c_device_shutdown so there is a shutdown

method.

Quoted 4 lines
Quoted 3 lines

However i2c_device_shutdown just finds the driver can calls driver->shutdown(), and that is the 'shutdown' that is NULL.

Then, i2c should be registered before than twl4030 as a platform device,

since

Quoted 1 line

twl4030 is an i2c device. Just let i2c shut down later than twl4030's.

Quoted 8 lines

It almost certainly is, but that is totally irrelevant.

The problem has nothing to do with ordering and nothing much to do with ->shutdown() being called.

The problem is simply that pm_runtime_disable() is being called on all devices, and that stops devices that are asleep from waking up.

Please correct me if I am wrong
1. This change only affects when the user issues "reboot" or "shutdown"
2. The pm_runtime_disable(dev) is only be called before this "dev" is coming to shutdown
3. If i2c bus/driver->shutdown is not called, its runtime pm is still enabled.
4. You may issue i2c xfer after i2c bus/driver->shutdown is called.

Quoted 15 lines

I think the intention of putting that call in was to stop devices that are
awake from going to sleep, and maybe that is justified. But stopping devices
that are asleep from waking up isn't.

NeilBrown

Quoted 6 lines
Quoted 6 lines

Thanks,
NeilBrown

#27 lore raw
Quoted 28 lines · On Mon, 5 Dec 2011 08:32:27 +0000 Chen Peter-B29397 <[email protected]>…
Quoted 28 lines
Quoted 3 lines
Quoted 3 lines

stays

Quoted 1 line
Quoted 1 line

asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen

and

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines

system doesn't get powered off.

So here is a device that should *not* have pm disabled at

shutdown.

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

So I feel this fix is a little too heavy-handed.

Maybe the device's runtime PM should not be disabled if there is no ->shutdown defined in its driver, how about the blew?

Thanks, but that won't actually help.

dev->bus->shutdown is i2c_device_shutdown so there is a shutdown

method.

Quoted 4 lines
Quoted 3 lines

However i2c_device_shutdown just finds the driver can calls driver->shutdown(), and that is the 'shutdown' that is NULL.

Then, i2c should be registered before than twl4030 as a platform device,

since

Quoted 1 line

twl4030 is an i2c device. Just let i2c shut down later than twl4030's.

It almost certainly is, but that is totally irrelevant.

Quoted 8 lines
Quoted 6 lines

The problem has nothing to do with ordering and nothing much to do with ->shutdown() being called.

The problem is simply that pm_runtime_disable() is being called on all devices, and that stops devices that are asleep from waking up.

Please correct me if I am wrong
1. This change only affects when the user issues "reboot" or "shutdown"

well "halt -p" or "poweroff", but yes.

Quoted 2 lines

2. The pm_runtime_disable(dev) is only be called before this "dev" is coming to shutdown

Yes, but the important point is that is being called before pm_power_off is called.

Quoted 1 line

3. If i2c bus/driver->shutdown is not called, its runtime pm is still enabled.

I think you mean "disabled" ??

Yes, but I don't see how that is relevant.

Quoted 1 line

4. You may issue i2c xfer after i2c bus/driver->shutdown is called.

Yes, but again I cannot see the relevance.

NeilBrown

Quoted 23 lines
Quoted 16 lines

I think the intention of putting that call in was to stop devices that are
awake from going to sleep, and maybe that is justified. But stopping devices
that are asleep from waking up isn't.

NeilBrown

Quoted 6 lines
Quoted 6 lines

Thanks,
NeilBrown

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#28 lore raw
In reply to NeilBrown
Quoted 24 lines

Hi,
this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses twl4030
for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend mode.
When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake it up,
performs the transfer, then calls pm_runtime_put to let it go back to sleep.

So it is asleep when the new pm_runtime_disable() call is made, so it stays
asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and the system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

Quoted 8 lines

So I feel this fix is a little too heavy-handed.
I don't fully understand the problem scenario described above but it seems to
me that if the auto-suspend timer can fire after the hardware has been shut
down, then maybe the hardware-shutdown should be disabling that timer. Maybe?

Oh, I am sorry to cause your problem. I think it may not be easy to handle this kinds of problem well.

In my opinion, it is better to handle shutdown/suspend SYNC at device drivers. Since the pm core is hard to know driver's shutdown is finished, and vice versa.

1. Driver needs to has relationship between suspend/shutdown, like usb host, hcd needs to know downstream port's suspend, and usb core needs to know hcd's shutdown.

2. At driver's shutdown
static void xxx_driver_shutdown(struct platform_device *pdev)

{
	if (supports_autosuspend(&pdev->dev) {
		pm_runtime_cancel_pending(&pdev->dev);
		wait_xxx_driver_suspend(pdev); /* need to sync with driver's suspend */
	}
	real_shutdown();		
}
Quoted 4 lines

Suggestions?

Thanks,
NeilBrown

#29 lore raw
Quoted 43 lines · On Mon, 5 Dec 2011 03:29:24 +0000 Chen Peter-B29397 <[email protected]>…
Quoted 24 lines

Hi,
this patches causes a problem for me.

Specifically it makes it impossible to power-down a device which uses twl4030
for power control on an omap3 processor.

To perform the shutdown we need to send a command over the i2c bus. The relevant bus is called omap_i2c.1 and this is normally in suspend mode.
When a request is sent, omap_i2c_xfer uses pm_runtime_get_sync to wake it up,
performs the transfer, then calls pm_runtime_put to let it go back to sleep.

So it is asleep when the new pm_runtime_disable() call is made, so it stays
asleep, omap_i2c_xfer cannot wake it, the transfer doesn't happen and the system doesn't get powered off.

So here is a device that should *not* have pm disabled at shutdown.

Quoted 8 lines

So I feel this fix is a little too heavy-handed.
I don't fully understand the problem scenario described above but it seems to
me that if the auto-suspend timer can fire after the hardware has been shut
down, then maybe the hardware-shutdown should be disabling that timer. Maybe?

Oh, I am sorry to cause your problem. I think it may not be easy to handle this kinds of problem well.

In my opinion, it is better to handle shutdown/suspend SYNC at device drivers. Since the pm core is hard to know driver's shutdown is finished, and vice versa.

1. Driver needs to has relationship between suspend/shutdown, like usb host, hcd needs to know downstream port's suspend, and usb core needs to know hcd's shutdown.

2. At driver's shutdown
static void xxx_driver_shutdown(struct platform_device *pdev)

Quoted 8 lines
{
	if (supports_autosuspend(&pdev->dev) {
		pm_runtime_cancel_pending(&pdev->dev);
		wait_xxx_driver_suspend(pdev); /* need to sync with driver's suspend */
	}
	real_shutdown();		
}

I think that makes sense to me.
It might be reasonable to call pm_runtime_barrier() in device_shutdown() to make it a bit easier for the ->shutdown function, but the final synchronisation should probably happen right there where you suggest.

It seems that driver->shutdown() is called from other places than just device_shutdown(). If a ->driver_shutdown function was allowed to assume that pm_runtime has been disabled, all of those call points would need to disable pm_runtime, which doesn't seem like the right way to go.

Thanks,
NeilBrown

Thanks,
NeilBrown