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 4120E45830; Wed, 21 Aug 2024 16:54:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B3C4A4278E; Wed, 21 Aug 2024 16:53:30 +0200 (CEST) Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by mails.dpdk.org (Postfix) with ESMTP id ADB80415D7 for ; Wed, 21 Aug 2024 16:53:26 +0200 (CEST) Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a7de4364ca8so747267166b.2 for ; Wed, 21 Aug 2024 07:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1724252006; x=1724856806; 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=Bac+s+7Xg+cl3PKbrjUDDqu6SNMsuzsAzsw7hSoypkM=; b=JkkLx6XiGUAApxT0tvLn+OI7zTncrWtWxKJSoVpgILAe0nREft0yezui8ixakqANvB dHuIAiyLx4RfBJT+4nBm2dGrzHFBrhz/gDjQsU5MzJH053rdvbX5j9/F15VqWP5emFHd EZcUxeEGjdeSeeSlv2EGHjDwU0ojOaKpP41VY4offvT1nCqWiRtva7I7NLwqkVMgvPzm 9IkraKjPEQRmETT0flXMvEsgMRJmHpwx/3la1Heg1yh8uDQWcX47qJtcsJ/xRr6yceiY ZrDHhupLOJCS/ggkjg7TNFoBikIGP/9t7Xn4H44jsolG2PoEd7rpobSoFkM3xt8bmMpj KT2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724252006; x=1724856806; 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=Bac+s+7Xg+cl3PKbrjUDDqu6SNMsuzsAzsw7hSoypkM=; b=sQD1GOeBRKN7qstmfmxrfhoLPcpHXwnxG8ZkMe26HJu7KsPkZepbLv5tTbSfv0DvyS 46mLxOyVdJq/NAd2pEfI4KpyFlplIHGhzvlUI7FX6lazb0PeFBIN3Av7avH07e/cIoxo dFEgQZU+s+ksb9t/eTbpHinnBYddWAC13jOdyHxWvz8EVMPnBIfv0b/WJ1oeDlWEpXyw EmoGN/L5fP74OLbV4vU08d8yIKfQOd5ISMtX640C/VmF/BPrwhZwfRPshku2Zg823RZR twfe5zLenWll394VRvqd0oBLg/XBAQY0K21y4lO5dA8lvjK+o9EkTc4pLoZvsXqTrNug HQ/A== X-Gm-Message-State: AOJu0YwTFdT8bZpDVHXX/M/gv/VZRzZ+itWPPqvlylMpPkJ8zAzgWG9S JmfxyDiaPjqrK2kBRTtNdTbGWxqmf8WHleV8vboKi4CqYOPJhAJVuP9SkjEE0GV5iPHtfiVlNgj jxAM= X-Google-Smtp-Source: AGHT+IEfAe1L0oYj1Ts96w68VNjcUwN7OVDbZJGTxKCCSvTrDEIA3mlDkzaJ7XHGypBKDtxvpNOp6w== X-Received: by 2002:a17:907:2d8f:b0:a86:82e2:8c64 with SMTP id a640c23a62f3a-a8682e28e67mr86241266b.35.1724252006210; Wed, 21 Aug 2024 07:53:26 -0700 (PDT) Received: from localhost.localdomain ([84.245.121.236]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8680c4725csm52434866b.91.2024.08.21.07.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 07:53:26 -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 v3 07/12] dts: add testpmd port information caching Date: Wed, 21 Aug 2024 16:53:10 +0200 Message-Id: <20240821145315.97974-8-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821145315.97974-1-juraj.linkes@pantheon.tech> References: <20240301155416.96960-1-juraj.linkes@pantheon.tech> <20240821145315.97974-1-juraj.linkes@pantheon.tech> 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. 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 b4ad253020..f0bcc918e5 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -654,6 +654,7 @@ class TestPmdShell(DPDKShell): """ _app_params: TestPmdParams + _ports: list[TestPmdPort] | None #: The path to the testpmd executable. path: ClassVar[PurePath] = PurePath("app", "dpdk-testpmd") @@ -686,6 +687,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. @@ -872,7 +888,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. @@ -890,7 +907,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