ia64/xen-unstable

changeset 1121:a39bbe7cddc4

bitkeeper revision 1.747 (403b7cf86JDQU8_ljAm9SqJGvsVF4w)

Physical hardware info dom0 op.
author mwilli2@equilibrium.research.intel-research.net
date Tue Feb 24 16:34:00 2004 +0000 (2004-02-24)
parents 205bdb40d5e6
children 6e6ef033e4fc
files .rootkeys tools/examples/xc_physinfo.py tools/xc/lib/xc.h tools/xc/lib/xc_misc.c tools/xc/py/Xc.c xen/common/dom0_ops.c xen/include/hypervisor-ifs/dom0_ops.h
line diff
     1.1 --- a/.rootkeys	Tue Feb 24 15:18:52 2004 +0000
     1.2 +++ b/.rootkeys	Tue Feb 24 16:34:00 2004 +0000
     1.3 @@ -48,6 +48,7 @@ 401d7e16NoWaBGC1RXbBcqAOr5Uaag tools/exa
     1.4  40278d91ZjLhxdjjrGe8HEdwHLj5xQ tools/examples/netbsd
     1.5  401d7e16NpnVrFSsR7lKKKfTwCYvWA tools/examples/xc_dom_control.py
     1.6  401d7e16RJj-lbtsVEjua6HYAIiKiA tools/examples/xc_dom_create.py
     1.7 +403b7cf7J7FsSSoEPGhx6gXR4pIdZg tools/examples/xc_physinfo.py
     1.8  401d7e16X4iojyKopo_j63AyzYZd2A tools/examples/xc_vd_tool.py
     1.9  40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/xendomains
    1.10  3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/examples/xc_physinfo.py	Tue Feb 24 16:34:00 2004 +0000
     2.3 @@ -0,0 +1,20 @@
     2.4 +#!/usr/bin/env python
     2.5 +
     2.6 +# Get information about the physical host machine
     2.7 +
     2.8 +import Xc
     2.9 +
    2.10 +xc = Xc.new()
    2.11 +
    2.12 +info = xc.physinfo()
    2.13 +
    2.14 +fmt_info = [ ( 'CPU cores', info['cores']),
    2.15 +             ('Hyperthreads per core', info['ht_per_core']),
    2.16 +             ('CPU Speed (MHz)', info['cpu_khz'] / 1000),
    2.17 +             ('Total physical mem (MB)', info['total_pages'] / 256),
    2.18 +             ('Free physical mem (MB)', info['free_pages'] / 256) ]
    2.19 +      
    2.20 +
    2.21 +for (item, val) in fmt_info:
    2.22 +    print "%-23s" % item, ':', val
    2.23 +
     3.1 --- a/tools/xc/lib/xc.h	Tue Feb 24 15:18:52 2004 +0000
     3.2 +++ b/tools/xc/lib/xc.h	Tue Feb 24 16:34:00 2004 +0000
     3.3 @@ -118,6 +118,14 @@ typedef struct {
     3.4      u64            nr_sectors;
     3.5  } xc_vbdextent_t;
     3.6  
     3.7 +typedef struct {
     3.8 +    int ht_per_core;
     3.9 +    int cores;
    3.10 +    unsigned long total_pages;
    3.11 +    unsigned long free_pages;
    3.12 +    unsigned long cpu_khz;
    3.13 +} xc_physinfo_t;
    3.14 +
    3.15  int xc_vbd_create(int xc_handle,
    3.16                    u64 domid, 
    3.17                    unsigned short vbdid, 
    3.18 @@ -153,5 +161,7 @@ int xc_readconsolering(int xc_handle,
    3.19                         unsigned int max_chars, 
    3.20                         int clear);
    3.21  
    3.22 +int xc_physinfo(int xc_handle,
    3.23 +		xc_physinfo_t *info);
    3.24  
    3.25  #endif /* __XC_H__ */
     4.1 --- a/tools/xc/lib/xc_misc.c	Tue Feb 24 15:18:52 2004 +0000
     4.2 +++ b/tools/xc/lib/xc_misc.c	Tue Feb 24 16:34:00 2004 +0000
     4.3 @@ -46,3 +46,25 @@ int xc_readconsolering(int xc_handle,
     4.4      return ret;
     4.5  }    
     4.6  
     4.7 +
     4.8 +int xc_physinfo(int xc_handle,
     4.9 +		xc_physinfo_t *put_info)
    4.10 +{
    4.11 +    int ret;
    4.12 +    dom0_op_t op;
    4.13 +    dom0_physinfo_t *got_info = &op.u.physinfo;
    4.14 +    
    4.15 +    op.cmd = DOM0_PHYSINFO;
    4.16 +    op.interface_version = DOM0_INTERFACE_VERSION;
    4.17 +
    4.18 +    if((ret = do_dom0_op(xc_handle, &op))) return ret;
    4.19 +
    4.20 +    put_info->ht_per_core = got_info->ht_per_core;
    4.21 +    put_info->cores       = got_info->cores;
    4.22 +    put_info->total_pages = got_info->total_pages;
    4.23 +    put_info->free_pages  = got_info->free_pages;
    4.24 +    put_info->cpu_khz     = got_info->cpu_khz;
    4.25 +
    4.26 +    return 0;
    4.27 +}
    4.28 +
     5.1 --- a/tools/xc/py/Xc.c	Tue Feb 24 15:18:52 2004 +0000
     5.2 +++ b/tools/xc/py/Xc.c	Tue Feb 24 16:34:00 2004 +0000
     5.3 @@ -788,6 +788,34 @@ static PyObject *pyxc_readconsolering(Py
     5.4      return PyString_FromStringAndSize(str, (ret < 0) ? 0 : ret);
     5.5  }
     5.6  
     5.7 +static PyObject *pyxc_physinfo(PyObject *self,
     5.8 +			       PyObject *args,
     5.9 +			       PyObject *kwds)
    5.10 +{
    5.11 +    XcObject *xc = (XcObject *)self;
    5.12 +    PyObject *ret_obj;
    5.13 +    int xc_ret;
    5.14 +    xc_physinfo_t info;
    5.15 +    
    5.16 +    xc_ret = xc_physinfo(xc->xc_handle, &info);
    5.17 +
    5.18 +    if(!xc_ret)
    5.19 +    {
    5.20 +        ret_obj = Py_BuildValue("{s:i,s:i,s:l,s:l,s:l}",
    5.21 +                                "ht_per_core", info.ht_per_core,
    5.22 +                                "cores",       info.cores,
    5.23 +                                "total_pages", info.total_pages,
    5.24 +                                "free_pages",  info.free_pages,
    5.25 +                                "cpu_khz",     info.cpu_khz);
    5.26 +    }
    5.27 +    else
    5.28 +    {
    5.29 +        ret_obj = Py_BuildValue(""); /* None */
    5.30 +    }
    5.31 +    
    5.32 +    return ret_obj;
    5.33 +}
    5.34 +
    5.35  static PyMethodDef pyxc_methods[] = {
    5.36      { "domain_create", 
    5.37        (PyCFunction)pyxc_domain_create, 
    5.38 @@ -1010,6 +1038,13 @@ static PyMethodDef pyxc_methods[] = {
    5.39        " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
    5.40        "Returns: [str] string is empty on failure.\n" },
    5.41  
    5.42 +    { "physinfo",
    5.43 +      (PyCFunction)pyxc_physinfo,
    5.44 +      METH_VARARGS, "\n"
    5.45 +      "Get information about the physical host machine\n"
    5.46 +      "Returns [dict]: information about the hardware"
    5.47 +      "        [None]: on failure.\n" },
    5.48 +
    5.49      { NULL, NULL, 0, NULL }
    5.50  };
    5.51  
     6.1 --- a/xen/common/dom0_ops.c	Tue Feb 24 15:18:52 2004 +0000
     6.2 +++ b/xen/common/dom0_ops.c	Tue Feb 24 16:34:00 2004 +0000
     6.3 @@ -451,8 +451,31 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
     6.4                           	op->u.readconsole.count,
     6.5  				op->u.readconsole.cmd); 
     6.6      }
     6.7 -    break;    
     6.8 +    break;
     6.9 +
    6.10 +    case DOM0_PHYSINFO:
    6.11 +    {
    6.12 +        extern int phys_proc_id[];
    6.13 +        extern unsigned long cpu_khz;
    6.14 +
    6.15 +        dom0_physinfo_t *pi = &op->u.physinfo;
    6.16 +
    6.17 +        int old_id = phys_proc_id[0];
    6.18 +        int ht = 0;
    6.19  
    6.20 +        while( ( ht < smp_num_cpus ) && ( phys_proc_id[ht] == old_id ) ) ht++;
    6.21 +
    6.22 +        pi->ht_per_core = ht;
    6.23 +        pi->cores       = smp_num_cpus / pi->ht_per_core;
    6.24 +        pi->total_pages = max_page;
    6.25 +        pi->free_pages  = free_pfns;
    6.26 +        pi->cpu_khz     = cpu_khz;
    6.27 +
    6.28 +        copy_to_user(u_dom0_op, op, sizeof(*op));
    6.29 +        ret = 0;
    6.30 +    }
    6.31 +    break;
    6.32 +    
    6.33      default:
    6.34          ret = -ENOSYS;
    6.35  
     7.1 --- a/xen/include/hypervisor-ifs/dom0_ops.h	Tue Feb 24 15:18:52 2004 +0000
     7.2 +++ b/xen/include/hypervisor-ifs/dom0_ops.h	Tue Feb 24 16:34:00 2004 +0000
     7.3 @@ -17,8 +17,7 @@
     7.4   * This makes sure that old versions of dom0 tools will stop working in a
     7.5   * well-defined way (rather than crashing the machine, for instance).
     7.6   */
     7.7 -#define DOM0_INTERFACE_VERSION   0xAAAA0006
     7.8 -
     7.9 +#define DOM0_INTERFACE_VERSION   0xAAAA0007
    7.10  
    7.11  /*
    7.12   * The following is all CPU context. Note that the i387_ctxt block is filled 
    7.13 @@ -218,6 +217,19 @@ typedef struct dom0_gettbufs_st
    7.14    unsigned long phys_addr;
    7.15  } dom0_gettbufs_t;
    7.16  
    7.17 +/*
    7.18 + * Get physical information about the host machine
    7.19 + */
    7.20 +#define DOM0_PHYSINFO         22
    7.21 +typedef struct dom0_physinfo_st
    7.22 +{
    7.23 +    int ht_per_core;
    7.24 +    int cores;
    7.25 +    unsigned long cpu_khz;
    7.26 +    unsigned long total_pages;
    7.27 +    unsigned long free_pages;
    7.28 +} dom0_physinfo_t;
    7.29 +
    7.30  typedef struct dom0_op_st
    7.31  {
    7.32      unsigned long cmd;
    7.33 @@ -241,6 +253,7 @@ typedef struct dom0_op_st
    7.34  	dom0_readconsole_t	readconsole;
    7.35  	dom0_pincpudomain_t     pincpudomain;
    7.36          dom0_gettbufs_t         gettbufs;
    7.37 +        dom0_physinfo_t         physinfo;
    7.38      } u;
    7.39  } dom0_op_t;
    7.40