From 375cb698e606b2743fc64ac4b544f895f42f5294 Mon Sep 17 00:00:00 2001 From: Liran Rotenberg Date: Mon, 4 Jul 2022 12:08:18 +0300 Subject: [PATCH] core: release core reminders 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 --- .../utils/VdsCpuUnitPinningHelper.java | 30 ++++++++++++++-- .../utils/VdsCpuUnitPinningHelperTest.java | 36 +++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/utils/VdsCpuUnitPinningHelper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/utils/VdsCpuUnitPinningHelper.java index daaa283ff13..072ae5a69e3 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/utils/VdsCpuUnitPinningHelper.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/utils/VdsCpuUnitPinningHelper.java @@ -194,10 +194,18 @@ private List allocateDedicatedCpus(List 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--; + } } } @@ -210,6 +218,22 @@ private List allocateDedicatedCpus(List cpuTopology, VM return cpusToBeAllocated; } + private void releaseDedicatedCpu(Guid vmId, List cpusToBeAllocated) { + VdsCpuUnit releasedCpu = cpusToBeAllocated.remove(cpusToBeAllocated.size() - 1); + releasedCpu.unPinVm(vmId); + } + + private void releaseIsolateThreadsCpu(Guid vmId, List cpusToBeAllocated) { + VdsCpuUnit cpuUnit = cpusToBeAllocated.get(cpusToBeAllocated.size() - 1); + int coreId = cpuUnit.getCore(); + int socketId = cpuUnit.getSocket(); + List cpusToRemove = getCpusInCore(getCoresInSocket(cpusToBeAllocated, socketId), coreId); + cpusToRemove.forEach(vdsCpuUnit -> { + vdsCpuUnit.unPinVm(vmId); + cpusToBeAllocated.remove(vdsCpuUnit); + }); + } + private int countTakenCores(List cpuTopology) { if (cpuTopology.isEmpty()) { return 0; diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/scheduling/utils/VdsCpuUnitPinningHelperTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/scheduling/utils/VdsCpuUnitPinningHelperTest.java index 3a735aefab3..99be29d85d6 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/scheduling/utils/VdsCpuUnitPinningHelperTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/scheduling/utils/VdsCpuUnitPinningHelperTest.java @@ -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 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 cpus = vdsCpuUnitPinningHelper.updatePhysicalCpuAllocations(vm, new HashMap<>(), host.getId()); + assertEquals(12, cpus.size()); + assertEquals(12, cpuTopology.stream().filter(VdsCpuUnit::isExclusive).count()); + } + }