[PATCH v3 5/7] qemu migration: add multithread compression options

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

 



Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
 include/libvirt/libvirt-domain.h | 25 ++++++++++++++++++++++++-
 src/qemu/qemu_domain.c           |  3 +++
 src/qemu/qemu_domain.h           |  1 +
 src/qemu/qemu_driver.c           | 27 ++++++++++++++++++++++++++-
 src/qemu/qemu_migration.c        | 36 ++++++++++++++++++++++++++++++++++--
 src/qemu/qemu_migration.h        |  6 ++++++
 6 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index e868515..36f6e09 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -764,9 +764,32 @@ typedef enum {
  * that are used to compress migration traffic. Note that this option cannot
  * be used together with VIR_MIGRATE_COMPRESSED flag, use only one of them.
  */
-
 # define VIR_MIGRATE_PARAM_COMPRESSION    "compression"
 
+/**
+ * VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL:
+ *
+ * virDomainMigrate* params field: the level of compression for multithread
+ * compression as VIR_TYPED_PARAM_INT. Accepted values * are in range 0-9.
+ * 0 is no compression, 1 is maximum speed and 9 is maximum compression.
+ */
+# define VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL    "compression.mt.level"
+
+/**
+ * VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS:
+ *
+ * virDomainMigrate* params field: the number of compression threads for
+ * multithread compression as VIR_TYPED_PARAM_UINT.
+ */
+# define VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS "compression.mt.threads"
+
+/**
+ * VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS:
+ *
+ * virDomainMigrate* params field: the number of decompression threads for
+ * multithread compression as VIR_TYPED_PARAM_UINT.
+ */
+# define VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS "compression.mt.dthreads"
 
 /* Domain migration. */
 virDomainPtr virDomainMigrate (virDomainPtr domain, virConnectPtr dconn,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 1df1b74..03ddee2 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -491,6 +491,9 @@ qemuDomainObjPrivateAlloc(void)
         goto error;
 
     priv->migMaxBandwidth = QEMU_DOMAIN_MIG_BANDWIDTH_MAX;
+    priv->migrationMT.level = 1;
+    priv->migrationMT.threads = 8;
+    priv->migrationMT.dthreads = 2;
 
     return priv;
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 7fc4fff..48554cd 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -182,6 +182,7 @@ struct _qemuDomainObjPrivate {
     int nbdPort; /* Port used for migration with NBD */
     unsigned short migrationPort;
     int preMigrationState;
+    qemuMonitorMigrationMTParameters migrationMT;
 
     virChrdevsPtr devs;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 129da6d..eb3fd80 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12418,7 +12418,7 @@ qemuGetCompression(virTypedParameterPtr params, int nparams,
 {
     size_t i;
 
-    memset(compression, 0, sizeof(*compression));
+    qemuMigrationCompressionInit(compression);
 
     for (i = 0; i < nparams; i++) {
         if (STRNEQ(params[i].field, VIR_MIGRATE_PARAM_COMPRESSION))
@@ -12448,6 +12448,31 @@ qemuGetCompression(virTypedParameterPtr params, int nparams,
         }
     }
 
+    if ((virTypedParamsGet(params, nparams,
+                VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL) != NULL ||
+        virTypedParamsGet(params, nparams,
+                VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS) != NULL ||
+        virTypedParamsGet(params, nparams,
+                VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS) != NULL) &&
+        !(compression->method & QEMU_MIGRATION_COMPESS_MULTITHREAD)) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("You cannot specify multithread compression "
+                          "parameters without turning it on."));
+        return -1;
+    }
+
+    if (virTypedParamsGetInt(params, nparams,
+                             VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL,
+                             &compression->mt.level) < 0 ||
+        virTypedParamsGetUInt(params, nparams,
+                             VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS,
+                             &compression->mt.threads) < 0 ||
+        virTypedParamsGetUInt(params, nparams,
+                             VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS,
+                             &compression->mt.dthreads) < 0) {
+        return -1;
+    }
+
     return 0;
 }
 
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d37e416..81ff6b3 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3307,9 +3307,12 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver,
                             unsigned int flags)
 {
     qemuMigrationCompression deflt;
+    qemuMigrationCompression merged;
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    int ret = -1;
 
     if (!compression) {
-        memset(&deflt, 0, sizeof(deflt));
+        qemuMigrationCompressionInit(&deflt);
         if (flags & VIR_MIGRATE_COMPRESSED)
             deflt.method = QEMU_MIGRATION_COMPESS_XBZRLE;
         compression = &deflt;
@@ -3327,7 +3330,30 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver,
                                job) < 0)
         return -1;
 
-    return 0;
+    merged.mt.level = compression->mt.level != -1 ?
+                                            compression->mt.level :
+                                            priv->migrationMT.level;
+    merged.mt.threads = compression->mt.threads != 0 ?
+                                            compression->mt.threads:
+                                            priv->migrationMT.threads;
+    merged.mt.dthreads = compression->mt.dthreads != 0 ?
+                                            compression->mt.dthreads :
+                                            priv->migrationMT.dthreads;
+
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0)
+        return -1;
+
+    if ((compression->method & QEMU_MIGRATION_COMPESS_MULTITHREAD) &&
+        qemuMonitorSetMigrationCompressParametersMT(priv->mon, &merged.mt) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        ret = -1;
+
+    return ret;
 }
 
 static int
@@ -6358,3 +6384,9 @@ qemuMigrationErrorReport(virQEMUDriverPtr driver,
     virSetError(err);
     virFreeError(err);
 }
+
+void qemuMigrationCompressionInit(qemuMigrationCompressionPtr compression)
+{
+        memset(compression, 0, sizeof(*compression));
+        compression->mt.level = -1;
+}
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 45de616..63c6a1a 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -58,6 +58,9 @@ typedef qemuMigrationCompression *qemuMigrationCompressionPtr;
                                         VIR_TYPED_PARAM_MULTIPLE, \
     VIR_MIGRATE_PARAM_COMPRESSION,      VIR_TYPED_PARAM_STRING |  \
                                         VIR_TYPED_PARAM_MULTIPLE, \
+    VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL,         VIR_TYPED_PARAM_INT,   \
+    VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS,       VIR_TYPED_PARAM_UINT,   \
+    VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS,      VIR_TYPED_PARAM_UINT,   \
     NULL
 
 
@@ -84,8 +87,11 @@ typedef enum {
 
 struct _qemuMigrationCompression {
     qemuMigrationCompressMethod method;
+    qemuMonitorMigrationMTParameters mt;
 };
 
+void qemuMigrationCompressionInit(qemuMigrationCompressionPtr compression);
+
 int qemuMigrationJobStart(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           qemuDomainAsyncJob job)
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]