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