Linux 3.15-rc1
[linux/fpc-iii.git] / arch / arm64 / kernel / topology.c
blob3e06b0be4ec81ee1e80c81975e7f8f0c3763d318
1 /*
2 * arch/arm64/kernel/topology.c
4 * Copyright (C) 2011,2013,2014 Linaro Limited.
6 * Based on the arm32 version written by Vincent Guittot in turn based on
7 * arch/sh/kernel/topology.c
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.
14 #include <linux/cpu.h>
15 #include <linux/cpumask.h>
16 #include <linux/init.h>
17 #include <linux/percpu.h>
18 #include <linux/node.h>
19 #include <linux/nodemask.h>
20 #include <linux/sched.h>
22 #include <asm/topology.h>
25 * cpu topology table
27 struct cpu_topology cpu_topology[NR_CPUS];
28 EXPORT_SYMBOL_GPL(cpu_topology);
30 const struct cpumask *cpu_coregroup_mask(int cpu)
32 return &cpu_topology[cpu].core_sibling;
35 static void update_siblings_masks(unsigned int cpuid)
37 struct cpu_topology *cpu_topo, *cpuid_topo = &cpu_topology[cpuid];
38 int cpu;
40 if (cpuid_topo->cluster_id == -1) {
42 * DT does not contain topology information for this cpu
43 * reset it to default behaviour
45 pr_debug("CPU%u: No topology information configured\n", cpuid);
46 cpuid_topo->core_id = 0;
47 cpumask_set_cpu(cpuid, &cpuid_topo->core_sibling);
48 cpumask_set_cpu(cpuid, &cpuid_topo->thread_sibling);
49 return;
52 /* update core and thread sibling masks */
53 for_each_possible_cpu(cpu) {
54 cpu_topo = &cpu_topology[cpu];
56 if (cpuid_topo->cluster_id != cpu_topo->cluster_id)
57 continue;
59 cpumask_set_cpu(cpuid, &cpu_topo->core_sibling);
60 if (cpu != cpuid)
61 cpumask_set_cpu(cpu, &cpuid_topo->core_sibling);
63 if (cpuid_topo->core_id != cpu_topo->core_id)
64 continue;
66 cpumask_set_cpu(cpuid, &cpu_topo->thread_sibling);
67 if (cpu != cpuid)
68 cpumask_set_cpu(cpu, &cpuid_topo->thread_sibling);
72 void store_cpu_topology(unsigned int cpuid)
74 update_siblings_masks(cpuid);
78 * init_cpu_topology is called at boot when only one cpu is running
79 * which prevent simultaneous write access to cpu_topology array
81 void __init init_cpu_topology(void)
83 unsigned int cpu;
85 /* init core mask and power*/
86 for_each_possible_cpu(cpu) {
87 struct cpu_topology *cpu_topo = &cpu_topology[cpu];
89 cpu_topo->thread_id = -1;
90 cpu_topo->core_id = -1;
91 cpu_topo->cluster_id = -1;
92 cpumask_clear(&cpu_topo->core_sibling);
93 cpumask_clear(&cpu_topo->thread_sibling);