usertools: fix pmdinfo parsing

Message ID 20201103183906.8088-1-david.marchand@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series usertools: fix pmdinfo parsing |

Checks

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

Commit Message

David Marchand Nov. 3, 2020, 6:39 p.m. UTC
  This script was using the librte_pmd prefix has a filter to follow
DT_NEEDED entries.
Now that we changed the driver names, update this heuristic with an
explicit list of device classes.

Fixes: a20b2c01a7a1 ("build: standardize component names and defines")

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 usertools/dpdk-pmdinfo.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Robin Jarry Nov. 3, 2020, 7:27 p.m. UTC | #1
2020-11-03, David Marchand:
> This script was using the librte_pmd prefix has a filter to follow
> DT_NEEDED entries.
> Now that we changed the driver names, update this heuristic with an
> explicit list of device classes.
> 
> Fixes: a20b2c01a7a1 ("build: standardize component names and defines")
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  usertools/dpdk-pmdinfo.py | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
> index 1661982791..687a9fd032 100755
> --- a/usertools/dpdk-pmdinfo.py
> +++ b/usertools/dpdk-pmdinfo.py
> @@ -450,7 +450,10 @@ def process_dt_needed_entries(self):
>          for tag in dynsec.iter_tags():
>              # pyelftools may return byte-strings, force decode them
>              if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
> -                if 'librte_pmd' in force_unicode(tag.needed):
> +                words = force_unicode(tag.needed).split('_')
> +                if words and len(words) >= 3 and words[0] == 'librte' and \
> +                   words[1] in ['baseband', 'compress', 'crypto', 'event',
> +                                'net', 'raw', 'regex', 'vdpa']:

This code is already ugly and I don't have much better to suggest...

Acked-by: Robin Jarry <robin.jarry@6wind.com>
  
David Marchand Nov. 3, 2020, 8:20 p.m. UTC | #2
On Tue, Nov 3, 2020 at 8:27 PM Robin Jarry <robin.jarry@6wind.com> wrote:
> 2020-11-03, David Marchand:
> > This script was using the librte_pmd prefix has a filter to follow

as*

> > DT_NEEDED entries.
> > Now that we changed the driver names, update this heuristic with an
> > explicit list of device classes.
> >
> > Fixes: a20b2c01a7a1 ("build: standardize component names and defines")
> >
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
> >  usertools/dpdk-pmdinfo.py | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
> > index 1661982791..687a9fd032 100755
> > --- a/usertools/dpdk-pmdinfo.py
> > +++ b/usertools/dpdk-pmdinfo.py
> > @@ -450,7 +450,10 @@ def process_dt_needed_entries(self):
> >          for tag in dynsec.iter_tags():
> >              # pyelftools may return byte-strings, force decode them
> >              if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
> > -                if 'librte_pmd' in force_unicode(tag.needed):
> > +                words = force_unicode(tag.needed).split('_')
> > +                if words and len(words) >= 3 and words[0] == 'librte' and \
> > +                   words[1] in ['baseband', 'compress', 'crypto', 'event',
> > +                                'net', 'raw', 'regex', 'vdpa']:
>
> This code is already ugly and I don't have much better to suggest...

Less ugly with a regular expression?

if re.match(r"^librte_(baseband|compress|crypto|event|net|raw|regex|vdpa)_",
            force_unicode(tag.needed)):
  
Stephen Hemminger Nov. 3, 2020, 11:54 p.m. UTC | #3
On Tue, 3 Nov 2020 21:20:43 +0100
David Marchand <david.marchand@redhat.com> wrote:

> On Tue, Nov 3, 2020 at 8:27 PM Robin Jarry <robin.jarry@6wind.com> wrote:
> > 2020-11-03, David Marchand:  
> > > This script was using the librte_pmd prefix has a filter to follow  
> 
> as*
> 
> > > DT_NEEDED entries.
> > > Now that we changed the driver names, update this heuristic with an
> > > explicit list of device classes.
> > >
> > > Fixes: a20b2c01a7a1 ("build: standardize component names and defines")
> > >
> > > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > > ---
> > >  usertools/dpdk-pmdinfo.py | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
> > > index 1661982791..687a9fd032 100755
> > > --- a/usertools/dpdk-pmdinfo.py
> > > +++ b/usertools/dpdk-pmdinfo.py
> > > @@ -450,7 +450,10 @@ def process_dt_needed_entries(self):
> > >          for tag in dynsec.iter_tags():
> > >              # pyelftools may return byte-strings, force decode them
> > >              if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
> > > -                if 'librte_pmd' in force_unicode(tag.needed):
> > > +                words = force_unicode(tag.needed).split('_')
> > > +                if words and len(words) >= 3 and words[0] == 'librte' and \
> > > +                   words[1] in ['baseband', 'compress', 'crypto', 'event',
> > > +                                'net', 'raw', 'regex', 'vdpa']:  
> >
> > This code is already ugly and I don't have much better to suggest...  
> 
> Less ugly with a regular expression?
> 
> if re.match(r"^librte_(baseband|compress|crypto|event|net|raw|regex|vdpa)_",
>             force_unicode(tag.needed)):
> 
> 

I prefer the list approach, much less error prone.
The code would read better if the list of drivers was in a variable
instead of a long line of code and the string processing was done separate from
the test.
Something like
                   drivers = ['baseband', 'compress'...
                   prefix = 'librte_pmd'
		   name = force_unicode(tag.needed)
                   if name.startswith(prefix):
                       suffix = name[len(prefix):]
                       if suffx in drivers:
  
Olivier Matz Nov. 4, 2020, 8:04 a.m. UTC | #4
On Tue, Nov 03, 2020 at 03:54:39PM -0800, Stephen Hemminger wrote:
> On Tue, 3 Nov 2020 21:20:43 +0100
> David Marchand <david.marchand@redhat.com> wrote:
> 
> > On Tue, Nov 3, 2020 at 8:27 PM Robin Jarry <robin.jarry@6wind.com> wrote:
> > > 2020-11-03, David Marchand:  
> > > > This script was using the librte_pmd prefix has a filter to follow  
> > 
> > as*
> > 
> > > > DT_NEEDED entries.
> > > > Now that we changed the driver names, update this heuristic with an
> > > > explicit list of device classes.
> > > >
> > > > Fixes: a20b2c01a7a1 ("build: standardize component names and defines")
> > > >
> > > > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > > > ---
> > > >  usertools/dpdk-pmdinfo.py | 5 ++++-
> > > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
> > > > index 1661982791..687a9fd032 100755
> > > > --- a/usertools/dpdk-pmdinfo.py
> > > > +++ b/usertools/dpdk-pmdinfo.py
> > > > @@ -450,7 +450,10 @@ def process_dt_needed_entries(self):
> > > >          for tag in dynsec.iter_tags():
> > > >              # pyelftools may return byte-strings, force decode them
> > > >              if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
> > > > -                if 'librte_pmd' in force_unicode(tag.needed):
> > > > +                words = force_unicode(tag.needed).split('_')
> > > > +                if words and len(words) >= 3 and words[0] == 'librte' and \
> > > > +                   words[1] in ['baseband', 'compress', 'crypto', 'event',
> > > > +                                'net', 'raw', 'regex', 'vdpa']:  
> > >
> > > This code is already ugly and I don't have much better to suggest...  
> > 
> > Less ugly with a regular expression?
> > 
> > if re.match(r"^librte_(baseband|compress|crypto|event|net|raw|regex|vdpa)_",
> >             force_unicode(tag.needed)):
> > 
> > 
> 
> I prefer the list approach, much less error prone.
> The code would read better if the list of drivers was in a variable
> instead of a long line of code and the string processing was done separate from
> the test.
> Something like
>                    drivers = ['baseband', 'compress'...
>                    prefix = 'librte_pmd'
> 		   name = force_unicode(tag.needed)
>                    if name.startswith(prefix):
>                        suffix = name[len(prefix):]
>                        if suffx in drivers:
> 
> 
>                           

I agree with Stephen that the list approach and an intermediate
variable is clearer than regex. However, I'd keep the split() as
in the original patch.
  
Robin Jarry Nov. 4, 2020, 8:06 a.m. UTC | #5
2020-11-03, David Marchand:
> Less ugly with a regular expression?
> 
> if re.match(r"^librte_(baseband|compress|crypto|event|net|raw|regex|vdpa)_",
>             force_unicode(tag.needed)):

No, that's worse :D

As Stephen said, maybe it would be more readable if the list of
supported classes were in a constant somewhere.

  DRIVER_CLASSES = (
      'baseband',
      'compress',
      'crypto',
      'event',
      'net',
      'raw,
      'regex',
      'vdpa',
  )
  

Patch

diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
index 1661982791..687a9fd032 100755
--- a/usertools/dpdk-pmdinfo.py
+++ b/usertools/dpdk-pmdinfo.py
@@ -450,7 +450,10 @@  def process_dt_needed_entries(self):
         for tag in dynsec.iter_tags():
             # pyelftools may return byte-strings, force decode them
             if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
-                if 'librte_pmd' in force_unicode(tag.needed):
+                words = force_unicode(tag.needed).split('_')
+                if words and len(words) >= 3 and words[0] == 'librte' and \
+                   words[1] in ['baseband', 'compress', 'crypto', 'event',
+                                'net', 'raw', 'regex', 'vdpa']:
                     library = search_file(force_unicode(tag.needed),
                                           runpath + ":" + ldlibpath +
                                           ":/usr/lib64:/lib64:/usr/lib:/lib")