[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Added some more fields to host_cpu.



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1172536647 0
# Node ID 50e0616fd012573f6e4c5b52c32bde6882308a24
# Parent  e7b2a282c9e70fbadd38ccc7cc7d1fcb6a32b886
Added some more fields to host_cpu.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 docs/xen-api/xenapi-datamodel.tex   |  140 ++++++++++++++++++------------------
 tools/libxen/include/xen_host_cpu.h |   36 ++++-----
 tools/libxen/src/xen_host_cpu.c     |   75 +++++++++++--------
 tools/python/xen/xend/XendAPI.py    |   45 +++++++----
 tools/python/xen/xend/XendNode.py   |   60 +++++++++++----
 5 files changed, 209 insertions(+), 147 deletions(-)

diff -r e7b2a282c9e7 -r 50e0616fd012 docs/xen-api/xenapi-datamodel.tex
--- a/docs/xen-api/xenapi-datamodel.tex Mon Feb 26 17:20:36 2007 +0000
+++ b/docs/xen-api/xenapi-datamodel.tex Tue Feb 27 00:37:27 2007 +0000
@@ -6278,11 +6278,13 @@ Quals & Field & Type & Description \\
 Quals & Field & Type & Description \\
 \hline
 $\mathit{RO}_\mathit{run}$ &  {\tt uuid} & string & unique identifier/object 
reference \\
-$\mathit{RO}_\mathit{ins}$ &  {\tt host} & host ref & the host the CPU is in \\
-$\mathit{RO}_\mathit{ins}$ &  {\tt number} & int & the number of the physical 
CPU within the host \\
-$\mathit{RO}_\mathit{ins}$ &  {\tt vendor} & string & the vendor of the 
physical CPU \\
-$\mathit{RO}_\mathit{ins}$ &  {\tt speed} & int & the speed of the physical 
CPU \\
-$\mathit{RO}_\mathit{ins}$ &  {\tt modelname} & string & the model name of the 
physical CPU \\
+$\mathit{RO}_\mathit{run}$ &  {\tt host} & host ref & the host the CPU is in \\
+$\mathit{RO}_\mathit{run}$ &  {\tt number} & int & the number of the physical 
CPU within the host \\
+$\mathit{RO}_\mathit{run}$ &  {\tt vendor} & string & the vendor of the 
physical CPU \\
+$\mathit{RO}_\mathit{run}$ &  {\tt speed} & int & the speed of the physical 
CPU \\
+$\mathit{RO}_\mathit{run}$ &  {\tt modelname} & string & the model name of the 
physical CPU \\
+$\mathit{RO}_\mathit{run}$ &  {\tt stepping} & string & the stepping of the 
physical CPU \\
+$\mathit{RO}_\mathit{run}$ &  {\tt flags} & string & the flags of the physical 
CPU \\
 $\mathit{RO}_\mathit{run}$ &  {\tt utilisation} & float & the current CPU 
utilisation \\
 \hline
 \end{longtable}
@@ -6479,6 +6481,70 @@ value of the field
 \vspace{0.3cm}
 \vspace{0.3cm}
 \vspace{0.3cm}
+\subsubsection{RPC name:~get\_stepping}
+
+{\bf Overview:} 
+Get the stepping field of the given host\_cpu.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} string get_stepping (session_id s, host_cpu ref 
self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt host\_cpu ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+string
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_flags}
+
+{\bf Overview:} 
+Get the flags field of the given host\_cpu.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} string get_flags (session_id s, host_cpu ref 
self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt host\_cpu ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+string
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
 \subsubsection{RPC name:~get\_utilisation}
 
 {\bf Overview:} 
@@ -6508,70 +6574,6 @@ float
 
 
 value of the field
-\vspace{0.3cm}
-\vspace{0.3cm}
-\vspace{0.3cm}
-\subsubsection{RPC name:~create}
-
-{\bf Overview:} 
-Create a new host\_cpu instance, and return its handle.
-
- \noindent {\bf Signature:} 
-\begin{verbatim} (host_cpu ref) create (session_id s, host_cpu record 
args)\end{verbatim}
-
-
-\noindent{\bf Arguments:}
-
- 
-\vspace{0.3cm}
-\begin{tabular}{|c|c|p{7cm}|}
- \hline
-{\bf type} & {\bf name} & {\bf description} \\ \hline
-{\tt host\_cpu record } & args & All constructor arguments \\ \hline 
-
-\end{tabular}
-
-\vspace{0.3cm}
-
- \noindent {\bf Return Type:} 
-{\tt 
-host\_cpu ref
-}
-
-
-reference to the newly created object
-\vspace{0.3cm}
-\vspace{0.3cm}
-\vspace{0.3cm}
-\subsubsection{RPC name:~destroy}
-
-{\bf Overview:} 
-Destroy the specified host\_cpu instance.
-
- \noindent {\bf Signature:} 
-\begin{verbatim} void destroy (session_id s, host_cpu ref self)\end{verbatim}
-
-
-\noindent{\bf Arguments:}
-
- 
-\vspace{0.3cm}
-\begin{tabular}{|c|c|p{7cm}|}
- \hline
-{\bf type} & {\bf name} & {\bf description} \\ \hline
-{\tt host\_cpu ref } & self & reference to the object \\ \hline 
-
-\end{tabular}
-
-\vspace{0.3cm}
-
- \noindent {\bf Return Type:} 
-{\tt 
-void
-}
-
-
-
 \vspace{0.3cm}
 \vspace{0.3cm}
 \vspace{0.3cm}
diff -r e7b2a282c9e7 -r 50e0616fd012 tools/libxen/include/xen_host_cpu.h
--- a/tools/libxen/include/xen_host_cpu.h       Mon Feb 26 17:20:36 2007 +0000
+++ b/tools/libxen/include/xen_host_cpu.h       Tue Feb 27 00:37:27 2007 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, XenSource Inc.
+ * Copyright (c) 2006-2007, XenSource Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,8 +25,8 @@
 
 
 /*
- * The host_cpu class. 
- *  
+ * The host_cpu class.
+ * 
  * A physical CPU.
  */
 
@@ -68,6 +68,8 @@ typedef struct xen_host_cpu_record
     char *vendor;
     int64_t speed;
     char *modelname;
+    char *stepping;
+    char *flags;
     double utilisation;
 } xen_host_cpu_record;
 
@@ -165,20 +167,6 @@ xen_host_cpu_get_by_uuid(xen_session *se
 
 
 /**
- * Create a new host_cpu instance, and return its handle.
- */
-extern bool
-xen_host_cpu_create(xen_session *session, xen_host_cpu *result, 
xen_host_cpu_record *record);
-
-
-/**
- * Destroy the specified host_cpu instance.
- */
-extern bool
-xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu);
-
-
-/**
  * Get the uuid field of the given host_cpu.
  */
 extern bool
@@ -221,6 +209,20 @@ xen_host_cpu_get_modelname(xen_session *
 
 
 /**
+ * Get the stepping field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_stepping(xen_session *session, char **result, xen_host_cpu 
host_cpu);
+
+
+/**
+ * Get the flags field of the given host_cpu.
+ */
+extern bool
+xen_host_cpu_get_flags(xen_session *session, char **result, xen_host_cpu 
host_cpu);
+
+
+/**
  * Get the utilisation field of the given host_cpu.
  */
 extern bool
diff -r e7b2a282c9e7 -r 50e0616fd012 tools/libxen/src/xen_host_cpu.c
--- a/tools/libxen/src/xen_host_cpu.c   Mon Feb 26 17:20:36 2007 +0000
+++ b/tools/libxen/src/xen_host_cpu.c   Tue Feb 27 00:37:27 2007 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, XenSource Inc.
+ * Copyright (c) 2006-2007, XenSource Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -55,6 +55,12 @@ static const struct_member xen_host_cpu_
         { .key = "modelname",
           .type = &abstract_type_string,
           .offset = offsetof(xen_host_cpu_record, modelname) },
+        { .key = "stepping",
+          .type = &abstract_type_string,
+          .offset = offsetof(xen_host_cpu_record, stepping) },
+        { .key = "flags",
+          .type = &abstract_type_string,
+          .offset = offsetof(xen_host_cpu_record, flags) },
         { .key = "utilisation",
           .type = &abstract_type_float,
           .offset = offsetof(xen_host_cpu_record, utilisation) }
@@ -82,6 +88,8 @@ xen_host_cpu_record_free(xen_host_cpu_re
     xen_host_record_opt_free(record->host);
     free(record->vendor);
     free(record->modelname);
+    free(record->stepping);
+    free(record->flags);
     free(record);
 }
 
@@ -127,37 +135,6 @@ xen_host_cpu_get_by_uuid(xen_session *se
 
 
 bool
-xen_host_cpu_create(xen_session *session, xen_host_cpu *result, 
xen_host_cpu_record *record)
-{
-    abstract_value param_values[] =
-        {
-            { .type = &xen_host_cpu_record_abstract_type_,
-              .u.struct_val = record }
-        };
-
-    abstract_type result_type = abstract_type_string;
-
-    *result = NULL;
-    XEN_CALL_("host_cpu.create");
-    return session->ok;
-}
-
-
-bool
-xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu)
-{
-    abstract_value param_values[] =
-        {
-            { .type = &abstract_type_string,
-              .u.string_val = host_cpu }
-        };
-
-    xen_call_(session, "host_cpu.destroy", param_values, 1, NULL, NULL);
-    return session->ok;
-}
-
-
-bool
 xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu 
host_cpu)
 {
     abstract_value param_values[] =
@@ -241,6 +218,40 @@ xen_host_cpu_get_modelname(xen_session *
 
 
 bool
+xen_host_cpu_get_stepping(xen_session *session, char **result, xen_host_cpu 
host_cpu)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = host_cpu }
+        };
+
+    abstract_type result_type = abstract_type_string;
+
+    *result = NULL;
+    XEN_CALL_("host_cpu.get_stepping");
+    return session->ok;
+}
+
+
+bool
+xen_host_cpu_get_flags(xen_session *session, char **result, xen_host_cpu 
host_cpu)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = host_cpu }
+        };
+
+    abstract_type result_type = abstract_type_string;
+
+    *result = NULL;
+    XEN_CALL_("host_cpu.get_flags");
+    return session->ok;
+}
+
+
+bool
 xen_host_cpu_get_utilisation(xen_session *session, double *result, 
xen_host_cpu host_cpu)
 {
     abstract_value param_values[] =
diff -r e7b2a282c9e7 -r 50e0616fd012 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Mon Feb 26 17:20:36 2007 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Tue Feb 27 00:37:27 2007 +0000
@@ -753,27 +753,44 @@ class XendAPI(object):
 
     host_cpu_attr_ro = ['host',
                         'number',
+                        'vendor',
+                        'speed',
+                        'modelname',
+                        'stepping',
+                        'flags',
                         'utilisation']
 
     # attributes
-    def host_cpu_get_host(self, session, host_cpu_ref):
+    def _host_cpu_get(self, ref, field):
+        return xen_api_success(
+            XendNode.instance().get_host_cpu_field(ref, field))
+
+    def host_cpu_get_host(self, _, ref):
         return xen_api_success(XendNode.instance().uuid)
-    def host_cpu_get_utilisation(self, session, host_cpu_ref):
-        util = XendNode.instance().get_host_cpu_load(host_cpu_ref)
-        return xen_api_success(util)
-    def host_cpu_get_number(self, session, host_cpu_ref):
-        num = XendNode.instance().get_host_cpu_number(host_cpu_ref)
-        return xen_api_success(num)
+    def host_cpu_get_number(self, _, ref):
+        return self._host_cpu_get(ref, 'number')
+    def host_cpu_get_vendor(self, _, ref):
+        return self._host_cpu_get(ref, 'vendor')
+    def host_cpu_get_speed(self, _, ref):
+        return self._host_cpu_get(ref, 'speed')
+    def host_cpu_get_modelname(self, _, ref):
+        return self._host_cpu_get(ref, 'modelname')
+    def host_cpu_get_stepping(self, _, ref):
+        return self._host_cpu_get(ref, 'stepping')
+    def host_cpu_get_flags(self, _, ref):
+        return self._host_cpu_get(ref, 'flags')
+    def host_cpu_get_utilisation(self, _, ref):
+        return xen_api_success(XendNode.instance().get_host_cpu_load(ref))
 
     # object methods
-    def host_cpu_destroy(self, session, host_cpu_ref):
-        return xen_api_error(XEND_ERROR_UNSUPPORTED)
-    def host_cpu_get_record(self, session, host_cpu_ref):
+    def host_cpu_get_record(self, _, ref):
         node = XendNode.instance()
-        record = {'uuid': host_cpu_ref,
-                  'host': node.uuid,
-                  'number': node.get_host_cpu_number(host_cpu_ref),
-                  'utilisation': node.get_host_cpu_load(host_cpu_ref)}
+        record = dict([(f, node.get_host_cpu_field(ref, f))
+                       for f in self.host_cpu_attr_ro
+                       if f not in ['uuid', 'host', 'utilisation']])
+        record['uuid'] = ref
+        record['host'] = node.uuid
+        record['utilisation'] = node.get_host_cpu_load(ref)
         return xen_api_success(record)
 
     # class methods
diff -r e7b2a282c9e7 -r 50e0616fd012 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Mon Feb 26 17:20:36 2007 +0000
+++ b/tools/python/xen/xend/XendNode.py Tue Feb 27 00:37:27 2007 +0000
@@ -81,7 +81,7 @@ class XendNode:
         for cpu_uuid, cpu in saved_cpus.items():
             self.cpus[cpu_uuid] = cpu
 
-        # verify we have enough cpus here
+        cpuinfo = parse_proc_cpuinfo()
         physinfo = self.physinfo_dict()
         cpu_count = physinfo['nr_cpus']
         cpu_features = physinfo['hw_caps']
@@ -91,12 +91,23 @@ class XendNode:
         if cpu_count != len(self.cpus):
             self.cpus = {}
             for i in range(cpu_count):
-                cpu_uuid = uuid.createString()
-                cpu_info = {'uuid': cpu_uuid,
-                            'host': self.uuid,
-                            'number': i,
-                            'features': cpu_features}
-                self.cpus[cpu_uuid] = cpu_info
+                u = uuid.createString()
+                self.cpus[u] = {'uuid': u, 'number': i }
+
+        for u in self.cpus.keys():
+            log.error(self.cpus[u])
+            number = self.cpus[u]['number']
+            log.error(number)
+            log.error(cpuinfo)
+            self.cpus[u].update(
+                { 'host'     : self.uuid,
+                  'features' : cpu_features,
+                  'speed'    : int(float(cpuinfo[number]['cpu MHz'])),
+                  'vendor'   : cpuinfo[number]['vendor_id'],
+                  'modelname': cpuinfo[number]['model name'],
+                  'stepping' : cpuinfo[number]['stepping'],
+                  'flags'    : cpuinfo[number]['flags'],
+                })
 
         self.pifs = {}
         self.pif_metrics = {}
@@ -368,18 +379,12 @@ class XendNode:
         else:
             raise XendError('Invalid CPU Reference')
 
-    def get_host_cpu_features(self, host_cpu_ref):
+    def get_host_cpu_field(self, ref, field):
         try:
-            return self.cpus[host_cpu_ref]['features']
+            return self.cpus[ref][field]
         except KeyError:
             raise XendError('Invalid CPU Reference')
 
-    def get_host_cpu_number(self, host_cpu_ref):
-        try:
-            return self.cpus[host_cpu_ref]['number']
-        except KeyError:
-            raise XendError('Invalid CPU Reference')        
-            
     def get_host_cpu_load(self, host_cpu_ref):
         host_cpu = self.cpus.get(host_cpu_ref)
         if not host_cpu:
@@ -542,6 +547,31 @@ class XendNode:
             pif.refresh(Brctl.get_state())
 
 
+def parse_proc_cpuinfo():
+    cpuinfo = {}
+    f = file('/proc/cpuinfo', 'r')
+    try:
+        p = -1
+        d = {}
+        for line in f:
+            keyvalue = line.split(':')
+            if len(keyvalue) != 2:
+                continue
+            key = keyvalue[0].strip()
+            val = keyvalue[1].strip()
+            if key == 'processor':
+                if p != -1:
+                    cpuinfo[p] = d
+                p = int(val)
+                d = {}
+            else:
+                d[key] = val
+        cpuinfo[p] = d
+        return cpuinfo
+    finally:
+        f.close()
+
+
 def instance():
     global inst
     try:

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.