All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dario Faggioli <dario.faggioli@citrix.com>
To: xen-devel@lists.xen.org
Cc: Andrew.Cooper3@citrix.com, Wei Liu <wei.liu2@citrix.com>,
	Ian.Campbell@citrix.com, Ian.Jackson@citrix.com
Subject: [PATCH v10 08/11] xl: move away from the (deprecated) use of cpumap for hard affinity
Date: Fri, 20 Jun 2014 18:19:56 +0200	[thread overview]
Message-ID: <20140620161955.450.4185.stgit@Solace> (raw)
In-Reply-To: <20140620161751.450.15846.stgit@Solace>

and start using the vcpu_hard_affinity array instead. This comes
with a few bonuses:

 - allows us to unify the parsing of the two was VCPU affinity
   is specified in the domain config file (i.e., cpus="1,3,10-15"
   and cpus=[2, 4, 8]);

 - unifying the parsing makes it possible to do things like this:

      cpus = ["3-4", "2-6"]

   which it was not before. What it means is that VCPU 0 must be
   pinned to PCPU 3,4 and VCPU 1 to PCPUs 2,3,4,5,6. Before this
   change, in fact, the list variant (cpus=[xx, yy]) only supported
   only single values. (Of course, the old [2, 3] syntax continues
   to work, although, without the '"' quotes, it is not possible
   to specify ranges.)

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
---
Changes from v9:
 * new patch, basically containing the xl bits of what was the
   cpumap deprecation patch in v9.
---
 docs/man/xl.cfg.pod.5    |    8 ++++----
 tools/libxl/xl_cmdimpl.c |   47 ++++++++++++++++++++++++----------------------
 2 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5
index c087cbc..af48622 100644
--- a/docs/man/xl.cfg.pod.5
+++ b/docs/man/xl.cfg.pod.5
@@ -143,11 +143,11 @@ Combining this with "all" is also possible, meaning "all,^nodes:1"
 results in all the vcpus of the guest running on all the cpus on the
 host, except for the cpus belonging to the host NUMA node 1.
 
-=item ["2", "3"] (or [2, 3])
+=item ["2", "3-8,^5"]
 
-To ask for specific vcpu mapping. That means (in this example), vcpu #0
-of the guest will run on cpu #2 of the host and vcpu #1 of the guest will
-run on cpu #3 of the host.
+To ask for specific vcpu mapping. That means (in this example), vcpu 0
+of the guest will run on cpu 2 of the host and vcpu 1 of the guest will
+run on cpus 3,4,6,7,8 of the host.
 
 =back
 
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index f2f5fb2..06478a8 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -656,14 +656,16 @@ static int update_cpumap_range(const char *str, libxl_bitmap *cpumap)
 static int vcpupin_parse(const char *cpu, libxl_bitmap *cpumap)
 {
     char *ptr, *saveptr = NULL;
+    char *buf = strdup(cpu);
     int rc = 0;
 
-    for (ptr = strtok_r(cpu, ",", &saveptr); ptr;
+    for (ptr = strtok_r(buf, ",", &saveptr); ptr;
          ptr = strtok_r(NULL, ",", &saveptr)) {
         rc = update_cpumap_range(ptr, cpumap);
         if (rc)
             break;
     }
+    free(buf);
 
     return rc;
 }
@@ -797,17 +799,31 @@ static void parse_config_data(const char *config_source,
     if (!xlu_cfg_get_long (config, "maxvcpus", &l, 0))
         b_info->max_vcpus = l;
 
-    if (!xlu_cfg_get_list (config, "cpus", &cpus, &num_cpus, 1)) {
+    buf = NULL; num_cpus = 0;
+    if (!xlu_cfg_get_list (config, "cpus", &cpus, &num_cpus, 1) ||
+        !xlu_cfg_get_string (config, "cpus", &buf, 0)) {
+        const char *buf2 = NULL; //XXX Trick the compiler!!!
         int j = 0;
 
+        /*
+         * If we are here, and buf is !NULL, we're dealing with a string. What
+         * we do in this case is parse it, and put the result in _all_ (up to
+         * b_info->max_vcpus) the elements of the vcpu affinity array.
+         *
+         * If buf is NULL, we have a list, and what we do is putting in the
+         * i-eth element of the vcpu affinity array the result of the parsing
+         * of the i-eth entry of the list. If there are more vcpus than
+         * entries, it is fine to just not touch the last array elements.
+         */
+
         /* Silently ignore values corresponding to non existing vcpus */
-        if (num_cpus > b_info->max_vcpus)
+        if (num_cpus > b_info->max_vcpus || buf)
             num_cpus = b_info->max_vcpus;
 
         b_info->vcpu_hard_affinity = xmalloc(num_cpus * sizeof(libxl_bitmap));
 
-        while ((buf = xlu_cfg_get_listitem(cpus, j)) != NULL && j < num_cpus) {
-            i = atoi(buf);
+        while ((buf || (buf2 = xlu_cfg_get_listitem(cpus, j)) != NULL) &&
+               j < num_cpus) {
 
             libxl_bitmap_init(&b_info->vcpu_hard_affinity[j]);
             if (libxl_cpu_bitmap_alloc(ctx,
@@ -815,8 +831,10 @@ static void parse_config_data(const char *config_source,
                 fprintf(stderr, "Unable to allocate cpumap for vcpu %d\n", j);
                 exit(1);
             }
-            libxl_bitmap_set_none(&b_info->vcpu_hard_affinity[j]);
-            libxl_bitmap_set(&b_info->vcpu_hard_affinity[j], i);
+
+            if (vcpupin_parse(buf ? buf : buf2,
+                              &b_info->vcpu_hard_affinity[j]))
+                exit(1);
 
             j++;
         }
@@ -825,21 +843,6 @@ static void parse_config_data(const char *config_source,
         /* We have a list of cpumaps, disable automatic placement */
         libxl_defbool_set(&b_info->numa_placement, false);
     }
-    else if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
-        char *buf2 = strdup(buf);
-
-        if (libxl_cpu_bitmap_alloc(ctx, &b_info->cpumap, 0)) {
-            fprintf(stderr, "Unable to allocate cpumap\n");
-            exit(1);
-        }
-
-        libxl_bitmap_set_none(&b_info->cpumap);
-        if (vcpupin_parse(buf2, &b_info->cpumap))
-            exit(1);
-        free(buf2);
-
-        libxl_defbool_set(&b_info->numa_placement, false);
-    }
 
     if (!xlu_cfg_get_long (config, "memory", &l, 0)) {
         b_info->max_memkb = l * 1024;

  parent reply	other threads:[~2014-06-20 16:19 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-20 16:18 [PATCH v10 00/11] Series short description Dario Faggioli
2014-06-20 16:18 ` [PATCH v10 01/11] libxc/libxl: bump library SONAMEs Dario Faggioli
2014-06-20 16:19 ` [PATCH v10 02/11] libxc: get and set soft and hard affinity Dario Faggioli
2014-06-20 16:19 ` [PATCH v10 03/11] libxl: get and set soft affinity Dario Faggioli
2014-06-20 16:19 ` [PATCH v10 04/11] xl: enable getting and setting " Dario Faggioli
2014-06-27 12:33   ` Ian Campbell
2014-06-27 13:18     ` Dario Faggioli
2014-06-27 13:22       ` Ian Campbell
2014-06-27 13:45         ` Dario Faggioli
2014-06-20 16:19 ` [PATCH v10 05/11] libxl: Change default for b_info->{cpu, node}map to "not allocated" Dario Faggioli
2014-06-27 10:44   ` Ian Campbell
2014-06-27 12:07     ` Dario Faggioli
2014-06-27 12:44       ` Ian Campbell
2014-06-20 16:19 ` [PATCH v10 06/11] libxl/xl: push VCPU affinity pinning down to libxl Dario Faggioli
2014-06-27 10:55   ` Ian Campbell
2014-06-20 16:19 ` [PATCH v10 07/11] libxl/xl: deprecate the build_info->cpumap field Dario Faggioli
2014-06-27 10:57   ` Ian Campbell
2014-06-27 12:08     ` Dario Faggioli
2014-06-20 16:19 ` Dario Faggioli [this message]
2014-06-27 11:00   ` [PATCH v10 08/11] xl: move away from the (deprecated) use of cpumap for hard affinity Ian Campbell
2014-06-27 12:24     ` Dario Faggioli
2014-06-20 16:20 ` [PATCH v10 09/11] xl: move the vcpu affinity parsing in a function Dario Faggioli
2014-06-20 16:20 ` [PATCH v10 10/11] libxl/xl: make it possible to specify soft-affinity in domain config file Dario Faggioli
2014-06-27 12:47   ` Ian Campbell
2014-06-27 13:07     ` Dario Faggioli
2014-06-27 16:41     ` Dario Faggioli
2014-06-20 16:20 ` [PATCH v10 11/11] libxl: automatic NUMA placement affects soft affinity Dario Faggioli
2014-06-27 13:32 ` [PATCH v10 00/11] Series short description Ian Campbell

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=20140620161955.450.4185.stgit@Solace \
    --to=dario.faggioli@citrix.com \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.