aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl
diff options
context:
space:
mode:
authorDario Faggioli <dario.faggioli@citrix.com>2012-01-27 19:14:00 +0000
committerDario Faggioli <dario.faggioli@citrix.com>2012-01-27 19:14:00 +0000
commit3290f842f7cefdd9d0d43271025d1d945d5e8529 (patch)
treee9933e61d9cab23597333bbf64d118353db30fe7 /tools/libxl
parent7c4f9f61a2c98b3ae2cd5f898738368e1836fab2 (diff)
downloadxen-3290f842f7cefdd9d0d43271025d1d945d5e8529.tar.gz
xen-3290f842f7cefdd9d0d43271025d1d945d5e8529.tar.bz2
xen-3290f842f7cefdd9d0d43271025d1d945d5e8529.zip
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 ... 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> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl')
-rw-r--r--tools/libxl/libxl_utils.h2
-rw-r--r--tools/libxl/xl_cmdimpl.c92
2 files changed, 66 insertions, 28 deletions
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 0790fa0620..19ad357d37 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -71,6 +71,8 @@ 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);
#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 --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 681a148389..3fed318eea 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3568,13 +3568,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);
@@ -3591,32 +3650,9 @@ static void vcpupin(const char *d, const char *vcpu, char *cpu)
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) {