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 4AB37457FE; Fri, 23 Aug 2024 09:41:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D9E9143245; Fri, 23 Aug 2024 09:41:40 +0200 (CEST) Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by mails.dpdk.org (Postfix) with ESMTP id 0887842FEF for ; Fri, 23 Aug 2024 09:41:40 +0200 (CEST) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4280ee5f1e3so13196645e9.0 for ; Fri, 23 Aug 2024 00:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1724398899; x=1725003699; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RX0ELEHvidysfNci/LfrVTsiL8pS06qTsVAtl/xo4bQ=; b=CcXp8BWhIrYaYmmk/eFjHF1bETMOImP4sIsaGmE2N6i/o0+oZXQ+2PJQWxrW6hkuv+ yIS0CECDo69vimZDC8RnfPmTfPPWSiVuddA1/J6Sz4amUgRV2zRnNXmYtiIws3/VtrPr twyBYZMHlDPUi4cgH6JHN0lPPMwevlgJOqxyHl6SzKkoCJUKX7toZYf4rscGShdguhRq +PF+8sGsvmhEDa/z34218eHcHwliHxDjN7Wp2XNs4A0CgOzgNE5E6OeWr/5meonaZEQS LpIP6gkB488b1Id2+TassaD6b3a2V8O6LWKh1whG1tv83/gVdfGx9V/Q+yEyYciboEpi ZRDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724398899; x=1725003699; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RX0ELEHvidysfNci/LfrVTsiL8pS06qTsVAtl/xo4bQ=; b=cAFUeINFI/afZ5wP6w/q4JiKVKEXrREW9xc35Q7xr3Y+ab+QyTZsKIteUdCze/gFzJ i878FxXArlJqaPVrZ39qVq5926HRk0Ie3l4IPmHeepcZqyOA1kOwrG7TPedbUcYU980a 2klAp2A0k/0hPobae40ObVwcVWF5FZ7j57chJiu+wKGCqdRSSRKEBR4mFMC4QGNwgZyz A8qDudKHyrPUri4cuXyun7YLa7qAYfGy6jFe7CvmB0cjJuk4k6x0xmy9AbV0GvNUd5cp wZkloG2ukPhUL+pX2bGMEg0BRyFHt9xus1YdwjaVDkKsTs3fJCzMpQ27fKl/aEMcns6D qcvg== X-Gm-Message-State: AOJu0Yw7HSZh+MtFgYq5o0yDWFD09MR570XCNxG9bldLxc00oSSKRspT Xy8C97eOrSD8tTaADMZ6oQXaJUhYeeNyAHK1FCQJsX2c4f1vfcNsWdG5WtE0VeE= X-Google-Smtp-Source: AGHT+IHsZCgKfyCYedV/GcawneLpT7WPajzAvcM53llJ0OkuRhzOcNCGduQCQz2ICigZAaYSCfkZSw== X-Received: by 2002:a05:600c:4e8a:b0:428:150e:4f13 with SMTP id 5b1f17b1804b1-42acca0199emr9179055e9.33.1724398899333; Fri, 23 Aug 2024 00:41:39 -0700 (PDT) Received: from localhost.localdomain ([84.245.121.107]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac517a442sm50486115e9.36.2024.08.23.00.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 00:41:39 -0700 (PDT) From: =?UTF-8?q?Juraj=20Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, jspewock@iol.unh.edu, probb@iol.unh.edu, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, npratte@iol.unh.edu, dmarx@iol.unh.edu, alex.chapman@arm.com Cc: dev@dpdk.org, =?UTF-8?q?Juraj=20Linke=C5=A1?= Subject: [PATCH v1] dts: add testpmd port information caching Date: Fri, 23 Aug 2024 09:41:37 +0200 Message-Id: <20240823074137.13989-1-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 When using port information multiple times in a testpmd shell instance lifespan, it's desirable to not get the information each time, so caching is added. In case the information changes, there's a way to force the update with either TestPmdShell.show_port_info() or TestPmdShell.show_port_info_all(). Signed-off-by: Juraj Linkeš --- dts/framework/remote_session/testpmd_shell.py | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 43e9f56517..0a5cb385c9 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -586,6 +586,7 @@ class TestPmdShell(DPDKShell): """ _app_params: TestPmdParams + _ports: list[TestPmdPort] | None #: The path to the testpmd executable. path: ClassVar[PurePath] = PurePath("app", "dpdk-testpmd") @@ -618,6 +619,21 @@ def __init__( TestPmdParams(**app_params), name, ) + self._ports = None + + @property + def ports(self) -> list[TestPmdPort]: + """The ports of the instance. + + This caches the ports returned by :meth:`show_port_info_all`. + To force an update of port information, execute :meth:`show_port_info_all` or + :meth:`show_port_info`. + + Returns: The list of known testpmd ports. + """ + if self._ports is None: + return self.show_port_info_all() + return self._ports def start(self, verify: bool = True) -> None: """Start packet forwarding with the current configuration. @@ -747,7 +763,8 @@ def show_port_info_all(self) -> list[TestPmdPort]: # executed on a pseudo-terminal created by paramiko on the remote node, lines end with CRLF. # Therefore we also need to take the carriage return into account. iter = re.finditer(r"\*{21}.*?[\r\n]{4}", output + "\r\n", re.S) - return [TestPmdPort.parse(block.group(0)) for block in iter] + self._ports = [TestPmdPort.parse(block.group(0)) for block in iter] + return self._ports def show_port_info(self, port_id: int) -> TestPmdPort: """Returns the given port information. @@ -765,7 +782,16 @@ def show_port_info(self, port_id: int) -> TestPmdPort: if output.startswith("Invalid port"): raise InteractiveCommandExecutionError("invalid port given") - return TestPmdPort.parse(output) + port = TestPmdPort.parse(output) + self._update_port(port) + return port + + def _update_port(self, port: TestPmdPort) -> None: + if self._ports: + self._ports = [ + existing_port if port.id != existing_port.id else port + for existing_port in self._ports + ] def show_port_stats_all(self) -> list[TestPmdPortStats]: """Returns the statistics of all the ports. -- 2.34.1