From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0057.outbound.protection.outlook.com [104.47.32.57]) by dpdk.org (Postfix) with ESMTP id 8242C695D for ; Wed, 22 Mar 2017 15:12:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=RXheZ0TqdhQ+EAGO83rbxomOy1/euCzFadn0x6cczsA=; b=cggvylp8ZQ9mdhbRkCYB228dfTyp83LKd1u4CyngNyWwXf/VJsWV72DAvQg7L7MCWPVtct4Bhq0fmb3hIASVCkKQ3TKoL22Fdg89rq0z20bVjmZszmLxMRBKKvuyg977+TDYUPAeY8mvX9+5uRd64pMgvaC83UuDt0GtliyGA9M= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost.caveonetworks.com (111.93.218.67) by BLUPR0701MB1714.namprd07.prod.outlook.com (10.163.85.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.977.11; Wed, 22 Mar 2017 14:12:08 +0000 From: Jerin Jacob To: dev@dpdk.org Cc: thomas.monjalon@6wind.com, ferruh.yigit@intel.com, gprathyusha@caviumnetworks.com, Jerin Jacob Date: Wed, 22 Mar 2017 19:41:28 +0530 Message-Id: <1490191892-10396-4-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1490191892-10396-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1490191892-10396-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: MAXPR01CA0061.INDPRD01.PROD.OUTLOOK.COM (10.164.146.161) To BLUPR0701MB1714.namprd07.prod.outlook.com (10.163.85.140) X-MS-Office365-Filtering-Correlation-Id: 2520aa0d-ba7b-4824-0c4f-08d4712d6e1e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BLUPR0701MB1714; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 3:lO4YWCN1AJ56l0m4NSVnVDb1GZUDXo1/E1glitu4vcGLGpPMxsR8uIDSeEFbaSFlhD06ZcEbK6dl8LNfXAoeZ/9uoqc7y/1ss0Hky31fUvv0a4bDvmSzO14Xoqf6IXOfT3pwpSCoWVj/SeZ/xL+yw9+op1AHh/HXm7TqsORllT9Z9e2JmMJ5yBPP0c0iXxLLugwj18nZO1wt0MsIg7a3PhQ4Ixr8NyPX49jLPctPuih7rtPx55N+2SznOUkXdx38p8Ga36l2+PqJjp5lNZ2VsA==; 25:kdtK2sq83p3FMWNLhZFSI80HWFFn+FLmny2sgy86jRGJZf3pGjSDmynSF0RDqlD7931rpUoiTd+dCGajpJVI1x++bEsotg0TCHXdexikCYftwyZukB2oL1SWTTTfGPrQDAVEiq6zi4jBns+t4NHw3hnb9GxcsVvG92f+RgK+pQBgcnKbDNW891KOjW4cb70AVutsfyqIfmjUGFyH/XYU4QNIPt2L80O/AGReVO6+zPATutd3WezISMxJK+pukOKQVa126KUShfoXwltCpHgiAFSw7Hh/BAvUYQgeKW97XDxC/mQC65/P17Nhxv6BYzWJPHAYtVyrocMfrQlVOdnVHQSGN1xDbEH0WyyGLIcWpXT/Qw5HV/dxIHFxE4b+IUI5wN/5u2igb+cTf+hyMpYz4VdoSIYsRe8DA0ENY3wjQA+aeVO6yFsoyciJFcurpCKQVgUaoUcRkzVo01/lEe4lNQ== X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 31:Ib3uIq7/bKnwg1qlgHXDPnH2bgLyhf4UQItO3QRI6b5WgWCu1qegUs/Uo4nkcQ5thQZ/sZDn1XKv3mP7ZoUez6AFPcsQEKj3ijQYpqX0yonuSLmFSS5WeefFi8wyvpF0hGReNQv8itv+hND8l9xhbrbSvwSjfFsHIZSYJJ2SV02gbKK3D4Yb5NYbUTuIs/6GRJDL1JTaMOnbW3sq9rFZaXOpBrznXW+Eh53UpT76RakAAIz4HkR9Dd3hdZMgnJzC; 20:EOtg3HK7DOfkKP16zLM7NG1ho/UkflDYXN++Ed+acahET0/rWX7N7AYdo4pp+KcivBDHf9b67MRSiP47M5G4bz/Z2YP9Re94IlD+lsy+kJASYPkEsR4Pd5Cx7uf4uA0ybq87vNvsn53E/ikvAf9u41+m2PvIEDIi8afQVgxwdppy3J/4Dkf/9Ct2LN68e4kXAjGcVSzz/wCH7js0bHGtCI8YFtqpTk/WuYdrOdDJ5lVOQylaH9xuTIw4Ay6DhDP5I/w2pRuBiNT+Pmv66Yc6A9b8K9FWsa72YLHnwRRbTRTzSYvXbZM4d883Uni9yB5iujBQojSJ8Ob3Asx35JiFAVKtlLNqRdXgNY07nDWOJTTvtq4rfHrQQ0mVw7YDpu2f+zGtm0R56nKFyODw5pETkuu/JhXSDECQaWG5m7isE68CzDbDyUB15i0bK695Mey0AujzFeAE/buAX3yYjr6yJa28gGjfx4I1KUW3avlRwHU3ix1xh4tnVAp0rZNS0sX81pPcTmMyKv0/0AG8GqlArEPIU0CJtZKBhUKPPqtuEQg0gGKPf7mprivLpvZiE/GE+WdO73fZVIpmnPcgS5V+YpFJKJiNBvBDV62rVZvPVrg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123564025)(20161123555025)(20161123558025)(20161123560025)(20161123562025)(6072148); SRVR:BLUPR0701MB1714; BCL:0; PCL:0; RULEID:; SRVR:BLUPR0701MB1714; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 4:y/RBbiHTLn4btCt32SmV7AgzOrahqsC6+28qgaYOSk4KSqfT8oXahinbC/BwWoVaxie8EO0kegotjaV2WbNCS8TOsQExm30SS+w0iLRagSWVZkbrs4+OYYrdoUqmFYpX8OPBdjVOJkyHIl9VFAbTkrvo0RX+9HfGCVc93jtQ0MWL3L/YxRsIdqRyGXK6aCGDETVX40HcJo95qoJy+SsFMaZ1KPN3ys48CYrG/nRPhLrDGua2Rg5cL1ce96ZblOJ1qKDBFIMvy4DsH396HMWzp15pKd++1v2pzLv7vjLc/TIn6o6yDQnt5RThj1hg3/y4ZA3tC+p80UswwnZS40EbVoZ+dcYoi+0NzJwh4F6GSuB8qCVCl1Ihj+0atJj0U+x/hNDrgcvOrnlWGUT9tWwqkmzxLOV3pSo7EW7bGzhcbPGXtVsW+PCJM7kwyiA8XwN+ArC2pUO2AIbO2PnikZHmMaTa0sxhzHfObDL+nouwbQ+l2mLlHDoZPMlmV7wMVbRuvIXbHkKmv4eT9wb0m3X6MLI4fcmDg+qDa5gTNsBh+JGUBYZoy06RDrBGvKe0XP08Jz3MvQj3YGqxzzn12YcFoGwF0gE8yfc+nrZkZDKQ1uA= X-Forefront-PRVS: 02543CD7CD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(6486002)(53936002)(4326008)(6506006)(50466002)(48376002)(189998001)(36756003)(25786009)(6512007)(33646002)(53416004)(2906002)(6666003)(2950100002)(42882006)(47776003)(66066001)(6916009)(76506005)(42186005)(38730400002)(107886003)(110136004)(5660300001)(5009440100003)(50226002)(305945005)(7736002)(2361001)(3846002)(6116002)(81166006)(2351001)(8676002)(50986999)(76176999)(5003940100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0701MB1714; H:localhost.caveonetworks.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0701MB1714; 23:f9nm8mW3PICK3JR1ZBVh5hY42xNBAsEre58FGia?= =?us-ascii?Q?kHlOwtSPMS+xWfqaY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2uudkFPAB?= =?us-ascii?Q?KhOL0bOUEfas+dIpGBsERNCUWOrWcyibuy1tYgnfaX3kWn8BG+5V1zrMxSQP?= =?us-ascii?Q?UapFR1WzedE0lMGszCGflxlXxJZm8/PUqIs2NZk/4oSl15A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 6:ATomUiZz6WktvobZvTLu37X/BGVZIynyt2qbBnR5r9hOhzVI6YQMT+ukmMNeYGpcrWJLsNxLlATO80Au/uh6aYFPNX2h5P1PDvNryl3s5kSjRuEWyiRQ0mbDSHKop2S23mC1jbuukbgVgIekoGxRZOu9Z0oaHK+0ePrXbVq1e/6U1IWWPUlgwKTPrhRWDNy/oXzV8tzqTscYRqUGS/RV8b1X7U4Vs4fcxrBUuSmcALRDWU49qsvRVCeAfc0x0h77sYHLiS+UU140NTAQjPcCivN72t5huJQg9kAmlqiuRmx4IbOkewPebzkrk6SwjSL2/o6ulk+gzonQy+vLIg30p074XJnBKhTLzEqQ3xObEajrvPF5qsaEkhmFCrvKSQs98Br0nPHz3YSmnpUnU2vbNg==; 5:G+FC+O9jRnwy/UuLHSjTx9QOvBvI4HnxwFmYZqUJ+LA0M+6gcibdXRqdLgfXFechBPQ95cSGXtfemUVfbXrRuKwbs5tHu8EY1kACf8Q/tBMRnqZXfar47o6Magu3NmBWvhikjuKgKHBBs/XT8JRbpw==; 24:8Su+dfoATLzKtWUEwz52AC21DGDLz/bisvahhJnzMZOi4R5MKE3bzkAkGJCAN64yUS/ha2uZ13802hmvGTw+W7Fh8gLbJ2+L1yMgjLF1Zj4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 7:L75GoQZW4OPupoztcKHMlG6DH/xLbSImlaIKuWMtim/SA6mCNO6lCzQRwp1rqC/712SfNH09wPRyEdZpQJDFb6LaX3w1Ws685xjeyupNsSpT+/BnZ0IGl8ikFd37UbdOeK+83J4JqilYjEUO5pHgwujkuuix98M+GHCv7wJT5e8UV/gWzvw/RQ+7+R75lKX5Rw3rd5RFfbrWuIDvYVMBlEjLRADsfoPfwt81s8i+WDgte1B4bGYIkE1iCiF8e8ooRRM+gHtATGdKAmTu2T5SznddXPbywcmXC5zq4bGKMMgeMDh6AsMqp+J66vB3K82Wgl2u/Pdtt1KjvGlkyXQmIA== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2017 14:12:08.2885 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1714 Subject: [dpdk-dev] [PATCH 3/7] usertools: optimize lspci invocation 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: , X-List-Received-Date: Wed, 22 Mar 2017 14:12:12 -0000 From: Guduri Prathyusha lspci invoked twice over all the pci devices in the system. The first pass is to extract Numeric IDs and second pass to get extended device details. As an optimization, Used lspci with -nn option in get_device_details() to obtain Numeric ID and extended device details in one shot. In addition to this, After binding the PCI device, lspci needs to be invoked again to confirm the proper bind operation. Used a boolean argument to express this case in get_pci_device_details() Signed-off-by: Guduri Prathyusha Signed-off-by: Jerin Jacob --- usertools/dpdk-devbind.py | 52 ++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index 83c4c17..9beadde 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -208,19 +208,20 @@ def has_driver(dev_id): return "Driver_str" in devices[dev_id] -def get_pci_device_details(dev_id): +def get_pci_device_details(dev_id, probe_lspci): '''This function gets additional details for a PCI device''' device = {} - extra_info = check_output(["lspci", "-vmmks", dev_id]).splitlines() + if probe_lspci: + extra_info = check_output(["lspci", "-vmmks", dev_id]).splitlines() - # parse lspci details - for line in extra_info: - if len(line) == 0: - continue - name, value = line.decode().split("\t", 1) - name = name.strip(":") + "_str" - device[name] = value + # parse lspci details + for line in extra_info: + if len(line) == 0: + continue + name, value = line.decode().split("\t", 1) + name = name.strip(":") + "_str" + device[name] = value # check for a unix interface name device["Interface"] = "" for base, dirs, _ in os.walk("/sys/bus/pci/devices/%s/" % dev_id): @@ -246,20 +247,30 @@ def get_device_details(devices_type): global dpdk_drivers # first loop through and read details for all devices - # request machine readable format, with numeric IDs + # request machine readable format, with numeric IDs and String dev = {} - dev_lines = check_output(["lspci", "-Dvmmn"]).splitlines() + dev_lines = check_output(["lspci", "-Dvmmnnk"]).splitlines() for dev_line in dev_lines: if len(dev_line) == 0: if dev["Class"][0:2] == devices_type: # convert device and vendor ids to numbers, then add to global dev["Vendor"] = int(dev["Vendor"], 16) dev["Device"] = int(dev["Device"], 16) + if "Driver" in dev.keys(): + dev["Driver_str"] = dev.pop("Driver") # use dict to make copy of dev devices[dev["Slot"]] = dict(dev) + # Clear previous device's data + dev = {} else: name, value = dev_line.decode().split("\t", 1) - dev[name.rstrip(":")] = value + value_list = value.rsplit(' ', 1) + if len(value_list) > 1: + # String stored in _str + dev[name.rstrip(":") + '_str'] = value_list[0] + # Numeric IDs + dev[name.rstrip(":")] = value_list[len(value_list) - 1] \ + .rstrip("]").lstrip("[") if devices_type == NETWORK_BASE_CLASS: # check what is the interface if any for an ssh connection if @@ -281,7 +292,8 @@ def get_device_details(devices_type): # get additional info and add it to existing data devices[d] = devices[d].copy() - devices[d].update(get_pci_device_details(d).items()) + # No need to probe lspci + devices[d].update(get_pci_device_details(d, False).items()) if devices_type == NETWORK_BASE_CLASS: for _if in ssh_if: @@ -412,7 +424,7 @@ def bind_one(dev_id, driver, force): # for some reason, closing dev_id after adding a new PCI ID to new_id # results in IOError. however, if the device was successfully bound, # we don't care for any errors and can safely ignore IOError - tmp = get_pci_device_details(dev_id) + tmp = get_pci_device_details(dev_id, True) if "Driver_str" in tmp and tmp["Driver_str"] == driver: return print("Error: bind failed for %s - Cannot bind to driver %s" @@ -450,7 +462,7 @@ def bind_all(dev_list, driver, force=False): # update information about this device devices[d] = dict(devices[d].items() + - get_pci_device_details(d).items()) + get_pci_device_details(d, True).items()) # check if updated information indicates that the device was bound if "Driver_str" in devices[d]: @@ -470,8 +482,9 @@ def display_devices(title, dev_list, extra_params=None): else: for dev in dev_list: if extra_params is not None: - strings.append("%s '%s' %s" % (dev["Slot"], + strings.append("%s '%s %s' %s" % (dev["Slot"], dev["Device_str"], + dev["Device"], extra_params % dev)) else: strings.append("%s '%s'" % (dev["Slot"], dev["Device_str"])) @@ -497,12 +510,13 @@ def show_device_status(devices_type, device_name): kernel_drv.append(devices[d]) # print each category separately, so we can clearly see what's used by DPDK - display_devices("%s devices using DPDK-compatible driver" % device_name, dpdk_drv, - "drv=%(Driver_str)s unused=%(Module_str)s") + display_devices("%s devices using DPDK-compatible driver" % device_name, + dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s") display_devices("%s devices using kernel driver" % device_name, kernel_drv, "if=%(Interface)s drv=%(Driver_str)s " "unused=%(Module_str)s %(Active)s") - display_devices("Other %s devices" % device_name, no_drv, "unused=%(Module_str)s") + display_devices("Other %s devices" % device_name, no_drv, + "unused=%(Module_str)s") def show_status(): '''Function called when the script is passed the "--status" option. -- 2.5.5