numa_64.c 17 KB

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