All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dario Faggioli <dario.faggioli@citrix.com>
To: xen-devel@lists.xen.org
Cc: keir@xen.org, Ian.Campbell@citrix.com, Andrew.Cooper3@citrix.com,
	George.Dunlap@citrix.com, JBeulich@suse.com,
	Ian.Jackson@citrix.com, Wei Liu <wei.liu2@citrix.com>
Subject: [PATCH v8 12/13] xl: enable for specifying soft-affinity in the config file
Date: Fri, 13 Jun 2014 15:10:44 +0200	[thread overview]
Message-ID: <20140613131044.4106.9707.stgit@Solace> (raw)
In-Reply-To: <20140613124847.4106.70161.stgit@Solace>

in a similar way to how hard-affinity is specified (i.e.,
exactly how plain vcpu-affinity was being specified before
this change).

To do so, we add a vcpu_soft_affinity array to build_info,
and treat it much like vcpu_hard_affinity. The new config
option is called "cpus_soft".

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
---
Changes from v7:
 * WARNING: this patch underwent quite a fundamental rework,
   given it's now building on top of Wei's "push vcpu affinity
   to libxl" patch. That's why I think it should be re-reviewed
   almost from scratch (sorry! :-P), and that's why I did not
   add IanC's ack, although he provided it to the v7 version
   of it.

Changes from v6:
 * update and improve the changelog.

Changes from v4:
 * fix typos and rephrase docs, as suggested during review;
 * more refactoring, i.e., more addressing factor of potential
   common code, as requested during review.

Changes from v3:
 * fix typos and language issues in docs and comments, as
   suggested during review;
 * common code to soft and hard affinity parsing factored
   together, as requested uring review.

Changes from v2:
 * use the new libxl API. Although the implementation changed
   only a little bit, I removed IanJ's Acked-by, although I am
   here saying that he did provided it, as requested.
---
 docs/man/xl.cfg.pod.5       |   23 ++++++++++++++++++++---
 tools/libxl/libxl.h         |   14 ++++++++++++++
 tools/libxl/libxl_dom.c     |   19 +++++++++++++------
 tools/libxl/libxl_types.idl |    1 +
 tools/libxl/xl_cmdimpl.c    |   40 +++++++++++++++++++++++++++-------------
 5 files changed, 75 insertions(+), 22 deletions(-)

diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5
index af48622..25a4ff7 100644
--- a/docs/man/xl.cfg.pod.5
+++ b/docs/man/xl.cfg.pod.5
@@ -152,19 +152,36 @@ run on cpus 3,4,6,7,8 of the host.
 =back
 
 If this option is not specified, no vcpu to cpu pinning is established,
-and the vcpus of the guest can run on all the cpus of the host.
+and the vcpus of the guest can run on all the cpus of the host. If this
+option is specified, the intersection of the vcpu pinning mask, provided
+here, and the soft affinity mask, provided via B<cpus\_soft=> (if any),
+is utilized to compute the domain node-affinity, for driving memory
+allocations.
 
 If we are on a NUMA machine (i.e., if the host has more than one NUMA
 node) and this option is not specified, libxl automatically tries to
 place the guest on the least possible number of nodes. That, however,
 will not affect vcpu pinning, so the guest will still be able to run on
-all the cpus, it will just prefer the ones from the node it has been
-placed on. A heuristic approach is used for choosing the best node (or
+all the cpus. A heuristic approach is used for choosing the best node (or
 set of nodes), with the goals of maximizing performance for the guest
 and, at the same time, achieving efficient utilization of host cpus
 and memory. See F<docs/misc/xl-numa-placement.markdown> for more
 details.
 
+=item B<cpus_soft="CPU-LIST">
+
+Exactly as B<cpus=>, but specifies soft affinity, rather than pinning
+(hard affinity). When using the credit scheduler, this means what cpus
+the vcpus of the domain prefer.
+
+A C<CPU-LIST> is specified exactly as above, for B<cpus=>.
+
+If this option is not specified, the vcpus of the guest will not have
+any preference regarding on what cpu to run. If this option is specified,
+the intersection of the soft affinity mask, provided here, and the vcpu
+pinning, provided via B<cpus=> (if any), is utilized to compute the
+domain node-affinity, for driving memory allocations.
+
 =back
 
 =head3 CPU Scheduling
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 663abe2..a7c60a4 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -353,6 +353,20 @@
 #define LIBXL_HAVE_BUILDINFO_VCPU_HARD_AFFINITY_ARRAY 1
 
 /*
+ * LIBXL_HAVE_BUILDINFO_VCPU_SOFT_AFFINITY_ARRAY
+ *
+ * If this is defined, then libxl_domain_build_info structure will
+ * contain vcpu_soft_affinity, an array of libxl_bitmap that contains
+ * the necessary information to set the soft affinity of each VCPU to
+ * a set of PCPUs.
+ *
+ * The number of libxl_bitmap in the array equals to the maximum number
+ * of VCPUs. The size of each bitmap is computed basing on the maximum
+ * number of PCPUs.
+ */
+#define LIBXL_HAVE_BUILDINFO_VCPU_HARD_AFFINITY_ARRAY 1
+
+/*
  * LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST
  *
  * If this is defined, then the libxl_domain_build_info structure will
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 0b00470..9874dc4 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -262,14 +262,21 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     }
     libxl_domain_set_nodeaffinity(ctx, domid, &info->nodemap);
 
-    /* If we have the vcpu hard affinity list, honour it */
-    if (d_config->b_info.num_vcpu_hard_affinity) {
+    /* If we have the vcpu hard and/or soft affinity list, honour it/them */
+    if (d_config->b_info.num_vcpu_hard_affinity ||
+        d_config->b_info.num_vcpu_soft_affinity) {
         int i;
 
-        for (i = 0; i < d_config->b_info.num_vcpu_hard_affinity; i++) {
-            if (libxl_set_vcpuaffinity(ctx, domid, i,
-                                       &d_config->b_info.vcpu_hard_affinity[i],
-                                       NULL)) {
+        for (i = 0; i < d_config->b_info.max_vcpus; i++) {
+            libxl_bitmap *hard_affinity, *soft_affinity;
+
+            hard_affinity = d_config->b_info.num_vcpu_hard_affinity ?
+                &d_config->b_info.vcpu_hard_affinity[i] : NULL;
+            soft_affinity = d_config->b_info.num_vcpu_soft_affinity ?
+                &d_config->b_info.vcpu_soft_affinity[i] : NULL;
+
+            if (libxl_set_vcpuaffinity(ctx, domid, i, hard_affinity,
+                                       soft_affinity)) {
                 LOG(ERROR, "setting affinity failed on vcpu `%d'", i);
                 return ERROR_FAIL;
             }
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index cd5c0d4..1744b00 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -304,6 +304,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
     # is indeed harmless, but won't produce any actual effect on the domain.
     ("nodemap",         libxl_bitmap),
     ("vcpu_hard_affinity", Array(libxl_bitmap, "num_vcpu_hard_affinity")),
+    ("vcpu_soft_affinity", Array(libxl_bitmap, "num_vcpu_soft_affinity")),
     ("numa_placement",  libxl_defbool),
     ("tsc_mode",        libxl_tsc_mode),
     ("max_memkb",       MemKB),
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index d08a149..d0a8557 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -693,22 +693,32 @@ static void parse_top_level_sdl_options(XLU_Config *config,
 }
 
 static void parse_vcpu_affinity(XLU_Config *config, XLU_ConfigList *cpus,
-                                const char *buf, libxl_domain_build_info *info)
+                                const char *buf, libxl_domain_build_info *info,
+                                bool is_hard)
 {
-    info->num_vcpu_hard_affinity = info->max_vcpus;
     const char *buf2;
+    libxl_bitmap *vcpu_affinity_array;
     int i;
 
-    info->vcpu_hard_affinity =
-        xmalloc(info->num_vcpu_hard_affinity * sizeof(libxl_bitmap));
+    if (is_hard) {
+        info->num_vcpu_hard_affinity = info->max_vcpus;
+        info->vcpu_hard_affinity =
+            xmalloc(info->max_vcpus * sizeof(libxl_bitmap));
+        vcpu_affinity_array = info->vcpu_hard_affinity;
+    } else {
+        info->num_vcpu_soft_affinity = info->max_vcpus;
+        info->vcpu_soft_affinity =
+            xmalloc(info->max_vcpus * sizeof(libxl_bitmap));
+        vcpu_affinity_array = info->vcpu_soft_affinity;
+    }
 
-    for (i = 0; i < info->num_vcpu_hard_affinity; i++) {
-        libxl_bitmap_init(&info->vcpu_hard_affinity[i]);
-        if (libxl_cpu_bitmap_alloc(ctx, &info->vcpu_hard_affinity[i], 0)) {
+    for (i = 0; i < info->max_vcpus; i++) {
+        libxl_bitmap_init(&vcpu_affinity_array[i]);
+        if (libxl_cpu_bitmap_alloc(ctx, &vcpu_affinity_array[i], 0)) {
             fprintf(stderr, "Unable to allocate cpumap for vcpu %d\n", i);
             exit(1);
         }
-        libxl_bitmap_set_none(&info->vcpu_hard_affinity[i]);
+        libxl_bitmap_set_none(&vcpu_affinity_array[i]);
     }
 
     /*
@@ -720,13 +730,12 @@ static void parse_vcpu_affinity(XLU_Config *config, XLU_ConfigList *cpus,
      * vcpus than elements, the missing ones have their affinity masks
      * completely full).
      */
-    for (i = 0; i < info->num_vcpu_hard_affinity; i++) {
+    for (i = 0; i < info->max_vcpus; i++) {
         if (buf || ((buf2 = xlu_cfg_get_listitem(cpus, i)) != NULL)) {
-            if (vcpupin_parse(buf ? buf : buf2,
-                              &info->vcpu_hard_affinity[i]))
+            if (vcpupin_parse(buf ? buf : buf2, &vcpu_affinity_array[i]))
                 exit(1);
         } else
-            libxl_bitmap_set_any(&info->vcpu_hard_affinity[i]);
+            libxl_bitmap_set_any(&vcpu_affinity_array[i]);
     }
 
     /* We have a list of cpumaps, disable automatic placement */
@@ -867,7 +876,12 @@ static void parse_config_data(const char *config_source,
     buf = NULL;
     if (!xlu_cfg_get_list (config, "cpus", &cpus, 0, 1) ||
         !xlu_cfg_get_string (config, "cpus", &buf, 0))
-        parse_vcpu_affinity(config, cpus, buf, b_info);
+        parse_vcpu_affinity(config, cpus, buf, b_info, /* is_hard */ true);
+
+    buf = NULL;
+    if (!xlu_cfg_get_list (config, "cpus_soft", &cpus, 0, 1) ||
+        !xlu_cfg_get_string (config, "cpus_soft", &buf, 0))
+        parse_vcpu_affinity(config, cpus, buf, b_info, /* is_hard */ false);
 
     if (!xlu_cfg_get_long (config, "memory", &l, 0)) {
         b_info->max_memkb = l * 1024;

  parent reply	other threads:[~2014-06-13 13:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-13 13:09 [PATCH v8 00/13] Implement vcpu soft affinity for credit1 Dario Faggioli
2014-06-13 13:09 ` [PATCH v8 01/13] xen: sched: rename v->cpu_affinity into v->cpu_hard_affinity Dario Faggioli
2014-06-13 13:09 ` [PATCH v8 02/13] xen: sched: introduce soft-affinity and use it instead d->node-affinity Dario Faggioli
2014-06-13 13:09 ` [PATCH v8 03/13] xen: derive NUMA node affinity from hard and soft CPU affinity Dario Faggioli
2014-06-13 13:09 ` [PATCH v8 04/13] xen/libxc: sched: DOMCTL_*vcpuaffinity works with hard and soft affinity Dario Faggioli
2014-06-13 13:09 ` [PATCH v8 05/13] libxc/libxl: bump library SONAMEs Dario Faggioli
2014-06-13 13:09 ` [PATCH v8 06/13] libxc: get and set soft and hard affinity Dario Faggioli
2014-06-13 13:10 ` [PATCH v8 07/13] libxl: get and set soft affinity Dario Faggioli
2014-06-13 13:10 ` [PATCH v8 08/13] xl: enable getting and setting " Dario Faggioli
2014-06-13 13:10 ` [PATCH v8 09/13] libxl/xl: push VCPU affinity pinning down to libxl Dario Faggioli
2014-06-13 13:25   ` Wei Liu
2014-06-17 10:09     ` Dario Faggioli
2014-06-13 13:10 ` [PATCH v8 10/13] libxl/xl: deprecate the build_info->cpumap field Dario Faggioli
2014-06-13 13:34   ` Wei Liu
2014-06-13 13:38     ` Ian Campbell
2014-06-17 10:11       ` Dario Faggioli
2014-06-13 13:49     ` Wei Liu
2014-06-17  9:59       ` Dario Faggioli
2014-06-17 10:16   ` Wei Liu
2014-06-17 10:29     ` Dario Faggioli
2014-06-17 10:45       ` Wei Liu
2014-06-13 13:10 ` [PATCH v8 11/13] xl: move the vcpu affinity parsing in a function Dario Faggioli
2014-06-13 13:10 ` Dario Faggioli [this message]
2014-06-17 10:34   ` [PATCH v8 12/13] xl: enable for specifying soft-affinity in the config file Wei Liu
2014-06-13 13:10 ` [PATCH v8 13/13] libxl: automatic NUMA placement affects soft affinity 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=20140613131044.4106.9707.stgit@Solace \
    --to=dario.faggioli@citrix.com \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=George.Dunlap@citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=keir@xen.org \
    --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.