From: Dario Faggioli <raistlin@linux.it>
To: xen-devel <xen-devel@lists.xensource.com>
Cc: "Ian.Campbell" <Ian.Campbell@eu.citrix.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Juergen Gross <juergen.gross@ts.fujitsu.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [PATCHv2 1 of 2] libxl: extend pCPUs specification for vcpu-pin.
Date: Mon, 23 Jan 2012 19:21:11 +0100 [thread overview]
Message-ID: <1327342871.2476.14.camel@Abyss> (raw)
In-Reply-To: <1327342219.2476.9.camel@Abyss>
[-- Attachment #1.1.1: Type: text/plain, Size: 5271 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 370924e204dc tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h Mon Jan 23 15:10:43 2012 +0000
+++ b/tools/libxl/libxl_utils.h Mon Jan 23 18:02:41 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 370924e204dc tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon Jan 23 15:10:43 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c Mon Jan 23 18:02:41 2012 +0000
@@ -3503,13 +3503,77 @@ 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, ret = 0;
+
+ 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)) {
+ if (*toka == '^') {
+ /* Add the cpu to the removal list */
+ toka++;
+ cpuida = strtoul(toka, &endptr, 10);
+ if (toka == endptr) {
+ fprintf(stderr, "Error: Invalid argument.\n");
+ ret = EINVAL;
+ goto vcpp_out;
+ }
+ libxl_cpumap_set(&exclude_cpumap, cpuida);
+ } else {
+ /* Valid (range of) cpu(s) */
+ cpuida = cpuidb = strtoul(toka, &endptr, 10);
+ if (endptr == toka) {
+ fprintf(stderr, "Error: Invalid argument.\n");
+ ret = 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");
+ ret = EINVAL;
+ goto vcpp_out;
+ }
+ }
+ while (cpuida <= cpuidb) {
+ libxl_cpumap_set(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 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);
@@ -3526,32 +3590,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: 5120 bytes --]
# HG changeset patch
# Parent 370924e204dc29e12cd807dd730974d6b2bc53d3
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 370924e204dc tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h Mon Jan 23 15:10:43 2012 +0000
+++ b/tools/libxl/libxl_utils.h Mon Jan 23 18:02:41 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 370924e204dc tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon Jan 23 15:10:43 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c Mon Jan 23 18:02:41 2012 +0000
@@ -3503,13 +3503,77 @@ 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, ret = 0;
+
+ 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)) {
+ if (*toka == '^') {
+ /* Add the cpu to the removal list */
+ toka++;
+ cpuida = strtoul(toka, &endptr, 10);
+ if (toka == endptr) {
+ fprintf(stderr, "Error: Invalid argument.\n");
+ ret = EINVAL;
+ goto vcpp_out;
+ }
+ libxl_cpumap_set(&exclude_cpumap, cpuida);
+ } else {
+ /* Valid (range of) cpu(s) */
+ cpuida = cpuidb = strtoul(toka, &endptr, 10);
+ if (endptr == toka) {
+ fprintf(stderr, "Error: Invalid argument.\n");
+ ret = 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");
+ ret = EINVAL;
+ goto vcpp_out;
+ }
+ }
+ while (cpuida <= cpuidb) {
+ libxl_cpumap_set(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 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);
@@ -3526,32 +3590,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
next prev parent reply other threads:[~2012-01-23 18:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-23 18:10 [PATCHv2 0 of 2] libxl: Extend CPU affinity specification and enable it in config file Dario Faggioli
2012-01-23 18:21 ` Dario Faggioli [this message]
2012-01-25 10:19 ` [PATCHv2 1 of 2] libxl: extend pCPUs specification for vcpu-pin Ian Campbell
2012-01-25 10:47 ` Dario Faggioli
2012-01-25 11:06 ` Dario Faggioli
2012-01-23 18:22 ` [PATCHv2 2 of 2] libxl: allow for specifying the CPU affinity in the config file Dario Faggioli
2012-01-25 10:28 ` Ian Campbell
2012-01-25 10:44 ` 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=1327342871.2476.14.camel@Abyss \
--to=raistlin@linux.it \
--cc=George.Dunlap@eu.citrix.com \
--cc=Ian.Campbell@eu.citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=juergen.gross@ts.fujitsu.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).