All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] PM: runtime/cpuidle: Improve suspend-to-ram support for cpuidle-psci
@ 2022-04-01 14:11 ` Ulf Hansson
  0 siblings, 0 replies; 12+ messages in thread
From: Ulf Hansson @ 2022-04-01 14:11 UTC (permalink / raw)
  To: Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Maulik Shah, Daniel Lezcano, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Alexandre Torgue, Ulf Hansson,
	linux-arm-kernel

Maulik Shah reported a problem with suspend-to-ram for one of the Qualcomm
platforms that is using PSCI OSI mode. Briefly described, the genpd on/off
notifiers doesn't get sent when the boot CPU is turned on/off, which prevents
the needed platform specific operations to be executed.

This series intends to solve these problems.

Note that, I have tested this on Dragonboard 410c, with some local hacks to the
PSCI firmware driver. This was needed because the PSCI firmware didn't support
SYSTEM_SUSPEND, so I basically made psci_system_suspend_enter() to call
cpu_do_idle() and forced a suspend ops to be registered.

Maulik, can you please test this at your setup?

Kind regards
Ulf Hansson


Ulf Hansson (2):
  PM: runtime: Allow to call __pm_runtime_set_status() from atomic
    context
  cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode

 drivers/base/power/runtime.c   |  9 ++++---
 drivers/cpuidle/cpuidle-psci.c | 46 ++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 4 deletions(-)

-- 
2.25.1


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

* [PATCH 0/2] PM: runtime/cpuidle: Improve suspend-to-ram support for cpuidle-psci
@ 2022-04-01 14:11 ` Ulf Hansson
  0 siblings, 0 replies; 12+ messages in thread
From: Ulf Hansson @ 2022-04-01 14:11 UTC (permalink / raw)
  To: Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Maulik Shah, Daniel Lezcano, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Alexandre Torgue, Ulf Hansson,
	linux-arm-kernel

Maulik Shah reported a problem with suspend-to-ram for one of the Qualcomm
platforms that is using PSCI OSI mode. Briefly described, the genpd on/off
notifiers doesn't get sent when the boot CPU is turned on/off, which prevents
the needed platform specific operations to be executed.

This series intends to solve these problems.

Note that, I have tested this on Dragonboard 410c, with some local hacks to the
PSCI firmware driver. This was needed because the PSCI firmware didn't support
SYSTEM_SUSPEND, so I basically made psci_system_suspend_enter() to call
cpu_do_idle() and forced a suspend ops to be registered.

Maulik, can you please test this at your setup?

Kind regards
Ulf Hansson


Ulf Hansson (2):
  PM: runtime: Allow to call __pm_runtime_set_status() from atomic
    context
  cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode

 drivers/base/power/runtime.c   |  9 ++++---
 drivers/cpuidle/cpuidle-psci.c | 46 ++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 4 deletions(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 1/2] PM: runtime: Allow to call __pm_runtime_set_status() from atomic context
  2022-04-01 14:11 ` Ulf Hansson
@ 2022-04-01 14:11   ` Ulf Hansson
  -1 siblings, 0 replies; 12+ messages in thread
From: Ulf Hansson @ 2022-04-01 14:11 UTC (permalink / raw)
  To: Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Maulik Shah, Daniel Lezcano, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Alexandre Torgue, Ulf Hansson,
	linux-arm-kernel

The only two users of __pm_runtime_set_status() are pm_runtime_set_active()
and pm_runtime_set_suspended(). These are widely used and should be called
from non-atomic context to work as expected. However, it would be
convenient to allow them be called from atomic context too, as shown from a
subsequent change, so let's add support for this.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/base/power/runtime.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index d4059e6ffeae..91d757914686 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1210,12 +1210,13 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
 {
 	struct device *parent = dev->parent;
 	bool notify_parent = false;
+	unsigned long flags;
 	int error = 0;
 
 	if (status != RPM_ACTIVE && status != RPM_SUSPENDED)
 		return -EINVAL;
 
-	spin_lock_irq(&dev->power.lock);
+	spin_lock_irqsave(&dev->power.lock, flags);
 
 	/*
 	 * Prevent PM-runtime from being enabled for the device or return an
@@ -1226,7 +1227,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
 	else
 		error = -EAGAIN;
 
-	spin_unlock_irq(&dev->power.lock);
+	spin_unlock_irqrestore(&dev->power.lock, flags);
 
 	if (error)
 		return error;
@@ -1247,7 +1248,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
 		device_links_read_unlock(idx);
 	}
 
-	spin_lock_irq(&dev->power.lock);
+	spin_lock_irqsave(&dev->power.lock, flags);
 
 	if (dev->power.runtime_status == status || !parent)
 		goto out_set;
@@ -1288,7 +1289,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
 		dev->power.runtime_error = 0;
 
  out:
-	spin_unlock_irq(&dev->power.lock);
+	spin_unlock_irqrestore(&dev->power.lock, flags);
 
 	if (notify_parent)
 		pm_request_idle(parent);
-- 
2.25.1


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

* [PATCH 1/2] PM: runtime: Allow to call __pm_runtime_set_status() from atomic context
@ 2022-04-01 14:11   ` Ulf Hansson
  0 siblings, 0 replies; 12+ messages in thread
From: Ulf Hansson @ 2022-04-01 14:11 UTC (permalink / raw)
  To: Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Maulik Shah, Daniel Lezcano, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Alexandre Torgue, Ulf Hansson,
	linux-arm-kernel

The only two users of __pm_runtime_set_status() are pm_runtime_set_active()
and pm_runtime_set_suspended(). These are widely used and should be called
from non-atomic context to work as expected. However, it would be
convenient to allow them be called from atomic context too, as shown from a
subsequent change, so let's add support for this.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/base/power/runtime.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index d4059e6ffeae..91d757914686 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1210,12 +1210,13 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
 {
 	struct device *parent = dev->parent;
 	bool notify_parent = false;
+	unsigned long flags;
 	int error = 0;
 
 	if (status != RPM_ACTIVE && status != RPM_SUSPENDED)
 		return -EINVAL;
 
-	spin_lock_irq(&dev->power.lock);
+	spin_lock_irqsave(&dev->power.lock, flags);
 
 	/*
 	 * Prevent PM-runtime from being enabled for the device or return an
@@ -1226,7 +1227,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
 	else
 		error = -EAGAIN;
 
-	spin_unlock_irq(&dev->power.lock);
+	spin_unlock_irqrestore(&dev->power.lock, flags);
 
 	if (error)
 		return error;
@@ -1247,7 +1248,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
 		device_links_read_unlock(idx);
 	}
 
-	spin_lock_irq(&dev->power.lock);
+	spin_lock_irqsave(&dev->power.lock, flags);
 
 	if (dev->power.runtime_status == status || !parent)
 		goto out_set;
@@ -1288,7 +1289,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
 		dev->power.runtime_error = 0;
 
  out:
-	spin_unlock_irq(&dev->power.lock);
+	spin_unlock_irqrestore(&dev->power.lock, flags);
 
 	if (notify_parent)
 		pm_request_idle(parent);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 2/2] cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode
  2022-04-01 14:11 ` Ulf Hansson
@ 2022-04-01 14:11   ` Ulf Hansson
  -1 siblings, 0 replies; 12+ messages in thread
From: Ulf Hansson @ 2022-04-01 14:11 UTC (permalink / raw)
  To: Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Maulik Shah, Daniel Lezcano, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Alexandre Torgue, Ulf Hansson,
	linux-arm-kernel

When PSCI OSI mode is supported the syscore flag is set for the CPU devices
that becomes attached to their PM domains (genpds). In the suspend-to-idle
case, we call dev_pm_genpd_suspend|resume() to allow genpd to properly
manage the power-off/on operations (pick an idlestate and manage the on/off
notifications).

For suspend-to-ram, dev_pm_genpd_suspend|resume() is currently not being
called, which causes a problem that the genpd on/off notifiers do not get
sent as expected. This prevents the platform-specific operations from being
executed, typically needed just before/after the boot CPU is being turned
off/on.

To deal with this problem, let's register a syscore ops for cpuidle-psci
when PSCI OSI mode is being used and call dev_pm_genpd_suspend|resume()
from them. In this way, genpd regains control of the PM domain topology and
then sends the on/off notifications when it's appropriate.

Reported-by: Maulik Shah <quic_mkshah@quicinc.com>
Suggested-by: Maulik Shah <quic_mkshah@quicinc.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/cpuidle/cpuidle-psci.c | 46 ++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c
index b51b5df08450..540105ca0781 100644
--- a/drivers/cpuidle/cpuidle-psci.c
+++ b/drivers/cpuidle/cpuidle-psci.c
@@ -23,6 +23,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/syscore_ops.h>
 
 #include <asm/cpuidle.h>
 
@@ -131,6 +132,49 @@ static int psci_idle_cpuhp_down(unsigned int cpu)
 	return 0;
 }
 
+static void psci_idle_syscore_switch(bool suspend)
+{
+	bool cleared = false;
+	struct device *dev;
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		dev = per_cpu_ptr(&psci_cpuidle_data, cpu)->dev;
+
+		if (dev && suspend) {
+			dev_pm_genpd_suspend(dev);
+		} else if (dev) {
+			dev_pm_genpd_resume(dev);
+
+			/* Account for userspace having offlined a CPU. */
+			if (pm_runtime_status_suspended(dev))
+				pm_runtime_set_active(dev);
+
+			/* Clear domain state to re-start fresh. */
+			if (!cleared) {
+				psci_set_domain_state(0);
+				cleared = true;
+			}
+		}
+	}
+}
+
+static int psci_idle_syscore_suspend(void)
+{
+	psci_idle_syscore_switch(true);
+	return 0;
+}
+
+static void psci_idle_syscore_resume(void)
+{
+	psci_idle_syscore_switch(false);
+}
+
+static struct syscore_ops psci_idle_syscore_ops = {
+	.suspend = psci_idle_syscore_suspend,
+	.resume = psci_idle_syscore_resume,
+};
+
 static void psci_idle_init_cpuhp(void)
 {
 	int err;
@@ -138,6 +182,8 @@ static void psci_idle_init_cpuhp(void)
 	if (!psci_cpuidle_use_cpuhp)
 		return;
 
+	register_syscore_ops(&psci_idle_syscore_ops);
+
 	err = cpuhp_setup_state_nocalls(CPUHP_AP_CPU_PM_STARTING,
 					"cpuidle/psci:online",
 					psci_idle_cpuhp_up,
-- 
2.25.1


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

* [PATCH 2/2] cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode
@ 2022-04-01 14:11   ` Ulf Hansson
  0 siblings, 0 replies; 12+ messages in thread
From: Ulf Hansson @ 2022-04-01 14:11 UTC (permalink / raw)
  To: Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Maulik Shah, Daniel Lezcano, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Alexandre Torgue, Ulf Hansson,
	linux-arm-kernel

When PSCI OSI mode is supported the syscore flag is set for the CPU devices
that becomes attached to their PM domains (genpds). In the suspend-to-idle
case, we call dev_pm_genpd_suspend|resume() to allow genpd to properly
manage the power-off/on operations (pick an idlestate and manage the on/off
notifications).

For suspend-to-ram, dev_pm_genpd_suspend|resume() is currently not being
called, which causes a problem that the genpd on/off notifiers do not get
sent as expected. This prevents the platform-specific operations from being
executed, typically needed just before/after the boot CPU is being turned
off/on.

To deal with this problem, let's register a syscore ops for cpuidle-psci
when PSCI OSI mode is being used and call dev_pm_genpd_suspend|resume()
from them. In this way, genpd regains control of the PM domain topology and
then sends the on/off notifications when it's appropriate.

Reported-by: Maulik Shah <quic_mkshah@quicinc.com>
Suggested-by: Maulik Shah <quic_mkshah@quicinc.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/cpuidle/cpuidle-psci.c | 46 ++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c
index b51b5df08450..540105ca0781 100644
--- a/drivers/cpuidle/cpuidle-psci.c
+++ b/drivers/cpuidle/cpuidle-psci.c
@@ -23,6 +23,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/syscore_ops.h>
 
 #include <asm/cpuidle.h>
 
@@ -131,6 +132,49 @@ static int psci_idle_cpuhp_down(unsigned int cpu)
 	return 0;
 }
 
+static void psci_idle_syscore_switch(bool suspend)
+{
+	bool cleared = false;
+	struct device *dev;
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		dev = per_cpu_ptr(&psci_cpuidle_data, cpu)->dev;
+
+		if (dev && suspend) {
+			dev_pm_genpd_suspend(dev);
+		} else if (dev) {
+			dev_pm_genpd_resume(dev);
+
+			/* Account for userspace having offlined a CPU. */
+			if (pm_runtime_status_suspended(dev))
+				pm_runtime_set_active(dev);
+
+			/* Clear domain state to re-start fresh. */
+			if (!cleared) {
+				psci_set_domain_state(0);
+				cleared = true;
+			}
+		}
+	}
+}
+
+static int psci_idle_syscore_suspend(void)
+{
+	psci_idle_syscore_switch(true);
+	return 0;
+}
+
+static void psci_idle_syscore_resume(void)
+{
+	psci_idle_syscore_switch(false);
+}
+
+static struct syscore_ops psci_idle_syscore_ops = {
+	.suspend = psci_idle_syscore_suspend,
+	.resume = psci_idle_syscore_resume,
+};
+
 static void psci_idle_init_cpuhp(void)
 {
 	int err;
@@ -138,6 +182,8 @@ static void psci_idle_init_cpuhp(void)
 	if (!psci_cpuidle_use_cpuhp)
 		return;
 
+	register_syscore_ops(&psci_idle_syscore_ops);
+
 	err = cpuhp_setup_state_nocalls(CPUHP_AP_CPU_PM_STARTING,
 					"cpuidle/psci:online",
 					psci_idle_cpuhp_up,
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 0/2] PM: runtime/cpuidle: Improve suspend-to-ram support for cpuidle-psci
  2022-04-01 14:11 ` Ulf Hansson
@ 2022-04-13 15:16   ` Rafael J. Wysocki
  -1 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2022-04-13 15:16 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi, Linux PM,
	Maulik Shah, Daniel Lezcano, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Alexandre Torgue, Linux ARM

On Fri, Apr 1, 2022 at 4:11 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> Maulik Shah reported a problem with suspend-to-ram for one of the Qualcomm
> platforms that is using PSCI OSI mode. Briefly described, the genpd on/off
> notifiers doesn't get sent when the boot CPU is turned on/off, which prevents
> the needed platform specific operations to be executed.
>
> This series intends to solve these problems.
>
> Note that, I have tested this on Dragonboard 410c, with some local hacks to the
> PSCI firmware driver. This was needed because the PSCI firmware didn't support
> SYSTEM_SUSPEND, so I basically made psci_system_suspend_enter() to call
> cpu_do_idle() and forced a suspend ops to be registered.
>
> Maulik, can you please test this at your setup?
>
> Kind regards
> Ulf Hansson
>
>
> Ulf Hansson (2):
>   PM: runtime: Allow to call __pm_runtime_set_status() from atomic
>     context
>   cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode
>
>  drivers/base/power/runtime.c   |  9 ++++---
>  drivers/cpuidle/cpuidle-psci.c | 46 ++++++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 4 deletions(-)

Both patches applied as 5.19 material (in the PM-sleep category,
because they really are system-wide suspend support material).

Thanks!

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

* Re: [PATCH 0/2] PM: runtime/cpuidle: Improve suspend-to-ram support for cpuidle-psci
@ 2022-04-13 15:16   ` Rafael J. Wysocki
  0 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2022-04-13 15:16 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi, Linux PM,
	Maulik Shah, Daniel Lezcano, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Alexandre Torgue, Linux ARM

On Fri, Apr 1, 2022 at 4:11 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> Maulik Shah reported a problem with suspend-to-ram for one of the Qualcomm
> platforms that is using PSCI OSI mode. Briefly described, the genpd on/off
> notifiers doesn't get sent when the boot CPU is turned on/off, which prevents
> the needed platform specific operations to be executed.
>
> This series intends to solve these problems.
>
> Note that, I have tested this on Dragonboard 410c, with some local hacks to the
> PSCI firmware driver. This was needed because the PSCI firmware didn't support
> SYSTEM_SUSPEND, so I basically made psci_system_suspend_enter() to call
> cpu_do_idle() and forced a suspend ops to be registered.
>
> Maulik, can you please test this at your setup?
>
> Kind regards
> Ulf Hansson
>
>
> Ulf Hansson (2):
>   PM: runtime: Allow to call __pm_runtime_set_status() from atomic
>     context
>   cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode
>
>  drivers/base/power/runtime.c   |  9 ++++---
>  drivers/cpuidle/cpuidle-psci.c | 46 ++++++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 4 deletions(-)

Both patches applied as 5.19 material (in the PM-sleep category,
because they really are system-wide suspend support material).

Thanks!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/2] PM: runtime: Allow to call __pm_runtime_set_status() from atomic context
  2022-04-01 14:11   ` Ulf Hansson
@ 2022-04-19  8:54     ` Maulik Shah (mkshah)
  -1 siblings, 0 replies; 12+ messages in thread
From: Maulik Shah (mkshah) @ 2022-04-19  8:54 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi,
	linux-pm
  Cc: Daniel Lezcano, Lukasz Luba, Vincent Guittot, Stephen Boyd,
	Bjorn Andersson, Alexandre Torgue, linux-arm-kernel

Hi,

On 4/1/2022 7:41 PM, Ulf Hansson wrote:
> The only two users of __pm_runtime_set_status() are pm_runtime_set_active()
> and pm_runtime_set_suspended(). These are widely used and should be called
> from non-atomic context to work as expected. However, it would be
> convenient to allow them be called from atomic context too, as shown from a
> subsequent change, so let's add support for this.
>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Maulik Shah <quic_mkshah@quicinc.com>

Thanks,
Maulik
> ---
>   drivers/base/power/runtime.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index d4059e6ffeae..91d757914686 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -1210,12 +1210,13 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
>   {
>   	struct device *parent = dev->parent;
>   	bool notify_parent = false;
> +	unsigned long flags;
>   	int error = 0;
>   
>   	if (status != RPM_ACTIVE && status != RPM_SUSPENDED)
>   		return -EINVAL;
>   
> -	spin_lock_irq(&dev->power.lock);
> +	spin_lock_irqsave(&dev->power.lock, flags);
>   
>   	/*
>   	 * Prevent PM-runtime from being enabled for the device or return an
> @@ -1226,7 +1227,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
>   	else
>   		error = -EAGAIN;
>   
> -	spin_unlock_irq(&dev->power.lock);
> +	spin_unlock_irqrestore(&dev->power.lock, flags);
>   
>   	if (error)
>   		return error;
> @@ -1247,7 +1248,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
>   		device_links_read_unlock(idx);
>   	}
>   
> -	spin_lock_irq(&dev->power.lock);
> +	spin_lock_irqsave(&dev->power.lock, flags);
>   
>   	if (dev->power.runtime_status == status || !parent)
>   		goto out_set;
> @@ -1288,7 +1289,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
>   		dev->power.runtime_error = 0;
>   
>    out:
> -	spin_unlock_irq(&dev->power.lock);
> +	spin_unlock_irqrestore(&dev->power.lock, flags);
>   
>   	if (notify_parent)
>   		pm_request_idle(parent);

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

* Re: [PATCH 1/2] PM: runtime: Allow to call __pm_runtime_set_status() from atomic context
@ 2022-04-19  8:54     ` Maulik Shah (mkshah)
  0 siblings, 0 replies; 12+ messages in thread
From: Maulik Shah (mkshah) @ 2022-04-19  8:54 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi,
	linux-pm
  Cc: Daniel Lezcano, Lukasz Luba, Vincent Guittot, Stephen Boyd,
	Bjorn Andersson, Alexandre Torgue, linux-arm-kernel

Hi,

On 4/1/2022 7:41 PM, Ulf Hansson wrote:
> The only two users of __pm_runtime_set_status() are pm_runtime_set_active()
> and pm_runtime_set_suspended(). These are widely used and should be called
> from non-atomic context to work as expected. However, it would be
> convenient to allow them be called from atomic context too, as shown from a
> subsequent change, so let's add support for this.
>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Maulik Shah <quic_mkshah@quicinc.com>

Thanks,
Maulik
> ---
>   drivers/base/power/runtime.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index d4059e6ffeae..91d757914686 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -1210,12 +1210,13 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
>   {
>   	struct device *parent = dev->parent;
>   	bool notify_parent = false;
> +	unsigned long flags;
>   	int error = 0;
>   
>   	if (status != RPM_ACTIVE && status != RPM_SUSPENDED)
>   		return -EINVAL;
>   
> -	spin_lock_irq(&dev->power.lock);
> +	spin_lock_irqsave(&dev->power.lock, flags);
>   
>   	/*
>   	 * Prevent PM-runtime from being enabled for the device or return an
> @@ -1226,7 +1227,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
>   	else
>   		error = -EAGAIN;
>   
> -	spin_unlock_irq(&dev->power.lock);
> +	spin_unlock_irqrestore(&dev->power.lock, flags);
>   
>   	if (error)
>   		return error;
> @@ -1247,7 +1248,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
>   		device_links_read_unlock(idx);
>   	}
>   
> -	spin_lock_irq(&dev->power.lock);
> +	spin_lock_irqsave(&dev->power.lock, flags);
>   
>   	if (dev->power.runtime_status == status || !parent)
>   		goto out_set;
> @@ -1288,7 +1289,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status)
>   		dev->power.runtime_error = 0;
>   
>    out:
> -	spin_unlock_irq(&dev->power.lock);
> +	spin_unlock_irqrestore(&dev->power.lock, flags);
>   
>   	if (notify_parent)
>   		pm_request_idle(parent);

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 2/2] cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode
  2022-04-01 14:11   ` Ulf Hansson
@ 2022-04-19  8:54     ` Maulik Shah (mkshah)
  -1 siblings, 0 replies; 12+ messages in thread
From: Maulik Shah (mkshah) @ 2022-04-19  8:54 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi,
	linux-pm
  Cc: Daniel Lezcano, Lukasz Luba, Vincent Guittot, Stephen Boyd,
	Bjorn Andersson, Alexandre Torgue, linux-arm-kernel

Hi,

On 4/1/2022 7:41 PM, Ulf Hansson wrote:
> When PSCI OSI mode is supported the syscore flag is set for the CPU devices
> that becomes attached to their PM domains (genpds). In the suspend-to-idle
> case, we call dev_pm_genpd_suspend|resume() to allow genpd to properly
> manage the power-off/on operations (pick an idlestate and manage the on/off
> notifications).
>
> For suspend-to-ram, dev_pm_genpd_suspend|resume() is currently not being
> called, which causes a problem that the genpd on/off notifiers do not get
> sent as expected. This prevents the platform-specific operations from being
> executed, typically needed just before/after the boot CPU is being turned
> off/on.
>
> To deal with this problem, let's register a syscore ops for cpuidle-psci
> when PSCI OSI mode is being used and call dev_pm_genpd_suspend|resume()
> from them. In this way, genpd regains control of the PM domain topology and
> then sends the on/off notifications when it's appropriate.
>
> Reported-by: Maulik Shah <quic_mkshah@quicinc.com>
> Suggested-by: Maulik Shah <quic_mkshah@quicinc.com>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Maulik Shah <quic_mkshah@quicinc.com>

Thanks,
Maulik


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

* Re: [PATCH 2/2] cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode
@ 2022-04-19  8:54     ` Maulik Shah (mkshah)
  0 siblings, 0 replies; 12+ messages in thread
From: Maulik Shah (mkshah) @ 2022-04-19  8:54 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Sudeep Holla, Lorenzo Pieralisi,
	linux-pm
  Cc: Daniel Lezcano, Lukasz Luba, Vincent Guittot, Stephen Boyd,
	Bjorn Andersson, Alexandre Torgue, linux-arm-kernel

Hi,

On 4/1/2022 7:41 PM, Ulf Hansson wrote:
> When PSCI OSI mode is supported the syscore flag is set for the CPU devices
> that becomes attached to their PM domains (genpds). In the suspend-to-idle
> case, we call dev_pm_genpd_suspend|resume() to allow genpd to properly
> manage the power-off/on operations (pick an idlestate and manage the on/off
> notifications).
>
> For suspend-to-ram, dev_pm_genpd_suspend|resume() is currently not being
> called, which causes a problem that the genpd on/off notifiers do not get
> sent as expected. This prevents the platform-specific operations from being
> executed, typically needed just before/after the boot CPU is being turned
> off/on.
>
> To deal with this problem, let's register a syscore ops for cpuidle-psci
> when PSCI OSI mode is being used and call dev_pm_genpd_suspend|resume()
> from them. In this way, genpd regains control of the PM domain topology and
> then sends the on/off notifications when it's appropriate.
>
> Reported-by: Maulik Shah <quic_mkshah@quicinc.com>
> Suggested-by: Maulik Shah <quic_mkshah@quicinc.com>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Maulik Shah <quic_mkshah@quicinc.com>

Thanks,
Maulik


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-04-19  8:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 14:11 [PATCH 0/2] PM: runtime/cpuidle: Improve suspend-to-ram support for cpuidle-psci Ulf Hansson
2022-04-01 14:11 ` Ulf Hansson
2022-04-01 14:11 ` [PATCH 1/2] PM: runtime: Allow to call __pm_runtime_set_status() from atomic context Ulf Hansson
2022-04-01 14:11   ` Ulf Hansson
2022-04-19  8:54   ` Maulik Shah (mkshah)
2022-04-19  8:54     ` Maulik Shah (mkshah)
2022-04-01 14:11 ` [PATCH 2/2] cpuidle: psci: Improve support for suspend-to-ram for PSCI OSI mode Ulf Hansson
2022-04-01 14:11   ` Ulf Hansson
2022-04-19  8:54   ` Maulik Shah (mkshah)
2022-04-19  8:54     ` Maulik Shah (mkshah)
2022-04-13 15:16 ` [PATCH 0/2] PM: runtime/cpuidle: Improve suspend-to-ram support for cpuidle-psci Rafael J. Wysocki
2022-04-13 15:16   ` Rafael J. Wysocki

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.