[Kimchi-devel] [PATCH] Host info: Add support to Power (ppc).

Aline Manera alinefm at linux.vnet.ibm.com
Tue Jun 17 19:30:43 UTC 2014


On 06/16/2014 04:53 PM, Paulo Vital wrote:
> Add support to get the correct information of Power's CPU hardware,
> due to differences between the content of Power's /proc/cpuinfo and x86's
> /proc/cpuinfo.
>
> Also, add IBM PowerKVM information as supported distro.
>
> Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/host.py | 49 ++++++++++++++++++++++++++++++++++++++++++------
>   1 file changed, 43 insertions(+), 6 deletions(-)
>
> diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
> index 5844f4b..5716487 100644
> --- a/src/kimchi/model/host.py
> +++ b/src/kimchi/model/host.py
> @@ -50,17 +50,54 @@ class HostModel(object):
>           self.task = TaskModel(**kargs)
>           self.host_info = self._get_host_info()
>
> -    def _get_host_info(self):
> -        res = {}
> +    def _get_ppc_cpu_info(self):
> +        i = 0
>           with open('/proc/cpuinfo') as f:
>               for line in f.xreadlines():
> -                if "model name" in line:
> -                    res['cpu'] = line.split(':')[1].strip()
> -                    break
> +                if 'cpu' in line:
> +                    # Parse CPU information
> +                    cpu_info = line.split(':')[1].strip()
> +                    cpu_info = cpu_info.split('(')[0].strip()
> +                    i = i + 1
> +                if 'revision' in line:
> +                    # Parse CPU's revision information
> +                    rev_info = line.split(':')[1].strip()
> +                    rev_info = rev_info.split('(')[0].strip()
> +                    i = i + 1
> +                if 'clock' in line:
> +                    # Parse CPU's clock information
> +                    clock_info = line.split(':')[1].strip()
> +                    clock_info = clock_info.split('MHz')[0].strip()
> +                    clock_info = float(clock_info) / 1000
> +                    i = i + 1
> +
> +                # Power machines show, for each cpu/core, a block with all
> +                # cpu information. Here we control the scan of the necessary
> +                # information (1st block provides everything), skipping the
> +                # with/for loop when find all information.
> +                if i == 3:
> +                    return "%s (%s) @ %s GHz" % (cpu_info, rev_info, clock_info)
> +
> +        return ""
> +

There are some duplicated code
What about?

res = {}
with open('/proc/cpuinfo') as f:
     for line in f.xreadlines():
         for key in ['cpu', 'revision', 'clock']:
             if key in line:
                 info = line.split(':')[1].strip()
                 if key == 'clock':
                     value = float(info.split('MHz')[0].strip()) / 1000

                 else:
                     value = info.split('(')[0].strip()
                 res[key] = value

if len(res.keys()) == 3:
     return "%(cpu)s (%(revision)s @ %(clock)s GHz" % res

return ""

> +    def _get_host_info(self):
> +        res = {}
> +        if platform.machine().startswith('ppc'):
> +            res['cpu'] = self._get_ppc_cpu_info()
> +        else:
> +            with open('/proc/cpuinfo') as f:
> +                for line in f.xreadlines():
> +                    if "model name" in line:
> +                        res['cpu'] = line.split(':')[1].strip()
> +                        break
>
>           res['memory'] = psutil.TOTAL_PHYMEM
> +
> +        # Include IBM PowerKVM name to supported distro names
> +        _sup_distros = platform._supported_dists + ('ibm_powerkvm',)
>           # 'fedora' '17' 'Beefy Miracle'
> -        distro, version, codename = platform.linux_distribution()
> +        distro, version, codename = platform.linux_distribution(
> +            supported_dists=_sup_distros)
>           res['os_distro'] = distro
>           res['os_version'] = version
>           res['os_codename'] = unicode(codename, "utf-8")




More information about the Kimchi-devel mailing list