Skip to contentSkip to conversation

CPU hotplug for qemu-xen

PATCH In review Anthony PERARD 2 participants 6 messages Jun 26, 2013

lore
Share & tools
lore
#0 lore raw

v5 cover CPU hotplug for qemu-xen

Hi all,

This series implements the 'cpu-add' QMP command to hotplug CPU with qemu-xen.

When using adding vcpus with this series, libxl will report many "error". This is because libxl call the QMP command 'cpu-add' for every plugged vcpus, even those that have been plugged before. There is currently no way to list cpus that are plugged by QEMU. Also, the way errors are handled by libxl_qmp those not help yet to suppress this error printing.

Unplug of vcpu is not supported by the series.

v5:
- added a comment about the ignored return value
v4:
- ignore the return value of libxl__qmp_cpu_add as it those not give any usefull information.

And before (v2-v3):
- use more and different macro in the libxl patch.

Anthony PERARD (2):
libxl: Add "cpu-add" QMP command.
libxl: Use QMP cpu-add to hotplug CPU with qemu-xen.

 tools/libxl/libxl.c          | 52 +++++++++++++++++++++++++++++++++++++++-----
 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_qmp.c      | 21 ++++++++++++++++++
 3 files changed, 69 insertions(+), 6 deletions(-)
Signature · 1 line
Anthony PERARD
#1 lore raw

PATCH v5 1/2 libxl: Add "cpu-add" QMP command.

---
 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_qmp.c      | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)
tools/libxl/libxl_internal.h +2 -0
index 3ba3a21..3e45b94 100644
@@ -1412,6 +1412,8 @@ _hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename);
 /* Set dirty bitmap logging status */
 _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable);
 _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk);
+/* Add a virtual CPU */
+_hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index);
 /* close and free the QMP handler */
 _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);
 /* remove the socket file, if the file has already been removed,
tools/libxl/libxl_qmp.c +21 -0
index 644d2c0..3d6dec6 100644
@@ -668,6 +668,18 @@ static void qmp_parameters_add_bool(libxl__gc *gc,
     qmp_parameters_common_add(gc, param, name, obj);
 }
 
+static void qmp_parameters_add_integer(libxl__gc *gc,
+                                       libxl__json_object **param,
+                                       const char *name, const int i)
+{
+    libxl__json_object *obj;
+
+    obj = libxl__json_object_alloc(gc, JSON_INTEGER);
+    obj->u.i = i;
+
+    qmp_parameters_common_add(gc, param, name, obj);
+}
+
 #define QMP_PARAMETERS_SPRINTF(args, name, format, ...) \
     qmp_parameters_add_string(gc, args, name, \
                               libxl__sprintf(gc, format, __VA_ARGS__))
@@ -929,6 +941,15 @@ int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid,
     }
 }
 
+int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index)
+{
+    libxl__json_object *args = NULL;
+
+    qmp_parameters_add_integer(gc, &args, "id", index);
+
+    return qmp_run_command(gc, domid, "cpu-add", args, NULL, NULL);
+}
+
 int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
                                const libxl_domain_config *guest_config)
 {
Signature · 1 line
Anthony PERARD
#2 lore raw

Re: [PATCH v5 1/2] libxl: Add "cpu-add" QMP command.

Quoted 1 line · Anthony PERARD

+int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index)

libxl_qmp.c: In function ‘libxl__qmp_cpu_add’:
libxl_qmp.c:944:54: error: declaration of ‘index’ shadows a global declaration [-Werror=shadow]
cc1: all warnings being treated as errors

index() is a function in <strings.h>

I'll s/index/idx/ as I apply.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v5 1/2] libxl: Add "cpu-add" QMP command.

Quoted 10 lines · Ian Campbell
Quoted 1 line · Anthony PERARD

+int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index)

libxl_qmp.c: In function ‘libxl__qmp_cpu_add’:
libxl_qmp.c:944:54: error: declaration of ‘index’ shadows a global declaration [-Werror=shadow]
cc1: all warnings being treated as errors

index() is a function in <strings.h>

I'll s/index/idx/ as I apply.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw

PATCH v5 2/2 libxl: Use QMP cpu-add to hotplug CPU with qemu-xen.

In reply to Anthony PERARD
---
 tools/libxl/libxl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 6 deletions(-)
tools/libxl/libxl.c +46 -6
index ee1fa9c..185dfba 100644
@@ -4237,33 +4237,73 @@ int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,
     return 0;
 }
 
-int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)
+static int libxl__set_vcpuonline_xenstore(libxl__gc *gc, uint32_t domid,
+                                         libxl_bitmap *cpumap)
 {
-    GC_INIT(ctx);
     libxl_dominfo info;
     char *dompath;
     xs_transaction_t t;
     int i, rc = ERROR_FAIL;
 
-    if (libxl_domain_info(ctx, &info, domid) < 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain info list");
+    if (libxl_domain_info(CTX, &info, domid) < 0) {
+        LOGE(ERROR, "getting domain info list");
         goto out;
     }
     if (!(dompath = libxl__xs_get_dompath(gc, domid)))
         goto out;
 
 retry_transaction:
-    t = xs_transaction_start(ctx->xsh);
+    t = xs_transaction_start(CTX->xsh);
     for (i = 0; i <= info.vcpu_max_id; i++)
         libxl__xs_write(gc, t,
                        libxl__sprintf(gc, "%s/cpu/%u/availability", dompath, i),
                        "%s", libxl_bitmap_test(cpumap, i) ? "online" : "offline");
-    if (!xs_transaction_end(ctx->xsh, t, 0)) {
+    if (!xs_transaction_end(CTX->xsh, t, 0)) {
         if (errno == EAGAIN)
             goto retry_transaction;
     } else
         rc = 0;
 out:
+    return rc;
+}
+
+static int libxl__set_vcpuonline_qmp(libxl__gc *gc, uint32_t domid,
+                                     libxl_bitmap *cpumap)
+{
+    libxl_dominfo info;
+    int i;
+
+    if (libxl_domain_info(CTX, &info, domid) < 0) {
+        LOGE(ERROR, "getting domain info list");
+        return ERROR_FAIL;
+    }
+    for (i = 0; i <= info.vcpu_max_id; i++) {
+        if (libxl_bitmap_test(cpumap, i)) {
+            /* Return value is ignore because it does not tell anything useful
+             * on the completion of the command.
+             * (For instance, "CPU already plugged-in" give the same return
+             * value as "command not supported".)
+             */
+            libxl__qmp_cpu_add(gc, domid, i);
+        }
+    }
+    return 0;
+}
+
+int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)
+{
+    GC_INIT(ctx);
+    int rc;
+    switch (libxl__device_model_version_running(gc, domid)) {
+    case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
+        rc = libxl__set_vcpuonline_xenstore(gc, domid, cpumap);
+        break;
+    case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
+        rc = libxl__set_vcpuonline_qmp(gc, domid, cpumap);
+        break;
+    default:
+        rc = ERROR_INVAL;
+    }
     GC_FREE;
     return rc;
 }
Signature · 1 line
Anthony PERARD
#5 lore raw
In reply to Anthony PERARD
Quoted 3 lines · Anthony PERARD

Hi all,

This series implements the 'cpu-add' QMP command to hotplug CPU with qemu-xen.

Acked the second one + applied both, thanks.

Ian.