From: Jerin Jacob <jerin.jacob@caviumnetworks.com>
To: dev@dpdk.org
Cc: thomas.monjalon@6wind.com, ferruh.yigit@intel.com,
gprathyusha@caviumnetworks.com,
Jerin Jacob <jerin.jacob@caviumnetworks.com>
Subject: [dpdk-dev] [PATCH 1/7] usertools: refactor the get NIC and crypto details
Date: Wed, 22 Mar 2017 19:41:26 +0530 [thread overview]
Message-ID: <1490191892-10396-2-git-send-email-jerin.jacob@caviumnetworks.com> (raw)
In-Reply-To: <1490191892-10396-1-git-send-email-jerin.jacob@caviumnetworks.com>
From: Guduri Prathyusha <gprathyusha@caviumnetworks.com>
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 <gprathyusha@caviumnetworks.com>
Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
---
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
next prev parent reply other threads:[~2017-03-22 14:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-22 14:11 [dpdk-dev] [PATCH 0/7] dpdk-devbind.py refactor Jerin Jacob
2017-03-22 14:11 ` Jerin Jacob [this message]
2017-03-22 14:11 ` [dpdk-dev] [PATCH 2/7] usertools: refactor the show status function Jerin Jacob
2017-03-22 14:11 ` [dpdk-dev] [PATCH 3/7] usertools: optimize lspci invocation Jerin Jacob
2017-03-22 14:11 ` [dpdk-dev] [PATCH 4/7] usertools: use optimized driver override scheme to bind Jerin Jacob
2017-03-22 14:11 ` [dpdk-dev] [PATCH 5/7] usertools: define DPDK PCI functional device Jerin Jacob
2017-03-22 14:11 ` [dpdk-dev] [PATCH 6/7] usertools: add eventdev " Jerin Jacob
2017-03-22 14:11 ` [dpdk-dev] [PATCH 7/7] usertools: add mempool " Jerin Jacob
2017-04-25 9:30 ` [dpdk-dev] [PATCH 0/7] dpdk-devbind.py refactor Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1490191892-10396-2-git-send-email-jerin.jacob@caviumnetworks.com \
--to=jerin.jacob@caviumnetworks.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=gprathyusha@caviumnetworks.com \
--cc=thomas.monjalon@6wind.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).