DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards
@ 2020-08-20 12:23 Bruce Richardson
  2020-08-20 14:44 ` Ferruh Yigit
  2020-08-24 17:04 ` [dpdk-dev] [PATCH v4] " Bruce Richardson
  0 siblings, 2 replies; 13+ messages in thread
From: Bruce Richardson @ 2020-08-20 12:23 UTC (permalink / raw)
  To: dev; +Cc: anatoly.burakov, Bruce Richardson

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(+)

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'''
-- 
2.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-20 12:23 [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards Bruce Richardson
@ 2020-08-20 14:44 ` Ferruh Yigit
  2020-08-20 15:43   ` [dpdk-dev] [PATCH v2] " Bruce Richardson
                     ` (2 more replies)
  2020-08-24 17:04 ` [dpdk-dev] [PATCH v4] " Bruce Richardson
  1 sibling, 3 replies; 13+ messages in thread
From: Ferruh Yigit @ 2020-08-20 14:44 UTC (permalink / raw)
  To: Bruce Richardson, dev; +Cc: anatoly.burakov

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).

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [dpdk-dev] [PATCH v2] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-20 14:44 ` Ferruh Yigit
@ 2020-08-20 15:43   ` Bruce Richardson
  2020-08-21  9:14     ` Burakov, Anatoly
  2020-08-21  9:17     ` Burakov, Anatoly
  2020-08-20 15:43   ` [dpdk-dev] [PATCH] " Bruce Richardson
  2020-08-20 15:52   ` [dpdk-dev] [PATCH v3] " Bruce Richardson
  2 siblings, 2 replies; 13+ messages in thread
From: Bruce Richardson @ 2020-08-20 15:43 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, Ferruh Yigit

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>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
V2: added help text additions
---
 usertools/dpdk-devbind.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 86b6b53c40..d13defbe1a 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:
@@ -89,6 +90,8 @@ def usage():
 where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
 or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
 also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
+If devices are specified using PCI <domain:>bus:device:func format, then
+shell wildcards and ranges may be used, e.g. 80:04.*, 80:04.[0-3]
 
 Options:
     --help, --usage:
@@ -145,6 +148,9 @@ def usage():
 To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
         %(argv0)s -b ixgbe 02:00.0 02:00.1
 
+To bind all funcions on device 0000:02:00 to ixgbe kernel driver
+        %(argv0)s -b ixgbe 02:00.*
+
     """ % locals())  # replace items from local variables
 
 
@@ -689,6 +695,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'''
-- 
2.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-20 14:44 ` Ferruh Yigit
  2020-08-20 15:43   ` [dpdk-dev] [PATCH v2] " Bruce Richardson
@ 2020-08-20 15:43   ` Bruce Richardson
  2020-08-20 15:52   ` [dpdk-dev] [PATCH v3] " Bruce Richardson
  2 siblings, 0 replies; 13+ messages in thread
From: Bruce Richardson @ 2020-08-20 15:43 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, anatoly.burakov

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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [dpdk-dev] [PATCH v3] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-20 14:44 ` Ferruh Yigit
  2020-08-20 15:43   ` [dpdk-dev] [PATCH v2] " Bruce Richardson
  2020-08-20 15:43   ` [dpdk-dev] [PATCH] " Bruce Richardson
@ 2020-08-20 15:52   ` Bruce Richardson
  2 siblings, 0 replies; 13+ messages in thread
From: Bruce Richardson @ 2020-08-20 15:52 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, Ferruh Yigit

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>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>

---
V3: fix typo in help text additions
V2: added help text additions
---
 usertools/dpdk-devbind.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 86b6b53c40..5dee63e675 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:
@@ -89,6 +90,8 @@ def usage():
 where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
 or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
 also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
+If devices are specified using PCI <domain:>bus:device:func format, then
+shell wildcards and ranges may be used, e.g. 80:04.*, 80:04.[0-3]
 
 Options:
     --help, --usage:
@@ -145,6 +148,9 @@ def usage():
 To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
         %(argv0)s -b ixgbe 02:00.0 02:00.1
 
+To bind all functions on device 0000:02:00 to ixgbe kernel driver
+        %(argv0)s -b ixgbe 02:00.*
+
     """ % locals())  # replace items from local variables
 
 
@@ -689,6 +695,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'''
-- 
2.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH v2] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-20 15:43   ` [dpdk-dev] [PATCH v2] " Bruce Richardson
@ 2020-08-21  9:14     ` Burakov, Anatoly
  2020-08-24 17:05       ` Bruce Richardson
  2020-08-21  9:17     ` Burakov, Anatoly
  1 sibling, 1 reply; 13+ messages in thread
From: Burakov, Anatoly @ 2020-08-21  9:14 UTC (permalink / raw)
  To: Bruce Richardson, dev; +Cc: Ferruh Yigit

On 20-Aug-20 4:43 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>
> Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> V2: added help text additions
> ---
>   usertools/dpdk-devbind.py | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> index 86b6b53c40..d13defbe1a 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:
> @@ -89,6 +90,8 @@ def usage():
>   where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
>   or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
>   also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
> +If devices are specified using PCI <domain:>bus:device:func format, then
> +shell wildcards and ranges may be used, e.g. 80:04.*, 80:04.[0-3]
>   
>   Options:
>       --help, --usage:
> @@ -145,6 +148,9 @@ def usage():
>   To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
>           %(argv0)s -b ixgbe 02:00.0 02:00.1
>   
> +To bind all funcions on device 0000:02:00 to ixgbe kernel driver
> +        %(argv0)s -b ixgbe 02:00.*
> +
>       """ % locals())  # replace items from local variables
>   
>   
> @@ -689,6 +695,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)

os.path.join()?

> +        if globbed_arg:
> +            new_args.extend([a[len(sysfs_path):] for a in globbed_arg])

os.path.basename()?

> +        else:
> +            new_args.append(arg)
> +    args = new_args
>   
>   def do_arg_actions():
>       '''do the actual action requested by the user'''
> 


-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH v2] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-20 15:43   ` [dpdk-dev] [PATCH v2] " Bruce Richardson
  2020-08-21  9:14     ` Burakov, Anatoly
@ 2020-08-21  9:17     ` Burakov, Anatoly
  2020-08-24 16:19       ` Bruce Richardson
  1 sibling, 1 reply; 13+ messages in thread
From: Burakov, Anatoly @ 2020-08-21  9:17 UTC (permalink / raw)
  To: Bruce Richardson, dev; +Cc: Ferruh Yigit

On 20-Aug-20 4:43 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>
> Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> V2: added help text additions
> ---
>   usertools/dpdk-devbind.py | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> index 86b6b53c40..d13defbe1a 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:
> @@ -89,6 +90,8 @@ def usage():
>   where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
>   or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
>   also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
> +If devices are specified using PCI <domain:>bus:device:func format, then
> +shell wildcards and ranges may be used, e.g. 80:04.*, 80:04.[0-3]
>   
>   Options:
>       --help, --usage:
> @@ -145,6 +148,9 @@ def usage():
>   To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
>           %(argv0)s -b ixgbe 02:00.0 02:00.1
>   
> +To bind all funcions on device 0000:02:00 to ixgbe kernel driver
> +        %(argv0)s -b ixgbe 02:00.*
> +
>       """ % locals())  # replace items from local variables
>   
>   
> @@ -689,6 +695,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)

Also, could be

glob_path = arg if arg.startswith("0000:") else "0000:" + arg
globbed_arg = glob(os.path.join(sysfs_path, glob_path))

No need to glob twice :)

> +        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'''
> 


-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH v2] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-21  9:17     ` Burakov, Anatoly
@ 2020-08-24 16:19       ` Bruce Richardson
  0 siblings, 0 replies; 13+ messages in thread
From: Bruce Richardson @ 2020-08-24 16:19 UTC (permalink / raw)
  To: Burakov, Anatoly; +Cc: dev, Ferruh Yigit

On Fri, Aug 21, 2020 at 10:17:14AM +0100, Burakov, Anatoly wrote:
> On 20-Aug-20 4:43 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>
> > Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> > ---
> > V2: added help text additions
> > ---
> >   usertools/dpdk-devbind.py | 16 ++++++++++++++++
> >   1 file changed, 16 insertions(+)
> > 
> > diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> > index 86b6b53c40..d13defbe1a 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:
> > @@ -89,6 +90,8 @@ def usage():
> >   where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
> >   or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
> >   also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
> > +If devices are specified using PCI <domain:>bus:device:func format, then
> > +shell wildcards and ranges may be used, e.g. 80:04.*, 80:04.[0-3]
> >   Options:
> >       --help, --usage:
> > @@ -145,6 +148,9 @@ def usage():
> >   To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
> >           %(argv0)s -b ixgbe 02:00.0 02:00.1
> > +To bind all funcions on device 0000:02:00 to ixgbe kernel driver
> > +        %(argv0)s -b ixgbe 02:00.*
> > +
> >       """ % locals())  # replace items from local variables
> > @@ -689,6 +695,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)
> 
> Also, could be
> 
> glob_path = arg if arg.startswith("0000:") else "0000:" + arg
> globbed_arg = glob(os.path.join(sysfs_path, glob_path))
> 
> No need to glob twice :)
> 

Well, the two are not quite equivalent if one assumes that the domain part
can start with something other than 0000. If the domain is e.g. FFFF:, you
don't want to prefix that with 0000 - only if no domain is specified.
Therefore it's safer to glob twice, especially since we are not
particularly concerned about performance here (or else we wouldn't be using
python!).

/Bruce

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [dpdk-dev] [PATCH v4] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-20 12:23 [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards Bruce Richardson
  2020-08-20 14:44 ` Ferruh Yigit
@ 2020-08-24 17:04 ` Bruce Richardson
  2020-08-28 15:48   ` Ferruh Yigit
  2020-08-28 16:02   ` Burakov, Anatoly
  1 sibling, 2 replies; 13+ messages in thread
From: Bruce Richardson @ 2020-08-24 17:04 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Anatoly Burakov, Bruce Richardson

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>

---
V4: change path manipulation to use os.path.join and basename
    separated pci_glob out into separate function with doc string
    [dropped Ferruh's test-by due to scope of changes]
V3: fix typo in help text additions
V2: added help text additions
---
 usertools/dpdk-devbind.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 86b6b53c40..6c23d243fa 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -8,7 +8,9 @@
 import os
 import getopt
 import subprocess
+from glob import glob
 from os.path import exists, abspath, dirname, basename
+from os.path import join as path_join
 
 if sys.version_info.major < 3:
     print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
@@ -89,6 +91,8 @@ def usage():
 where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
 or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
 also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
+If devices are specified using PCI <domain:>bus:device:func format, then
+shell wildcards and ranges may be used, e.g. 80:04.*, 80:04.[0-3]
 
 Options:
     --help, --usage:
@@ -145,6 +149,9 @@ def usage():
 To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
         %(argv0)s -b ixgbe 02:00.0 02:00.1
 
+To bind all functions on device 0000:02:00 to ixgbe kernel driver
+        %(argv0)s -b ixgbe 02:00.*
+
     """ % locals())  # replace items from local variables
 
 
@@ -648,6 +655,19 @@ def show_status():
     if status_dev == "misc" or status_dev == "all":
         show_device_status(misc_devices, "Misc (rawdev)")
 
+
+def pci_glob(arg):
+    '''Returns a list containing either:
+    * List of PCI B:D:F matching arg, using shell wildcards e.g. 80:04.*
+    * Only the passed arg if matching list is empty'''
+    sysfs_path = "/sys/bus/pci/devices"
+    for _glob in [arg, '0000:' + arg]:
+        paths = [basename(path) for path in glob(path_join(sysfs_path, _glob))]
+        if paths:
+            return paths
+    return [arg]
+
+
 def parse_args():
     '''Parses the command-line arguments given by the user and takes the
     appropriate action for each'''
@@ -689,6 +709,11 @@ def parse_args():
             else:
                 b_flag = arg
 
+    # resolve any PCI globs in the args
+    new_args = []
+    for arg in args:
+        new_args.extend(pci_glob(arg))
+    args = new_args
 
 def do_arg_actions():
     '''do the actual action requested by the user'''
-- 
2.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH v2] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-21  9:14     ` Burakov, Anatoly
@ 2020-08-24 17:05       ` Bruce Richardson
  0 siblings, 0 replies; 13+ messages in thread
From: Bruce Richardson @ 2020-08-24 17:05 UTC (permalink / raw)
  To: Burakov, Anatoly; +Cc: dev, Ferruh Yigit

On Fri, Aug 21, 2020 at 10:14:19AM +0100, Burakov, Anatoly wrote:
> On 20-Aug-20 4:43 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>
> > Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> > ---
> > V2: added help text additions
> > ---
> >   usertools/dpdk-devbind.py | 16 ++++++++++++++++
> >   1 file changed, 16 insertions(+)
> > 
> > diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> > index 86b6b53c40..d13defbe1a 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:
> > @@ -89,6 +90,8 @@ def usage():
> >   where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
> >   or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
> >   also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
> > +If devices are specified using PCI <domain:>bus:device:func format, then
> > +shell wildcards and ranges may be used, e.g. 80:04.*, 80:04.[0-3]
> >   Options:
> >       --help, --usage:
> > @@ -145,6 +148,9 @@ def usage():
> >   To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
> >           %(argv0)s -b ixgbe 02:00.0 02:00.1
> > +To bind all funcions on device 0000:02:00 to ixgbe kernel driver
> > +        %(argv0)s -b ixgbe 02:00.*
> > +
> >       """ % locals())  # replace items from local variables
> > @@ -689,6 +695,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)
> 
> os.path.join()?
> 
> > +        if globbed_arg:
> > +            new_args.extend([a[len(sysfs_path):] for a in globbed_arg])
> 
> os.path.basename()?
> 
These are used in V4.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH v4] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-24 17:04 ` [dpdk-dev] [PATCH v4] " Bruce Richardson
@ 2020-08-28 15:48   ` Ferruh Yigit
  2020-09-08 21:44     ` Thomas Monjalon
  2020-08-28 16:02   ` Burakov, Anatoly
  1 sibling, 1 reply; 13+ messages in thread
From: Ferruh Yigit @ 2020-08-28 15:48 UTC (permalink / raw)
  To: Bruce Richardson, dev; +Cc: Anatoly Burakov

On 8/24/2020 6:04 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>
>

Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH v4] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-24 17:04 ` [dpdk-dev] [PATCH v4] " Bruce Richardson
  2020-08-28 15:48   ` Ferruh Yigit
@ 2020-08-28 16:02   ` Burakov, Anatoly
  1 sibling, 0 replies; 13+ messages in thread
From: Burakov, Anatoly @ 2020-08-28 16:02 UTC (permalink / raw)
  To: Richardson, Bruce, dev; +Cc: Yigit, Ferruh, Richardson, Bruce

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Thanks,
Anatoly

> -----Original Message-----
> From: Bruce Richardson <bruce.richardson@intel.com>
> Sent: Monday, August 24, 2020 6:05 PM
> To: dev@dpdk.org
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; Burakov, Anatoly
> <anatoly.burakov@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>
> Subject: [PATCH v4] usertools/dpdk-devbind: add support for PCI wildcards
> 
> 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>
> 
> ---


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dpdk-dev] [PATCH v4] usertools/dpdk-devbind: add support for PCI wildcards
  2020-08-28 15:48   ` Ferruh Yigit
@ 2020-09-08 21:44     ` Thomas Monjalon
  0 siblings, 0 replies; 13+ messages in thread
From: Thomas Monjalon @ 2020-09-08 21:44 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev, Anatoly Burakov, Ferruh Yigit

28/08/2020 17:48, Ferruh Yigit:
> On 8/24/2020 6:04 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>
> 
> Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied, thanks



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-09-08 21:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-20 12:23 [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards Bruce Richardson
2020-08-20 14:44 ` Ferruh Yigit
2020-08-20 15:43   ` [dpdk-dev] [PATCH v2] " Bruce Richardson
2020-08-21  9:14     ` Burakov, Anatoly
2020-08-24 17:05       ` Bruce Richardson
2020-08-21  9:17     ` Burakov, Anatoly
2020-08-24 16:19       ` Bruce Richardson
2020-08-20 15:43   ` [dpdk-dev] [PATCH] " Bruce Richardson
2020-08-20 15:52   ` [dpdk-dev] [PATCH v3] " Bruce Richardson
2020-08-24 17:04 ` [dpdk-dev] [PATCH v4] " Bruce Richardson
2020-08-28 15:48   ` Ferruh Yigit
2020-09-08 21:44     ` Thomas Monjalon
2020-08-28 16:02   ` Burakov, Anatoly

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git