numa_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Generic VM initialization for x86-64 NUMA setups.
  3. * Copyright 2002,2003 Andi Kleen, SuSE Labs.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/mm.h>
  7. #include <linux/string.h>
  8. #include <linux/init.h>
  9. #include <linux/bootmem.h>
  10. #include <linux/mmzone.h>
  11. #include <linux/ctype.h>
  12. #include <linux/module.h>
  13. #include <linux/nodemask.h>
  14. #include <asm/e820.h>
  15. #include <asm/proto.h>
  16. #include <asm/dma.h>
  17. #include <asm/numa.h>
  18. #include <asm/acpi.h>
  19. #ifndef Dprintk
  20. #define Dprintk(x...)
  21. #endif
  22. struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
  23. bootmem_data_t plat_node_bdata[MAX_NUMNODES];
  24. struct memnode memnode;
  25. unsigned char cpu_to_node[NR_CPUS] __read_mostly = {
  26. [0 ... NR_CPUS-1] = NUMA_NO_NODE
  27. };
  28. unsigned char apicid_to_node[MAX_LOCAL_APIC] __cpuinitdata = {
  29. [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
  30. };
  31. cpumask_t node_to_cpumask[MAX_NUMNODES] __read_mostly;
  32. int numa_off __initdata;
  33. unsigned long __initdata nodemap_addr;
  34. unsigned long __initdata nodemap_size;
  35. /*
  36. * Given a shift value, try to populate memnodemap[]
  37. * Returns :
  38. * 1 if OK
  39. * 0 if memnodmap[] too small (of shift too small)
  40. * -1 if node overlap or lost ram (shift too big)
  41. */
  42. static int __init
  43. populate_memnodemap(const struct bootnode *nodes, int numnodes, int shift)
  44. {
  45. int i;
  46. int res = -1;
  47. unsigned long addr, end;
  48. memset(memnodemap, 0xff, memnodemapsize);
  49. for (i = 0; i < numnodes; i++) {
  50. addr = nodes[i].start;
  51. end = nodes[i].end;
  52. if (addr >= end)
  53. continue;
  54. if ((end >> shift) >= memnodemapsize)
  55. return 0;
  56. do {
  57. if (memnodemap[addr >> shift] != 0xff)
  58. return -1;
  59. memnodemap[addr >> shift] = i;
  60. addr += (1UL << shift);
  61. } while (addr < end);
  62. res = 1;
  63. }
  64. return res;
  65. }
  66. static int __init allocate_cachealigned_memnodemap(void)
  67. {
  68. unsigned long pad, pad_addr;
  69. memnodemap = memnode.embedded_map;
  70. if (memnodemapsize <= 48)
  71. return 0;
  72. pad = L1_CACHE_BYTES - 1;
  73. pad_addr = 0x8000;
  74. nodemap_size = pad + memnodemapsize;
  75. nodemap_addr = find_e820_area(pad_addr, end_pfn<<PAGE_SHIFT,
  76. nodemap_size);
  77. if (nodemap_addr == -1UL) {
  78. printk(KERN_ERR
  79. "NUMA: Unable to allocate Memory to Node hash map\n");
  80. nodemap_addr = nodemap_size = 0;
  81. return -1;
  82. }
  83. pad_addr = (nodemap_addr + pad) & ~pad;
  84. memnodemap = phys_to_virt(pad_addr);
  85. printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n",
  86. nodemap_addr, nodemap_addr + nodemap_size);
  87. return 0;
  88. }
  89. /*
  90. * The LSB of all start and end addresses in the node map is the value of the
  91. * maximum possible shift.
  92. */
  93. static int __init
  94. extract_lsb_from_nodes (const struct bootnode *nodes, int numnodes)
  95. {
  96. int i, nodes_used = 0;
  97. unsigned long start, end;
  98. unsigned long bitfield = 0, memtop = 0;
  99. for (i = 0; i < numnodes; i++) {
  100. start = nodes[i].start;
  101. end = nodes[i].end;
  102. if (start >= end)
  103. continue;
  104. bitfield |= start;
  105. nodes_used++;
  106. if (end > memtop)
  107. memtop = end;
  108. }
  109. if (nodes_used <= 1)
  110. i = 63;
  111. else
  112. i = find_first_bit(&bitfield, sizeof(unsigned long)*8);
  113. memnodemapsize = (memtop >> i)+1;
  114. return i;
  115. }
  116. int __init compute_hash_shift(struct bootnode *nodes, int numnodes)
  117. {
  118. int shift;
  119. shift = extract_lsb_from_nodes(nodes, numnodes);
  120. if (allocate_cachealigned_memnodemap())
  121. return -1;
  122. printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n",
  123. shift);
  124. if (populate_memnodemap(nodes, numnodes, shift) != 1) {
  125. printk(KERN_INFO
  126. "Your memory is not aligned you need to rebuild your kernel "
  127. "with a bigger NODEMAPSIZE shift=%d\n",
  128. shift);
  129. return -1;
  130. }
  131. return shift;
  132. }
  133. #ifdef CONFIG_SPARSEMEM
  134. int early_pfn_to_nid(unsigned long pfn)
  135. {
  136. return phys_to_nid(pfn << PAGE_SHIFT);
  137. }
  138. #endif
  139. static void * __init
  140. early_node_mem(int nodeid, unsigned long start, unsigned long end,
  141. unsigned long size)
  142. {
  143. unsigned long mem = find_e820_area(start, end, size);
  144. void *ptr;
  145. if (mem != -1L)
  146. return __va(mem);
  147. ptr = __alloc_bootmem_nopanic(size,
  148. SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS));
  149. if (ptr == NULL) {
  150. printk(KERN_ERR "Cannot find %lu bytes in node %d\n",
  151. size, nodeid);
  152. return NULL;
  153. }
  154. return ptr;
  155. }
  156. /* Initialize bootmem allocator for a node */
  157. void __init setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
  158. {
  159. unsigned long start_pfn, end_pfn, bootmap_pages, bootmap_size, bootmap_start;
  160. unsigned long nodedata_phys;
  161. void *bootmap;
  162. const int pgdat_size = round_up(sizeof(pg_data_t), PAGE_SIZE);
  163. start = round_up(start, ZONE_ALIGN);
  164. printk(KERN_INFO "Bootmem setup node %d %016lx-%016lx\n", nodeid, start, end);
  165. start_pfn = start >> PAGE_SHIFT;
  166. end_pfn = end >> PAGE_SHIFT;
  167. node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size);
  168. if (node_data[nodeid] == NULL)
  169. return;
  170. nodedata_phys = __pa(node_data[nodeid]);
  171. memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
  172. NODE_DATA(nodeid)->bdata = &plat_node_bdata[nodeid];
  173. NODE_DATA(nodeid)->node_start_pfn = start_pfn;
  174. NODE_DATA(nodeid)->node_spanned_pages = end_pfn - start_pfn;
  175. /* Find a place for the bootmem map */
  176. bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  177. bootmap_start = round_up(nodedata_phys + pgdat_size, PAGE_SIZE);
  178. bootmap = early_node_mem(nodeid, bootmap_start, end,
  179. bootmap_pages<<PAGE_SHIFT);
  180. if (bootmap == NULL) {
  181. if (nodedata_phys < start || nodedata_phys >= end)
  182. free_bootmem((unsigned long)node_data[nodeid],pgdat_size);
  183. node_data[nodeid] = NULL;
  184. return;
  185. }
  186. bootmap_start = __pa(bootmap);
  187. Dprintk("bootmap start %lu pages %lu\n", bootmap_start, bootmap_pages);
  188. bootmap_size = init_bootmem_node(NODE_DATA(nodeid),
  189. bootmap_start >> PAGE_SHIFT,
  190. start_pfn, end_pfn);
  191. free_bootmem_with_active_regions(nodeid, end);
  192. reserve_bootmem_node(NODE_DATA(nodeid), nodedata_phys, pgdat_size);
  193. reserve_bootmem_node(NODE_DATA(nodeid), bootmap_start, bootmap_pages<<PAGE_SHIFT);
  194. #ifdef CONFIG_ACPI_NUMA
  195. srat_reserve_add_area(nodeid);
  196. #endif
  197. node_set_online(nodeid);
  198. }
  199. /* Initialize final allocator for a zone */
  200. void __init setup_node_zones(int nodeid)
  201. {
  202. unsigned long start_pfn, end_pfn, memmapsize, limit;
  203. start_pfn = node_start_pfn(nodeid);
  204. end_pfn = node_end_pfn(nodeid);
  205. Dprintk(KERN_INFO "Setting up memmap for node %d %lx-%lx\n",
  206. nodeid, start_pfn, end_pfn);
  207. /* Try to allocate mem_map at end to not fill up precious <4GB
  208. memory. */
  209. memmapsize = sizeof(struct page) * (end_pfn-start_pfn);
  210. limit = end_pfn << PAGE_SHIFT;
  211. #ifdef CONFIG_FLAT_NODE_MEM_MAP
  212. NODE_DATA(nodeid)->node_mem_map =
  213. __alloc_bootmem_core(NODE_DATA(nodeid)->bdata,
  214. memmapsize, SMP_CACHE_BYTES,
  215. round_down(limit - memmapsize, PAGE_SIZE),
  216. limit);
  217. #endif
  218. }
  219. void __init numa_init_array(void)
  220. {
  221. int rr, i;
  222. /* There are unfortunately some poorly designed mainboards around
  223. that only connect memory to a single CPU. This breaks the 1:1 cpu->node
  224. mapping. To avoid this fill in the mapping for all possible
  225. CPUs, as the number of CPUs is not known yet.
  226. We round robin the existing nodes. */
  227. rr = first_node(node_online_map);
  228. for (i = 0; i < NR_CPUS; i++) {
  229. if (cpu_to_node(i) != NUMA_NO_NODE)
  230. continue;
  231. numa_set_node(i, rr);
  232. rr = next_node(rr, node_online_map);
  233. if (rr == MAX_NUMNODES)
  234. rr = first_node(node_online_map);
  235. }
  236. }
  237. #ifdef CONFIG_NUMA_EMU
  238. /* Numa emulation */
  239. char *cmdline __initdata;
  240. /*
  241. * Setups up nid to range from addr to addr + size. If the end boundary is
  242. * greater than max_addr, then max_addr is used instead. The return value is 0
  243. * if there is additional memory left for allocation past addr and -1 otherwise.
  244. * addr is adjusted to be at the end of the node.
  245. */
  246. static int __init setup_node_range(int nid, struct bootnode *nodes, u64 *addr,
  247. u64 size, u64 max_addr)
  248. {
  249. int ret = 0;
  250. nodes[nid].start = *addr;
  251. *addr += size;
  252. if (*addr >= max_addr) {
  253. *addr = max_addr;
  254. ret = -1;
  255. }
  256. nodes[nid].end = *addr;
  257. node_set(nid, node_possible_map);
  258. printk(KERN_INFO "Faking node %d at %016Lx-%016Lx (%LuMB)\n", nid,
  259. nodes[nid].start, nodes[nid].end,
  260. (nodes[nid].end - nodes[nid].start) >> 20);
  261. return ret;
  262. }
  263. /*
  264. * Splits num_nodes nodes up equally starting at node_start. The return value
  265. * is the number of nodes split up and addr is adjusted to be at the end of the
  266. * last node allocated.
  267. */
  268. static int __init split_nodes_equally(struct bootnode *nodes, u64 *addr,
  269. u64 max_addr, int node_start,
  270. int num_nodes)
  271. {
  272. unsigned int big;
  273. u64 size;
  274. int i;
  275. if (num_nodes <= 0)
  276. return -1;
  277. if (num_nodes > MAX_NUMNODES)
  278. num_nodes = MAX_NUMNODES;
  279. size = (max_addr - *addr - e820_hole_size(*addr, max_addr)) /
  280. num_nodes;
  281. /*
  282. * Calculate the number of big nodes that can be allocated as a result
  283. * of consolidating the leftovers.
  284. */
  285. big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * num_nodes) /
  286. FAKE_NODE_MIN_SIZE;
  287. /* Round down to nearest FAKE_NODE_MIN_SIZE. */
  288. size &= FAKE_NODE_MIN_HASH_MASK;
  289. if (!size) {
  290. printk(KERN_ERR "Not enough memory for each node. "
  291. "NUMA emulation disabled.\n");
  292. return -1;
  293. }
  294. for (i = node_start; i < num_nodes + node_start; i++) {
  295. u64 end = *addr + size;
  296. if (i < big)
  297. end += FAKE_NODE_MIN_SIZE;
  298. /*
  299. * The final node can have the remaining system RAM. Other
  300. * nodes receive roughly the same amount of available pages.
  301. */
  302. if (i == num_nodes + node_start - 1)
  303. end = max_addr;
  304. else
  305. while (end - *addr - e820_hole_size(*addr, end) <
  306. size) {
  307. end += FAKE_NODE_MIN_SIZE;
  308. if (end > max_addr) {
  309. end = max_addr;
  310. break;
  311. }
  312. }
  313. if (setup_node_range(i, nodes, addr, end - *addr, max_addr) < 0)
  314. break;
  315. }
  316. return i - node_start + 1;
  317. }
  318. /*
  319. * Splits the remaining system RAM into chunks of size. The remaining memory is
  320. * always assigned to a final node and can be asymmetric. Returns the number of
  321. * nodes split.
  322. */
  323. static int __init split_nodes_by_size(struct bootnode *nodes, u64 *addr,
  324. u64 max_addr, int node_start, u64 size)
  325. {
  326. int i = node_start;
  327. size = (size << 20) & FAKE_NODE_MIN_HASH_MASK;
  328. while (!setup_node_range(i++, nodes, addr, size, max_addr))
  329. ;
  330. return i - node_start;
  331. }
  332. /*
  333. * Sets up the system RAM area from start_pfn to end_pfn according to the
  334. * numa=fake command-line option.
  335. */
  336. static int __init numa_emulation(unsigned long start_pfn, unsigned long end_pfn)
  337. {
  338. struct bootnode nodes[MAX_NUMNODES];
  339. u64 addr = start_pfn << PAGE_SHIFT;
  340. u64 max_addr = end_pfn << PAGE_SHIFT;
  341. int num_nodes = 0;
  342. int coeff_flag;
  343. int coeff = -1;
  344. int num = 0;
  345. u64 size;
  346. int i;
  347. memset(&nodes, 0, sizeof(nodes));
  348. /*
  349. * If the numa=fake command-line is just a single number N, split the
  350. * system RAM into N fake nodes.
  351. */
  352. if (!strchr(cmdline, '*') && !strchr(cmdline, ',')) {
  353. num_nodes = split_nodes_equally(nodes, &addr, max_addr, 0,
  354. simple_strtol(cmdline, NULL, 0));
  355. if (num_nodes < 0)
  356. return num_nodes;
  357. goto out;
  358. }
  359. /* Parse the command line. */
  360. for (coeff_flag = 0; ; cmdline++) {
  361. if (*cmdline && isdigit(*cmdline)) {
  362. num = num * 10 + *cmdline - '0';
  363. continue;
  364. }
  365. if (*cmdline == '*') {
  366. if (num > 0)
  367. coeff = num;
  368. coeff_flag = 1;
  369. }
  370. if (!*cmdline || *cmdline == ',') {
  371. if (!coeff_flag)
  372. coeff = 1;
  373. /*
  374. * Round down to the nearest FAKE_NODE_MIN_SIZE.
  375. * Command-line coefficients are in megabytes.
  376. */
  377. size = ((u64)num << 20) & FAKE_NODE_MIN_HASH_MASK;
  378. if (size)
  379. for (i = 0; i < coeff; i++, num_nodes++)
  380. if (setup_node_range(num_nodes, nodes,
  381. &addr, size, max_addr) < 0)
  382. goto done;
  383. if (!*cmdline)
  384. break;
  385. coeff_flag = 0;
  386. coeff = -1;
  387. }
  388. num = 0;
  389. }
  390. done:
  391. if (!num_nodes)
  392. return -1;
  393. /* Fill remainder of system RAM, if appropriate. */
  394. if (addr < max_addr) {
  395. if (coeff_flag && coeff < 0) {
  396. /* Split remaining nodes into num-sized chunks */
  397. num_nodes += split_nodes_by_size(nodes, &addr, max_addr,
  398. num_nodes, num);
  399. goto out;
  400. }
  401. switch (*(cmdline - 1)) {
  402. case '*':
  403. /* Split remaining nodes into coeff chunks */
  404. if (coeff <= 0)
  405. break;
  406. num_nodes += split_nodes_equally(nodes, &addr, max_addr,
  407. num_nodes, coeff);
  408. break;
  409. case ',':
  410. /* Do not allocate remaining system RAM */
  411. break;
  412. default:
  413. /* Give one final node */
  414. setup_node_range(num_nodes, nodes, &addr,
  415. max_addr - addr, max_addr);
  416. num_nodes++;
  417. }
  418. }
  419. out:
  420. memnode_shift = compute_hash_shift(nodes, num_nodes);
  421. if (memnode_shift < 0) {
  422. memnode_shift = 0;
  423. printk(KERN_ERR "No NUMA hash function found. NUMA emulation "
  424. "disabled.\n");
  425. return -1;
  426. }
  427. /*
  428. * We need to vacate all active ranges that may have been registered by
  429. * SRAT and set acpi_numa to -1 so that srat_disabled() always returns
  430. * true. NUMA emulation has succeeded so we will not scan ACPI nodes.
  431. */
  432. remove_all_active_ranges();
  433. #ifdef CONFIG_ACPI_NUMA
  434. acpi_numa = -1;
  435. #endif
  436. for_each_node_mask(i, node_possible_map) {
  437. e820_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
  438. nodes[i].end >> PAGE_SHIFT);
  439. setup_node_bootmem(i, nodes[i].start, nodes[i].end);
  440. }
  441. acpi_fake_nodes(nodes, num_nodes);
  442. numa_init_array();
  443. return 0;
  444. }
  445. #endif /* CONFIG_NUMA_EMU */
  446. void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
  447. {
  448. int i;
  449. nodes_clear(node_possible_map);
  450. #ifdef CONFIG_NUMA_EMU
  451. if (cmdline && !numa_emulation(start_pfn, end_pfn))
  452. return;
  453. nodes_clear(node_possible_map);
  454. #endif
  455. #ifdef CONFIG_ACPI_NUMA
  456. if (!numa_off && !acpi_scan_nodes(start_pfn << PAGE_SHIFT,
  457. end_pfn << PAGE_SHIFT))
  458. return;
  459. nodes_clear(node_possible_map);
  460. #endif
  461. #ifdef CONFIG_K8_NUMA
  462. if (!numa_off && !k8_scan_nodes(start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT))
  463. return;
  464. nodes_clear(node_possible_map);
  465. #endif
  466. printk(KERN_INFO "%s\n",
  467. numa_off ? "NUMA turned off" : "No NUMA configuration found");
  468. printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
  469. start_pfn << PAGE_SHIFT,
  470. end_pfn << PAGE_SHIFT);
  471. /* setup dummy node covering all memory */
  472. memnode_shift = 63;
  473. memnodemap = memnode.embedded_map;
  474. memnodemap[0] = 0;
  475. nodes_clear(node_online_map);
  476. node_set_online(0);
  477. node_set(0, node_possible_map);
  478. for (i = 0; i < NR_CPUS; i++)
  479. numa_set_node(i, 0);
  480. node_to_cpumask[0] = cpumask_of_cpu(0);
  481. e820_register_active_regions(0, start_pfn, end_pfn);
  482. setup_node_bootmem(0, start_pfn << PAGE_SHIFT, end_pfn << PAGE_SHIFT);
  483. }
  484. __cpuinit void numa_add_cpu(int cpu)
  485. {
  486. set_bit(cpu, &node_to_cpumask[cpu_to_node(cpu)]);
  487. }
  488. void __cpuinit numa_set_node(int cpu, int node)
  489. {
  490. cpu_pda(cpu)->nodenumber = node;
  491. cpu_to_node(cpu) = node;
  492. }
  493. unsigned long __init numa_free_all_bootmem(void)
  494. {
  495. int i;
  496. unsigned long pages = 0;
  497. for_each_online_node(i) {
  498. pages += free_all_bootmem_node(NODE_DATA(i));
  499. }
  500. return pages;
  501. }
  502. void __init paging_init(void)
  503. {
  504. int i;
  505. unsigned long max_zone_pfns[MAX_NR_ZONES];
  506. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  507. max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
  508. max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
  509. max_zone_pfns[ZONE_NORMAL] = end_pfn;
  510. sparse_memory_present_with_active_regions(MAX_NUMNODES);
  511. sparse_init();
  512. for_each_online_node(i) {
  513. setup_node_zones(i);
  514. }
  515. free_area_init_nodes(max_zone_pfns);
  516. }
  517. static __init int numa_setup(char *opt)
  518. {
  519. if (!opt)
  520. return -EINVAL;
  521. if (!strncmp(opt,"off",3))
  522. numa_off = 1;
  523. #ifdef CONFIG_NUMA_EMU
  524. if (!strncmp(opt, "fake=", 5))
  525. cmdline = opt + 5;
  526. #endif
  527. #ifdef CONFIG_ACPI_NUMA
  528. if (!strncmp(opt,"noacpi",6))
  529. acpi_numa = -1;
  530. if (!strncmp(opt,"hotadd=", 7))
  531. hotadd_percent = simple_strtoul(opt+7, NULL, 10);
  532. #endif
  533. return 0;
  534. }
  535. early_param("numa", numa_setup);
  536. /*
  537. * Setup early cpu_to_node.
  538. *
  539. * Populate cpu_to_node[] only if x86_cpu_to_apicid[],
  540. * and apicid_to_node[] tables have valid entries for a CPU.
  541. * This means we skip cpu_to_node[] initialisation for NUMA
  542. * emulation and faking node case (when running a kernel compiled
  543. * for NUMA on a non NUMA box), which is OK as cpu_to_node[]
  544. * is already initialized in a round robin manner at numa_init_array,
  545. * prior to this call, and this initialization is good enough
  546. * for the fake NUMA cases.
  547. */
  548. void __init init_cpu_to_node(void)
  549. {
  550. int i;
  551. for (i = 0; i < NR_CPUS; i++) {
  552. u8 apicid = x86_cpu_to_apicid_init[i];
  553. if (apicid == BAD_APICID)
  554. continue;
  555. if (apicid_to_node[apicid] == NUMA_NO_NODE)
  556. continue;
  557. numa_set_node(i,apicid_to_node[apicid]);
  558. }
  559. }
  560. EXPORT_SYMBOL(cpu_to_node);
  561. EXPORT_SYMBOL(node_to_cpumask);
  562. EXPORT_SYMBOL(memnode);
  563. EXPORT_SYMBOL(node_data);
  564. #ifdef CONFIG_DISCONTIGMEM
  565. /*
  566. * Functions to convert PFNs from/to per node page addresses.
  567. * These are out of line because they are quite big.
  568. * They could be all tuned by pre caching more state.
  569. * Should do that.
  570. */
  571. int pfn_valid(unsigned long pfn)
  572. {
  573. unsigned nid;
  574. if (pfn >= num_physpages)
  575. return 0;
  576. nid = pfn_to_nid(pfn);
  577. if (nid == 0xff)
  578. return 0;
  579. return pfn >= node_start_pfn(nid) && (pfn) < node_end_pfn(nid);
  580. }
  581. EXPORT_SYMBOL(pfn_valid);
  582. #endif