From: Vincent Guittot <vincent.guittot@linaro.org> Date: 2012-06-20 15:20:03
This patchset creates an arch_scale_freq_power function for ARM, which is used
to set the relative capacity of each core of a big.LITTLE system. It also removes
the broken power estimation of x86.
Modification since v2:
- set_power_scale function becomes static
- Rework loop in update_siblings_masks
- Remove useless code in parse_dt_topology
Modification since v1:
- Add and update explanation about the use of the table and the range of the value
- Remove the use of NR_CPUS and use nr_cpu_ids instead
- Remove broken power estimation of x86
Peter Zijlstra (1):
sched, x86: Remove broken power estimation
Vincent Guittot (4):
ARM: topology: Add arch_scale_freq_power function
ARM: topology: factorize the update of sibling masks
ARM: topology: Update cpu_power according to DT information
sched: cpu_power: enable ARCH_POWER
arch/arm/kernel/topology.c | 209 +++++++++++++++++++++++++++++++++++++-----
arch/x86/kernel/cpu/Makefile | 2 +-
arch/x86/kernel/cpu/sched.c | 55 -----------
kernel/sched/features.h | 2 +-
4 files changed, 189 insertions(+), 79 deletions(-)
delete mode 100644 arch/x86/kernel/cpu/sched.c
--
1.7.9.5
From: Vincent Guittot <vincent.guittot@linaro.org> Date: 2012-06-20 15:20:18
Add infrastructure to be able to modify the cpu_power of each core
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
---
arch/arm/kernel/topology.c | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
From: Vincent Guittot <vincent.guittot@linaro.org> Date: 2012-06-20 15:20:23
This factorization has also been proposed in another patchset that has not been
merged yet:
http://lists.infradead.org/pipermail/linux-arm-kernel/2012-January/080873.html
So, this patch could be dropped depending of the state of the other one.
Signed-off-by: Lorenzo Pieralisi <redacted>
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
---
arch/arm/kernel/topology.c | 48 +++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 21 deletions(-)
@@ -91,7 +117,6 @@ void store_cpu_topology(unsigned int cpuid){structcputopo_arm*cpuid_topo=&cpu_topology[cpuid];unsignedintmpidr;-unsignedintcpu;/* If the cpu topology has been already set, just return */if(cpuid_topo->core_id!=-1)
@@ -133,26 +158,7 @@ void store_cpu_topology(unsigned int cpuid)cpuid_topo->socket_id=-1;}-/* update core and thread sibling masks */-for_each_possible_cpu(cpu){-structcputopo_arm*cpu_topo=&cpu_topology[cpu];--if(cpuid_topo->socket_id==cpu_topo->socket_id){-cpumask_set_cpu(cpuid,&cpu_topo->core_sibling);-if(cpu!=cpuid)-cpumask_set_cpu(cpu,-&cpuid_topo->core_sibling);--if(cpuid_topo->core_id==cpu_topo->core_id){-cpumask_set_cpu(cpuid,-&cpu_topo->thread_sibling);-if(cpu!=cpuid)-cpumask_set_cpu(cpu,-&cpuid_topo->thread_sibling);-}-}-}-smp_wmb();+update_siblings_masks(cpuid);printk(KERN_INFO"CPU%u: thread %d, cpu %d, socket %d, mpidr %x\n",cpuid,cpu_topology[cpuid].thread_id,
From: Vincent Guittot <vincent.guittot@linaro.org> Date: 2012-06-20 15:20:32
Use cpu compatibility field and clock-frequency field of DT to
estimate the capacity of each core of the system and to update
the cpu_power field accordingly.
This patch enables to put more running tasks on big cores than
on LITTLE ones. But this patch doesn't ensure that long running
tasks will run on big cores and short ones on LITTLE cores.
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
---
arch/arm/kernel/topology.c | 123 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 123 insertions(+)
@@ -49,6 +51,122 @@ static void set_power_scale(unsigned int cpu, unsigned long power)per_cpu(cpu_scale,cpu)=power;}+#ifdef CONFIG_OF+structcpu_efficiency{+constchar*compatible;+unsignedlongefficiency;+};++/*+*Tableofrelativeefficiencyofeachprocessors+*Theefficiencyvaluemustfitin20bit.Thefinal+*cpu_scalevaluemustbeintherange+*0<cpu_scale<2*SCHED_POWER_SCALE.+*Processorsthatarenotdefinedinthetable,+*usethedefaultSCHED_POWER_SCALEvalueforcpu_scale.+*/+structcpu_efficiencytable_efficiency[]={+{"arm,cortex-a15",3891},+{"arm,cortex-a7",2048},+{NULL,},+};++structcpu_capacity{+unsignedlonghwid;+unsignedlongcapacity;+};++structcpu_capacity*cpu_capacity;++unsignedlongmiddle_capacity=1;++staticvoid__initparse_dt_topology(void)+{+structcpu_efficiency*cpu_eff;+structdevice_node*cn=NULL;+unsignedlongmin_capacity=(unsignedlong)(-1);+unsignedlongmax_capacity=0;+unsignedlongcapacity=0;+intalloc_size,cpu=0;++alloc_size=nr_cpu_ids*sizeof(structcpu_capacity);+cpu_capacity=(structcpu_capacity*)kzalloc(alloc_size,GFP_NOWAIT);++while((cn=of_find_node_by_type(cn,"cpu"))){+constu32*rate,*reg;+intlen;++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=(unsignedlong)(-1);++middle_capacity=(min_capacity+max_capacity)>>11;+}++voidupdate_cpu_power(unsignedintcpu,unsignedlonghwid)+{+unsignedintidx=0;++/* look for the cpu's hwid in the cpu capacity table */+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);++printk(KERN_INFO"CPU%u: update cpu_power %lu\n",+cpu,arch_scale_freq_power(NULL,cpu));+}++#else+staticinlinevoidparse_dt_topology(void){}+staticinlinevoidupdate_cpu_power(unsignedintcpuid,unsignedintmpidr){}+#endif++/**cputopologymanagement*/
@@ -62,6 +180,7 @@ static void set_power_scale(unsigned int cpu, unsigned long power)*Thesemasksreflectthecurrentuseoftheaffinitylevels.*Theaffinitylevelcanbeupto16bitsaccordingtoARMARM*/+#define MPIDR_HWID_BITMASK 0xFFFFFF#define MPIDR_LEVEL0_MASK 0x3#define MPIDR_LEVEL0_SHIFT 0
@@ -160,6 +279,8 @@ void store_cpu_topology(unsigned int cpuid)update_siblings_masks(cpuid);+update_cpu_power(cpuid,mpidr&MPIDR_HWID_BITMASK);+printk(KERN_INFO"CPU%u: thread %d, cpu %d, socket %d, mpidr %x\n",cpuid,cpu_topology[cpuid].thread_id,cpu_topology[cpuid].core_id,
From: Peter Zijlstra <hidden> Date: 2012-07-02 09:11:59
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.
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?
From: Vincent Guittot <vincent.guittot@linaro.org> Date: 2012-07-02 12:11:08
On 2 July 2012 11:11, Peter Zijlstra [off-list ref] wrote:
On Wed, 2012-06-20 at 17:19 +0200, Vincent Guittot wrote:
quoted
+#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.
Yes, that's it. Now, Regarding the div_round_closest that is used in
the scheduler to compute the capacity, It should rather stay in the
range
0 < cpu_scale < 3*SCHED_POWER_SCALE/2.
quoted
+ * 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().
*/
ok
quoted
+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.
Yes, This function is called for each cpu. I will add a comment about
that and also about the fact that the complete sequence is done only
once.
I will also add an optimization for system with identical CPUs and DT
information
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?
I will add more comments but we can't be higher than 2047. The max
value for a cpu_power will be :
max / ( (min + max) / 2^11 ) which is equal to
max / (min + max) * 2^11 so the cpu_scale is smaller than 2^11 as min
is never equal to 0
We can have a cpu_power of 0 is a CPU has 2048 times more capacity
than another one in the system but I'm not sure that it's a realistic
use case
From: Vincent Guittot <vincent.guittot@linaro.org> Date: 2012-06-20 15:20:41
From: Peter Zijlstra <redacted>
The x86 sched power implementation has been broken forever and gets in
the way of other stuff, remove it.
For archaeological interest, fixing this code would require dealing with
the cross-cpu calling of these functions and more importantly, we need
to filter idle time out of the a/m-perf stuff because the ratio will go
down to 0 when idle, giving a 0 capacity which is not what we'd want.
Signed-off-by: Peter Zijlstra <redacted>
Link: http://lkml.kernel.org/n/tip-wjjwelpti8f8k7i1pdnzmdr8 at git.kernel.org
---
arch/x86/kernel/cpu/Makefile | 2 +-
arch/x86/kernel/cpu/sched.c | 55 ------------------------------------------
2 files changed, 1 insertion(+), 56 deletions(-)
delete mode 100644 arch/x86/kernel/cpu/sched.c
@@ -1,55 +0,0 @@-#include <linux/sched.h>-#include <linux/math64.h>-#include <linux/percpu.h>-#include <linux/irqflags.h>--#include <asm/cpufeature.h>-#include <asm/processor.h>--#ifdef CONFIG_SMP--static DEFINE_PER_CPU(struct aperfmperf, old_perf_sched);--static unsigned long scale_aperfmperf(void)-{- struct aperfmperf val, *old = &__get_cpu_var(old_perf_sched);- unsigned long ratio, flags;-- local_irq_save(flags);- get_aperfmperf(&val);- local_irq_restore(flags);-- ratio = calc_aperfmperf_ratio(old, &val);- *old = val;-- return ratio;-}--unsigned long arch_scale_freq_power(struct sched_domain *sd, int cpu)-{- /*- * do aperf/mperf on the cpu level because it includes things- * like turbo mode, which are relevant to full cores.- */- if (boot_cpu_has(X86_FEATURE_APERFMPERF))- return scale_aperfmperf();-- /*- * maybe have something cpufreq here- */-- return default_scale_freq_power(sd, cpu);-}--unsigned long arch_scale_smt_power(struct sched_domain *sd, int cpu)-{- /*- * aperf/mperf already includes the smt gain- */- if (boot_cpu_has(X86_FEATURE_APERFMPERF))- return SCHED_LOAD_SCALE;-- return default_scale_smt_power(sd, cpu);-}--#endif
From: Vincent Guittot <vincent.guittot@linaro.org> Date: 2012-06-20 15:20:46
Heteregeneous ARM platform uses arch_scale_freq_power function
to reflect the relative capacity of each core
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
---
kernel/sched/features.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)