ia64/xen-unstable

changeset 14149:50e0616fd012

Added some more fields to host_cpu.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Feb 27 00:37:27 2007 +0000 (2007-02-27)
parents e7b2a282c9e7
children 42dd9055ee1f
files docs/xen-api/xenapi-datamodel.tex tools/libxen/include/xen_host_cpu.h tools/libxen/src/xen_host_cpu.c tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendNode.py
line diff
     1.1 --- a/docs/xen-api/xenapi-datamodel.tex	Mon Feb 26 17:20:36 2007 +0000
     1.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Tue Feb 27 00:37:27 2007 +0000
     1.3 @@ -6278,11 +6278,13 @@ all fields from the object
     1.4  Quals & Field & Type & Description \\
     1.5  \hline
     1.6  $\mathit{RO}_\mathit{run}$ &  {\tt uuid} & string & unique identifier/object reference \\
     1.7 -$\mathit{RO}_\mathit{ins}$ &  {\tt host} & host ref & the host the CPU is in \\
     1.8 -$\mathit{RO}_\mathit{ins}$ &  {\tt number} & int & the number of the physical CPU within the host \\
     1.9 -$\mathit{RO}_\mathit{ins}$ &  {\tt vendor} & string & the vendor of the physical CPU \\
    1.10 -$\mathit{RO}_\mathit{ins}$ &  {\tt speed} & int & the speed of the physical CPU \\
    1.11 -$\mathit{RO}_\mathit{ins}$ &  {\tt modelname} & string & the model name of the physical CPU \\
    1.12 +$\mathit{RO}_\mathit{run}$ &  {\tt host} & host ref & the host the CPU is in \\
    1.13 +$\mathit{RO}_\mathit{run}$ &  {\tt number} & int & the number of the physical CPU within the host \\
    1.14 +$\mathit{RO}_\mathit{run}$ &  {\tt vendor} & string & the vendor of the physical CPU \\
    1.15 +$\mathit{RO}_\mathit{run}$ &  {\tt speed} & int & the speed of the physical CPU \\
    1.16 +$\mathit{RO}_\mathit{run}$ &  {\tt modelname} & string & the model name of the physical CPU \\
    1.17 +$\mathit{RO}_\mathit{run}$ &  {\tt stepping} & string & the stepping of the physical CPU \\
    1.18 +$\mathit{RO}_\mathit{run}$ &  {\tt flags} & string & the flags of the physical CPU \\
    1.19  $\mathit{RO}_\mathit{run}$ &  {\tt utilisation} & float & the current CPU utilisation \\
    1.20  \hline
    1.21  \end{longtable}
    1.22 @@ -6479,6 +6481,70 @@ value of the field
    1.23  \vspace{0.3cm}
    1.24  \vspace{0.3cm}
    1.25  \vspace{0.3cm}
    1.26 +\subsubsection{RPC name:~get\_stepping}
    1.27 +
    1.28 +{\bf Overview:} 
    1.29 +Get the stepping field of the given host\_cpu.
    1.30 +
    1.31 + \noindent {\bf Signature:} 
    1.32 +\begin{verbatim} string get_stepping (session_id s, host_cpu ref self)\end{verbatim}
    1.33 +
    1.34 +
    1.35 +\noindent{\bf Arguments:}
    1.36 +
    1.37 + 
    1.38 +\vspace{0.3cm}
    1.39 +\begin{tabular}{|c|c|p{7cm}|}
    1.40 + \hline
    1.41 +{\bf type} & {\bf name} & {\bf description} \\ \hline
    1.42 +{\tt host\_cpu ref } & self & reference to the object \\ \hline 
    1.43 +
    1.44 +\end{tabular}
    1.45 +
    1.46 +\vspace{0.3cm}
    1.47 +
    1.48 + \noindent {\bf Return Type:} 
    1.49 +{\tt 
    1.50 +string
    1.51 +}
    1.52 +
    1.53 +
    1.54 +value of the field
    1.55 +\vspace{0.3cm}
    1.56 +\vspace{0.3cm}
    1.57 +\vspace{0.3cm}
    1.58 +\subsubsection{RPC name:~get\_flags}
    1.59 +
    1.60 +{\bf Overview:} 
    1.61 +Get the flags field of the given host\_cpu.
    1.62 +
    1.63 + \noindent {\bf Signature:} 
    1.64 +\begin{verbatim} string get_flags (session_id s, host_cpu ref self)\end{verbatim}
    1.65 +
    1.66 +
    1.67 +\noindent{\bf Arguments:}
    1.68 +
    1.69 + 
    1.70 +\vspace{0.3cm}
    1.71 +\begin{tabular}{|c|c|p{7cm}|}
    1.72 + \hline
    1.73 +{\bf type} & {\bf name} & {\bf description} \\ \hline
    1.74 +{\tt host\_cpu ref } & self & reference to the object \\ \hline 
    1.75 +
    1.76 +\end{tabular}
    1.77 +
    1.78 +\vspace{0.3cm}
    1.79 +
    1.80 + \noindent {\bf Return Type:} 
    1.81 +{\tt 
    1.82 +string
    1.83 +}
    1.84 +
    1.85 +
    1.86 +value of the field
    1.87 +\vspace{0.3cm}
    1.88 +\vspace{0.3cm}
    1.89 +\vspace{0.3cm}
    1.90  \subsubsection{RPC name:~get\_utilisation}
    1.91  
    1.92  {\bf Overview:} 
    1.93 @@ -6511,70 +6577,6 @@ value of the field
    1.94  \vspace{0.3cm}
    1.95  \vspace{0.3cm}
    1.96  \vspace{0.3cm}
    1.97 -\subsubsection{RPC name:~create}
    1.98 -
    1.99 -{\bf Overview:} 
   1.100 -Create a new host\_cpu instance, and return its handle.
   1.101 -
   1.102 - \noindent {\bf Signature:} 
   1.103 -\begin{verbatim} (host_cpu ref) create (session_id s, host_cpu record args)\end{verbatim}
   1.104 -
   1.105 -
   1.106 -\noindent{\bf Arguments:}
   1.107 -
   1.108 - 
   1.109 -\vspace{0.3cm}
   1.110 -\begin{tabular}{|c|c|p{7cm}|}
   1.111 - \hline
   1.112 -{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.113 -{\tt host\_cpu record } & args & All constructor arguments \\ \hline 
   1.114 -
   1.115 -\end{tabular}
   1.116 -
   1.117 -\vspace{0.3cm}
   1.118 -
   1.119 - \noindent {\bf Return Type:} 
   1.120 -{\tt 
   1.121 -host\_cpu ref
   1.122 -}
   1.123 -
   1.124 -
   1.125 -reference to the newly created object
   1.126 -\vspace{0.3cm}
   1.127 -\vspace{0.3cm}
   1.128 -\vspace{0.3cm}
   1.129 -\subsubsection{RPC name:~destroy}
   1.130 -
   1.131 -{\bf Overview:} 
   1.132 -Destroy the specified host\_cpu instance.
   1.133 -
   1.134 - \noindent {\bf Signature:} 
   1.135 -\begin{verbatim} void destroy (session_id s, host_cpu ref self)\end{verbatim}
   1.136 -
   1.137 -
   1.138 -\noindent{\bf Arguments:}
   1.139 -
   1.140 - 
   1.141 -\vspace{0.3cm}
   1.142 -\begin{tabular}{|c|c|p{7cm}|}
   1.143 - \hline
   1.144 -{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.145 -{\tt host\_cpu ref } & self & reference to the object \\ \hline 
   1.146 -
   1.147 -\end{tabular}
   1.148 -
   1.149 -\vspace{0.3cm}
   1.150 -
   1.151 - \noindent {\bf Return Type:} 
   1.152 -{\tt 
   1.153 -void
   1.154 -}
   1.155 -
   1.156 -
   1.157 -
   1.158 -\vspace{0.3cm}
   1.159 -\vspace{0.3cm}
   1.160 -\vspace{0.3cm}
   1.161  \subsubsection{RPC name:~get\_by\_uuid}
   1.162  
   1.163  {\bf Overview:} 
     2.1 --- a/tools/libxen/include/xen_host_cpu.h	Mon Feb 26 17:20:36 2007 +0000
     2.2 +++ b/tools/libxen/include/xen_host_cpu.h	Tue Feb 27 00:37:27 2007 +0000
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2006, XenSource Inc.
     2.6 + * Copyright (c) 2006-2007, XenSource Inc.
     2.7   *
     2.8   * This library is free software; you can redistribute it and/or
     2.9   * modify it under the terms of the GNU Lesser General Public
    2.10 @@ -25,8 +25,8 @@
    2.11  
    2.12  
    2.13  /*
    2.14 - * The host_cpu class. 
    2.15 - *  
    2.16 + * The host_cpu class.
    2.17 + * 
    2.18   * A physical CPU.
    2.19   */
    2.20  
    2.21 @@ -68,6 +68,8 @@ typedef struct xen_host_cpu_record
    2.22      char *vendor;
    2.23      int64_t speed;
    2.24      char *modelname;
    2.25 +    char *stepping;
    2.26 +    char *flags;
    2.27      double utilisation;
    2.28  } xen_host_cpu_record;
    2.29  
    2.30 @@ -165,20 +167,6 @@ xen_host_cpu_get_by_uuid(xen_session *se
    2.31  
    2.32  
    2.33  /**
    2.34 - * Create a new host_cpu instance, and return its handle.
    2.35 - */
    2.36 -extern bool
    2.37 -xen_host_cpu_create(xen_session *session, xen_host_cpu *result, xen_host_cpu_record *record);
    2.38 -
    2.39 -
    2.40 -/**
    2.41 - * Destroy the specified host_cpu instance.
    2.42 - */
    2.43 -extern bool
    2.44 -xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu);
    2.45 -
    2.46 -
    2.47 -/**
    2.48   * Get the uuid field of the given host_cpu.
    2.49   */
    2.50  extern bool
    2.51 @@ -221,6 +209,20 @@ xen_host_cpu_get_modelname(xen_session *
    2.52  
    2.53  
    2.54  /**
    2.55 + * Get the stepping field of the given host_cpu.
    2.56 + */
    2.57 +extern bool
    2.58 +xen_host_cpu_get_stepping(xen_session *session, char **result, xen_host_cpu host_cpu);
    2.59 +
    2.60 +
    2.61 +/**
    2.62 + * Get the flags field of the given host_cpu.
    2.63 + */
    2.64 +extern bool
    2.65 +xen_host_cpu_get_flags(xen_session *session, char **result, xen_host_cpu host_cpu);
    2.66 +
    2.67 +
    2.68 +/**
    2.69   * Get the utilisation field of the given host_cpu.
    2.70   */
    2.71  extern bool
     3.1 --- a/tools/libxen/src/xen_host_cpu.c	Mon Feb 26 17:20:36 2007 +0000
     3.2 +++ b/tools/libxen/src/xen_host_cpu.c	Tue Feb 27 00:37:27 2007 +0000
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2006, XenSource Inc.
     3.6 + * Copyright (c) 2006-2007, XenSource Inc.
     3.7   *
     3.8   * This library is free software; you can redistribute it and/or
     3.9   * modify it under the terms of the GNU Lesser General Public
    3.10 @@ -55,6 +55,12 @@ static const struct_member xen_host_cpu_
    3.11          { .key = "modelname",
    3.12            .type = &abstract_type_string,
    3.13            .offset = offsetof(xen_host_cpu_record, modelname) },
    3.14 +        { .key = "stepping",
    3.15 +          .type = &abstract_type_string,
    3.16 +          .offset = offsetof(xen_host_cpu_record, stepping) },
    3.17 +        { .key = "flags",
    3.18 +          .type = &abstract_type_string,
    3.19 +          .offset = offsetof(xen_host_cpu_record, flags) },
    3.20          { .key = "utilisation",
    3.21            .type = &abstract_type_float,
    3.22            .offset = offsetof(xen_host_cpu_record, utilisation) }
    3.23 @@ -82,6 +88,8 @@ xen_host_cpu_record_free(xen_host_cpu_re
    3.24      xen_host_record_opt_free(record->host);
    3.25      free(record->vendor);
    3.26      free(record->modelname);
    3.27 +    free(record->stepping);
    3.28 +    free(record->flags);
    3.29      free(record);
    3.30  }
    3.31  
    3.32 @@ -127,37 +135,6 @@ xen_host_cpu_get_by_uuid(xen_session *se
    3.33  
    3.34  
    3.35  bool
    3.36 -xen_host_cpu_create(xen_session *session, xen_host_cpu *result, xen_host_cpu_record *record)
    3.37 -{
    3.38 -    abstract_value param_values[] =
    3.39 -        {
    3.40 -            { .type = &xen_host_cpu_record_abstract_type_,
    3.41 -              .u.struct_val = record }
    3.42 -        };
    3.43 -
    3.44 -    abstract_type result_type = abstract_type_string;
    3.45 -
    3.46 -    *result = NULL;
    3.47 -    XEN_CALL_("host_cpu.create");
    3.48 -    return session->ok;
    3.49 -}
    3.50 -
    3.51 -
    3.52 -bool
    3.53 -xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu)
    3.54 -{
    3.55 -    abstract_value param_values[] =
    3.56 -        {
    3.57 -            { .type = &abstract_type_string,
    3.58 -              .u.string_val = host_cpu }
    3.59 -        };
    3.60 -
    3.61 -    xen_call_(session, "host_cpu.destroy", param_values, 1, NULL, NULL);
    3.62 -    return session->ok;
    3.63 -}
    3.64 -
    3.65 -
    3.66 -bool
    3.67  xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu host_cpu)
    3.68  {
    3.69      abstract_value param_values[] =
    3.70 @@ -241,6 +218,40 @@ xen_host_cpu_get_modelname(xen_session *
    3.71  
    3.72  
    3.73  bool
    3.74 +xen_host_cpu_get_stepping(xen_session *session, char **result, xen_host_cpu host_cpu)
    3.75 +{
    3.76 +    abstract_value param_values[] =
    3.77 +        {
    3.78 +            { .type = &abstract_type_string,
    3.79 +              .u.string_val = host_cpu }
    3.80 +        };
    3.81 +
    3.82 +    abstract_type result_type = abstract_type_string;
    3.83 +
    3.84 +    *result = NULL;
    3.85 +    XEN_CALL_("host_cpu.get_stepping");
    3.86 +    return session->ok;
    3.87 +}
    3.88 +
    3.89 +
    3.90 +bool
    3.91 +xen_host_cpu_get_flags(xen_session *session, char **result, xen_host_cpu host_cpu)
    3.92 +{
    3.93 +    abstract_value param_values[] =
    3.94 +        {
    3.95 +            { .type = &abstract_type_string,
    3.96 +              .u.string_val = host_cpu }
    3.97 +        };
    3.98 +
    3.99 +    abstract_type result_type = abstract_type_string;
   3.100 +
   3.101 +    *result = NULL;
   3.102 +    XEN_CALL_("host_cpu.get_flags");
   3.103 +    return session->ok;
   3.104 +}
   3.105 +
   3.106 +
   3.107 +bool
   3.108  xen_host_cpu_get_utilisation(xen_session *session, double *result, xen_host_cpu host_cpu)
   3.109  {
   3.110      abstract_value param_values[] =
     4.1 --- a/tools/python/xen/xend/XendAPI.py	Mon Feb 26 17:20:36 2007 +0000
     4.2 +++ b/tools/python/xen/xend/XendAPI.py	Tue Feb 27 00:37:27 2007 +0000
     4.3 @@ -753,27 +753,44 @@ class XendAPI(object):
     4.4  
     4.5      host_cpu_attr_ro = ['host',
     4.6                          'number',
     4.7 +                        'vendor',
     4.8 +                        'speed',
     4.9 +                        'modelname',
    4.10 +                        'stepping',
    4.11 +                        'flags',
    4.12                          'utilisation']
    4.13  
    4.14      # attributes
    4.15 -    def host_cpu_get_host(self, session, host_cpu_ref):
    4.16 +    def _host_cpu_get(self, ref, field):
    4.17 +        return xen_api_success(
    4.18 +            XendNode.instance().get_host_cpu_field(ref, field))
    4.19 +
    4.20 +    def host_cpu_get_host(self, _, ref):
    4.21          return xen_api_success(XendNode.instance().uuid)
    4.22 -    def host_cpu_get_utilisation(self, session, host_cpu_ref):
    4.23 -        util = XendNode.instance().get_host_cpu_load(host_cpu_ref)
    4.24 -        return xen_api_success(util)
    4.25 -    def host_cpu_get_number(self, session, host_cpu_ref):
    4.26 -        num = XendNode.instance().get_host_cpu_number(host_cpu_ref)
    4.27 -        return xen_api_success(num)
    4.28 +    def host_cpu_get_number(self, _, ref):
    4.29 +        return self._host_cpu_get(ref, 'number')
    4.30 +    def host_cpu_get_vendor(self, _, ref):
    4.31 +        return self._host_cpu_get(ref, 'vendor')
    4.32 +    def host_cpu_get_speed(self, _, ref):
    4.33 +        return self._host_cpu_get(ref, 'speed')
    4.34 +    def host_cpu_get_modelname(self, _, ref):
    4.35 +        return self._host_cpu_get(ref, 'modelname')
    4.36 +    def host_cpu_get_stepping(self, _, ref):
    4.37 +        return self._host_cpu_get(ref, 'stepping')
    4.38 +    def host_cpu_get_flags(self, _, ref):
    4.39 +        return self._host_cpu_get(ref, 'flags')
    4.40 +    def host_cpu_get_utilisation(self, _, ref):
    4.41 +        return xen_api_success(XendNode.instance().get_host_cpu_load(ref))
    4.42  
    4.43      # object methods
    4.44 -    def host_cpu_destroy(self, session, host_cpu_ref):
    4.45 -        return xen_api_error(XEND_ERROR_UNSUPPORTED)
    4.46 -    def host_cpu_get_record(self, session, host_cpu_ref):
    4.47 +    def host_cpu_get_record(self, _, ref):
    4.48          node = XendNode.instance()
    4.49 -        record = {'uuid': host_cpu_ref,
    4.50 -                  'host': node.uuid,
    4.51 -                  'number': node.get_host_cpu_number(host_cpu_ref),
    4.52 -                  'utilisation': node.get_host_cpu_load(host_cpu_ref)}
    4.53 +        record = dict([(f, node.get_host_cpu_field(ref, f))
    4.54 +                       for f in self.host_cpu_attr_ro
    4.55 +                       if f not in ['uuid', 'host', 'utilisation']])
    4.56 +        record['uuid'] = ref
    4.57 +        record['host'] = node.uuid
    4.58 +        record['utilisation'] = node.get_host_cpu_load(ref)
    4.59          return xen_api_success(record)
    4.60  
    4.61      # class methods
     5.1 --- a/tools/python/xen/xend/XendNode.py	Mon Feb 26 17:20:36 2007 +0000
     5.2 +++ b/tools/python/xen/xend/XendNode.py	Tue Feb 27 00:37:27 2007 +0000
     5.3 @@ -81,7 +81,7 @@ class XendNode:
     5.4          for cpu_uuid, cpu in saved_cpus.items():
     5.5              self.cpus[cpu_uuid] = cpu
     5.6  
     5.7 -        # verify we have enough cpus here
     5.8 +        cpuinfo = parse_proc_cpuinfo()
     5.9          physinfo = self.physinfo_dict()
    5.10          cpu_count = physinfo['nr_cpus']
    5.11          cpu_features = physinfo['hw_caps']
    5.12 @@ -91,12 +91,23 @@ class XendNode:
    5.13          if cpu_count != len(self.cpus):
    5.14              self.cpus = {}
    5.15              for i in range(cpu_count):
    5.16 -                cpu_uuid = uuid.createString()
    5.17 -                cpu_info = {'uuid': cpu_uuid,
    5.18 -                            'host': self.uuid,
    5.19 -                            'number': i,
    5.20 -                            'features': cpu_features}
    5.21 -                self.cpus[cpu_uuid] = cpu_info
    5.22 +                u = uuid.createString()
    5.23 +                self.cpus[u] = {'uuid': u, 'number': i }
    5.24 +
    5.25 +        for u in self.cpus.keys():
    5.26 +            log.error(self.cpus[u])
    5.27 +            number = self.cpus[u]['number']
    5.28 +            log.error(number)
    5.29 +            log.error(cpuinfo)
    5.30 +            self.cpus[u].update(
    5.31 +                { 'host'     : self.uuid,
    5.32 +                  'features' : cpu_features,
    5.33 +                  'speed'    : int(float(cpuinfo[number]['cpu MHz'])),
    5.34 +                  'vendor'   : cpuinfo[number]['vendor_id'],
    5.35 +                  'modelname': cpuinfo[number]['model name'],
    5.36 +                  'stepping' : cpuinfo[number]['stepping'],
    5.37 +                  'flags'    : cpuinfo[number]['flags'],
    5.38 +                })
    5.39  
    5.40          self.pifs = {}
    5.41          self.pif_metrics = {}
    5.42 @@ -368,18 +379,12 @@ class XendNode:
    5.43          else:
    5.44              raise XendError('Invalid CPU Reference')
    5.45  
    5.46 -    def get_host_cpu_features(self, host_cpu_ref):
    5.47 +    def get_host_cpu_field(self, ref, field):
    5.48          try:
    5.49 -            return self.cpus[host_cpu_ref]['features']
    5.50 +            return self.cpus[ref][field]
    5.51          except KeyError:
    5.52              raise XendError('Invalid CPU Reference')
    5.53  
    5.54 -    def get_host_cpu_number(self, host_cpu_ref):
    5.55 -        try:
    5.56 -            return self.cpus[host_cpu_ref]['number']
    5.57 -        except KeyError:
    5.58 -            raise XendError('Invalid CPU Reference')        
    5.59 -            
    5.60      def get_host_cpu_load(self, host_cpu_ref):
    5.61          host_cpu = self.cpus.get(host_cpu_ref)
    5.62          if not host_cpu:
    5.63 @@ -542,6 +547,31 @@ class XendNode:
    5.64              pif.refresh(Brctl.get_state())
    5.65  
    5.66  
    5.67 +def parse_proc_cpuinfo():
    5.68 +    cpuinfo = {}
    5.69 +    f = file('/proc/cpuinfo', 'r')
    5.70 +    try:
    5.71 +        p = -1
    5.72 +        d = {}
    5.73 +        for line in f:
    5.74 +            keyvalue = line.split(':')
    5.75 +            if len(keyvalue) != 2:
    5.76 +                continue
    5.77 +            key = keyvalue[0].strip()
    5.78 +            val = keyvalue[1].strip()
    5.79 +            if key == 'processor':
    5.80 +                if p != -1:
    5.81 +                    cpuinfo[p] = d
    5.82 +                p = int(val)
    5.83 +                d = {}
    5.84 +            else:
    5.85 +                d[key] = val
    5.86 +        cpuinfo[p] = d
    5.87 +        return cpuinfo
    5.88 +    finally:
    5.89 +        f.close()
    5.90 +
    5.91 +
    5.92  def instance():
    5.93      global inst
    5.94      try: