ia64/xen-unstable

changeset 15580:29761c9b9105

Add new domctl hypercall to expose current heap values. This
functionality is needed for probing how much memory is available in a
given node prior to VM creation.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Jul 11 13:03:57 2007 +0100 (2007-07-11)
parents ac814633799b
children c6491ed12f84
files tools/libxc/xc_domain.c tools/libxc/xenctrl.h xen/common/page_alloc.c xen/common/sysctl.c xen/include/public/sysctl.h xen/include/xen/mm.h
line diff
     1.1 --- a/tools/libxc/xc_domain.c	Wed Jul 11 10:56:52 2007 +0100
     1.2 +++ b/tools/libxc/xc_domain.c	Wed Jul 11 13:03:57 2007 +0100
     1.3 @@ -588,6 +588,27 @@ int xc_domain_ioport_permission(int xc_h
     1.4      return do_domctl(xc_handle, &domctl);
     1.5  }
     1.6  
     1.7 +int xc_availheap(int xc_handle,
     1.8 +                 int min_width,
     1.9 +                 int max_width,
    1.10 +                 int node,
    1.11 +                 uint64_t *bytes)
    1.12 +{
    1.13 +    DECLARE_SYSCTL;
    1.14 +    int rc;
    1.15 +
    1.16 +    sysctl.cmd = XEN_SYSCTL_availheap;
    1.17 +    sysctl.u.availheap.min_bitwidth = min_width;
    1.18 +    sysctl.u.availheap.max_bitwidth = max_width;
    1.19 +    sysctl.u.availheap.node = node;
    1.20 +
    1.21 +    rc = xc_sysctl(xc_handle, &sysctl);
    1.22 +
    1.23 +    *bytes = sysctl.u.availheap.avail_bytes;
    1.24 +
    1.25 +    return rc;
    1.26 +}
    1.27 +
    1.28  int xc_vcpu_setcontext(int xc_handle,
    1.29                         uint32_t domid,
    1.30                         uint32_t vcpu,
     2.1 --- a/tools/libxc/xenctrl.h	Wed Jul 11 10:56:52 2007 +0100
     2.2 +++ b/tools/libxc/xenctrl.h	Wed Jul 11 13:03:57 2007 +0100
     2.3 @@ -616,6 +616,20 @@ int xc_get_pfn_type_batch(int xc_handle,
     2.4  /* Get current total pages allocated to a domain. */
     2.5  long xc_get_tot_pages(int xc_handle, uint32_t domid);
     2.6  
     2.7 +/**
     2.8 + * This function retrieves the the number of bytes available
     2.9 + * in the heap in a specific range of address-widths and nodes.
    2.10 + * 
    2.11 + * @parm xc_handle a handle to an open hypervisor interface
    2.12 + * @parm domid the domain to query
    2.13 + * @parm min_width the smallest address width to query (0 if don't care)
    2.14 + * @parm max_width the largest address width to query (0 if don't care)
    2.15 + * @parm node the node to query (-1 for all)
    2.16 + * @parm *bytes caller variable to put total bytes counted
    2.17 + * @return 0 on success, <0 on failure.
    2.18 + */
    2.19 +int xc_availheap(int xc_handle, int min_width, int max_width, int node,
    2.20 +                 uint64_t *bytes);
    2.21  
    2.22  /*
    2.23   * Trace Buffer Operations
     3.1 --- a/xen/common/page_alloc.c	Wed Jul 11 10:56:52 2007 +0100
     3.2 +++ b/xen/common/page_alloc.c	Wed Jul 11 13:03:57 2007 +0100
     3.3 @@ -936,6 +936,21 @@ void free_domheap_pages(struct page_info
     3.4          put_domain(d);
     3.5  }
     3.6  
     3.7 +unsigned long avail_domheap_pages_region(
     3.8 +    unsigned int node, unsigned int min_width, unsigned int max_width)
     3.9 +{
    3.10 +    int zone_lo, zone_hi;
    3.11 +
    3.12 +    zone_lo = min_width ? (min_width - (PAGE_SHIFT + 1)) : (MEMZONE_XEN + 1);
    3.13 +    zone_lo = max_t(int, MEMZONE_XEN + 1, zone_lo);
    3.14 +    zone_lo = min_t(int, NR_ZONES - 1, zone_lo);
    3.15 +
    3.16 +    zone_hi = max_width ? (max_width - (PAGE_SHIFT + 1)) : (NR_ZONES - 1);
    3.17 +    zone_hi = max_t(int, MEMZONE_XEN + 1, zone_hi);
    3.18 +    zone_hi = min_t(int, NR_ZONES - 1, zone_hi);
    3.19 +
    3.20 +    return avail_heap_pages(zone_lo, zone_hi, node);
    3.21 +}
    3.22  
    3.23  unsigned long avail_domheap_pages(void)
    3.24  {
    3.25 @@ -957,11 +972,6 @@ unsigned long avail_domheap_pages(void)
    3.26      return avail_nrm + avail_dma;
    3.27  }
    3.28  
    3.29 -unsigned long avail_nodeheap_pages(int node)
    3.30 -{
    3.31 -    return avail_heap_pages(0, NR_ZONES - 1, node);
    3.32 -}
    3.33 -
    3.34  static void pagealloc_keyhandler(unsigned char key)
    3.35  {
    3.36      unsigned int zone = MEMZONE_XEN;
     4.1 --- a/xen/common/sysctl.c	Wed Jul 11 10:56:52 2007 +0100
     4.2 +++ b/xen/common/sysctl.c	Wed Jul 11 13:03:57 2007 +0100
     4.3 @@ -21,6 +21,8 @@
     4.4  #include <xen/keyhandler.h>
     4.5  #include <asm/current.h>
     4.6  #include <public/sysctl.h>
     4.7 +#include <asm/numa.h>
     4.8 +#include <xen/nodemask.h>
     4.9  
    4.10  extern long arch_do_sysctl(
    4.11      struct xen_sysctl *op, XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl);
    4.12 @@ -169,6 +171,18 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
    4.13      }
    4.14      break;
    4.15  
    4.16 +    case XEN_SYSCTL_availheap:
    4.17 +    { 
    4.18 +        op->u.availheap.avail_bytes = avail_domheap_pages_region(
    4.19 +            op->u.availheap.node,
    4.20 +            op->u.availheap.min_bitwidth,
    4.21 +            op->u.availheap.max_bitwidth);
    4.22 +        op->u.availheap.avail_bytes <<= PAGE_SHIFT;
    4.23 +
    4.24 +        ret = copy_to_guest(u_sysctl, op, 1) ? -EFAULT : 0;
    4.25 +    }
    4.26 +    break;
    4.27 +
    4.28      default:
    4.29          ret = arch_do_sysctl(op, u_sysctl);
    4.30          break;
     5.1 --- a/xen/include/public/sysctl.h	Wed Jul 11 10:56:52 2007 +0100
     5.2 +++ b/xen/include/public/sysctl.h	Wed Jul 11 13:03:57 2007 +0100
     5.3 @@ -185,6 +185,18 @@ struct xen_sysctl_getcpuinfo {
     5.4  typedef struct xen_sysctl_getcpuinfo xen_sysctl_getcpuinfo_t;
     5.5  DEFINE_XEN_GUEST_HANDLE(xen_sysctl_getcpuinfo_t); 
     5.6  
     5.7 +#define XEN_SYSCTL_availheap         9
     5.8 +struct xen_sysctl_availheap {
     5.9 +    /* IN variables. */
    5.10 +    uint32_t min_bitwidth;  /* Smallest address width (zero if don't care). */
    5.11 +    uint32_t max_bitwidth;  /* Largest address width (zero if don't care). */
    5.12 +    int32_t  node;          /* NUMA node of interest (-1 for all nodes). */
    5.13 +    /* OUT variables. */
    5.14 +    uint64_t avail_bytes;   /* Bytes available in the specified region. */
    5.15 +};
    5.16 +typedef struct xen_sysctl_availheap xen_sysctl_availheap_t;
    5.17 +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_availheap_t);
    5.18 + 
    5.19  struct xen_sysctl {
    5.20      uint32_t cmd;
    5.21      uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
    5.22 @@ -197,6 +209,7 @@ struct xen_sysctl {
    5.23          struct xen_sysctl_getdomaininfolist getdomaininfolist;
    5.24          struct xen_sysctl_debug_keys        debug_keys;
    5.25          struct xen_sysctl_getcpuinfo        getcpuinfo;
    5.26 +        struct xen_sysctl_availheap         availheap;
    5.27          uint8_t                             pad[128];
    5.28      } u;
    5.29  };
     6.1 --- a/xen/include/xen/mm.h	Wed Jul 11 10:56:52 2007 +0100
     6.2 +++ b/xen/include/xen/mm.h	Wed Jul 11 13:03:57 2007 +0100
     6.3 @@ -61,6 +61,8 @@ struct page_info *__alloc_domheap_pages(
     6.4      struct domain *d, unsigned int cpu, unsigned int order, 
     6.5      unsigned int memflags);
     6.6  void free_domheap_pages(struct page_info *pg, unsigned int order);
     6.7 +unsigned long avail_domheap_pages_region(
     6.8 +    unsigned int node, unsigned int min_width, unsigned int max_width);
     6.9  unsigned long avail_domheap_pages(void);
    6.10  #define alloc_domheap_page(d) (alloc_domheap_pages(d,0,0))
    6.11  #define free_domheap_page(p)  (free_domheap_pages(p,0))