numa.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 can
  7. * be split away from DISCONTIGMEM and are used on NUMA machines with
  8. * contiguous memory.
  9. *
  10. * 2002/08/07 Erich Focht <efocht@ess.nec.de>
  11. */
  12. #include <linux/cpu.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mm.h>
  15. #include <linux/node.h>
  16. #include <linux/init.h>
  17. #include <linux/bootmem.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. /*
  28. * This is a matrix with "distances" between nodes, they should be
  29. * proportional to the memory access latency ratios.
  30. */
  31. u8 numa_slit[MAX_NUMNODES * MAX_NUMNODES];
  32. /* Identify which cnode a physical address resides on */
  33. int
  34. paddr_to_nid(unsigned long paddr)
  35. {
  36. int i;
  37. for (i = 0; i < num_node_memblks; i++)
  38. if (paddr >= node_memblk[i].start_paddr &&
  39. paddr < node_memblk[i].start_paddr + node_memblk[i].size)
  40. break;
  41. return (i < num_node_memblks) ? node_memblk[i].nid : (num_node_memblks ? -1 : 0);
  42. }
  43. #if defined(CONFIG_SPARSEMEM) && defined(CONFIG_NUMA)
  44. /*
  45. * Because of holes evaluate on section limits.
  46. * If the section of memory exists, then return the node where the section
  47. * resides. Otherwise return node 0 as the default. This is used by
  48. * SPARSEMEM to allocate the SPARSEMEM sectionmap on the NUMA node where
  49. * the section resides.
  50. */
  51. int early_pfn_to_nid(unsigned long pfn)
  52. {
  53. int i, section = pfn >> PFN_SECTION_SHIFT, ssec, esec;
  54. for (i = 0; i < num_node_memblks; i++) {
  55. ssec = node_memblk[i].start_paddr >> PA_SECTION_SHIFT;
  56. esec = (node_memblk[i].start_paddr + node_memblk[i].size +
  57. ((1L << PA_SECTION_SHIFT) - 1)) >> PA_SECTION_SHIFT;
  58. if (section >= ssec && section < esec)
  59. return node_memblk[i].nid;
  60. }
  61. return 0;
  62. }
  63. #endif