Skip to content

Commit

Permalink
Fix the cpu pinning parsing logic to parse the format appropriately a…
Browse files Browse the repository at this point in the history
…nd exclude cpu from pinning list

Signed-off-by: ShubhaOracle <[email protected]>
  • Loading branch information
shubhaOracle committed Mar 15, 2024
1 parent 5d82b9e commit bb93151
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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)
2 changes: 2 additions & 0 deletions 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 @@ -264,6 +265,7 @@ def test_pinned_cpus(self):
assert len(pinning) == 2
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 bb93151

Please sign in to comment.