Skip to content

Commit 8e3ffb8

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Allow enabling PCI scheduling in Placement"
2 parents 922f5f6 + 2cb1eed commit 8e3ffb8

File tree

10 files changed

+77
-69
lines changed

10 files changed

+77
-69
lines changed

doc/source/admin/pci-passthrough.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ capabilities.
6565
:oslo.config:option:`pci.device_spec` configuration that uses the
6666
``devname`` field.
6767

68+
.. versionchanged:: 27.0.0 (2023.1 Antelope):
69+
Nova provides Placement based scheduling support for servers with flavor
70+
based PCI requests. This support is disable by default.
71+
6872
Enabling PCI passthrough
6973
------------------------
7074

@@ -442,6 +446,24 @@ removed and VFs from the same PF is configured (or vice versa) then
442446
nova-compute will refuse to start as it would create a situation where both
443447
the PF and its VFs are made available for consumption.
444448

449+
Since nova 27.0.0 (2023.1 Antelope) scheduling and allocation of PCI devices
450+
in Placement can also be enabled via
451+
:oslo.config:option:`filter_scheduler.pci_in_placement`. Please note that this
452+
should only be enabled after all the computes in the system is configured to
453+
report PCI inventory in Placement via
454+
enabling :oslo.config:option:`pci.report_in_placement`. In Antelope flavor
455+
based PCI requests are support but Neutron port base PCI requests are not
456+
handled in Placement.
457+
458+
If you are upgrading from an earlier version with already existing servers with
459+
PCI usage then you must enable :oslo.config:option:`pci.report_in_placement`
460+
first on all your computes having PCI allocations and then restart the
461+
nova-compute service, before you enable
462+
:oslo.config:option:`filter_scheduler.pci_in_placement`. The compute service
463+
will heal the missing PCI allocation in placement during startup and will
464+
continue healing missing allocations for future servers until the scheduling
465+
support is enabled.
466+
445467
If a flavor requests multiple ``type-VF`` devices via
446468
:nova:extra-spec:`pci_passthrough:alias` then it is important to consider the
447469
value of :nova:extra-spec:`group_policy` as well. The value ``none``

nova/compute/pci_placement_translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def update_provider_tree_for_pci(
614614
if updated:
615615
LOG.debug(
616616
"Placement PCI view needs allocation healing. This should only "
617-
"happen if [scheduler]pci_in_placement is still disabled. "
617+
"happen if [filter_scheduler]pci_in_placement is still disabled. "
618618
"Original allocations: %s New allocations: %s",
619619
old_alloc,
620620
allocations,

nova/conf/pci.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
``vendor_id`` and ``product_id`` values of the alias in the form of
8080
``CUSTOM_PCI_{vendor_id}_{product_id}``. The ``resource_class`` requested
8181
in the alias is matched against the ``resource_class`` defined in the
82-
``[pci]device_spec``.
82+
``[pci]device_spec``. This field can only be used only if
83+
``[filter_scheduler]pci_in_placement`` is enabled.
8384
8485
``traits``
8586
An optional comma separated list of Placement trait names requested to be
@@ -91,7 +92,8 @@
9192
prefixed. The maximum allowed length of a trait name is 255 character
9293
including the prefix. Every trait in ``traits`` requested in the alias
9394
ensured to be in the list of traits provided in the ``traits`` field of
94-
the ``[pci]device_spec`` when scheduling the request.
95+
the ``[pci]device_spec`` when scheduling the request. This field can only
96+
be used only if ``[filter_scheduler]pci_in_placement`` is enabled.
9597
9698
* Supports multiple aliases by repeating the option (not by specifying
9799
a list value)::

nova/conf/scheduler.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,26 @@
745745
Related options:
746746
747747
* ``[filter_scheduler] aggregate_image_properties_isolation_namespace``
748-
""")]
748+
"""),
749+
cfg.BoolOpt(
750+
"pci_in_placement",
751+
default=False,
752+
help="""
753+
Enable scheduling and claiming PCI devices in Placement.
754+
755+
This can be enabled after ``[pci]report_in_placement`` is enabled on all
756+
compute hosts.
757+
758+
When enabled the scheduler queries Placement about the PCI device
759+
availability to select destination for a server with PCI request. The scheduler
760+
also allocates the selected PCI devices in Placement. Note that this logic
761+
does not replace the PCIPassthroughFilter but extends it.
762+
763+
* ``[pci] report_in_placement``
764+
* ``[pci] alias``
765+
* ``[pci] device_spec``
766+
"""),
767+
]
749768

750769
metrics_group = cfg.OptGroup(
751770
name="metrics",

nova/objects/request_spec.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from oslo_utils import versionutils
2323

2424
from nova.compute import pci_placement_translator
25+
import nova.conf
2526
from nova.db.api import api as api_db_api
2627
from nova.db.api import models as api_models
2728
from nova import exception
@@ -30,6 +31,7 @@
3031
from nova.objects import fields
3132
from nova.objects import instance as obj_instance
3233

34+
CONF = nova.conf.CONF
3335
LOG = logging.getLogger(__name__)
3436

3537
REQUEST_SPEC_OPTIONAL_ATTRS = ['requested_destination',
@@ -487,16 +489,8 @@ def _rc_from_request(spec: ty.Dict[str, ty.Any]) -> str:
487489
def _traits_from_request(spec: ty.Dict[str, ty.Any]) -> ty.Set[str]:
488490
return pci_placement_translator.get_traits(spec.get("traits", ""))
489491

490-
# This is here temporarily until the PCI placement scheduling is under
491-
# implementation. When that is done there will be a config option
492-
# [scheduler]pci_in_placement to configure this. Now we add this as a
493-
# function to allow tests to selectively enable the WIP feature
494-
@staticmethod
495-
def _pci_in_placement_enabled():
496-
return False
497-
498492
def generate_request_groups_from_pci_requests(self):
499-
if not self._pci_in_placement_enabled():
493+
if not CONF.filter_scheduler.pci_in_placement:
500494
return False
501495

502496
for pci_request in self.pci_requests.requests:

nova/pci/stats.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def _filter_pools_based_on_placement_allocation(
552552
# by it. This could happen if the instance only has neutron port
553553
# based InstancePCIRequest as that is currently not having
554554
# placement allocation (except for QoS ports, but that handled in a
555-
# separate codepath) or if the [scheduler]pci_in_placement
555+
# separate codepath) or if the [filter_scheduler]pci_in_placement
556556
# configuration option is not enabled in the scheduler.
557557
return pools
558558

@@ -563,15 +563,15 @@ def _filter_pools_based_on_placement_allocation(
563563
# NOTE(gibi): There can be pools without rp_uuid field if the
564564
# [pci]report_in_placement is not enabled for a compute with
565565
# viable PCI devices. We have a non-empty rp_uuids, so we know
566-
# that the [scheduler]pci_in_placement is enabled. This is a
567-
# configuration error.
566+
# that the [filter_scheduler]pci_in_placement is enabled. This
567+
# is a configuration error.
568568
LOG.warning(
569569
"The PCI pool %s isn't mapped to an RP UUID but the "
570570
"scheduler is configured to create PCI allocations in "
571571
"placement. This should not happen. Please enable "
572572
"[pci]report_in_placement on all compute hosts before "
573-
"enabling [scheduler]pci_in_placement in the scheduler. "
574-
"This pool is ignored now.", pool)
573+
"enabling [filter_scheduler]pci_in_placement in the "
574+
"scheduler. This pool is ignored now.", pool)
575575
continue
576576

577577
if rp_uuid in rp_uuids:
@@ -809,7 +809,7 @@ def _get_rp_uuids_for_request(
809809
# but the object is hard to change retroactively
810810
rp_uuids = request.spec[0].get('rp_uuids')
811811
if not rp_uuids:
812-
# This can happen if [scheduler]pci_in_placement is not
812+
# This can happen if [filter_scheduler]pci_in_placement is not
813813
# enabled yet
814814
# set() will signal that any PCI pool can be used for this
815815
# request

nova/tests/functional/libvirt/test_pci_in_placement.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,15 +1616,7 @@ def test_heal_allocation_during_same_host_resize(self):
16161616
class RCAndTraitBasedPCIAliasTests(PlacementPCIReportingTests):
16171617
def setUp(self):
16181618
super().setUp()
1619-
# TODO(gibi): replace this with setting the [scheduler]pci_in_placement
1620-
# confing to True once that config is added
1621-
self.mock_pci_in_placement_enabled = self.useFixture(
1622-
fixtures.MockPatch(
1623-
'nova.objects.request_spec.RequestSpec.'
1624-
'_pci_in_placement_enabled',
1625-
return_value=True
1626-
)
1627-
).mock
1619+
self.flags(group='filter_scheduler', pci_in_placement=True)
16281620

16291621
def test_boot_with_custom_rc_and_traits(self):
16301622
# The fake libvirt will emulate on the host:
@@ -1737,12 +1729,13 @@ def test_boot_with_custom_rc_and_traits(self):
17371729
self.assert_no_pci_healing("compute1")
17381730

17391731
def test_device_claim_consistent_with_placement_allocation(self):
1740-
"""As soon as [scheduler]pci_in_placement is enabled the nova-scheduler
1741-
will allocate PCI devices in placement. Then on the nova-compute side
1742-
the PCI claim will also allocate PCI devices in the nova DB. This test
1743-
will create a situation where the two allocation could contradict and
1744-
observes that in a contradicting situation the PCI claim will fail
1745-
instead of allocating a device that is not allocated in placement.
1732+
"""As soon as [filter_scheduler]pci_in_placement is enabled the
1733+
nova-scheduler will allocate PCI devices in placement. Then on the
1734+
nova-compute side the PCI claim will also allocate PCI devices in the
1735+
nova DB. This test will create a situation where the two allocation
1736+
could contradict and observes that in a contradicting situation the PCI
1737+
claim will fail instead of allocating a device that is not allocated in
1738+
placement.
17461739
17471740
For the contradiction to happen we need two PCI devices that looks
17481741
different from placement perspective than from the nova DB perspective.

nova/tests/functional/libvirt/test_pci_sriov_servers.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,15 +1952,7 @@ class PCIServersTest(_PCIServersTestBase):
19521952
def setUp(self):
19531953
super().setUp()
19541954
self.flags(group="pci", report_in_placement=True)
1955-
# TODO(gibi): replace this with setting the [scheduler]pci_prefilter
1956-
# confing to True once that config is added
1957-
self.mock_pci_in_placement_enabled = self.useFixture(
1958-
fixtures.MockPatch(
1959-
'nova.objects.request_spec.RequestSpec.'
1960-
'_pci_in_placement_enabled',
1961-
return_value=True
1962-
)
1963-
).mock
1955+
self.flags(group='filter_scheduler', pci_in_placement=True)
19641956

19651957
def test_create_server_with_pci_dev_and_numa(self):
19661958
"""Verifies that an instance can be booted with cpu pinning and with an
@@ -3026,15 +3018,7 @@ class PCIServersWithPreferredNUMATest(_PCIServersTestBase):
30263018
def setUp(self):
30273019
super().setUp()
30283020
self.flags(group="pci", report_in_placement=True)
3029-
# TODO(gibi): replace this with setting the [scheduler]pci_in_placement
3030-
# confing to True once that config is added
3031-
self.mock_pci_in_placement_enabled = self.useFixture(
3032-
fixtures.MockPatch(
3033-
'nova.objects.request_spec.RequestSpec.'
3034-
'_pci_in_placement_enabled',
3035-
return_value=True
3036-
)
3037-
).mock
3021+
self.flags(group='filter_scheduler', pci_in_placement=True)
30383022

30393023
def test_create_server_with_pci_dev_and_numa(self):
30403024
"""Validate behavior of 'preferred' PCI NUMA policy.

nova/tests/unit/objects/test_request_spec.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import collections
1515
from unittest import mock
1616

17-
import fixtures
1817
from oslo_serialization import jsonutils
1918
from oslo_utils.fixture import uuidsentinel as uuids
2019
from oslo_utils import uuidutils
@@ -431,13 +430,8 @@ def test_from_components_with_port_resource_request(self, ):
431430
self.assertListEqual([rg], spec.requested_resources)
432431
self.assertEqual(req_lvl_params, spec.request_level_params)
433432

434-
# TODO(gibi): replace this with setting the config
435-
# [scheduler]pci_in_placement=True once that flag is available
436-
@mock.patch(
437-
'nova.objects.request_spec.RequestSpec._pci_in_placement_enabled',
438-
new=mock.Mock(return_value=True),
439-
)
440433
def test_from_components_flavor_based_pci_requests(self):
434+
self.flags(group='filter_scheduler', pci_in_placement=True)
441435
ctxt = context.RequestContext(
442436
fakes.FAKE_USER_ID, fakes.FAKE_PROJECT_ID
443437
)
@@ -1119,18 +1113,10 @@ class TestRemoteRequestSpecObject(test_objects._RemoteTest,
11191113
class TestInstancePCIRequestToRequestGroups(test.NoDBTestCase):
11201114
def setUp(self):
11211115
super().setUp()
1122-
# TODO(gibi): replace this with setting the config
1123-
# [scheduler]pci_in_placement=True once that flag is available
1124-
self.mock_pci_in_placement_enabled = self.useFixture(
1125-
fixtures.MockPatch(
1126-
"nova.objects.request_spec.RequestSpec."
1127-
"_pci_in_placement_enabled",
1128-
return_value=True,
1129-
)
1130-
).mock
1116+
self.flags(group='filter_scheduler', pci_in_placement=True)
11311117

11321118
def test_pci_reqs_ignored_if_disabled(self):
1133-
self.mock_pci_in_placement_enabled.return_value = False
1119+
self.flags(group='filter_scheduler', pci_in_placement=False)
11341120

11351121
spec = request_spec.RequestSpec(
11361122
requested_resources=[],
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
Since 26.0.0 (Zed) Nova supports tracking PCI devices in Placement. Now
5+
Nova also supports scheduling flavor based PCI device requests via
6+
Placement. This support is disable by default. Please read
7+
`documentation <https://docs.openstack.org/nova/latest/admin/pci-passthrough.html#pci-tracking-in-placement>`_
8+
for more details on what is supported how this feature can be enabled.

0 commit comments

Comments
 (0)