linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpuidle: riscv-sbi: Add cluster_pm_enter()/exit()
@ 2024-02-26  6:51 Nick Hu
  2024-04-28 22:00 ` patchwork-bot+linux-riscv
  2024-04-29 14:32 ` Ulf Hansson
  0 siblings, 2 replies; 17+ messages in thread
From: Nick Hu @ 2024-02-26  6:51 UTC (permalink / raw)
  To: anup, rafael, daniel.lezcano, paul.walmsley, palmer, linux-pm,
	linux-riscv, linux-kernel
  Cc: zong.li, Nick Hu

When the cpus in the same cluster are all in the idle state, the kernel
might put the cluster into a deeper low power state. Call the
cluster_pm_enter() before entering the low power state and call the
cluster_pm_exit() after the cluster woken up.

Signed-off-by: Nick Hu <nick.hu@sifive.com>
---
 drivers/cpuidle/cpuidle-riscv-sbi.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
index e8094fc92491..298dc76a00cf 100644
--- a/drivers/cpuidle/cpuidle-riscv-sbi.c
+++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
@@ -394,6 +394,7 @@ static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd)
 {
 	struct genpd_power_state *state = &pd->states[pd->state_idx];
 	u32 *pd_state;
+	int ret;
 
 	if (!state->data)
 		return 0;
@@ -401,6 +402,10 @@ static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd)
 	if (!sbi_cpuidle_pd_allow_domain_state)
 		return -EBUSY;
 
+	ret = cpu_cluster_pm_enter();
+	if (ret)
+		return ret;
+
 	/* OSI mode is enabled, set the corresponding domain state. */
 	pd_state = state->data;
 	sbi_set_domain_state(*pd_state);
@@ -408,6 +413,19 @@ static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd)
 	return 0;
 }
 
+static int sbi_cpuidle_pd_power_on(struct generic_pm_domain *pd)
+{
+	struct genpd_power_state *state = &pd->states[pd->state_idx];
+
+	if (!state->data)
+		return 0;
+
+	if (!sbi_cpuidle_pd_allow_domain_state)
+		return -EBUSY;
+
+	return cpu_cluster_pm_exit();
+}
+
 struct sbi_pd_provider {
 	struct list_head link;
 	struct device_node *node;
@@ -433,10 +451,12 @@ static int sbi_pd_init(struct device_node *np)
 	pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN;
 
 	/* Allow power off when OSI is available. */
-	if (sbi_cpuidle_use_osi)
+	if (sbi_cpuidle_use_osi) {
 		pd->power_off = sbi_cpuidle_pd_power_off;
-	else
+		pd->power_on = sbi_cpuidle_pd_power_on;
+	} else {
 		pd->flags |= GENPD_FLAG_ALWAYS_ON;
+	}
 
 	/* Use governor for CPU PM domains if it has some states to manage. */
 	pd_gov = pd->states ? &pm_domain_cpu_gov : NULL;
-- 
2.34.1


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

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

end of thread, other threads:[~2024-05-24 12:54 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-26  6:51 [PATCH] cpuidle: riscv-sbi: Add cluster_pm_enter()/exit() Nick Hu
2024-04-28 22:00 ` patchwork-bot+linux-riscv
2024-04-29 14:32 ` Ulf Hansson
2024-04-29 16:22   ` Nick Hu
2024-04-29 16:26     ` Nick Hu
2024-04-30  8:12       ` Ulf Hansson
2024-05-14  9:50         ` Nick Hu
2024-05-14 14:23           ` Anup Patel
2024-05-14 14:54             ` Anup Patel
2024-05-15 12:15               ` Nick Hu
2024-05-15 13:45                 ` Anup Patel
2024-05-16  4:09                   ` Nick Hu
2024-05-17  4:39                     ` Anup Patel
2024-05-23  3:26                       ` Nick Hu
2024-05-24 10:41                       ` Ulf Hansson
2024-05-24 12:54                         ` Anup Patel
2024-04-29 20:59   ` Palmer Dabbelt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).