Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/kernel/topology.c |
| 3 | * |
| 4 | * Copyright (C) 2011 Linaro Limited. |
| 5 | * Written by: Vincent Guittot |
| 6 | * |
| 7 | * based on arch/sh/kernel/topology.c |
| 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General Public |
| 10 | * License. See the file "COPYING" in the main directory of this archive |
| 11 | * for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/cpu.h> |
| 15 | #include <linux/cpumask.h> |
Arnd Bergmann | 92bdd3f | 2013-05-31 22:49:22 +0100 | [diff] [blame] | 16 | #include <linux/export.h> |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 17 | #include <linux/init.h> |
| 18 | #include <linux/percpu.h> |
| 19 | #include <linux/node.h> |
| 20 | #include <linux/nodemask.h> |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 21 | #include <linux/of.h> |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 22 | #include <linux/sched.h> |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 23 | #include <linux/slab.h> |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 24 | |
| 25 | #include <asm/cputype.h> |
| 26 | #include <asm/topology.h> |
| 27 | |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 28 | /* |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 29 | * cpu capacity scale management |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | /* |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 33 | * cpu capacity table |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 34 | * This per cpu data structure describes the relative capacity of each core. |
| 35 | * On a heteregenous system, cores don't have the same computation capacity |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 36 | * and we reflect that difference in the cpu_capacity field so the scheduler |
| 37 | * can take this difference into account during load balance. A per cpu |
| 38 | * structure is preferred because each CPU updates its own cpu_capacity field |
| 39 | * during the load balance except for idle cores. One idle core is selected |
| 40 | * to run the rebalance_domains for all idle cores and the cpu_capacity can be |
| 41 | * updated during this sequence. |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 42 | */ |
Juri Lelli | d78e13a | 2016-01-07 16:27:33 +0100 | [diff] [blame] | 43 | static DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE; |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 44 | |
Morten Rasmussen | 25cea24 | 2015-04-14 16:25:31 +0100 | [diff] [blame] | 45 | unsigned long scale_cpu_capacity(struct sched_domain *sd, int cpu) |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 46 | { |
| 47 | return per_cpu(cpu_scale, cpu); |
| 48 | } |
| 49 | |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 50 | static void set_capacity_scale(unsigned int cpu, unsigned long capacity) |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 51 | { |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 52 | per_cpu(cpu_scale, cpu) = capacity; |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 55 | #ifdef CONFIG_OF |
| 56 | struct cpu_efficiency { |
| 57 | const char *compatible; |
| 58 | unsigned long efficiency; |
| 59 | }; |
| 60 | |
| 61 | /* |
| 62 | * Table of relative efficiency of each processors |
| 63 | * The efficiency value must fit in 20bit and the final |
| 64 | * cpu_scale value must be in the range |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 65 | * 0 < cpu_scale < 3*SCHED_CAPACITY_SCALE/2 |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 66 | * in order to return at most 1 when DIV_ROUND_CLOSEST |
| 67 | * is used to compute the capacity of a CPU. |
| 68 | * Processors that are not defined in the table, |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 69 | * use the default SCHED_CAPACITY_SCALE value for cpu_scale. |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 70 | */ |
Mark Brown | 145bc29 | 2013-12-10 12:10:17 +0100 | [diff] [blame] | 71 | static const struct cpu_efficiency table_efficiency[] = { |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 72 | {"arm,cortex-a15", 3891}, |
| 73 | {"arm,cortex-a7", 2048}, |
| 74 | {NULL, }, |
| 75 | }; |
| 76 | |
Mark Brown | 145bc29 | 2013-12-10 12:10:17 +0100 | [diff] [blame] | 77 | static unsigned long *__cpu_capacity; |
Sudeep KarkadaNagesha | 816a8de | 2013-06-17 14:20:00 +0100 | [diff] [blame] | 78 | #define cpu_capacity(cpu) __cpu_capacity[cpu] |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 79 | |
Mark Brown | 145bc29 | 2013-12-10 12:10:17 +0100 | [diff] [blame] | 80 | static unsigned long middle_capacity = 1; |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * Iterate all CPUs' descriptor in DT and compute the efficiency |
| 84 | * (as per table_efficiency). Also calculate a middle efficiency |
| 85 | * as close as possible to (max{eff_i} - min{eff_i}) / 2 |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 86 | * This is later used to scale the cpu_capacity field such that an |
| 87 | * 'average' CPU is of middle capacity. Also see the comments near |
| 88 | * table_efficiency[] and update_cpu_capacity(). |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 89 | */ |
| 90 | static void __init parse_dt_topology(void) |
| 91 | { |
Mark Brown | 145bc29 | 2013-12-10 12:10:17 +0100 | [diff] [blame] | 92 | const struct cpu_efficiency *cpu_eff; |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 93 | struct device_node *cn = NULL; |
Mark Brown | 44ae903 | 2014-03-20 15:16:54 +0100 | [diff] [blame] | 94 | unsigned long min_capacity = ULONG_MAX; |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 95 | unsigned long max_capacity = 0; |
| 96 | unsigned long capacity = 0; |
Mark Brown | 44ae903 | 2014-03-20 15:16:54 +0100 | [diff] [blame] | 97 | int cpu = 0; |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 98 | |
Mark Brown | 44ae903 | 2014-03-20 15:16:54 +0100 | [diff] [blame] | 99 | __cpu_capacity = kcalloc(nr_cpu_ids, sizeof(*__cpu_capacity), |
| 100 | GFP_NOWAIT); |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 101 | |
Sudeep KarkadaNagesha | 816a8de | 2013-06-17 14:20:00 +0100 | [diff] [blame] | 102 | for_each_possible_cpu(cpu) { |
| 103 | const u32 *rate; |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 104 | int len; |
| 105 | |
Sudeep KarkadaNagesha | 816a8de | 2013-06-17 14:20:00 +0100 | [diff] [blame] | 106 | /* too early to use cpu->of_node */ |
| 107 | cn = of_get_cpu_node(cpu, NULL); |
| 108 | if (!cn) { |
| 109 | pr_err("missing device node for CPU %d\n", cpu); |
| 110 | continue; |
| 111 | } |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 112 | |
| 113 | for (cpu_eff = table_efficiency; cpu_eff->compatible; cpu_eff++) |
| 114 | if (of_device_is_compatible(cn, cpu_eff->compatible)) |
| 115 | break; |
| 116 | |
| 117 | if (cpu_eff->compatible == NULL) |
| 118 | continue; |
| 119 | |
| 120 | rate = of_get_property(cn, "clock-frequency", &len); |
| 121 | if (!rate || len != 4) { |
| 122 | pr_err("%s missing clock-frequency property\n", |
| 123 | cn->full_name); |
| 124 | continue; |
| 125 | } |
| 126 | |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 127 | capacity = ((be32_to_cpup(rate)) >> 20) * cpu_eff->efficiency; |
| 128 | |
| 129 | /* Save min capacity of the system */ |
| 130 | if (capacity < min_capacity) |
| 131 | min_capacity = capacity; |
| 132 | |
| 133 | /* Save max capacity of the system */ |
| 134 | if (capacity > max_capacity) |
| 135 | max_capacity = capacity; |
| 136 | |
Sudeep KarkadaNagesha | 816a8de | 2013-06-17 14:20:00 +0100 | [diff] [blame] | 137 | cpu_capacity(cpu) = capacity; |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 140 | /* If min and max capacities are equals, we bypass the update of the |
| 141 | * cpu_scale because all CPUs have the same capacity. Otherwise, we |
| 142 | * compute a middle_capacity factor that will ensure that the capacity |
| 143 | * of an 'average' CPU of the system will be as close as possible to |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 144 | * SCHED_CAPACITY_SCALE, which is the default value, but with the |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 145 | * constraint explained near table_efficiency[]. |
| 146 | */ |
Sudeep KarkadaNagesha | 816a8de | 2013-06-17 14:20:00 +0100 | [diff] [blame] | 147 | if (4*max_capacity < (3*(max_capacity + min_capacity))) |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 148 | middle_capacity = (min_capacity + max_capacity) |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 149 | >> (SCHED_CAPACITY_SHIFT+1); |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 150 | else |
| 151 | middle_capacity = ((max_capacity / 3) |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 152 | >> (SCHED_CAPACITY_SHIFT-1)) + 1; |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 153 | |
| 154 | } |
| 155 | |
Dietmar Eggemann | b4ca4bc | 2015-07-10 13:57:19 +0100 | [diff] [blame] | 156 | static const struct sched_group_energy * const cpu_core_energy(int cpu); |
| 157 | |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 158 | /* |
| 159 | * Look for a customed capacity of a CPU in the cpu_capacity table during the |
| 160 | * boot. The update of all CPUs is in O(n^2) for heteregeneous system but the |
| 161 | * function returns directly for SMP system. |
| 162 | */ |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 163 | static void update_cpu_capacity(unsigned int cpu) |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 164 | { |
Dietmar Eggemann | b4ca4bc | 2015-07-10 13:57:19 +0100 | [diff] [blame] | 165 | unsigned long capacity = SCHED_CAPACITY_SCALE; |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 166 | |
Dietmar Eggemann | b4ca4bc | 2015-07-10 13:57:19 +0100 | [diff] [blame] | 167 | if (cpu_core_energy(cpu)) { |
| 168 | int max_cap_idx = cpu_core_energy(cpu)->nr_cap_states - 1; |
| 169 | capacity = cpu_core_energy(cpu)->cap_states[max_cap_idx].cap; |
| 170 | } |
| 171 | |
| 172 | set_capacity_scale(cpu, capacity); |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 173 | |
Russell King | 4ed89f2 | 2014-10-28 11:26:42 +0000 | [diff] [blame] | 174 | pr_info("CPU%u: update cpu_capacity %lu\n", |
Vincent Guittot | d3bfca1 | 2014-08-26 13:06:48 +0200 | [diff] [blame] | 175 | cpu, arch_scale_cpu_capacity(NULL, cpu)); |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | #else |
| 179 | static inline void parse_dt_topology(void) {} |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 180 | static inline void update_cpu_capacity(unsigned int cpuid) {} |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 181 | #endif |
| 182 | |
Lorenzo Pieralisi | dca463da | 2012-11-15 17:30:32 +0000 | [diff] [blame] | 183 | /* |
Vincent Guittot | 130d9aa | 2012-07-10 14:08:40 +0100 | [diff] [blame] | 184 | * cpu topology table |
| 185 | */ |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 186 | struct cputopo_arm cpu_topology[NR_CPUS]; |
Arnd Bergmann | 92bdd3f | 2013-05-31 22:49:22 +0100 | [diff] [blame] | 187 | EXPORT_SYMBOL_GPL(cpu_topology); |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 188 | |
Vincent Guittot | 4cbd6b1 | 2011-11-29 15:50:20 +0100 | [diff] [blame] | 189 | const struct cpumask *cpu_coregroup_mask(int cpu) |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 190 | { |
| 191 | return &cpu_topology[cpu].core_sibling; |
| 192 | } |
| 193 | |
Vincent Guittot | fb2aa85 | 2014-04-11 11:44:41 +0200 | [diff] [blame] | 194 | /* |
| 195 | * The current assumption is that we can power gate each core independently. |
| 196 | * This will be superseded by DT binding once available. |
| 197 | */ |
| 198 | const struct cpumask *cpu_corepower_mask(int cpu) |
| 199 | { |
| 200 | return &cpu_topology[cpu].thread_sibling; |
| 201 | } |
| 202 | |
Mark Brown | 145bc29 | 2013-12-10 12:10:17 +0100 | [diff] [blame] | 203 | static void update_siblings_masks(unsigned int cpuid) |
Vincent Guittot | cb75dac | 2012-07-10 14:11:11 +0100 | [diff] [blame] | 204 | { |
| 205 | struct cputopo_arm *cpu_topo, *cpuid_topo = &cpu_topology[cpuid]; |
| 206 | int cpu; |
| 207 | |
| 208 | /* update core and thread sibling masks */ |
| 209 | for_each_possible_cpu(cpu) { |
| 210 | cpu_topo = &cpu_topology[cpu]; |
| 211 | |
| 212 | if (cpuid_topo->socket_id != cpu_topo->socket_id) |
| 213 | continue; |
| 214 | |
| 215 | cpumask_set_cpu(cpuid, &cpu_topo->core_sibling); |
| 216 | if (cpu != cpuid) |
| 217 | cpumask_set_cpu(cpu, &cpuid_topo->core_sibling); |
| 218 | |
| 219 | if (cpuid_topo->core_id != cpu_topo->core_id) |
| 220 | continue; |
| 221 | |
| 222 | cpumask_set_cpu(cpuid, &cpu_topo->thread_sibling); |
| 223 | if (cpu != cpuid) |
| 224 | cpumask_set_cpu(cpu, &cpuid_topo->thread_sibling); |
| 225 | } |
| 226 | smp_wmb(); |
| 227 | } |
| 228 | |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 229 | /* |
| 230 | * store_cpu_topology is called at boot when only one cpu is running |
| 231 | * and with the mutex cpu_hotplug.lock locked, when several cpus have booted, |
| 232 | * which prevents simultaneous write access to cpu_topology array |
| 233 | */ |
| 234 | void store_cpu_topology(unsigned int cpuid) |
| 235 | { |
| 236 | struct cputopo_arm *cpuid_topo = &cpu_topology[cpuid]; |
| 237 | unsigned int mpidr; |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 238 | |
| 239 | /* If the cpu topology has been already set, just return */ |
| 240 | if (cpuid_topo->core_id != -1) |
| 241 | return; |
| 242 | |
| 243 | mpidr = read_cpuid_mpidr(); |
| 244 | |
| 245 | /* create cpu topology mapping */ |
| 246 | if ((mpidr & MPIDR_SMP_BITMASK) == MPIDR_SMP_VALUE) { |
| 247 | /* |
| 248 | * This is a multiprocessor system |
| 249 | * multiprocessor format & multiprocessor mode field are set |
| 250 | */ |
| 251 | |
| 252 | if (mpidr & MPIDR_MT_BITMASK) { |
| 253 | /* core performance interdependency */ |
Lorenzo Pieralisi | 71db5bf | 2012-11-16 15:24:06 +0000 | [diff] [blame] | 254 | cpuid_topo->thread_id = MPIDR_AFFINITY_LEVEL(mpidr, 0); |
| 255 | cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
| 256 | cpuid_topo->socket_id = MPIDR_AFFINITY_LEVEL(mpidr, 2); |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 257 | } else { |
| 258 | /* largely independent cores */ |
| 259 | cpuid_topo->thread_id = -1; |
Lorenzo Pieralisi | 71db5bf | 2012-11-16 15:24:06 +0000 | [diff] [blame] | 260 | cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0); |
| 261 | cpuid_topo->socket_id = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 262 | } |
| 263 | } else { |
| 264 | /* |
| 265 | * This is an uniprocessor system |
| 266 | * we are in multiprocessor format but uniprocessor system |
| 267 | * or in the old uniprocessor format |
| 268 | */ |
| 269 | cpuid_topo->thread_id = -1; |
| 270 | cpuid_topo->core_id = 0; |
| 271 | cpuid_topo->socket_id = -1; |
| 272 | } |
| 273 | |
Vincent Guittot | cb75dac | 2012-07-10 14:11:11 +0100 | [diff] [blame] | 274 | update_siblings_masks(cpuid); |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 275 | |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 276 | update_cpu_capacity(cpuid); |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 277 | |
Russell King | 4ed89f2 | 2014-10-28 11:26:42 +0000 | [diff] [blame] | 278 | pr_info("CPU%u: thread %d, cpu %d, socket %d, mpidr %x\n", |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 279 | cpuid, cpu_topology[cpuid].thread_id, |
| 280 | cpu_topology[cpuid].core_id, |
| 281 | cpu_topology[cpuid].socket_id, mpidr); |
| 282 | } |
| 283 | |
Dietmar Eggemann | 61100bd | 2014-11-14 17:16:41 +0000 | [diff] [blame] | 284 | /* |
| 285 | * ARM TC2 specific energy cost model data. There are no unit requirements for |
| 286 | * the data. Data can be normalized to any reference point, but the |
| 287 | * normalization must be consistent. That is, one bogo-joule/watt must be the |
| 288 | * same quantity for all data, but we don't care what it is. |
| 289 | */ |
| 290 | static struct idle_state idle_states_cluster_a7[] = { |
| 291 | { .power = 25 }, /* arch_cpu_idle() (active idle) = WFI */ |
| 292 | { .power = 25 }, /* WFI */ |
| 293 | { .power = 10 }, /* cluster-sleep-l */ |
| 294 | }; |
| 295 | |
| 296 | static struct idle_state idle_states_cluster_a15[] = { |
| 297 | { .power = 70 }, /* arch_cpu_idle() (active idle) = WFI */ |
| 298 | { .power = 70 }, /* WFI */ |
| 299 | { .power = 25 }, /* cluster-sleep-b */ |
| 300 | }; |
| 301 | |
| 302 | static struct capacity_state cap_states_cluster_a7[] = { |
| 303 | /* Cluster only power */ |
| 304 | { .cap = 150, .power = 2967, }, /* 350 MHz */ |
| 305 | { .cap = 172, .power = 2792, }, /* 400 MHz */ |
| 306 | { .cap = 215, .power = 2810, }, /* 500 MHz */ |
| 307 | { .cap = 258, .power = 2815, }, /* 600 MHz */ |
| 308 | { .cap = 301, .power = 2919, }, /* 700 MHz */ |
| 309 | { .cap = 344, .power = 2847, }, /* 800 MHz */ |
| 310 | { .cap = 387, .power = 3917, }, /* 900 MHz */ |
| 311 | { .cap = 430, .power = 4905, }, /* 1000 MHz */ |
| 312 | }; |
| 313 | |
| 314 | static struct capacity_state cap_states_cluster_a15[] = { |
| 315 | /* Cluster only power */ |
| 316 | { .cap = 426, .power = 7920, }, /* 500 MHz */ |
| 317 | { .cap = 512, .power = 8165, }, /* 600 MHz */ |
| 318 | { .cap = 597, .power = 8172, }, /* 700 MHz */ |
| 319 | { .cap = 682, .power = 8195, }, /* 800 MHz */ |
| 320 | { .cap = 768, .power = 8265, }, /* 900 MHz */ |
| 321 | { .cap = 853, .power = 8446, }, /* 1000 MHz */ |
| 322 | { .cap = 938, .power = 11426, }, /* 1100 MHz */ |
| 323 | { .cap = 1024, .power = 15200, }, /* 1200 MHz */ |
| 324 | }; |
| 325 | |
| 326 | static struct sched_group_energy energy_cluster_a7 = { |
| 327 | .nr_idle_states = ARRAY_SIZE(idle_states_cluster_a7), |
| 328 | .idle_states = idle_states_cluster_a7, |
| 329 | .nr_cap_states = ARRAY_SIZE(cap_states_cluster_a7), |
| 330 | .cap_states = cap_states_cluster_a7, |
| 331 | }; |
| 332 | |
| 333 | static struct sched_group_energy energy_cluster_a15 = { |
| 334 | .nr_idle_states = ARRAY_SIZE(idle_states_cluster_a15), |
| 335 | .idle_states = idle_states_cluster_a15, |
| 336 | .nr_cap_states = ARRAY_SIZE(cap_states_cluster_a15), |
| 337 | .cap_states = cap_states_cluster_a15, |
| 338 | }; |
| 339 | |
| 340 | static struct idle_state idle_states_core_a7[] = { |
| 341 | { .power = 0 }, /* arch_cpu_idle (active idle) = WFI */ |
| 342 | { .power = 0 }, /* WFI */ |
| 343 | { .power = 0 }, /* cluster-sleep-l */ |
| 344 | }; |
| 345 | |
| 346 | static struct idle_state idle_states_core_a15[] = { |
| 347 | { .power = 0 }, /* arch_cpu_idle (active idle) = WFI */ |
| 348 | { .power = 0 }, /* WFI */ |
| 349 | { .power = 0 }, /* cluster-sleep-b */ |
| 350 | }; |
| 351 | |
| 352 | static struct capacity_state cap_states_core_a7[] = { |
| 353 | /* Power per cpu */ |
| 354 | { .cap = 150, .power = 187, }, /* 350 MHz */ |
| 355 | { .cap = 172, .power = 275, }, /* 400 MHz */ |
| 356 | { .cap = 215, .power = 334, }, /* 500 MHz */ |
| 357 | { .cap = 258, .power = 407, }, /* 600 MHz */ |
| 358 | { .cap = 301, .power = 447, }, /* 700 MHz */ |
| 359 | { .cap = 344, .power = 549, }, /* 800 MHz */ |
| 360 | { .cap = 387, .power = 761, }, /* 900 MHz */ |
| 361 | { .cap = 430, .power = 1024, }, /* 1000 MHz */ |
| 362 | }; |
| 363 | |
| 364 | static struct capacity_state cap_states_core_a15[] = { |
| 365 | /* Power per cpu */ |
| 366 | { .cap = 426, .power = 2021, }, /* 500 MHz */ |
| 367 | { .cap = 512, .power = 2312, }, /* 600 MHz */ |
| 368 | { .cap = 597, .power = 2756, }, /* 700 MHz */ |
| 369 | { .cap = 682, .power = 3125, }, /* 800 MHz */ |
| 370 | { .cap = 768, .power = 3524, }, /* 900 MHz */ |
| 371 | { .cap = 853, .power = 3846, }, /* 1000 MHz */ |
| 372 | { .cap = 938, .power = 5177, }, /* 1100 MHz */ |
| 373 | { .cap = 1024, .power = 6997, }, /* 1200 MHz */ |
| 374 | }; |
| 375 | |
| 376 | static struct sched_group_energy energy_core_a7 = { |
| 377 | .nr_idle_states = ARRAY_SIZE(idle_states_core_a7), |
| 378 | .idle_states = idle_states_core_a7, |
| 379 | .nr_cap_states = ARRAY_SIZE(cap_states_core_a7), |
| 380 | .cap_states = cap_states_core_a7, |
| 381 | }; |
| 382 | |
| 383 | static struct sched_group_energy energy_core_a15 = { |
| 384 | .nr_idle_states = ARRAY_SIZE(idle_states_core_a15), |
| 385 | .idle_states = idle_states_core_a15, |
| 386 | .nr_cap_states = ARRAY_SIZE(cap_states_core_a15), |
| 387 | .cap_states = cap_states_core_a15, |
| 388 | }; |
| 389 | |
| 390 | /* sd energy functions */ |
| 391 | static inline |
| 392 | const struct sched_group_energy * const cpu_cluster_energy(int cpu) |
| 393 | { |
| 394 | return cpu_topology[cpu].socket_id ? &energy_cluster_a7 : |
| 395 | &energy_cluster_a15; |
| 396 | } |
| 397 | |
| 398 | static inline |
| 399 | const struct sched_group_energy * const cpu_core_energy(int cpu) |
| 400 | { |
| 401 | return cpu_topology[cpu].socket_id ? &energy_core_a7 : |
| 402 | &energy_core_a15; |
| 403 | } |
| 404 | |
Guenter Roeck | b6220ad | 2014-06-24 18:05:29 -0700 | [diff] [blame] | 405 | static inline int cpu_corepower_flags(void) |
Vincent Guittot | fb2aa85 | 2014-04-11 11:44:41 +0200 | [diff] [blame] | 406 | { |
Morten Rasmussen | 858d718 | 2015-01-13 13:50:46 +0000 | [diff] [blame] | 407 | return SD_SHARE_PKG_RESOURCES | SD_SHARE_POWERDOMAIN | \ |
| 408 | SD_SHARE_CAP_STATES; |
Vincent Guittot | fb2aa85 | 2014-04-11 11:44:41 +0200 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static struct sched_domain_topology_level arm_topology[] = { |
| 412 | #ifdef CONFIG_SCHED_MC |
Dietmar Eggemann | 61100bd | 2014-11-14 17:16:41 +0000 | [diff] [blame] | 413 | { cpu_coregroup_mask, cpu_corepower_flags, cpu_core_energy, SD_INIT_NAME(MC) }, |
Vincent Guittot | fb2aa85 | 2014-04-11 11:44:41 +0200 | [diff] [blame] | 414 | #endif |
Dietmar Eggemann | 61100bd | 2014-11-14 17:16:41 +0000 | [diff] [blame] | 415 | { cpu_cpu_mask, NULL, cpu_cluster_energy, SD_INIT_NAME(DIE) }, |
Vincent Guittot | fb2aa85 | 2014-04-11 11:44:41 +0200 | [diff] [blame] | 416 | { NULL, }, |
| 417 | }; |
| 418 | |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 419 | /* |
| 420 | * init_cpu_topology is called at boot when only one cpu is running |
| 421 | * which prevent simultaneous write access to cpu_topology array |
| 422 | */ |
Venkatraman Sathiyamoorthy | f7e416e | 2012-08-03 07:58:33 +0100 | [diff] [blame] | 423 | void __init init_cpu_topology(void) |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 424 | { |
| 425 | unsigned int cpu; |
| 426 | |
Nicolas Pitre | ca8ce3d | 2014-05-26 18:19:39 -0400 | [diff] [blame] | 427 | /* init core mask and capacity */ |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 428 | for_each_possible_cpu(cpu) { |
| 429 | struct cputopo_arm *cpu_topo = &(cpu_topology[cpu]); |
| 430 | |
| 431 | cpu_topo->thread_id = -1; |
| 432 | cpu_topo->core_id = -1; |
| 433 | cpu_topo->socket_id = -1; |
| 434 | cpumask_clear(&cpu_topo->core_sibling); |
| 435 | cpumask_clear(&cpu_topo->thread_sibling); |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 436 | } |
| 437 | smp_wmb(); |
Vincent Guittot | 339ca09 | 2012-07-10 14:13:12 +0100 | [diff] [blame] | 438 | |
| 439 | parse_dt_topology(); |
Vincent Guittot | fb2aa85 | 2014-04-11 11:44:41 +0200 | [diff] [blame] | 440 | |
| 441 | /* Set scheduler topology descriptor */ |
| 442 | set_sched_topology(arm_topology); |
Vincent Guittot | c9018aa | 2011-08-08 13:21:59 +0100 | [diff] [blame] | 443 | } |