mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
qemu: Add helper to retrieve vCPU pid
Instead of directly accessing the array add a helper to do this.
This commit is contained in:
parent
220a2d51de
commit
e6b36736a8
@ -1043,7 +1043,8 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
|
||||
goto cleanup;
|
||||
|
||||
/* move the thread for vcpu to sub dir */
|
||||
if (virCgroupAddTask(cgroup_vcpu, priv->vcpupids[i]) < 0)
|
||||
if (virCgroupAddTask(cgroup_vcpu,
|
||||
qemuDomainGetVcpuPid(vm, i)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (period || quota) {
|
||||
|
@ -4131,3 +4131,23 @@ qemuDomainHasVcpuPids(virDomainObjPtr vm)
|
||||
|
||||
return priv->nvcpupids > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuDomainGetVcpuPid:
|
||||
* @vm: domain object
|
||||
* @vcpu: cpu id
|
||||
*
|
||||
* Returns the vCPU pid. If @vcpu is offline or out of range 0 is returned.
|
||||
*/
|
||||
pid_t
|
||||
qemuDomainGetVcpuPid(virDomainObjPtr vm,
|
||||
unsigned int vcpu)
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
|
||||
if (vcpu >= priv->nvcpupids)
|
||||
return 0;
|
||||
|
||||
return priv->vcpupids[vcpu];
|
||||
}
|
||||
|
@ -506,5 +506,6 @@ int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
|
||||
const virDomainMemoryDef *mem);
|
||||
|
||||
bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
|
||||
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpu);
|
||||
|
||||
#endif /* __QEMU_DOMAIN_H__ */
|
||||
|
@ -1449,7 +1449,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
|
||||
&(info[i].cpu),
|
||||
NULL,
|
||||
vm->pid,
|
||||
priv->vcpupids[i]) < 0) {
|
||||
qemuDomainGetVcpuPid(vm, i)) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
_("cannot get vCPU placement & pCPU time"));
|
||||
return -1;
|
||||
@ -1462,7 +1462,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
|
||||
unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
|
||||
virBitmapPtr map = NULL;
|
||||
|
||||
if (!(map = virProcessGetAffinity(priv->vcpupids[v])))
|
||||
if (!(map = virProcessGetAffinity(qemuDomainGetVcpuPid(vm, v))))
|
||||
return -1;
|
||||
|
||||
virBitmapToDataBuf(map, cpumap, maplen);
|
||||
@ -5156,7 +5156,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
|
||||
goto endjob;
|
||||
}
|
||||
} else {
|
||||
if (virProcessSetAffinity(priv->vcpupids[vcpu], pcpumap) < 0) {
|
||||
if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu),
|
||||
pcpumap) < 0) {
|
||||
virReportError(VIR_ERR_SYSTEM_ERROR,
|
||||
_("failed to set cpu affinity for vcpu %d"),
|
||||
vcpu);
|
||||
|
@ -2234,7 +2234,6 @@ qemuProcessSetLinkStates(virQEMUDriverPtr driver,
|
||||
static int
|
||||
qemuProcessSetVcpuAffinities(virDomainObjPtr vm)
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virDomainDefPtr def = vm->def;
|
||||
virDomainPinDefPtr pininfo;
|
||||
int n;
|
||||
@ -2267,7 +2266,7 @@ qemuProcessSetVcpuAffinities(virDomainObjPtr vm)
|
||||
n)))
|
||||
continue;
|
||||
|
||||
if (virProcessSetAffinity(priv->vcpupids[n],
|
||||
if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, n),
|
||||
pininfo->cpumask) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -2355,7 +2354,7 @@ qemuProcessSetSchedulers(virDomainObjPtr vm)
|
||||
size_t i = 0;
|
||||
|
||||
for (i = 0; i < priv->nvcpupids; i++) {
|
||||
if (qemuProcessSetSchedParams(i, priv->vcpupids[i],
|
||||
if (qemuProcessSetSchedParams(i, qemuDomainGetVcpuPid(vm, i),
|
||||
vm->def->cputune.nvcpusched,
|
||||
vm->def->cputune.vcpusched) < 0)
|
||||
return -1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user