numa_64.c 17 KB

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