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 6, 2022
1 parent c9b4ead commit 375cb69
Show file tree
Hide file tree
Showing 2 changed files with 63 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
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,40 @@ public void shouldSucceedToDedicateEqualSockets() {
assertEquals(6, cpus.stream().filter(cpu -> cpu.getSocket() == 1).count());
}

@Test
public void releaseReminderOnIsolateThreads() {
VM vm = new VM();
vm.setId(Guid.newGuid());
vm.setNumOfSockets(2);
vm.setCpuPerSocket(3);
vm.setThreadsPerCpu(1);
vm.setCpuPinningPolicy(CpuPinningPolicy.ISOLATE_THREADS);

List<VdsCpuUnit> cpuTopology = new ArrayList<>();
cpuTopology.add(new VdsCpuUnit(0, 0, 0, 0));
cpuTopology.add(new VdsCpuUnit(0, 0, 0, 1));
cpuTopology.add(new VdsCpuUnit(0, 0, 1, 0));
VdsCpuUnit vdsmTaken = new VdsCpuUnit(0, 0, 1, 1);
vdsmTaken.pinVm(Guid.SYSTEM, CpuPinningPolicy.MANUAL);
cpuTopology.add(vdsmTaken);
cpuTopology.add(new VdsCpuUnit(0, 0, 2, 0));
cpuTopology.add(new VdsCpuUnit(0, 0, 2, 1));
cpuTopology.add(new VdsCpuUnit(0, 0, 3, 0));
cpuTopology.add(new VdsCpuUnit(0, 0, 3, 1));

cpuTopology.add(new VdsCpuUnit(1, 1, 0, 0));
cpuTopology.add(new VdsCpuUnit(1, 1, 0, 1));
cpuTopology.add(new VdsCpuUnit(1, 1, 1, 0));
cpuTopology.add(new VdsCpuUnit(1, 1, 1, 0));
cpuTopology.add(new VdsCpuUnit(1, 1, 2, 0));
cpuTopology.add(new VdsCpuUnit(1, 1, 2, 1));
cpuTopology.add(new VdsCpuUnit(1, 1, 3, 0));
cpuTopology.add(new VdsCpuUnit(1, 1, 3, 1));

when(vdsManager.getCpuTopology()).thenReturn(cpuTopology);
List<VdsCpuUnit> cpus = vdsCpuUnitPinningHelper.updatePhysicalCpuAllocations(vm, new HashMap<>(), host.getId());
assertEquals(12, cpus.size());
assertEquals(12, cpuTopology.stream().filter(VdsCpuUnit::isExclusive).count());
}

}

0 comments on commit 375cb69

Please sign in to comment.