numa.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * This file contains NUMA specific variables and functions which are used on
  7. * NUMA machines with contiguous memory.
  8. *
  9. * 2002/08/07 Erich Focht <[email protected]>
  10. */
  11. #include <linux/cpu.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mm.h>
  14. #include <linux/node.h>
  15. #include <linux/init.h>
  16. #include <linux/memblock.h>
  17. #include <linux/module.h>
  18. #include <asm/mmzone.h>
  19. #include <asm/numa.h>
  20. /*
  21. * The following structures are usually initialized by ACPI or
  22. * similar mechanisms and describe the NUMA characteristics of the machine.
  23. */
  24. int num_node_memblks;
  25. struct node_memblk_s node_memblk[NR_NODE_MEMBLKS];
  26. struct node_cpuid_s node_cpuid[NR_CPUS] =
  27. { [0 ... NR_CPUS-1] = { .phys_id = 0, .nid = NUMA_NO_NODE } };
  28. /*
  29. * This is a matrix with "distances" between nodes, they should be
  30. * proportional to the memory access latency ratios.
  31. */
  32. u8 numa_slit[MAX_NUMNODES * MAX_NUMNODES];
  33. int __node_distance(int from, int to)
  34. {
  35. return slit_distance(from, to);
  36. }
  37. EXPORT_SYMBOL(__node_distance);
  38. /* Identify which cnode a physical address resides on */
  39. int
  40. paddr_to_nid(unsigned long paddr)
  41. {
  42. int i;
  43. for (i = 0; i < num_node_memblks; i++)
  44. if (paddr >= node_memblk[i].start_paddr &&
  45. paddr < node_memblk[i].start_paddr + node_memblk[i].size)
  46. break;
  47. return (i < num_node_memblks) ? node_memblk[i].nid : (num_node_memblks ? -1 : 0);
  48. }
  49. EXPORT_SYMBOL(paddr_to_nid);
  50. #if defined(CONFIG_SPARSEMEM) && defined(CONFIG_NUMA)
  51. void numa_clear_node(int cpu)
  52. {
  53. unmap_cpu_from_node(cpu, NUMA_NO_NODE);
  54. }
  55. #ifdef CONFIG_MEMORY_HOTPLUG
  56. /*
  57. * SRAT information is stored in node_memblk[], then we can use SRAT
  58. * information at memory-hot-add if necessary.
  59. */
  60. int memory_add_physaddr_to_nid(u64 addr)
  61. {
  62. int nid = paddr_to_nid(addr);
  63. if (nid < 0)
  64. return 0;
  65. return nid;
  66. }
  67. EXPORT_SYMBOL(memory_add_physaddr_to_nid);
  68. #endif
  69. #endif