blob: 20340631179f669fd7d9216d85f210c2a4cf381e [file] [log] [blame]
Tony Luck8d7e3512005-07-06 18:18:10 -07001/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * ia64 kernel NUMA specific stuff
17 *
18 * Copyright (C) 2002 Erich Focht <efocht@ess.nec.de>
19 * Copyright (C) 2004 Silicon Graphics, Inc.
20 * Jesse Barnes <jbarnes@sgi.com>
21 */
Tony Luck8d7e3512005-07-06 18:18:10 -070022#include <linux/topology.h>
23#include <linux/module.h>
24#include <asm/processor.h>
25#include <asm/smp.h>
26
Jack Steinera9de9832006-03-02 16:02:28 -060027u16 cpu_to_node_map[NR_CPUS] __cacheline_aligned;
Tony Luck8d7e3512005-07-06 18:18:10 -070028EXPORT_SYMBOL(cpu_to_node_map);
29
30cpumask_t node_to_cpu_mask[MAX_NUMNODES] __cacheline_aligned;
31
KAMEZAWA Hiroyuki3212fe12006-09-25 16:25:31 -070032void __cpuinit map_cpu_to_node(int cpu, int nid)
33{
34 int oldnid;
35 if (nid < 0) { /* just initialize by zero */
36 cpu_to_node_map[cpu] = 0;
37 return;
38 }
39 /* sanity check first */
40 oldnid = cpu_to_node_map[cpu];
41 if (cpu_isset(cpu, node_to_cpu_mask[oldnid])) {
42 return; /* nothing to do */
43 }
44 /* we don't have cpu-driven node hot add yet...
45 In usual case, node is created from SRAT at boot time. */
46 if (!node_online(nid))
47 nid = first_online_node;
48 cpu_to_node_map[cpu] = nid;
49 cpu_set(cpu, node_to_cpu_mask[nid]);
50 return;
51}
52
53void __cpuinit unmap_cpu_from_node(int cpu, int nid)
54{
55 WARN_ON(!cpu_isset(cpu, node_to_cpu_mask[nid]));
56 WARN_ON(cpu_to_node_map[cpu] != nid);
57 cpu_to_node_map[cpu] = 0;
58 cpu_clear(cpu, node_to_cpu_mask[nid]);
59}
60
61
Tony Luck8d7e3512005-07-06 18:18:10 -070062/**
63 * build_cpu_to_node_map - setup cpu to node and node to cpumask arrays
64 *
65 * Build cpu to node mapping and initialize the per node cpu masks using
66 * info from the node_cpuid array handed to us by ACPI.
67 */
68void __init build_cpu_to_node_map(void)
69{
70 int cpu, i, node;
71
72 for(node=0; node < MAX_NUMNODES; node++)
73 cpus_clear(node_to_cpu_mask[node]);
74
75 for(cpu = 0; cpu < NR_CPUS; ++cpu) {
76 node = -1;
77 for (i = 0; i < NR_CPUS; ++i)
78 if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {
79 node = node_cpuid[i].nid;
80 break;
81 }
KAMEZAWA Hiroyuki3212fe12006-09-25 16:25:31 -070082 map_cpu_to_node(cpu, node);
Tony Luck8d7e3512005-07-06 18:18:10 -070083 }
84}