From: Dario Faggioli <raistlin@linux.it>
To: xen-devel <xen-devel@lists.xensource.com>
Cc: "Ian.Campbell" <Ian.Campbell@eu.citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [PATCH 2 of 3] libxl: allow for specifying the CPU affinity in the config file.
Date: Wed, 11 Jan 2012 18:00:31 +0000 [thread overview]
Message-ID: <1326304831.12973.3.camel@Abyss> (raw)
In-Reply-To: <1326304198.2401.6.camel@Abyss>
[-- Attachment #1.1.1: Type: text/plain, Size: 4939 bytes --]
Enable CPU affinity specification in a VM's config file with the
exact syntax `xl vcpu-pin' provides.
Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
diff -r 9ce68a4036b1 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c Wed Jan 11 17:38:04 2012 +0000
+++ b/tools/libxl/libxl_create.c Wed Jan 11 17:40:45 2012 +0000
@@ -78,6 +78,8 @@ int libxl_init_build_info(libxl_ctx *ctx
memset(b_info, '\0', sizeof(*b_info));
b_info->max_vcpus = 1;
b_info->cur_vcpus = 1;
+ if (libxl_cpumap_alloc(ctx, &b_info->cpumap))
+ return ERROR_NOMEM;
b_info->max_memkb = 32 * 1024;
b_info->target_memkb = b_info->max_memkb;
b_info->disable_migrate = 0;
diff -r 9ce68a4036b1 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c Wed Jan 11 17:38:04 2012 +0000
+++ b/tools/libxl/libxl_dom.c Wed Jan 11 17:40:45 2012 +0000
@@ -72,8 +72,14 @@ int libxl__build_pre(libxl__gc *gc, uint
libxl_domain_build_info *info, libxl__domain_build_state *state)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
- int tsc_mode;
+ int i, tsc_mode;
xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
+ for (i = 0; i < info->max_vcpus; i++) {
+ if (libxl_set_vcpuaffinity(ctx, domid, i, &info->cpumap) == -1) {
+ LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "libxl_set_vcpuaffinity failed. "
+ "Going ahead without setting affinity for cpu %d.\n", i);
+ }
+ }
xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + LIBXL_MAXMEM_CONSTANT);
if (info->type == LIBXL_DOMAIN_TYPE_PV)
xc_domain_set_memmap_limit(ctx->xch, domid,
diff -r 9ce68a4036b1 tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl Wed Jan 11 17:38:04 2012 +0000
+++ b/tools/libxl/libxl_types.idl Wed Jan 11 17:40:45 2012 +0000
@@ -162,6 +162,7 @@ libxl_domain_create_info = Struct("domai
libxl_domain_build_info = Struct("domain_build_info",[
("max_vcpus", integer),
("cur_vcpus", integer),
+ ("cpumap", libxl_cpumap),
("tsc_mode", libxl_tsc_mode),
("max_memkb", uint32),
("target_memkb", uint32),
diff -r 9ce68a4036b1 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Wed Jan 11 17:38:04 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c Wed Jan 11 17:40:45 2012 +0000
@@ -288,16 +288,24 @@ static void dolog(const char *file, int
libxl_write_exactly(NULL, logfile, s, rc, NULL, NULL);
}
+static void print_bitmap(uint8_t *map, int maplen, FILE *stream);
+
static void printf_info(int domid,
libxl_domain_config *d_config,
libxl_device_model_info *dm_info)
{
- int i;
+ int i, nr_cpus = -1;
libxl_dominfo info;
+ libxl_physinfo physinfo;
libxl_domain_create_info *c_info = &d_config->c_info;
libxl_domain_build_info *b_info = &d_config->b_info;
+ if (libxl_get_physinfo(ctx, &physinfo) == 0)
+ nr_cpus = physinfo.nr_cpus;
+ else
+ fprintf(stderr, "libxl_physinfo failed.\n");
+
printf("(domain\n\t(domid %d)\n", domid);
printf("\t(create_info)\n");
printf("\t(hvm %d)\n", c_info->type == LIBXL_DOMAIN_TYPE_HVM);
@@ -328,6 +336,9 @@ static void printf_info(int domid,
printf("\t(build_info)\n");
printf("\t(max_vcpus %d)\n", b_info->max_vcpus);
+ printf("\t(CPU affinity ");
+ print_bitmap(b_info->cpumap.map, nr_cpus, stdout);
+ printf(")\n");
printf("\t(tsc_mode %s)\n", libxl_tsc_mode_to_string(b_info->tsc_mode));
printf("\t(max_memkb %d)\n", b_info->max_memkb);
printf("\t(target_memkb %d)\n", b_info->target_memkb);
@@ -569,6 +580,8 @@ static void split_string_into_string_lis
free(s);
}
+static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap);
+
static void parse_config_data(const char *configfile_filename_report,
const char *configfile_data,
int configfile_len,
@@ -661,6 +674,13 @@ static void parse_config_data(const char
if (!xlu_cfg_get_long (config, "maxvcpus", &l, 0))
b_info->max_vcpus = l;
+ if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
+ char *buf2 = strdup(buf);
+ vcpupin_parse(buf2, &b_info->cpumap);
+ } else {
+ memset(b_info->cpumap.map, -1, b_info->cpumap.size);
+ }
+
if (!xlu_cfg_get_long (config, "memory", &l, 0)) {
b_info->max_memkb = l * 1024;
b_info->target_memkb = b_info->max_memkb;
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-------------------------------------------------------------------
Dario Faggioli, http://retis.sssup.it/people/faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
PhD Candidate, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa (Italy)
[-- Attachment #1.1.2: support-cpus-par-in-config-file.patch --]
[-- Type: text/x-patch, Size: 4743 bytes --]
# HG changeset patch
# Parent 9ce68a4036b1a01b17ecf5db0bde5c114655ec0b
libxl: allow for specifying the CPU affinity in the config file.
Enable CPU affinity specification in a VM's config file with the
exact syntax `xl vcpu-pin' provides.
Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
diff -r 9ce68a4036b1 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c Wed Jan 11 17:38:04 2012 +0000
+++ b/tools/libxl/libxl_create.c Wed Jan 11 17:40:45 2012 +0000
@@ -78,6 +78,8 @@ int libxl_init_build_info(libxl_ctx *ctx
memset(b_info, '\0', sizeof(*b_info));
b_info->max_vcpus = 1;
b_info->cur_vcpus = 1;
+ if (libxl_cpumap_alloc(ctx, &b_info->cpumap))
+ return ERROR_NOMEM;
b_info->max_memkb = 32 * 1024;
b_info->target_memkb = b_info->max_memkb;
b_info->disable_migrate = 0;
diff -r 9ce68a4036b1 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c Wed Jan 11 17:38:04 2012 +0000
+++ b/tools/libxl/libxl_dom.c Wed Jan 11 17:40:45 2012 +0000
@@ -72,8 +72,14 @@ int libxl__build_pre(libxl__gc *gc, uint
libxl_domain_build_info *info, libxl__domain_build_state *state)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
- int tsc_mode;
+ int i, tsc_mode;
xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
+ for (i = 0; i < info->max_vcpus; i++) {
+ if (libxl_set_vcpuaffinity(ctx, domid, i, &info->cpumap) == -1) {
+ LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "libxl_set_vcpuaffinity failed. "
+ "Going ahead without setting affinity for cpu %d.\n", i);
+ }
+ }
xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + LIBXL_MAXMEM_CONSTANT);
if (info->type == LIBXL_DOMAIN_TYPE_PV)
xc_domain_set_memmap_limit(ctx->xch, domid,
diff -r 9ce68a4036b1 tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl Wed Jan 11 17:38:04 2012 +0000
+++ b/tools/libxl/libxl_types.idl Wed Jan 11 17:40:45 2012 +0000
@@ -162,6 +162,7 @@ libxl_domain_create_info = Struct("domai
libxl_domain_build_info = Struct("domain_build_info",[
("max_vcpus", integer),
("cur_vcpus", integer),
+ ("cpumap", libxl_cpumap),
("tsc_mode", libxl_tsc_mode),
("max_memkb", uint32),
("target_memkb", uint32),
diff -r 9ce68a4036b1 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Wed Jan 11 17:38:04 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c Wed Jan 11 17:40:45 2012 +0000
@@ -288,16 +288,24 @@ static void dolog(const char *file, int
libxl_write_exactly(NULL, logfile, s, rc, NULL, NULL);
}
+static void print_bitmap(uint8_t *map, int maplen, FILE *stream);
+
static void printf_info(int domid,
libxl_domain_config *d_config,
libxl_device_model_info *dm_info)
{
- int i;
+ int i, nr_cpus = -1;
libxl_dominfo info;
+ libxl_physinfo physinfo;
libxl_domain_create_info *c_info = &d_config->c_info;
libxl_domain_build_info *b_info = &d_config->b_info;
+ if (libxl_get_physinfo(ctx, &physinfo) == 0)
+ nr_cpus = physinfo.nr_cpus;
+ else
+ fprintf(stderr, "libxl_physinfo failed.\n");
+
printf("(domain\n\t(domid %d)\n", domid);
printf("\t(create_info)\n");
printf("\t(hvm %d)\n", c_info->type == LIBXL_DOMAIN_TYPE_HVM);
@@ -328,6 +336,9 @@ static void printf_info(int domid,
printf("\t(build_info)\n");
printf("\t(max_vcpus %d)\n", b_info->max_vcpus);
+ printf("\t(CPU affinity ");
+ print_bitmap(b_info->cpumap.map, nr_cpus, stdout);
+ printf(")\n");
printf("\t(tsc_mode %s)\n", libxl_tsc_mode_to_string(b_info->tsc_mode));
printf("\t(max_memkb %d)\n", b_info->max_memkb);
printf("\t(target_memkb %d)\n", b_info->target_memkb);
@@ -569,6 +580,8 @@ static void split_string_into_string_lis
free(s);
}
+static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap);
+
static void parse_config_data(const char *configfile_filename_report,
const char *configfile_data,
int configfile_len,
@@ -661,6 +674,13 @@ static void parse_config_data(const char
if (!xlu_cfg_get_long (config, "maxvcpus", &l, 0))
b_info->max_vcpus = l;
+ if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
+ char *buf2 = strdup(buf);
+ vcpupin_parse(buf2, &b_info->cpumap);
+ } else {
+ memset(b_info->cpumap.map, -1, b_info->cpumap.size);
+ }
+
if (!xlu_cfg_get_long (config, "memory", &l, 0)) {
b_info->max_memkb = l * 1024;
b_info->target_memkb = b_info->max_memkb;
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
[-- Attachment #2: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2012-01-11 18:00 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-11 17:49 [PATCH 0 of 3] libxl: Extend CPU affinity specification and enable it in config file Dario Faggioli
2012-01-11 17:58 ` [PATCH 1 of 3] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
2012-01-12 8:38 ` Ian Campbell
2012-01-12 17:34 ` Ian Jackson
2012-01-12 23:12 ` Dario Faggioli
2012-01-13 13:34 ` Ian Jackson
2012-01-13 16:45 ` Dario Faggioli
2012-01-13 16:48 ` Ian Jackson
2012-01-23 10:21 ` Ian Campbell
2012-01-23 10:27 ` Dario Faggioli
2012-01-23 10:50 ` Ian Campbell
2012-01-11 18:00 ` Dario Faggioli [this message]
2012-01-12 8:43 ` [PATCH 2 of 3] libxl: allow for specifying the CPU affinity in the config file Ian Campbell
2012-01-12 22:56 ` Dario Faggioli
2012-01-13 8:09 ` Ian Campbell
2012-01-13 9:13 ` Dario Faggioli
2012-01-11 18:01 ` [PATCH 3 of 3] libxl: Align examples with current code Dario Faggioli
2012-01-12 8:37 ` Ian Campbell
2012-01-12 22:45 ` Dario Faggioli
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=1326304831.12973.3.camel@Abyss \
--to=raistlin@linux.it \
--cc=Ian.Campbell@eu.citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/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.