ia64/xen-unstable

view xen/arch/ia64/xen/xensetup.c @ 15693:87a72ba32301

[IA64] Saner dom0 memory and cpu defaults

Some ia64 xen dom0 tweaks:
* Increase default memory allocation from 512M to 4G
* Increase default vcpu allocation from 1 to 4
* Implement rough calculation of what the maximum memory
that can be safely allocated to dom0 is
* If need be, scale down requested memory allocation to fit
available memory, rather than simply panicking
* If dom0_mem=0 is specified, allocate all available mem

Signed-off-by: Jarod Wilson <jwilson@redhat.com>
author Alex Williamson <alex.williamson@hp.com>
date Wed Aug 08 20:48:11 2007 -0600 (2007-08-08)
parents 6a89339b81d0
children 9341dd055619 7e7e0ea6a0bb
line source
1 /******************************************************************************
2 * xensetup.c
3 * Copyright (c) 2004-2005 Hewlett-Packard Co
4 * Dan Magenheimer <dan.magenheimer@hp.com>
5 */
7 #include <xen/config.h>
8 #include <xen/lib.h>
9 #include <xen/errno.h>
10 #include <xen/multiboot.h>
11 #include <xen/sched.h>
12 #include <xen/mm.h>
13 #include <public/version.h>
14 #include <xen/gdbstub.h>
15 #include <xen/version.h>
16 #include <xen/console.h>
17 #include <xen/domain.h>
18 #include <xen/serial.h>
19 #include <xen/trace.h>
20 #include <xen/keyhandler.h>
21 #include <xen/vga.h>
22 #include <asm/meminit.h>
23 #include <asm/page.h>
24 #include <asm/setup.h>
25 #include <xen/string.h>
26 #include <asm/vmx.h>
27 #include <linux/efi.h>
28 #include <asm/iosapic.h>
29 #include <xen/softirq.h>
30 #include <xen/rcupdate.h>
31 #include <acm/acm_hooks.h>
32 #include <asm/sn/simulator.h>
34 unsigned long xenheap_phys_end, total_pages;
36 char saved_command_line[COMMAND_LINE_SIZE];
37 char __initdata dom0_command_line[COMMAND_LINE_SIZE];
39 cpumask_t cpu_present_map;
41 extern unsigned long domain0_ready;
43 int find_max_pfn (unsigned long, unsigned long, void *);
45 /* FIXME: which header these declarations should be there ? */
46 extern void early_setup_arch(char **);
47 extern void late_setup_arch(char **);
48 extern void hpsim_serial_init(void);
49 extern void setup_per_cpu_areas(void);
50 extern void mem_init(void);
51 extern void init_IRQ(void);
52 extern void trap_init(void);
53 extern void xen_patch_kernel(void);
55 /* opt_nosmp: If true, secondary processors are ignored. */
56 static int opt_nosmp;
57 boolean_param("nosmp", opt_nosmp);
59 /* maxcpus: maximum number of CPUs to activate. */
60 static unsigned int __initdata max_cpus = NR_CPUS;
61 integer_param("maxcpus", max_cpus);
63 /* xencons: if true enable xenconsole input (and irq).
64 Note: you have to disable 8250 serials in domains (to avoid use of the
65 same resource). */
66 static int __initdata opt_xencons = 1;
67 integer_param("xencons", opt_xencons);
69 /* Toggle to allow non-legacy xencons UARTs to run in polling mode */
70 static int __initdata opt_xencons_poll;
71 boolean_param("xencons_poll", opt_xencons_poll);
73 /*
74 * opt_xenheap_megabytes: Size of Xen heap in megabytes, including:
75 * xen image
76 * bootmap bits
77 * xen heap
78 * Note: To allow xenheap size configurable, the prerequisite is
79 * to configure elilo allowing relocation defaultly. Then since
80 * elilo chooses 256M as alignment when relocating, alignment issue
81 * on IPF can be addressed.
82 */
83 unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
84 unsigned long xenheap_size = XENHEAP_DEFAULT_SIZE;
85 unsigned long xen_pstart;
86 void *xen_pickle_offset __read_mostly;
88 static int __init
89 xen_count_pages(u64 start, u64 end, void *arg)
90 {
91 unsigned long *count = arg;
93 /* FIXME: do we need consider difference between DMA-usable memory and
94 * normal memory? Seems that HV has no requirement to operate DMA which
95 * is owned by Dom0? */
96 *count += (end - start) >> PAGE_SHIFT;
97 return 0;
98 }
100 static void __init do_initcalls(void)
101 {
102 initcall_t *call;
103 for ( call = &__initcall_start; call < &__initcall_end; call++ )
104 (*call)();
105 }
107 /*
108 * IPF loader only supports one commaind line currently, for
109 * both xen and guest kernel. This function provides pre-parse
110 * to mixed command line, to split it into two parts.
111 *
112 * User should split the parameters by "--", with strings after
113 * spliter for guest kernel. Missing "--" means whole line belongs
114 * to guest. Example:
115 * "com2=57600,8n1 console=com2 -- console=ttyS1 console=tty
116 * root=/dev/sda3 ro"
117 */
118 static char null[4] = { 0 };
120 void __init early_cmdline_parse(char **cmdline_p)
121 {
122 char *guest_cmd;
123 static const char * const split = "--";
125 if (*cmdline_p == NULL) {
126 *cmdline_p = &null[0];
127 saved_command_line[0] = '\0';
128 dom0_command_line[0] = '\0';
129 return;
130 }
132 guest_cmd = strstr(*cmdline_p, split);
133 /* If no spliter, whole line is for guest */
134 if (guest_cmd == NULL) {
135 guest_cmd = *cmdline_p;
136 *cmdline_p = &null[0];
137 } else {
138 *guest_cmd = '\0'; /* Split boot parameters for xen and guest */
139 guest_cmd += strlen(split);
140 while (*guest_cmd == ' ') guest_cmd++;
141 }
143 strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);
144 strlcpy(dom0_command_line, guest_cmd, COMMAND_LINE_SIZE);
145 return;
146 }
148 struct ns16550_defaults ns16550_com1 = {
149 .data_bits = 8,
150 .parity = 'n',
151 .stop_bits = 1
152 };
154 unsigned int ns16550_com1_gsi;
155 unsigned int ns16550_com1_polarity;
156 unsigned int ns16550_com1_trigger;
158 struct ns16550_defaults ns16550_com2 = {
159 .data_bits = 8,
160 .parity = 'n',
161 .stop_bits = 1
162 };
164 /* efi_print: print efi table at boot */
165 static int __initdata opt_efi_print;
166 boolean_param("efi_print", opt_efi_print);
168 /* print EFI memory map: */
169 static void __init
170 efi_print(void)
171 {
172 void *efi_map_start, *efi_map_end;
173 u64 efi_desc_size;
175 efi_memory_desc_t *md;
176 void *p;
177 int i;
179 if (!opt_efi_print)
180 return;
182 efi_map_start = __va(ia64_boot_param->efi_memmap);
183 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
184 efi_desc_size = ia64_boot_param->efi_memdesc_size;
186 for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
187 md = p;
188 printk("mem%02u: type=%2u, attr=0x%016lx, range=[0x%016lx-0x%016lx) "
189 "(%luMB)\n", i, md->type, md->attribute, md->phys_addr,
190 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
191 md->num_pages >> (20 - EFI_PAGE_SHIFT));
192 }
193 }
195 /*
196 * These functions are utility functions for getting and
197 * testing memory descriptors for allocating the xenheap area.
198 */
199 static efi_memory_desc_t *
200 efi_get_md (unsigned long phys_addr)
201 {
202 void *efi_map_start, *efi_map_end, *p;
203 efi_memory_desc_t *md;
204 u64 efi_desc_size;
206 efi_map_start = __va(ia64_boot_param->efi_memmap);
207 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
208 efi_desc_size = ia64_boot_param->efi_memdesc_size;
210 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
211 md = p;
212 if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
213 return md;
214 }
215 return 0;
216 }
218 static int
219 is_xenheap_usable_memory(efi_memory_desc_t *md)
220 {
221 if (!(md->attribute & EFI_MEMORY_WB))
222 return 0;
224 switch (md->type) {
225 case EFI_LOADER_CODE:
226 case EFI_LOADER_DATA:
227 case EFI_BOOT_SERVICES_CODE:
228 case EFI_BOOT_SERVICES_DATA:
229 case EFI_CONVENTIONAL_MEMORY:
230 return 1;
231 }
232 return 0;
233 }
235 static inline int
236 md_overlaps(efi_memory_desc_t *md, unsigned long phys_addr)
237 {
238 return (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT));
239 }
241 #define MD_SIZE(md) (md->num_pages << EFI_PAGE_SHIFT)
243 extern char __init_begin[], __init_end[];
244 static void noinline init_done(void)
245 {
246 memset(__init_begin, 0, __init_end - __init_begin);
247 flush_icache_range((unsigned long)__init_begin, (unsigned long)__init_end);
248 init_xenheap_pages(__pa(__init_begin), __pa(__init_end));
249 printk("Freed %ldkB init memory.\n",
250 (long)(__init_end-__init_begin)>>10);
252 startup_cpu_idle_loop();
253 }
255 int running_on_sim;
257 static int __init
258 is_platform_hp_ski(void)
259 {
260 int i;
261 long cpuid[6];
263 for (i = 0; i < 5; ++i)
264 cpuid[i] = ia64_get_cpuid(i);
266 if ((cpuid[0] & 0xff) != 'H')
267 return 0;
268 if ((cpuid[3] & 0xff) != 0x4)
269 return 0;
270 if (((cpuid[3] >> 8) & 0xff) != 0x0)
271 return 0;
272 if (((cpuid[3] >> 16) & 0xff) != 0x0)
273 return 0;
274 if (((cpuid[3] >> 24) & 0x7) != 0x7)
275 return 0;
277 return 1;
278 }
280 void __init start_kernel(void)
281 {
282 char *cmdline;
283 unsigned long nr_pages;
284 unsigned long dom0_memory_start, dom0_memory_size;
285 unsigned long dom0_initrd_start, dom0_initrd_size;
286 unsigned long md_end, relo_start, relo_end, relo_size = 0;
287 struct domain *idle_domain;
288 struct vcpu *dom0_vcpu0;
289 efi_memory_desc_t *kern_md, *last_md, *md;
290 void *xen_heap_start;
291 #ifdef CONFIG_SMP
292 int i;
293 #endif
295 /* Be sure the struct shared_info size is <= XSI_SIZE. */
296 BUILD_BUG_ON(sizeof(struct shared_info) > XSI_SIZE);
298 /* Kernel may be relocated by EFI loader */
299 xen_pstart = ia64_tpa(KERNEL_START);
301 running_on_sim = is_platform_hp_ski();
303 early_setup_arch(&cmdline);
305 /* We initialise the serial devices very early so we can get debugging. */
306 if (running_on_sim)
307 hpsim_serial_init();
308 else {
309 ns16550_init(0, &ns16550_com1);
310 ns16550_init(1, &ns16550_com2);
311 }
312 serial_init_preirq();
314 #ifdef CONFIG_VGA
315 /* Plug in a default VGA mode */
316 vga_console_info.video_type = XEN_VGATYPE_TEXT_MODE_3;
317 vga_console_info.u.text_mode_3.font_height = 16; /* generic VGA? */
318 vga_console_info.u.text_mode_3.cursor_x =
319 ia64_boot_param->console_info.orig_x;
320 vga_console_info.u.text_mode_3.cursor_y =
321 ia64_boot_param->console_info.orig_y;
322 vga_console_info.u.text_mode_3.rows =
323 ia64_boot_param->console_info.num_rows;
324 vga_console_info.u.text_mode_3.columns =
325 ia64_boot_param->console_info.num_cols;
326 #endif
328 init_console();
329 set_printk_prefix("(XEN) ");
331 if (running_on_sim || ia64_boot_param->domain_start == 0 ||
332 ia64_boot_param->domain_size == 0) {
333 /* This is possible only with the old elilo, which does not support
334 a vmm. Fix now, and continue without initrd. */
335 printk ("Your elilo is not Xen-aware. Bootparams fixed\n");
336 ia64_boot_param->domain_start = ia64_boot_param->initrd_start;
337 ia64_boot_param->domain_size = ia64_boot_param->initrd_size;
338 ia64_boot_param->initrd_start = 0;
339 ia64_boot_param->initrd_size = 0;
340 }
342 printk("Xen command line: %s\n", saved_command_line);
343 /* xenheap should be in same TR-covered range with xen image */
344 xenheap_phys_end = xen_pstart + xenheap_size;
345 printk("xen image pstart: 0x%lx, xenheap pend: 0x%lx\n",
346 xen_pstart, xenheap_phys_end);
348 xen_patch_kernel();
350 kern_md = md = efi_get_md(xen_pstart);
351 md_end = __pa(ia64_imva(&_end));
352 relo_start = xenheap_phys_end;
354 /*
355 * Scan through the memory descriptors after the kernel
356 * image to make sure we have enough room for the xenheap
357 * area, pushing out whatever may already be there.
358 */
359 while (relo_start + relo_size >= md_end) {
360 md = efi_get_md(md_end);
362 BUG_ON(!md);
363 BUG_ON(!is_xenheap_usable_memory(md));
365 md_end = md->phys_addr + MD_SIZE(md);
366 /*
367 * The dom0 kernel or initrd could overlap, reserve space
368 * at the end to relocate them later.
369 */
370 if (md->type == EFI_LOADER_DATA) {
371 /* Test for ranges we're not prepared to move */
372 BUG_ON(md_overlaps(md, __pa(ia64_boot_param)) ||
373 md_overlaps(md, ia64_boot_param->efi_memmap) ||
374 md_overlaps(md, ia64_boot_param->command_line));
376 relo_size += MD_SIZE(md);
377 /* If range overlaps the end, push out the relocation start */
378 if (md_end > relo_start)
379 relo_start = md_end;
380 }
381 }
382 last_md = md;
383 relo_end = relo_start + relo_size;
385 md_end = __pa(ia64_imva(&_end));
387 /*
388 * Move any relocated data out into the previously found relocation
389 * area. Any extra memory descriptrs are moved out to the end
390 * and set to zero pages.
391 */
392 for (md = efi_get_md(md_end) ;; md = efi_get_md(md_end)) {
393 md_end = md->phys_addr + MD_SIZE(md);
395 if (md->type == EFI_LOADER_DATA) {
396 unsigned long relo_offset;
398 if (md_overlaps(md, ia64_boot_param->domain_start)) {
399 relo_offset = ia64_boot_param->domain_start - md->phys_addr;
400 printk("Moving Dom0 kernel image: 0x%lx -> 0x%lx (%ld KiB)\n",
401 ia64_boot_param->domain_start, relo_start + relo_offset,
402 ia64_boot_param->domain_size >> 10);
403 ia64_boot_param->domain_start = relo_start + relo_offset;
404 }
405 if (ia64_boot_param->initrd_size &&
406 md_overlaps(md, ia64_boot_param->initrd_start)) {
407 relo_offset = ia64_boot_param->initrd_start - md->phys_addr;
408 printk("Moving Dom0 initrd image: 0x%lx -> 0x%lx (%ld KiB)\n",
409 ia64_boot_param->initrd_start, relo_start + relo_offset,
410 ia64_boot_param->initrd_size >> 10);
411 ia64_boot_param->initrd_start = relo_start + relo_offset;
412 }
413 memcpy(__va(relo_start), __va(md->phys_addr), MD_SIZE(md));
414 relo_start += MD_SIZE(md);
415 }
417 if (md == kern_md)
418 continue;
419 if (md == last_md)
420 break;
422 md->phys_addr = relo_end;
423 md->num_pages = 0;
424 }
426 /* Trim the last entry */
427 md->phys_addr = relo_end;
428 md->num_pages = (md_end - relo_end) >> EFI_PAGE_SHIFT;
430 /*
431 * Expand the new kernel/xenheap (and maybe dom0/initrd) out to
432 * the full size. This range will already be type EFI_LOADER_DATA,
433 * therefore the xenheap area is now protected being allocated for
434 * use by find_memmap_space() in efi.c
435 */
436 kern_md->num_pages = (relo_end - kern_md->phys_addr) >> EFI_PAGE_SHIFT;
438 reserve_memory();
440 /* first find highest page frame number */
441 max_page = 0;
442 efi_memmap_walk(find_max_pfn, &max_page);
443 printk("find_memory: efi_memmap_walk returns max_page=%lx\n",max_page);
444 efi_print();
446 /*
447 * later [__init_begin, __init_end) will be freed up as xen heap
448 * so that struct domain might be allocated from the init area
449 * which is < xen_heap_start. so we can't simply set
450 * xen_pickle_offset = xen_heap_start.
451 */
452 xen_pickle_offset = ia64_imva(__init_begin);
454 xen_heap_start = memguard_init(ia64_imva(&_end));
455 printk("Before xen_heap_start: %p\n", xen_heap_start);
456 xen_heap_start = __va(init_boot_allocator(__pa(xen_heap_start)));
457 printk("After xen_heap_start: %p\n", xen_heap_start);
459 efi_memmap_walk(filter_rsvd_memory, init_boot_pages);
460 efi_memmap_walk(xen_count_pages, &nr_pages);
462 printk("System RAM: %luMB (%lukB)\n",
463 nr_pages >> (20 - PAGE_SHIFT),
464 nr_pages << (PAGE_SHIFT - 10));
465 total_pages = nr_pages;
467 init_frametable();
469 trap_init();
471 init_xenheap_pages(__pa(xen_heap_start), xenheap_phys_end);
472 printk("Xen heap: %luMB (%lukB)\n",
473 (xenheap_phys_end-__pa(xen_heap_start)) >> 20,
474 (xenheap_phys_end-__pa(xen_heap_start)) >> 10);
476 end_boot_allocator();
478 late_setup_arch(&cmdline);
480 scheduler_init();
481 idle_vcpu[0] = (struct vcpu*) ia64_r13;
482 idle_domain = domain_create(IDLE_DOMAIN_ID, 0, 0);
483 if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
484 BUG();
486 alloc_dom_xen_and_dom_io();
487 setup_per_cpu_areas();
488 mem_init();
490 local_irq_disable();
491 init_IRQ ();
492 init_xen_time(); /* initialise the time */
493 timer_init();
495 rcu_init();
497 #ifdef CONFIG_XEN_IA64_TLBFLUSH_CLOCK
498 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
499 #endif
501 #ifdef CONFIG_SMP
502 if ( opt_nosmp )
503 {
504 max_cpus = 0;
505 smp_num_siblings = 1;
506 //boot_cpu_data.x86_num_cores = 1;
507 }
509 /* A vcpu is created for the idle domain on every physical cpu.
510 Limit the number of cpus to the maximum number of vcpus. */
511 if (max_cpus > MAX_VIRT_CPUS)
512 max_cpus = MAX_VIRT_CPUS;
514 smp_prepare_cpus(max_cpus);
516 /* We aren't hotplug-capable yet. */
517 for_each_cpu ( i )
518 cpu_set(i, cpu_present_map);
520 /* Enable IRQ to receive IPI (needed for ITC sync). */
521 local_irq_enable();
523 printk("num_online_cpus=%d, max_cpus=%d\n",num_online_cpus(),max_cpus);
524 for_each_present_cpu ( i )
525 {
526 if ( num_online_cpus() >= max_cpus )
527 break;
528 if ( !cpu_online(i) ) {
529 rcu_online_cpu(i);
530 __cpu_up(i);
531 }
532 }
534 local_irq_disable();
536 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
537 smp_cpus_done(max_cpus);
538 #endif
540 initialise_gdb(); /* could be moved earlier */
542 do_initcalls();
543 sort_main_extable();
545 init_rid_allocator ();
547 local_irq_enable();
549 if (opt_xencons) {
550 initialize_keytable();
551 if (ns16550_com1_gsi) {
552 if (opt_xencons_poll ||
553 iosapic_register_intr(ns16550_com1_gsi,
554 ns16550_com1_polarity,
555 ns16550_com1_trigger) < 0) {
556 ns16550_com1.irq = 0;
557 ns16550_init(0, &ns16550_com1);
558 }
559 }
560 serial_init_postirq();
561 }
563 expose_p2m_init();
565 /* Create initial domain 0. */
566 dom0 = domain_create(0, 0, DOM0_SSIDREF);
567 if (dom0 == NULL)
568 panic("Error creating domain 0\n");
569 dom0_vcpu0 = alloc_vcpu(dom0, 0, 0);
570 if (dom0_vcpu0 == NULL || vcpu_late_initialise(dom0_vcpu0) != 0)
571 panic("Cannot allocate dom0 vcpu 0\n");
573 dom0->is_privileged = 1;
575 /*
576 * We're going to setup domain0 using the module(s) that we stashed safely
577 * above our heap. The second module, if present, is an initrd ramdisk.
578 */
579 dom0_memory_start = (unsigned long) __va(ia64_boot_param->domain_start);
580 dom0_memory_size = ia64_boot_param->domain_size;
581 dom0_initrd_start = (unsigned long) __va(ia64_boot_param->initrd_start);
582 dom0_initrd_size = ia64_boot_param->initrd_size;
584 if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_size,
585 dom0_initrd_start,dom0_initrd_size,
586 0) != 0)
587 panic("Could not set up DOM0 guest OS\n");
589 if (!running_on_sim && !IS_MEDUSA()) // slow on ski and pages are pre-initialized to zero
590 scrub_heap_pages();
592 init_trace_bufs();
594 if (opt_xencons) {
595 console_endboot();
596 serial_endboot();
597 }
599 domain0_ready = 1;
601 domain_unpause_by_systemcontroller(dom0);
603 init_done();
604 }
606 void arch_get_xen_caps(xen_capabilities_info_t *info)
607 {
608 /* Interface name is always xen-3.0-* for Xen-3.x. */
609 int major = 3, minor = 0;
610 char s[32];
612 (*info)[0] = '\0';
614 snprintf(s, sizeof(s), "xen-%d.%d-ia64 ", major, minor);
615 safe_strcat(*info, s);
617 snprintf(s, sizeof(s), "xen-%d.%d-ia64be ", major, minor);
618 safe_strcat(*info, s);
620 if (vmx_enabled)
621 {
622 snprintf(s, sizeof(s), "hvm-%d.%d-ia64 ", major, minor);
623 safe_strcat(*info, s);
624 }
625 }