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

[Xen-devel] [PATCH] libxl: extract and save affinity maps from hypervisor



This is required to retain affinity setting across save/restore and
migration.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/libxl/libxl_domain.c | 46 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c
index 3377bba..24fac9b 100644
--- a/tools/libxl/libxl_domain.c
+++ b/tools/libxl/libxl_domain.c
@@ -1603,16 +1603,18 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, 
uint32_t domid,
 
     /* VCPUs */
     {
-        libxl_bitmap *map = &d_config->b_info.avail_vcpus;
-        unsigned int max_vcpus = d_config->b_info.max_vcpus;
+        libxl_domain_build_info *b_info = &d_config->b_info;
+        libxl_bitmap *map = &b_info->avail_vcpus;
+        unsigned int max_vcpus = b_info->max_vcpus;
         libxl_device_model_version version;
+        int i;
 
         libxl_bitmap_dispose(map);
         libxl_bitmap_init(map);
         libxl_bitmap_alloc(CTX, map, max_vcpus);
         libxl_bitmap_set_none(map);
 
-        switch (d_config->b_info.type) {
+        switch (b_info->type) {
         case LIBXL_DOMAIN_TYPE_HVM:
             version = libxl__device_model_version_running(gc, domid);
             assert(version != LIBXL_DEVICE_MODEL_VERSION_UNKNOWN);
@@ -1642,6 +1644,44 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, 
uint32_t domid,
             LOGD(ERROR, domid, "Fail to update available cpu map");
             goto out;
         }
+
+        /* Affinity maps */
+
+#define REALLOC_AFFINITY_MAP(n)                                               \
+        for (i = 0; i < b_info->num_vcpu_ ## n ## _affinity; i++) {           \
+            libxl_bitmap *m = &b_info->vcpu_ ## n ## _affinity[i];            \
+            libxl_bitmap_dispose(m);                                          \
+            libxl_bitmap_init(m);                                             \
+            libxl_cpu_bitmap_alloc(CTX, m, 0);                                \
+        }                                                                     \
+        b_info->vcpu_ ## n ## _affinity =                                     \
+            libxl__realloc(NOGC, b_info->vcpu_ ## n ## _affinity,             \
+                    max_vcpus * sizeof(b_info->vcpu_ ## n ## _affinity[0]));  \
+        for (i = b_info->num_vcpu_ ## n ## _affinity; i < max_vcpus; i++) {   \
+            libxl_bitmap *m = &b_info->vcpu_ ## n ## _affinity[i];            \
+            libxl_bitmap_init(m);                                             \
+            libxl_cpu_bitmap_alloc(CTX, m, 0);                                \
+        }                                                                     \
+        b_info->num_vcpu_ ## n ## _affinity = max_vcpus;
+
+        REALLOC_AFFINITY_MAP(hard);
+        REALLOC_AFFINITY_MAP(soft);
+
+#undef REALLOC_AFFINITY_MAP
+
+        /* Get current maps from hypervisor */
+        for (i = 0; i < max_vcpus; i++) {
+            libxl_bitmap *hard = &b_info->vcpu_hard_affinity[i];
+            libxl_bitmap *soft = &b_info->vcpu_soft_affinity[i];
+
+            if (xc_vcpu_getaffinity(CTX->xch, domid, i, hard->map, soft->map,
+                XEN_VCPUAFFINITY_SOFT|XEN_VCPUAFFINITY_HARD) == -1) {
+                LOGED(ERROR, domid, "Getting vcpu affinity");
+                rc = ERROR_FAIL;
+                goto out;
+            }
+        }
+
     }
 
     /* Memory limits:

base-commit: 94b8b2e09290cca0fcd8afd930f7f083458b1afe
-- 
git-series 0.9.1

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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