All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/2]
@ 2015-09-29 12:29 ` Tomeu Vizoso
  0 siblings, 0 replies; 16+ messages in thread
From: Tomeu Vizoso @ 2015-09-29 12:29 UTC (permalink / raw)
  To: linux-pm, Alan Stern, Rafael J. Wysocki, martyn.welch
  Cc: Tomeu Vizoso, linux-usb, linux-kernel, Len Brown, Kevin Hilman,
	Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

Hi,

this is v5 of an attempt to make it easier for devices to remain in
runtime PM when the system goes to sleep, mainly to reduce the time
spent resuming devices.

For this, we interpret the absence of all PM callback implementations as
it being safe to do direct_complete, so their ancestors aren't prevented
from remaining runtime-suspended.

Additionally, the prepare() callback of USB devices will return 1 if
runtime PM is enabled and the current wakeup settings are correct.

With these changes, a uvcvideo device (for example) stays in runtime
suspend when the system goes to sleep and is left in that state when the
system resumes, not delaying it unnecessarily.

Thanks,

Tomeu

Changes in v5:
- Check for all dev_pm_ops instances associated to a device, updating a
  no_pm_callbacks flag at the times when that could change.

Tomeu Vizoso (2):
  PM / sleep: Go direct_complete if driver has no callbacks
  USB / PM: Allow USB devices to remain runtime-suspended when sleeping

 drivers/base/dd.c           |  3 ++
 drivers/base/power/domain.c |  5 ++++
 drivers/base/power/main.c   | 69 ++++++++++++++++++++++++++++++++-------------
 drivers/base/power/power.h  |  2 ++
 drivers/usb/core/port.c     |  6 ++++
 drivers/usb/core/usb.c      | 11 +++++++-
 include/linux/pm.h          |  1 +
 7 files changed, 77 insertions(+), 20 deletions(-)

-- 
2.4.3


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v5 0/2]
@ 2015-09-29 12:29 ` Tomeu Vizoso
  0 siblings, 0 replies; 16+ messages in thread
From: Tomeu Vizoso @ 2015-09-29 12:29 UTC (permalink / raw)
  To: linux-pm-u79uwXL29TY76Z2rM5mHXA, Alan Stern, Rafael J. Wysocki,
	martyn.welch-ZGY8ohtN/8pPYcu2f3hruQ
  Cc: Tomeu Vizoso, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Len Brown, Kevin Hilman,
	Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

Hi,

this is v5 of an attempt to make it easier for devices to remain in
runtime PM when the system goes to sleep, mainly to reduce the time
spent resuming devices.

For this, we interpret the absence of all PM callback implementations as
it being safe to do direct_complete, so their ancestors aren't prevented
from remaining runtime-suspended.

Additionally, the prepare() callback of USB devices will return 1 if
runtime PM is enabled and the current wakeup settings are correct.

With these changes, a uvcvideo device (for example) stays in runtime
suspend when the system goes to sleep and is left in that state when the
system resumes, not delaying it unnecessarily.

Thanks,

Tomeu

Changes in v5:
- Check for all dev_pm_ops instances associated to a device, updating a
  no_pm_callbacks flag at the times when that could change.

Tomeu Vizoso (2):
  PM / sleep: Go direct_complete if driver has no callbacks
  USB / PM: Allow USB devices to remain runtime-suspended when sleeping

 drivers/base/dd.c           |  3 ++
 drivers/base/power/domain.c |  5 ++++
 drivers/base/power/main.c   | 69 ++++++++++++++++++++++++++++++++-------------
 drivers/base/power/power.h  |  2 ++
 drivers/usb/core/port.c     |  6 ++++
 drivers/usb/core/usb.c      | 11 +++++++-
 include/linux/pm.h          |  1 +
 7 files changed, 77 insertions(+), 20 deletions(-)

-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-09-29 12:29 ` Tomeu Vizoso
  (?)
@ 2015-09-29 12:29 ` Tomeu Vizoso
  2015-09-29 13:37     ` kbuild test robot
                     ` (4 more replies)
  -1 siblings, 5 replies; 16+ messages in thread
From: Tomeu Vizoso @ 2015-09-29 12:29 UTC (permalink / raw)
  To: linux-pm, Alan Stern, Rafael J. Wysocki, martyn.welch
  Cc: Tomeu Vizoso, linux-kernel, Len Brown, Kevin Hilman,
	Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

If a suitable prepare callback cannot be found for a given device and
its driver has no PM callbacks at all, assume that it can go direct to
complete when the system goes to sleep.

The reason for this is that there's lots of devices in a system that do
no PM at all and there's no reason for them to prevent their ancestors
to do direct_complete if they can support it.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---

Changes in v5:
- Check for all dev_pm_ops instances associated to a device, updating a
  no_pm_callbacks flag at the times when that could change.

 drivers/base/dd.c           |  3 ++
 drivers/base/power/domain.c |  5 ++++
 drivers/base/power/main.c   | 69 ++++++++++++++++++++++++++++++++-------------
 drivers/base/power/power.h  |  2 ++
 include/linux/pm.h          |  1 +
 5 files changed, 61 insertions(+), 19 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index be0eb4639128..fe0e9cb684b8 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -205,6 +205,8 @@ static void driver_bound(struct device *dev)
 
 	klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
 
+	device_check_pm_callbacks(dev);
+
 	/*
 	 * Make sure the device is no longer in one of the deferred lists and
 	 * kick off retrying all pending devices
@@ -695,6 +697,7 @@ static void __device_release_driver(struct device *dev)
 			dev->pm_domain->dismiss(dev);
 
 		klist_remove(&dev->p->knode_driver);
+		device_check_pm_callbacks(dev);
 		if (dev->bus)
 			blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 						     BUS_NOTIFY_UNBOUND_DRIVER,
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 16550c63d611..3cae1aa1885b 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -20,6 +20,8 @@
 #include <linux/suspend.h>
 #include <linux/export.h>
 
+#include "power.h"
+
 #define GENPD_RETRY_MAX_MS	250		/* Approximate */
 
 #define GENPD_DEV_CALLBACK(genpd, type, callback, dev)		\
@@ -1305,6 +1307,7 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
 
 	list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
 
+	device_check_pm_callbacks(dev);
  out:
 	mutex_unlock(&genpd->lock);
 
@@ -1369,6 +1372,8 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,
 
 	genpd_free_dev_data(dev, gpd_data);
 
+	device_check_pm_callbacks(dev);
+
 	return 0;
 
  out:
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 1710c26ba097..b6eaa00b2540 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -117,6 +117,31 @@ void device_pm_unlock(void)
 	mutex_unlock(&dpm_list_mtx);
 }
 
+static bool pm_ops_is_empty(const struct dev_pm_ops *ops)
+{
+	if (!ops)
+		return true;
+
+	return !ops->prepare &&
+	       !ops->suspend &&
+	       !ops->suspend_late &&
+	       !ops->suspend_noirq &&
+	       !ops->resume_noirq &&
+	       !ops->resume_early &&
+	       !ops->resume &&
+	       !ops->complete;
+}
+
+void device_check_pm_callbacks(struct device *dev)
+{
+	dev->power.no_pm_callbacks =
+		(!dev->bus || pm_ops_is_empty(dev->bus->pm)) &&
+		(!dev->class || pm_ops_is_empty(dev->class->pm)) &&
+		(!dev->type || pm_ops_is_empty(dev->type->pm)) &&
+		(!dev->pm_domain || pm_ops_is_empty(&dev->pm_domain->ops)) &&
+		(!dev->driver || pm_ops_is_empty(dev->driver->pm));
+}
+
 /**
  * device_pm_add - Add a device to the PM core's list of active devices.
  * @dev: Device to add to the list.
@@ -131,6 +156,8 @@ void device_pm_add(struct device *dev)
 			dev_name(dev->parent));
 	list_add_tail(&dev->power.entry, &dpm_list);
 	mutex_unlock(&dpm_list_mtx);
+
+	device_check_pm_callbacks(dev);
 }
 
 /**
@@ -1569,27 +1596,31 @@ static int device_prepare(struct device *dev, pm_message_t state)
 
 	dev->power.wakeup_path = device_may_wakeup(dev);
 
-	if (dev->pm_domain) {
-		info = "preparing power domain ";
-		callback = dev->pm_domain->ops.prepare;
-	} else if (dev->type && dev->type->pm) {
-		info = "preparing type ";
-		callback = dev->type->pm->prepare;
-	} else if (dev->class && dev->class->pm) {
-		info = "preparing class ";
-		callback = dev->class->pm->prepare;
-	} else if (dev->bus && dev->bus->pm) {
-		info = "preparing bus ";
-		callback = dev->bus->pm->prepare;
-	}
+	if (dev->power.no_pm_callbacks)
+		ret = 1;	/* Let device go direct_complete */
+	else {
+		if (dev->pm_domain) {
+			info = "preparing power domain ";
+			callback = dev->pm_domain->ops.prepare;
+		} else if (dev->type && dev->type->pm) {
+			info = "preparing type ";
+			callback = dev->type->pm->prepare;
+		} else if (dev->class && dev->class->pm) {
+			info = "preparing class ";
+			callback = dev->class->pm->prepare;
+		} else if (dev->bus && dev->bus->pm) {
+			info = "preparing bus ";
+			callback = dev->bus->pm->prepare;
+		}
 
-	if (!callback && dev->driver && dev->driver->pm) {
-		info = "preparing driver ";
-		callback = dev->driver->pm->prepare;
-	}
+		if (!callback && dev->driver && dev->driver->pm) {
+			info = "preparing driver ";
+			callback = dev->driver->pm->prepare;
+		}
 
-	if (callback)
-		ret = callback(dev);
+		if (callback)
+			ret = callback(dev);
+	}
 
 	device_unlock(dev);
 
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 998fa6b23084..518a8fc84e8d 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -9,6 +9,8 @@ static inline void device_pm_init_common(struct device *dev)
 	}
 }
 
+extern void device_check_pm_callbacks(struct device *dev);
+
 #ifdef CONFIG_PM
 
 static inline void pm_runtime_early_init(struct device *dev)
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 35d599e7250d..e334b9b8cd46 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -566,6 +566,7 @@ struct dev_pm_info {
 	bool			ignore_children:1;
 	bool			early_init:1;	/* Owned by the PM core */
 	bool			direct_complete:1;	/* Owned by the PM core */
+	bool			no_pm_callbacks:1;	/* Owned by the PM core */
 	spinlock_t		lock;
 #ifdef CONFIG_PM_SLEEP
 	struct list_head	entry;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v5 2/2] USB / PM: Allow USB devices to remain runtime-suspended when sleeping
  2015-09-29 12:29 ` Tomeu Vizoso
  (?)
  (?)
@ 2015-09-29 12:29 ` Tomeu Vizoso
  -1 siblings, 0 replies; 16+ messages in thread
From: Tomeu Vizoso @ 2015-09-29 12:29 UTC (permalink / raw)
  To: linux-pm, Alan Stern, Rafael J. Wysocki, martyn.welch
  Cc: Tomeu Vizoso, Greg Kroah-Hartman, linux-usb, linux-kernel

Have dev_pm_ops.prepare return 1 for USB devices and ports so that USB
devices can remain runtime-suspended when the system goes to a sleep
state, if their wakeup state is correct and they have runtime PM enabled.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---


 drivers/usb/core/port.c |  6 ++++++
 drivers/usb/core/usb.c  | 11 ++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 210618319f10..f49707d73b5a 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -168,12 +168,18 @@ static int usb_port_runtime_suspend(struct device *dev)
 
 	return retval;
 }
+
+static int usb_port_prepare(struct device *dev)
+{
+	return 1;
+}
 #endif
 
 static const struct dev_pm_ops usb_port_pm_ops = {
 #ifdef CONFIG_PM
 	.runtime_suspend =	usb_port_runtime_suspend,
 	.runtime_resume =	usb_port_runtime_resume,
+	.prepare =		usb_port_prepare,
 #endif
 };
 
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 8d5b2f4113cd..cf4dde11db1c 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -316,7 +316,16 @@ static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 static int usb_dev_prepare(struct device *dev)
 {
-	return 0;		/* Implement eventually? */
+	struct usb_device *udev = to_usb_device(dev);
+
+	if (!pm_runtime_enabled(dev))
+		return 0;
+
+	/* Return 0 if the current wakeup setting is wrong, otherwise 1 */
+	if (udev->do_remote_wakeup != device_may_wakeup(dev))
+		return 0;
+
+	return 1;
 }
 
 static void usb_dev_complete(struct device *dev)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-09-29 12:29 ` [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks Tomeu Vizoso
@ 2015-09-29 13:37     ` kbuild test robot
  2015-09-29 13:38     ` kbuild test robot
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: kbuild test robot @ 2015-09-29 13:37 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: kbuild-all, linux-pm, Alan Stern, Rafael J. Wysocki,
	martyn.welch, Tomeu Vizoso, linux-kernel, Len Brown,
	Kevin Hilman, Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

[-- Attachment #1: Type: text/plain, Size: 1871 bytes --]

Hi Tomeu,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: sh-sh7785lcr_32bit_defconfig (attached as .config)
reproduce:
  wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
  chmod +x ~/bin/make.cross
  git checkout 5bf5ff8fb7c319addf70c42d9e58ff3981ecac56
  # save the attached .config to linux build tree
  make.cross ARCH=sh 

All error/warnings (new ones prefixed by >>):

   drivers/built-in.o: In function `driver_bound':
>> drivers/base/dd.c:198: undefined reference to `device_check_pm_callbacks'
   drivers/built-in.o: In function `__device_release_driver':
   drivers/base/dd.c:676: undefined reference to `device_check_pm_callbacks'

vim +198 drivers/base/dd.c

d1c3414c2 Grant Likely       2012-03-05  192  }
d1c3414c2 Grant Likely       2012-03-05  193  late_initcall(deferred_probe_initcall);
07e4a3e27 Patrick Mochel     2005-03-21  194  
1901fb260 Kay Sievers        2006-10-07  195  static void driver_bound(struct device *dev)
07e4a3e27 Patrick Mochel     2005-03-21  196  {
8940b4f31 Greg Kroah-Hartman 2008-12-16  197  	if (klist_node_attached(&dev->p->knode_driver)) {
f86db396f Andrew Morton      2006-08-14 @198  		printk(KERN_WARNING "%s: device %s already bound\n",
2b3a302a0 Harvey Harrison    2008-03-04  199  			__func__, kobject_name(&dev->kobj));
1901fb260 Kay Sievers        2006-10-07  200  		return;
f86db396f Andrew Morton      2006-08-14  201  	}

:::::: The code at line 198 was first introduced by commit
:::::: f86db396ff455ed586751d21816a1ebd431264e5 drivers/base: check errors

:::::: TO: Andrew Morton <akpm@osdl.org>
:::::: CC: Greg Kroah-Hartman <gregkh@suse.de>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 15794 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
@ 2015-09-29 13:37     ` kbuild test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kbuild test robot @ 2015-09-29 13:37 UTC (permalink / raw)
  Cc: kbuild-all, linux-pm, Alan Stern, Rafael J. Wysocki,
	martyn.welch, Tomeu Vizoso, linux-kernel, Len Brown,
	Kevin Hilman, Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

[-- Attachment #1: Type: text/plain, Size: 1871 bytes --]

Hi Tomeu,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: sh-sh7785lcr_32bit_defconfig (attached as .config)
reproduce:
  wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
  chmod +x ~/bin/make.cross
  git checkout 5bf5ff8fb7c319addf70c42d9e58ff3981ecac56
  # save the attached .config to linux build tree
  make.cross ARCH=sh 

All error/warnings (new ones prefixed by >>):

   drivers/built-in.o: In function `driver_bound':
>> drivers/base/dd.c:198: undefined reference to `device_check_pm_callbacks'
   drivers/built-in.o: In function `__device_release_driver':
   drivers/base/dd.c:676: undefined reference to `device_check_pm_callbacks'

vim +198 drivers/base/dd.c

d1c3414c2 Grant Likely       2012-03-05  192  }
d1c3414c2 Grant Likely       2012-03-05  193  late_initcall(deferred_probe_initcall);
07e4a3e27 Patrick Mochel     2005-03-21  194  
1901fb260 Kay Sievers        2006-10-07  195  static void driver_bound(struct device *dev)
07e4a3e27 Patrick Mochel     2005-03-21  196  {
8940b4f31 Greg Kroah-Hartman 2008-12-16  197  	if (klist_node_attached(&dev->p->knode_driver)) {
f86db396f Andrew Morton      2006-08-14 @198  		printk(KERN_WARNING "%s: device %s already bound\n",
2b3a302a0 Harvey Harrison    2008-03-04  199  			__func__, kobject_name(&dev->kobj));
1901fb260 Kay Sievers        2006-10-07  200  		return;
f86db396f Andrew Morton      2006-08-14  201  	}

:::::: The code at line 198 was first introduced by commit
:::::: f86db396ff455ed586751d21816a1ebd431264e5 drivers/base: check errors

:::::: TO: Andrew Morton <akpm@osdl.org>
:::::: CC: Greg Kroah-Hartman <gregkh@suse.de>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 15794 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-09-29 12:29 ` [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks Tomeu Vizoso
@ 2015-09-29 13:38     ` kbuild test robot
  2015-09-29 13:38     ` kbuild test robot
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: kbuild test robot @ 2015-09-29 13:38 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: kbuild-all, linux-pm, Alan Stern, Rafael J. Wysocki,
	martyn.welch, Tomeu Vizoso, linux-kernel, Len Brown,
	Kevin Hilman, Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

[-- Attachment #1: Type: text/plain, Size: 971 bytes --]

Hi Tomeu,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: parisc-b180_defconfig (attached as .config)
reproduce:
  wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
  chmod +x ~/bin/make.cross
  git checkout 5bf5ff8fb7c319addf70c42d9e58ff3981ecac56
  # save the attached .config to linux build tree
  make.cross ARCH=parisc 

All error/warnings (new ones prefixed by >>):

   drivers/built-in.o: In function `driver_bound':
>> drivers/base/.tmp_dd.o:(.text.driver_bound+0x40): undefined reference to `device_check_pm_callbacks'
   drivers/built-in.o: In function `__device_release_driver':
>> drivers/base/.tmp_dd.o:(.text.__device_release_driver+0xac): undefined reference to `device_check_pm_callbacks'

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 12157 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
@ 2015-09-29 13:38     ` kbuild test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kbuild test robot @ 2015-09-29 13:38 UTC (permalink / raw)
  Cc: kbuild-all, linux-pm, Alan Stern, Rafael J. Wysocki,
	martyn.welch, Tomeu Vizoso, linux-kernel, Len Brown,
	Kevin Hilman, Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

[-- Attachment #1: Type: text/plain, Size: 971 bytes --]

Hi Tomeu,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: parisc-b180_defconfig (attached as .config)
reproduce:
  wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
  chmod +x ~/bin/make.cross
  git checkout 5bf5ff8fb7c319addf70c42d9e58ff3981ecac56
  # save the attached .config to linux build tree
  make.cross ARCH=parisc 

All error/warnings (new ones prefixed by >>):

   drivers/built-in.o: In function `driver_bound':
>> drivers/base/.tmp_dd.o:(.text.driver_bound+0x40): undefined reference to `device_check_pm_callbacks'
   drivers/built-in.o: In function `__device_release_driver':
>> drivers/base/.tmp_dd.o:(.text.__device_release_driver+0xac): undefined reference to `device_check_pm_callbacks'

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 12157 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-09-29 12:29 ` [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks Tomeu Vizoso
@ 2015-09-29 13:39     ` kbuild test robot
  2015-09-29 13:38     ` kbuild test robot
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: kbuild test robot @ 2015-09-29 13:39 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: kbuild-all, linux-pm, Alan Stern, Rafael J. Wysocki,
	martyn.welch, Tomeu Vizoso, linux-kernel, Len Brown,
	Kevin Hilman, Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

[-- Attachment #1: Type: text/plain, Size: 2184 bytes --]

Hi Tomeu,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: mn10300-asb2364_defconfig (attached as .config)
reproduce:
  wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
  chmod +x ~/bin/make.cross
  git checkout 5bf5ff8fb7c319addf70c42d9e58ff3981ecac56
  # save the attached .config to linux build tree
  make.cross ARCH=mn10300 

All error/warnings (new ones prefixed by >>):

   drivers/built-in.o: In function `fb_register_client':
>> drivers/video/fbdev/core/fb_notify.c:36: undefined reference to `device_check_pm_callbacks'
>> drivers/video/fbdev/core/fb_notify.c:36: undefined reference to `device_check_pm_callbacks'

vim +36 drivers/video/fbdev/core/fb_notify.c

256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  30   *	fb_unregister_client - unregister a client notifier
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  31   *	@nb: notifier block to callback on events
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  32   */
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  33  int fb_unregister_client(struct notifier_block *nb)
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  34  {
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  35  	return blocking_notifier_chain_unregister(&fb_notifier_list, nb);
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30 @36  }
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  37  EXPORT_SYMBOL(fb_unregister_client);
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  38  
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  39  /**

:::::: The code at line 36 was first introduced by commit
:::::: 256154fbc31c25a8df4d398232acfa9d4892224c [PATCH] fbdev: statically link the framebuffer notification functions

:::::: TO: Antonino A. Daplas <adaplas@gmail.com>
:::::: CC: Linus Torvalds <torvalds@g5.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 8462 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
@ 2015-09-29 13:39     ` kbuild test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kbuild test robot @ 2015-09-29 13:39 UTC (permalink / raw)
  Cc: kbuild-all, linux-pm, Alan Stern, Rafael J. Wysocki,
	martyn.welch, Tomeu Vizoso, linux-kernel, Len Brown,
	Kevin Hilman, Greg Kroah-Hartman, Pavel Machek, Ulf Hansson

[-- Attachment #1: Type: text/plain, Size: 2184 bytes --]

Hi Tomeu,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: mn10300-asb2364_defconfig (attached as .config)
reproduce:
  wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
  chmod +x ~/bin/make.cross
  git checkout 5bf5ff8fb7c319addf70c42d9e58ff3981ecac56
  # save the attached .config to linux build tree
  make.cross ARCH=mn10300 

All error/warnings (new ones prefixed by >>):

   drivers/built-in.o: In function `fb_register_client':
>> drivers/video/fbdev/core/fb_notify.c:36: undefined reference to `device_check_pm_callbacks'
>> drivers/video/fbdev/core/fb_notify.c:36: undefined reference to `device_check_pm_callbacks'

vim +36 drivers/video/fbdev/core/fb_notify.c

256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  30   *	fb_unregister_client - unregister a client notifier
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  31   *	@nb: notifier block to callback on events
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  32   */
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  33  int fb_unregister_client(struct notifier_block *nb)
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  34  {
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  35  	return blocking_notifier_chain_unregister(&fb_notifier_list, nb);
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30 @36  }
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  37  EXPORT_SYMBOL(fb_unregister_client);
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  38  
256154fb drivers/video/fb_notify.c Antonino A. Daplas 2006-07-30  39  /**

:::::: The code at line 36 was first introduced by commit
:::::: 256154fbc31c25a8df4d398232acfa9d4892224c [PATCH] fbdev: statically link the framebuffer notification functions

:::::: TO: Antonino A. Daplas <adaplas@gmail.com>
:::::: CC: Linus Torvalds <torvalds@g5.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 8462 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-09-29 12:29 ` [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks Tomeu Vizoso
@ 2015-09-29 14:39     ` Alan Stern
  2015-09-29 13:38     ` kbuild test robot
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Alan Stern @ 2015-09-29 14:39 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: linux-pm, Rafael J. Wysocki, martyn.welch, linux-kernel,
	Len Brown, Kevin Hilman, Greg Kroah-Hartman, Pavel Machek,
	Ulf Hansson

On Tue, 29 Sep 2015, Tomeu Vizoso wrote:

> If a suitable prepare callback cannot be found for a given device and
> its driver has no PM callbacks at all, assume that it can go direct to
> complete when the system goes to sleep.
> 
> The reason for this is that there's lots of devices in a system that do
> no PM at all and there's no reason for them to prevent their ancestors
> to do direct_complete if they can support it.
> 
> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>

> +void device_check_pm_callbacks(struct device *dev)
> +{
> +	dev->power.no_pm_callbacks =
> +		(!dev->bus || pm_ops_is_empty(dev->bus->pm)) &&
> +		(!dev->class || pm_ops_is_empty(dev->class->pm)) &&
> +		(!dev->type || pm_ops_is_empty(dev->type->pm)) &&
> +		(!dev->pm_domain || pm_ops_is_empty(&dev->pm_domain->ops)) &&
> +		(!dev->driver || pm_ops_is_empty(dev->driver->pm));
> +}

One fairly minor point: You should lock dev->power.lock before setting
this bitfield.  This is because bitfields are not SMP-safe.

Alan Stern


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
@ 2015-09-29 14:39     ` Alan Stern
  0 siblings, 0 replies; 16+ messages in thread
From: Alan Stern @ 2015-09-29 14:39 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: linux-pm, Rafael J. Wysocki, martyn.welch, linux-kernel,
	Len Brown, Kevin Hilman, Greg Kroah-Hartman, Pavel Machek,
	Ulf Hansson

On Tue, 29 Sep 2015, Tomeu Vizoso wrote:

> If a suitable prepare callback cannot be found for a given device and
> its driver has no PM callbacks at all, assume that it can go direct to
> complete when the system goes to sleep.
> 
> The reason for this is that there's lots of devices in a system that do
> no PM at all and there's no reason for them to prevent their ancestors
> to do direct_complete if they can support it.
> 
> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>

> +void device_check_pm_callbacks(struct device *dev)
> +{
> +	dev->power.no_pm_callbacks =
> +		(!dev->bus || pm_ops_is_empty(dev->bus->pm)) &&
> +		(!dev->class || pm_ops_is_empty(dev->class->pm)) &&
> +		(!dev->type || pm_ops_is_empty(dev->type->pm)) &&
> +		(!dev->pm_domain || pm_ops_is_empty(&dev->pm_domain->ops)) &&
> +		(!dev->driver || pm_ops_is_empty(dev->driver->pm));
> +}

One fairly minor point: You should lock dev->power.lock before setting
this bitfield.  This is because bitfields are not SMP-safe.

Alan Stern


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-09-29 12:29 ` [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks Tomeu Vizoso
                     ` (3 preceding siblings ...)
  2015-09-29 14:39     ` Alan Stern
@ 2015-10-04 15:16   ` Pavel Machek
  2015-10-05  8:25     ` Tomeu Vizoso
  4 siblings, 1 reply; 16+ messages in thread
From: Pavel Machek @ 2015-10-04 15:16 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: linux-pm, Alan Stern, Rafael J. Wysocki, martyn.welch,
	linux-kernel, Len Brown, Kevin Hilman, Greg Kroah-Hartman,
	Ulf Hansson

On Tue 2015-09-29 14:29:19, Tomeu Vizoso wrote:
> If a suitable prepare callback cannot be found for a given device and
> its driver has no PM callbacks at all, assume that it can go direct to
> complete when the system goes to sleep.
> 
> The reason for this is that there's lots of devices in a system that do
> no PM at all and there's no reason for them to prevent their ancestors
> to do direct_complete if they can support it.

Dunno. This sounds like asking for trouble. Even if most devices can handle
this, is not this bound to introduce some bugs?

Thanks,
									Pavel

> 
> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> ---
> 
> Changes in v5:
> - Check for all dev_pm_ops instances associated to a device, updating a
>   no_pm_callbacks flag at the times when that could change.
> 
>  drivers/base/dd.c           |  3 ++
>  drivers/base/power/domain.c |  5 ++++
>  drivers/base/power/main.c   | 69 ++++++++++++++++++++++++++++++++-------------
>  drivers/base/power/power.h  |  2 ++
>  include/linux/pm.h          |  1 +
>  5 files changed, 61 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index be0eb4639128..fe0e9cb684b8 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -205,6 +205,8 @@ static void driver_bound(struct device *dev)
>  
>  	klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
>  
> +	device_check_pm_callbacks(dev);
> +
>  	/*
>  	 * Make sure the device is no longer in one of the deferred lists and
>  	 * kick off retrying all pending devices
> @@ -695,6 +697,7 @@ static void __device_release_driver(struct device *dev)
>  			dev->pm_domain->dismiss(dev);
>  
>  		klist_remove(&dev->p->knode_driver);
> +		device_check_pm_callbacks(dev);
>  		if (dev->bus)
>  			blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
>  						     BUS_NOTIFY_UNBOUND_DRIVER,
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 16550c63d611..3cae1aa1885b 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -20,6 +20,8 @@
>  #include <linux/suspend.h>
>  #include <linux/export.h>
>  
> +#include "power.h"
> +
>  #define GENPD_RETRY_MAX_MS	250		/* Approximate */
>  
>  #define GENPD_DEV_CALLBACK(genpd, type, callback, dev)		\
> @@ -1305,6 +1307,7 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
>  
>  	list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
>  
> +	device_check_pm_callbacks(dev);
>   out:
>  	mutex_unlock(&genpd->lock);
>  
> @@ -1369,6 +1372,8 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,
>  
>  	genpd_free_dev_data(dev, gpd_data);
>  
> +	device_check_pm_callbacks(dev);
> +
>  	return 0;
>  
>   out:
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index 1710c26ba097..b6eaa00b2540 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -117,6 +117,31 @@ void device_pm_unlock(void)
>  	mutex_unlock(&dpm_list_mtx);
>  }
>  
> +static bool pm_ops_is_empty(const struct dev_pm_ops *ops)
> +{
> +	if (!ops)
> +		return true;
> +
> +	return !ops->prepare &&
> +	       !ops->suspend &&
> +	       !ops->suspend_late &&
> +	       !ops->suspend_noirq &&
> +	       !ops->resume_noirq &&
> +	       !ops->resume_early &&
> +	       !ops->resume &&
> +	       !ops->complete;
> +}
> +
> +void device_check_pm_callbacks(struct device *dev)
> +{
> +	dev->power.no_pm_callbacks =
> +		(!dev->bus || pm_ops_is_empty(dev->bus->pm)) &&
> +		(!dev->class || pm_ops_is_empty(dev->class->pm)) &&
> +		(!dev->type || pm_ops_is_empty(dev->type->pm)) &&
> +		(!dev->pm_domain || pm_ops_is_empty(&dev->pm_domain->ops)) &&
> +		(!dev->driver || pm_ops_is_empty(dev->driver->pm));
> +}
> +
>  /**
>   * device_pm_add - Add a device to the PM core's list of active devices.
>   * @dev: Device to add to the list.
> @@ -131,6 +156,8 @@ void device_pm_add(struct device *dev)
>  			dev_name(dev->parent));
>  	list_add_tail(&dev->power.entry, &dpm_list);
>  	mutex_unlock(&dpm_list_mtx);
> +
> +	device_check_pm_callbacks(dev);
>  }
>  
>  /**
> @@ -1569,27 +1596,31 @@ static int device_prepare(struct device *dev, pm_message_t state)
>  
>  	dev->power.wakeup_path = device_may_wakeup(dev);
>  
> -	if (dev->pm_domain) {
> -		info = "preparing power domain ";
> -		callback = dev->pm_domain->ops.prepare;
> -	} else if (dev->type && dev->type->pm) {
> -		info = "preparing type ";
> -		callback = dev->type->pm->prepare;
> -	} else if (dev->class && dev->class->pm) {
> -		info = "preparing class ";
> -		callback = dev->class->pm->prepare;
> -	} else if (dev->bus && dev->bus->pm) {
> -		info = "preparing bus ";
> -		callback = dev->bus->pm->prepare;
> -	}
> +	if (dev->power.no_pm_callbacks)
> +		ret = 1;	/* Let device go direct_complete */
> +	else {
> +		if (dev->pm_domain) {
> +			info = "preparing power domain ";
> +			callback = dev->pm_domain->ops.prepare;
> +		} else if (dev->type && dev->type->pm) {
> +			info = "preparing type ";
> +			callback = dev->type->pm->prepare;
> +		} else if (dev->class && dev->class->pm) {
> +			info = "preparing class ";
> +			callback = dev->class->pm->prepare;
> +		} else if (dev->bus && dev->bus->pm) {
> +			info = "preparing bus ";
> +			callback = dev->bus->pm->prepare;
> +		}
>  
> -	if (!callback && dev->driver && dev->driver->pm) {
> -		info = "preparing driver ";
> -		callback = dev->driver->pm->prepare;
> -	}
> +		if (!callback && dev->driver && dev->driver->pm) {
> +			info = "preparing driver ";
> +			callback = dev->driver->pm->prepare;
> +		}
>  
> -	if (callback)
> -		ret = callback(dev);
> +		if (callback)
> +			ret = callback(dev);
> +	}
>  
>  	device_unlock(dev);
>  
> diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
> index 998fa6b23084..518a8fc84e8d 100644
> --- a/drivers/base/power/power.h
> +++ b/drivers/base/power/power.h
> @@ -9,6 +9,8 @@ static inline void device_pm_init_common(struct device *dev)
>  	}
>  }
>  
> +extern void device_check_pm_callbacks(struct device *dev);
> +
>  #ifdef CONFIG_PM
>  
>  static inline void pm_runtime_early_init(struct device *dev)
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 35d599e7250d..e334b9b8cd46 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -566,6 +566,7 @@ struct dev_pm_info {
>  	bool			ignore_children:1;
>  	bool			early_init:1;	/* Owned by the PM core */
>  	bool			direct_complete:1;	/* Owned by the PM core */
> +	bool			no_pm_callbacks:1;	/* Owned by the PM core */
>  	spinlock_t		lock;
>  #ifdef CONFIG_PM_SLEEP
>  	struct list_head	entry;
> -- 
> 2.4.3

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-10-04 15:16   ` Pavel Machek
@ 2015-10-05  8:25     ` Tomeu Vizoso
  2015-10-05  9:07       ` Pavel Machek
  0 siblings, 1 reply; 16+ messages in thread
From: Tomeu Vizoso @ 2015-10-05  8:25 UTC (permalink / raw)
  To: Pavel Machek
  Cc: linux-pm, Alan Stern, Rafael J. Wysocki, martyn.welch,
	linux-kernel, Len Brown, Kevin Hilman, Greg Kroah-Hartman,
	Ulf Hansson

On 4 October 2015 at 17:16, Pavel Machek <pavel@ucw.cz> wrote:
> On Tue 2015-09-29 14:29:19, Tomeu Vizoso wrote:
>> If a suitable prepare callback cannot be found for a given device and
>> its driver has no PM callbacks at all, assume that it can go direct to
>> complete when the system goes to sleep.
>>
>> The reason for this is that there's lots of devices in a system that do
>> no PM at all and there's no reason for them to prevent their ancestors
>> to do direct_complete if they can support it.
>
> Dunno. This sounds like asking for trouble. Even if most devices can handle
> this, is not this bound to introduce some bugs?

Hi Pavel,

in which situations do you think that this could be problematic?

Thanks,

Tomeu

> Thanks,
>                                                                         Pavel
>
>>
>> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
>> ---
>>
>> Changes in v5:
>> - Check for all dev_pm_ops instances associated to a device, updating a
>>   no_pm_callbacks flag at the times when that could change.
>>
>>  drivers/base/dd.c           |  3 ++
>>  drivers/base/power/domain.c |  5 ++++
>>  drivers/base/power/main.c   | 69 ++++++++++++++++++++++++++++++++-------------
>>  drivers/base/power/power.h  |  2 ++
>>  include/linux/pm.h          |  1 +
>>  5 files changed, 61 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
>> index be0eb4639128..fe0e9cb684b8 100644
>> --- a/drivers/base/dd.c
>> +++ b/drivers/base/dd.c
>> @@ -205,6 +205,8 @@ static void driver_bound(struct device *dev)
>>
>>       klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
>>
>> +     device_check_pm_callbacks(dev);
>> +
>>       /*
>>        * Make sure the device is no longer in one of the deferred lists and
>>        * kick off retrying all pending devices
>> @@ -695,6 +697,7 @@ static void __device_release_driver(struct device *dev)
>>                       dev->pm_domain->dismiss(dev);
>>
>>               klist_remove(&dev->p->knode_driver);
>> +             device_check_pm_callbacks(dev);
>>               if (dev->bus)
>>                       blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
>>                                                    BUS_NOTIFY_UNBOUND_DRIVER,
>> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
>> index 16550c63d611..3cae1aa1885b 100644
>> --- a/drivers/base/power/domain.c
>> +++ b/drivers/base/power/domain.c
>> @@ -20,6 +20,8 @@
>>  #include <linux/suspend.h>
>>  #include <linux/export.h>
>>
>> +#include "power.h"
>> +
>>  #define GENPD_RETRY_MAX_MS   250             /* Approximate */
>>
>>  #define GENPD_DEV_CALLBACK(genpd, type, callback, dev)               \
>> @@ -1305,6 +1307,7 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
>>
>>       list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
>>
>> +     device_check_pm_callbacks(dev);
>>   out:
>>       mutex_unlock(&genpd->lock);
>>
>> @@ -1369,6 +1372,8 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,
>>
>>       genpd_free_dev_data(dev, gpd_data);
>>
>> +     device_check_pm_callbacks(dev);
>> +
>>       return 0;
>>
>>   out:
>> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
>> index 1710c26ba097..b6eaa00b2540 100644
>> --- a/drivers/base/power/main.c
>> +++ b/drivers/base/power/main.c
>> @@ -117,6 +117,31 @@ void device_pm_unlock(void)
>>       mutex_unlock(&dpm_list_mtx);
>>  }
>>
>> +static bool pm_ops_is_empty(const struct dev_pm_ops *ops)
>> +{
>> +     if (!ops)
>> +             return true;
>> +
>> +     return !ops->prepare &&
>> +            !ops->suspend &&
>> +            !ops->suspend_late &&
>> +            !ops->suspend_noirq &&
>> +            !ops->resume_noirq &&
>> +            !ops->resume_early &&
>> +            !ops->resume &&
>> +            !ops->complete;
>> +}
>> +
>> +void device_check_pm_callbacks(struct device *dev)
>> +{
>> +     dev->power.no_pm_callbacks =
>> +             (!dev->bus || pm_ops_is_empty(dev->bus->pm)) &&
>> +             (!dev->class || pm_ops_is_empty(dev->class->pm)) &&
>> +             (!dev->type || pm_ops_is_empty(dev->type->pm)) &&
>> +             (!dev->pm_domain || pm_ops_is_empty(&dev->pm_domain->ops)) &&
>> +             (!dev->driver || pm_ops_is_empty(dev->driver->pm));
>> +}
>> +
>>  /**
>>   * device_pm_add - Add a device to the PM core's list of active devices.
>>   * @dev: Device to add to the list.
>> @@ -131,6 +156,8 @@ void device_pm_add(struct device *dev)
>>                       dev_name(dev->parent));
>>       list_add_tail(&dev->power.entry, &dpm_list);
>>       mutex_unlock(&dpm_list_mtx);
>> +
>> +     device_check_pm_callbacks(dev);
>>  }
>>
>>  /**
>> @@ -1569,27 +1596,31 @@ static int device_prepare(struct device *dev, pm_message_t state)
>>
>>       dev->power.wakeup_path = device_may_wakeup(dev);
>>
>> -     if (dev->pm_domain) {
>> -             info = "preparing power domain ";
>> -             callback = dev->pm_domain->ops.prepare;
>> -     } else if (dev->type && dev->type->pm) {
>> -             info = "preparing type ";
>> -             callback = dev->type->pm->prepare;
>> -     } else if (dev->class && dev->class->pm) {
>> -             info = "preparing class ";
>> -             callback = dev->class->pm->prepare;
>> -     } else if (dev->bus && dev->bus->pm) {
>> -             info = "preparing bus ";
>> -             callback = dev->bus->pm->prepare;
>> -     }
>> +     if (dev->power.no_pm_callbacks)
>> +             ret = 1;        /* Let device go direct_complete */
>> +     else {
>> +             if (dev->pm_domain) {
>> +                     info = "preparing power domain ";
>> +                     callback = dev->pm_domain->ops.prepare;
>> +             } else if (dev->type && dev->type->pm) {
>> +                     info = "preparing type ";
>> +                     callback = dev->type->pm->prepare;
>> +             } else if (dev->class && dev->class->pm) {
>> +                     info = "preparing class ";
>> +                     callback = dev->class->pm->prepare;
>> +             } else if (dev->bus && dev->bus->pm) {
>> +                     info = "preparing bus ";
>> +                     callback = dev->bus->pm->prepare;
>> +             }
>>
>> -     if (!callback && dev->driver && dev->driver->pm) {
>> -             info = "preparing driver ";
>> -             callback = dev->driver->pm->prepare;
>> -     }
>> +             if (!callback && dev->driver && dev->driver->pm) {
>> +                     info = "preparing driver ";
>> +                     callback = dev->driver->pm->prepare;
>> +             }
>>
>> -     if (callback)
>> -             ret = callback(dev);
>> +             if (callback)
>> +                     ret = callback(dev);
>> +     }
>>
>>       device_unlock(dev);
>>
>> diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
>> index 998fa6b23084..518a8fc84e8d 100644
>> --- a/drivers/base/power/power.h
>> +++ b/drivers/base/power/power.h
>> @@ -9,6 +9,8 @@ static inline void device_pm_init_common(struct device *dev)
>>       }
>>  }
>>
>> +extern void device_check_pm_callbacks(struct device *dev);
>> +
>>  #ifdef CONFIG_PM
>>
>>  static inline void pm_runtime_early_init(struct device *dev)
>> diff --git a/include/linux/pm.h b/include/linux/pm.h
>> index 35d599e7250d..e334b9b8cd46 100644
>> --- a/include/linux/pm.h
>> +++ b/include/linux/pm.h
>> @@ -566,6 +566,7 @@ struct dev_pm_info {
>>       bool                    ignore_children:1;
>>       bool                    early_init:1;   /* Owned by the PM core */
>>       bool                    direct_complete:1;      /* Owned by the PM core */
>> +     bool                    no_pm_callbacks:1;      /* Owned by the PM core */
>>       spinlock_t              lock;
>>  #ifdef CONFIG_PM_SLEEP
>>       struct list_head        entry;
>> --
>> 2.4.3
>
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-10-05  8:25     ` Tomeu Vizoso
@ 2015-10-05  9:07       ` Pavel Machek
  2015-10-05 13:29         ` Rafael J. Wysocki
  0 siblings, 1 reply; 16+ messages in thread
From: Pavel Machek @ 2015-10-05  9:07 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: linux-pm, Alan Stern, Rafael J. Wysocki, martyn.welch,
	linux-kernel, Len Brown, Kevin Hilman, Greg Kroah-Hartman,
	Ulf Hansson

On Mon 2015-10-05 10:25:45, Tomeu Vizoso wrote:
> On 4 October 2015 at 17:16, Pavel Machek <pavel@ucw.cz> wrote:
> > On Tue 2015-09-29 14:29:19, Tomeu Vizoso wrote:
> >> If a suitable prepare callback cannot be found for a given device and
> >> its driver has no PM callbacks at all, assume that it can go direct to
> >> complete when the system goes to sleep.
> >>
> >> The reason for this is that there's lots of devices in a system that do
> >> no PM at all and there's no reason for them to prevent their ancestors
> >> to do direct_complete if they can support it.
> >
> > Dunno. This sounds like asking for trouble. Even if most devices can handle
> > this, is not this bound to introduce some bugs?
> 
> Hi Pavel,
> 
> in which situations do you think that this could be problematic?

Well.. driver with no PM callbacks probably works "by accident", and now you are changing
its environment. Do you have explanation why it will not break?

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks
  2015-10-05  9:07       ` Pavel Machek
@ 2015-10-05 13:29         ` Rafael J. Wysocki
  0 siblings, 0 replies; 16+ messages in thread
From: Rafael J. Wysocki @ 2015-10-05 13:29 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Tomeu Vizoso, linux-pm, Alan Stern, martyn.welch, linux-kernel,
	Len Brown, Kevin Hilman, Greg Kroah-Hartman, Ulf Hansson

On Monday, October 05, 2015 11:07:27 AM Pavel Machek wrote:
> On Mon 2015-10-05 10:25:45, Tomeu Vizoso wrote:
> > On 4 October 2015 at 17:16, Pavel Machek <pavel@ucw.cz> wrote:
> > > On Tue 2015-09-29 14:29:19, Tomeu Vizoso wrote:
> > >> If a suitable prepare callback cannot be found for a given device and
> > >> its driver has no PM callbacks at all, assume that it can go direct to
> > >> complete when the system goes to sleep.
> > >>
> > >> The reason for this is that there's lots of devices in a system that do
> > >> no PM at all and there's no reason for them to prevent their ancestors
> > >> to do direct_complete if they can support it.
> > >
> > > Dunno. This sounds like asking for trouble. Even if most devices can handle
> > > this, is not this bound to introduce some bugs?
> > 
> > Hi Pavel,
> > 
> > in which situations do you think that this could be problematic?
> 
> Well.. driver with no PM callbacks probably works "by accident",

How exactly?

Do you have at least one example of that?

Thanks,
Rafael


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-10-05 13:01 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-29 12:29 [PATCH v5 0/2] Tomeu Vizoso
2015-09-29 12:29 ` Tomeu Vizoso
2015-09-29 12:29 ` [PATCH v5 1/2] PM / sleep: Go direct_complete if driver has no callbacks Tomeu Vizoso
2015-09-29 13:37   ` kbuild test robot
2015-09-29 13:37     ` kbuild test robot
2015-09-29 13:38   ` kbuild test robot
2015-09-29 13:38     ` kbuild test robot
2015-09-29 13:39   ` kbuild test robot
2015-09-29 13:39     ` kbuild test robot
2015-09-29 14:39   ` Alan Stern
2015-09-29 14:39     ` Alan Stern
2015-10-04 15:16   ` Pavel Machek
2015-10-05  8:25     ` Tomeu Vizoso
2015-10-05  9:07       ` Pavel Machek
2015-10-05 13:29         ` Rafael J. Wysocki
2015-09-29 12:29 ` [PATCH v5 2/2] USB / PM: Allow USB devices to remain runtime-suspended when sleeping Tomeu Vizoso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.