numa.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Common code for 32 and 64-bit NUMA */
  2. #include <linux/topology.h>
  3. #include <linux/module.h>
  4. #include <linux/bootmem.h>
  5. #ifdef CONFIG_DEBUG_PER_CPU_MAPS
  6. # define DBG(x...) printk(KERN_DEBUG x)
  7. #else
  8. # define DBG(x...)
  9. #endif
  10. /*
  11. * Which logical CPUs are on which nodes
  12. */
  13. cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
  14. EXPORT_SYMBOL(node_to_cpumask_map);
  15. /*
  16. * Allocate node_to_cpumask_map based on number of available nodes
  17. * Requires node_possible_map to be valid.
  18. *
  19. * Note: node_to_cpumask() is not valid until after this is done.
  20. * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
  21. */
  22. void __init setup_node_to_cpumask_map(void)
  23. {
  24. unsigned int node, num = 0;
  25. /* setup nr_node_ids if not done yet */
  26. if (nr_node_ids == MAX_NUMNODES) {
  27. for_each_node_mask(node, node_possible_map)
  28. num = node;
  29. nr_node_ids = num + 1;
  30. }
  31. /* allocate the map */
  32. for (node = 0; node < nr_node_ids; node++)
  33. alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
  34. /* cpumask_of_node() will now work */
  35. pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
  36. }
  37. #ifdef CONFIG_DEBUG_PER_CPU_MAPS
  38. /*
  39. * Returns a pointer to the bitmask of CPUs on Node 'node'.
  40. */
  41. const struct cpumask *cpumask_of_node(int node)
  42. {
  43. if (node >= nr_node_ids) {
  44. printk(KERN_WARNING
  45. "cpumask_of_node(%d): node > nr_node_ids(%d)\n",
  46. node, nr_node_ids);
  47. dump_stack();
  48. return cpu_none_mask;
  49. }
  50. if (node_to_cpumask_map[node] == NULL) {
  51. printk(KERN_WARNING
  52. "cpumask_of_node(%d): no node_to_cpumask_map!\n",
  53. node);
  54. dump_stack();
  55. return cpu_online_mask;
  56. }
  57. return node_to_cpumask_map[node];
  58. }
  59. EXPORT_SYMBOL(cpumask_of_node);
  60. #endif