numa_64.c 17 KB

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