devbind: don't display non-existent device categories

Message ID 07b7c67be5adc770b028212ef8918d4ae8f11255.1542127066.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series devbind: don't display non-existent device categories |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing fail Performance Testing issues
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Anatoly Burakov Nov. 13, 2018, 4:42 p.m. UTC
  If there aren't any devices of a particular category on user's
system, we still display them, which is bad for usability. Fix
devbind to not print out a category unless there are devices in
it.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 usertools/dpdk-devbind.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
  

Comments

Hunt, David Nov. 15, 2018, 1:27 p.m. UTC | #1
Hi Anatoly,

On 13/11/2018 4:42 PM, Anatoly Burakov wrote:
> If there aren't any devices of a particular category on user's
> system, we still display them, which is bad for usability. Fix
> devbind to not print out a category unless there are devices in
> it.
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>   usertools/dpdk-devbind.py | 27 ++++++++++++++++++++-------
>   1 file changed, 20 insertions(+), 7 deletions(-)
>
> diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> index 7d564634c..9f190e227 100755
> --- a/usertools/dpdk-devbind.py
> +++ b/usertools/dpdk-devbind.py
> @@ -546,14 +546,27 @@ def show_device_status(devices_type, device_name):
>               else:
>                   kernel_drv.append(devices[d])
>   
> +    n_devs = len(dpdk_drv) + len(kernel_drv) + len(no_drv)
> +
> +    # don't bother displaying anything if there are no devices
> +    if n_devs == 0:
> +        msg = "No '%s' devices detected" % device_name
> +	print("")
> +	print(msg)
> +	print("".join('=' * len(msg)))
> +        return
> +
>       # print each category separately, so we can clearly see what's used by DPDK
> -    display_devices("%s devices using DPDK-compatible driver" % device_name,
> -                    dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
> -    display_devices("%s devices using kernel driver" % device_name, kernel_drv,
> -                    "if=%(Interface)s drv=%(Driver_str)s "
> -                    "unused=%(Module_str)s %(Active)s")
> -    display_devices("Other %s devices" % device_name, no_drv,
> -                    "unused=%(Module_str)s")
> +    if len(dpdk_drv) != 0:
> +        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:
> +        display_devices("%s devices using kernel driver" % device_name, kernel_drv,
> +                        "if=%(Interface)s drv=%(Driver_str)s "
> +                        "unused=%(Module_str)s %(Active)s")
> +    if len(no_drv) != 0:
> +        display_devices("Other %s devices" % device_name, no_drv,
> +                        "unused=%(Module_str)s")
>   
>   def show_status():
>       '''Function called when the script is passed the "--status" option.


I REALLY like this patch. It makes the dpdk-devbind output MUCH more 
readable!

Reviewed-by: David Hunt <david.hunt@intel.com>
  
Wiles, Keith Nov. 15, 2018, 2:06 p.m. UTC | #2
> On Nov 15, 2018, at 7:27 AM, Hunt, David <david.hunt@intel.com> wrote:
> 
> Hi Anatoly,
> 
> On 13/11/2018 4:42 PM, Anatoly Burakov wrote:
>> If there aren't any devices of a particular category on user's
>> system, we still display them, which is bad for usability. Fix
>> devbind to not print out a category unless there are devices in
>> it.
>> 
>> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>> ---
>>  usertools/dpdk-devbind.py | 27 ++++++++++++++++++++-------
>>  1 file changed, 20 insertions(+), 7 deletions(-)
>> 
>> diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
>> index 7d564634c..9f190e227 100755
>> --- a/usertools/dpdk-devbind.py
>> +++ b/usertools/dpdk-devbind.py
>> @@ -546,14 +546,27 @@ def show_device_status(devices_type, device_name):
>>              else:
>>                  kernel_drv.append(devices[d])
>>  +    n_devs = len(dpdk_drv) + len(kernel_drv) + len(no_drv)
>> +
>> +    # don't bother displaying anything if there are no devices
>> +    if n_devs == 0:
>> +        msg = "No '%s' devices detected" % device_name
>> +	print("")
>> +	print(msg)
>> +	print("".join('=' * len(msg)))
>> +        return
>> +
>>      # print each category separately, so we can clearly see what's used by DPDK
>> -    display_devices("%s devices using DPDK-compatible driver" % device_name,
>> -                    dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
>> -    display_devices("%s devices using kernel driver" % device_name, kernel_drv,
>> -                    "if=%(Interface)s drv=%(Driver_str)s "
>> -                    "unused=%(Module_str)s %(Active)s")
>> -    display_devices("Other %s devices" % device_name, no_drv,
>> -                    "unused=%(Module_str)s")
>> +    if len(dpdk_drv) != 0:
>> +        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:
>> +        display_devices("%s devices using kernel driver" % device_name, kernel_drv,
>> +                        "if=%(Interface)s drv=%(Driver_str)s "
>> +                        "unused=%(Module_str)s %(Active)s")
>> +    if len(no_drv) != 0:
>> +        display_devices("Other %s devices" % device_name, no_drv,
>> +                        "unused=%(Module_str)s")
>>    def show_status():
>>      '''Function called when the script is passed the "--status" option.
> 
> 
> I REALLY like this patch. It makes the dpdk-devbind output MUCH more readable!
> 

I even modified my version of dpdk-devbind to do just that as it keep scrolling off the screen. I was going to get around to sending a patch. :-)

The output should be a compressed as possible, to me even the ‘=======‘ lines are not required if you indented the information lines by a couple spaces. But that does not need to be done in this patch.

> Reviewed-by: David Hunt <david.hunt@intel.com>

Regards,
Keith
  
Thomas Monjalon Nov. 18, 2018, 11:13 p.m. UTC | #3
13/11/2018 17:42, Anatoly Burakov:
> --- a/usertools/dpdk-devbind.py
> +++ b/usertools/dpdk-devbind.py
> +    n_devs = len(dpdk_drv) + len(kernel_drv) + len(no_drv)
> +
> +    # don't bother displaying anything if there are no devices
> +    if n_devs == 0:
> +        msg = "No '%s' devices detected" % device_name
> +	print("")
> +	print(msg)
> +	print("".join('=' * len(msg)))
> +        return
> +

Indentation is wrong here:
	TabError: inconsistent use of tabs and spaces in indentation
  
Anatoly Burakov Nov. 19, 2018, 10:03 a.m. UTC | #4
On 18-Nov-18 11:13 PM, Thomas Monjalon wrote:
> 13/11/2018 17:42, Anatoly Burakov:
>> --- a/usertools/dpdk-devbind.py
>> +++ b/usertools/dpdk-devbind.py
>> +    n_devs = len(dpdk_drv) + len(kernel_drv) + len(no_drv)
>> +
>> +    # don't bother displaying anything if there are no devices
>> +    if n_devs == 0:
>> +        msg = "No '%s' devices detected" % device_name
>> +	print("")
>> +	print(msg)
>> +	print("".join('=' * len(msg)))
>> +        return
>> +
> 
> Indentation is wrong here:
> 	TabError: inconsistent use of tabs and spaces in indentation
> 

Oops, auto indentation in my editor strikes again... i'll submit a v2.
  

Patch

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 7d564634c..9f190e227 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -546,14 +546,27 @@  def show_device_status(devices_type, device_name):
             else:
                 kernel_drv.append(devices[d])
 
+    n_devs = len(dpdk_drv) + len(kernel_drv) + len(no_drv)
+
+    # don't bother displaying anything if there are no devices
+    if n_devs == 0:
+        msg = "No '%s' devices detected" % device_name
+	print("")
+	print(msg)
+	print("".join('=' * len(msg)))
+        return
+
     # print each category separately, so we can clearly see what's used by DPDK
-    display_devices("%s devices using DPDK-compatible driver" % device_name,
-                    dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
-    display_devices("%s devices using kernel driver" % device_name, kernel_drv,
-                    "if=%(Interface)s drv=%(Driver_str)s "
-                    "unused=%(Module_str)s %(Active)s")
-    display_devices("Other %s devices" % device_name, no_drv,
-                    "unused=%(Module_str)s")
+    if len(dpdk_drv) != 0:
+        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:
+        display_devices("%s devices using kernel driver" % device_name, kernel_drv,
+                        "if=%(Interface)s drv=%(Driver_str)s "
+                        "unused=%(Module_str)s %(Active)s")
+    if len(no_drv) != 0:
+        display_devices("Other %s devices" % device_name, no_drv,
+                        "unused=%(Module_str)s")
 
 def show_status():
     '''Function called when the script is passed the "--status" option.