Skip to content

Commit

Permalink
core: release core reminders
Browse files Browse the repository at this point in the history
We now release using unPin the VdsCpuUnit we need. This is good for
`dedicated` policy. When we are handling `isolate-threads` policy we
need to release the whole core. Otherwise the engine thinks it's taken.

Change-Id: I0b028e0dc5db72f5ef3099059f355d975a81fc90
Bug-Url: https://bugzilla.redhat.com/2103620
Signed-off-by: Liran Rotenberg <lrotenbe@redhat.com>
  • Loading branch information
liranr23 committed Jul 4, 2022
1 parent c9b4ead commit b9cfa17
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,18 @@ private List<VdsCpuUnit> allocateDedicatedCpus(List<VdsCpuUnit> cpuTopology, VM
}
socketsLeft -= coreCount / vm.getCpuPerSocket();
int coresReminder = coreCount % vm.getCpuPerSocket();
for (int i = 0; i < coresReminder * vm.getThreadsPerCpu(); i++) {
int numOfCpusToRemove = vm.getCpuPinningPolicy() == CpuPinningPolicy.DEDICATED ?
coresReminder * vm.getThreadsPerCpu() : coresReminder;
for (int i = 0; i < numOfCpusToRemove; i++) {
if (!cpusToBeAllocated.isEmpty()) {
VdsCpuUnit releasedCpu = cpusToBeAllocated.remove(cpusToBeAllocated.size() - 1);
releasedCpu.unPinVm(vm.getId());
switch(vm.getCpuPinningPolicy()) {
case DEDICATED:
releaseDedicatedCpu(vm.getId(), cpusToBeAllocated);
break;
case ISOLATE_THREADS:
releaseIsolateThreadsCpu(vm.getId(), cpusToBeAllocated);
numOfAllocatedCPUs--;
}
}
}

Expand All @@ -210,6 +218,22 @@ private List<VdsCpuUnit> allocateDedicatedCpus(List<VdsCpuUnit> cpuTopology, VM
return cpusToBeAllocated;
}

private void releaseDedicatedCpu(Guid vmId, List<VdsCpuUnit> cpusToBeAllocated) {
VdsCpuUnit releasedCpu = cpusToBeAllocated.remove(cpusToBeAllocated.size() - 1);
releasedCpu.unPinVm(vmId);
}

private void releaseIsolateThreadsCpu(Guid vmId, List<VdsCpuUnit> cpusToBeAllocated) {
VdsCpuUnit cpuUnit = cpusToBeAllocated.get(cpusToBeAllocated.size() - 1);
int coreId = cpuUnit.getCore();
int socketId = cpuUnit.getSocket();
List<VdsCpuUnit> cpusToRemove = getCpusInCore(getCoresInSocket(cpusToBeAllocated, socketId), coreId);
cpusToRemove.forEach(vdsCpuUnit -> {
vdsCpuUnit.unPinVm(vmId);
cpusToBeAllocated.remove(vdsCpuUnit);
});
}

private int countTakenCores(List<VdsCpuUnit> cpuTopology) {
if (cpuTopology.isEmpty()) {
return 0;
Expand Down

0 comments on commit b9cfa17

Please sign in to comment.