xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
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 1 of 3] libxl: extend pCPUs specification for vcpu-pin.
Date: Wed, 11 Jan 2012 17:58:59 +0000	[thread overview]
Message-ID: <1326304739.12973.1.camel@Abyss> (raw)
In-Reply-To: <1326304198.2401.6.camel@Abyss>


[-- Attachment #1.1.1: Type: text/plain, Size: 5022 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
 ...

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

diff -r 9cdcedc133e5 tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Wed Jan 11 10:34:45 2012 +0100
+++ b/tools/libxl/libxl_utils.h	Wed Jan 11 17:38:04 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(var, map) for (var = 0; var < (map).size * 8; var++) \
+                                             if (libxl_cpumap_test(&(map), var))
 
 int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray);
 
diff -r 9cdcedc133e5 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Wed Jan 11 10:34:45 2012 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 11 17:38:04 2012 +0000
@@ -3501,13 +3501,67 @@ 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;
+    int i, rmcpu, ret = 0;
+
+    if (libxl_cpumap_alloc(ctx, &exclude_cpumap))
+        return ENOMEM;
+
+    if (strcmp(cpu, "all")) {
+        for (toka = strtok(cpu, ","), i = 0; toka; toka = strtok(NULL, ","), ++i) {
+            rmcpu = 0;
+            if (*toka == '^') {
+                toka++; rmcpu = 1;
+            }
+            cpuida = strtoul(toka, &endptr, 10);
+            if (toka == endptr) {
+                fprintf(stderr, "Error: Invalid argument.\n");
+                ret = EINVAL;
+                goto vcpp_out;
+            }
+            if (rmcpu) {
+                libxl_cpumap_set(&exclude_cpumap, cpuida);
+            } else if (*endptr == '-') {
+                tokb = endptr + 1;
+                cpuidb = strtoul(tokb, &endptr, 10);
+                if ((tokb == endptr) || (cpuida > cpuidb)) {
+                    fprintf(stderr, "Error: Invalid argument.\n");
+                    ret = EINVAL;
+                    goto vcpp_out;
+                }
+                while (cpuida <= cpuidb) {
+                    libxl_cpumap_set(cpumap, cpuida);
+                    ++cpuida;
+                }
+            } else {
+                libxl_cpumap_set(cpumap, cpuida);
+            }
+        }
+
+        libxl_for_each_set_cpu(i, exclude_cpumap) {
+            libxl_cpumap_reset(cpumap, i);
+        }
+    } else {
+        memset(cpumap->map, -1, cpumap->size);
+    }
+
+vcpp_out:
+    libxl_cpumap_dispose(&exclude_cpumap);
+
+    return ret;
+}
+
 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);
@@ -3524,32 +3578,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, 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: generalize-vcpupin-parsig.patch --]
[-- Type: text/x-patch, Size: 4809 bytes --]

# HG changeset patch
# Parent 9cdcedc133e5227c635dbb00bd4779015311107a
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 9cdcedc133e5 tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Wed Jan 11 10:34:45 2012 +0100
+++ b/tools/libxl/libxl_utils.h	Wed Jan 11 17:38:04 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(var, map) for (var = 0; var < (map).size * 8; var++) \
+                                             if (libxl_cpumap_test(&(map), var))
 
 int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray);
 
diff -r 9cdcedc133e5 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Wed Jan 11 10:34:45 2012 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 11 17:38:04 2012 +0000
@@ -3501,13 +3501,67 @@ 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;
+    int i, rmcpu, ret = 0;
+
+    if (libxl_cpumap_alloc(ctx, &exclude_cpumap))
+        return ENOMEM;
+
+    if (strcmp(cpu, "all")) {
+        for (toka = strtok(cpu, ","), i = 0; toka; toka = strtok(NULL, ","), ++i) {
+            rmcpu = 0;
+            if (*toka == '^') {
+                toka++; rmcpu = 1;
+            }
+            cpuida = strtoul(toka, &endptr, 10);
+            if (toka == endptr) {
+                fprintf(stderr, "Error: Invalid argument.\n");
+                ret = EINVAL;
+                goto vcpp_out;
+            }
+            if (rmcpu) {
+                libxl_cpumap_set(&exclude_cpumap, cpuida);
+            } else if (*endptr == '-') {
+                tokb = endptr + 1;
+                cpuidb = strtoul(tokb, &endptr, 10);
+                if ((tokb == endptr) || (cpuida > cpuidb)) {
+                    fprintf(stderr, "Error: Invalid argument.\n");
+                    ret = EINVAL;
+                    goto vcpp_out;
+                }
+                while (cpuida <= cpuidb) {
+                    libxl_cpumap_set(cpumap, cpuida);
+                    ++cpuida;
+                }
+            } else {
+                libxl_cpumap_set(cpumap, cpuida);
+            }
+        }
+
+        libxl_for_each_set_cpu(i, exclude_cpumap) {
+            libxl_cpumap_reset(cpumap, i);
+        }
+    } else {
+        memset(cpumap->map, -1, cpumap->size);
+    }
+
+vcpp_out:
+    libxl_cpumap_dispose(&exclude_cpumap);
+
+    return ret;
+}
+
 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);
@@ -3524,32 +3578,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

  reply	other threads:[~2012-01-11 17:58 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 ` Dario Faggioli [this message]
2012-01-12  8:38   ` [PATCH 1 of 3] libxl: extend pCPUs specification for vcpu-pin 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 ` [PATCH 2 of 3] libxl: allow for specifying the CPU affinity in the config file Dario Faggioli
2012-01-12  8:43   ` 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=1326304739.12973.1.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 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).