From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 531E345838; Wed, 21 Aug 2024 23:31:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6D82F42E1D; Wed, 21 Aug 2024 23:31:14 +0200 (CEST) Received: from mail-ot1-f100.google.com (mail-ot1-f100.google.com [209.85.210.100]) by mails.dpdk.org (Postfix) with ESMTP id 33F6E42E49 for ; Wed, 21 Aug 2024 23:31:12 +0200 (CEST) Received: by mail-ot1-f100.google.com with SMTP id 46e09a7af769-70949118d26so155073a34.0 for ; Wed, 21 Aug 2024 14:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1724275871; x=1724880671; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vG8EY4mNSxLdW17S0Lx3oqM/z0QMlUYuXV4e1/CLlgY=; b=FBts8uE8cFH8I/vMhJx5iIYHseS/SmfGGWpP3DJrXBmpsrHoM7oE6aJWVt6mPYVkN7 Bav0pgJQoUz/Bjf7DkdDvwNzie/XXngV8A1WYZ3wGIjjjWHDhN6FKEhHs0STIRM8nZq3 fZcjiDRUtAv7KWVNb2T/qrMFJ7/z668gPFi6E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724275871; x=1724880671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vG8EY4mNSxLdW17S0Lx3oqM/z0QMlUYuXV4e1/CLlgY=; b=SpXcO1Bkw6RU5xatWU1tV6hx/rx6zAwFBMkym5gHSS3H+aYIu7++/9W6B+ANLoHpGe bPGte67ZR8lhPONytV2fn9f1bsZ5ERrKw7RyVMkiv4ogTp6h0n5rLXxLcIYNqVY+yFxY /n8ZQ6xGJGOdQyWpRZvrFgswnDUxhrne1NRGxRkS6wloQJ6DGtkz8EJTMMFr6zcNCWh6 H2jNoTVwClzBf+8YRfKm3eOq9q8S8aW/f70L3TCs+HMVXrDl2KAea3zm7nr9dR6kI09M izRtm7HzirgPwqq2GbdyQrnyoQsCadXu8ubL7jWS+xeAl4FLsfGC8zsx9YksDbINwDut m7oQ== X-Gm-Message-State: AOJu0Yxvw799lcpSf3VoBMbWtSDm/pandvc7RsNxLlZ2UcbZETz2GJnI pK3cpGh6TQrDl2JNqQ23xxsG6RDFUCteFB4ceFxkmqsDOvT5YwvnvwzxLACqv1mlx6qx5h4C8aN WAC/vkEKxN9Ffbx1UdEwnamyak2MmHPYh X-Google-Smtp-Source: AGHT+IEID1wzYyakj4P2CM0UtdR637Hc/Mow6ZQHIbFsfCmtoBYtjMy4gWi+geggaVFLBkxh59xeu7y1EfoJ X-Received: by 2002:a05:6830:2806:b0:709:4936:d8fd with SMTP id 46e09a7af769-70df88967e2mr4796808a34.29.1724275871283; Wed, 21 Aug 2024 14:31:11 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [132.177.123.84]) by smtp-relay.gmail.com with ESMTPS id 46e09a7af769-70e03897d8csm4763a34.0.2024.08.21.14.31.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Aug 2024 14:31:11 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::1083]) by postal.iol.unh.edu (Postfix) with ESMTP id 698D9605C352; Wed, 21 Aug 2024 17:31:10 -0400 (EDT) From: jspewock@iol.unh.edu To: Luca.Vizzarro@arm.com, thomas@monjalon.net, paul.szczepanek@arm.com, wathsala.vithanage@arm.com, probb@iol.unh.edu, yoan.picchi@foss.arm.com, juraj.linkes@pantheon.tech, Honnappa.Nagarahalli@arm.com, npratte@iol.unh.edu, alex.chapman@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [RFC PATCH v3 5/5] dts: add functions for managing VFs to Node Date: Wed, 21 Aug 2024 17:30:42 -0400 Message-ID: <20240821213042.24814-6-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240821213042.24814-1-jspewock@iol.unh.edu> References: <20240821191557.18744-1-jspewock@iol.unh.edu> <20240821213042.24814-1-jspewock@iol.unh.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Jeremy Spewock In order for test suites to create virtual functions there has to be functions in the API that developers can use. This patch adds the ability to create virtual functions to the Node API so that they are reachable within test suites. Bugzilla ID: 1500 Depends-on: patch-143101 ("dts: add binding to different drivers to TG node") Signed-off-by: Jeremy Spewock --- dts/framework/testbed_model/node.py | 96 ++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py index 85d4eb1f7c..101a8edfbc 100644 --- a/dts/framework/testbed_model/node.py +++ b/dts/framework/testbed_model/node.py @@ -14,6 +14,7 @@ """ import os +import re import tarfile from abc import ABC from ipaddress import IPv4Interface, IPv6Interface @@ -24,9 +25,10 @@ OS, BuildTargetConfiguration, NodeConfiguration, + PortConfig, TestRunConfiguration, ) -from framework.exception import ConfigurationError +from framework.exception import ConfigurationError, InternalError from framework.logger import DTSLogger, get_dts_logger from framework.settings import SETTINGS @@ -39,7 +41,7 @@ ) from .linux_session import LinuxSession from .os_session import OSSession -from .port import Port +from .port import Port, VirtualFunction class Node(ABC): @@ -335,6 +337,96 @@ def _bind_port_to_driver(self, port: Port, for_dpdk: bool = True) -> None: verify=True, ) + def create_virtual_functions( + self, num: int, pf_port: Port, dpdk_driver: str | None = None + ) -> list[VirtualFunction]: + """Create virtual functions (VFs) from a given physical function (PF) on the node. + + Virtual functions will be created if there are not any currently configured on `pf_port`. + If there are greater than or equal to `num` VFs already configured on `pf_port`, those will + be used instead of creating more. In order to create VFs, the PF must be bound to its + kernel driver. This method will handle binding `pf_port` and any other ports in the test + run that reside on the same device back to their OS drivers if this was not done already. + VFs gathered in this method will be bound to `driver` if one is provided, or the DPDK + driver for `pf_port` and then added to `self.ports`. + + Args: + num: The number of VFs to create. Must be greater than 0. + pf_port: The PF to create the VFs on. + dpdk_driver: Optional driver to bind the VFs to after they are created. Defaults to the + DPDK driver of `pf_port`. + + Raises: + InternalError: If `num` is less than or equal to 0. + """ + if num <= 0: + raise InternalError( + "Method for creating virtual functions received a non-positive value." + ) + if not dpdk_driver: + dpdk_driver = pf_port.os_driver_for_dpdk + # Get any other port that is on the same device which DTS is aware of + all_device_ports = [ + p for p in self.ports if p.pci.split(".")[0] == pf_port.pci.split(".")[0] + ] + # Ports must be bound to the kernel driver in order to create VFs from them + for port in all_device_ports: + self._bind_port_to_driver(port, False) + # Some PMDs require the interface being up in order to make VFs + self.configure_port_state(port) + created_vfs = self.main_session.set_num_virtual_functions(num, pf_port) + # We don't need more then `num` VFs from the list + vf_pcis = self.main_session.get_pci_addr_of_vfs(pf_port)[:num] + devbind_info = self.main_session.send_command( + f"{self.path_to_devbind_script} -s", privileged=True + ).stdout + + ret = [] + + for pci in vf_pcis: + original_driver = re.search(f"{pci}.*drv=([\\d\\w-]*)", devbind_info) + os_driver = original_driver[1] if original_driver else pf_port.os_driver + vf_config = PortConfig( + self.name, pci, dpdk_driver, os_driver, pf_port.peer.node, pf_port.peer.pci + ) + vf_port = VirtualFunction(self.name, vf_config, created_vfs, pf_port) + self.main_session.update_ports([vf_port]) + self._bind_port_to_driver(vf_port) + self.ports.append(vf_port) + ret.append(vf_port) + return ret + + def get_vfs_on_port(self, pf_port: Port) -> list[VirtualFunction]: + """Get all virtual functions (VFs) that DTS is aware of on `pf_port`. + + Args: + pf_port: The port to search for the VFs on. + + Returns: + A list of VFs in the framework that were created/gathered from `pf_port`. + """ + return [p for p in self.ports if isinstance(p, VirtualFunction) and p.pf_port == pf_port] + + def remove_virtual_functions(self, pf_port: Port) -> None: + """Removes all virtual functions (VFs) created on `pf_port` by DTS. + + Finds all the VFs that were created from `pf_port` and either removes them if they were + created by the DTS framework or binds them back to their os_driver if they were preexisting + on the node. + + Args: + pf_port: Port to remove the VFs from. + """ + vf_ports = self.get_vfs_on_port(pf_port) + if any(vf.created_by_framework for vf in vf_ports): + self.main_session.set_num_virtual_functions(0, pf_port) + else: + self._logger.info("Skipping removing VFs since they were not created by DTS.") + # Bind all VFs that we are no longer using back to their original driver + for vf in vf_ports: + self._bind_port_to_driver(vf, for_dpdk=False) + self.ports = [p for p in self.ports if p not in vf_ports] + def create_session(node_config: NodeConfiguration, name: str, logger: DTSLogger) -> OSSession: """Factory for OS-aware sessions. -- 2.46.0