From: Elena Ufimtseva <ufimtseva@gmail.com>
To: xen-devel@lists.xen.org
Cc: keir@xen.org, Ian.Campbell@citrix.com,
stefano.stabellini@eu.citrix.com, george.dunlap@eu.citrix.com,
msw@linux.com, dario.faggioli@citrix.com, lccycc123@gmail.com,
ian.jackson@eu.citrix.com, JBeulich@suse.com,
Elena Ufimtseva <ufimtseva@gmail.com>
Subject: [PATCH v6 09/10] libxl: vnuma nodes placement bits
Date: Fri, 18 Jul 2014 01:50:08 -0400 [thread overview]
Message-ID: <1405662609-31486-10-git-send-email-ufimtseva@gmail.com> (raw)
In-Reply-To: <1405662609-31486-1-git-send-email-ufimtseva@gmail.com>
Automatic numa placement cancels manual vnode placement
mechanism. If numa placement explicitly specified, try
to fit vnodes to the physical nodes.
Signed-off-by: Elena Ufimtseva <ufimtseva@gmail.com>
---
tools/libxl/libxl_create.c | 1 +
tools/libxl/libxl_dom.c | 148 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 149 insertions(+)
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 0686f96..038f96e 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -188,6 +188,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
return ERROR_FAIL;
libxl_defbool_setdefault(&b_info->numa_placement, true);
+ libxl_defbool_setdefault(&b_info->vnuma_autoplacement, true);
if (b_info->max_memkb == LIBXL_MEMKB_DEFAULT)
b_info->max_memkb = 32 * 1024;
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 83eb29a..98e42b3 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -23,6 +23,7 @@
#include <xc_dom.h>
#include <xen/hvm/hvm_info_table.h>
#include <xen/hvm/hvm_xs_strings.h>
+#include <libxl_vnuma.h>
libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid)
{
@@ -227,6 +228,61 @@ static void hvm_set_conf_params(xc_interface *handle, uint32_t domid,
libxl_defbool_val(info->u.hvm.nested_hvm));
}
+/* sets vnode_to_pnode map. */
+static int libxl__init_vnode_to_pnode(libxl__gc *gc, uint32_t domid,
+ libxl_domain_build_info *info)
+{
+ unsigned int i, n;
+ int nr_nodes = 0;
+ uint64_t *vnodes_mem;
+ unsigned long long *nodes_claim = NULL;
+ libxl_numainfo *ninfo = NULL;
+
+ if (info->vnuma_vnodemap == NULL) {
+ info->vnuma_vnodemap = libxl__calloc(gc, info->nr_nodes,
+ sizeof(*info->vnuma_vnodemap));
+ }
+
+ /* default setting. */
+ for (i = 0; i < info->nr_nodes; i++)
+ info->vnuma_vnodemap[i] = VNUMA_NO_NODE;
+
+ /* Get NUMA info. */
+ ninfo = libxl_get_numainfo(CTX, &nr_nodes);
+ if (ninfo == NULL)
+ return ERROR_FAIL;
+ /* Nothing to see if only one NUMA node. */
+ if (nr_nodes <= 1)
+ return 0;
+
+ vnodes_mem = info->vnuma_mem;
+ /*
+ * TODO: change algorithm. The current just fits the nodes
+ * by its memory sizes. If no p-node found, will be used default
+ * value of NUMA_NO_NODE.
+ */
+ nodes_claim = libxl__calloc(gc, info->nr_nodes, sizeof(*nodes_claim));
+ if ( !nodes_claim )
+ return ERROR_FAIL;
+
+ libxl_for_each_set_bit(n, info->nodemap)
+ {
+ for (i = 0; i < info->nr_nodes; i++)
+ {
+ unsigned long mem_sz = vnodes_mem[i] << 20;
+ if ((nodes_claim[n] + mem_sz <= ninfo[n].free) &&
+ /* vnode was not set yet. */
+ (info->vnuma_vnodemap[i] == VNUMA_NO_NODE ) )
+ {
+ info->vnuma_vnodemap[i] = n;
+ nodes_claim[n] += mem_sz;
+ }
+ }
+ }
+
+ return 0;
+}
+
int libxl__build_pre(libxl__gc *gc, uint32_t domid,
libxl_domain_config *d_config, libxl__domain_build_state *state)
{
@@ -240,6 +296,21 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
return ERROR_FAIL;
}
+ struct vmemrange *memrange = libxl__calloc(gc, info->nr_nodes,
+ sizeof(*memrange));
+ if (libxl__vnuma_align_mem(gc, domid, info, memrange) < 0) {
+ LOG(DETAIL, "Failed to align memory map.\n");
+ return ERROR_FAIL;
+ }
+
+ /*
+ * NUMA placement and vNUMA autoplacement handling:
+ * If numa_placement is set to default, do not use vnode to pnode
+ * mapping as automatic placement algorithm will find best numa nodes.
+ * If numa_placement is not used, we can try and use domain vnode
+ * to pnode mask.
+ */
+
/*
* Check if the domain has any CPU or node affinity already. If not, try
* to build up the latter via automatic NUMA placement. In fact, in case
@@ -268,7 +339,33 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
rc = numa_place_domain(gc, domid, info);
if (rc)
return rc;
+
+ /*
+ * If vnode_to_pnode mask was defined, dont use it if we automatically
+ * place domain on NUMA nodes, just give warning.
+ */
+ if (!libxl_defbool_val(info->vnuma_autoplacement)) {
+ LOG(INFO, "Automatic NUMA placement for domain is turned on. \
+ vnode to physical nodes mapping will not be used.");
+ }
+ if (libxl__init_vnode_to_pnode(gc, domid, info) < 0) {
+ LOG(ERROR, "Failed to build vnode to pnode map\n");
+ return ERROR_FAIL;
+ }
+ } else {
+ if (!libxl_defbool_val(info->vnuma_autoplacement)) {
+ if (!libxl__vnodemap_is_usable(gc, info)) {
+ LOG(ERROR, "Defined vnode to pnode domain map cannot be used.\n");
+ return ERROR_FAIL;
+ }
+ } else {
+ if (libxl__init_vnode_to_pnode(gc, domid, info) < 0) {
+ LOG(ERROR, "Failed to build vnode to pnode map.\n");
+ return ERROR_FAIL;
+ }
+ }
}
+
if (info->nodemap.size)
libxl_domain_set_nodeaffinity(ctx, domid, &info->nodemap);
/* As mentioned in libxl.h, vcpu_hard_array takes precedence */
@@ -294,6 +391,19 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
return ERROR_FAIL;
}
+ /*
+ * XEN_DOMCTL_setvnuma subop hypercall needs to know max mem
+ * for domain set by xc_domain_setmaxmem. So set vNUMA after
+ * maxmem is being set.
+ */
+ if (xc_domain_setvnuma(ctx->xch, domid, info->nr_nodes,
+ info->max_vcpus, memrange,
+ info->vdistance, info->vnuma_vcpumap,
+ info->vnuma_vnodemap) < 0) {
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't set vnuma topology");
+ return ERROR_FAIL;
+ }
+
xs_domid = xs_read(ctx->xsh, XBT_NULL, "/tool/xenstored/domid", NULL);
state->store_domid = xs_domid ? atoi(xs_domid) : 0;
free(xs_domid);
@@ -389,6 +499,39 @@ retry_transaction:
return 0;
}
+static int libxl__dom_vnuma_init(struct libxl_domain_build_info *info,
+ struct xc_dom_image *dom)
+{
+ errno = ERROR_INVAL;
+
+ if (info->nr_nodes == 0)
+ return -1;
+
+ dom->vnode_to_pnode = (unsigned int *)malloc(
+ info->nr_nodes * sizeof(*info->vnuma_vnodemap));
+ dom->numa_memszs = (uint64_t *)malloc(
+ info->nr_nodes * sizeof(*info->vnuma_mem));
+
+ errno = ERROR_FAIL;
+ if ( dom->numa_memszs == NULL || dom->vnode_to_pnode == NULL ) {
+ info->nr_nodes = 0;
+ if (dom->vnode_to_pnode)
+ free(dom->vnode_to_pnode);
+ if (dom->numa_memszs)
+ free(dom->numa_memszs);
+ return -1;
+ }
+
+ memcpy(dom->numa_memszs, info->vnuma_mem,
+ sizeof(*info->vnuma_mem) * info->nr_nodes);
+ memcpy(dom->vnode_to_pnode, info->vnuma_vnodemap,
+ sizeof(*info->vnuma_vnodemap) * info->nr_nodes);
+
+ dom->nr_nodes = info->nr_nodes;
+
+ return 0;
+}
+
int libxl__build_pv(libxl__gc *gc, uint32_t domid,
libxl_domain_build_info *info, libxl__domain_build_state *state)
{
@@ -446,6 +589,11 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
dom->xenstore_domid = state->store_domid;
dom->claim_enabled = libxl_defbool_val(info->claim_mode);
+ if ( (ret = libxl__dom_vnuma_init(info, dom)) != 0 ) {
+ LOGE(ERROR, "Failed to set doman vnuma");
+ goto out;
+ }
+
if ( (ret = xc_dom_boot_xen_init(dom, ctx->xch, domid)) != 0 ) {
LOGE(ERROR, "xc_dom_boot_xen_init failed");
goto out;
--
1.7.10.4
next prev parent reply other threads:[~2014-07-18 5:50 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-18 5:49 [PATCH v6 00/10] vnuma introduction Elena Ufimtseva
2014-07-18 5:50 ` [PATCH v6 01/10] xen: vnuma topology and subop hypercalls Elena Ufimtseva
2014-07-18 10:30 ` Wei Liu
2014-07-20 13:16 ` Elena Ufimtseva
2014-07-20 15:59 ` Wei Liu
2014-07-22 15:18 ` Dario Faggioli
2014-07-23 5:33 ` Elena Ufimtseva
2014-07-18 13:49 ` Konrad Rzeszutek Wilk
2014-07-20 13:26 ` Elena Ufimtseva
2014-07-22 15:14 ` Dario Faggioli
2014-07-23 5:22 ` Elena Ufimtseva
2014-07-23 14:06 ` Jan Beulich
2014-07-25 4:52 ` Elena Ufimtseva
2014-07-25 7:33 ` Jan Beulich
2014-07-18 5:50 ` [PATCH v6 02/10] xsm bits for vNUMA hypercalls Elena Ufimtseva
2014-07-18 13:50 ` Konrad Rzeszutek Wilk
2014-07-18 15:26 ` Daniel De Graaf
2014-07-20 13:48 ` Elena Ufimtseva
2014-07-18 5:50 ` [PATCH v6 03/10] vnuma hook to debug-keys u Elena Ufimtseva
2014-07-23 14:10 ` Jan Beulich
2014-07-18 5:50 ` [PATCH v6 04/10] libxc: Introduce xc_domain_setvnuma to set vNUMA Elena Ufimtseva
2014-07-18 10:33 ` Wei Liu
2014-07-29 10:33 ` Ian Campbell
2014-07-18 5:50 ` [PATCH v6 05/10] libxl: vnuma topology configuration parser and doc Elena Ufimtseva
2014-07-18 10:53 ` Wei Liu
2014-07-20 14:04 ` Elena Ufimtseva
2014-07-29 10:38 ` Ian Campbell
2014-07-29 10:42 ` Ian Campbell
2014-08-06 4:46 ` Elena Ufimtseva
2014-07-18 5:50 ` [PATCH v6 06/10] libxc: move code to arch_boot_alloc func Elena Ufimtseva
2014-07-29 10:38 ` Ian Campbell
2014-07-18 5:50 ` [PATCH v6 07/10] libxc: allocate domain memory for vnuma enabled Elena Ufimtseva
2014-07-29 10:43 ` Ian Campbell
2014-08-06 4:48 ` Elena Ufimtseva
2014-07-18 5:50 ` [PATCH v6 08/10] libxl: build numa nodes memory blocks Elena Ufimtseva
2014-07-18 11:01 ` Wei Liu
2014-07-20 12:58 ` Elena Ufimtseva
2014-07-20 15:59 ` Wei Liu
2014-07-18 5:50 ` Elena Ufimtseva [this message]
2014-07-18 5:50 ` [PATCH v6 10/10] libxl: set vnuma for domain Elena Ufimtseva
2014-07-18 10:58 ` Wei Liu
2014-07-29 10:45 ` Ian Campbell
2014-08-12 3:52 ` Elena Ufimtseva
2014-08-12 9:42 ` Wei Liu
2014-08-12 17:10 ` Dario Faggioli
2014-08-12 17:13 ` Wei Liu
2014-08-12 17:24 ` Elena Ufimtseva
2014-07-18 6:16 ` [PATCH v6 00/10] vnuma introduction Elena Ufimtseva
2014-07-18 9:53 ` Wei Liu
2014-07-18 10:13 ` Dario Faggioli
2014-07-18 11:48 ` Wei Liu
2014-07-20 14:57 ` Elena Ufimtseva
2014-07-22 15:49 ` Dario Faggioli
2014-07-22 14:03 ` Dario Faggioli
2014-07-22 14:48 ` Wei Liu
2014-07-22 15:06 ` Dario Faggioli
2014-07-22 16:47 ` Wei Liu
2014-07-22 19:43 ` Is: cpuid creation of PV guests is not correct. Was:Re: " Konrad Rzeszutek Wilk
2014-07-22 22:34 ` Is: cpuid creation of PV guests is not correct Andrew Cooper
2014-07-22 22:53 ` Is: cpuid creation of PV guests is not correct. Was:Re: [PATCH v6 00/10] vnuma introduction Dario Faggioli
2014-07-23 6:00 ` Elena Ufimtseva
2014-07-22 12:49 ` Dario Faggioli
2014-07-23 5:59 ` Elena Ufimtseva
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=1405662609-31486-10-git-send-email-ufimtseva@gmail.com \
--to=ufimtseva@gmail.com \
--cc=Ian.Campbell@citrix.com \
--cc=JBeulich@suse.com \
--cc=dario.faggioli@citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=keir@xen.org \
--cc=lccycc123@gmail.com \
--cc=msw@linux.com \
--cc=stefano.stabellini@eu.citrix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).