[11/13] cpuidle: psci: Attach CPU devices to their PM domains

Message ID 20191010113937.15962-12-ulf.hansson@linaro.org
State New
Headers show
Series
  • cpuidle: psci: Support hierarchical CPU arrangement
Related show

Commit Message

Ulf Hansson Oct. 10, 2019, 11:39 a.m.
In order to enable a CPU to be power managed through its PM domain, let's
try to attach it by calling psci_dt_attach_cpu() during the cpuidle
initialization.

psci_dt_attach_cpu() returns a pointer to the attached struct device, which
later should be used for runtime PM, hence we need to store it somewhere.
Rather than adding yet another per CPU variable, let's create a per CPU
struct to collect the relevant per CPU variables.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

---
 drivers/cpuidle/cpuidle-psci.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

-- 
2.17.1

Comments

Ulf Hansson Oct. 24, 2019, 4:55 p.m. | #1
On Thu, 24 Oct 2019 at 18:35, Sudeep Holla <sudeep.holla@arm.com> wrote:
>

> On Thu, Oct 10, 2019 at 01:39:35PM +0200, Ulf Hansson wrote:

> > In order to enable a CPU to be power managed through its PM domain, let's

> > try to attach it by calling psci_dt_attach_cpu() during the cpuidle

> > initialization.

> >

> > psci_dt_attach_cpu() returns a pointer to the attached struct device, which

> > later should be used for runtime PM, hence we need to store it somewhere.

> > Rather than adding yet another per CPU variable, let's create a per CPU

> > struct to collect the relevant per CPU variables.

> >

> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

> > ---

> >  drivers/cpuidle/cpuidle-psci.c | 23 +++++++++++++++++++----

> >  1 file changed, 19 insertions(+), 4 deletions(-)

> >

> > diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c

> > index a16467daf99d..1510422c7a53 100644

> > --- a/drivers/cpuidle/cpuidle-psci.c

> > +++ b/drivers/cpuidle/cpuidle-psci.c

> > @@ -23,7 +23,12 @@

> >  #include "cpuidle-psci.h"

> >  #include "dt_idle_states.h"

> >

> > -static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state);

> > +struct psci_cpuidle_data {

> > +     u32 *psci_states;

> > +     struct device *dev;

> > +};

> > +

> > +static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data);

> >  static DEFINE_PER_CPU(u32, domain_state);

> >

>

> /me just thinking still: If it make sense to keep psci_states separate

> and domain_state and only other things needed for RPM/OSI in the

> structure. I do understand that we modify domain_state and hence

> we can't use READ_MOSTLY then. Let's see, for now keep it as is, thought

> I will think out aloud.


I believe we are striving towards the same goal, which likely means to
separate the non-OSI path vs OSI path, as much as possible. Simply to
avoid any unnecessary operation being done in the non-OSI path. Right?

However, while I was trying to address that, I realized that it would
probably introduce even more changes to the series. Therefore, it
thought it may be better to address these kind of changes on top, as
improvements.

Does it make sense?

Kind regards
Uffe

Patch

diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c
index a16467daf99d..1510422c7a53 100644
--- a/drivers/cpuidle/cpuidle-psci.c
+++ b/drivers/cpuidle/cpuidle-psci.c
@@ -23,7 +23,12 @@ 
 #include "cpuidle-psci.h"
 #include "dt_idle_states.h"
 
-static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state);
+struct psci_cpuidle_data {
+	u32 *psci_states;
+	struct device *dev;
+};
+
+static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data);
 static DEFINE_PER_CPU(u32, domain_state);
 
 void psci_set_domain_state(u32 state)
@@ -45,7 +50,7 @@  static int psci_enter_idle_state(struct cpuidle_device *dev,
 				struct cpuidle_driver *drv, int idx)
 {
 	int ret;
-	u32 *states = __this_cpu_read(psci_power_state);
+	u32 *states = __this_cpu_read(psci_cpuidle_data.psci_states);
 	u32 state = psci_get_domain_state();
 
 	if (!state && idx)
@@ -103,7 +108,9 @@  static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node,
 {
 	int i, ret = 0;
 	u32 *psci_states;
+	struct device *dev;
 	struct device_node *state_node;
+	struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu);
 
 	psci_states = kcalloc(state_nodes, sizeof(*psci_states), GFP_KERNEL);
 	if (!psci_states)
@@ -128,8 +135,16 @@  static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node,
 		goto free_mem;
 	}
 
-	/* Idle states parsed correctly, initialize per-cpu pointer */
-	per_cpu(psci_power_state, cpu) = psci_states;
+	dev = psci_dt_attach_cpu(cpu);
+	if (IS_ERR(dev)) {
+		ret = PTR_ERR(dev);
+		goto free_mem;
+	}
+
+	data->dev = dev;
+
+	/* Idle states parsed correctly, store them in the per-cpu struct. */
+	data->psci_states = psci_states;
 	return 0;
 
 free_mem: