From patchwork Sun Sep 6 01:31:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76614 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 70D7AA04C5; Sun, 6 Sep 2020 03:31:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CBF791C0D2; Sun, 6 Sep 2020 03:31:46 +0200 (CEST) Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by dpdk.org (Postfix) with ESMTP id 9FDED2BAB for ; Sun, 6 Sep 2020 03:31:43 +0200 (CEST) Received: by mail-pj1-f65.google.com with SMTP id b16so4944467pjp.0 for ; Sat, 05 Sep 2020 18:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ciLvjNOIsfeYXD5MxG0NqKGDF/Q594uMpv3G9vdvQyE=; b=va9dZJwp54rz0Z1c4Ws4PXQClBBb47q/nmu7XOEmF15xR/GDsPpX6GN6s/m8gpk9E8 rkOBHs13EwyfyWxoDD7FzGfvWIEv6S5XVbPuHnVNrnGnnbv39NfKgOXHe5QHpJJNyOip WR29luOUG6pRonXTwOFZjdTsnkMILwuupT21IjjCJtCLrlgVw58J9Ngqpr2zOR/wm7u1 4JqHQ7KcUbMmhUG+NH3thlYXramXlQh1TH7Y/UJ8SgY0ZLy0ulqFcrHQrDzsfHcAvtd9 NUjgQqvwqWs4Kh3KichIF43PWY5NBbawEf54pBS40hrGAUztCY/ZH7x+4JOkKKWA/PKy jNbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ciLvjNOIsfeYXD5MxG0NqKGDF/Q594uMpv3G9vdvQyE=; b=lVYkF/v4cmiv1AudwMfOKaAIIMVpKZN0bqMWrWB0y9y4LYRuE5L8fioTFIyHHVlaF5 CL5jPsIla8a6nUs+n30WjFxW0rWhIdexCEPkV9CXyWw7Iwsy/XoG7QGRgXdcdAkvfkDJ /k9Wd7URgY/NjsKs2TWo9eHOMPGE8o2brkXgmHnjxW8ztLhOvAybBdtA3DVooEC7/ZCj wOj1/qlJDqMkPF3Nz98/91x5lGRVFvJz/mxVboaF1jChqod1yjGs2p0wEhPw0XyUPdD3 vVuAibAYEiNhroI3/wsto8nio+9YslP1BM9mtitsbto3YYW2nDqrYnYZkGJGIZyJNotP /zFg== X-Gm-Message-State: AOAM531ESH9PpaYXzgLP9cXaLEnvLCZ6Zp6HiwtPIEwr5pXyLu3T4o1J kza61XqGEJ2DiYIwNoGWn63xjo1kj0LrLw== X-Google-Smtp-Source: ABdhPJwPwl7Cleq2HjYPLPgSJUMIc7vyJdjhMshRyGKxCWKGnchsc/9uzxeUA3KGGry5wMIJU4iRqg== X-Received: by 2002:a17:902:6ac3:: with SMTP id i3mr14263892plt.21.1599355902498; Sat, 05 Sep 2020 18:31:42 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:41 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:23 -0700 Message-Id: <20200906013133.26360-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 01/11] cpu_layout: refactor to meet python standards X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Rearrange code to make it pass python lint. This includes add a main function, docstring, and some variable name changes. Signed-off-by: Stephen Hemminger --- usertools/cpu_layout.py | 145 +++++++++++++++++++++++----------------- 1 file changed, 85 insertions(+), 60 deletions(-) diff --git a/usertools/cpu_layout.py b/usertools/cpu_layout.py index 89a48cec463e..1e4577143ac5 100755 --- a/usertools/cpu_layout.py +++ b/usertools/cpu_layout.py @@ -2,67 +2,92 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2010-2014 Intel Corporation # Copyright(c) 2017 Cavium, Inc. All rights reserved. +""" +Show CPU layout +""" +SYS_DEVICES_CPU = "/sys/devices/system/cpu" -import sys - -sockets = [] -cores = [] -core_map = {} -base_path = "/sys/devices/system/cpu" -fd = open("{}/kernel_max".format(base_path)) -max_cpus = int(fd.read()) -fd.close() -for cpu in range(max_cpus + 1): - try: - fd = open("{}/cpu{}/topology/core_id".format(base_path, cpu)) - except IOError: - continue - except: - break - core = int(fd.read()) - fd.close() - fd = open("{}/cpu{}/topology/physical_package_id".format(base_path, cpu)) - socket = int(fd.read()) - fd.close() - if core not in cores: - cores.append(core) - if socket not in sockets: - sockets.append(socket) - key = (socket, core) - if key not in core_map: - core_map[key] = [] - core_map[key].append(cpu) - -print(format("=" * (47 + len(base_path)))) -print("Core and Socket Information (as reported by '{}')".format(base_path)) -print("{}\n".format("=" * (47 + len(base_path)))) -print("cores = ", cores) -print("sockets = ", sockets) -print("") - -max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1)) -max_thread_count = len(list(core_map.values())[0]) -max_core_map_len = (max_processor_len * max_thread_count) \ + +def print_coremap(sockets, cores, core_map): + '''print core, thread, socket mapping''' + max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1)) + max_thread_count = len(list(core_map.values())[0]) + max_core_map_len = (max_processor_len * max_thread_count) \ + len(", ") * (max_thread_count - 1) \ + len('[]') + len('Socket ') -max_core_id_len = len(str(max(cores))) - -output = " ".ljust(max_core_id_len + len('Core ')) -for s in sockets: - output += " Socket %s" % str(s).ljust(max_core_map_len - len('Socket ')) -print(output) - -output = " ".ljust(max_core_id_len + len('Core ')) -for s in sockets: - output += " --------".ljust(max_core_map_len) - output += " " -print(output) - -for c in cores: - output = "Core %s" % str(c).ljust(max_core_id_len) - for s in sockets: - if (s,c) in core_map: - output += " " + str(core_map[(s, c)]).ljust(max_core_map_len) - else: - output += " " * (max_core_map_len + 1) + + max_core_id_len = len(str(max(cores))) + + output = " ".ljust(max_core_id_len + len('Core ')) + for socket in sockets: + output += " Socket %s" % str(socket).ljust(max_core_map_len - + len('Socket ')) + print(output) + + output = " ".ljust(max_core_id_len + len('Core ')) + for socket in sockets: + output += " --------".ljust(max_core_map_len) + output += " " print(output) + + for core in cores: + output = "Core %s" % str(core).ljust(max_core_id_len) + for socket in sockets: + if (socket, core) in core_map: + output += " " + str(core_map[(socket, + core)]).ljust(max_core_map_len) + else: + output += " " * (max_core_map_len + 1) + print(output) + + +def print_header(sockets, cores): + '''print the core socket information header''' + header_len = 47 + len(SYS_DEVICES_CPU) + print(format("=" * header_len)) + print("Core and Socket Information (as reported by '{}')".format( + SYS_DEVICES_CPU)) + print("{}\n".format("=" * header_len)) + print("cores = ", cores) + print("sockets = ", sockets) + print("") + + +def main(): + '''program main function''' + + with open("{}/kernel_max".format(SYS_DEVICES_CPU)) as kernel_max: + max_cpus = int(kernel_max.read()) + + core_map = {} + sockets = [] + cores = [] + + for cpu in range(max_cpus + 1): + topo_path = "{}/cpu{}/topology/".format(SYS_DEVICES_CPU, cpu) + try: + with open(topo_path + "core_id") as core_id: + core = int(core_id.read()) + except FileNotFoundError: + break + except IOError: + continue + + with open(topo_path + "physical_package_id") as package_id: + socket = int(package_id.read()) + + if core not in cores: + cores.append(core) + if socket not in sockets: + sockets.append(socket) + key = (socket, core) + if key not in core_map: + core_map[key] = [] + core_map[key].append(cpu) + + print_header(sockets, cores) + print_coremap(sockets, cores, core_map) + + +if __name__ == "__main__": + main() From patchwork Sun Sep 6 01:31:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76615 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1298BA04C5; Sun, 6 Sep 2020 03:32:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 261ED1C0DA; Sun, 6 Sep 2020 03:31:48 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id E1B121BEA7 for ; Sun, 6 Sep 2020 03:31:44 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id j34so897216pgi.7 for ; Sat, 05 Sep 2020 18:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+I97ORinggSpAxlykndpMsIbCkjHdqnrrc4mcPDuiiI=; b=K5QPR8aUcgURlI0zoGZ5Nr2StEeJsz0mXhE4tjCwlNdC1vN9VpcPvvJB+4Zveye+xQ dA69eQrXx0ya6f7Oj+rkwqrZqMlGX9uhXlMjH+QH3O2LuV8qRMUK/QlfHxnbXuaqMSti 43sj3aZU8Sp42+r8mxSTT6bTauRoKoZzb3Nd8CWUnDKgOm8HiqqJHqrbp+AgxFnaTn39 Zukf9betBJNpbwGnUMNgnppL348qRiLaRlSvMmlH2hY/TR6E/nPUoY+YHP0k6rMMX1PC ufxcRliDGJ3bQKEbUKd1t7bG7Zu2SvtMDdUQuPMNFtXw1//kNHmBsTpfEPAwya4r8+XP LY3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+I97ORinggSpAxlykndpMsIbCkjHdqnrrc4mcPDuiiI=; b=TQOLhTwjCXwT6nO0gIqEfR+oAEob7RDkZn7ifjRzfI3jghhE7s7eDeXugfGBHM/7fa 7w4tBUkWCRg0TIfIZkESTvgxHFSvr6AUEVGAmewz3sBzXHKjq8jq66KAIKClgxnXkXJe Ryw/9/79CKsNqOBaec4fO0aZXIGxJHoKIHdb3xayHtmHJNrfr3hOVoGmCwC3fA1qJkWD cpHP8x6iqScRnrWmTVuqnLyW8WXXqJQzksqM3KvTJDxiahQV3Q6soxfDQ2KO1ILbSHzK GEGiKuAHTMG2MWcCdNHPHAerT2jXX2+3eIhgtQi2qPFafn2hEDTQYYJ6TgNPGv7scTVC fOEQ== X-Gm-Message-State: AOAM530YViUWPNqtrGiVB2KwqU2qZNnopp4gbFSK6/123xOefjXaOn6n 04KKNYYCPUBHEQx83OnHM7/9U1DqirT70g== X-Google-Smtp-Source: ABdhPJyWu8juY08y2wNC5+ekZV/zINxvyq8yq5ZysyJPnEf0PiI3UJrMsXeXIdMIjQ7J4516iQ4RzA== X-Received: by 2002:a63:413:: with SMTP id 19mr12446211pge.310.1599355903589; Sat, 05 Sep 2020 18:31:43 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:42 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:24 -0700 Message-Id: <20200906013133.26360-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 02/11] dpdk-pmdinfo: replace string.split with split X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In python3 the standard way to split strings is to use the split() on the string object itself. The old way is broken and would cause a traceback. Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 16619827911a..7576a3313f36 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -11,7 +11,6 @@ import io import os import platform -import string import sys from elftools.common.exceptions import ELFError from elftools.common.py3compat import byte2int @@ -229,7 +228,7 @@ def loadLocal(self): def search_file(filename, search_path): """ Given a search path, find file with requested name """ - for path in string.split(search_path, ":"): + for path in search_path.split(':'): candidate = os.path.join(path, filename) if os.path.exists(candidate): return os.path.abspath(candidate) From patchwork Sun Sep 6 01:31:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76616 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3E3A3A04C5; Sun, 6 Sep 2020 03:32:15 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 69A1D1C10C; Sun, 6 Sep 2020 03:31:49 +0200 (CEST) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by dpdk.org (Postfix) with ESMTP id CEB1A1C0CA for ; Sun, 6 Sep 2020 03:31:45 +0200 (CEST) Received: by mail-pg1-f179.google.com with SMTP id m5so6280424pgj.9 for ; Sat, 05 Sep 2020 18:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PFsX6joj8+LucDxtxZNyqLzFyGOrNSF26W4kRtBfMww=; b=LWDvE3eI9OcLtgssGHw6CClClW/TshHk+vY6RT23qFKXCi6H7S2mZswln5fZOfNHZV EkRr9jFRAtGQrCxLY2eVoR+IZHVaow3rpsRUf6qN+Hk81yLF1aGUBrk8MmiWhAawO74K MvEGJdZsbShe96OdKhHDI/duvAj8k2e48hSD1c1xQGrs+o+ERPxA9iB8soZPgkvxSmZC G0WSLeOS19+lAYUbaf089DtdRNGMmRoawn1OdVnAIPO5M1sZlUoYRJXMnFTqziaIWFw6 WBLBVCIHtVN+F4pPReYWwT+7X1AV3NXATpS+VmxfBZEoUeJDfLglfFmE2jsYnh9FnU70 3T3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PFsX6joj8+LucDxtxZNyqLzFyGOrNSF26W4kRtBfMww=; b=JDdXtVIzZTZyXsPt1MJSzQGISf+4XnBLNAYpRA5HCszx02An9doHB5ixB62UlYYrR5 v/3oN/iCV3xotquABo9QB1PFHr9OHfN/e4icpthSu9d6ah8FpHMwHjqD3OjmOJJuOLDv R8DkzCMFFlFDd/d55L9ZP6tg5PK03TEmgo+Jg+bPDYWcwdLVAgczNdgiM/0jhGtjMOPU Fi85JJxwC0TFMsqmibbU1wN8+kWGjq2lMQTuthOmKjbtVsD4MjF/2mFWMH4POQmroFkz 5ORZHJjrhqqVPrraeFlwXM/nglc/4sYAe6KyOWlIgkkXqHWam0CPkTfpO/0oufTJdMLL oXkw== X-Gm-Message-State: AOAM533FSE0HBuEYku9LIMScNwfdvpwGYPAVUXE5Hx/z9kho9VkYiRiE 7oDgSIiPfiW7pmsVh4sFGKx4TvkLmH6Q5Q== X-Google-Smtp-Source: ABdhPJyEGqVEBpxNKAm8DR7cn7OxTaDM5uVt/VnV0GLopb2tDovsg+LnvN8lF+kVjQjedqAESpuFCA== X-Received: by 2002:a65:6897:: with SMTP id e23mr12498606pgt.103.1599355904709; Sat, 05 Sep 2020 18:31:44 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:25 -0700 Message-Id: <20200906013133.26360-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 03/11] dpdk-pmdinfo: replace io.open with open X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The builtin open() is the recommended approach in python3. io.open was for compatiablity with older versions. Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 7576a3313f36..4fefdc83e583 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -8,7 +8,6 @@ # # ------------------------------------------------------------------------- import json -import io import os import platform import sys @@ -211,7 +210,7 @@ def readLocal(self, filename): """ Reads the local file """ - with io.open(filename, 'r', encoding='utf-8') as f: + with open(filename, 'r', encoding='utf-8') as f: self.contents = f.readlines() self.date = self.findDate(self.contents) @@ -380,7 +379,7 @@ def search_for_autoload_path(self): return (None, None) if raw_output is False: print("Scanning for autoload path in %s" % library) - scanfile = io.open(library, 'rb') + scanfile = open(library, 'rb') scanelf = ReadElf(scanfile, sys.stdout) except AttributeError: # Not a dynamic binary @@ -456,7 +455,7 @@ def process_dt_needed_entries(self): if library is not None: if raw_output is False: print("Scanning %s for pmd information" % library) - with io.open(library, 'rb') as file: + with open(library, 'rb') as file: try: libelf = ReadElf(file, sys.stdout) except ELFError: @@ -499,7 +498,7 @@ def scan_autoload_path(autoload_path): scan_autoload_path(dpath) if os.path.isfile(dpath): try: - file = io.open(dpath, 'rb') + file = open(dpath, 'rb') readelf = ReadElf(file, sys.stdout) except ELFError: # this is likely not an elf file, skip it @@ -526,7 +525,7 @@ def scan_for_autoload_pmds(dpdk_path): print("Must specify a file name") return - file = io.open(dpdk_path, 'rb') + file = open(dpdk_path, 'rb') try: readelf = ReadElf(file, sys.stdout) except ElfError: @@ -621,7 +620,7 @@ def main(stream=None): print("File not found") sys.exit(1) - with io.open(myelffile, 'rb') as file: + with open(myelffile, 'rb') as file: try: readelf = ReadElf(file, sys.stdout) readelf.process_dt_needed_entries() From patchwork Sun Sep 6 01:31:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76617 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 96E2BA04C5; Sun, 6 Sep 2020 03:32:24 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9F2011C115; Sun, 6 Sep 2020 03:31:50 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 0D99F1C0D7 for ; Sun, 6 Sep 2020 03:31:46 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id j34so897238pgi.7 for ; Sat, 05 Sep 2020 18:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YZAObi26Mj7i1wXxn0UqzwljKJJrpie5NpnVUpfmVQo=; b=lgjDkU8nxoeJYgMHCHSdMaO6I62McsIh1lZvWSxn7wENsvIQMGuEI0/odYyQXUo8KO 2Idb9Tl6H4VabOgUXmOhK5zBo1RucoEQE6rQ2jkscfxvAIVGhiHZ/hHM0XrEsL5/ArGY VMygJjAINZaE1RvB+WIM1wA3poDpWyTjWQEp033Nv1YSlX/NSyOJ+DLQg2q+he+rIoJe 3v8cyX/erREzhXea8Drl4YKTuit8NVARXrL8tubVwGKnkcXUKOw6/dh8/WCTbqmZ7XzN Merku2g1soQTcV83lG//PICR87f6DLaKCYfZLDTphhAM1OT92Gw4gC514egQuSGCte48 K3pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YZAObi26Mj7i1wXxn0UqzwljKJJrpie5NpnVUpfmVQo=; b=kIHLGJKFZKiXgMKD+kJloyM+p8QmCc0k4PLmthWeKWufFDkBp9k5iSzprCEVEHVHTQ KifxRcEnYZwe+GK15GeJRoeND0p4e58gw4RXco7ZtxiYveTngG2Y12ybexVX7jJBP/bx UIw3vzwN/zLGXt6i6gOuIeI9dXiI6eOsa2MeyRLvs+5juh4Ql5KlHMNtxSOGbkvlndvt S1Beof4DkwOxcvRZhDRASiw1m5uW/7/YxaeZTmwcb4Oh4EBOTkweHRps+TPJTJg4zcGm 45208oEsEhgZ8voCvBCxHRLsFInQGu8EurWg1kwDGO1m83w7JbnwUN/6/Embs5lOfa4k jfzA== X-Gm-Message-State: AOAM53185XbYZOtkTTaCjehqpz5++yetS2Cp3hdmqIQjQcXTrQkNFgkC aHxN20y9u48WAqZh/ugOCu37Uu7HduRTiw== X-Google-Smtp-Source: ABdhPJwNC/euFIrD6k52qeaXrclA8X+jBwL/WJ3aw2WdPN4Uzig0K7OY7oZbgw0nD+vdK2zRuaGcpg== X-Received: by 2002:a63:f00a:: with SMTP id k10mr12399278pgh.76.1599355905820; Sat, 05 Sep 2020 18:31:45 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:45 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:26 -0700 Message-Id: <20200906013133.26360-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 04/11] dpdk-pmdinfo: remove dead code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The method loadLocal() is never called, and if it was it would throw an exception because it calling readLocal() without a filename. Pylint spotted this. Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 4fefdc83e583..9ee8fe9fa1ec 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -214,14 +214,6 @@ def readLocal(self, filename): self.contents = f.readlines() self.date = self.findDate(self.contents) - def loadLocal(self): - """ - Loads database from local. If there is no file, - it creates a new one from web - """ - self.date = idsfile[0].split("/")[1].split("-")[0] - self.readLocal() - # ======================================= From patchwork Sun Sep 6 01:31:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76618 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3D10DA04C5; Sun, 6 Sep 2020 03:32:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CDBB91C119; Sun, 6 Sep 2020 03:31:51 +0200 (CEST) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by dpdk.org (Postfix) with ESMTP id 2D8CF1C0DB for ; Sun, 6 Sep 2020 03:31:48 +0200 (CEST) Received: by mail-pf1-f170.google.com with SMTP id b124so6678796pfg.13 for ; Sat, 05 Sep 2020 18:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cwmla8CMmFUdBdPAiemA09ybJYnR4MMF1AiTpy6Z9V0=; b=RZ34p0P68xOatkMMCjQvO0yLcC7LEyM5qkp+WS/8cUa77NL7adCCURKKKcAPqANxe9 mMPlwT1En1Cp7Y8fhMgyN4PSb+vM9yxLUJYvhmw9oAXYRk1tUxvkGyrj27i50AF7NYy5 SAnJ7Hnip6CQeguNXEScFxF9rFkcz0mYuaGsZvpykmf68wP5qEq/CDIx6waT9/4O6kKq Ceq6cvdXjS/6mhLuRcUNYqMcpd6cgRYx4gprLcUpWWWzZxN83rLHyQyO+nu2Td2Gc30w ZYC5lnvgKDgzZF2KwurLIExsvM+JlEwD0X3rIFSvqMC55F7yJRBAQ8ZP6ZESL0DFE1Bs YrAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Cwmla8CMmFUdBdPAiemA09ybJYnR4MMF1AiTpy6Z9V0=; b=AjAocUJOkjen9mP1lw8a9qi9L0r79m1ffiHvgu5ij1QE3qFKHk7fKS/wNI18kDgEHv qhIIF3vMieyy/VjmRp22eJmJz4bLaB0G8LCwdlEchyVjkTwmgd32nmmBXhXA8OSowPRR A0XLL4IAcfSOgpAPo47mQyOcXmVBMc1+vbglAptdTOGDWvDQn+9IjZKRYhl4ChBvq7js 0jJGB0LFbp9++9xFUl9wzTA6f8vOYyROB35ow1r0oYYPQx8c/fDbP0d2L0WfGsfhJC/6 38suqJOUGCmHeXjKJO4O9fAgd68qK6r7oyT6N+ojeFweInGtDl6/Dz3O7WOm3BqiJVTc eVIw== X-Gm-Message-State: AOAM53349aXfOEv+2MOW8YiyCJDbQI8nZnKKueey4bf2RGykyV7Ir2H2 CiXOyHT/+3UUMAQDMVrt8J+b/PkCMZvANQ== X-Google-Smtp-Source: ABdhPJy6aP4AE9YX19wNmunpay1EmvD2MqXR81OP8Dvlna+tkmlsNHWVzFDtwX8Y1GsJXyJqmA+BnQ== X-Received: by 2002:a63:6dc7:: with SMTP id i190mr11860454pgc.27.1599355906877; Sat, 05 Sep 2020 18:31:46 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:27 -0700 Message-Id: <20200906013133.26360-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 05/11] dpdk-pmdinfo: remove unnecessary paren and else X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Python lint complains: usertools/dpdk-pmdinfo.py:303:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:328:0: C0325: Unnecessary parens after 'not' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:341:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:394:0: C0325: Unnecessary parens after 'not' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:407:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:515:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:530:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:533:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:534:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:539:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:594:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:602:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:605:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:611:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) usertools/dpdk-pmdinfo.py:110:12: R1705: Unnecessary "else" after "return" (no-else-return) usertools/dpdk-pmdinfo.py:254:12: R1705: Unnecessary "else" after "return" (no-else-return) Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 9ee8fe9fa1ec..32f8a82519fb 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -109,8 +109,7 @@ def find_subid(self, subven, subdev): except: if (subven == "ffff" and subdev == "ffff"): return SubDevice("ffff", "ffff", "(All Subdevices)") - else: - return SubDevice(subven, subdev, "(Unknown Subdevice)") + return SubDevice(subven, subdev, "(Unknown Subdevice)") class SubDevice: @@ -253,8 +252,7 @@ def _section_from_spec(self, spec): num = int(spec) if num < self.elffile.num_sections(): return self.elffile.get_section(num) - else: - return None + return None except ValueError: # Not a number. Must be a name then section = self.elffile.get_section_by_name(force_unicode(spec)) @@ -300,7 +298,7 @@ def parse_pmd_info_string(self, mystring): except KeyError: continue - if (len(pmdinfo["pci_ids"]) != 0): + if len(pmdinfo["pci_ids"]) != 0: print("PMD HW SUPPORT:") if pcidb is not None: self.pretty_print_pmdinfo(pmdinfo) @@ -325,7 +323,7 @@ def display_pmd_info_strings(self, section_spec): while dataptr < len(data): while (dataptr < len(data) and - not (32 <= byte2int(data[dataptr]) <= 127)): + not 32 <= byte2int(data[dataptr]) <= 127): dataptr += 1 if dataptr >= len(data): @@ -338,7 +336,7 @@ def display_pmd_info_strings(self, section_spec): # pyelftools may return byte-strings, force decode them mystring = force_unicode(data[dataptr:endptr]) rc = mystring.find("PMD_INFO_STRING") - if (rc != -1): + if rc != -1: self.parse_pmd_info_string(mystring) dataptr = endptr @@ -391,7 +389,7 @@ def search_for_autoload_path(self): while dataptr < len(data): while (dataptr < len(data) and - not (32 <= byte2int(data[dataptr]) <= 127)): + not 32 <= byte2int(data[dataptr]) <= 127): dataptr += 1 if dataptr >= len(data): @@ -404,7 +402,7 @@ def search_for_autoload_path(self): # pyelftools may return byte-strings, force decode them mystring = force_unicode(data[dataptr:endptr]) rc = mystring.find("DPDK_PLUGIN_PATH") - if (rc != -1): + if rc != -1: rc = mystring.find("=") return (mystring[rc + 1:], library) @@ -512,7 +510,7 @@ def scan_for_autoload_pmds(dpdk_path): """ global raw_output - if (os.path.isfile(dpdk_path) is False): + if os.path.isfile(dpdk_path) is False: if raw_output is False: print("Must specify a file name") return @@ -527,16 +525,16 @@ def scan_for_autoload_pmds(dpdk_path): (autoload_path, scannedfile) = readelf.search_for_autoload_path() if not autoload_path: - if (raw_output is False): + if raw_output is False: print("No autoload path configured in %s" % dpdk_path) return - if (raw_output is False): - if (scannedfile is None): + if raw_output is False: + if scannedfile is None: scannedfile = dpdk_path print("Found autoload path %s in %s" % (autoload_path, scannedfile)) file.close() - if (raw_output is False): + if raw_output is False: print("Discovered Autoload HW Support:") scan_autoload_path(autoload_path) return @@ -591,7 +589,7 @@ def main(stream=None): options.pcifile = None pcidb = None - if (len(args) == 0): + if len(args) == 0: optparser.print_usage() exit(1) @@ -599,16 +597,16 @@ def main(stream=None): exit(scan_for_autoload_pmds(args[0])) ldlibpath = os.environ.get('LD_LIBRARY_PATH') - if (ldlibpath is None): + if ldlibpath is None: ldlibpath = "" - if (os.path.exists(args[0]) is True): + if os.path.exists(args[0]) is True: myelffile = args[0] else: myelffile = search_file( args[0], ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib") - if (myelffile is None): + if myelffile is None: print("File not found") sys.exit(1) From patchwork Sun Sep 6 01:31:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76619 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 11AA7A04C5; Sun, 6 Sep 2020 03:32:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 653EC1C126; Sun, 6 Sep 2020 03:31:53 +0200 (CEST) Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by dpdk.org (Postfix) with ESMTP id 2FA581C0CD for ; Sun, 6 Sep 2020 03:31:49 +0200 (CEST) Received: by mail-pg1-f176.google.com with SMTP id 31so6263046pgy.13 for ; Sat, 05 Sep 2020 18:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aRa6qQxtPXReZzHu42y98tv9PIL+dbM+384ha1rUngw=; b=n8YBASWAL976+O4bMyfeSrvYUczyJ/R4HrwAL7TRP4q3prbkwNRnVJ/r4xwKWz8L5z c231B3lUJ4UxpiCZmi24kuj4tJl0wP83hyvzn7Q8iQXnhi/EyuPQrjWjToHkb6Azr8FX SOnmRyg5W7QC4FjvGydiyYmQ9JQSlBX0RFhewQuPieS8K8yGCD6NS6f3imTF0g7C2vr/ t9A4t6ClqLzioYJEBgoOudMxo/Ty+0bLbLagFquXhwgA+zH3mmljsqJ5daTN+cDPflt1 eYp9oPMpSP8WzwfBAqyDByYT48c4oiDcuQnjNyLEGqVSF1+I0XG/chG5V/ziK0mehxrv UO4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aRa6qQxtPXReZzHu42y98tv9PIL+dbM+384ha1rUngw=; b=Vr7S/4UeJnEjtxhgwwWiHD9BaDfONWGoeG3RIzWPFt32aAARWVj2EsjxFbcXyO6pi6 yRCFLT2u7UvHhh1jcWGOZde3+NoViEW8qxHbqYq/qScCHdAreN34HZ+pyHsnudBZQ4D/ GdbLj2EAd+a+Z/9tVJZTGx2WpL2veuGRUWphty3j3pl2Gc2IymXI5sl0UWdItBX7lWyu TENvxIMzV4vVtfTitbyyeRpVTDtDj76BWNf4xojK4pS5HRky3mB0/DCvQ4Yysp3nTnaH m5A3wiSnvR/szZLKnk5HulFo7Vwr4JrejPNWVqliZaAXwYluGtKhCnwUo2JfFFp/BJ9g sp/Q== X-Gm-Message-State: AOAM531vJm2+zB+oLTF5gWoEXcQS5GwsRI1QuZFSubSjfAgRcG/agHbF YIeMk0Ya3rghZmdNwBAbQrJzBri9zOwN3Q== X-Google-Smtp-Source: ABdhPJykHW147q/i17vIfg9/NLRyb6Wgh8F8EaeZLZDLqyqw6Hns9n1zN0JFDns7Gfl3E6AtaDcugA== X-Received: by 2002:a63:4746:: with SMTP id w6mr12460848pgk.412.1599355908003; Sat, 05 Sep 2020 18:31:48 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:28 -0700 Message-Id: <20200906013133.26360-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 06/11] dpdk-pmdinfo: replace is False and is True X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Code reads better if unnecessary comparison with False and True is not used. Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 32f8a82519fb..7c27a91182e4 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -367,7 +367,7 @@ def search_for_autoload_path(self): ":/usr/lib64:/lib64:/usr/lib:/lib") if library is None: return (None, None) - if raw_output is False: + if not raw_output: print("Scanning for autoload path in %s" % library) scanfile = open(library, 'rb') scanelf = ReadElf(scanfile, sys.stdout) @@ -443,7 +443,7 @@ def process_dt_needed_entries(self): runpath + ":" + ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib") if library is not None: - if raw_output is False: + if not raw_output: print("Scanning %s for pmd information" % library) with open(library, 'rb') as file: try: @@ -473,7 +473,7 @@ def force_bytes(s): def scan_autoload_path(autoload_path): global raw_output - if os.path.exists(autoload_path) is False: + if not os.path.exists(autoload_path): return try: @@ -497,7 +497,7 @@ def scan_autoload_path(autoload_path): # No permission to read the file, skip it continue - if raw_output is False: + if not raw_output: print("Hw Support for library %s" % d) readelf.display_pmd_info_strings(".rodata") file.close() @@ -510,8 +510,8 @@ def scan_for_autoload_pmds(dpdk_path): """ global raw_output - if os.path.isfile(dpdk_path) is False: - if raw_output is False: + if not os.path.isfile(dpdk_path): + if not raw_output: print("Must specify a file name") return @@ -519,22 +519,22 @@ def scan_for_autoload_pmds(dpdk_path): try: readelf = ReadElf(file, sys.stdout) except ElfError: - if raw_output is False: + if not raw_output: print("Unable to parse %s" % file) return (autoload_path, scannedfile) = readelf.search_for_autoload_path() if not autoload_path: - if raw_output is False: + if not raw_output: print("No autoload path configured in %s" % dpdk_path) return - if raw_output is False: + if not raw_output: if scannedfile is None: scannedfile = dpdk_path print("Found autoload path %s in %s" % (autoload_path, scannedfile)) file.close() - if raw_output is False: + if not raw_output: print("Discovered Autoload HW Support:") scan_autoload_path(autoload_path) return @@ -593,14 +593,14 @@ def main(stream=None): optparser.print_usage() exit(1) - if options.pdir is True: + if options.pdir: exit(scan_for_autoload_pmds(args[0])) ldlibpath = os.environ.get('LD_LIBRARY_PATH') if ldlibpath is None: ldlibpath = "" - if os.path.exists(args[0]) is True: + if os.path.exists(args[0]): myelffile = args[0] else: myelffile = search_file( From patchwork Sun Sep 6 01:31:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76620 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4DF8EA04C5; Sun, 6 Sep 2020 03:32:53 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8498B1C12C; Sun, 6 Sep 2020 03:31:54 +0200 (CEST) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by dpdk.org (Postfix) with ESMTP id 418B41C112 for ; Sun, 6 Sep 2020 03:31:50 +0200 (CEST) Received: by mail-pg1-f173.google.com with SMTP id v15so6287569pgh.6 for ; Sat, 05 Sep 2020 18:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hI58Pz/6Cs2k0URmOEslnb5nfs6wcSuchRbbNDNcdcc=; b=2I6f3FiTgZKJbnSKbN7U90LJ1/Resp+rasHwtLg+5xq+VV4IXRrMWoVfhFNEH5NKVX xTG182AZ/AzKilMcQ63y7eJAG6vPqoPSOWNW7XQSUWetc3jI8a/XudeMSv1UrevqO2Ib gkpoHdZQruDCIyAw1CDxASGk5M6YwRSHfnRiv+4TH9ZgIZ1YaL7Uihc4fYSdtjbQuGTL SfnaEShNty5MQeD1IcaxglabWRnD6XHwO3VyaYP3siPLXDYM4eJUU1K04+zIdWj1UESk AwMElSTifQ4dmx5IYPbDsDO+tZoaLm45TnV6NL7wzhuvghRntm6wdSKtZyBkSOUJ1YSh CP1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hI58Pz/6Cs2k0URmOEslnb5nfs6wcSuchRbbNDNcdcc=; b=HZ34EsWeGCkzied3GGPaY+rQULcEsEjnox04U0ItNyDh/Z9bJX5J2cIE7uQtmda820 lB4GR7aXZsMBs49zurhPJc1EbZv9cIdAyyqirIorQwjPG1E/CwleGG3Tr2EyQaTm8RJz Ki4UT6Nb4UpaUqBRYQQ+flCxkp1f1iC2D+xGox6yYyXr7NeUgTZh26tQDEKln6rPgGXU n9J2tGuKFi0hH3DuA5f3XaDwNxtqfJphppbpz7TmuyGOIwoLdkxZgTM1r98suI/LU3Tw PPlijFsgjkeWvky37VXuki3gvFGyhCLaT38103ddWPpdv92E/f7igh+UupmwZXkosBGw TftQ== X-Gm-Message-State: AOAM533Aj8jf+BmtdtQ7eHsAdSE1M3mpybxe/aRCJHiSH7ZhrpRk+qbR sNBQLTUbXePpNq4fMfpoLKSoPao3lpJhSA== X-Google-Smtp-Source: ABdhPJz+bMwe9ar2L0XI/oD1tIRYJQFnhxX83OM1AtI+BPcH1E27X1oXFVlq1GrtIKWdwSg55JPUXw== X-Received: by 2002:a63:5160:: with SMTP id r32mr12877397pgl.112.1599355909157; Sat, 05 Sep 2020 18:31:49 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:29 -0700 Message-Id: <20200906013133.26360-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 07/11] dpdk-pmdinfo: fix indentation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This fixes indentation warnings from pylint. Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 7c27a91182e4..d72feb308a6c 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -323,7 +323,7 @@ def display_pmd_info_strings(self, section_spec): while dataptr < len(data): while (dataptr < len(data) and - not 32 <= byte2int(data[dataptr]) <= 127): + not 32 <= byte2int(data[dataptr]) <= 127): dataptr += 1 if dataptr >= len(data): @@ -389,7 +389,7 @@ def search_for_autoload_path(self): while dataptr < len(data): while (dataptr < len(data) and - not 32 <= byte2int(data[dataptr]) <= 127): + not 32 <= byte2int(data[dataptr]) <= 127): dataptr += 1 if dataptr >= len(data): From patchwork Sun Sep 6 01:31:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76621 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9F829A04C5; Sun, 6 Sep 2020 03:33:02 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A79161C133; Sun, 6 Sep 2020 03:31:55 +0200 (CEST) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by dpdk.org (Postfix) with ESMTP id 5B4151C119 for ; Sun, 6 Sep 2020 03:31:51 +0200 (CEST) Received: by mail-pf1-f175.google.com with SMTP id v196so6719790pfc.1 for ; Sat, 05 Sep 2020 18:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iMO/PzdH6BzFxhvjyiwkT2zMKEuzx76leBgohpMUT5g=; b=NicL8A1/yEg69v7RPflHSWFlcGLjLaYvG2vqo0TJawO5CMIYJf4bqupSmfOWB9eSoA b/+QFbB0nrqiDFBBxOHeOpG17MLXj7RbRWay1kxpKMCIy6u7zQKDB8f61WPA4MdLiTAY UDzPiMZdGCewh9L0J+4/H5sbjRh8/mDYfqL6Pq/TuQBhknty9/R2nIikOsFS3eO1Y3ru eEvbDhgGqTj4LA+/REpFvzB4+Gk+QP6u+LULuW+yCiDj/OaXScRBaHtbkZeM1JM0CmD0 Po/omKccDeMmy3tXNIWnG6IKw1+M2amYdrbm3m06ZFb6nQh0s6wJAlzF1JYVEjokGMfZ jdOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iMO/PzdH6BzFxhvjyiwkT2zMKEuzx76leBgohpMUT5g=; b=QxxBlZJYtxb2XUuRYVbvrtVkKynv1HH9AylrbLFWUzxdJN7Q0YOa23Wq2Yzctemm+R 26fRCZGvMN/4kX88MSQZsaIwcYf6KjOZ1CoMoQSili9KDnjt6jGd5Bjm2AOJ9n01VA0X 4bU/D7WIErYxWb/FDhzxPxhbOjZ33p1JcJeZPFysWwKcndRIVJQbr+cEZbe0Sp3qDuuR qTNp61rpqr5qPaE39XFBJWZwiwIKGf2oMZrm7uHTk9wTZW88cRNh8CPCJUqOUjlC+B5e ZGBQO9ZenA09yLLIfWXh1/Tk0/qD6BFrBEG5WIEeZ+bV12aMv5EwBdCHe9KNmV1n0wds 9fKA== X-Gm-Message-State: AOAM530AHqkQaPUtfKJPCdVCrGkADSu/XtbMyCKJqm5s3/MRQ5UiRonF N6wgLYmdSTzKhKxffHX6cWS7Zad0/tWxoA== X-Google-Smtp-Source: ABdhPJy+WQsYOdPm1xD1OA1ZO5pdwROe0kUFvOJ+m+ll5sccTNEazDQiViZZc8yrDaZh4QfHQ/skIg== X-Received: by 2002:a65:4641:: with SMTP id k1mr12270942pgr.133.1599355910224; Sat, 05 Sep 2020 18:31:50 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:30 -0700 Message-Id: <20200906013133.26360-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 08/11] dpdk-pmdinfo: replace deprecated optparse with argparse X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The optparse module is deprecated and replaced with new argparse. The code now enforces the rule that only one of the output formats can be specified: raw or json. Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 70 ++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index d72feb308a6c..d746348f1415 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -11,10 +11,11 @@ import os import platform import sys +import argparse from elftools.common.exceptions import ELFError from elftools.common.py3compat import byte2int from elftools.elf.elffile import ELFFile -from optparse import OptionParser + # For running from development directory. It should take precedence over the # installed pyelftools. @@ -555,56 +556,49 @@ def main(stream=None): if not os.path.exists(pcifile_default): pcifile_default = "/usr/share/misc/pci_vendors" - optparser = OptionParser( - usage='usage: %prog [-hrtp] [-d ', - description="Dump pmd hardware support info", - add_help_option=True) - optparser.add_option('-r', '--raw', - action='store_true', dest='raw_output', - help='Dump raw json strings') - optparser.add_option("-d", "--pcidb", dest="pcifile", - help="specify a pci database " - "to get vendor names from", - default=pcifile_default, metavar="FILE") - optparser.add_option("-t", "--table", dest="tblout", - help="output information on hw support as a " - "hex table", - action='store_true') - optparser.add_option("-p", "--plugindir", dest="pdir", - help="scan dpdk for autoload plugins", - action='store_true') - - options, args = optparser.parse_args() - - if options.raw_output: + parser = argparse.ArgumentParser( + usage='usage: %(prog)s [-hrtp] [-d ] elf_file', + description="Dump pmd hardware support info") + group = parser.add_mutually_exclusive_group() + group.add_argument('-r', '--raw', + action='store_true', dest='raw_output', + help='dump raw json strings') + group.add_argument("-t", "--table", dest="tblout", + help="output information on hw support as a hex table", + action='store_true') + parser.add_argument("-d", "--pcidb", dest="pcifile", + help="specify a pci database to get vendor names from", + default=pcifile_default, metavar="FILE") + parser.add_argument("-p", "--plugindir", dest="pdir", + help="scan dpdk for autoload plugins", + action='store_true') + parser.add_argument("elf_file", help="driver shared object file") + args = parser.parse_args() + + if args.raw_output: raw_output = True - if options.pcifile: - pcidb = PCIIds(options.pcifile) + if args.tblout: + args.pcifile = None + + if args.pcifile: + pcidb = PCIIds(args.pcifile) if pcidb is None: print("Pci DB file not found") exit(1) - if options.tblout: - options.pcifile = None - pcidb = None - - if len(args) == 0: - optparser.print_usage() - exit(1) - - if options.pdir: + if args.pdir: exit(scan_for_autoload_pmds(args[0])) ldlibpath = os.environ.get('LD_LIBRARY_PATH') if ldlibpath is None: ldlibpath = "" - if os.path.exists(args[0]): - myelffile = args[0] + if os.path.exists(args.elf_file): + myelffile = args.elf_file else: - myelffile = search_file( - args[0], ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib") + myelffile = search_file(args.elf_file, + ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib") if myelffile is None: print("File not found") From patchwork Sun Sep 6 01:31:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76622 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id AF174A04C5; Sun, 6 Sep 2020 03:33:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B30351C136; Sun, 6 Sep 2020 03:31:56 +0200 (CEST) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by dpdk.org (Postfix) with ESMTP id 7270A1C11E for ; Sun, 6 Sep 2020 03:31:52 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id y6so405027plt.9 for ; Sat, 05 Sep 2020 18:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aByLlh9qPbdoOHH7F/DxU/9BzjIrTZlqAe0AUsV6+zE=; b=dIIeJ/g9LVm9VrshWmP+7hrHQr+wgcd7i3xatXIxtiNldesLNgOjSX1MPDzfjF4yAw yHsqIaY7fiU+Yc9op7IEcCsrAKWSqhdkqe4idj3Emc8dm3sv1nvIKBPpN1k1LRyXsahd gayht/zHNV/EqhIKdCmpgvzLKexSQgSidhj88PwOdhPKcxKd8lCH5fUU1tBtcvgQEvTK DDWOxYKM5Cb0PX2mwDvPcu4L8GDeoTp3N8RmNxVFVeeKOR6oV8SkgUBgmIwPzzZCuwxW swRsKywjANZeAiOqLbai+ojTA9wS5m9/aw8T/XndvWWXs2ni2cmCRJzvodBBEXi5Vc26 6B7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aByLlh9qPbdoOHH7F/DxU/9BzjIrTZlqAe0AUsV6+zE=; b=axizPmtqXyR0DihHuoDALXNEZMLfdY7+e3HNgZv265u2Eb1X4gtL8K0WvEDY1D19Vs cH+DHF3lbB2KxbAhJNqqvup/0abZlkm0AkLSmooLQ6jTpKHyA+f5qssm3AdKGq96PQ9o G4YM49rXasxel+04aKHO0rF6WCgFE65RKTRS/pJf5V2CWk5nSNJOnaAZvjBp2TuxKNKP abt4gkMwJlunrzj9YbRHXzktFT9hMLnNEcBDRUDR0Puq8qNWQUZnXWqQp1n+UjUmAG/h UbFM28lBZDBEVMF1wmH2EGmmLW0tqhkVc+oA4xaIzsTHfqVgUDuHvIEezcz+WsJlKSCV d6dw== X-Gm-Message-State: AOAM533keviIwDV6ET6RmKXn/+tIiO3WoRdJGaaFReA3IOSoIP8UV+k4 /BOJi9ukFjPkrNPR12ZqNcjW57fVOPoj1Q== X-Google-Smtp-Source: ABdhPJyOoFcW5ljmwKFWH9YdXlz1UKkaVzjiTfl7s54R6Yy3SkF6xiiRIY6rO8tiSAyne7dFCgma0A== X-Received: by 2002:a17:902:b092:b029:d0:89f1:9e2c with SMTP id p18-20020a170902b092b02900d089f19e2cmr12865457plr.8.1599355911259; Sat, 05 Sep 2020 18:31:51 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:50 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:31 -0700 Message-Id: <20200906013133.26360-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 09/11] dpdk-pmdinfo: do not use len(x) to test for empty X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This fixes the following python lint warnings. usertools/dpdk-pmdinfo.py:188:11: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition) usertools/dpdk-pmdinfo.py:196:21: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition) usertools/dpdk-pmdinfo.py:302:11: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition) Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index d746348f1415..632271e2f1d2 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -185,7 +185,7 @@ def findDate(self, content): return None def parse(self): - if len(self.contents) < 1: + if not len(self.contents): print("data/%s-pci.ids not found" % self.date) else: vendorID = "" @@ -193,7 +193,7 @@ def parse(self): for l in self.contents: if l[0] == "#": continue - elif len(l.strip()) == 0: + elif not l.strip(): continue else: if l.find("\t\t") == 0: @@ -299,7 +299,7 @@ def parse_pmd_info_string(self, mystring): except KeyError: continue - if len(pmdinfo["pci_ids"]) != 0: + if pmdinfo["pci_ids"]: print("PMD HW SUPPORT:") if pcidb is not None: self.pretty_print_pmdinfo(pmdinfo) From patchwork Sun Sep 6 01:31:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76623 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 16DD7A04C5; Sun, 6 Sep 2020 03:33:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DA7A31C190; Sun, 6 Sep 2020 03:31:57 +0200 (CEST) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by dpdk.org (Postfix) with ESMTP id 9B3171C129 for ; Sun, 6 Sep 2020 03:31:53 +0200 (CEST) Received: by mail-pg1-f170.google.com with SMTP id u13so6306195pgh.1 for ; Sat, 05 Sep 2020 18:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fKkIOINUQ2FC8wT3qqw/AlsKkaC+NNbLh/FZX952GRc=; b=QtHic2I8YnPEKrXGk+KAMd7eYEPpgBhmd9HHleVCrzeC8J7rlhvJnxq8JG9voo1VBU dOGX/eBAtEzWYcuE1EcnP9K+obxq5dztlX6LKIPLaHnz7WVzIvPYCUERFKEwMGALindY vX6GVs7DbpdiFNCoJ+ZMSbOb6xguN4SUVnREyqmYZKl+G8Oh6iE5NSbpSY6N8ZQCnT2T lT4OwWGtEznbhcCYY55wtZDy9drYyNDX1AQr9whXQv+aakB3sZpu2QhXl0kYe+r/HF+A rOVlm839TephFKWexSfKjvvzvuCIStnRp8fSag3BgItPs/DWgDNOhBoOfoUUTCPZVxhh ufrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fKkIOINUQ2FC8wT3qqw/AlsKkaC+NNbLh/FZX952GRc=; b=XcayyIqa8yzw4sNoDkCVUJsN3TTy7aqLszh/Q8CcvCR0BDKUN+nkPlGJYki8iCKXoV gDZnNxy9zu8MUWNmFUFB9i47fTy6vSJbWAVqxwr0M9QVeyjdTDiYIqL8ePzFg/1d2vli oxL71zZqw/E8tRpgzEI+BI7GygjKl4Jt0zwelZ7fxJ7Vht8H/2pq9XQgKTbl1cSiKm23 MoCgalkjLJd0X0KImTvQr/EtJclYsOYMDOCkeau2ImmkMd12vmafh1gdbDmJzw1vKTOA rFBJ75GqwYETGqag5yFKIXunuefEzqWgLI7QeOf8RBIM1nXuR/1wOaXd/vDglooPs694 9lAA== X-Gm-Message-State: AOAM532xlFc8ZzQ8KXGciImbbvyRUiIjHClcsR7SyM9+eHl1Ic8lk2uI hogqRs5PHM/h0a/AmKu4SqvzCCOf5hTxLg== X-Google-Smtp-Source: ABdhPJzJ8W6xmCGcLERqx2k4Q4X6NOyvNWivpI7D2uvcHihZ1Lp93DLDBoApNthvmlwbG/dUsXhNkA== X-Received: by 2002:aa7:84d5:0:b029:13c:1611:653a with SMTP id x21-20020aa784d50000b029013c1611653amr13128355pfn.12.1599355912270; Sat, 05 Sep 2020 18:31:52 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:51 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:32 -0700 Message-Id: <20200906013133.26360-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 10/11] dpdk-telemetry-client: fix some pylint warnings X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Convert comments to docstrings as appropriate. Remove unnecessary paren in if statement. Remove extra whitespace after print. Signed-off-by: Stephen Hemminger Acked-by: Bruce Richardson --- usertools/dpdk-telemetry-client.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/usertools/dpdk-telemetry-client.py b/usertools/dpdk-telemetry-client.py index fa599046a46b..7a22d1b99864 100755 --- a/usertools/dpdk-telemetry-client.py +++ b/usertools/dpdk-telemetry-client.py @@ -32,7 +32,8 @@ def __del__(self): class Client: - def __init__(self): # Creates a client instance + def __init__(self): + ''' Creates a client instance ''' self.socket = Socket() self.file_path = None self.choice = None @@ -45,16 +46,18 @@ def __del__(self): except: print("Error - Client could not be destroyed") - def getFilepath(self, file_path): # Gets arguments from Command-Line and assigns to instance of client + def getFilepath(self, file_path): + '''Gets arguments from Command-Line and assigns to instance of client''' self.file_path = file_path - def register(self): # Connects a client to DPDK-instance + def register(self): + '''Connects a client to DPDK-instance''' if os.path.exists(self.file_path): os.unlink(self.file_path) try: self.socket.recv_fd.bind(self.file_path) except socket.error as msg: - print ("Error - Socket binding error: " + str(msg) + "\n") + print("Error - Socket binding error: " + str(msg) + "\n") self.socket.recv_fd.settimeout(2) self.socket.send_fd.connect("/var/run/dpdk/rte/telemetry") JSON = (API_REG + self.file_path + "\"}}") @@ -63,16 +66,19 @@ def register(self): # Connects a client to DPDK-instance self.socket.recv_fd.listen(1) self.socket.client_fd = self.socket.recv_fd.accept()[0] - def unregister(self): # Unregister a given client + def unregister(self): + ''' Unregister a given client ''' self.socket.client_fd.send((API_UNREG + self.file_path + "\"}}").encode()) self.socket.client_fd.close() - def requestMetrics(self): # Requests metrics for given client + def requestMetrics(self): + ''' Requests metrics for given client ''' self.socket.client_fd.send(METRICS_REQ.encode()) data = self.socket.client_fd.recv(BUFFER_SIZE).decode() print("\nResponse: \n", data) - def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics for given client + def repeatedlyRequestMetrics(self, sleep_time): + ''' Recursively requests metrics for given client ''' print("\nPlease enter the number of times you'd like to continuously request Metrics:") n_requests = int(input("\n:")) print("\033[F") #Removes the user input from screen, cleans it up @@ -81,12 +87,14 @@ def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics f self.requestMetrics() time.sleep(sleep_time) - def requestGlobalMetrics(self): #Requests global metrics for given client + def requestGlobalMetrics(self): + ''' Requests global metrics for given client ''' self.socket.client_fd.send(GLOBAL_METRICS_REQ.encode()) data = self.socket.client_fd.recv(BUFFER_SIZE).decode() print("\nResponse: \n", data) - def interactiveMenu(self, sleep_time): # Creates Interactive menu within the script + def interactiveMenu(self, sleep_time): + ''' Creates Interactive menu within the script ''' while self.choice != 4: print("\nOptions Menu") print("[1] Send for Metrics for all ports") @@ -116,7 +124,7 @@ def interactiveMenu(self, sleep_time): # Creates Interactive menu within the scr sleep_time = 1 file_path = "" - if (len(sys.argv) == 2): + if len(sys.argv) == 2: file_path = sys.argv[1] else: print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").") From patchwork Sun Sep 6 01:31:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 76624 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 800E9A04C5; Sun, 6 Sep 2020 03:33:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 760221C19C; Sun, 6 Sep 2020 03:31:59 +0200 (CEST) Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by dpdk.org (Postfix) with ESMTP id C222B1C131 for ; Sun, 6 Sep 2020 03:31:54 +0200 (CEST) Received: by mail-pl1-f171.google.com with SMTP id h2so2873486plr.0 for ; Sat, 05 Sep 2020 18:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=veMtQD1DrLwwOyJC9ALx22CoZCRML0Lgun+sh/m+t6U=; b=M1L3fm0rNc1ZV/nNAgc+prJq+FGoT3cpAMkM0gJuPMMO705prZNb106Ow/MAD5TION adn3RBanQUJl/mavKKZkNHZHGKd6qNNqvA7lnZ1eXNeRAghPT+SvGo14f/7ccCKq3xQL ldipDvPqMnCyzwJeFCNVvcgOP35lIZysk4aU+hiJMo4PQmdy2d5KGXegDsrZjabB6KEL X2BfXgXvi8HMkP2pZjFh0iQ9+9BsbssNh90S6I1Zc4erc1j+t9vrJgs1/RxmkL9iUkXP oCmGu5TXF+4D2Uqe0Fhy11s5qYMyDQHGQe9m7VdsvOa3A08hXYw/2qoYWImvoOyAEAMh b3Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=veMtQD1DrLwwOyJC9ALx22CoZCRML0Lgun+sh/m+t6U=; b=iMb9UPLZLG3O3s+TQqvBbNAQSruJC0VNL0+3BsunhoKAOWE/w4Y7Bt+ViTvGd9Bk1a BcBu3rkM6RYkCdR4BV96yNEo/PxVoE+lptr/q5F1QdHG0AUDga/ePvYHmPPw3unDpj8a srea1TzRIH84py1AB7/d7lTQqCLR6ibXbqR96o7l2M9oWv6jfOjLmy8WVEK/CCNNFMXb Zr8WN6aksCDxPm8yCF1Fyum3wFp+WWPGi9doaWlQ9lHqNLU2myiwFBwKH19MFHsdUbGo oBEJVzt8yfst3UZLasNLsSWsGRUvVC0E4SCMJJYkAQZJGQY28Ku9oH9wpef+exz11QU7 YsNw== X-Gm-Message-State: AOAM532upMC3Zp61TO39KgyMSfx3S3jzql+jShWfkhER0nICIA52aC7c SBBepm0iAw4OxW6fmF7qRN1bd0icM6N+FA== X-Google-Smtp-Source: ABdhPJzw8yPuUZFXfzV0sa1JRZ54kggFYJZETNtYq3ccKj1poe/C2TrxBIE2epk0cBXLKzWUzXu1ug== X-Received: by 2002:a17:902:7788:: with SMTP id o8mr14961037pll.43.1599355913547; Sat, 05 Sep 2020 18:31:53 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:52 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:33 -0700 Message-Id: <20200906013133.26360-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 11/11] dpdk-devbind: use argparse instead of getopt X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Using the python standard argument parser instead of C library style getopt gives a number of advantages such as checking for conflicting arguments, restricting choices, and automatically generating help messages. The result is similar to the original the only visible change is that some of the help messages are now less wordy. Signed-off-by: Stephen Hemminger --- usertools/dpdk-devbind.py | 196 +++++++++++++++++--------------------- 1 file changed, 85 insertions(+), 111 deletions(-) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index bcdc5da881d9..33d3ef798f7d 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -5,8 +5,8 @@ import sys import os -import getopt import subprocess +import argparse from os.path import exists, abspath, dirname, basename # The PCI base class for all devices @@ -72,76 +72,6 @@ args = [] -def usage(): - '''Print usage information for the program''' - argv0 = basename(sys.argv[0]) - print(""" -Usage: ------- - - %(argv0)s [options] DEVICE1 DEVICE2 .... - -where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax -or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may -also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc. - -Options: - --help, --usage: - Display usage information and quit - - -s, --status: - Print the current status of all known network, crypto, event - and mempool devices. - For each device, it displays the PCI domain, bus, slot and function, - along with a text description of the device. Depending upon whether the - device is being used by a kernel driver, the igb_uio driver, or no - driver, other relevant information will be displayed: - * the Linux interface name e.g. if=eth0 - * the driver being used e.g. drv=igb_uio - * any suitable drivers not currently using that device - e.g. unused=igb_uio - NOTE: if this flag is passed along with a bind/unbind option, the - status display will always occur after the other operations have taken - place. - - --status-dev: - Print the status of given device group. Supported device groups are: - "net", "baseband", "crypto", "event", "mempool" and "compress" - - -b driver, --bind=driver: - Select the driver to use or \"none\" to unbind the device - - -u, --unbind: - Unbind a device (Equivalent to \"-b none\") - - --force: - By default, network devices which are used by Linux - as indicated by - having routes in the routing table - cannot be modified. Using the - --force flag overrides this behavior, allowing active links to be - forcibly unbound. - WARNING: This can lead to loss of network connection and should be used - with caution. - -Examples: ---------- - -To display current device status: - %(argv0)s --status - -To display current network device status: - %(argv0)s --status-dev net - -To bind eth1 from the current driver and move to use igb_uio - %(argv0)s --bind=igb_uio eth1 - -To unbind 0000:01:00.0 from using any driver - %(argv0)s -u 0000:01:00.0 - -To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver - %(argv0)s -b ixgbe 02:00.0 02:00.1 - - """ % locals()) # replace items from local variables - # check if a specific kernel module is loaded def module_is_loaded(module): global loaded_modules @@ -642,38 +572,93 @@ def parse_args(): global status_dev global force_flag global args - if len(sys.argv) <= 1: - usage() - sys.exit(0) - try: - opts, args = getopt.getopt(sys.argv[1:], "b:us", - ["help", "usage", "status", "status-dev=", - "force", "bind=", "unbind", ]) - except getopt.GetoptError as error: - print(str(error)) - print("Run '%s --usage' for further information" % sys.argv[0]) + parser = argparse.ArgumentParser( + description='Utility to bind and unbind devices from Linux kernel', + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=""" +Examples: +--------- + +To display current device status: + %(prog)s --status + +To display current network device status: + %(prog)s --status-dev net + +To bind eth1 from the current driver and move to use vfio-pci + %(prog)s --bind=vfio-pci eth1 + +To unbind 0000:01:00.0 from using any driver + %(prog)s -u 0000:01:00.0 + +To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver + %(prog)s -b ixgbe 02:00.0 02:00.1 +""") + + parser.add_argument( + '-s', + '--status', + action='store_true', + help="Print the current status of all known devices.") + parser.add_argument( + '--status-dev', + help="Print the status of given device group.", + choices=['net', 'baseband', 'crypto', 'event', 'mempool', 'compress']) + bind_group = parser.add_mutually_exclusive_group() + bind_group.add_argument( + '-b', + '--bind', + metavar='DRIVER', + help="Select the driver to use or \"none\" to unbind the device") + bind_group.add_argument( + '-u', + '--unbind', + action='store_true', + help="Unbind a device (equivalent to \"-b none\")") + parser.add_argument( + '--force', + action='store_true', + help=""" +Override restriction on binding devices in use by Linux" +WARNING: This can lead to loss of network connection and should be used with caution. +""") + parser.add_argument( + 'devices', + metavar='DEVICE', + nargs='*', + help=""" +Device specified as PCI "domain:bus:slot.func" syntax or "bus:slot.func" syntax. +For devices bound to Linux kernel drivers, they may be referred to by interface name. +""") + + opt = parser.parse_args() + + if opt.status_dev: + status_flag = True + status_dev = opt.status_dev + if opt.status: + status_flag = True + status_dev = "all" + if opt.force: + force_flag = True + if opt.bind: + b_flag = opt.bind + elif opt.unbind: + b_flag = "none" + args = opt.devices + + if not b_flag and not status_flag: + print("Error: No action specified for devices. " + "Please give a --bind, --ubind or --status option", + file=sys.stderr) + parser.print_usage() sys.exit(1) - for opt, arg in opts: - if opt == "--help" or opt == "--usage": - usage() - sys.exit(0) - if opt == "--status-dev": - status_flag = True - status_dev = arg - if opt == "--status" or opt == "-s": - status_flag = True - status_dev = "all" - if opt == "--force": - force_flag = True - if opt == "-b" or opt == "-u" or opt == "--bind" or opt == "--unbind": - if b_flag is not None: - sys.exit("Error: binding and unbinding are mutually exclusive") - if opt == "-u" or opt == "--unbind": - b_flag = "none" - else: - b_flag = arg + if b_flag and not args: + print("Error: No devices specified.", file=sys.stderr) + parser.print_usage() + sys.exit(1) def do_arg_actions(): @@ -683,17 +668,6 @@ def do_arg_actions(): global force_flag global args - if b_flag is None and not status_flag: - print("Error: No action specified for devices. " - "Please give a -b or -u option", file=sys.stderr) - usage() - sys.exit(1) - - if b_flag is not None and len(args) == 0: - print("Error: No devices specified.", file=sys.stderr) - usage() - sys.exit(1) - if b_flag == "none" or b_flag == "None": unbind_all(args, force_flag) elif b_flag is not None: