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