xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file.
@ 2012-01-25 14:15 Dario Faggioli
  2012-01-25 14:35 ` [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Dario Faggioli @ 2012-01-25 14:15 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian.Campbell, George Dunlap, Juergen Gross, Ian Jackson


[-- Attachment #1.1: Type: text/plain, Size: 1619 bytes --]

Hello Everyone,

This series slightly extends the current support for specifying CPU
affinity, basically adding the support for "^<cpuid>" kind of entries
(i.e., "^6", meaning "not on CPU#6), and enables doing so in a VM's
config file, like it (probably?) was possible with `xm'.

With respect to v1:
* Syntax made even more general, now "0-4,^1-2" is supported
* Avoid touching printf_info (dryrun case of domain creation)
* Remove another fwd decl that survived to the last round

With respect to v1:
* Reworked (hopefully improved) the parsing of the cpu-pin string
* Removed forward declarations (as asked during review)
* Added some helper functions (as asked during review)
* Put a saner default for cpu-pinning for libxl (as asked during review)

Regards,
Dario

--
generalize-vcpupin-parsig.patch
support-cpus-par-in-config-file.patch
-- 
tools/libxl/libxl.c         |   15 +++++++++++++++
 tools/libxl/libxl.h         |    2 ++
 tools/libxl/libxl_create.c  |    3 +++
 tools/libxl/libxl_dom.c     |    1 +
 tools/libxl/libxl_types.idl |    1 +
 tools/libxl/libxl_utils.h   |   14 ++++++++++++++
 tools/libxl/xl_cmdimpl.c    |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
 7 files changed, 124 insertions(+), 29 deletions(-)

-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-------------------------------------------------------------------
Dario Faggioli, Ph.D, http://retis.sssup.it/people/faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)



[-- 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin.
  2012-01-25 14:15 [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file Dario Faggioli
@ 2012-01-25 14:35 ` Dario Faggioli
  2012-01-25 14:43   ` Ian Campbell
  2012-01-25 14:36 ` [PATCHv3 1 of 2] libxl: allow for specifying the CPU affinity in the config file Dario Faggioli
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Dario Faggioli @ 2012-01-25 14:35 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian.Campbell, George Dunlap, Juergen Gross, Ian Jackson


[-- Attachment #1.1: Type: text/plain, Size: 5117 bytes --]

Allow for "^<cpuid>" syntax while specifying the pCPUs list
during a vcpu-pin. This enables doing the following:

 xl vcpu-pin 1 1 0-4,^2

and achieving:

 xl vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 ...
 Squeeze_pv                           1     1    3   -b-       2.4  0-1,3-4
 ...

Negative ranges are also supported, such as "0-4,^1-2" to
mean "0,3-4"

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>

diff -r a2a8089b1ffb tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Tue Jan 24 16:46:17 2012 +0000
+++ b/tools/libxl/libxl_utils.h	Wed Jan 25 11:40:22 2012 +0000
@@ -71,6 +71,8 @@ int libxl_cpumap_test(libxl_cpumap *cpum
 void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
 #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
+#define libxl_for_each_set_cpu(v, m) for (v = 0; v < (m).size * 8; v++) \
+                                             if (libxl_cpumap_test(&(m), v))
 
 int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray);
 
diff -r a2a8089b1ffb tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Tue Jan 24 16:46:17 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 25 11:40:22 2012 +0000
@@ -3503,13 +3503,72 @@ int main_vcpulist(int argc, char **argv)
     return 0;
 }
 
+static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
+{
+    libxl_cpumap exclude_cpumap;
+    uint32_t cpuida, cpuidb;
+    char *endptr, *toka, *tokb, *saveptr = NULL;
+    int i, rc = 0, rmcpu;
+
+    if (!strcmp(cpu, "all")) {
+        memset(cpumap->map, -1, cpumap->size);
+        return 0;
+    }
+
+    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
+        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
+        return ENOMEM;
+    }
+
+    for (toka = strtok_r(cpu, ",", &saveptr); toka;
+         toka = strtok_r(NULL, ",", &saveptr)) {
+        rmcpu = 0;
+        if (*toka == '^') {
+            /* This (These) Cpu(s) will be removed from the map */
+            toka++;
+            rmcpu = 1;
+        }
+        /* Extract a valid (range of) cpu(s) */
+        cpuida = cpuidb = strtoul(toka, &endptr, 10);
+        if (endptr == toka) {
+            fprintf(stderr, "Error: Invalid argument.\n");
+            rc = EINVAL;
+            goto vcpp_out;
+        }
+        if (*endptr == '-') {
+            tokb = endptr + 1;
+            cpuidb = strtoul(tokb, &endptr, 10);
+            if (endptr == tokb || cpuida > cpuidb) {
+                fprintf(stderr, "Error: Invalid argument.\n");
+                rc = EINVAL;
+                goto vcpp_out;
+            }
+        }
+        while (cpuida <= cpuidb) {
+            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
+                         libxl_cpumap_set(&exclude_cpumap, cpuida);
+            cpuida++;
+        }
+    }
+
+    /* Clear all the cpus from the removal list */
+    libxl_for_each_set_cpu(i, exclude_cpumap) {
+        libxl_cpumap_reset(cpumap, i);
+    }
+
+vcpp_out:
+    libxl_cpumap_dispose(&exclude_cpumap);
+
+    return rc;
+}
+
 static void vcpupin(const char *d, const char *vcpu, char *cpu)
 {
     libxl_vcpuinfo *vcpuinfo;
     libxl_cpumap cpumap;
 
-    uint32_t vcpuid, cpuida, cpuidb;
-    char *endptr, *toka, *tokb;
+    uint32_t vcpuid;
+    char *endptr;
     int i, nb_vcpu;
 
     vcpuid = strtoul(vcpu, &endptr, 10);
@@ -3526,32 +3585,9 @@ static void vcpupin(const char *d, const
     if (libxl_cpumap_alloc(ctx, &cpumap)) {
         goto vcpupin_out;
     }
-    if (strcmp(cpu, "all")) {
-        for (toka = strtok(cpu, ","), i = 0; toka; toka = strtok(NULL, ","), ++i) {
-            cpuida = strtoul(toka, &endptr, 10);
-            if (toka == endptr) {
-                fprintf(stderr, "Error: Invalid argument.\n");
-                goto vcpupin_out1;
-            }
-            if (*endptr == '-') {
-                tokb = endptr + 1;
-                cpuidb = strtoul(tokb, &endptr, 10);
-                if ((tokb == endptr) || (cpuida > cpuidb)) {
-                    fprintf(stderr, "Error: Invalid argument.\n");
-                    goto vcpupin_out1;
-                }
-                while (cpuida <= cpuidb) {
-                    libxl_cpumap_set(&cpumap, cpuida);
-                    ++cpuida;
-                }
-            } else {
-                libxl_cpumap_set(&cpumap, cpuida);
-            }
-        }
-    }
-    else {
-        memset(cpumap.map, -1, cpumap.size);
-    }
+
+    if (vcpupin_parse(cpu, &cpumap))
+        goto vcpupin_out1;
 
     if (vcpuid != -1) {
         if (libxl_set_vcpuaffinity(ctx, domid, vcpuid, &cpumap) == -1) {

-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-------------------------------------------------------------------
Dario Faggioli, Ph.D, http://retis.sssup.it/people/faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)



[-- 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCHv3 1 of 2] libxl: allow for specifying the CPU affinity in the config file.
  2012-01-25 14:15 [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file Dario Faggioli
  2012-01-25 14:35 ` [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
@ 2012-01-25 14:36 ` Dario Faggioli
  2012-01-25 14:45   ` Ian Campbell
  2012-01-25 14:37 ` [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
  2012-01-27 19:18 ` [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file Ian Jackson
  3 siblings, 1 reply; 7+ messages in thread
From: Dario Faggioli @ 2012-01-25 14:36 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian.Campbell, George Dunlap, Juergen Gross, Ian Jackson


[-- Attachment #1.1.1: Type: text/plain, Size: 10344 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 e4fd5305381e tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl.c	Wed Jan 25 14:08:21 2012 +0000
@@ -2663,6 +2663,21 @@ int libxl_set_vcpuaffinity(libxl_ctx *ct
     return 0;
 }
 
+int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
+                               unsigned int max_vcpus, libxl_cpumap *cpumap)
+{
+    int i, rc = 0;
+
+    for (i = 0; i < max_vcpus; i++) {
+        if (libxl_set_vcpuaffinity(ctx, domid, i, cpumap)) {
+            LIBXL__LOG(ctx, LIBXL__LOG_WARNING,
+                       "failed to set affinity for %d", i);
+            rc = ERROR_FAIL;
+        }
+    }
+    return rc;
+}
+
 int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap)
 {
     GC_INIT(ctx);
diff -r e4fd5305381e tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl.h	Wed Jan 25 14:08:21 2012 +0000
@@ -560,6 +560,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
                                        int *nb_vcpu, int *nrcpus);
 int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
                            libxl_cpumap *cpumap);
+int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
+                               unsigned int max_vcpus, libxl_cpumap *cpumap);
 int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap);
 
 int libxl_get_sched_id(libxl_ctx *ctx);
diff -r e4fd5305381e tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl_create.c	Wed Jan 25 14:08:21 2012 +0000
@@ -71,6 +71,9 @@ 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;
+    libxl_cpumap_set_any(&b_info->cpumap);
     b_info->max_memkb = 32 * 1024;
     b_info->target_memkb = b_info->max_memkb;
     b_info->disable_migrate = 0;
diff -r e4fd5305381e tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl_dom.c	Wed Jan 25 14:08:21 2012 +0000
@@ -65,6 +65,7 @@ int libxl__build_pre(libxl__gc *gc, uint
     libxl_ctx *ctx = libxl__gc_owner(gc);
     int tsc_mode;
     xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
+    libxl_set_vcpuaffinity_all(ctx, domid, info->max_vcpus, &info->cpumap);
     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 e4fd5305381e tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl_types.idl	Wed Jan 25 14:08:21 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 e4fd5305381e tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl_utils.h	Wed Jan 25 14:08:21 2012 +0000
@@ -70,6 +70,18 @@ int libxl_cpumap_alloc(libxl_ctx *ctx, l
 int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
+static inline void libxl_cpumap_set_any(libxl_cpumap *cpumap)
+{
+    memset(cpumap->map, -1, cpumap->size);
+}
+static inline void libxl_cpumap_set_none(libxl_cpumap *cpumap)
+{
+    memset(cpumap->map, 0, cpumap->size);
+}
+static inline int libxl_cpumap_cpu_valid(libxl_cpumap *cpumap, int cpu)
+{
+    return cpu >= 0 && cpu < (cpumap->size * 8);
+}
 #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
 #define libxl_for_each_set_cpu(v, m) for (v = 0; v < (m).size * 8; v++) \
                                              if (libxl_cpumap_test(&(m), v))
diff -r e4fd5305381e tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 25 14:08:21 2012 +0000
@@ -569,6 +569,65 @@ static void split_string_into_string_lis
     free(s);
 }
 
+static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
+{
+    libxl_cpumap exclude_cpumap;
+    uint32_t cpuida, cpuidb;
+    char *endptr, *toka, *tokb, *saveptr = NULL;
+    int i, rc = 0, rmcpu;
+
+    if (!strcmp(cpu, "all")) {
+        libxl_cpumap_set_any(cpumap);
+        return 0;
+    }
+
+    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
+        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
+        return ENOMEM;
+    }
+
+    for (toka = strtok_r(cpu, ",", &saveptr); toka;
+         toka = strtok_r(NULL, ",", &saveptr)) {
+        rmcpu = 0;
+        if (*toka == '^') {
+            /* This (These) Cpu(s) will be removed from the map */
+            toka++;
+            rmcpu = 1;
+        }
+        /* Extract a valid (range of) cpu(s) */
+        cpuida = cpuidb = strtoul(toka, &endptr, 10);
+        if (endptr == toka) {
+            fprintf(stderr, "Error: Invalid argument.\n");
+            rc = EINVAL;
+            goto vcpp_out;
+        }
+        if (*endptr == '-') {
+            tokb = endptr + 1;
+            cpuidb = strtoul(tokb, &endptr, 10);
+            if (endptr == tokb || cpuida > cpuidb) {
+                fprintf(stderr, "Error: Invalid argument.\n");
+                rc = EINVAL;
+                goto vcpp_out;
+            }
+        }
+        while (cpuida <= cpuidb) {
+            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
+                         libxl_cpumap_set(&exclude_cpumap, cpuida);
+            cpuida++;
+        }
+    }
+
+    /* Clear all the cpus from the removal list */
+    libxl_for_each_set_cpu(i, exclude_cpumap) {
+        libxl_cpumap_reset(cpumap, i);
+    }
+
+vcpp_out:
+    libxl_cpumap_dispose(&exclude_cpumap);
+
+    return rc;
+}
+
 static void parse_config_data(const char *configfile_filename_report,
                               const char *configfile_data,
                               int configfile_len,
@@ -578,7 +637,7 @@ static void parse_config_data(const char
     const char *buf;
     long l;
     XLU_Config *config;
-    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *cpuids;
+    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids;
     int pci_power_mgmt = 0;
     int pci_msitranslate = 1;
     int e;
@@ -661,6 +720,29 @@ 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_list (config, "cpus", &cpus, 0, 1)) {
+        int i, n_cpus = 0;
+
+        libxl_cpumap_set_none(&b_info->cpumap);
+        while ((buf = xlu_cfg_get_listitem(cpus, n_cpus)) != NULL) {
+            i = atoi(buf);
+            if (!libxl_cpumap_cpu_valid(&b_info->cpumap, i)) {
+                fprintf(stderr, "cpu %d illegal\n", i);
+                exit(1);
+            }
+            libxl_cpumap_set(&b_info->cpumap, i);
+            n_cpus++;
+        }
+    }
+    else if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
+        char *buf2 = strdup(buf);
+
+        libxl_cpumap_set_none(&b_info->cpumap);
+        if (vcpupin_parse(buf2, &b_info->cpumap))
+            exit(1);
+        free(buf2);
+    }
+
     if (!xlu_cfg_get_long (config, "memory", &l, 0)) {
         b_info->max_memkb = l * 1024;
         b_info->target_memkb = b_info->max_memkb;
@@ -3503,65 +3585,6 @@ int main_vcpulist(int argc, char **argv)
     return 0;
 }
 
-static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
-{
-    libxl_cpumap exclude_cpumap;
-    uint32_t cpuida, cpuidb;
-    char *endptr, *toka, *tokb, *saveptr = NULL;
-    int i, rc = 0, rmcpu;
-
-    if (!strcmp(cpu, "all")) {
-        memset(cpumap->map, -1, cpumap->size);
-        return 0;
-    }
-
-    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
-        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
-        return ENOMEM;
-    }
-
-    for (toka = strtok_r(cpu, ",", &saveptr); toka;
-         toka = strtok_r(NULL, ",", &saveptr)) {
-        rmcpu = 0;
-        if (*toka == '^') {
-            /* This (These) Cpu(s) will be removed from the map */
-            toka++;
-            rmcpu = 1;
-        }
-        /* Extract a valid (range of) cpu(s) */
-        cpuida = cpuidb = strtoul(toka, &endptr, 10);
-        if (endptr == toka) {
-            fprintf(stderr, "Error: Invalid argument.\n");
-            rc = EINVAL;
-            goto vcpp_out;
-        }
-        if (*endptr == '-') {
-            tokb = endptr + 1;
-            cpuidb = strtoul(tokb, &endptr, 10);
-            if (endptr == tokb || cpuida > cpuidb) {
-                fprintf(stderr, "Error: Invalid argument.\n");
-                rc = EINVAL;
-                goto vcpp_out;
-            }
-        }
-        while (cpuida <= cpuidb) {
-            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
-                         libxl_cpumap_set(&exclude_cpumap, cpuida);
-            cpuida++;
-        }
-    }
-
-    /* Clear all the cpus from the removal list */
-    libxl_for_each_set_cpu(i, exclude_cpumap) {
-        libxl_cpumap_reset(cpumap, i);
-    }
-
-vcpp_out:
-    libxl_cpumap_dispose(&exclude_cpumap);
-
-    return rc;
-}
-
 static void vcpupin(const char *d, const char *vcpu, char *cpu)
 {
     libxl_vcpuinfo *vcpuinfo;

-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-------------------------------------------------------------------
Dario Faggioli, Ph.D, http://retis.sssup.it/people/faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)



[-- Attachment #1.1.2: support-cpus-par-in-config-file.patch --]
[-- Type: text/x-patch, Size: 10210 bytes --]

# HG changeset patch
# Parent e4fd5305381e63af968fba07e5b49dd321d084dc
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 e4fd5305381e tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl.c	Wed Jan 25 14:08:21 2012 +0000
@@ -2663,6 +2663,21 @@ int libxl_set_vcpuaffinity(libxl_ctx *ct
     return 0;
 }
 
+int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
+                               unsigned int max_vcpus, libxl_cpumap *cpumap)
+{
+    int i, rc = 0;
+
+    for (i = 0; i < max_vcpus; i++) {
+        if (libxl_set_vcpuaffinity(ctx, domid, i, cpumap)) {
+            LIBXL__LOG(ctx, LIBXL__LOG_WARNING,
+                       "failed to set affinity for %d", i);
+            rc = ERROR_FAIL;
+        }
+    }
+    return rc;
+}
+
 int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap)
 {
     GC_INIT(ctx);
diff -r e4fd5305381e tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl.h	Wed Jan 25 14:08:21 2012 +0000
@@ -560,6 +560,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
                                        int *nb_vcpu, int *nrcpus);
 int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
                            libxl_cpumap *cpumap);
+int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
+                               unsigned int max_vcpus, libxl_cpumap *cpumap);
 int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap);
 
 int libxl_get_sched_id(libxl_ctx *ctx);
diff -r e4fd5305381e tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl_create.c	Wed Jan 25 14:08:21 2012 +0000
@@ -71,6 +71,9 @@ 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;
+    libxl_cpumap_set_any(&b_info->cpumap);
     b_info->max_memkb = 32 * 1024;
     b_info->target_memkb = b_info->max_memkb;
     b_info->disable_migrate = 0;
diff -r e4fd5305381e tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl_dom.c	Wed Jan 25 14:08:21 2012 +0000
@@ -65,6 +65,7 @@ int libxl__build_pre(libxl__gc *gc, uint
     libxl_ctx *ctx = libxl__gc_owner(gc);
     int tsc_mode;
     xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
+    libxl_set_vcpuaffinity_all(ctx, domid, info->max_vcpus, &info->cpumap);
     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 e4fd5305381e tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl_types.idl	Wed Jan 25 14:08:21 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 e4fd5305381e tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/libxl_utils.h	Wed Jan 25 14:08:21 2012 +0000
@@ -70,6 +70,18 @@ int libxl_cpumap_alloc(libxl_ctx *ctx, l
 int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
+static inline void libxl_cpumap_set_any(libxl_cpumap *cpumap)
+{
+    memset(cpumap->map, -1, cpumap->size);
+}
+static inline void libxl_cpumap_set_none(libxl_cpumap *cpumap)
+{
+    memset(cpumap->map, 0, cpumap->size);
+}
+static inline int libxl_cpumap_cpu_valid(libxl_cpumap *cpumap, int cpu)
+{
+    return cpu >= 0 && cpu < (cpumap->size * 8);
+}
 #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
 #define libxl_for_each_set_cpu(v, m) for (v = 0; v < (m).size * 8; v++) \
                                              if (libxl_cpumap_test(&(m), v))
diff -r e4fd5305381e tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Wed Jan 25 11:40:23 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 25 14:08:21 2012 +0000
@@ -569,6 +569,65 @@ static void split_string_into_string_lis
     free(s);
 }
 
+static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
+{
+    libxl_cpumap exclude_cpumap;
+    uint32_t cpuida, cpuidb;
+    char *endptr, *toka, *tokb, *saveptr = NULL;
+    int i, rc = 0, rmcpu;
+
+    if (!strcmp(cpu, "all")) {
+        libxl_cpumap_set_any(cpumap);
+        return 0;
+    }
+
+    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
+        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
+        return ENOMEM;
+    }
+
+    for (toka = strtok_r(cpu, ",", &saveptr); toka;
+         toka = strtok_r(NULL, ",", &saveptr)) {
+        rmcpu = 0;
+        if (*toka == '^') {
+            /* This (These) Cpu(s) will be removed from the map */
+            toka++;
+            rmcpu = 1;
+        }
+        /* Extract a valid (range of) cpu(s) */
+        cpuida = cpuidb = strtoul(toka, &endptr, 10);
+        if (endptr == toka) {
+            fprintf(stderr, "Error: Invalid argument.\n");
+            rc = EINVAL;
+            goto vcpp_out;
+        }
+        if (*endptr == '-') {
+            tokb = endptr + 1;
+            cpuidb = strtoul(tokb, &endptr, 10);
+            if (endptr == tokb || cpuida > cpuidb) {
+                fprintf(stderr, "Error: Invalid argument.\n");
+                rc = EINVAL;
+                goto vcpp_out;
+            }
+        }
+        while (cpuida <= cpuidb) {
+            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
+                         libxl_cpumap_set(&exclude_cpumap, cpuida);
+            cpuida++;
+        }
+    }
+
+    /* Clear all the cpus from the removal list */
+    libxl_for_each_set_cpu(i, exclude_cpumap) {
+        libxl_cpumap_reset(cpumap, i);
+    }
+
+vcpp_out:
+    libxl_cpumap_dispose(&exclude_cpumap);
+
+    return rc;
+}
+
 static void parse_config_data(const char *configfile_filename_report,
                               const char *configfile_data,
                               int configfile_len,
@@ -578,7 +637,7 @@ static void parse_config_data(const char
     const char *buf;
     long l;
     XLU_Config *config;
-    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *cpuids;
+    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids;
     int pci_power_mgmt = 0;
     int pci_msitranslate = 1;
     int e;
@@ -661,6 +720,29 @@ 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_list (config, "cpus", &cpus, 0, 1)) {
+        int i, n_cpus = 0;
+
+        libxl_cpumap_set_none(&b_info->cpumap);
+        while ((buf = xlu_cfg_get_listitem(cpus, n_cpus)) != NULL) {
+            i = atoi(buf);
+            if (!libxl_cpumap_cpu_valid(&b_info->cpumap, i)) {
+                fprintf(stderr, "cpu %d illegal\n", i);
+                exit(1);
+            }
+            libxl_cpumap_set(&b_info->cpumap, i);
+            n_cpus++;
+        }
+    }
+    else if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
+        char *buf2 = strdup(buf);
+
+        libxl_cpumap_set_none(&b_info->cpumap);
+        if (vcpupin_parse(buf2, &b_info->cpumap))
+            exit(1);
+        free(buf2);
+    }
+
     if (!xlu_cfg_get_long (config, "memory", &l, 0)) {
         b_info->max_memkb = l * 1024;
         b_info->target_memkb = b_info->max_memkb;
@@ -3503,65 +3585,6 @@ int main_vcpulist(int argc, char **argv)
     return 0;
 }
 
-static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
-{
-    libxl_cpumap exclude_cpumap;
-    uint32_t cpuida, cpuidb;
-    char *endptr, *toka, *tokb, *saveptr = NULL;
-    int i, rc = 0, rmcpu;
-
-    if (!strcmp(cpu, "all")) {
-        memset(cpumap->map, -1, cpumap->size);
-        return 0;
-    }
-
-    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
-        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
-        return ENOMEM;
-    }
-
-    for (toka = strtok_r(cpu, ",", &saveptr); toka;
-         toka = strtok_r(NULL, ",", &saveptr)) {
-        rmcpu = 0;
-        if (*toka == '^') {
-            /* This (These) Cpu(s) will be removed from the map */
-            toka++;
-            rmcpu = 1;
-        }
-        /* Extract a valid (range of) cpu(s) */
-        cpuida = cpuidb = strtoul(toka, &endptr, 10);
-        if (endptr == toka) {
-            fprintf(stderr, "Error: Invalid argument.\n");
-            rc = EINVAL;
-            goto vcpp_out;
-        }
-        if (*endptr == '-') {
-            tokb = endptr + 1;
-            cpuidb = strtoul(tokb, &endptr, 10);
-            if (endptr == tokb || cpuida > cpuidb) {
-                fprintf(stderr, "Error: Invalid argument.\n");
-                rc = EINVAL;
-                goto vcpp_out;
-            }
-        }
-        while (cpuida <= cpuidb) {
-            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
-                         libxl_cpumap_set(&exclude_cpumap, cpuida);
-            cpuida++;
-        }
-    }
-
-    /* Clear all the cpus from the removal list */
-    libxl_for_each_set_cpu(i, exclude_cpumap) {
-        libxl_cpumap_reset(cpumap, i);
-    }
-
-vcpp_out:
-    libxl_cpumap_dispose(&exclude_cpumap);
-
-    return rc;
-}
-
 static void vcpupin(const char *d, const char *vcpu, char *cpu)
 {
     libxl_vcpuinfo *vcpuinfo;

[-- 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin.
  2012-01-25 14:15 [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file Dario Faggioli
  2012-01-25 14:35 ` [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
  2012-01-25 14:36 ` [PATCHv3 1 of 2] libxl: allow for specifying the CPU affinity in the config file Dario Faggioli
@ 2012-01-25 14:37 ` Dario Faggioli
  2012-01-27 19:18 ` [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file Ian Jackson
  3 siblings, 0 replies; 7+ messages in thread
From: Dario Faggioli @ 2012-01-25 14:37 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian.Campbell, George Dunlap, Juergen Gross, Ian Jackson


[-- Attachment #1.1.1: Type: text/plain, Size: 5242 bytes --]

[Resending with patch attached, in case the client mangled the body of  
the message (although it really shouldn't!)] 

Allow for "^<cpuid>" syntax while specifying the pCPUs list
during a vcpu-pin. This enables doing the following:

 xl vcpu-pin 1 1 0-4,^2

and achieving:

 xl vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 ...
 Squeeze_pv                           1     1    3   -b-       2.4  0-1,3-4
 ...

Negative ranges are also supported, such as "0-4,^1-2" to
mean "0,3-4"

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>

diff -r a2a8089b1ffb tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Tue Jan 24 16:46:17 2012 +0000
+++ b/tools/libxl/libxl_utils.h	Wed Jan 25 11:40:22 2012 +0000
@@ -71,6 +71,8 @@ int libxl_cpumap_test(libxl_cpumap *cpum
 void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
 #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
+#define libxl_for_each_set_cpu(v, m) for (v = 0; v < (m).size * 8; v++) \
+                                             if (libxl_cpumap_test(&(m), v))
 
 int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray);
 
diff -r a2a8089b1ffb tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Tue Jan 24 16:46:17 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 25 11:40:22 2012 +0000
@@ -3503,13 +3503,72 @@ int main_vcpulist(int argc, char **argv)
     return 0;
 }
 
+static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
+{
+    libxl_cpumap exclude_cpumap;
+    uint32_t cpuida, cpuidb;
+    char *endptr, *toka, *tokb, *saveptr = NULL;
+    int i, rc = 0, rmcpu;
+
+    if (!strcmp(cpu, "all")) {
+        memset(cpumap->map, -1, cpumap->size);
+        return 0;
+    }
+
+    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
+        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
+        return ENOMEM;
+    }
+
+    for (toka = strtok_r(cpu, ",", &saveptr); toka;
+         toka = strtok_r(NULL, ",", &saveptr)) {
+        rmcpu = 0;
+        if (*toka == '^') {
+            /* This (These) Cpu(s) will be removed from the map */
+            toka++;
+            rmcpu = 1;
+        }
+        /* Extract a valid (range of) cpu(s) */
+        cpuida = cpuidb = strtoul(toka, &endptr, 10);
+        if (endptr == toka) {
+            fprintf(stderr, "Error: Invalid argument.\n");
+            rc = EINVAL;
+            goto vcpp_out;
+        }
+        if (*endptr == '-') {
+            tokb = endptr + 1;
+            cpuidb = strtoul(tokb, &endptr, 10);
+            if (endptr == tokb || cpuida > cpuidb) {
+                fprintf(stderr, "Error: Invalid argument.\n");
+                rc = EINVAL;
+                goto vcpp_out;
+            }
+        }
+        while (cpuida <= cpuidb) {
+            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
+                         libxl_cpumap_set(&exclude_cpumap, cpuida);
+            cpuida++;
+        }
+    }
+
+    /* Clear all the cpus from the removal list */
+    libxl_for_each_set_cpu(i, exclude_cpumap) {
+        libxl_cpumap_reset(cpumap, i);
+    }
+
+vcpp_out:
+    libxl_cpumap_dispose(&exclude_cpumap);
+
+    return rc;
+}
+
 static void vcpupin(const char *d, const char *vcpu, char *cpu)
 {
     libxl_vcpuinfo *vcpuinfo;
     libxl_cpumap cpumap;
 
-    uint32_t vcpuid, cpuida, cpuidb;
-    char *endptr, *toka, *tokb;
+    uint32_t vcpuid;
+    char *endptr;
     int i, nb_vcpu;
 
     vcpuid = strtoul(vcpu, &endptr, 10);
@@ -3526,32 +3585,9 @@ static void vcpupin(const char *d, const
     if (libxl_cpumap_alloc(ctx, &cpumap)) {
         goto vcpupin_out;
     }
-    if (strcmp(cpu, "all")) {
-        for (toka = strtok(cpu, ","), i = 0; toka; toka = strtok(NULL, ","), ++i) {
-            cpuida = strtoul(toka, &endptr, 10);
-            if (toka == endptr) {
-                fprintf(stderr, "Error: Invalid argument.\n");
-                goto vcpupin_out1;
-            }
-            if (*endptr == '-') {
-                tokb = endptr + 1;
-                cpuidb = strtoul(tokb, &endptr, 10);
-                if ((tokb == endptr) || (cpuida > cpuidb)) {
-                    fprintf(stderr, "Error: Invalid argument.\n");
-                    goto vcpupin_out1;
-                }
-                while (cpuida <= cpuidb) {
-                    libxl_cpumap_set(&cpumap, cpuida);
-                    ++cpuida;
-                }
-            } else {
-                libxl_cpumap_set(&cpumap, cpuida);
-            }
-        }
-    }
-    else {
-        memset(cpumap.map, -1, cpumap.size);
-    }
+
+    if (vcpupin_parse(cpu, &cpumap))
+        goto vcpupin_out1;
 
     if (vcpuid != -1) {
         if (libxl_set_vcpuaffinity(ctx, domid, vcpuid, &cpumap) == -1) {

-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-------------------------------------------------------------------
Dario Faggioli, Ph.D, http://retis.sssup.it/people/faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)




[-- Attachment #1.1.2: generalize-vcpupin-parsig.patch --]
[-- Type: text/x-patch, Size: 4891 bytes --]

# HG changeset patch
# Parent a2a8089b1ffbf5757ca3191cb8f74a5f1ed7fed1
libxl: extend pCPUs specification for vcpu-pin.

Allow for "^<cpuid>" syntax while specifying the pCPUs list
during a vcpu-pin. This enables doing the following:

 xl vcpu-pin 1 1 0-4,^2

and achieving:

 xl vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 ...
 Squeeze_pv                           1     1    3   -b-       2.4  0-1,3-4
 ...

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>

diff -r a2a8089b1ffb tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Tue Jan 24 16:46:17 2012 +0000
+++ b/tools/libxl/libxl_utils.h	Wed Jan 25 11:40:22 2012 +0000
@@ -71,6 +71,8 @@ int libxl_cpumap_test(libxl_cpumap *cpum
 void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
 #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
+#define libxl_for_each_set_cpu(v, m) for (v = 0; v < (m).size * 8; v++) \
+                                             if (libxl_cpumap_test(&(m), v))
 
 int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray);
 
diff -r a2a8089b1ffb tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Tue Jan 24 16:46:17 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 25 11:40:22 2012 +0000
@@ -3503,13 +3503,72 @@ int main_vcpulist(int argc, char **argv)
     return 0;
 }
 
+static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
+{
+    libxl_cpumap exclude_cpumap;
+    uint32_t cpuida, cpuidb;
+    char *endptr, *toka, *tokb, *saveptr = NULL;
+    int i, rc = 0, rmcpu;
+
+    if (!strcmp(cpu, "all")) {
+        memset(cpumap->map, -1, cpumap->size);
+        return 0;
+    }
+
+    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
+        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
+        return ENOMEM;
+    }
+
+    for (toka = strtok_r(cpu, ",", &saveptr); toka;
+         toka = strtok_r(NULL, ",", &saveptr)) {
+        rmcpu = 0;
+        if (*toka == '^') {
+            /* This (These) Cpu(s) will be removed from the map */
+            toka++;
+            rmcpu = 1;
+        }
+        /* Extract a valid (range of) cpu(s) */
+        cpuida = cpuidb = strtoul(toka, &endptr, 10);
+        if (endptr == toka) {
+            fprintf(stderr, "Error: Invalid argument.\n");
+            rc = EINVAL;
+            goto vcpp_out;
+        }
+        if (*endptr == '-') {
+            tokb = endptr + 1;
+            cpuidb = strtoul(tokb, &endptr, 10);
+            if (endptr == tokb || cpuida > cpuidb) {
+                fprintf(stderr, "Error: Invalid argument.\n");
+                rc = EINVAL;
+                goto vcpp_out;
+            }
+        }
+        while (cpuida <= cpuidb) {
+            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
+                         libxl_cpumap_set(&exclude_cpumap, cpuida);
+            cpuida++;
+        }
+    }
+
+    /* Clear all the cpus from the removal list */
+    libxl_for_each_set_cpu(i, exclude_cpumap) {
+        libxl_cpumap_reset(cpumap, i);
+    }
+
+vcpp_out:
+    libxl_cpumap_dispose(&exclude_cpumap);
+
+    return rc;
+}
+
 static void vcpupin(const char *d, const char *vcpu, char *cpu)
 {
     libxl_vcpuinfo *vcpuinfo;
     libxl_cpumap cpumap;
 
-    uint32_t vcpuid, cpuida, cpuidb;
-    char *endptr, *toka, *tokb;
+    uint32_t vcpuid;
+    char *endptr;
     int i, nb_vcpu;
 
     vcpuid = strtoul(vcpu, &endptr, 10);
@@ -3526,32 +3585,9 @@ static void vcpupin(const char *d, const
     if (libxl_cpumap_alloc(ctx, &cpumap)) {
         goto vcpupin_out;
     }
-    if (strcmp(cpu, "all")) {
-        for (toka = strtok(cpu, ","), i = 0; toka; toka = strtok(NULL, ","), ++i) {
-            cpuida = strtoul(toka, &endptr, 10);
-            if (toka == endptr) {
-                fprintf(stderr, "Error: Invalid argument.\n");
-                goto vcpupin_out1;
-            }
-            if (*endptr == '-') {
-                tokb = endptr + 1;
-                cpuidb = strtoul(tokb, &endptr, 10);
-                if ((tokb == endptr) || (cpuida > cpuidb)) {
-                    fprintf(stderr, "Error: Invalid argument.\n");
-                    goto vcpupin_out1;
-                }
-                while (cpuida <= cpuidb) {
-                    libxl_cpumap_set(&cpumap, cpuida);
-                    ++cpuida;
-                }
-            } else {
-                libxl_cpumap_set(&cpumap, cpuida);
-            }
-        }
-    }
-    else {
-        memset(cpumap.map, -1, cpumap.size);
-    }
+
+    if (vcpupin_parse(cpu, &cpumap))
+        goto vcpupin_out1;
 
     if (vcpuid != -1) {
         if (libxl_set_vcpuaffinity(ctx, domid, vcpuid, &cpumap) == -1) {

[-- 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin.
  2012-01-25 14:35 ` [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
@ 2012-01-25 14:43   ` Ian Campbell
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Campbell @ 2012-01-25 14:43 UTC (permalink / raw)
  To: Dario Faggioli; +Cc: George Dunlap, Juergen Gross, xen-devel, Ian Jackson

On Wed, 2012-01-25 at 14:35 +0000, Dario Faggioli wrote:
> Allow for "^<cpuid>" syntax while specifying the pCPUs list
> during a vcpu-pin. This enables doing the following:
> 
>  xl vcpu-pin 1 1 0-4,^2
> 
> and achieving:
> 
>  xl vcpu-list
>  Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
>  ...
>  Squeeze_pv                           1     1    3   -b-       2.4  0-1,3-4
>  ...
> 
> Negative ranges are also supported, such as "0-4,^1-2" to
> mean "0,3-4"
> 
> Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCHv3 1 of 2] libxl: allow for specifying the CPU affinity in the config file.
  2012-01-25 14:36 ` [PATCHv3 1 of 2] libxl: allow for specifying the CPU affinity in the config file Dario Faggioli
@ 2012-01-25 14:45   ` Ian Campbell
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Campbell @ 2012-01-25 14:45 UTC (permalink / raw)
  To: Dario Faggioli; +Cc: George Dunlap, Juergen Gross, xen-devel, Ian Jackson

On Wed, 2012-01-25 at 14:36 +0000, Dario Faggioli wrote:
> 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>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

(if you do end up resending for any reason then you could combine the
code motion of vcpupin_parse in ths patch with it's introduction in the
prior patch).

> 
> diff -r e4fd5305381e tools/libxl/libxl.c
> --- a/tools/libxl/libxl.c	Wed Jan 25 11:40:23 2012 +0000
> +++ b/tools/libxl/libxl.c	Wed Jan 25 14:08:21 2012 +0000
> @@ -2663,6 +2663,21 @@ int libxl_set_vcpuaffinity(libxl_ctx *ct
>      return 0;
>  }
>  
> +int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
> +                               unsigned int max_vcpus, libxl_cpumap *cpumap)
> +{
> +    int i, rc = 0;
> +
> +    for (i = 0; i < max_vcpus; i++) {
> +        if (libxl_set_vcpuaffinity(ctx, domid, i, cpumap)) {
> +            LIBXL__LOG(ctx, LIBXL__LOG_WARNING,
> +                       "failed to set affinity for %d", i);
> +            rc = ERROR_FAIL;
> +        }
> +    }
> +    return rc;
> +}
> +
>  int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap)
>  {
>      GC_INIT(ctx);
> diff -r e4fd5305381e tools/libxl/libxl.h
> --- a/tools/libxl/libxl.h	Wed Jan 25 11:40:23 2012 +0000
> +++ b/tools/libxl/libxl.h	Wed Jan 25 14:08:21 2012 +0000
> @@ -560,6 +560,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
>                                         int *nb_vcpu, int *nrcpus);
>  int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
>                             libxl_cpumap *cpumap);
> +int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
> +                               unsigned int max_vcpus, libxl_cpumap *cpumap);
>  int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap);
>  
>  int libxl_get_sched_id(libxl_ctx *ctx);
> diff -r e4fd5305381e tools/libxl/libxl_create.c
> --- a/tools/libxl/libxl_create.c	Wed Jan 25 11:40:23 2012 +0000
> +++ b/tools/libxl/libxl_create.c	Wed Jan 25 14:08:21 2012 +0000
> @@ -71,6 +71,9 @@ 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;
> +    libxl_cpumap_set_any(&b_info->cpumap);
>      b_info->max_memkb = 32 * 1024;
>      b_info->target_memkb = b_info->max_memkb;
>      b_info->disable_migrate = 0;
> diff -r e4fd5305381e tools/libxl/libxl_dom.c
> --- a/tools/libxl/libxl_dom.c	Wed Jan 25 11:40:23 2012 +0000
> +++ b/tools/libxl/libxl_dom.c	Wed Jan 25 14:08:21 2012 +0000
> @@ -65,6 +65,7 @@ int libxl__build_pre(libxl__gc *gc, uint
>      libxl_ctx *ctx = libxl__gc_owner(gc);
>      int tsc_mode;
>      xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
> +    libxl_set_vcpuaffinity_all(ctx, domid, info->max_vcpus, &info->cpumap);
>      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 e4fd5305381e tools/libxl/libxl_types.idl
> --- a/tools/libxl/libxl_types.idl	Wed Jan 25 11:40:23 2012 +0000
> +++ b/tools/libxl/libxl_types.idl	Wed Jan 25 14:08:21 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 e4fd5305381e tools/libxl/libxl_utils.h
> --- a/tools/libxl/libxl_utils.h	Wed Jan 25 11:40:23 2012 +0000
> +++ b/tools/libxl/libxl_utils.h	Wed Jan 25 14:08:21 2012 +0000
> @@ -70,6 +70,18 @@ int libxl_cpumap_alloc(libxl_ctx *ctx, l
>  int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu);
>  void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
>  void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
> +static inline void libxl_cpumap_set_any(libxl_cpumap *cpumap)
> +{
> +    memset(cpumap->map, -1, cpumap->size);
> +}
> +static inline void libxl_cpumap_set_none(libxl_cpumap *cpumap)
> +{
> +    memset(cpumap->map, 0, cpumap->size);
> +}
> +static inline int libxl_cpumap_cpu_valid(libxl_cpumap *cpumap, int cpu)
> +{
> +    return cpu >= 0 && cpu < (cpumap->size * 8);
> +}
>  #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
>  #define libxl_for_each_set_cpu(v, m) for (v = 0; v < (m).size * 8; v++) \
>                                               if (libxl_cpumap_test(&(m), v))
> diff -r e4fd5305381e tools/libxl/xl_cmdimpl.c
> --- a/tools/libxl/xl_cmdimpl.c	Wed Jan 25 11:40:23 2012 +0000
> +++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 25 14:08:21 2012 +0000
> @@ -569,6 +569,65 @@ static void split_string_into_string_lis
>      free(s);
>  }
>  
> +static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
> +{
> +    libxl_cpumap exclude_cpumap;
> +    uint32_t cpuida, cpuidb;
> +    char *endptr, *toka, *tokb, *saveptr = NULL;
> +    int i, rc = 0, rmcpu;
> +
> +    if (!strcmp(cpu, "all")) {
> +        libxl_cpumap_set_any(cpumap);
> +        return 0;
> +    }
> +
> +    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
> +        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
> +        return ENOMEM;
> +    }
> +
> +    for (toka = strtok_r(cpu, ",", &saveptr); toka;
> +         toka = strtok_r(NULL, ",", &saveptr)) {
> +        rmcpu = 0;
> +        if (*toka == '^') {
> +            /* This (These) Cpu(s) will be removed from the map */
> +            toka++;
> +            rmcpu = 1;
> +        }
> +        /* Extract a valid (range of) cpu(s) */
> +        cpuida = cpuidb = strtoul(toka, &endptr, 10);
> +        if (endptr == toka) {
> +            fprintf(stderr, "Error: Invalid argument.\n");
> +            rc = EINVAL;
> +            goto vcpp_out;
> +        }
> +        if (*endptr == '-') {
> +            tokb = endptr + 1;
> +            cpuidb = strtoul(tokb, &endptr, 10);
> +            if (endptr == tokb || cpuida > cpuidb) {
> +                fprintf(stderr, "Error: Invalid argument.\n");
> +                rc = EINVAL;
> +                goto vcpp_out;
> +            }
> +        }
> +        while (cpuida <= cpuidb) {
> +            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
> +                         libxl_cpumap_set(&exclude_cpumap, cpuida);
> +            cpuida++;
> +        }
> +    }
> +
> +    /* Clear all the cpus from the removal list */
> +    libxl_for_each_set_cpu(i, exclude_cpumap) {
> +        libxl_cpumap_reset(cpumap, i);
> +    }
> +
> +vcpp_out:
> +    libxl_cpumap_dispose(&exclude_cpumap);
> +
> +    return rc;
> +}
> +
>  static void parse_config_data(const char *configfile_filename_report,
>                                const char *configfile_data,
>                                int configfile_len,
> @@ -578,7 +637,7 @@ static void parse_config_data(const char
>      const char *buf;
>      long l;
>      XLU_Config *config;
> -    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *cpuids;
> +    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids;
>      int pci_power_mgmt = 0;
>      int pci_msitranslate = 1;
>      int e;
> @@ -661,6 +720,29 @@ 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_list (config, "cpus", &cpus, 0, 1)) {
> +        int i, n_cpus = 0;
> +
> +        libxl_cpumap_set_none(&b_info->cpumap);
> +        while ((buf = xlu_cfg_get_listitem(cpus, n_cpus)) != NULL) {
> +            i = atoi(buf);
> +            if (!libxl_cpumap_cpu_valid(&b_info->cpumap, i)) {
> +                fprintf(stderr, "cpu %d illegal\n", i);
> +                exit(1);
> +            }
> +            libxl_cpumap_set(&b_info->cpumap, i);
> +            n_cpus++;
> +        }
> +    }
> +    else if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
> +        char *buf2 = strdup(buf);
> +
> +        libxl_cpumap_set_none(&b_info->cpumap);
> +        if (vcpupin_parse(buf2, &b_info->cpumap))
> +            exit(1);
> +        free(buf2);
> +    }
> +
>      if (!xlu_cfg_get_long (config, "memory", &l, 0)) {
>          b_info->max_memkb = l * 1024;
>          b_info->target_memkb = b_info->max_memkb;
> @@ -3503,65 +3585,6 @@ int main_vcpulist(int argc, char **argv)
>      return 0;
>  }
>  
> -static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
> -{
> -    libxl_cpumap exclude_cpumap;
> -    uint32_t cpuida, cpuidb;
> -    char *endptr, *toka, *tokb, *saveptr = NULL;
> -    int i, rc = 0, rmcpu;
> -
> -    if (!strcmp(cpu, "all")) {
> -        memset(cpumap->map, -1, cpumap->size);
> -        return 0;
> -    }
> -
> -    if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
> -        fprintf(stderr, "Error: Failed to allocate cpumap.\n");
> -        return ENOMEM;
> -    }
> -
> -    for (toka = strtok_r(cpu, ",", &saveptr); toka;
> -         toka = strtok_r(NULL, ",", &saveptr)) {
> -        rmcpu = 0;
> -        if (*toka == '^') {
> -            /* This (These) Cpu(s) will be removed from the map */
> -            toka++;
> -            rmcpu = 1;
> -        }
> -        /* Extract a valid (range of) cpu(s) */
> -        cpuida = cpuidb = strtoul(toka, &endptr, 10);
> -        if (endptr == toka) {
> -            fprintf(stderr, "Error: Invalid argument.\n");
> -            rc = EINVAL;
> -            goto vcpp_out;
> -        }
> -        if (*endptr == '-') {
> -            tokb = endptr + 1;
> -            cpuidb = strtoul(tokb, &endptr, 10);
> -            if (endptr == tokb || cpuida > cpuidb) {
> -                fprintf(stderr, "Error: Invalid argument.\n");
> -                rc = EINVAL;
> -                goto vcpp_out;
> -            }
> -        }
> -        while (cpuida <= cpuidb) {
> -            rmcpu == 0 ? libxl_cpumap_set(cpumap, cpuida) :
> -                         libxl_cpumap_set(&exclude_cpumap, cpuida);
> -            cpuida++;
> -        }
> -    }
> -
> -    /* Clear all the cpus from the removal list */
> -    libxl_for_each_set_cpu(i, exclude_cpumap) {
> -        libxl_cpumap_reset(cpumap, i);
> -    }
> -
> -vcpp_out:
> -    libxl_cpumap_dispose(&exclude_cpumap);
> -
> -    return rc;
> -}
> -
>  static void vcpupin(const char *d, const char *vcpu, char *cpu)
>  {
>      libxl_vcpuinfo *vcpuinfo;
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file.
  2012-01-25 14:15 [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file Dario Faggioli
                   ` (2 preceding siblings ...)
  2012-01-25 14:37 ` [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
@ 2012-01-27 19:18 ` Ian Jackson
  3 siblings, 0 replies; 7+ messages in thread
From: Ian Jackson @ 2012-01-27 19:18 UTC (permalink / raw)
  To: Dario Faggioli; +Cc: Ian.Campbell, George Dunlap, Juergen Gross, xen-devel

Dario Faggioli writes ("[Xen-devel] [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file."):
> This series slightly extends the current support for specifying CPU
> affinity, basically adding the support for "^<cpuid>" kind of entries
> (i.e., "^6", meaning "not on CPU#6), and enables doing so in a VM's
> config file, like it (probably?) was possible with `xm'.

Thanks, I have applied both of these.

A couple of comments for when you next send patches:

 * Having two patches both titled 1/2 is rather confusing,
   particularly if you then gratuitously repost one of them.

 * There doesn't seem to be any need for you to attach a second copy
   of the patch - in both cases the first one was in fact fine - and
   it would be easier for me if you didn't.

Thanks,
Ian.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-01-27 19:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-25 14:15 [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file Dario Faggioli
2012-01-25 14:35 ` [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
2012-01-25 14:43   ` Ian Campbell
2012-01-25 14:36 ` [PATCHv3 1 of 2] libxl: allow for specifying the CPU affinity in the config file Dario Faggioli
2012-01-25 14:45   ` Ian Campbell
2012-01-25 14:37 ` [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin Dario Faggioli
2012-01-27 19:18 ` [PATCHv3 0 of 2] libxl: Extend CPU affinity syntax and enable for specifying it in config file Ian Jackson

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).