ia64/xen-unstable

changeset 12925:234257c78627

[XEN][POWERPC] Allocate Xen memory area based on the amount of memory
This will make sure that there is enough memory for large HTABs, as well as:
- enables "xenheap_megabytes=" cmdline option
- consistently reports on memory system
- reduces noise in memory.c
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author Jimi Xenidis <jimix@watson.ibm.com>
date Fri Sep 29 14:31:05 2006 -0400 (2006-09-29)
parents 2985a7a12706
children 4ca8abbd89c8
files xen/arch/powerpc/domain_build.c xen/arch/powerpc/memory.c xen/arch/powerpc/setup.c
line diff
     1.1 --- a/xen/arch/powerpc/domain_build.c	Fri Sep 29 11:29:32 2006 -0400
     1.2 +++ b/xen/arch/powerpc/domain_build.c	Fri Sep 29 14:31:05 2006 -0400
     1.3 @@ -178,8 +178,7 @@ int construct_dom0(struct domain *d,
     1.4          shadow_set_allocation(d, opt_dom0_shadow, &preempt);
     1.5      } while (preempt);
     1.6      if (shadow_get_allocation(d) == 0)
     1.7 -        panic("shadow allocation failed 0x%x < 0x%x\n",
     1.8 -              shadow_get_allocation(d), opt_dom0_shadow);
     1.9 +        panic("shadow allocation failed: %dMib\n", opt_dom0_shadow);
    1.10  
    1.11      ASSERT( image_len < rma_sz );
    1.12  
     2.1 --- a/xen/arch/powerpc/memory.c	Fri Sep 29 11:29:32 2006 -0400
     2.2 +++ b/xen/arch/powerpc/memory.c	Fri Sep 29 14:31:05 2006 -0400
     2.3 @@ -24,7 +24,26 @@
     2.4  #include "oftree.h"
     2.5  #include "rtas.h"
     2.6  
     2.7 +#undef DEBUG
     2.8 +#ifdef DEBUG
     2.9 +#define DBG(fmt...) printk(fmt)
    2.10 +#else
    2.11 +#define DBG(fmt...)
    2.12 +#endif
    2.13 +
    2.14 +/*
    2.15 + * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
    2.16 + * page_info table and allocation bitmap.
    2.17 + */
    2.18 +static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
    2.19 +integer_param("xenheap_megabytes", opt_xenheap_megabytes);
    2.20 +
    2.21  unsigned long xenheap_phys_end;
    2.22 +static uint nr_pages;
    2.23 +static ulong xenheap_size;
    2.24 +static ulong save_start;
    2.25 +static ulong save_end;
    2.26 +
    2.27  struct membuf {
    2.28      ulong start;
    2.29      ulong size;
    2.30 @@ -34,31 +53,23 @@ typedef void (*walk_mem_fn)(struct membu
    2.31  
    2.32  static ulong free_xenheap(ulong start, ulong end)
    2.33  {
    2.34 -    ulong save_start;
    2.35 -    ulong save_end;
    2.36 -
    2.37      start = ALIGN_UP(start, PAGE_SIZE);
    2.38      end = ALIGN_DOWN(end, PAGE_SIZE);
    2.39  
    2.40 -    printk("%s: 0x%lx - 0x%lx\n", __func__, start, end);
    2.41 -
    2.42 -    save_start = oftree;
    2.43 -    save_end = oftree_end;
    2.44 -    if (rtas_base) {
    2.45 -        if (save_start > rtas_base)
    2.46 -            save_start = rtas_base;
    2.47 -        if (save_end < rtas_end)
    2.48 -            save_end = rtas_end;
    2.49 -    }
    2.50 +    DBG("%s: 0x%lx - 0x%lx\n", __func__, start, end);
    2.51  
    2.52      /* need to do this better */
    2.53      if (save_start <= end && save_start >= start) {
    2.54 -        printk("%s:     Go around the saved area: 0x%lx - 0x%lx\n",
    2.55 +        DBG("%s:     Go around the saved area: 0x%lx - 0x%lx\n",
    2.56                 __func__, save_start, save_end);
    2.57          init_xenheap_pages(start, ALIGN_DOWN(save_start, PAGE_SIZE));
    2.58 +        xenheap_size += ALIGN_DOWN(save_start, PAGE_SIZE) - start;
    2.59 +
    2.60          init_xenheap_pages(ALIGN_UP(save_end, PAGE_SIZE), end);
    2.61 +        xenheap_size += end - ALIGN_UP(save_end, PAGE_SIZE);
    2.62      } else {
    2.63          init_xenheap_pages(start, end);
    2.64 +        xenheap_size += end - start;
    2.65      }
    2.66  
    2.67      return ALIGN_UP(end, PAGE_SIZE);
    2.68 @@ -71,8 +82,10 @@ static void set_max_page(struct membuf *
    2.69      for (i = 0; i < entries; i++) {
    2.70          ulong end_page;
    2.71  
    2.72 +        printk("  %016lx: %016lx\n", mb[i].start, mb[i].size);
    2.73 +        nr_pages += mb[i].size >> PAGE_SHIFT;
    2.74 +
    2.75          end_page = (mb[i].start + mb[i].size) >> PAGE_SHIFT;
    2.76 -
    2.77          if (end_page > max_page)
    2.78              max_page = end_page;
    2.79      }
    2.80 @@ -163,19 +176,42 @@ static void setup_xenheap(module_t *mod,
    2.81  void memory_init(module_t *mod, int mcount)
    2.82  {
    2.83      ulong eomem;
    2.84 -    ulong heap_start, heap_size;
    2.85 -
    2.86 -    printk("Physical RAM map:\n");
    2.87 +    ulong heap_start;
    2.88 +    ulong xh_pages;
    2.89  
    2.90      /* lets find out how much memory there is and set max_page */
    2.91      max_page = 0;
    2.92 +    printk("Physical RAM map:\n");
    2.93      ofd_walk_mem((void *)oftree, set_max_page);
    2.94      eomem = max_page << PAGE_SHIFT;
    2.95  
    2.96      if (eomem == 0){
    2.97          panic("ofd_walk_mem() failed\n");
    2.98      }
    2.99 -    printk("End of RAM: %luMB (%lukB)\n", eomem >> 20, eomem >> 10);
   2.100 +
   2.101 +    /* find the portion of memory we need to keep safe */
   2.102 +    save_start = oftree;
   2.103 +    save_end = oftree_end;
   2.104 +    if (rtas_base) {
   2.105 +        if (save_start > rtas_base)
   2.106 +            save_start = rtas_base;
   2.107 +        if (save_end < rtas_end)
   2.108 +            save_end = rtas_end;
   2.109 +    }
   2.110 +
   2.111 +    /* minimum heap has to reach to the end of all Xen required memory */
   2.112 +    xh_pages = ALIGN_UP(save_end, PAGE_SIZE) >> PAGE_SHIFT;
   2.113 +    xh_pages += opt_xenheap_megabytes << (20 - PAGE_SHIFT);
   2.114 +
   2.115 +    /* While we are allocating HTABS from The Xen Heap we need it to
   2.116 +     * be larger */
   2.117 +    xh_pages  += nr_pages >> 5;
   2.118 +
   2.119 +    xenheap_phys_end = xh_pages << PAGE_SHIFT;
   2.120 +    printk("End of Xen Area: %luMiB (%luKiB)\n",
   2.121 +           xenheap_phys_end >> 20, xenheap_phys_end >> 10);
   2.122 +
   2.123 +    printk("End of RAM: %luMiB (%luKiB)\n", eomem >> 20, eomem >> 10);
   2.124  
   2.125      /* Architecturally the first 4 pages are exception hendlers, we
   2.126       * will also be copying down some code there */
   2.127 @@ -199,22 +235,20 @@ void memory_init(module_t *mod, int mcou
   2.128          panic("total_pages > max_page: 0x%lx > 0x%lx\n",
   2.129                total_pages, max_page);
   2.130  
   2.131 -    printk("total_pages: 0x%016lx\n", total_pages);
   2.132 +    DBG("total_pages: 0x%016lx\n", total_pages);
   2.133  
   2.134      init_frametable();
   2.135      end_boot_allocator();
   2.136  
   2.137      /* Add memory between the beginning of the heap and the beginning
   2.138 -     * of out text */
   2.139 +     * of our text */
   2.140      free_xenheap(heap_start, (ulong)_start);
   2.141 -
   2.142 -    heap_size = xenheap_phys_end - heap_start;
   2.143 -    printk("Xen heap: %luMB (%lukB)\n", heap_size >> 20, heap_size >> 10);
   2.144 -
   2.145      setup_xenheap(mod, mcount);
   2.146 +    printk("Xen Heap: %luMiB (%luKiB)\n",
   2.147 +           xenheap_size >> 20, xenheap_size >> 10);
   2.148  
   2.149      eomem = avail_domheap_pages();
   2.150 -    printk("Domheap pages: 0x%lx %luMB (%lukB)\n", eomem,
   2.151 +    printk("Dom Heap: %luMiB (%luKiB)\n",
   2.152             (eomem << PAGE_SHIFT) >> 20,
   2.153             (eomem << PAGE_SHIFT) >> 10);
   2.154  }
     3.1 --- a/xen/arch/powerpc/setup.c	Fri Sep 29 11:29:32 2006 -0400
     3.2 +++ b/xen/arch/powerpc/setup.c	Fri Sep 29 14:31:05 2006 -0400
     3.3 @@ -290,9 +290,6 @@ static void __init __start_xen(multiboot
     3.4      /* let synchronize until we really get going */
     3.5      console_start_sync();
     3.6  
     3.7 -    /* we give the first RMA to the hypervisor */
     3.8 -    xenheap_phys_end = rma_size(cpu_default_rma_order_pages());
     3.9 -
    3.10      /* Check that we have at least one Multiboot module. */
    3.11      if (!(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0)) {
    3.12          panic("FATAL ERROR: Require at least one Multiboot module.\n");