# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1184155437 -3600
# Node ID 29761c9b91056700f4215a023bd948fff78d8f22
# Parent ac814633799b1421afaba09c0880a17eb753526f
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@xxxxxxxxxx>
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
tools/libxc/xc_domain.c | 21 +++++++++++++++++++++
tools/libxc/xenctrl.h | 14 ++++++++++++++
xen/common/page_alloc.c | 20 +++++++++++++++-----
xen/common/sysctl.c | 14 ++++++++++++++
xen/include/public/sysctl.h | 13 +++++++++++++
xen/include/xen/mm.h | 2 ++
6 files changed, 79 insertions(+), 5 deletions(-)
diff -r ac814633799b -r 29761c9b9105 tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c Wed Jul 11 10:56:52 2007 +0100
+++ b/tools/libxc/xc_domain.c Wed Jul 11 13:03:57 2007 +0100
@@ -586,6 +586,27 @@ int xc_domain_ioport_permission(int xc_h
domctl.u.ioport_permission.allow_access = allow_access;
return do_domctl(xc_handle, &domctl);
+}
+
+int xc_availheap(int xc_handle,
+ int min_width,
+ int max_width,
+ int node,
+ uint64_t *bytes)
+{
+ DECLARE_SYSCTL;
+ int rc;
+
+ sysctl.cmd = XEN_SYSCTL_availheap;
+ sysctl.u.availheap.min_bitwidth = min_width;
+ sysctl.u.availheap.max_bitwidth = max_width;
+ sysctl.u.availheap.node = node;
+
+ rc = xc_sysctl(xc_handle, &sysctl);
+
+ *bytes = sysctl.u.availheap.avail_bytes;
+
+ return rc;
}
int xc_vcpu_setcontext(int xc_handle,
diff -r ac814633799b -r 29761c9b9105 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h Wed Jul 11 10:56:52 2007 +0100
+++ b/tools/libxc/xenctrl.h Wed Jul 11 13:03:57 2007 +0100
@@ -616,6 +616,20 @@ int xc_get_pfn_type_batch(int xc_handle,
/* Get current total pages allocated to a domain. */
long xc_get_tot_pages(int xc_handle, uint32_t domid);
+/**
+ * This function retrieves the the number of bytes available
+ * in the heap in a specific range of address-widths and nodes.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm domid the domain to query
+ * @parm min_width the smallest address width to query (0 if don't care)
+ * @parm max_width the largest address width to query (0 if don't care)
+ * @parm node the node to query (-1 for all)
+ * @parm *bytes caller variable to put total bytes counted
+ * @return 0 on success, <0 on failure.
+ */
+int xc_availheap(int xc_handle, int min_width, int max_width, int node,
+ uint64_t *bytes);
/*
* Trace Buffer Operations
diff -r ac814633799b -r 29761c9b9105 xen/common/page_alloc.c
--- a/xen/common/page_alloc.c Wed Jul 11 10:56:52 2007 +0100
+++ b/xen/common/page_alloc.c Wed Jul 11 13:03:57 2007 +0100
@@ -936,6 +936,21 @@ void free_domheap_pages(struct page_info
put_domain(d);
}
+unsigned long avail_domheap_pages_region(
+ unsigned int node, unsigned int min_width, unsigned int max_width)
+{
+ int zone_lo, zone_hi;
+
+ zone_lo = min_width ? (min_width - (PAGE_SHIFT + 1)) : (MEMZONE_XEN + 1);
+ zone_lo = max_t(int, MEMZONE_XEN + 1, zone_lo);
+ zone_lo = min_t(int, NR_ZONES - 1, zone_lo);
+
+ zone_hi = max_width ? (max_width - (PAGE_SHIFT + 1)) : (NR_ZONES - 1);
+ zone_hi = max_t(int, MEMZONE_XEN + 1, zone_hi);
+ zone_hi = min_t(int, NR_ZONES - 1, zone_hi);
+
+ return avail_heap_pages(zone_lo, zone_hi, node);
+}
unsigned long avail_domheap_pages(void)
{
@@ -955,11 +970,6 @@ unsigned long avail_domheap_pages(void)
avail_dma = 0;
return avail_nrm + avail_dma;
-}
-
-unsigned long avail_nodeheap_pages(int node)
-{
- return avail_heap_pages(0, NR_ZONES - 1, node);
}
static void pagealloc_keyhandler(unsigned char key)
diff -r ac814633799b -r 29761c9b9105 xen/common/sysctl.c
--- a/xen/common/sysctl.c Wed Jul 11 10:56:52 2007 +0100
+++ b/xen/common/sysctl.c Wed Jul 11 13:03:57 2007 +0100
@@ -21,6 +21,8 @@
#include <xen/keyhandler.h>
#include <asm/current.h>
#include <public/sysctl.h>
+#include <asm/numa.h>
+#include <xen/nodemask.h>
extern long arch_do_sysctl(
struct xen_sysctl *op, XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl);
@@ -166,6 +168,18 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
if ( copy_to_guest(u_sysctl, op, 1) )
ret = -EFAULT;
+ }
+ break;
+
+ case XEN_SYSCTL_availheap:
+ {
+ op->u.availheap.avail_bytes = avail_domheap_pages_region(
+ op->u.availheap.node,
+ op->u.availheap.min_bitwidth,
+ op->u.availheap.max_bitwidth);
+ op->u.availheap.avail_bytes <<= PAGE_SHIFT;
+
+ ret = copy_to_guest(u_sysctl, op, 1) ? -EFAULT : 0;
}
break;
diff -r ac814633799b -r 29761c9b9105 xen/include/public/sysctl.h
--- a/xen/include/public/sysctl.h Wed Jul 11 10:56:52 2007 +0100
+++ b/xen/include/public/sysctl.h Wed Jul 11 13:03:57 2007 +0100
@@ -185,6 +185,18 @@ typedef struct xen_sysctl_getcpuinfo xen
typedef struct xen_sysctl_getcpuinfo xen_sysctl_getcpuinfo_t;
DEFINE_XEN_GUEST_HANDLE(xen_sysctl_getcpuinfo_t);
+#define XEN_SYSCTL_availheap 9
+struct xen_sysctl_availheap {
+ /* IN variables. */
+ uint32_t min_bitwidth; /* Smallest address width (zero if don't care). */
+ uint32_t max_bitwidth; /* Largest address width (zero if don't care). */
+ int32_t node; /* NUMA node of interest (-1 for all nodes). */
+ /* OUT variables. */
+ uint64_t avail_bytes; /* Bytes available in the specified region. */
+};
+typedef struct xen_sysctl_availheap xen_sysctl_availheap_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_availheap_t);
+
struct xen_sysctl {
uint32_t cmd;
uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
@@ -197,6 +209,7 @@ struct xen_sysctl {
struct xen_sysctl_getdomaininfolist getdomaininfolist;
struct xen_sysctl_debug_keys debug_keys;
struct xen_sysctl_getcpuinfo getcpuinfo;
+ struct xen_sysctl_availheap availheap;
uint8_t pad[128];
} u;
};
diff -r ac814633799b -r 29761c9b9105 xen/include/xen/mm.h
--- a/xen/include/xen/mm.h Wed Jul 11 10:56:52 2007 +0100
+++ b/xen/include/xen/mm.h Wed Jul 11 13:03:57 2007 +0100
@@ -61,6 +61,8 @@ struct page_info *__alloc_domheap_pages(
struct domain *d, unsigned int cpu, unsigned int order,
unsigned int memflags);
void free_domheap_pages(struct page_info *pg, unsigned int order);
+unsigned long avail_domheap_pages_region(
+ unsigned int node, unsigned int min_width, unsigned int max_width);
unsigned long avail_domheap_pages(void);
#define alloc_domheap_page(d) (alloc_domheap_pages(d,0,0))
#define free_domheap_page(p) (free_domheap_pages(p,0))
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|