X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=usertools%2Fdpdk-devbind.py;h=98bd1b7e4da189be04604a0cb7c68aba48796127;hb=e863fe3a13da89787fdf3b5c590101a3c0f10af6;hp=bd7dc09e62dc92071a30680a1c068183d0019c6e;hpb=81255f27c65c7f42f50ee8dfb0feeb40c36c4c61;p=dpdk.git diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index bd7dc09e62..98bd1b7e4d 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -7,9 +7,10 @@ import sys import os import subprocess import argparse +import platform from glob import glob -from os.path import exists, abspath, dirname, basename +from os.path import exists, basename from os.path import join as path_join # The PCI base class for all devices @@ -107,7 +108,17 @@ def module_is_loaded(module): loaded_modules = sysfs_mods - return module in sysfs_mods + # add built-in modules as loaded + release = platform.uname().release + filename = os.path.join("/lib/modules/", release, "modules.builtin") + if os.path.exists(filename): + try: + with open(filename) as f: + loaded_modules += [os.path.splitext(os.path.basename(mod))[0] for mod in f] + except IOError: + print("Warning: cannot read list of built-in kernel modules") + + return module in loaded_modules def check_modules(): @@ -143,7 +154,7 @@ def get_pci_device_details(dev_id, probe_lspci): extra_info = subprocess.check_output(["lspci", "-vmmks", dev_id]).splitlines() # parse lspci details for line in extra_info: - if len(line) == 0: + if not line: continue name, value = line.decode("utf8").split("\t", 1) name = name.strip(":") + "_str" @@ -178,7 +189,7 @@ def get_device_details(devices_type): dev = {} dev_lines = subprocess.check_output(["lspci", "-Dvmmnnk"]).splitlines() for dev_line in dev_lines: - if len(dev_line) == 0: + if not dev_line: if device_type_match(dev, devices_type): # Replace "Driver" with "Driver_str" to have consistency of # of dictionary key names @@ -193,7 +204,7 @@ def get_device_details(devices_type): else: name, value = dev_line.decode("utf8").split("\t", 1) value_list = value.rsplit(' ', 1) - if len(value_list) > 1: + if value_list: # String stored in _str dev[name.rstrip(":") + '_str'] = value_list[0] # Numeric IDs @@ -341,7 +352,7 @@ def bind_one(dev_id, driver, force): # of unbinding those devices if driver in dpdk_drivers: filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id - if os.path.exists(filename): + if exists(filename): try: f = open(filename, "w") except: @@ -404,7 +415,7 @@ def bind_one(dev_id, driver, force): # Before unbinding it, overwrite driver_override with empty string so that # the device can be bound to any other driver filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id - if os.path.exists(filename): + if exists(filename): try: f = open(filename, "w") except: @@ -472,7 +483,7 @@ def bind_all(dev_list, driver, force=False): # that are not bound to any other driver could be bound even if no one has # asked them to. hence, we check the list of drivers again, and see if # some of the previously-unbound devices were erroneously bound. - if not os.path.exists("/sys/bus/pci/devices/%s/driver_override" % d): + if not exists("/sys/bus/pci/devices/%s/driver_override" % d): for d in devices.keys(): # skip devices that were already bound or that we know should be bound if "Driver_str" in devices[d] or d in dev_list: @@ -495,7 +506,7 @@ def display_devices(title, dev_list, extra_params=None): strings = [] # this holds the strings to print. We sort before printing print("\n%s" % title) print("="*len(title)) - if len(dev_list) == 0: + if not dev_list: strings.append("") else: for dev in dev_list: @@ -538,17 +549,17 @@ def show_device_status(devices_type, device_name, if_field=False): return # print each category separately, so we can clearly see what's used by DPDK - if len(dpdk_drv) != 0: + if dpdk_drv: display_devices("%s devices using DPDK-compatible driver" % device_name, dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s") - if len(kernel_drv) != 0: + if kernel_drv: if_text = "" if if_field: if_text = "if=%(Interface)s " display_devices("%s devices using kernel driver" % device_name, kernel_drv, if_text + "drv=%(Driver_str)s " "unused=%(Module_str)s %(Active)s") - if len(no_drv) != 0: + if no_drv: display_devices("Other %s devices" % device_name, no_drv, "unused=%(Module_str)s") @@ -557,28 +568,28 @@ def show_status(): Displays to the user what devices are bound to the igb_uio driver, the kernel driver or to no driver''' - if status_dev == "net" or status_dev == "all": + if status_dev in ["net", "all"]: show_device_status(network_devices, "Network", if_field=True) - if status_dev == "baseband" or status_dev == "all": + if status_dev in ["baseband", "all"]: show_device_status(baseband_devices, "Baseband") - if status_dev == "crypto" or status_dev == "all": + if status_dev in ["crypto", "all"]: show_device_status(crypto_devices, "Crypto") - if status_dev == "event" or status_dev == "all": + if status_dev in ["event", "all"]: show_device_status(eventdev_devices, "Eventdev") - if status_dev == "mempool" or status_dev == "all": + if status_dev in ["mempool", "all"]: show_device_status(mempool_devices, "Mempool") - if status_dev == "compress" or status_dev == "all": + if status_dev in ["compress", "all"]: show_device_status(compress_devices, "Compress") - if status_dev == "misc" or status_dev == "all": + if status_dev in ["misc", "all"]: show_device_status(misc_devices, "Misc (rawdev)") - if status_dev == "regex" or status_dev == "all": + if status_dev in ["regex", "all"]: show_device_status(regex_devices, "Regex") @@ -634,7 +645,8 @@ To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver parser.add_argument( '--status-dev', help="Print the status of given device group.", - choices=['net', 'baseband', 'crypto', 'event', 'mempool', 'compress']) + choices=['baseband', 'compress', 'crypto', 'event', + 'mempool', 'misc', 'net', 'regex']) bind_group = parser.add_mutually_exclusive_group() bind_group.add_argument( '-b', @@ -703,7 +715,7 @@ def do_arg_actions(): global force_flag global args - if b_flag == "none" or b_flag == "None": + if b_flag in ["none", "None"]: unbind_all(args, force_flag) elif b_flag is not None: bind_all(args, b_flag, force_flag)