All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xen.org
Cc: Wei Liu <wei.liu2@citrix.com>,
	ian.campbell@citrix.com, dario.faggioli@citrix.com,
	ian.jackson@eu.citrix.com, JBeulich@suse.com,
	boris.ostrovsky@oracle.com, ufimtseva@gmail.com
Subject: [PATCH v2 09/19] libxl: functions to build vmemranges for PV guest
Date: Mon, 1 Dec 2014 15:33:33 +0000	[thread overview]
Message-ID: <1417448023-27311-10-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1417448023-27311-1-git-send-email-wei.liu2@citrix.com>

One vmemrange is generated for each vnode. And for those guests who care
about machine E820 map, vmemranges are further split to accommodate
memory holes.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Dario Faggioli <dario.faggioli@citrix.com>
Cc: Elena Ufimtseva <ufimtseva@gmail.com>
---
 tools/libxl/libxl_arch.h     |    6 ++++
 tools/libxl/libxl_arm.c      |    9 +++++
 tools/libxl/libxl_internal.h |    5 +++
 tools/libxl/libxl_vnuma.c    |   34 +++++++++++++++++++
 tools/libxl/libxl_x86.c      |   74 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 128 insertions(+)

diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index d3bc136..e249048 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -27,4 +27,10 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,
 int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
                                       libxl_domain_build_info *info,
                                       struct xc_dom_image *dom);
+
+/* build vNUMA vmemrange with arch specific information */
+int libxl__arch_vnuma_build_vmemrange(libxl__gc *gc,
+                                      uint32_t domid,
+                                      libxl_domain_build_info *b_info,
+                                      libxl__domain_build_state *state);
 #endif
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 34d21f5..1f1bc24 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -707,6 +707,15 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
     return 0;
 }
 
+int libxl__arch_vnuma_build_vmemrange(libxl__gc *gc,
+                                      uint32_t domid,
+                                      libxl_domain_build_info *info,
+                                      libxl__domain_build_state *state)
+{
+    /* Don't touch anything. */
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 88da7ba..1678715 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3397,6 +3397,11 @@ int libxl__vnuma_config_check(libxl__gc *gc,
                               const libxl_domain_build_info *b_info,
                               const libxl__domain_build_state *state);
 
+int libxl__vnuma_build_vmemrange_pv(libxl__gc *gc,
+                                    uint32_t domid,
+                                    libxl_domain_build_info *b_info,
+                                    libxl__domain_build_state *state);
+
 _hidden int libxl__ms_vm_genid_set(libxl__gc *gc, uint32_t domid,
                                    const libxl_ms_vm_genid *id);
 
diff --git a/tools/libxl/libxl_vnuma.c b/tools/libxl/libxl_vnuma.c
index d92376d..b8d9268 100644
--- a/tools/libxl/libxl_vnuma.c
+++ b/tools/libxl/libxl_vnuma.c
@@ -14,6 +14,7 @@
  */
 #include "libxl_osdeps.h" /* must come before any other headers */
 #include "libxl_internal.h"
+#include "libxl_arch.h"
 #include <stdlib.h>
 
 /* Sort vmemranges in ascending order with "start" */
@@ -129,6 +130,39 @@ out:
     return rc;
 }
 
+/* Build vmemranges for PV guest */
+int libxl__vnuma_build_vmemrange_pv(libxl__gc *gc,
+                                    uint32_t domid,
+                                    libxl_domain_build_info *b_info,
+                                    libxl__domain_build_state *state)
+{
+    int i;
+    uint64_t next;
+    xen_vmemrange_t *v = NULL;
+
+    assert(state->vmemranges == NULL);
+
+    /* Generate one vmemrange for each virtual node. */
+    next = 0;
+    for (i = 0; i < b_info->num_vnuma_nodes; i++) {
+        libxl_vnode_info *p = &b_info->vnuma_nodes[i];
+
+        v = libxl__realloc(gc, v, sizeof(*v) * (i+1));
+
+        v[i].start = next;
+        v[i].end = next + (p->mem << 20); /* mem is in MiB */
+        v[i].flags = 0;
+        v[i].nid = i;
+
+        next = v[i].end;
+    }
+
+    state->vmemranges = v;
+    state->num_vmemranges = i;
+
+    return libxl__arch_vnuma_build_vmemrange(gc, domid, b_info, state);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index e959e37..2018afc 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -338,6 +338,80 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
     return 0;
 }
 
+int libxl__arch_vnuma_build_vmemrange(libxl__gc *gc,
+                                      uint32_t domid,
+                                      libxl_domain_build_info *b_info,
+                                      libxl__domain_build_state *state)
+{
+    int i, x, n, rc;
+    uint32_t nr_e820;
+    struct e820entry map[E820MAX];
+    xen_vmemrange_t *v;
+
+    /* Only touch vmemranges if it's PV guest and e820_host is true */
+    if (!(b_info->type == LIBXL_DOMAIN_TYPE_PV &&
+          libxl_defbool_val(b_info->u.pv.e820_host))) {
+        rc = 0;
+        goto out;
+    }
+
+    rc = e820_host_sanitize(gc, b_info, map, &nr_e820);
+    if (rc) goto out;
+
+    /* Ditch old vmemranges and start with host E820 map. Note, memory
+     * was gc allocated.
+     */
+    state->vmemranges = NULL;
+    state->num_vmemranges = 0;
+
+    n = 0; /* E820 counter */
+    x = 0;
+    v = NULL;
+    for (i = 0; i < b_info->num_vnuma_nodes; i++) {
+        libxl_vnode_info *p = &b_info->vnuma_nodes[i];
+        uint64_t remaining = (p->mem << 20);
+
+        while (remaining > 0) {
+            if (n >= nr_e820) {
+                rc = ERROR_FAIL;
+                goto out;
+            }
+
+            /* Skip non RAM region */
+            if (map[n].type != E820_RAM) {
+                n++;
+                continue;
+            }
+
+            v = libxl__realloc(gc, v, sizeof(xen_vmemrange_t) * (x+1));
+
+            if (map[n].size >= remaining) {
+                v[x].start = map[n].addr;
+                v[x].end = map[n].addr + remaining;
+                map[n].addr += remaining;
+                map[n].size -= remaining;
+                remaining = 0;
+            } else {
+                v[x].start = map[n].addr;
+                v[x].end = map[n].addr + map[n].size;
+                remaining -= map[n].size;
+                n++;
+            }
+
+            v[x].flags = 0;
+            v[x].nid = i;
+            x++;
+        }
+    }
+
+    state->vmemranges = v;
+    state->num_vmemranges = x;
+
+    rc = 0;
+out:
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
-- 
1.7.10.4

  parent reply	other threads:[~2014-12-01 15:33 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-01 15:33 [PATCH v2 00/19] Virtual NUMA for PV and HVM Wei Liu
2014-12-01 15:33 ` [PATCH v2 01/19] xen: dump vNUMA information with debug key "u" Wei Liu
2014-12-08 17:01   ` Jan Beulich
2014-12-09 11:22     ` Wei Liu
2014-12-09 11:38       ` Jan Beulich
2014-12-01 15:33 ` [PATCH v2 02/19] xen: make two memory hypercalls vNUMA-aware Wei Liu
2014-12-08 17:05   ` Jan Beulich
2014-12-01 15:33 ` [PATCH v2 03/19] libxc: allocate memory with vNUMA information for PV guest Wei Liu
2015-01-12 17:11   ` Ian Campbell
2014-12-01 15:33 ` [PATCH v2 04/19] libxl: add emacs local variables in libxl_{x86, arm}.c Wei Liu
2015-01-12 17:11   ` Ian Campbell
2014-12-01 15:33 ` [PATCH v2 05/19] libxl: introduce vNUMA types Wei Liu
2015-01-12 17:17   ` Ian Campbell
2015-01-12 17:21     ` Wei Liu
2015-01-12 17:24       ` Ian Campbell
2014-12-01 15:33 ` [PATCH v2 06/19] libxl: add vmemrange to libxl__domain_build_state Wei Liu
2014-12-01 15:33 ` [PATCH v2 07/19] libxl: introduce libxl__vnuma_config_check Wei Liu
2014-12-01 15:33 ` [PATCH v2 08/19] libxl: x86: factor out e820_host_sanitize Wei Liu
2014-12-01 15:33 ` Wei Liu [this message]
2014-12-01 15:33 ` [PATCH v2 10/19] libxl: build, check and pass vNUMA info to Xen for PV guest Wei Liu
2014-12-01 15:33 ` [PATCH v2 11/19] xen: handle XENMEMF_get_vnumainfo in compat_memory_op Wei Liu
2014-12-09  9:09   ` Jan Beulich
2014-12-01 15:33 ` [PATCH v2 12/19] hvmloader: retrieve vNUMA information from hypervisor Wei Liu
2014-12-09 16:46   ` Jan Beulich
2014-12-09 17:52     ` Wei Liu
2014-12-10  8:19       ` Jan Beulich
2014-12-01 15:33 ` [PATCH v2 13/19] hvmloader: construct SRAT Wei Liu
2014-12-09 16:53   ` Jan Beulich
2014-12-09 18:06     ` Wei Liu
2014-12-10  8:20       ` Jan Beulich
2014-12-10 10:54         ` Wei Liu
2014-12-10 11:06           ` Jan Beulich
2014-12-10 11:10             ` Wei Liu
2014-12-01 15:33 ` [PATCH v2 14/19] hvmloader: construct SLIT Wei Liu
2014-12-09 16:57   ` Jan Beulich
2014-12-09 18:09     ` Wei Liu
2014-12-01 15:33 ` [PATCH v2 15/19] libxc: allocate memory with vNUMA information for HVM guest Wei Liu
2014-12-01 15:33 ` [PATCH v2 16/19] libxl: build, check and pass vNUMA info to Xen " Wei Liu
2014-12-01 15:33 ` [PATCH v2 17/19] libxl: disallow memory relocation when vNUMA is enabled Wei Liu
2014-12-01 15:33 ` [PATCH v2 18/19] libxlutil: nested list support Wei Liu
2014-12-01 15:33 ` [PATCH v2 19/19] xl: vNUMA support Wei Liu
2014-12-08  9:58 ` [PATCH v2 00/19] Virtual NUMA for PV and HVM Wei Liu
2014-12-08 10:19   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417448023-27311-10-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=dario.faggioli@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=ufimtseva@gmail.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.