Skip to content

Commit 7c1ca50

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Expose the mdev class"
2 parents 9cb92e8 + 9be996c commit 7c1ca50

File tree

8 files changed

+276
-76
lines changed

8 files changed

+276
-76
lines changed

nova/conf/devices.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,25 @@ def register_dynamic_opts(conf):
7070
the initial configuration has been loaded.
7171
"""
7272

73-
# Register the '[mdev_$(MDEV_TYPE)]/device_addresses' opts, implicitly
74-
# registering the '[mdev_$(MDEV_TYPE)]' groups in the process
7573
for mdev_type in conf.devices.enabled_mdev_types:
74+
# Register the '[mdev_$(MDEV_TYPE)]/device_addresses' opts, implicitly
75+
# registering the '[mdev_$(MDEV_TYPE)]' groups in the process
7676
opt = cfg.ListOpt('device_addresses', default=[],
7777
item_type=cfg.types.String(),
7878
deprecated_group='vgpu_%s' % mdev_type)
7979
conf.register_opt(opt, group='mdev_%s' % mdev_type)
8080

81+
# Register the '[mdev_$(MDEV_TYPE)]/mdev_class' opts
82+
class_opt = cfg.StrOpt(
83+
'mdev_class',
84+
default='VGPU',
85+
regex=r'^(VGPU|CUSTOM_[A-Z0-9_]+)$',
86+
max_length=255,
87+
help='Class of mediated device to manage used to differentiate '
88+
'between device types. The name has to be prefixed by '
89+
'CUSTOM_ if it is not VGPU.')
90+
conf.register_opt(class_opt, group='mdev_%s' % mdev_type)
91+
8192

8293
def list_opts():
8394
return {devices_group: mdev_opts}

nova/tests/fixtures/libvirt.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ def _reset():
232232

233233
NVIDIA_11_VGPU_TYPE = 'nvidia-11'
234234
NVIDIA_12_VGPU_TYPE = 'nvidia-12'
235-
PGPU1_PCI_ADDR = 'pci_0000_81_00_0'
236-
PGPU2_PCI_ADDR = 'pci_0000_81_01_0'
237-
PGPU3_PCI_ADDR = 'pci_0000_81_02_0'
235+
MLX5_CORE_TYPE = 'mlx5_core'
236+
MDEVCAP_DEV1_PCI_ADDR = 'pci_0000_81_00_0'
237+
MDEVCAP_DEV2_PCI_ADDR = 'pci_0000_81_01_0'
238+
MDEVCAP_DEV3_PCI_ADDR = 'pci_0000_81_02_0'
238239

239240
os_uname = collections.namedtuple(
240241
'uname_result', ['sysname', 'nodename', 'release', 'version', 'machine'],
@@ -296,9 +297,9 @@ class FakePCIDevice(object):
296297

297298
def __init__(
298299
self, dev_type, bus, slot, function, iommu_group, numa_node, *,
299-
vf_ratio=None, multiple_gpu_types=False, parent=None,
300-
vend_id=None, vend_name=None, prod_id=None, prod_name=None,
301-
driver_name=None,
300+
vf_ratio=None, multiple_gpu_types=False, generic_types=False,
301+
parent=None, vend_id=None, vend_name=None, prod_id=None,
302+
prod_name=None, driver_name=None,
302303
):
303304
"""Populate pci devices
304305
@@ -312,6 +313,7 @@ def __init__(
312313
:param vf_ratio: (int) Ratio of Virtual Functions on Physical. Only
313314
applicable if ``dev_type`` is one of: ``PF``, ``VF``.
314315
:param multiple_gpu_types: (bool) Supports different vGPU types.
316+
:param generic_types: (bool) Support both mlx5 and nvidia-12 types.
315317
:param parent: (int, int, int) A tuple of bus, slot and function
316318
corresponding to the parent.
317319
:param vend_id: (str) The vendor ID.
@@ -329,6 +331,7 @@ def __init__(
329331
self.numa_node = numa_node
330332
self.vf_ratio = vf_ratio
331333
self.multiple_gpu_types = multiple_gpu_types
334+
self.generic_types = generic_types
332335
self.parent = parent
333336

334337
self.vend_id = vend_id
@@ -414,6 +417,15 @@ def generate_xml(self, skip_capability=False):
414417
'type_id': NVIDIA_12_VGPU_TYPE,
415418
'instances': 8,
416419
})
420+
if self.generic_types:
421+
types = [self.mdevtypes_templ % {
422+
'type_id': MLX5_CORE_TYPE,
423+
'instances': 16,
424+
}]
425+
types.append(self.mdevtypes_templ % {
426+
'type_id': NVIDIA_12_VGPU_TYPE,
427+
'instances': 8,
428+
})
417429
if not skip_capability:
418430
capability = self.cap_templ % {
419431
'cap_type': MDEV_CAPABLE_CAP_TYPE,
@@ -457,7 +469,8 @@ class HostPCIDevicesInfo(object):
457469
TOTAL_NUMA_NODES = 2
458470

459471
def __init__(self, num_pci=0, num_pfs=2, num_vfs=8, num_mdevcap=0,
460-
numa_node=None, multiple_gpu_types=False):
472+
numa_node=None, multiple_gpu_types=False,
473+
generic_types=False):
461474
"""Create a new HostPCIDevicesInfo object.
462475
463476
:param num_pci: (int) The number of (non-SR-IOV) and (non-MDEV capable)
@@ -470,6 +483,7 @@ def __init__(self, num_pci=0, num_pfs=2, num_vfs=8, num_mdevcap=0,
470483
devices will be assigned to the specified node else they will be
471484
split between ``$TOTAL_NUMA_NODES`` nodes.
472485
:param multiple_gpu_types: (bool) Supports different vGPU types
486+
:param generic_types: (bool) Supports both nvidia-12 and mlx5 types
473487
"""
474488
self.devices = {}
475489

@@ -509,7 +523,8 @@ def __init__(self, num_pci=0, num_pfs=2, num_vfs=8, num_mdevcap=0,
509523
function=function,
510524
iommu_group=iommu_group,
511525
numa_node=self._calc_numa_node(dev, numa_node),
512-
multiple_gpu_types=multiple_gpu_types)
526+
multiple_gpu_types=multiple_gpu_types,
527+
generic_types=generic_types)
513528

514529
slot += 1
515530
iommu_group += 1
@@ -555,9 +570,9 @@ def __init__(self, num_pci=0, num_pfs=2, num_vfs=8, num_mdevcap=0,
555570

556571
def add_device(
557572
self, dev_type, bus, slot, function, iommu_group, numa_node,
558-
vf_ratio=None, multiple_gpu_types=False, parent=None,
559-
vend_id=None, vend_name=None, prod_id=None, prod_name=None,
560-
driver_name=None,
573+
vf_ratio=None, multiple_gpu_types=False, generic_types=False,
574+
parent=None, vend_id=None, vend_name=None, prod_id=None,
575+
prod_name=None, driver_name=None,
561576
):
562577
pci_dev_name = _get_libvirt_nodedev_name(bus, slot, function)
563578

@@ -572,6 +587,7 @@ def add_device(
572587
numa_node=numa_node,
573588
vf_ratio=vf_ratio,
574589
multiple_gpu_types=multiple_gpu_types,
590+
generic_types=generic_types,
575591
parent=parent,
576592
vend_id=vend_id,
577593
vend_name=vend_name,

nova/tests/functional/libvirt/test_reshape.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ def test_create_servers_with_vgpu(
6464
fakelibvirt.FakeMdevDevice(
6565
dev_name='mdev_4b20d080_1b54_4048_85b3_a6a62d165c01',
6666
type_id=fakelibvirt.NVIDIA_11_VGPU_TYPE,
67-
parent=fakelibvirt.PGPU1_PCI_ADDR),
67+
parent=fakelibvirt.MDEVCAP_DEV1_PCI_ADDR),
6868
'mdev_4b20d080_1b54_4048_85b3_a6a62d165c02':
6969
fakelibvirt.FakeMdevDevice(
7070
dev_name='mdev_4b20d080_1b54_4048_85b3_a6a62d165c02',
7171
type_id=fakelibvirt.NVIDIA_11_VGPU_TYPE,
72-
parent=fakelibvirt.PGPU2_PCI_ADDR),
72+
parent=fakelibvirt.MDEVCAP_DEV2_PCI_ADDR),
7373
'mdev_4b20d080_1b54_4048_85b3_a6a62d165c03':
7474
fakelibvirt.FakeMdevDevice(
7575
dev_name='mdev_4b20d080_1b54_4048_85b3_a6a62d165c03',
7676
type_id=fakelibvirt.NVIDIA_11_VGPU_TYPE,
77-
parent=fakelibvirt.PGPU3_PCI_ADDR),
77+
parent=fakelibvirt.MDEVCAP_DEV3_PCI_ADDR),
7878
}
7979

8080
# start a compute with vgpu support disabled so the driver will
@@ -181,9 +181,9 @@ def test_create_servers_with_vgpu(
181181
# which ones are used.
182182
usages = {}
183183
pgpu_uuid_to_name = {}
184-
for pci_device in [fakelibvirt.PGPU1_PCI_ADDR,
185-
fakelibvirt.PGPU2_PCI_ADDR,
186-
fakelibvirt.PGPU3_PCI_ADDR]:
184+
for pci_device in [fakelibvirt.MDEVCAP_DEV1_PCI_ADDR,
185+
fakelibvirt.MDEVCAP_DEV2_PCI_ADDR,
186+
fakelibvirt.MDEVCAP_DEV3_PCI_ADDR]:
187187
gpu_rp_uuid = self.placement.get(
188188
'/resource_providers?name=compute1_%s' % pci_device).body[
189189
'resource_providers'][0]['uuid']

0 commit comments

Comments
 (0)