From patchwork Thu May 11 09:14:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 126822 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4221342A1B; Thu, 11 May 2023 11:14:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 81F7142F86; Thu, 11 May 2023 11:14:21 +0200 (CEST) Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by mails.dpdk.org (Postfix) with ESMTP id 4A56A42DA4 for ; Thu, 11 May 2023 11:14:18 +0200 (CEST) Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-50bc2feb320so12952748a12.3 for ; Thu, 11 May 2023 02:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon-tech.20221208.gappssmtp.com; s=20221208; t=1683796458; x=1686388458; 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=ItoRxVanKy6D7IaGIQZ4Ryqm65ysDjeB2kD3cnEkZQk=; b=dCqx0V2GODQbVyqVFBeu80xrOzcTwVWaaKOCLlOc5RWrNFshnN5wTUFV50PwR4TJs2 Bk3QGSN9gsxFFoaw080L5fFhPW1rHMskShUMSEXRAvdYaM3qrW16uJmdoxT4Mie60WLR 2aRpQmkUEYVpJ0kr4/FOcK2rpCgdPtw9E8kd3Koz3+erA2ToABUzibLNobeWfIdVMLOL oNmns4idsYcLuMGq7Nw8C7z4WXE72e7xdEcCU20oyTuPWDfo8/aJECBaOKbr54yFyonv Rzwvfu0uBmlD7nOpqM+i80shTkD4kmf8TsQrB1kOgdv71gP2eBip5xNpgJ06LrsUF5V6 fs9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683796458; x=1686388458; 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=ItoRxVanKy6D7IaGIQZ4Ryqm65ysDjeB2kD3cnEkZQk=; b=JSMvdKZZbpkWDD5wknOYnbJWxW2URABdO40vBs/AXEaV7hpy9nZ1WtincgTbuzpQra IllrKx/szm6o8+jMIGZ+qBrDgyvc/NsSS8h3Yee1Qwz6tj5u4fGij0cn4Rdk4aPS67sD PVsdSXZenvYg+1Z7Syfg90nGZkFxvUjhhINz2BnI4aiEE8fK/FCqN5g7qtNFocaFZHnv +HnVC1GHddw7NULBUYmOznY9BUxYoI3dulZDr5ROqrlWCq3W6t8n2EWb1tzVYlCeYV+s Y68fjKICr8za+dCxsZ6A3bxgmt3yX2Ln780GzrY1yKaVh39ahGUCMJ6NvUn0qi0qkqAO INsw== X-Gm-Message-State: AC+VfDy0Yl79yohm8Q5IjOR2MeHII8cAp+L1NAkPBVSW7vogZzv1xwcg qPXQjb5XtOTMvr/LoM6KsBHT5Q== X-Google-Smtp-Source: ACHHUZ7gt6Kqe5MXm3vKHvoKiLFdWIYJjfmy1ehN4XUqv8iqUuVfDuBH/6IxyUtctRVMdUUF2Nz8mw== X-Received: by 2002:a17:907:6ea1:b0:958:4c75:705e with SMTP id sh33-20020a1709076ea100b009584c75705emr23588412ejc.17.1683796457840; Thu, 11 May 2023 02:14:17 -0700 (PDT) Received: from localhost.localdomain (ip-46.34.233.151.o2inet.sk. [46.34.233.151]) by smtp.gmail.com with ESMTPSA id qa8-20020a170907868800b0096a2eaa508asm1710090ejc.168.2023.05.11.02.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 02:14:17 -0700 (PDT) From: =?utf-8?q?Juraj_Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, lijuan.tu@intel.com, bruce.richardson@intel.com, wathsala.vithanage@arm.com, jspewock@iol.unh.edu, probb@iol.unh.edu Cc: dev@dpdk.org, =?utf-8?q?Juraj_Linke=C5=A1?= Subject: [RFC PATCH v3 4/4] dts: format docstrigs to google format Date: Thu, 11 May 2023 11:14:08 +0200 Message-Id: <20230511091408.236638-5-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230511091408.236638-1-juraj.linkes@pantheon.tech> References: <20230504123749.1417259-1-juraj.linkes@pantheon.tech> <20230511091408.236638-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 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 WIP: only one module is reformatted to serve as a demonstration. The google format is documented here [0]. [0]: https://google.github.io/styleguide/pyguide.html Signed-off-by: Juraj Linkeš Acked-by: Jeremy Spweock --- dts/framework/testbed_model/node.py | 152 +++++++++++++++++++--------- 1 file changed, 103 insertions(+), 49 deletions(-) diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py index 90467981c3..ad8ef442af 100644 --- a/dts/framework/testbed_model/node.py +++ b/dts/framework/testbed_model/node.py @@ -3,8 +3,13 @@ # Copyright(c) 2022-2023 PANTHEON.tech s.r.o. # Copyright(c) 2022-2023 University of New Hampshire -""" -A node is a generic host that DTS connects to and manages. +"""Common functionality for node management. + +There's a base class, Node, that's supposed to be extended by other classes +with functionality specific to that node type. +The only part that can be used standalone is the Node.skip_setup static method, +which is a decorator used to skip method execution +if skip_setup is passed by the user on the cmdline or in an env variable. """ from typing import Any, Callable @@ -26,10 +31,25 @@ class Node(object): - """ - Basic class for node management. This class implements methods that - manage a node, such as information gathering (of CPU/PCI/NIC) and - environment setup. + """The base class for node management. + + It shouldn't be instantiated, but rather extended. + It implements common methods to manage any node: + + * connection to the node + * information gathering of CPU + * hugepages setup + + Arguments: + node_config: The config from the input configuration file. + + Attributes: + main_session: The primary OS-agnostic remote session used + to communicate with the node. + config: The configuration used to create the node. + name: The name of the node. + lcores: The list of logical cores that DTS can use on the node. + It's derived from logical cores present on the node and user configuration. """ main_session: OSSession @@ -56,65 +76,89 @@ def __init__(self, node_config: NodeConfiguration): self._logger.info(f"Created node: {self.name}") def set_up_execution(self, execution_config: ExecutionConfiguration) -> None: - """ - Perform the execution setup that will be done for each execution - this node is part of. + """Execution setup steps. + + Configure hugepages and call self._set_up_execution where + the rest of the configuration steps (if any) are implemented. + + Args: + execution_config: The execution configuration according to which + the setup steps will be taken. """ self._setup_hugepages() self._set_up_execution(execution_config) def _set_up_execution(self, execution_config: ExecutionConfiguration) -> None: - """ - This method exists to be optionally overwritten by derived classes and - is not decorated so that the derived class doesn't have to use the decorator. + """Optional additional execution setup steps for derived classes. + + Derived classes should overwrite this + if they want to add additional execution setup steps. """ def tear_down_execution(self) -> None: - """ - Perform the execution teardown that will be done after each execution - this node is part of concludes. + """Execution teardown steps. + + There are currently no common execution teardown steps + common to all DTS node types. """ self._tear_down_execution() def _tear_down_execution(self) -> None: - """ - This method exists to be optionally overwritten by derived classes and - is not decorated so that the derived class doesn't have to use the decorator. + """Optional additional execution teardown steps for derived classes. + + Derived classes should overwrite this + if they want to add additional execution teardown steps. """ def set_up_build_target( self, build_target_config: BuildTargetConfiguration ) -> None: - """ - Perform the build target setup that will be done for each build target - tested on this node. + """Build target setup steps. + + There are currently no common build target setup steps + common to all DTS node types. + + Args: + build_target_config: The build target configuration according to which + the setup steps will be taken. """ self._set_up_build_target(build_target_config) def _set_up_build_target( self, build_target_config: BuildTargetConfiguration ) -> None: - """ - This method exists to be optionally overwritten by derived classes and - is not decorated so that the derived class doesn't have to use the decorator. + """Optional additional build target setup steps for derived classes. + + Derived classes should optionally overwrite this + if they want to add additional build target setup steps. """ def tear_down_build_target(self) -> None: - """ - Perform the build target teardown that will be done after each build target - tested on this node. + """Build target teardown steps. + + There are currently no common build target teardown steps + common to all DTS node types. """ self._tear_down_build_target() def _tear_down_build_target(self) -> None: - """ - This method exists to be optionally overwritten by derived classes and - is not decorated so that the derived class doesn't have to use the decorator. + """Optional additional build target teardown steps for derived classes. + + Derived classes should overwrite this + if they want to add additional build target teardown steps. """ def create_session(self, name: str) -> OSSession: - """ - Create and return a new OSSession tailored to the remote OS. + """Create and return a new OS-agnostic remote session. + + The returned session won't be used by the object creating it. + Will be cleaned up automatically. + + Args: + name: The name of the session. + + Returns: + A new OS-agnostic remote session. """ session_name = f"{self.name} {name}" connection = create_session( @@ -130,14 +174,24 @@ def filter_lcores( filter_specifier: LogicalCoreCount | LogicalCoreList, ascending: bool = True, ) -> list[LogicalCore]: - """ - Filter the LogicalCores found on the Node according to - a LogicalCoreCount or a LogicalCoreList. + """Filter the node's logical cores that DTS can use. - If ascending is True, use cores with the lowest numerical id first - and continue in ascending order. If False, start with the highest - id and continue in descending order. This ordering affects which - sockets to consider first as well. + Logical cores that DTS can use are ones that are present on the node, + but filtered according to user config. + The filter_specifier will filter cores from those logical cores. + + Args: + filter_specifier: Two different filters can be used, one that specifies + the number of logical cores per core, cores per socket and + the number of sockets, + the other that specifies a logical core list. + ascending: If True, use cores with the lowest numerical id first + and continue in ascending order. If False, start with the highest + id and continue in descending order. This ordering affects which + sockets to consider first as well. + + Returns: + A list of logical cores. """ self._logger.debug(f"Filtering {filter_specifier} from {self.lcores}.") return lcore_filter( @@ -147,17 +201,14 @@ def filter_lcores( ).filter() def _get_remote_cpus(self) -> None: - """ - Scan CPUs in the remote OS and store a list of LogicalCores. - """ + """Scan CPUs in the remote OS and store a list of LogicalCores.""" self._logger.info("Getting CPU information.") self.lcores = self.main_session.get_remote_cpus(self.config.use_first_core) def _setup_hugepages(self): - """ - Setup hugepages on the Node. Different architectures can supply different - amounts of memory for hugepages and numa-based hugepage allocation may need - to be considered. + """Setup hugepages on the Node. + + Configure the hugepages only if they're specified in user configuration. """ if self.config.hugepages: self.main_session.setup_hugepages( @@ -165,9 +216,7 @@ def _setup_hugepages(self): ) def close(self) -> None: - """ - Close all connections and free other resources. - """ + """Close all connections and free other resources.""" if self.main_session: self.main_session.close() for session in self._other_sessions: @@ -176,6 +225,11 @@ def close(self) -> None: @staticmethod def skip_setup(func: Callable[..., Any]) -> Callable[..., Any]: + """A decorator that skips the decorated function. + + When used, the decorator executes an empty lambda function + instead of the decorated function. + """ if SETTINGS.skip_setup: return lambda *args: None else: