devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org,
	devicetree-discuss@lists.ozlabs.org, linux@arm.linux.org.uk,
	grant.likely@secretlab.ca, rob.herring@calxeda.com,
	yong.zhang0@gmail.com, namhyung@kernel.org,
	jean.pihet@newoldbits.com
Subject: Re: [PATCH v3 3/5] ARM: topology: Update cpu_power according to DT information
Date: Mon, 02 Jul 2012 11:11:23 +0200	[thread overview]
Message-ID: <1341220283.28750.138.camel@twins> (raw)
In-Reply-To: <1340205562-7653-4-git-send-email-vincent.guittot@linaro.org>

On Wed, 2012-06-20 at 17:19 +0200, Vincent Guittot wrote:
> +#ifdef CONFIG_OF
> +struct cpu_efficiency {
> +       const char *compatible;
> +       unsigned long efficiency;
> +};
> +
> +/*
> + * Table of relative efficiency of each processors
> + * The efficiency value must fit in 20bit. The final
> + * cpu_scale value must be in the range
> + * 0 < cpu_scale < 2*SCHED_POWER_SCALE.

This wants a why.. I suspects its to do with keeping capacity on 1.

> + * Processors that are not defined in the table,
> + * use the default SCHED_POWER_SCALE value for cpu_scale.
> + */
> +struct cpu_efficiency table_efficiency[] = {
> +       {"arm,cortex-a15", 3891},
> +       {"arm,cortex-a7",  2048},
> +       {NULL, },
> +};
> +
> +struct cpu_capacity {
> +       unsigned long hwid;
> +       unsigned long capacity;
> +};
> +
> +struct cpu_capacity *cpu_capacity;
> +
> +unsigned long middle_capacity = 1;

It would be very nice to not have to learn to read device-tree nonsense
to work on the scheduler, how about something like this:?

/*
 * Iterate all cpus and set the efficiency (as per table_efficiency)
 * also calculate the middle efficiency:
 *   (max{eff_i} - min{eff_i}) / 2
 * This is later used to scale the cpu_power field such that an
 * 'average' cpu is of middle power. Also see the comments near
 * table_efficiency[] and update_cpu_power().
 */

> +static void __init parse_dt_topology(void)
> +{
> +       struct cpu_efficiency *cpu_eff;
> +       struct device_node *cn = NULL;
> +       unsigned long min_capacity = (unsigned long)(-1);
> +       unsigned long max_capacity = 0;
> +       unsigned long capacity = 0;
> +       int alloc_size, cpu = 0;
> +
> +       alloc_size = nr_cpu_ids * sizeof(struct cpu_capacity);
> +       cpu_capacity = (struct cpu_capacity *)kzalloc(alloc_size, GFP_NOWAIT);
> +
> +       while ((cn = of_find_node_by_type(cn, "cpu"))) {
> +               const u32 *rate, *reg;
> +               int len;
> +
> +               if (cpu >= num_possible_cpus())
> +                       break;
> +
> +               for (cpu_eff = table_efficiency; cpu_eff->compatible; cpu_eff++)
> +                       if (of_device_is_compatible(cn, cpu_eff->compatible))
> +                               break;
> +
> +               if (cpu_eff->compatible == NULL)
> +                       continue;
> +
> +               rate = of_get_property(cn, "clock-frequency", &len);
> +               if (!rate || len != 4) {
> +                       pr_err("%s missing clock-frequency property\n",
> +                               cn->full_name);
> +                       continue;
> +               }
> +
> +               reg = of_get_property(cn, "reg", &len);
> +               if (!reg || len != 4) {
> +                       pr_err("%s missing reg property\n", cn->full_name);
> +                       continue;
> +               }
> +
> +               capacity = ((be32_to_cpup(rate)) >> 20) * cpu_eff->efficiency;
> +
> +               /* Save min capacity of the system */
> +               if (capacity < min_capacity)
> +                       min_capacity = capacity;
> +
> +               /* Save max capacity of the system */
> +               if (capacity > max_capacity)
> +                       max_capacity = capacity;
> +
> +               cpu_capacity[cpu].capacity = capacity;
> +               cpu_capacity[cpu++].hwid = be32_to_cpup(reg);
> +       }
> +
> +       if (cpu < num_possible_cpus())
> +               cpu_capacity[cpu].hwid = (unsigned long)(-1);
> +
> +       middle_capacity = (min_capacity + max_capacity) >> 11;
> +}
> +
> +void update_cpu_power(unsigned int cpu, unsigned long hwid)
> +{
> +       unsigned int idx = 0;
> +
> +       /* look for the cpu's hwid in the cpu capacity table */

This smells like an O(n^2) loop.. ARM has only small cpu counts so this
isn't an immediate issue, would still be nice to make a note of it
though.

> +       for (idx = 0; idx < num_possible_cpus(); idx++) {
> +               if (cpu_capacity[idx].hwid == hwid)
> +                       break;
> +
> +               if (cpu_capacity[idx].hwid == -1)
> +                       return;
> +       }
> +
> +       if (idx == num_possible_cpus())
> +               return;
> +
> +       set_power_scale(cpu, cpu_capacity[idx].capacity / middle_capacity);

OK, but there's no guarantee here you'll stay within that
[1,2*SCHED_POWER_SCALE-1] range. This might want a comment and or
runtime verification so that when people extend the table_efficiency[]
wrongly we'll get notice, humm?

> +       printk(KERN_INFO "CPU%u: update cpu_power %lu\n",
> +               cpu, arch_scale_freq_power(NULL, cpu));
> +} 

  reply	other threads:[~2012-07-02  9:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-20 15:19 [PATCH v3 0/5] ARM: topology: set the capacity of each cores for big.LITTLE Vincent Guittot
     [not found] ` <1340205562-7653-1-git-send-email-vincent.guittot-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-06-20 15:19   ` [PATCH v3 1/5] ARM: topology: Add arch_scale_freq_power function Vincent Guittot
2012-06-20 15:19   ` [PATCH v3 3/5] ARM: topology: Update cpu_power according to DT information Vincent Guittot
2012-07-02  9:11     ` Peter Zijlstra [this message]
2012-07-02 12:11       ` Vincent Guittot
     [not found]         ` <CAKfTPtAHvKcdgiL4xx-zBJU5DZ5YwGUbjgtoh9a1tf_C2Amg5w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-07-02 12:30           ` Peter Zijlstra
2012-06-20 15:19   ` [PATCH v3 4/5] sched, x86: Remove broken power estimation Vincent Guittot
2012-06-20 15:19   ` [PATCH v3 5/5] sched: cpu_power: enable ARCH_POWER Vincent Guittot
2012-06-20 15:19 ` [PATCH v3 2/5] ARM: topology: factorize the update of sibling masks Vincent Guittot
2012-06-21  0:01   ` Namhyung Kim

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=1341220283.28750.138.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=jean.pihet@newoldbits.com \
    --cc=linaro-dev@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=namhyung@kernel.org \
    --cc=rob.herring@calxeda.com \
    --cc=vincent.guittot@linaro.org \
    --cc=yong.zhang0@gmail.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 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).