mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
conf: Refactor emulatorpin handling
Store the emulator pinning cpu mask as a pure virBitmap rather than the virDomainPinDef since it stores only the bitmap and refactor qemuDomainPinEmulator to do the same operations in a much saner way. As a side effect virDomainEmulatorPinAdd and virDomainEmulatorPinDel can be removed since they don't add any value.
This commit is contained in:
parent
ff4c42ed7a
commit
ee3da892f2
@ -2474,7 +2474,7 @@ void virDomainDefFree(virDomainDefPtr def)
|
|||||||
|
|
||||||
virDomainPinDefArrayFree(def->cputune.vcpupin, def->cputune.nvcpupin);
|
virDomainPinDefArrayFree(def->cputune.vcpupin, def->cputune.nvcpupin);
|
||||||
|
|
||||||
virDomainPinDefFree(def->cputune.emulatorpin);
|
virBitmapFree(def->cputune.emulatorpin);
|
||||||
|
|
||||||
for (i = 0; i < def->cputune.nvcpusched; i++)
|
for (i = 0; i < def->cputune.nvcpusched; i++)
|
||||||
virBitmapFree(def->cputune.vcpusched[i].ids);
|
virBitmapFree(def->cputune.vcpusched[i].ids);
|
||||||
@ -13569,36 +13569,26 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Parse the XML definition for emulatorpin.
|
/* Parse the XML definition for emulatorpin.
|
||||||
* emulatorpin has the form of
|
* emulatorpin has the form of
|
||||||
* <emulatorpin cpuset='0'/>
|
* <emulatorpin cpuset='0'/>
|
||||||
*/
|
*/
|
||||||
static virDomainPinDefPtr
|
static virBitmapPtr
|
||||||
virDomainEmulatorPinDefParseXML(xmlNodePtr node)
|
virDomainEmulatorPinDefParseXML(xmlNodePtr node)
|
||||||
{
|
{
|
||||||
virDomainPinDefPtr def;
|
virBitmapPtr def = NULL;
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!(tmp = virXMLPropString(node, "cpuset"))) {
|
if (!(tmp = virXMLPropString(node, "cpuset"))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("missing cpuset for emulatorpin"));
|
_("missing cpuset for emulatorpin"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virBitmapParse(tmp, 0, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
ignore_value(virBitmapParse(tmp, 0, &def, VIR_DOMAIN_CPUMASK_LEN));
|
||||||
goto error;
|
|
||||||
|
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
error:
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
VIR_FREE(def);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -17768,50 +17758,6 @@ virDomainPinDel(virDomainPinDefPtr **pindef_list,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
virDomainEmulatorPinAdd(virDomainDefPtr def,
|
|
||||||
unsigned char *cpumap,
|
|
||||||
int maplen)
|
|
||||||
{
|
|
||||||
virDomainPinDefPtr emulatorpin = NULL;
|
|
||||||
|
|
||||||
if (!def->cputune.emulatorpin) {
|
|
||||||
/* No emulatorpin exists yet. */
|
|
||||||
if (VIR_ALLOC(emulatorpin) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
emulatorpin->id = -1;
|
|
||||||
emulatorpin->cpumask = virBitmapNewData(cpumap, maplen);
|
|
||||||
if (!emulatorpin->cpumask) {
|
|
||||||
virDomainPinDefFree(emulatorpin);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
def->cputune.emulatorpin = emulatorpin;
|
|
||||||
} else {
|
|
||||||
/* Since there is only 1 emulatorpin for each vm,
|
|
||||||
* juest replace the old one.
|
|
||||||
*/
|
|
||||||
virBitmapFree(def->cputune.emulatorpin->cpumask);
|
|
||||||
def->cputune.emulatorpin->cpumask = virBitmapNewData(cpumap, maplen);
|
|
||||||
if (!def->cputune.emulatorpin->cpumask)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
virDomainEmulatorPinDel(virDomainDefPtr def)
|
|
||||||
{
|
|
||||||
if (!def->cputune.emulatorpin)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
virDomainPinDefFree(def->cputune.emulatorpin);
|
|
||||||
def->cputune.emulatorpin = NULL;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainEventActionDefFormat(virBufferPtr buf,
|
virDomainEventActionDefFormat(virBufferPtr buf,
|
||||||
@ -21105,7 +21051,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
|||||||
char *cpumask;
|
char *cpumask;
|
||||||
virBufferAddLit(buf, "<emulatorpin ");
|
virBufferAddLit(buf, "<emulatorpin ");
|
||||||
|
|
||||||
if (!(cpumask = virBitmapFormat(def->cputune.emulatorpin->cpumask)))
|
if (!(cpumask = virBitmapFormat(def->cputune.emulatorpin)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
virBufferAsprintf(buf, "cpuset='%s'/>\n", cpumask);
|
virBufferAsprintf(buf, "cpuset='%s'/>\n", cpumask);
|
||||||
|
@ -2069,7 +2069,7 @@ struct _virDomainCputune {
|
|||||||
long long emulator_quota;
|
long long emulator_quota;
|
||||||
size_t nvcpupin;
|
size_t nvcpupin;
|
||||||
virDomainPinDefPtr *vcpupin;
|
virDomainPinDefPtr *vcpupin;
|
||||||
virDomainPinDefPtr emulatorpin;
|
virBitmapPtr emulatorpin;
|
||||||
|
|
||||||
size_t nvcpusched;
|
size_t nvcpusched;
|
||||||
virDomainThreadSchedParamPtr vcpusched;
|
virDomainThreadSchedParamPtr vcpusched;
|
||||||
@ -2674,12 +2674,6 @@ void virDomainPinDel(virDomainPinDefPtr **pindef_list,
|
|||||||
size_t *npin,
|
size_t *npin,
|
||||||
int vcpu);
|
int vcpu);
|
||||||
|
|
||||||
int virDomainEmulatorPinAdd(virDomainDefPtr def,
|
|
||||||
unsigned char *cpumap,
|
|
||||||
int maplen);
|
|
||||||
|
|
||||||
int virDomainEmulatorPinDel(virDomainDefPtr def);
|
|
||||||
|
|
||||||
void virDomainRNGDefFree(virDomainRNGDefPtr def);
|
void virDomainRNGDefFree(virDomainRNGDefPtr def);
|
||||||
|
|
||||||
bool virDomainDiskDefDstDuplicates(virDomainDefPtr def);
|
bool virDomainDiskDefDstDuplicates(virDomainDefPtr def);
|
||||||
|
@ -273,8 +273,6 @@ virDomainDiskSetFormat;
|
|||||||
virDomainDiskSetSource;
|
virDomainDiskSetSource;
|
||||||
virDomainDiskSetType;
|
virDomainDiskSetType;
|
||||||
virDomainDiskSourceIsBlockType;
|
virDomainDiskSourceIsBlockType;
|
||||||
virDomainEmulatorPinAdd;
|
|
||||||
virDomainEmulatorPinDel;
|
|
||||||
virDomainFSDefFree;
|
virDomainFSDefFree;
|
||||||
virDomainFSIndexByName;
|
virDomainFSIndexByName;
|
||||||
virDomainFSInsert;
|
virDomainFSInsert;
|
||||||
|
@ -1114,7 +1114,7 @@ qemuSetupCgroupForEmulator(virDomainObjPtr vm)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (def->cputune.emulatorpin)
|
if (def->cputune.emulatorpin)
|
||||||
cpumask = def->cputune.emulatorpin->cpumask;
|
cpumask = def->cputune.emulatorpin;
|
||||||
else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO)
|
else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO)
|
||||||
cpumask = priv->autoCpuset;
|
cpumask = priv->autoCpuset;
|
||||||
else if (def->cpumask)
|
else if (def->cpumask)
|
||||||
|
@ -5374,23 +5374,19 @@ qemuDomainPinEmulator(virDomainPtr dom,
|
|||||||
virQEMUDriverPtr driver = dom->conn->privateData;
|
virQEMUDriverPtr driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virCgroupPtr cgroup_emulator = NULL;
|
virCgroupPtr cgroup_emulator = NULL;
|
||||||
pid_t pid;
|
|
||||||
virDomainDefPtr persistentDef = NULL;
|
virDomainDefPtr persistentDef = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
qemuDomainObjPrivatePtr priv;
|
qemuDomainObjPrivatePtr priv;
|
||||||
bool doReset = false;
|
bool doReset = false;
|
||||||
size_t newVcpuPinNum = 0;
|
|
||||||
virDomainPinDefPtr *newVcpuPin = NULL;
|
|
||||||
virBitmapPtr pcpumap = NULL;
|
virBitmapPtr pcpumap = NULL;
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
virQEMUDriverConfigPtr cfg = NULL;
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
virObjectEventPtr event = NULL;
|
virObjectEventPtr event = NULL;
|
||||||
char * str = NULL;
|
char *str = NULL;
|
||||||
virTypedParameterPtr eventParams = NULL;
|
virTypedParameterPtr eventParams = NULL;
|
||||||
int eventNparams = 0;
|
int eventNparams = 0;
|
||||||
int eventMaxparams = 0;
|
int eventMaxparams = 0;
|
||||||
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||||
|
|
||||||
@ -5436,66 +5432,34 @@ qemuDomainPinEmulator(virDomainPtr dom,
|
|||||||
if (virBitmapIsAllSet(pcpumap))
|
if (virBitmapIsAllSet(pcpumap))
|
||||||
doReset = true;
|
doReset = true;
|
||||||
|
|
||||||
pid = vm->pid;
|
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
|
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
|
||||||
if (priv->vcpupids != NULL) {
|
if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR,
|
||||||
if (VIR_ALLOC(newVcpuPin) < 0)
|
0, false, &cgroup_emulator) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (virDomainPinAdd(&newVcpuPin, &newVcpuPinNum, cpumap, maplen, -1) < 0) {
|
if (qemuSetupCgroupCpusetCpus(cgroup_emulator, pcpumap) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("failed to update vcpupin"));
|
_("failed to set cpuset.cpus in cgroup"
|
||||||
virDomainPinDefArrayFree(newVcpuPin, newVcpuPinNum);
|
" for emulator threads"));
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCgroupHasController(priv->cgroup,
|
|
||||||
VIR_CGROUP_CONTROLLER_CPUSET)) {
|
|
||||||
/*
|
|
||||||
* Configure the corresponding cpuset cgroup.
|
|
||||||
*/
|
|
||||||
if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR,
|
|
||||||
0, false, &cgroup_emulator) < 0)
|
|
||||||
goto endjob;
|
|
||||||
if (qemuSetupCgroupCpusetCpus(cgroup_emulator,
|
|
||||||
newVcpuPin[0]->cpumask) < 0) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("failed to set cpuset.cpus in cgroup"
|
|
||||||
" for emulator threads"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (virProcessSetAffinity(pid, pcpumap) < 0) {
|
|
||||||
virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
|
|
||||||
_("failed to set cpu affinity for "
|
|
||||||
"emulator threads"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doReset) {
|
|
||||||
if (virDomainEmulatorPinDel(vm->def) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("failed to delete emulatorpin xml of "
|
|
||||||
"a running domain"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
virDomainPinDefFree(vm->def->cputune.emulatorpin);
|
|
||||||
vm->def->cputune.emulatorpin = newVcpuPin[0];
|
|
||||||
VIR_FREE(newVcpuPin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newVcpuPin)
|
|
||||||
virDomainPinDefArrayFree(newVcpuPin, newVcpuPinNum);
|
|
||||||
} else {
|
} else {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
if (virProcessSetAffinity(vm->pid, pcpumap) < 0) {
|
||||||
"%s", _("cpu affinity is not supported"));
|
virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
|
||||||
goto endjob;
|
_("failed to set cpu affinity for "
|
||||||
|
"emulator thread"));
|
||||||
|
goto endjob;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virBitmapFree(vm->def->cputune.emulatorpin);
|
||||||
|
vm->def->cputune.emulatorpin = NULL;
|
||||||
|
|
||||||
|
if (!doReset &&
|
||||||
|
!(vm->def->cputune.emulatorpin = virBitmapNewCopy(pcpumap)))
|
||||||
|
goto endjob;
|
||||||
|
|
||||||
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
|
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
@ -5510,22 +5474,12 @@ qemuDomainPinEmulator(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||||
|
virBitmapFree(persistentDef->cputune.emulatorpin);
|
||||||
|
persistentDef->cputune.emulatorpin = NULL;
|
||||||
|
|
||||||
if (doReset) {
|
if (!doReset &&
|
||||||
if (virDomainEmulatorPinDel(persistentDef) < 0) {
|
!(persistentDef->cputune.emulatorpin = virBitmapNewCopy(pcpumap)))
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
goto endjob;
|
||||||
_("failed to delete emulatorpin xml of "
|
|
||||||
"a persistent domain"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (virDomainEmulatorPinAdd(persistentDef, cpumap, maplen) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("failed to update or add emulatorpin xml "
|
|
||||||
"of a persistent domain"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = virDomainSaveConfig(cfg->configDir, persistentDef);
|
ret = virDomainSaveConfig(cfg->configDir, persistentDef);
|
||||||
goto endjob;
|
goto endjob;
|
||||||
@ -5592,7 +5546,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (targetDef->cputune.emulatorpin) {
|
if (targetDef->cputune.emulatorpin) {
|
||||||
cpumask = targetDef->cputune.emulatorpin->cpumask;
|
cpumask = targetDef->cputune.emulatorpin;
|
||||||
} else if (targetDef->cpumask) {
|
} else if (targetDef->cpumask) {
|
||||||
cpumask = targetDef->cpumask;
|
cpumask = targetDef->cpumask;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2414,7 +2414,7 @@ qemuProcessSetEmulatorAffinity(virDomainObjPtr vm)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (def->cputune.emulatorpin)
|
if (def->cputune.emulatorpin)
|
||||||
cpumask = def->cputune.emulatorpin->cpumask;
|
cpumask = def->cputune.emulatorpin;
|
||||||
else if (def->cpumask)
|
else if (def->cpumask)
|
||||||
cpumask = def->cpumask;
|
cpumask = def->cpumask;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user