From 151eee5a062bfb38f2dff694b162e1c3ebb65782 Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Tue, 21 Aug 2012 17:18:36 +0800 Subject: [PATCH] Introduce virDomainEmulatorPinAdd and virDomainEmulatorPinDel functions 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 Signed-off-by: Hu Tao --- 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 304ab88e78..9e97301374 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11124,6 +11124,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 8cd685e4c3..5a02323ea7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1998,6 +1998,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 6b9eded51c..8962de2ed9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -345,6 +345,8 @@ virDomainDiskSnapshotTypeFromString; virDomainDiskSnapshotTypeToString; virDomainDiskTypeFromString; virDomainDiskTypeToString; +virDomainEmulatorPinAdd; +virDomainEmulatorPinDel; virDomainFSDefFree; virDomainFSIndexByName; virDomainFSTypeFromString;