From: Tang Chen <tangchen@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx> Signed-off-by: Hu Tao <hutao@xxxxxxxxxxxxxx> --- src/conf/domain_conf.c | 73 +++++++++++++++++++++++++++++++++++++++++++++- src/conf/domain_conf.h | 6 ++++ src/libvirt_private.syms | 2 ++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1319362..7bd32a2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10974,6 +10974,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, @@ -12893,7 +12964,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, VIR_DOMAIN_CPUMASK_LEN); if (cpumask == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("failed to format cpuset for hypervisor")); + "%s", _("failed to format cpuset for emulator")); goto cleanup; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ac10323..c3acd13 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1977,6 +1977,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 29eaef5..b718ba6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -506,6 +506,8 @@ virDomainVcpuPinAdd; virDomainVcpuPinDefCopy; virDomainVcpuPinDefFree; virDomainVcpuPinDel; +virDomainEmulatorPinAdd; +virDomainEmulatorPinDel; virDomainVcpuPinFindByVcpu; virDomainVcpuPinIsDuplicate; virDomainVideoDefFree; -- 1.7.10.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list