This source file includes following definitions.
- map_cpu_to_node
- unmap_cpu_from_node
- build_cpu_to_node_map
1
2
3
4
5
6
7
8
9
10 #include <linux/topology.h>
11 #include <linux/module.h>
12 #include <asm/processor.h>
13 #include <asm/smp.h>
14
15 u16 cpu_to_node_map[NR_CPUS] __cacheline_aligned;
16 EXPORT_SYMBOL(cpu_to_node_map);
17
18 cpumask_t node_to_cpu_mask[MAX_NUMNODES] __cacheline_aligned;
19 EXPORT_SYMBOL(node_to_cpu_mask);
20
21 void map_cpu_to_node(int cpu, int nid)
22 {
23 int oldnid;
24 if (nid < 0) {
25 cpu_to_node_map[cpu] = 0;
26 return;
27 }
28
29 oldnid = cpu_to_node_map[cpu];
30 if (cpumask_test_cpu(cpu, &node_to_cpu_mask[oldnid])) {
31 return;
32 }
33
34
35 if (!node_online(nid))
36 nid = first_online_node;
37 cpu_to_node_map[cpu] = nid;
38 cpumask_set_cpu(cpu, &node_to_cpu_mask[nid]);
39 return;
40 }
41
42 void unmap_cpu_from_node(int cpu, int nid)
43 {
44 WARN_ON(!cpumask_test_cpu(cpu, &node_to_cpu_mask[nid]));
45 WARN_ON(cpu_to_node_map[cpu] != nid);
46 cpu_to_node_map[cpu] = 0;
47 cpumask_clear_cpu(cpu, &node_to_cpu_mask[nid]);
48 }
49
50
51
52
53
54
55
56
57 void __init build_cpu_to_node_map(void)
58 {
59 int cpu, i, node;
60
61 for(node=0; node < MAX_NUMNODES; node++)
62 cpumask_clear(&node_to_cpu_mask[node]);
63
64 for_each_possible_early_cpu(cpu) {
65 node = NUMA_NO_NODE;
66 for (i = 0; i < NR_CPUS; ++i)
67 if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {
68 node = node_cpuid[i].nid;
69 break;
70 }
71 map_cpu_to_node(cpu, node);
72 }
73 }