Skip to content

Commit c4e9e2e

Browse files
committed
hardware: refactor the code for CPU policy sanity check
The code setting the 'dedicated_cpus' for the 'dedicated' policy instance does not belong to the scope of CPU policy sanity check, moving it out of the sanity check block. Also removed a note saying 'get_dedicated_cpu_constraint' should be public, which seems not necessary. This is a follow-up commit in addressing comments in this topic [1]. [1] https://review.opendev.org/#/c/716267/14/ Part of blueprint use-pcpu-and-vcpu-in-one-instance Change-Id: I3fdfde36641dccfc9de60c25779e60fb9aabba82 Signed-off-by: Wang Huaqiang <[email protected]>
1 parent ba3388d commit c4e9e2e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

nova/virt/hardware.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,9 +1944,6 @@ def numa_get_constraints(flavor, image_meta):
19441944
# 'dedicated' policy.
19451945
if dedicated_cpus:
19461946
raise exception.RequiredMixedInstancePolicy()
1947-
# But for an instance with 'dedicated' CPU allocation policy, all
1948-
# CPUs are 'dedicated' CPUs, which is 1:1 pinned to a host CPU.
1949-
dedicated_cpus = set(range(flavor.vcpus))
19501947
else: # MIXED
19511948
# FIXME(huaqiang): So far, 'mixed' instance is not supported
19521949
# and the 'dedicated_cpus' variable is set to 'None' due to being not
@@ -1960,7 +1957,13 @@ def numa_get_constraints(flavor, image_meta):
19601957
pagesize = _get_numa_pagesize_constraint(flavor, image_meta)
19611958
vpmems = get_vpmems(flavor)
19621959

1960+
# If 'hw:cpu_dedicated_mask' is not found in flavor extra specs, the
1961+
# 'dedicated_cpus' variable is None, while we hope it being an empty set.
19631962
dedicated_cpus = dedicated_cpus or set()
1963+
if cpu_policy == fields.CPUAllocationPolicy.DEDICATED:
1964+
# But for an instance with 'dedicated' CPU allocation policy, all
1965+
# CPUs are 'dedicated' CPUs, which is 1:1 pinned to a host CPU.
1966+
dedicated_cpus = set(range(flavor.vcpus))
19641967

19651968
# NOTE(stephenfin): There are currently four things that will configure a
19661969
# NUMA topology for an instance:

0 commit comments

Comments
 (0)