numa_64.c 17 KB

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