[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 1 of 3] libxl: extend pCPUs specification for vcpu-pin.



On Wed, 2012-01-11 at 17:58 +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
>  ...
> 
> Signed-off-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx>

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

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



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.