ia64/xen-unstable

changeset 17986:4bdc3de246c3

numa: Extend MEMOP_ allocation functions to take a node argument.

The address_bits field will be limited to 8 bits and is now embedded
in the mem_flags member, which additionally contains the node number
(limited to 8 bit).

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Sat Jul 05 14:43:37 2008 +0100 (2008-07-05)
parents 5b7e60d70394
children 8606ff75779f
files tools/ioemu/vl.c tools/libxc/xc_domain.c tools/libxc/xc_private.c tools/libxc/xenctrl.h tools/python/xen/lowlevel/xc/xc.c xen/common/memory.c xen/common/page_alloc.c xen/include/public/memory.h xen/include/public/xen-compat.h
line diff
     1.1 --- a/tools/ioemu/vl.c	Sat Jul 05 14:42:08 2008 +0100
     1.2 +++ b/tools/ioemu/vl.c	Sat Jul 05 14:43:37 2008 +0100
     1.3 @@ -7044,8 +7044,9 @@ int set_mm_mapping(int xc_handle, uint32
     1.4  {
     1.5      int err = 0;
     1.6  
     1.7 -    err = xc_domain_memory_populate_physmap(xc_handle, domid, nr_pages, 0,
     1.8 -                                            address_bits, extent_start);
     1.9 +    err = xc_domain_memory_populate_physmap(
    1.10 +        xc_handle, domid, nr_pages, 0,
    1.11 +        XENMEMF_address_bits(address_bits), extent_start);
    1.12      if (err) {
    1.13          fprintf(stderr, "Failed to populate physmap\n");
    1.14          return -1;
     2.1 --- a/tools/libxc/xc_domain.c	Sat Jul 05 14:42:08 2008 +0100
     2.2 +++ b/tools/libxc/xc_domain.c	Sat Jul 05 14:43:37 2008 +0100
     2.3 @@ -438,14 +438,14 @@ int xc_domain_memory_increase_reservatio
     2.4                                            uint32_t domid,
     2.5                                            unsigned long nr_extents,
     2.6                                            unsigned int extent_order,
     2.7 -                                          unsigned int address_bits,
     2.8 +                                          unsigned int mem_flags,
     2.9                                            xen_pfn_t *extent_start)
    2.10  {
    2.11      int err;
    2.12      struct xen_memory_reservation reservation = {
    2.13          .nr_extents   = nr_extents,
    2.14          .extent_order = extent_order,
    2.15 -        .address_bits = address_bits,
    2.16 +        .mem_flags    = mem_flags,
    2.17          .domid        = domid
    2.18      };
    2.19  
    2.20 @@ -459,8 +459,8 @@ int xc_domain_memory_increase_reservatio
    2.21      if ( err >= 0 )
    2.22      {
    2.23          DPRINTF("Failed allocation for dom %d: "
    2.24 -                "%ld extents of order %d, addr_bits %d\n",
    2.25 -                domid, nr_extents, extent_order, address_bits);
    2.26 +                "%ld extents of order %d, mem_flags %x\n",
    2.27 +                domid, nr_extents, extent_order, mem_flags);
    2.28          errno = ENOMEM;
    2.29          err = -1;
    2.30      }
    2.31 @@ -478,7 +478,7 @@ int xc_domain_memory_decrease_reservatio
    2.32      struct xen_memory_reservation reservation = {
    2.33          .nr_extents   = nr_extents,
    2.34          .extent_order = extent_order,
    2.35 -        .address_bits = 0,
    2.36 +        .mem_flags    = 0,
    2.37          .domid        = domid
    2.38      };
    2.39  
    2.40 @@ -507,17 +507,17 @@ int xc_domain_memory_decrease_reservatio
    2.41  }
    2.42  
    2.43  int xc_domain_memory_populate_physmap(int xc_handle,
    2.44 -                                          uint32_t domid,
    2.45 -                                          unsigned long nr_extents,
    2.46 -                                          unsigned int extent_order,
    2.47 -                                          unsigned int address_bits,
    2.48 -                                          xen_pfn_t *extent_start)
    2.49 +                                      uint32_t domid,
    2.50 +                                      unsigned long nr_extents,
    2.51 +                                      unsigned int extent_order,
    2.52 +                                      unsigned int mem_flags,
    2.53 +                                      xen_pfn_t *extent_start)
    2.54  {
    2.55      int err;
    2.56      struct xen_memory_reservation reservation = {
    2.57          .nr_extents   = nr_extents,
    2.58          .extent_order = extent_order,
    2.59 -        .address_bits = address_bits,
    2.60 +        .mem_flags    = mem_flags,
    2.61          .domid        = domid
    2.62      };
    2.63      set_xen_guest_handle(reservation.extent_start, extent_start);
     3.1 --- a/tools/libxc/xc_private.c	Sat Jul 05 14:42:08 2008 +0100
     3.2 +++ b/tools/libxc/xc_private.c	Sat Jul 05 14:43:37 2008 +0100
     3.3 @@ -501,7 +501,7 @@ unsigned long xc_make_page_below_4G(
     3.4      }
     3.5  
     3.6      if ( xc_domain_memory_increase_reservation(
     3.7 -        xc_handle, domid, 1, 0, 32, &new_mfn) != 0 )
     3.8 +        xc_handle, domid, 1, 0, XENMEMF_address_bits(32), &new_mfn) != 0 )
     3.9      {
    3.10          DPRINTF("xc_make_page_below_4G increase failed. mfn=%lx\n",mfn);
    3.11          return 0;
     4.1 --- a/tools/libxc/xenctrl.h	Sat Jul 05 14:42:08 2008 +0100
     4.2 +++ b/tools/libxc/xenctrl.h	Sat Jul 05 14:43:37 2008 +0100
     4.3 @@ -611,7 +611,7 @@ int xc_domain_memory_increase_reservatio
     4.4                                            uint32_t domid,
     4.5                                            unsigned long nr_extents,
     4.6                                            unsigned int extent_order,
     4.7 -                                          unsigned int address_bits,
     4.8 +                                          unsigned int mem_flags,
     4.9                                            xen_pfn_t *extent_start);
    4.10  
    4.11  int xc_domain_memory_decrease_reservation(int xc_handle,
    4.12 @@ -624,7 +624,7 @@ int xc_domain_memory_populate_physmap(in
    4.13                                        uint32_t domid,
    4.14                                        unsigned long nr_extents,
    4.15                                        unsigned int extent_order,
    4.16 -                                      unsigned int address_bits,
    4.17 +                                      unsigned int mem_flags,
    4.18                                        xen_pfn_t *extent_start);
    4.19  
    4.20  int xc_domain_ioport_permission(int xc_handle,
     5.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Sat Jul 05 14:42:08 2008 +0100
     5.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Sat Jul 05 14:43:37 2008 +0100
     5.3 @@ -1317,33 +1317,6 @@ static PyObject *pyxc_domain_set_memmap_
     5.4      return zero;
     5.5  }
     5.6  
     5.7 -static PyObject *pyxc_domain_memory_increase_reservation(XcObject *self,
     5.8 -                                                         PyObject *args,
     5.9 -                                                         PyObject *kwds)
    5.10 -{
    5.11 -    uint32_t dom;
    5.12 -    unsigned long mem_kb;
    5.13 -    unsigned int extent_order = 0 , address_bits = 0;
    5.14 -    unsigned long nr_extents;
    5.15 -
    5.16 -    static char *kwd_list[] = { "domid", "mem_kb", "extent_order", "address_bits", NULL };
    5.17 -
    5.18 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "il|ii", kwd_list, 
    5.19 -                                      &dom, &mem_kb, &extent_order, &address_bits) )
    5.20 -        return NULL;
    5.21 -
    5.22 -    /* round down to nearest power of 2. Assume callers using extent_order>0
    5.23 -       know what they are doing */
    5.24 -    nr_extents = (mem_kb / (XC_PAGE_SIZE/1024)) >> extent_order;
    5.25 -    if ( xc_domain_memory_increase_reservation(self->xc_handle, dom, 
    5.26 -                                               nr_extents, extent_order, 
    5.27 -                                               address_bits, NULL) )
    5.28 -        return pyxc_error_to_exception();
    5.29 -    
    5.30 -    Py_INCREF(zero);
    5.31 -    return zero;
    5.32 -}
    5.33 -
    5.34  static PyObject *pyxc_domain_ioport_permission(XcObject *self,
    5.35                                                 PyObject *args,
    5.36                                                 PyObject *kwds)
    5.37 @@ -1817,13 +1790,6 @@ static PyMethodDef pyxc_methods[] = {
    5.38        " map_limitkb [int]: .\n"
    5.39        "Returns: [int] 0 on success; -1 on error.\n" },
    5.40  
    5.41 -    { "domain_memory_increase_reservation", 
    5.42 -      (PyCFunction)pyxc_domain_memory_increase_reservation, 
    5.43 -      METH_VARARGS | METH_KEYWORDS, "\n"
    5.44 -      "Increase a domain's memory reservation\n"
    5.45 -      " dom [int]: Identifier of domain.\n"
    5.46 -      " mem_kb [long]: .\n"
    5.47 -      "Returns: [int] 0 on success; -1 on error.\n" },
    5.48  #ifdef __ia64__
    5.49      { "nvram_init",
    5.50        (PyCFunction)pyxc_nvram_init,
     6.1 --- a/xen/common/memory.c	Sat Jul 05 14:42:08 2008 +0100
     6.2 +++ b/xen/common/memory.c	Sat Jul 05 14:43:37 2008 +0100
     6.3 @@ -44,7 +44,6 @@ static void increase_reservation(struct 
     6.4      unsigned long i;
     6.5      xen_pfn_t mfn;
     6.6      struct domain *d = a->domain;
     6.7 -    unsigned int node = domain_to_node(d);
     6.8  
     6.9      if ( !guest_handle_is_null(a->extent_list) &&
    6.10           !guest_handle_subrange_okay(a->extent_list, a->nr_done,
    6.11 @@ -63,8 +62,7 @@ static void increase_reservation(struct 
    6.12              goto out;
    6.13          }
    6.14  
    6.15 -        page = alloc_domheap_pages(
    6.16 -            d, a->extent_order, a->memflags | MEMF_node(node));
    6.17 +        page = alloc_domheap_pages(d, a->extent_order, a->memflags);
    6.18          if ( unlikely(page == NULL) ) 
    6.19          {
    6.20              gdprintk(XENLOG_INFO, "Could not allocate order=%d extent: "
    6.21 @@ -93,7 +91,6 @@ static void populate_physmap(struct memo
    6.22      unsigned long i, j;
    6.23      xen_pfn_t gpfn, mfn;
    6.24      struct domain *d = a->domain;
    6.25 -    unsigned int node = domain_to_node(d);
    6.26  
    6.27      if ( !guest_handle_subrange_okay(a->extent_list, a->nr_done,
    6.28                                       a->nr_extents-1) )
    6.29 @@ -114,8 +111,7 @@ static void populate_physmap(struct memo
    6.30          if ( unlikely(__copy_from_guest_offset(&gpfn, a->extent_list, i, 1)) )
    6.31              goto out;
    6.32  
    6.33 -        page = alloc_domheap_pages(
    6.34 -            d, a->extent_order, a->memflags | MEMF_node(node));
    6.35 +        page = alloc_domheap_pages(d, a->extent_order, a->memflags);
    6.36          if ( unlikely(page == NULL) ) 
    6.37          {
    6.38              gdprintk(XENLOG_INFO, "Could not allocate order=%d extent: "
    6.39 @@ -345,8 +341,10 @@ static long memory_exchange(XEN_GUEST_HA
    6.40      d = current->domain;
    6.41  
    6.42      memflags |= MEMF_bits(domain_clamp_alloc_bitsize(
    6.43 -        d, exch.out.address_bits ? : (BITS_PER_LONG+PAGE_SHIFT)));
    6.44 -    memflags |= MEMF_node(domain_to_node(d));
    6.45 +        d,
    6.46 +        XENMEMF_get_address_bits(exch.out.mem_flags) ? :
    6.47 +        (BITS_PER_LONG+PAGE_SHIFT)));
    6.48 +    memflags |= MEMF_node(XENMEMF_get_node(exch.out.mem_flags));
    6.49  
    6.50      for ( i = (exch.nr_exchanged >> in_chunk_order);
    6.51            i < (exch.in.nr_extents >> in_chunk_order);
    6.52 @@ -490,6 +488,7 @@ long do_memory_op(unsigned long cmd, XEN
    6.53  {
    6.54      struct domain *d;
    6.55      int rc, op;
    6.56 +    unsigned int address_bits;
    6.57      unsigned long start_extent, progress;
    6.58      struct xen_memory_reservation reservation;
    6.59      struct memop_args args;
    6.60 @@ -521,15 +520,17 @@ long do_memory_op(unsigned long cmd, XEN
    6.61          args.preempted    = 0;
    6.62          args.memflags     = 0;
    6.63  
    6.64 -        if ( (reservation.address_bits != 0) &&
    6.65 -             (reservation.address_bits <
    6.66 -              (get_order_from_pages(max_page) + PAGE_SHIFT)) )
    6.67 +        address_bits = XENMEMF_get_address_bits(reservation.mem_flags);
    6.68 +        if ( (address_bits != 0) &&
    6.69 +             (address_bits < (get_order_from_pages(max_page) + PAGE_SHIFT)) )
    6.70          {
    6.71 -            if ( reservation.address_bits <= PAGE_SHIFT )
    6.72 +            if ( address_bits <= PAGE_SHIFT )
    6.73                  return start_extent;
    6.74 -            args.memflags = MEMF_bits(reservation.address_bits);
    6.75 +            args.memflags = MEMF_bits(address_bits);
    6.76          }
    6.77  
    6.78 +        args.memflags |= MEMF_node(XENMEMF_get_node(reservation.mem_flags));
    6.79 +
    6.80          if ( likely(reservation.domid == DOMID_SELF) )
    6.81          {
    6.82              d = rcu_lock_current_domain();
     7.1 --- a/xen/common/page_alloc.c	Sat Jul 05 14:42:08 2008 +0100
     7.2 +++ b/xen/common/page_alloc.c	Sat Jul 05 14:43:37 2008 +0100
     7.3 @@ -792,6 +792,9 @@ struct page_info *alloc_domheap_pages(
     7.4  
     7.5      ASSERT(!in_irq());
     7.6  
     7.7 +    if ( node == NUMA_NO_NODE )
     7.8 +        node = domain_to_node(d);
     7.9 +
    7.10      bits = domain_clamp_alloc_bitsize(d, bits ? : (BITS_PER_LONG+PAGE_SHIFT));
    7.11      if ( bits <= (PAGE_SHIFT + 1) )
    7.12          return NULL;
     8.1 --- a/xen/include/public/memory.h	Sat Jul 05 14:42:08 2008 +0100
     8.2 +++ b/xen/include/public/memory.h	Sat Jul 05 14:43:37 2008 +0100
     8.3 @@ -35,6 +35,21 @@
     8.4  #define XENMEM_increase_reservation 0
     8.5  #define XENMEM_decrease_reservation 1
     8.6  #define XENMEM_populate_physmap     6
     8.7 +
     8.8 +#if __XEN_INTERFACE_VERSION__ >= 0x00030209
     8.9 +/*
    8.10 + * Maximum # bits addressable by the user of the allocated region (e.g., I/O 
    8.11 + * devices often have a 32-bit limitation even in 64-bit systems). If zero 
    8.12 + * then the user has no addressing restriction. This field is not used by 
    8.13 + * XENMEM_decrease_reservation.
    8.14 + */
    8.15 +#define XENMEMF_address_bits(x)     (x)
    8.16 +#define XENMEMF_get_address_bits(x) ((x) & 0xffu)
    8.17 +/* NUMA node to allocate from. */
    8.18 +#define XENMEMF_node(x)     (((x) + 1) << 8)
    8.19 +#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
    8.20 +#endif
    8.21 +
    8.22  struct xen_memory_reservation {
    8.23  
    8.24      /*
    8.25 @@ -53,13 +68,12 @@ struct xen_memory_reservation {
    8.26      xen_ulong_t    nr_extents;
    8.27      unsigned int   extent_order;
    8.28  
    8.29 -    /*
    8.30 -     * Maximum # bits addressable by the user of the allocated region (e.g., 
    8.31 -     * I/O devices often have a 32-bit limitation even in 64-bit systems). If 
    8.32 -     * zero then the user has no addressing restriction.
    8.33 -     * This field is not used by XENMEM_decrease_reservation.
    8.34 -     */
    8.35 +#if __XEN_INTERFACE_VERSION__ >= 0x00030209
    8.36 +    /* XENMEMF flags. */
    8.37 +    unsigned int   mem_flags;
    8.38 +#else
    8.39      unsigned int   address_bits;
    8.40 +#endif
    8.41  
    8.42      /*
    8.43       * Domain whose reservation is being changed.
     9.1 --- a/xen/include/public/xen-compat.h	Sat Jul 05 14:42:08 2008 +0100
     9.2 +++ b/xen/include/public/xen-compat.h	Sat Jul 05 14:43:37 2008 +0100
     9.3 @@ -27,7 +27,7 @@
     9.4  #ifndef __XEN_PUBLIC_XEN_COMPAT_H__
     9.5  #define __XEN_PUBLIC_XEN_COMPAT_H__
     9.6  
     9.7 -#define __XEN_LATEST_INTERFACE_VERSION__ 0x00030208
     9.8 +#define __XEN_LATEST_INTERFACE_VERSION__ 0x00030209
     9.9  
    9.10  #if defined(__XEN__) || defined(__XEN_TOOLS__)
    9.11  /* Xen is built with matching headers and implements the latest interface. */