From 0303fde937fd09f8e9b7d8114b538a585fc3ba1c Mon Sep 17 00:00:00 2001 From: Yumeng Bao Date: Mon, 24 Feb 2020 01:22:09 -0800 Subject: [PATCH] Fix GPU's improper cpid_type allowed value and attach_handle_type value ``ControlPathID`` table tracks identifiers for a control path interface to devices. When we were discussing the valid values of cpid_type at 2020-02-27 Cyborg weekly meeting[0], an agreement was made that allowed cpid_type values are "PCI". And for GPUs (either pGPU or vGPU), they all report "PCI" as their cpid_type, while ``attach_handle_type`` of them are different. This patch fixes the improper cpid_type allowed value and attach_handle_type value. No unit test is affected. vGPU report will be implemented in future release. [0]http://eavesdrop.openstack.org/meetings/openstack_cyborg/2020/openstack_cyborg.2020-02-27-03.00.log.html Closes task: 38954 Change-Id: Iafb23b47bf022f81776af77d205fc788d1b0d6b6 --- cyborg/accelerator/drivers/gpu/utils.py | 7 ++++++- cyborg/common/constants.py | 4 ++++ cyborg/objects/control_path.py | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cyborg/accelerator/drivers/gpu/utils.py b/cyborg/accelerator/drivers/gpu/utils.py index a53fb94d..41088e39 100644 --- a/cyborg/accelerator/drivers/gpu/utils.py +++ b/cyborg/accelerator/drivers/gpu/utils.py @@ -119,6 +119,8 @@ def _generate_driver_device(gpu): def _generate_controlpath_id(gpu): driver_cpid = driver_controlpath_id.DriverControlPathID() + # NOTE: GPUs (either pGPU or vGPU), they all report "PCI" as + # their cpid_type, while attach_handle_type of them are different. driver_cpid.cpid_type = "PCI" driver_cpid.cpid_info = utils.pci_str_to_json(gpu["devices"]) return driver_cpid @@ -147,7 +149,10 @@ def _generate_dep_list(gpu): def _generate_attach_handle(gpu): driver_ah = driver_attach_handle.DriverAttachHandle() - driver_ah.attach_type = constants.AH_TYPE_PCI + if gpu["rc"] == "PGPU": + driver_ah.attach_type = constants.AH_TYPE_PCI + else: + driver_ah.attach_type = constants.AH_TYPE_MDEV driver_ah.in_use = False driver_ah.attach_info = utils.pci_str_to_json(gpu["devices"]) return driver_ah diff --git a/cyborg/common/constants.py b/cyborg/common/constants.py index 286ad62d..119ef777 100644 --- a/cyborg/common/constants.py +++ b/cyborg/common/constants.py @@ -66,6 +66,10 @@ ATTACH_HANDLE_TYPES = (AH_TYPE_PCI, AH_TYPE_MDEV, AH_TYPE_TEST_PCI) = ( "PCI", "MDEV", "TEST_PCI") +# Control Path ID type +CPID_TYPE = (CPID_TYPE_PCI) = ("PCI") + + # Resource Class RESOURCES = { "FPGA": orc.FPGA, diff --git a/cyborg/objects/control_path.py b/cyborg/objects/control_path.py index 8f40d793..123e3f87 100644 --- a/cyborg/objects/control_path.py +++ b/cyborg/objects/control_path.py @@ -17,14 +17,13 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_versionedobjects import base as object_base +from cyborg.common import constants from cyborg.db import api as dbapi from cyborg.objects import base from cyborg.objects import fields as object_fields LOG = logging.getLogger(__name__) -CPID_TYPE = ["PCI", "MDEV"] - @base.CyborgObjectRegistry.register class ControlpathID(base.CyborgObject, object_base.VersionedObjectDictCompat): @@ -38,8 +37,9 @@ class ControlpathID(base.CyborgObject, object_base.VersionedObjectDictCompat): 'id': object_fields.IntegerField(nullable=False), 'uuid': object_fields.UUIDField(nullable=False), 'device_id': object_fields.IntegerField(nullable=False), - 'cpid_type': object_fields.EnumField(valid_values=CPID_TYPE, - nullable=False), + 'cpid_type': object_fields.EnumField( + valid_values=constants.CPID_TYPE, + nullable=False), 'cpid_info': object_fields.StringField(nullable=False) }