numa_64.c 16 KB

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