numa_64.c 17 KB

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