Skip to content

Commit

Permalink
virt: Add support for excluding CPUs in CPU list parsing
Browse files Browse the repository at this point in the history
Issue: The CPU pinning tool tip says that to exclude a cpu from pinning,
it needs to provided in the following format.
0#10-13_1#25-27,^26

With this format CPU 26 will be excluded from pinning. However, vdsm
code fails to parse the above string resulting in VM start failure.

Fix: Fix the cpu pinning parsing logic to parse the format appropriately
and exclude cpu from pinning list.

Signed-off-by: ShubhaOracle <[email protected]>
  • Loading branch information
shubhaOracle authored and tinez committed Mar 20, 2024
1 parent 5d82b9e commit c641c1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/vdsm/taskset.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ def cpulist_parse(cpu_range):
or the output of the 'taskset' and 'lscpu' tools.
"""
cpus = []
excluded_cpus = []
for item in cpu_range.split(','):
if '-' in item:
begin, end = item.split('-', 1)
cpus.extend(range(int(begin), int(end) + 1))
elif item.startswith("^"):
excluded_cpus.append(int(item[1:]))
else:
cpus.append(int(item))
return frozenset(cpus)
return frozenset(cpus) - frozenset(excluded_cpus)
4 changes: 3 additions & 1 deletion tests/virt/domaindescriptor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<cputune>
<vcpupin vcpu="0" cpuset="1,2,5-7" />
<vcpupin vcpu="1" cpuset="1,6,10" />
<vcpupin vcpu="2" cpuset="1-4,^3,6" />
</cputune>
</domain>
"""
Expand Down Expand Up @@ -261,9 +262,10 @@ def test_get_number_of_cpus(self, xml_data, expected):
def test_pinned_cpus(self):
desc = DomainDescriptor(PINNED_CPUS)
pinning = desc.pinned_cpus
assert len(pinning) == 2
assert len(pinning) == 3
assert pinning[0] == frozenset([1, 2, 5, 6, 7])
assert pinning[1] == frozenset([1, 6, 10])
assert pinning[2] == frozenset([1, 2, 4, 6])

def test_no_pinned_cpus(self):
desc = DomainDescriptor(NO_PINNED_CPUS)
Expand Down

0 comments on commit c641c1f

Please sign in to comment.