From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dario Faggioli Subject: [PATCHv3 1 of 2] libxl: extend pCPUs specification for vcpu-pin. Date: Wed, 25 Jan 2012 15:35:02 +0100 Message-ID: <1327502102.2723.15.camel@Abyss> References: <1327500920.2723.11.camel@Abyss> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1683186530190811548==" Return-path: In-Reply-To: <1327500920.2723.11.camel@Abyss> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel Cc: "Ian.Campbell" , George Dunlap , Juergen Gross , Ian Jackson List-Id: xen-devel@lists.xenproject.org --===============1683186530190811548== Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-CGSy+IITgneX3cfd+GRi" --=-CGSy+IITgneX3cfd+GRi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Allow for "^" 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 Aff= inity ... 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 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 =3D 0; var < (map).size * 8;= var++) +#define libxl_for_each_set_cpu(v, m) for (v =3D 0; v < (m).size * 8; v++) = \ + if (libxl_cpumap_test(&(m), v= )) =20 int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray); =20 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; } =20 +static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap) +{ + libxl_cpumap exclude_cpumap; + uint32_t cpuida, cpuidb; + char *endptr, *toka, *tokb, *saveptr =3D NULL; + int i, rc =3D 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 =3D strtok_r(cpu, ",", &saveptr); toka; + toka =3D strtok_r(NULL, ",", &saveptr)) { + rmcpu =3D 0; + if (*toka =3D=3D '^') { + /* This (These) Cpu(s) will be removed from the map */ + toka++; + rmcpu =3D 1; + } + /* Extract a valid (range of) cpu(s) */ + cpuida =3D cpuidb =3D strtoul(toka, &endptr, 10); + if (endptr =3D=3D toka) { + fprintf(stderr, "Error: Invalid argument.\n"); + rc =3D EINVAL; + goto vcpp_out; + } + if (*endptr =3D=3D '-') { + tokb =3D endptr + 1; + cpuidb =3D strtoul(tokb, &endptr, 10); + if (endptr =3D=3D tokb || cpuida > cpuidb) { + fprintf(stderr, "Error: Invalid argument.\n"); + rc =3D EINVAL; + goto vcpp_out; + } + } + while (cpuida <=3D cpuidb) { + rmcpu =3D=3D 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; =20 - uint32_t vcpuid, cpuida, cpuidb; - char *endptr, *toka, *tokb; + uint32_t vcpuid; + char *endptr; int i, nb_vcpu; =20 vcpuid =3D 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 =3D strtok(cpu, ","), i =3D 0; toka; toka =3D strtok(NUL= L, ","), ++i) { - cpuida =3D strtoul(toka, &endptr, 10); - if (toka =3D=3D endptr) { - fprintf(stderr, "Error: Invalid argument.\n"); - goto vcpupin_out1; - } - if (*endptr =3D=3D '-') { - tokb =3D endptr + 1; - cpuidb =3D strtoul(tokb, &endptr, 10); - if ((tokb =3D=3D endptr) || (cpuida > cpuidb)) { - fprintf(stderr, "Error: Invalid argument.\n"); - goto vcpupin_out1; - } - while (cpuida <=3D 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; =20 if (vcpuid !=3D -1) { if (libxl_set_vcpuaffinity(ctx, domid, vcpuid, &cpumap) =3D=3D -1)= { --=20 <> (Raistlin Majere) ------------------------------------------------------------------- Dario Faggioli, Ph.D, http://retis.sssup.it/people/faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) --=-CGSy+IITgneX3cfd+GRi Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEABECAAYFAk8gExYACgkQk4XaBE3IOsSh3QCdG2qBF2LSzWVy9DjzSxkdZw9x FGYAoK3vzlfeOpecoFRVZvxYtIt9jafL =PcYJ -----END PGP SIGNATURE----- --=-CGSy+IITgneX3cfd+GRi-- --===============1683186530190811548== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1683186530190811548==--