numa.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  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. */
  22. #include <linux/topology.h>
  23. #include <linux/module.h>
  24. #include <asm/processor.h>
  25. #include <asm/smp.h>
  26. u16 cpu_to_node_map[NR_CPUS] __cacheline_aligned;
  27. EXPORT_SYMBOL(cpu_to_node_map);
  28. cpumask_t node_to_cpu_mask[MAX_NUMNODES] __cacheline_aligned;
  29. EXPORT_SYMBOL(node_to_cpu_mask);
  30. void map_cpu_to_node(int cpu, int nid)
  31. {
  32. int oldnid;
  33. if (nid < 0) { /* just initialize by zero */
  34. cpu_to_node_map[cpu] = 0;
  35. return;
  36. }
  37. /* sanity check first */
  38. oldnid = cpu_to_node_map[cpu];
  39. if (cpumask_test_cpu(cpu, &node_to_cpu_mask[oldnid])) {
  40. return; /* nothing to do */
  41. }
  42. /* we don't have cpu-driven node hot add yet...
  43. In usual case, node is created from SRAT at boot time. */
  44. if (!node_online(nid))
  45. nid = first_online_node;
  46. cpu_to_node_map[cpu] = nid;
  47. cpumask_set_cpu(cpu, &node_to_cpu_mask[nid]);
  48. return;
  49. }
  50. void unmap_cpu_from_node(int cpu, int nid)
  51. {
  52. WARN_ON(!cpumask_test_cpu(cpu, &node_to_cpu_mask[nid]));
  53. WARN_ON(cpu_to_node_map[cpu] != nid);
  54. cpu_to_node_map[cpu] = 0;
  55. cpumask_clear_cpu(cpu, &node_to_cpu_mask[nid]);
  56. }
  57. /**
  58. * build_cpu_to_node_map - setup cpu to node and node to cpumask arrays
  59. *
  60. * Build cpu to node mapping and initialize the per node cpu masks using
  61. * info from the node_cpuid array handed to us by ACPI.
  62. */
  63. void __init build_cpu_to_node_map(void)
  64. {
  65. int cpu, i, node;
  66. for(node=0; node < MAX_NUMNODES; node++)
  67. cpumask_clear(&node_to_cpu_mask[node]);
  68. for_each_possible_early_cpu(cpu) {
  69. node = -1;
  70. for (i = 0; i < NR_CPUS; ++i)
  71. if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {
  72. node = node_cpuid[i].nid;
  73. break;
  74. }
  75. map_cpu_to_node(cpu, node);
  76. }
  77. }