All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: "Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Lorenzo Pieralisi <Lorenzo.Pieralisi@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Lina Iyer <ilina@codeaurora.org>,
	Linux PM <linux-pm@vger.kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 5/7] drivers: firmware: psci: Simplify state node parsing
Date: Thu, 28 Feb 2019 23:26:41 +0100	[thread overview]
Message-ID: <CAPDyKFrdwkERTGOkfjCZv-cb0sTvDqtNWY6kKyaeWLHSumRp1A@mail.gmail.com> (raw)
In-Reply-To: <a66689f2-51ba-6358-f161-66778daa1f09@linaro.org>

On Thu, 28 Feb 2019 at 16:40, Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>
> On 28/02/2019 14:59, Ulf Hansson wrote:
> > Instead of iterating through all the state nodes in DT, to find out how
> > many states that needs to be allocated, let's use the number already known
> > by the cpuidle driver. In this way we can drop the iteration altogether.
> >
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > ---
> >  drivers/firmware/psci/psci.c | 25 ++++++++++++-------------
> >  1 file changed, 12 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
> > index d50b46a0528f..cbfc936d251c 100644
> > --- a/drivers/firmware/psci/psci.c
> > +++ b/drivers/firmware/psci/psci.c
> > @@ -290,26 +290,20 @@ static int psci_dt_parse_state_node(struct device_node *np, u32 *state)
> >  static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv,
> >                       struct device_node *cpu_node, int cpu)
> >  {
> > -     int i, ret = 0, count = 0;
> > +     int i, ret = 0, num_state_nodes = drv->state_count - 1;
>
> why -1 ?

Because of the WFI state. The cpuidle-arm driver always carries this
state at index 0, which also is never used in
psci_cpu_suspend_enter(), where the similar is taken into account.

It's a bit of magic, so perhaps someone should post a patch that
documents this a bit better in the code, wherever it makes sense.

>
> >       u32 *psci_states;
> >       struct device_node *state_node;
> >
> > -     /* Count idle states */
> > -     while ((state_node = of_parse_phandle(cpu_node, "cpu-idle-states",
> > -                                           count))) {
> > -             count++;
> > -             of_node_put(state_node);
> > -     }
> > -
> > -     if (!count)
> > -             return -ENODEV;
> > -
> > -     psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
> > +     psci_states = kcalloc(num_state_nodes, sizeof(*psci_states),
> > +                     GFP_KERNEL);
> >       if (!psci_states)
> >               return -ENOMEM;
> >
> > -     for (i = 0; i < count; i++) {
> > +     for (i = 0; i < num_state_nodes; i++) {
> >               state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i);
> > +             if (!state_node)
> > +                     break;
> > +
> >               ret = psci_dt_parse_state_node(state_node, &psci_states[i]);
> >               of_node_put(state_node);
> >
> > @@ -319,6 +313,11 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv,
> >               pr_debug("psci-power-state %#x index %d\n", psci_states[i], i);
> >       }
> >
> > +     if (i != num_state_nodes) {
> > +             ret = -ENODEV;
> > +             goto free_mem;
> > +     }
> > +
> >       /* Idle states parsed correctly, initialize per-cpu pointer */
> >       per_cpu(psci_power_state, cpu) = psci_states;
> >       return 0;
> >

Again, thanks a lot for reviewing!

Kind regards
Uffe

WARNING: multiple messages have this Message-ID (diff)
From: Ulf Hansson <ulf.hansson@linaro.org>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Lorenzo Pieralisi <Lorenzo.Pieralisi@arm.com>,
	Linux PM <linux-pm@vger.kernel.org>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Lina Iyer <ilina@codeaurora.org>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 5/7] drivers: firmware: psci: Simplify state node parsing
Date: Thu, 28 Feb 2019 23:26:41 +0100	[thread overview]
Message-ID: <CAPDyKFrdwkERTGOkfjCZv-cb0sTvDqtNWY6kKyaeWLHSumRp1A@mail.gmail.com> (raw)
In-Reply-To: <a66689f2-51ba-6358-f161-66778daa1f09@linaro.org>

On Thu, 28 Feb 2019 at 16:40, Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>
> On 28/02/2019 14:59, Ulf Hansson wrote:
> > Instead of iterating through all the state nodes in DT, to find out how
> > many states that needs to be allocated, let's use the number already known
> > by the cpuidle driver. In this way we can drop the iteration altogether.
> >
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > ---
> >  drivers/firmware/psci/psci.c | 25 ++++++++++++-------------
> >  1 file changed, 12 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
> > index d50b46a0528f..cbfc936d251c 100644
> > --- a/drivers/firmware/psci/psci.c
> > +++ b/drivers/firmware/psci/psci.c
> > @@ -290,26 +290,20 @@ static int psci_dt_parse_state_node(struct device_node *np, u32 *state)
> >  static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv,
> >                       struct device_node *cpu_node, int cpu)
> >  {
> > -     int i, ret = 0, count = 0;
> > +     int i, ret = 0, num_state_nodes = drv->state_count - 1;
>
> why -1 ?

Because of the WFI state. The cpuidle-arm driver always carries this
state at index 0, which also is never used in
psci_cpu_suspend_enter(), where the similar is taken into account.

It's a bit of magic, so perhaps someone should post a patch that
documents this a bit better in the code, wherever it makes sense.

>
> >       u32 *psci_states;
> >       struct device_node *state_node;
> >
> > -     /* Count idle states */
> > -     while ((state_node = of_parse_phandle(cpu_node, "cpu-idle-states",
> > -                                           count))) {
> > -             count++;
> > -             of_node_put(state_node);
> > -     }
> > -
> > -     if (!count)
> > -             return -ENODEV;
> > -
> > -     psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
> > +     psci_states = kcalloc(num_state_nodes, sizeof(*psci_states),
> > +                     GFP_KERNEL);
> >       if (!psci_states)
> >               return -ENOMEM;
> >
> > -     for (i = 0; i < count; i++) {
> > +     for (i = 0; i < num_state_nodes; i++) {
> >               state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i);
> > +             if (!state_node)
> > +                     break;
> > +
> >               ret = psci_dt_parse_state_node(state_node, &psci_states[i]);
> >               of_node_put(state_node);
> >
> > @@ -319,6 +313,11 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv,
> >               pr_debug("psci-power-state %#x index %d\n", psci_states[i], i);
> >       }
> >
> > +     if (i != num_state_nodes) {
> > +             ret = -ENODEV;
> > +             goto free_mem;
> > +     }
> > +
> >       /* Idle states parsed correctly, initialize per-cpu pointer */
> >       per_cpu(psci_power_state, cpu) = psci_states;
> >       return 0;
> >

Again, thanks a lot for reviewing!

Kind regards
Uffe

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

  reply	other threads:[~2019-02-28 22:26 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28 13:59 [PATCH 0/7] drivers: firmware: psci: Some cleanup and refactoring Ulf Hansson
2019-02-28 13:59 ` Ulf Hansson
2019-02-28 13:59 ` [PATCH 1/7] drivers: firmware: psci: Move psci to separate directory Ulf Hansson
2019-02-28 13:59   ` Ulf Hansson
2019-02-28 13:59   ` Ulf Hansson
2019-02-28 14:34   ` Daniel Lezcano
2019-02-28 14:34     ` Daniel Lezcano
2019-03-01 17:03   ` Mark Rutland
2019-03-01 17:03     ` Mark Rutland
2019-02-28 13:59 ` [PATCH 2/7] MAINTAINERS: Update files for PSCI Ulf Hansson
2019-02-28 13:59   ` Ulf Hansson
2019-02-28 14:35   ` Daniel Lezcano
2019-02-28 14:35     ` Daniel Lezcano
2019-03-01 17:04   ` Mark Rutland
2019-03-01 17:04     ` Mark Rutland
2019-02-28 13:59 ` [PATCH 3/7] drivers: firmware: psci: Split psci_dt_cpu_init_idle() Ulf Hansson
2019-02-28 13:59   ` Ulf Hansson
2019-02-28 14:42   ` Daniel Lezcano
2019-02-28 14:42     ` Daniel Lezcano
2019-02-28 22:13     ` Ulf Hansson
2019-02-28 22:13       ` Ulf Hansson
2019-03-01 17:07   ` Mark Rutland
2019-03-01 17:07     ` Mark Rutland
2019-02-28 13:59 ` [PATCH 4/7] ARM/ARM64: cpuidle: Let back-end init ops take the driver as input Ulf Hansson
2019-02-28 13:59   ` Ulf Hansson
2019-02-28 15:30   ` Daniel Lezcano
2019-02-28 15:30     ` Daniel Lezcano
2019-03-01 17:31   ` Mark Rutland
2019-03-01 17:31     ` Mark Rutland
2019-02-28 13:59 ` [PATCH 5/7] drivers: firmware: psci: Simplify state node parsing Ulf Hansson
2019-02-28 13:59   ` Ulf Hansson
2019-02-28 15:40   ` Daniel Lezcano
2019-02-28 15:40     ` Daniel Lezcano
2019-02-28 22:26     ` Ulf Hansson [this message]
2019-02-28 22:26       ` Ulf Hansson
2019-02-28 22:41       ` Daniel Lezcano
2019-02-28 22:41         ` Daniel Lezcano
2019-03-01 17:28   ` Mark Rutland
2019-03-01 17:28     ` Mark Rutland
2019-03-04 10:14     ` Ulf Hansson
2019-03-04 10:14       ` Ulf Hansson
2019-03-06 18:15       ` Lorenzo Pieralisi
2019-03-06 18:15         ` Lorenzo Pieralisi
2019-03-08 10:36         ` Ulf Hansson
2019-03-08 10:36           ` Ulf Hansson
2019-03-08 11:49           ` Lorenzo Pieralisi
2019-03-08 11:49             ` Lorenzo Pieralisi
2019-03-08 13:07             ` Ulf Hansson
2019-03-08 13:07               ` Ulf Hansson
2019-03-08 13:17               ` Lorenzo Pieralisi
2019-03-08 13:17                 ` Lorenzo Pieralisi
2019-03-08 13:23                 ` Ulf Hansson
2019-03-08 13:23                   ` Ulf Hansson
2019-03-08 13:31                   ` Lorenzo Pieralisi
2019-03-08 13:31                     ` Lorenzo Pieralisi
2019-03-08 13:43                     ` Ulf Hansson
2019-03-08 13:43                       ` Ulf Hansson
2019-02-28 13:59 ` [PATCH 6/7] drivers: firmware: psci: Simplify error path of psci_dt_init() Ulf Hansson
2019-02-28 13:59   ` Ulf Hansson
2019-02-28 13:59 ` [PATCH 7/7] drivers: firmware: psci: Announce support for OS initiated suspend mode Ulf Hansson
2019-02-28 13:59   ` Ulf Hansson
2019-03-01 17:28   ` Stephen Boyd
2019-03-01 17:28     ` Stephen Boyd
2019-03-01 17:28     ` Stephen Boyd
2019-03-04 10:25     ` Ulf Hansson
2019-03-04 10:25       ` Ulf Hansson
2019-03-01 17:32   ` Mark Rutland
2019-03-01 17:32     ` Mark Rutland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPDyKFrdwkERTGOkfjCZv-cb0sTvDqtNWY6kKyaeWLHSumRp1A@mail.gmail.com \
    --to=ulf.hansson@linaro.org \
    --cc=Lorenzo.Pieralisi@arm.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=ilina@codeaurora.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=rjw@rjwysocki.net \
    --cc=sudeep.holla@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.