From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0088.outbound.protection.outlook.com [104.47.36.88]) by dpdk.org (Postfix) with ESMTP id ABE7E695D for ; Wed, 22 Mar 2017 15:12:06 +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=BZlmxq3uJc8uAVZcVCOS055tiEm4Hq7+umsdPx2GWSM=; b=EIhjbX8E6JWQkreiJMEajfpcCkPuNmljGbz5f4TIhaUHBTNrW5Y5oe82LcsZ1Uph2A3rEgiEMp1DZfiEMcV1m1eJhZxB3GKoQnmqNC7XIQRew8fO3pMmc7WIdgi3OWDX+E+eoyal7+2FJ4v3rPlxKF1CFKw+S9mSB9sGvEICGCc= 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:03 +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:26 +0530 Message-Id: <1490191892-10396-2-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: 6bc4a4dc-1193-4467-070d-08d4712d6b61 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BLUPR0701MB1714; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 3:Kjm9l/vMJAeNsDIHvQqRHz/XVqCv/NgYBtU12hBnTALlRcDkay0aivLeJBWt/cmqN8xRtMCoSvkg0huIOBJzVKeEANqM5K+eR44tUHBCyCzE4ocD8fyCSsRcJrgdtrnQI7w2al4EfzJnKE1xPEtGlpozocpYre3HKk+//yKba6pQ0rfw38VT+9RYhqbte/T8wf4oEcT07xPem/iVM1HA1e7CRee143Zj89D3Fe77O1VQYuxh+R4jhcrQYhWXMz4wVlIyBYEztp0+E18FvJw55w==; 25:AA+nhoSKx9Xae+Kb1VJE2OF3FZ8TEkVrmhc39IEnIlfd8BqZGw5cjzPm7zuEWXgOxuQBcgyMKModENPx67JogcVKWPDnM/C42PP+N5qEJKWjdQt6oMbnhpIY3bgDYAdiHcXqKCzNORsm2FsagDzh2qsdT4fyhTAtf0qlZHySwO1nORFlkaKHZs0G83xuE5c0CgMwc0/Lfk0/HOtNsFuta1lq8XnWM2pjR4Jx66cd7RBHY6Nlt11pxUDrmogOpTRE21I8G1XGKQSVGrNePWlTBkgNCrTwSQ9tSU6UjmjiqgVTvtbGMh9siWAm4hHjdPF11g5HF+qnuM1lIRaNVT5mjkL0eKlb1TEoALDH3a1m/zSLUkQV36Z8goZ2G6OjTE8b9TrhXrxKidhFA9x4ijvbjbezl3p7QeRoC3GMRIKVkO6eeE+aBw97Y6/egatjnR0YsXMyAACTRrWjBPqHKDVj1w== X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 31:HtSmiOjopyaWSAnWtO/Cab8xXdUEFTYRvpVKz8AveVogEhnWzfodNiK2i/ItEtldnmcCDM1da2ti22e0CAF9kDCeq+TcjWVeSzbZmRStsgOqXoS/0PfgPtGfsSTg+DPwqHIo9hjurqLP7o1c8R/SseVrgjqpeJrl8WGRHoZ2IbHclKVYsuHxJbCReP0aTSE+NtafDpY7dZEMgRxwHPxm0vP1buUA4useEo92XR2s9SU=; 20:f7+pwPnPbSQ/p55FsCJxUIngRS2qtL7zA7gN4eOaptwNfjyf+Qg0WaZWABD+uGsN/rNgGcwGN+1iwCUAjdAJKp/H8yMEIyGPn5pNMdaFF7kln28CJeNCD9WsLZEhRzGoMn7UrGSrDe7VgfxxjlkEW5gDUk1Ux7O7gez3m4ubVA9KTVbFsgHzf7gDIEO+3/eTvJ3IEp5nDspVCEDL3WTuiR7yfX9ncn9fGvofx3qUdDqZABm1C8mhtSyzNJlTXY4vctGiH17U+Vt7zOfMEt2Pf3EbxAYFIRy5Gxl6G3aHNqXc3L7we649zoSCCg3bLnTpW4dY3rhhu7qiiri9SlzujRv8KTxd0nMyFbqljy255pQupdyHzv5rpevGccx9bIaUbKMDSQO5bhPpwBU4pFw61NwwYljQMDTVcFZLm5HprW15BJyPG0qVEDPkjulzLtdGlx+0edQ7B8Op51x/K7a4CyxdPU0eJGtj3Za+RR0KDmM+vBxJYy9tmIRGjE7GW6VErFle4lrSXpDcnwVOjGuyo0Nb4f3iEN7xWz5N5KwlY3bK/3jTMC/NyMo3/xuMmovj3hnRck8Tj3eVGZTZDI1U50rtpMhg+bDKzYnREbgpchg= 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:08osxHtJ35cYQODbZAaA7Zl6PW8PW0sL+GTa718x7nQszI3ay5xy/YBnzuzlgkHiYBe+lgtiCha+4NfMY9toQPUvmB93WozRdW7osZS/PgbtDyS3JIGaya2uEAury3rTf4JLqbdYFskcA4pLtnXsVRDlLuIFQtzh23MN/EgyjNUeW6AGie2eWLVIKhzVB+LC7+OhWxp/8Dv4yNQUzAt4IGPgOiEQgHUHvVNTITjEpT1ZDHryFGyb+xEdbGbZldCf14Pb/DCTFdZlAyy6YPiTCel4el9xZ05J4M9XuQWH88jHVXM8THV8IzVdHOINd4qUBYxH4KjvbzZ35YgSql+QZffKh3isKWeMhb3bHl+3+o0Dg8TwmzJeA1yZfqF+azZAaT2fFdnotHLSzau/EcPBlilz4d/pkWE8xaCCQyfuRXA4S2USOcQX4v1LjK7ow426JEtOT6udA/CqdSVmzzNwuC04PV+IQqHtpZFfuEvB5gtK+IJChoNpudq1evJdLgSNv/pU2d6XgnThHo/E0sSaGi1kgfDLLiHPPot7oW9R2Wysy1+nkCMQSOqVC05YVgh67DoZD2jI3K7B0qfFzRCjPXAkaEBtYuNk2irYh1NOoAE= 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:LmpkH7XQYEFxMkdipVtFlGQewtgrOOSNHV6gd+a?= =?us-ascii?Q?Arr3Ue+Z664UmvKHc/jtH65T5muk+kOBFHOdOvnz55Pc6duCtN2SgbXKHUX3?= =?us-ascii?Q?rAHEov0gn2lQXYW03lHEiDGkdnh3cow9Lg7B7Lul7JMH+B0HZXPsxIcDldu/?= =?us-ascii?Q?qoEt3tvjJWxDzjFCytML1weYyLNVqblnwDrJnBL7hCtCA1OvAZW0tn+1AsCY?= =?us-ascii?Q?xyYytFNuN4BROHNGem11MBVCyvey1DdSj37X6+HZmU82JR49pILTVi3fA/Ft?= =?us-ascii?Q?aK0Ba8mu9h3LGGeG2g5OJ1ydMapfJ9069QfF/3WnGgYExlg7HXcupuyYjfnq?= =?us-ascii?Q?XP0XPN13O0jjgnd5DBsp6QutjARMTKNrPbQG4PioN46nmbeDdTYoDx//E6dy?= =?us-ascii?Q?ucIjIL6qH25m1TGGWU7AJ12VRU8Klycs1ssVjpjU57XnJZ7ZgYbc6tx+C5hx?= =?us-ascii?Q?8SUyHaXMr596CnK04am5evWMu0wuHOfLxlsOveCLALwietgG4WK1hCGZvfU4?= =?us-ascii?Q?aSByPLDHd+deVyIKCNgmeNCsnQsJO86QaknwbFm9WdbbXVWGYY1wneIrCeed?= =?us-ascii?Q?RfG1sMrvY6oGU/rlVjap0oSwA/eZrGhHTEbd/rKwx4MeoXX++C5osOFpTxAQ?= =?us-ascii?Q?f9pgSi2rX2rIF81r1tY78Y437NPgtkn9I6Ty47+3xnpRdDfYRG1GtKoqWxTg?= =?us-ascii?Q?R79zCzE4oLAtoujd+YiepH2BzAPY1neDboPXgo+7s6DLPVVTrHiTwyyfNjos?= =?us-ascii?Q?iWFfwrRtSude3Nh8EivUmWQ2FpTCHP6swWZ+pxpHbw5lZInMdzoIIG/AWsAX?= =?us-ascii?Q?qpD2rED13uef/s/zC8EpR/rpkpRGF+yCGHrz290/bpJ4+nc0H6O5mcHyl53C?= =?us-ascii?Q?/jdZv1on3A9iKV2KL5iM2EERXfesOwrPSj2bKxonSrarQE59kKYLs8eDQNzQ?= =?us-ascii?Q?mX5WxOMhyOSVoRcMLmh5nYmwjemydZnR3pb/c22i8ub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Gkgy/8puHQVp2IvNsSpzWGJGEFKxfsIWmX/cJrgQxPp4u8NrQvvPvqIKhQ/JhI1LnF9NTZomJ0EM1pLU5nGcMdVe+I1Qler3NiujkPV2C4+B+9s8ikG9ThYb6gw4vYEI83GWZDCtwoRWmaq1XYA/zDHKTYdfA== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2017 14:12:03.8034 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1714 Subject: [dpdk-dev] [PATCH 1/7] usertools: refactor the get NIC and crypto details 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:07 -0000 From: Guduri Prathyusha get_nic_details() and get_crypto_details() shares a lot of common code. Created a new unified get_device_details() function get the device details. Signed-off-by: Guduri Prathyusha Signed-off-by: Jerin Jacob --- usertools/dpdk-devbind.py | 115 +++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 79 deletions(-) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index 1b9c651..0444b54 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -234,23 +234,24 @@ def get_pci_device_details(dev_id): return device - -def get_nic_details(): - '''This function populates the "devices" dictionary. The keys used are - the pci addresses (domain:bus:slot.func). The values are themselves - dictionaries - one for each NIC.''' - global devices - global dpdk_drivers - - # clear any old data +def clear_data(): + '''This function clears any old data''' devices = {} + +def get_device_details(devices_type): + '''This function populates the "devices" dictionary. The keys used are + the pci addresses (domain:bus:slot.func). The values are themselves + dictionaries - one for each NIC.''' + global devices + global dpdk_drivers + # first loop through and read details for all devices # request machine readable format, with numeric IDs dev = {} dev_lines = check_output(["lspci", "-Dvmmn"]).splitlines() for dev_line in dev_lines: if len(dev_line) == 0: - if dev["Class"][0:2] == NETWORK_BASE_CLASS: + 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) @@ -260,81 +261,35 @@ def get_nic_details(): name, value = dev_line.decode().split("\t", 1) dev[name.rstrip(":")] = value - # check what is the interface if any for an ssh connection if - # any to this host, so we can mark it later. - ssh_if = [] - route = check_output(["ip", "-o", "route"]) - # filter out all lines for 169.254 routes - route = "\n".join(filter(lambda ln: not ln.startswith("169.254"), + if devices_type == NETWORK_BASE_CLASS: + # check what is the interface if any for an ssh connection if + # any to this host, so we can mark it later. + ssh_if = [] + route = check_output(["ip", "-o", "route"]) + # filter out all lines for 169.254 routes + route = "\n".join(filter(lambda ln: not ln.startswith("169.254"), route.decode().splitlines())) - rt_info = route.split() - for i in range(len(rt_info) - 1): - if rt_info[i] == "dev": - ssh_if.append(rt_info[i+1]) + rt_info = route.split() + for i in range(len(rt_info) - 1): + if rt_info[i] == "dev": + ssh_if.append(rt_info[i+1]) # based on the basic info, get extended text details for d in devices.keys(): - # get additional info and add it to existing data - devices[d] = devices[d].copy() - devices[d].update(get_pci_device_details(d).items()) - - for _if in ssh_if: - if _if in devices[d]["Interface"].split(","): - devices[d]["Ssh_if"] = True - devices[d]["Active"] = "*Active*" - break - - # add igb_uio to list of supporting modules if needed - if "Module_str" in devices[d]: - for driver in dpdk_drivers: - if driver not in devices[d]["Module_str"]: - devices[d]["Module_str"] = \ - devices[d]["Module_str"] + ",%s" % driver - else: - devices[d]["Module_str"] = ",".join(dpdk_drivers) - - # make sure the driver and module strings do not have any duplicates - if has_driver(d): - modules = devices[d]["Module_str"].split(",") - if devices[d]["Driver_str"] in modules: - modules.remove(devices[d]["Driver_str"]) - devices[d]["Module_str"] = ",".join(modules) - - -def get_crypto_details(): - '''This function populates the "devices" dictionary. The keys used are - the pci addresses (domain:bus:slot.func). The values are themselves - dictionaries - one for each NIC.''' - global devices - global dpdk_drivers - - # clear any old data - # devices = {} - # first loop through and read details for all devices - # request machine readable format, with numeric IDs - dev = {} - dev_lines = check_output(["lspci", "-Dvmmn"]).splitlines() - for dev_line in dev_lines: - if len(dev_line) == 0: - if dev["Class"][0:2] == CRYPTO_BASE_CLASS: - # convert device and vendor ids to numbers, then add to global - dev["Vendor"] = int(dev["Vendor"], 16) - dev["Device"] = int(dev["Device"], 16) - # use dict to make copy of dev - devices[dev["Slot"]] = dict(dev) - else: - name, value = dev_line.decode().split("\t", 1) - dev[name.rstrip(":")] = value - - # based on the basic info, get extended text details - for d in devices.keys(): - if devices[d]["Class"][0:2] != CRYPTO_BASE_CLASS: + if devices[d]["Class"][0:2] != devices_type: continue # get additional info and add it to existing data devices[d] = devices[d].copy() devices[d].update(get_pci_device_details(d).items()) + if devices_type == NETWORK_BASE_CLASS: + for _if in ssh_if: + if _if in devices[d]["Interface"].split(","): + devices[d]["Ssh_if"] = True + devices[d]["Active"] = "*Active*" + break + # add igb_uio to list of supporting modules if needed if "Module_str" in devices[d]: for driver in dpdk_drivers: @@ -638,8 +593,9 @@ def do_arg_actions(): bind_all(args, b_flag, force_flag) if status_flag: if b_flag is not None: - get_nic_details() # refresh if we have changed anything - get_crypto_details() # refresh if we have changed anything + clear_data() + get_device_details(NETWORK_BASE_CLASS) # refresh if we have changed anything + get_device_details(CRYPTO_BASE_CLASS) # refresh if we have changed anything show_status() @@ -647,8 +603,9 @@ def main(): '''program main function''' parse_args() check_modules() - get_nic_details() - get_crypto_details() + clear_data() + get_device_details(NETWORK_BASE_CLASS) + get_device_details(CRYPTO_BASE_CLASS) do_arg_actions() if __name__ == "__main__": -- 2.5.5