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 EE41345A29; Wed, 25 Sep 2024 15:29:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 797894025D; Wed, 25 Sep 2024 15:29:08 +0200 (CEST) Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by mails.dpdk.org (Postfix) with ESMTP id 27978400EF for ; Wed, 25 Sep 2024 15:29:06 +0200 (CEST) Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a8d2b24b7a8so184990666b.1 for ; Wed, 25 Sep 2024 06:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1727270946; x=1727875746; darn=dpdk.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=gAyjsImCCgzVGGt/oV/X/bDCfG18OPcZMx53Sn1W1Rk=; b=FzuKLBM0/mxU8OV1BWwGSixG/XMuhZHRGCq00Se0+Uyvqwt9uYvOVytIq3rPHTQ7r0 5kCPtRy/Ku1qGxRlUWYlxPKmtHAUNs/QG1kgzUiAIZp5NsDmV5VrhMUqCCykkLMBQvzd cciT1jKCEFZPBGCXOXO3PQ+w8RalvlcIroTbIcS6T40SsGmOl3tSikcJII/GU06GPeHz HhoSR0/X1IeoHo4Px6TjYFxN8yEwDNEy+oTDYHLMp7UcqiUQ6Ks1wvc5vfXXgzikq/0J MCcKG/h2guUKXQV2M+7jeY+uxg4VWzqHMdOtVFPBR8KgKhenRZ951gJJnWwTnkHRlHpP VLiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727270946; x=1727875746; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gAyjsImCCgzVGGt/oV/X/bDCfG18OPcZMx53Sn1W1Rk=; b=bmQsj8fHFDJhXu3h2cX5sPSYl/BPskJ1Hp2GTpI60zQI62lm1n1JIO7x3vIkJhPUwI pLDrfP+GayQeuHh8/nhhsxseRDzE8pvCdkbxvFjujRujw/0H/tljid12CTv+YtGBzojo VLYv3NZUAiENm9X+G1Ccu28zvWnQq6J8Ke8AE3YkUrOogRyG7U9PQ/C5lO75U2pwCxbl MBVB+WsCCp8EIXlFiCZVmst9P1/w0JPmAEuCPLNXuIrvBzTVxLQ5Nr0PeZp/5GTbniQ0 P7otl43TvEtwqX+JsPSIQ/lhs2b6OR5tYooXTQmpXvTkfA+igNZwCuk6Kw5iW649+10I czNw== X-Gm-Message-State: AOJu0YxhNWfii74peAx1TFAfgeeoWjPT+BqioTFOy27aUDXlI+OrFLf/ 2s18mg2/NZ/ovPDegiXEAG17pBUblwpwLPffjyb+l2XNluBXL5036HQMArgx7aA= X-Google-Smtp-Source: AGHT+IGEbGj0tbGhYXv8Gtekm0Ch6a7mixH5nUBZZrNp/HLXRUAE3VGuz7PQe1LdDgS4wOtkznXn1A== X-Received: by 2002:a17:907:1c15:b0:a90:9879:582b with SMTP id a640c23a62f3a-a93a16d0bc7mr311032866b.14.1727270945689; Wed, 25 Sep 2024 06:29:05 -0700 (PDT) Received: from [192.168.200.22] ([84.245.121.62]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9392f33efbsm212785866b.10.2024.09.25.06.29.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 06:29:05 -0700 (PDT) Message-ID: Date: Wed, 25 Sep 2024 15:29:03 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 5/5] dts: add functions for managing VFs to Node To: jspewock@iol.unh.edu, npratte@iol.unh.edu, 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 References: <20240821191557.18744-1-jspewock@iol.unh.edu> <20240923184235.22582-1-jspewock@iol.unh.edu> <20240923184235.22582-6-jspewock@iol.unh.edu> Content-Language: en-US From: =?UTF-8?Q?Juraj_Linke=C5=A1?= In-Reply-To: <20240923184235.22582-6-jspewock@iol.unh.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 I'm wondering whether we should move some of the functionality to the Port class, such as creating VFs and related logic. I wanted to move update_port and such there, but I ran into problems with imports. Maybe if we utilize the if TYPE_CHECKING: guard the imports would work. Seems like a lot would be simplified if we moved the VFs ports inside the Port class. > diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py > class Node(ABC): > @@ -276,6 +277,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. We should check that the passed port actually resides on this node. > + 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] > + ] Maybe we should create a PciAddress class that would process the address and provide useful methods, one of which we'd use here. > + # 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 These are OS drivers, not PMDs. > + 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 This looks like a good candidate for TextParser. > + > + 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]) This should be called after the for cycle so we only call it once. We can bind all VF ports after (again, preferably with just one call).