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 2F2DD45A12; Mon, 23 Sep 2024 20:43:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 090D14060A; Mon, 23 Sep 2024 20:42:58 +0200 (CEST) Received: from mail-yb1-f227.google.com (mail-yb1-f227.google.com [209.85.219.227]) by mails.dpdk.org (Postfix) with ESMTP id A279F402CF for ; Mon, 23 Sep 2024 20:42:54 +0200 (CEST) Received: by mail-yb1-f227.google.com with SMTP id 3f1490d57ef6-e249807cf13so147656276.3 for ; Mon, 23 Sep 2024 11:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1727116974; x=1727721774; 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=nQJNsgpJJyV9wgXuic5bVU5OqpDNQI3p7LF2jhYr4OM=; b=hAJ1mWjzQ6rNlSzT5UgodwTsUokFnENuaEIi4+cHHU3kVybaJ9pKrZD4Bt/xNWda0y dZZfDiyy86Oyw9g/nc968O4V6EMNj8y/swutB7qvPx5vxwyNQ5ZMEnWHa7suVuAxuCt4 rhiCN0Rz+bbYLifXpH17iATVAJfIQZjq/gBck= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727116974; x=1727721774; 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=nQJNsgpJJyV9wgXuic5bVU5OqpDNQI3p7LF2jhYr4OM=; b=Gxts7lEJF/kX+Zk7ggMQ3A29FBTayqBCFSOtWJ6IS+u2+AjOo89y6FcWDgX15zXf9g A9B676F4JZBtBhpZCqaiSaDWzs7v21qRI4ukcFyszwfe/rS5g5fL6N0crChIq3TFSV02 xI+Yl7wcZY0cHF2X8wQsP5iwIuWwm/VcRm6kstlM/bOGlxNqEmUtHGSaJhq49pcZ3ahK ZxhsfRxpSaHdfkeGJdbwTIyDWF/89Z30Upfpz78dktlCfahQMfHeOoo/OIuvOa0Pzicl cu7eUIwgJVvSMPHZATezsDSWj8YdAxz1bBs1B+IURVdabBzFD76dVF6MCZl8Gco6hJ2k TPPg== X-Gm-Message-State: AOJu0YwdNt7KapffOrSk9VGVwztKERqeqhvvlaGoDUSxhcUtov6NqyAt DeRLXe04BmUG4IyeMGmhMjuiYVc7jW1xL2vdUtCGZWxXx4XbHhbFt1lAt6g5l8kvAuShtQS65Il 14pJimLUAJsgUudgsNGqYa0T9g495K2AV X-Google-Smtp-Source: AGHT+IHdrpjJ55o5ZyVTuZrGZ786NrW0YH2yn8UErqt43SsVrn4lOwsx2qDB6wq6hX4NmUz4/73OuVyScobT X-Received: by 2002:a05:690c:90:b0:6af:55ec:3cd7 with SMTP id 00721157ae682-6dff290369amr91405087b3.28.1727116973971; Mon, 23 Sep 2024 11:42:53 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [132.177.123.84]) by smtp-relay.gmail.com with ESMTPS id af79cd13be357-7acb07de0a7sm68319385a.2.2024.09.23.11.42.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 11:42:53 -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 EF791605C351; Mon, 23 Sep 2024 14:42:52 -0400 (EDT) From: jspewock@iol.unh.edu To: npratte@iol.unh.edu, juraj.linkes@pantheon.tech, yoan.picchi@foss.arm.com, thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, wathsala.vithanage@arm.com, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, alex.chapman@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v4 4/5] dts: add OS abstractions for creating virtual functions Date: Mon, 23 Sep 2024 14:42:34 -0400 Message-ID: <20240923184235.22582-5-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923184235.22582-1-jspewock@iol.unh.edu> References: <20240821191557.18744-1-jspewock@iol.unh.edu> <20240923184235.22582-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 Virtual functions in the framework are created using SR-IOV. The process for doing this can vary depending on the operating system, so the commands to create VFs have to be abstracted into different classes based on the operating system. This patch adds the stubs for methods that create VFs and get the PCI addresses of all VFs on a port to the abstract class as well as a linux implementation for the methods. Bugzilla ID: 1500 Signed-off-by: Jeremy Spewock --- dts/framework/testbed_model/linux_session.py | 40 +++++++++++++++++++- dts/framework/testbed_model/os_session.py | 40 ++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/dts/framework/testbed_model/linux_session.py b/dts/framework/testbed_model/linux_session.py index 544a665b83..2615411470 100644 --- a/dts/framework/testbed_model/linux_session.py +++ b/dts/framework/testbed_model/linux_session.py @@ -15,7 +15,11 @@ from typing_extensions import NotRequired -from framework.exception import ConfigurationError, RemoteCommandExecutionError +from framework.exception import ( + ConfigurationError, + InternalError, + RemoteCommandExecutionError, +) from framework.utils import expand_range from .cpu import LogicalCore @@ -210,3 +214,37 @@ def configure_ipv4_forwarding(self, enable: bool) -> None: """Overrides :meth:`~.os_session.OSSession.configure_ipv4_forwarding`.""" state = 1 if enable else 0 self.send_command(f"sysctl -w net.ipv4.ip_forward={state}", privileged=True) + + def set_num_virtual_functions(self, num: int, pf_port: Port) -> bool: + """Overrides :meth:`~.os_session.OSSession.set_num_virtual_functions`.""" + sys_bus_path = f"/sys/bus/pci/devices/{pf_port.pci}/sriov_numvfs".replace(":", "\\:") + curr_num_vfs = int(self.send_command(f"cat {sys_bus_path}").stdout) + if num > 0 and curr_num_vfs >= num: + self._logger.info( + f"{curr_num_vfs} VFs already configured on port {pf_port.identifier.pci} on node " + f"{pf_port.identifier.node}." + ) + return False + elif num > 0 and curr_num_vfs > 0: + self._logger.error( + f"Not enough VFs configured on port {pf_port.identifier.pci} on node " + f"{pf_port.identifier.node}. Need {num} but only {curr_num_vfs} are configured. " + "DTS is unable to modify number of preexisting VFs." + ) + raise InternalError("Failed to create VFs on port.") + self.send_command(f"echo {num} > {sys_bus_path}", privileged=True, verify=True) + return True + + def get_pci_addr_of_vfs(self, pf_port: Port) -> list[str]: + """Overrides :meth:`~.os_session.OSSession.get_pci_addr_of_vfs`.""" + sys_bus_path = f"/sys/bus/pci/devices/{pf_port.pci}".replace(":", "\\:") + curr_num_vfs = int(self.send_command(f"cat {sys_bus_path}/sriov_numvfs").stdout) + if curr_num_vfs > 0: + pci_addrs = self.send_command( + 'awk -F "PCI_SLOT_NAME=" "/PCI_SLOT_NAME=/ {print \\$2}" ' + + f"{sys_bus_path}/virtfn*/uevent", + privileged=True, + ) + return pci_addrs.stdout.splitlines() + else: + return [] diff --git a/dts/framework/testbed_model/os_session.py b/dts/framework/testbed_model/os_session.py index 79f56b289b..191fc3c0c8 100644 --- a/dts/framework/testbed_model/os_session.py +++ b/dts/framework/testbed_model/os_session.py @@ -395,3 +395,43 @@ def configure_ipv4_forwarding(self, enable: bool) -> None: Args: enable: If :data:`True`, enable the forwarding, otherwise disable it. """ + + @abstractmethod + def set_num_virtual_functions(self, num: int, pf_port: Port) -> bool: + """Update the number of virtual functions (VFs) on a port. + + It should be noted that, due to the nature of VFs, if there are already VFs that exist on + the physical function (PF) prior to calling this function, additional ones cannot be added. + The only way to add more VFs is to remove the existing and then set the desired amount. For + this reason, this method will handle creation in the following order: + + 1. Use existing VFs on the PF if the number of existing VFs is greater than or equal to + `num` + 2. Throw an exception noting that VFs cannot be created if the PF has some VFs already set + on it, but the total VFs that it has are less then `num`. + 3. Create `num` VFs on the PF if there are none on it already + + Args: + num: The number of VFs to set on the port. + pf_port: The port to add the VFs to. + + Raises: + InternalError: If `pf_port` has less than `num` VFs configured on it + already. + + Returns: + :data:`True` if this method successfully created VFs, :data:`False` if existing VFs + were used instead. + """ + + @abstractmethod + def get_pci_addr_of_vfs(self, pf_port: Port) -> list[str]: + """Find the PCI addresses of all virtual functions (VFs) on the port `pf_port`. + + Args: + pf_port: The port to find the VFs on. + + Returns: + A list containing all of the PCI addresses of the VFs on the port. If the port has no + VFs then the list will be empty. + """ -- 2.46.0