diff mbox series

usertools/dpdk-devbind: add support for PCI wildcards

Message ID 20200820122355.3357-1-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Headers show
Series usertools/dpdk-devbind: add support for PCI wildcards | expand

Checks

Context Check Description
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Aug. 20, 2020, 12:23 p.m. UTC
When binding or unbinding a range of devices, it can be useful to use
wildcards to specify the devices rather than repeating the same prefix
multiple times. We can use the python "glob" module to give us this
functionality - at least for PCI devices - by checking /sys for matching
files.

Examples of use from my system:

    ./dpdk-devbind.py -b vfio-pci 80:04.*
    ./dpdk-devbind.py -u 80:04.[2-7]

The first example binds eight devices, 80:04.0..80:04.7, to vfio-pci. The
second then unbinds six of those devices, 80:04.2..80:04.7, from any
driver.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 usertools/dpdk-devbind.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Ferruh Yigit Aug. 20, 2020, 2:44 p.m. UTC | #1
On 8/20/2020 1:23 PM, Bruce Richardson wrote:
> When binding or unbinding a range of devices, it can be useful to use
> wildcards to specify the devices rather than repeating the same prefix
> multiple times. We can use the python "glob" module to give us this
> functionality - at least for PCI devices - by checking /sys for matching
> files.
> 
> Examples of use from my system:
> 
>     ./dpdk-devbind.py -b vfio-pci 80:04.*
>     ./dpdk-devbind.py -u 80:04.[2-7]
> 
> The first example binds eight devices, 80:04.0..80:04.7, to vfio-pci. The
> second then unbinds six of those devices, 80:04.2..80:04.7, from any
> driver.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

This is useful, thanks.
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>

It can be good to document this new capability in the 'help' output
(./usertools/dpdk-devbind.py --usage).
Bruce Richardson Aug. 20, 2020, 3:43 p.m. UTC | #2
On Thu, Aug 20, 2020 at 03:44:54PM +0100, Ferruh Yigit wrote:
> On 8/20/2020 1:23 PM, Bruce Richardson wrote:
> > When binding or unbinding a range of devices, it can be useful to use
> > wildcards to specify the devices rather than repeating the same prefix
> > multiple times. We can use the python "glob" module to give us this
> > functionality - at least for PCI devices - by checking /sys for matching
> > files.
> > 
> > Examples of use from my system:
> > 
> >     ./dpdk-devbind.py -b vfio-pci 80:04.*
> >     ./dpdk-devbind.py -u 80:04.[2-7]
> > 
> > The first example binds eight devices, 80:04.0..80:04.7, to vfio-pci. The
> > second then unbinds six of those devices, 80:04.2..80:04.7, from any
> > driver.
> > 
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> 
> This is useful, thanks.
> Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> It can be good to document this new capability in the 'help' output
> (./usertools/dpdk-devbind.py --usage).

Yep, good point, added in V2.
diff mbox series

Patch

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 86b6b53c40..70ed7bce9d 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -8,6 +8,7 @@ 
 import os
 import getopt
 import subprocess
+from glob import glob
 from os.path import exists, abspath, dirname, basename
 
 if sys.version_info.major < 3:
@@ -689,6 +690,16 @@  def parse_args():
             else:
                 b_flag = arg
 
+    # resolve any PCI globs in the args
+    new_args = []
+    sysfs_path = "/sys/bus/pci/devices/"
+    for arg in args:
+        globbed_arg = glob(sysfs_path + arg) + glob(sysfs_path + "0000:" + arg)
+        if globbed_arg:
+            new_args.extend([a[len(sysfs_path):] for a in globbed_arg])
+        else:
+            new_args.append(arg)
+    args = new_args
 
 def do_arg_actions():
     '''do the actual action requested by the user'''