numa_64.c 17 KB

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