diff mbox series

[2/5,V2] rteval: Construct a 'model name' on architectures that don't have one

Message ID 20210912154538.255217-1-jkacur@redhat.com
State New
Headers show
Series None | expand

Commit Message

John Kacur Sept. 12, 2021, 3:45 p.m. UTC
This is based on an idea from Punit Agrawal <punit1.agrawal@toshiba.co.jp>

On architectures that lack 'model name' in /proc/cpuinfo
create 'model name' Unknown when creating the per core dictionaries
in cpuinfo

For arm, we can construct the 'model name' from the
'CPU implementer'
'CPU architecture'
'CPU variant'
'CPU part'
'CPU revision'

Suggested-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/misc.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Punit Agrawal Sept. 13, 2021, 2:53 a.m. UTC | #1
Hi John,

John Kacur <jkacur@redhat.com> writes:

> This is based on an idea from Punit Agrawal <punit1.agrawal@toshiba.co.jp>

>

> On architectures that lack 'model name' in /proc/cpuinfo

> create 'model name' Unknown when creating the per core dictionaries

> in cpuinfo

>

> For arm, we can construct the 'model name' from the

> 'CPU implementer'

> 'CPU architecture'

> 'CPU variant'

> 'CPU part'

> 'CPU revision'

>

> Suggested-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>

> Signed-off-by: John Kacur <jkacur@redhat.com>

> ---

>  rteval/misc.py | 21 +++++++++++++++++++++

>  1 file changed, 21 insertions(+)

>

> diff --git a/rteval/misc.py b/rteval/misc.py

> index 0dd361ff19fd..c1d2a972430d 100644

> --- a/rteval/misc.py

> +++ b/rteval/misc.py

> @@ -77,6 +77,27 @@ def cpuinfo():

>              info[core] = {}

>              continue

>          info[core][key] = val

> +

> +    for (core, pcdict) in info.items():

> +        if not 'model name' in pcdict:

> +            # On Arm CPU implementer is present

> +            # Construct the model_name from the following fields

> +            if 'CPU implementer' in pcdict:

> +                model_name = [pcdict.get('CPU implementer')]

> +                model_name.append(pcdict.get('CPU architecture'))

> +                model_name.append(pcdict.get('CPU variant'))

> +                model_name.append(pcdict.get('CPU part'))

> +                model_name.append(pcdict.get('CPU revision', ''))


Is there a reason to use an empty default for "CPU revision" but not for
the other components? Maybe a left-over from original patch.

> +

> +                # If a list item is None, remove it

> +                model_name = [name for name in model_name if name]

> +

> +                # Convert the model_name list into a string

> +                model_name = " ".join(model_name)

> +                pcdict['model name'] = model_name

> +            else:

> +                pcdict['model name'] = 'Unknown'

> +

>      return info

>  

>  if __name__ == "__main__":


With the above comment addressed, fwiw -

Reviewed-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>

Tested-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>


Thanks,
Punit
John Kacur Sept. 13, 2021, 12:37 p.m. UTC | #2
On Mon, 13 Sep 2021, Punit Agrawal wrote:

> Hi John,

> 

> John Kacur <jkacur@redhat.com> writes:

> 

> > This is based on an idea from Punit Agrawal <punit1.agrawal@toshiba.co.jp>

> >

> > On architectures that lack 'model name' in /proc/cpuinfo

> > create 'model name' Unknown when creating the per core dictionaries

> > in cpuinfo

> >

> > For arm, we can construct the 'model name' from the

> > 'CPU implementer'

> > 'CPU architecture'

> > 'CPU variant'

> > 'CPU part'

> > 'CPU revision'

> >

> > Suggested-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>

> > Signed-off-by: John Kacur <jkacur@redhat.com>

> > ---

> >  rteval/misc.py | 21 +++++++++++++++++++++

> >  1 file changed, 21 insertions(+)

> >

> > diff --git a/rteval/misc.py b/rteval/misc.py

> > index 0dd361ff19fd..c1d2a972430d 100644

> > --- a/rteval/misc.py

> > +++ b/rteval/misc.py

> > @@ -77,6 +77,27 @@ def cpuinfo():

> >              info[core] = {}

> >              continue

> >          info[core][key] = val

> > +

> > +    for (core, pcdict) in info.items():

> > +        if not 'model name' in pcdict:

> > +            # On Arm CPU implementer is present

> > +            # Construct the model_name from the following fields

> > +            if 'CPU implementer' in pcdict:

> > +                model_name = [pcdict.get('CPU implementer')]

> > +                model_name.append(pcdict.get('CPU architecture'))

> > +                model_name.append(pcdict.get('CPU variant'))

> > +                model_name.append(pcdict.get('CPU part'))

> > +                model_name.append(pcdict.get('CPU revision', ''))

> 

> Is there a reason to use an empty default for "CPU revision" but not for

> the other components? Maybe a left-over from original patch.


Not sure of the origin of that typo, but thanks for catching it, removing.

> 

> > +

> > +                # If a list item is None, remove it

> > +                model_name = [name for name in model_name if name]

> > +

> > +                # Convert the model_name list into a string

> > +                model_name = " ".join(model_name)

> > +                pcdict['model name'] = model_name

> > +            else:

> > +                pcdict['model name'] = 'Unknown'

> > +

> >      return info

> >  

> >  if __name__ == "__main__":

> 

> With the above comment addressed, fwiw -

> 

> Reviewed-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>

> Tested-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>

> 

> Thanks,

> Punit

>
diff mbox series

Patch

diff --git a/rteval/misc.py b/rteval/misc.py
index 0dd361ff19fd..c1d2a972430d 100644
--- a/rteval/misc.py
+++ b/rteval/misc.py
@@ -77,6 +77,27 @@  def cpuinfo():
             info[core] = {}
             continue
         info[core][key] = val
+
+    for (core, pcdict) in info.items():
+        if not 'model name' in pcdict:
+            # On Arm CPU implementer is present
+            # Construct the model_name from the following fields
+            if 'CPU implementer' in pcdict:
+                model_name = [pcdict.get('CPU implementer')]
+                model_name.append(pcdict.get('CPU architecture'))
+                model_name.append(pcdict.get('CPU variant'))
+                model_name.append(pcdict.get('CPU part'))
+                model_name.append(pcdict.get('CPU revision', ''))
+
+                # If a list item is None, remove it
+                model_name = [name for name in model_name if name]
+
+                # Convert the model_name list into a string
+                model_name = " ".join(model_name)
+                pcdict['model name'] = model_name
+            else:
+                pcdict['model name'] = 'Unknown'
+
     return info
 
 if __name__ == "__main__":