ia64/xen-unstable

changeset 19326:e261fa202e39

xend: Add support for cpuinfo data on Solaris

Signed-off-by: Russell Blaine <russell.blaine@sun.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 12 10:57:44 2009 +0000 (2009-03-12)
parents fc24bd05571e
children 3118041f2259
files tools/python/xen/xend/osdep.py
line diff
     1.1 --- a/tools/python/xen/xend/osdep.py	Thu Mar 12 10:57:19 2009 +0000
     1.2 +++ b/tools/python/xen/xend/osdep.py	Thu Mar 12 10:57:44 2009 +0000
     1.3 @@ -18,6 +18,7 @@
     1.4  # Use is subject to license terms.
     1.5  
     1.6  import os
     1.7 +import commands
     1.8  
     1.9  _scripts_dir = {
    1.10      "Linux": "/etc/xen/scripts",
    1.11 @@ -142,7 +143,53 @@ def _linux_get_cpuinfo():
    1.12      finally:
    1.13          f.close()
    1.14  
    1.15 +def _solaris_get_cpuinfo():
    1.16 +    cpuinfo = {}
    1.17 +
    1.18 +    # call kstat to extrace specific cpu_info output
    1.19 +    cmd = "/usr/bin/kstat -p -c misc -m cpu_info"
    1.20 +    kstatoutput = commands.getoutput (cmd)
    1.21 +
    1.22 +    # walk each line
    1.23 +    for kstatline in kstatoutput.split('\n'):
    1.24 +
    1.25 +        # split the line on 
    1.26 +        # module:cpu #:module#:name value
    1.27 +        (module, cpunum, combo, namevalue) = kstatline.split (":")
    1.28 +
    1.29 +        # check to see if this cpunum is already a key.  If not,
    1.30 +        # initialize an empty hash table
    1.31 +        if not cpuinfo.has_key (int(cpunum)):
    1.32 +            cpuinfo[int(cpunum)] = {}
    1.33 +
    1.34 +        # split the namevalue output on whitespace
    1.35 +        data = namevalue.split()
    1.36 +
    1.37 +        # the key will be data[0]
    1.38 +        key = data[0]
    1.39 +
    1.40 +        # check the length of the data list.  If it's larger than
    1.41 +        # 2, join the rest of the list together with a space.
    1.42 +        # Otherwise, value is just data[1]
    1.43 +        if len (data) > 2:
    1.44 +            value = ' '.join (data[1:])
    1.45 +        else:
    1.46 +            value = data[1]
    1.47 +
    1.48 +        # add this key/value pair to the cpuhash
    1.49 +        cpuinfo[int(cpunum)][key] = value
    1.50 +    
    1.51 +    # Translate Solaris tokens into what Xend expects
    1.52 +    for key in cpuinfo.keys():
    1.53 +        cpuinfo[key]["flags"] = ""
    1.54 +        cpuinfo[key]["model name"] = cpuinfo[key]["brand"]
    1.55 +        cpuinfo[key]["cpu MHz"] = cpuinfo[key]["clock_MHz"]
    1.56 +
    1.57 +    # return the hash table
    1.58 +    return cpuinfo
    1.59 +
    1.60  _get_cpuinfo = {
    1.61 +    "SunOS": _solaris_get_cpuinfo
    1.62  }
    1.63  
    1.64  def _get(var, default=None):