Skip to contentSkip to conversation

PM / Domains: Add code for powering off all unused PM domains

PATCH New Rafael J. Wysocki 1 participant 5 messages Jul 10, 2011

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover PM / Domains: Add code for powering off all unused PM domains

Hi,

The following two patches are on top of the branch at:

git://git.kernel.org/pub/scm/linux/kernel/git/rafael/suspend-2.6.git pm-domains

and the patchset I sent earlier today:

https://lkml.org/lkml/2011/7/10/27

and this patch: https://patchwork.kernel.org/patch/961202/

They introduce a mechanism allowing platforms to power off all of the PM domains that don't contain devices in use in one shot. The first patch adds core support for that and the second one makes shmobile use it instead of its own code.

Thanks,
Rafael

#1 lore raw

PATCH 1/2 PM / Domains: Introduce function to power off all unused PM domains

From: Rafael J. Wysocki <[email protected]>

Add a new function pm_genpd_poweroff_unused() queuing up the execution of pm_genpd_poweroff() for every initialized generic PM domain. Calling it will cause every generic PM domain without devices in use to be powered off.

---
 drivers/base/power/domain.c |   21 +++++++++++++++++++++
 include/linux/pm_domain.h   |    3 +++
 2 files changed, 24 insertions(+)

Index: linux-2.6/include/linux/pm_domain.h =================================--- linux-2.6.orig/include/linux/pm_domain.h +++ linux-2.6/include/linux/pm_domain.h
@@ -24,6 +24,7 @@ struct dev_power_governor {

struct generic_pm_domain {
struct dev_pm_domain domain; /* PM domain operations */
+ struct list_head gpd_list_node; /* Node in the global PM domains list */
struct list_head sd_node; /* Node in the parent's subdomain list */
struct generic_pm_domain *parent; /* Parent PM domain */
struct list_head sd_list; /* List of dubdomains */
@@ -71,6 +72,7 @@ extern int pm_genpd_remove_subdomain(str
extern void pm_genpd_init(struct generic_pm_domain *genpd,
struct dev_power_governor *gov, bool is_off);
extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
+extern void pm_genpd_poweroff_unused(void);
#else
static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
struct device *dev)
@@ -98,6 +100,7 @@ static inline int pm_genpd_poweron(struc
{
return -ENOSYS;
}
+static inline void pm_genpd_poweroff_unused(void) {}
#endif

#endif /* _LINUX_PM_DOMAIN_H */
Index: linux-2.6/drivers/base/power/domain.c =================================--- linux-2.6.orig/drivers/base/power/domain.c +++ linux-2.6/drivers/base/power/domain.c
@@ -16,6 +16,9 @@
#include <linux/sched.h>
#include <linux/suspend.h>

+static LIST_HEAD(gpd_list);
+static DEFINE_MUTEX(gpd_list_lock);
+
#ifdef CONFIG_PM

static struct generic_pm_domain *dev_to_genpd(struct device *dev)
@@ -1241,4 +1244,22 @@ void pm_genpd_init(struct generic_pm_dom
genpd->domain.ops.restore_noirq = pm_genpd_restore_noirq; genpd->domain.ops.restore = pm_genpd_restore; genpd->domain.ops.complete = pm_genpd_complete;
+ mutex_lock(&gpd_list_lock);
+ list_add(&genpd->gpd_list_node, &gpd_list);
+ mutex_unlock(&gpd_list_lock);
+}
+
+/**
+ * pm_genpd_poweroff_unused - Power off all PM domains with no devices in use.
+ */
+void pm_genpd_poweroff_unused(void)
+{
+ struct generic_pm_domain *genpd;
+
+ mutex_lock(&gpd_list_lock);
+
+ list_for_each_entry(genpd, &gpd_list, gpd_list_node)
+ genpd_queue_power_off_work(genpd);
+
+ mutex_unlock(&gpd_list_lock);
}

#2 lore raw

PATCH 1/2 PM / Domains: Introduce function to power off all unused PM domains

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Add a new function pm_genpd_poweroff_unused() queuing up the execution of pm_genpd_poweroff() for every initialized generic PM domain. Calling it will cause every generic PM domain without devices in use to be powered off.

---
 drivers/base/power/domain.c |   21 +++++++++++++++++++++
 include/linux/pm_domain.h   |    3 +++
 2 files changed, 24 insertions(+)
include/linux/pm_domain.h +3 -0
Index: linux-2.6/include/linux/pm_domain.h
===================================================================
@@ -24,6 +24,7 @@ struct dev_power_governor {
 
 struct generic_pm_domain {
 	struct dev_pm_domain domain;	/* PM domain operations */
+	struct list_head gpd_list_node;	/* Node in the global PM domains list */
 	struct list_head sd_node;	/* Node in the parent's subdomain list */
 	struct generic_pm_domain *parent;	/* Parent PM domain */
 	struct list_head sd_list;	/* List of dubdomains */
@@ -71,6 +72,7 @@ extern int pm_genpd_remove_subdomain(str
 extern void pm_genpd_init(struct generic_pm_domain *genpd,
 			  struct dev_power_governor *gov, bool is_off);
 extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
+extern void pm_genpd_poweroff_unused(void);
 #else
 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
 				      struct device *dev)
@@ -98,6 +100,7 @@ static inline int pm_genpd_poweron(struc
 {
 	return -ENOSYS;
 }
+static inline void pm_genpd_poweroff_unused(void) {}
 #endif
 
 #endif /* _LINUX_PM_DOMAIN_H */
drivers/base/power/domain.c +21 -0
Index: linux-2.6/drivers/base/power/domain.c
===================================================================
@@ -16,6 +16,9 @@
 #include <linux/sched.h>
 #include <linux/suspend.h>
 
+static LIST_HEAD(gpd_list);
+static DEFINE_MUTEX(gpd_list_lock);
+
 #ifdef CONFIG_PM
 
 static struct generic_pm_domain *dev_to_genpd(struct device *dev)
@@ -1241,4 +1244,22 @@ void pm_genpd_init(struct generic_pm_dom
 	genpd->domain.ops.restore_noirq = pm_genpd_restore_noirq;
 	genpd->domain.ops.restore = pm_genpd_restore;
 	genpd->domain.ops.complete = pm_genpd_complete;
+	mutex_lock(&gpd_list_lock);
+	list_add(&genpd->gpd_list_node, &gpd_list);
+	mutex_unlock(&gpd_list_lock);
+}
+
+/**
+ * pm_genpd_poweroff_unused - Power off all PM domains with no devices in use.
+ */
+void pm_genpd_poweroff_unused(void)
+{
+	struct generic_pm_domain *genpd;
+
+	mutex_lock(&gpd_list_lock);
+
+	list_for_each_entry(genpd, &gpd_list, gpd_list_node)
+		genpd_queue_power_off_work(genpd);
+
+	mutex_unlock(&gpd_list_lock);
 }
#3 lore raw

PATCH 2/2 ARM / shmobile: Use pm_genpd_poweroff_unused()

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Make shmobile use pm_genpd_poweroff_unused() instead of the open-coded powering off PM domains without devices in use.

---
 arch/arm/mach-shmobile/include/mach/common.h |    1 -
 arch/arm/mach-shmobile/pm-sh7372.c           |   13 -------------
 arch/arm/mach-shmobile/pm_runtime.c          |    6 ++----
 3 files changed, 2 insertions(+), 18 deletions(-)
arch/arm/mach-shmobile/include/mach/common.h +0 -1
Index: linux-2.6/arch/arm/mach-shmobile/include/mach/common.h
===================================================================
@@ -12,7 +12,6 @@ extern struct platform_suspend_ops shmob
 struct cpuidle_device;
 extern void (*shmobile_cpuidle_modes[])(void);
 extern void (*shmobile_cpuidle_setup)(struct cpuidle_device *dev);
-extern void (*shmobile_runtime_pm_late_init)(void);
 
 extern void sh7367_init_irq(void);
 extern void sh7367_add_early_devices(void);
arch/arm/mach-shmobile/pm-sh7372.c +0 -13
Index: linux-2.6/arch/arm/mach-shmobile/pm-sh7372.c
===================================================================
@@ -126,17 +126,6 @@ static bool pd_active_wakeup(struct devi
 	return true;
 }
 
-static void sh7372_late_pm_domain_off(void)
-{
-	/* request power down of unused pm domains */
-	queue_work(pm_wq, &sh7372_a4lc.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_a4mp.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_d4.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_a3rv.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_a3ri.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_a3sg.genpd.power_off_work);
-}
-
 void sh7372_init_pm_domain(struct sh7372_pm_domain *sh7372_pd)
 {
 	struct generic_pm_domain *genpd = &sh7372_pd->genpd;
@@ -157,8 +146,6 @@ void sh7372_init_pm_domain(struct sh7372
 		genpd->power_on = pd_power_up;
 	}
 	genpd->power_on(&sh7372_pd->genpd);
-
-	shmobile_runtime_pm_late_init = sh7372_late_pm_domain_off;
 }
 
 void sh7372_add_device_to_domain(struct sh7372_pm_domain *sh7372_pd,
arch/arm/mach-shmobile/pm_runtime.c +2 -4
Index: linux-2.6/arch/arm/mach-shmobile/pm_runtime.c
===================================================================
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 #include <linux/io.h>
 #include <linux/pm_runtime.h>
+#include <linux/pm_domain.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/sh_clk.h>
@@ -57,12 +58,9 @@ static int __init sh_pm_runtime_init(voi
 }
 core_initcall(sh_pm_runtime_init);
 
-void (*shmobile_runtime_pm_late_init)(void);
-
 static int __init sh_pm_runtime_late_init(void)
 {
-	if (shmobile_runtime_pm_late_init)
-		shmobile_runtime_pm_late_init();
+	pm_genpd_poweroff_unused();
 	return 0;
 }
 late_initcall(sh_pm_runtime_late_init);
#4 lore raw

PATCH 2/2 ARM / shmobile: Use pm_genpd_poweroff_unused()

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Make shmobile use pm_genpd_poweroff_unused() instead of the open-coded powering off PM domains without devices in use.

---
 arch/arm/mach-shmobile/include/mach/common.h |    1 -
 arch/arm/mach-shmobile/pm-sh7372.c           |   13 -------------
 arch/arm/mach-shmobile/pm_runtime.c          |    6 ++----
 3 files changed, 2 insertions(+), 18 deletions(-)
arch/arm/mach-shmobile/include/mach/common.h +0 -1
Index: linux-2.6/arch/arm/mach-shmobile/include/mach/common.h
===================================================================
@@ -12,7 +12,6 @@ extern struct platform_suspend_ops shmob
 struct cpuidle_device;
 extern void (*shmobile_cpuidle_modes[])(void);
 extern void (*shmobile_cpuidle_setup)(struct cpuidle_device *dev);
-extern void (*shmobile_runtime_pm_late_init)(void);
 
 extern void sh7367_init_irq(void);
 extern void sh7367_add_early_devices(void);
arch/arm/mach-shmobile/pm-sh7372.c +0 -13
Index: linux-2.6/arch/arm/mach-shmobile/pm-sh7372.c
===================================================================
@@ -126,17 +126,6 @@ static bool pd_active_wakeup(struct devi
 	return true;
 }
 
-static void sh7372_late_pm_domain_off(void)
-{
-	/* request power down of unused pm domains */
-	queue_work(pm_wq, &sh7372_a4lc.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_a4mp.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_d4.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_a3rv.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_a3ri.genpd.power_off_work);
-	queue_work(pm_wq, &sh7372_a3sg.genpd.power_off_work);
-}
-
 void sh7372_init_pm_domain(struct sh7372_pm_domain *sh7372_pd)
 {
 	struct generic_pm_domain *genpd = &sh7372_pd->genpd;
@@ -157,8 +146,6 @@ void sh7372_init_pm_domain(struct sh7372
 		genpd->power_on = pd_power_up;
 	}
 	genpd->power_on(&sh7372_pd->genpd);
-
-	shmobile_runtime_pm_late_init = sh7372_late_pm_domain_off;
 }
 
 void sh7372_add_device_to_domain(struct sh7372_pm_domain *sh7372_pd,
arch/arm/mach-shmobile/pm_runtime.c +2 -4
Index: linux-2.6/arch/arm/mach-shmobile/pm_runtime.c
===================================================================
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 #include <linux/io.h>
 #include <linux/pm_runtime.h>
+#include <linux/pm_domain.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/sh_clk.h>
@@ -57,12 +58,9 @@ static int __init sh_pm_runtime_init(voi
 }
 core_initcall(sh_pm_runtime_init);
 
-void (*shmobile_runtime_pm_late_init)(void);
-
 static int __init sh_pm_runtime_late_init(void)
 {
-	if (shmobile_runtime_pm_late_init)
-		shmobile_runtime_pm_late_init();
+	pm_genpd_poweroff_unused();
 	return 0;
 }
 late_initcall(sh_pm_runtime_late_init);