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

[libvirt] [PATCH v2.1 13/21] Introduce virDomainEmulatorPinAdd and virDomainEmulatorPinDel functions



From: Tang Chen <tangchen cn fujitsu com>

Introduce 2 APIs to support emulator threads pin.
    1) virDomainEmulatorPinAdd: setup emulator threads pin with a given cpumap string.
    2) virDomainEmulatorPinDel: remove all emulator threads pin.

Signed-off-by: Tang Chen <tangchen cn fujitsu com>
Signed-off-by: Hu Tao <hutao cn fujitsu com>
---
 src/conf/domain_conf.c   |   71 ++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |    6 ++++
 src/libvirt_private.syms |    2 ++
 3 files changed, 79 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 94ec095..dab9c5d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11076,6 +11076,77 @@ virDomainVcpuPinDel(virDomainDefPtr def, int vcpu)
     return 0;
 }
 
+int
+virDomainEmulatorPinAdd(virDomainDefPtr def,
+                        unsigned char *cpumap,
+                        int maplen)
+{
+    virDomainVcpuPinDefPtr emulatorpin = NULL;
+    char *cpumask = NULL;
+    int i;
+
+    if (VIR_ALLOC_N(cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    /* Convert bitmap (cpumap) to cpumask, which is byte map. */
+    for (i = 0; i < maplen; i++) {
+        int cur;
+
+        for (cur = 0; cur < 8; cur++) {
+            if (cpumap[i] & (1 << cur))
+                cpumask[i * 8 + cur] = 1;
+        }
+    }
+
+    if (!def->cputune.emulatorpin) {
+        /* No emulatorpin exists yet. */
+        if (VIR_ALLOC(emulatorpin) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        emulatorpin->vcpuid = -1;
+        emulatorpin->cpumask = cpumask;
+        def->cputune.emulatorpin = emulatorpin;
+    } else {
+        /* Since there is only 1 emulatorpin for each vm,
+         * juest replace the old one.
+         */
+        VIR_FREE(def->cputune.emulatorpin->cpumask);
+        def->cputune.emulatorpin->cpumask = cpumask;
+    }
+
+    return 0;
+
+cleanup:
+    VIR_FREE(cpumask);
+    return -1;
+}
+
+int
+virDomainEmulatorPinDel(virDomainDefPtr def)
+{
+    virDomainVcpuPinDefPtr emulatorpin = NULL;
+
+    /* No emulatorpin exists yet */
+    if (!def->cputune.emulatorpin) {
+        return 0;
+    }
+
+    emulatorpin = def->cputune.emulatorpin;
+
+    VIR_FREE(emulatorpin->cpumask);
+    VIR_FREE(emulatorpin);
+    def->cputune.emulatorpin = NULL;
+
+    if (def->cputune.emulatorpin)
+        return -1;
+
+    return 0;
+}
+
 static int
 virDomainLifecycleDefFormat(virBufferPtr buf,
                             int type,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a7b2ff6..b6bf5a8 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1982,6 +1982,12 @@ int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr *vcpupin_list,
 
 int virDomainVcpuPinDel(virDomainDefPtr def, int vcpu);
 
+int virDomainEmulatorPinAdd(virDomainDefPtr def,
+                              unsigned char *cpumap,
+                              int maplen);
+
+int virDomainEmulatorPinDel(virDomainDefPtr def);
+
 int virDomainDiskIndexByName(virDomainDefPtr def, const char *name,
                              bool allow_ambiguous);
 const char *virDomainDiskPathByName(virDomainDefPtr, const char *name);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 80ea39a..d51a387 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -509,6 +509,8 @@ virDomainVcpuPinAdd;
 virDomainVcpuPinDefCopy;
 virDomainVcpuPinDefFree;
 virDomainVcpuPinDel;
+virDomainEmulatorPinAdd;
+virDomainEmulatorPinDel;
 virDomainVcpuPinFindByVcpu;
 virDomainVcpuPinIsDuplicate;
 virDomainVideoDefFree;
-- 
1.7.10.2


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