aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorEwan Mellor <ewan@xensource.com>2007-02-27 00:37:27 +0000
committerEwan Mellor <ewan@xensource.com>2007-02-27 00:37:27 +0000
commitd8309d27a1423904824363930736b7ea258a562d (patch)
tree9e93f767fbd07858b645f3bb56bb9ec846833593 /tools
parentb3c8af5814936eb99e2377428330c9938df67e43 (diff)
downloadxen-d8309d27a1423904824363930736b7ea258a562d.tar.gz
xen-d8309d27a1423904824363930736b7ea258a562d.tar.bz2
xen-d8309d27a1423904824363930736b7ea258a562d.zip
Added some more fields to host_cpu.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/libxen/include/xen_host_cpu.h36
-rw-r--r--tools/libxen/src/xen_host_cpu.c47
-rw-r--r--tools/python/xen/xend/XendAPI.py45
-rw-r--r--tools/python/xen/xend/XendNode.py60
4 files changed, 124 insertions, 64 deletions
diff --git a/tools/libxen/include/xen_host_cpu.h b/tools/libxen/include/xen_host_cpu.h
index 945a7279d1..f70023f24e 100644
--- a/tools/libxen/include/xen_host_cpu.h
+++ b/tools/libxen/include/xen_host_cpu.h
@@ -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 *session, xen_host_cpu *result, char *uuid)
/**
- * 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 *session, char **result, xen_host_cpu hos
/**
+ * 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 --git a/tools/libxen/src/xen_host_cpu.c b/tools/libxen/src/xen_host_cpu.c
index 1300ce0e43..425d0c60b9 100644
--- a/tools/libxen/src/xen_host_cpu.c
+++ b/tools/libxen/src/xen_host_cpu.c
@@ -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_record_struct_members[] =
{ .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_record *record)
xen_host_record_opt_free(record->host);
free(record->vendor);
free(record->modelname);
+ free(record->stepping);
+ free(record->flags);
free(record);
}
@@ -127,24 +135,24 @@ xen_host_cpu_get_by_uuid(xen_session *session, xen_host_cpu *result, char *uuid)
bool
-xen_host_cpu_create(xen_session *session, xen_host_cpu *result, xen_host_cpu_record *record)
+xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
- { .type = &xen_host_cpu_record_abstract_type_,
- .u.struct_val = record }
+ { .type = &abstract_type_string,
+ .u.string_val = host_cpu }
};
abstract_type result_type = abstract_type_string;
*result = NULL;
- XEN_CALL_("host_cpu.create");
+ XEN_CALL_("host_cpu.get_host");
return session->ok;
}
bool
-xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu)
+xen_host_cpu_get_number(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
@@ -152,13 +160,15 @@ xen_host_cpu_destroy(xen_session *session, xen_host_cpu host_cpu)
.u.string_val = host_cpu }
};
- xen_call_(session, "host_cpu.destroy", param_values, 1, NULL, NULL);
+ abstract_type result_type = abstract_type_int;
+
+ XEN_CALL_("host_cpu.get_number");
return session->ok;
}
bool
-xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu host_cpu)
+xen_host_cpu_get_vendor(xen_session *session, char **result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
@@ -169,13 +179,13 @@ xen_host_cpu_get_host(xen_session *session, xen_host *result, xen_host_cpu host_
abstract_type result_type = abstract_type_string;
*result = NULL;
- XEN_CALL_("host_cpu.get_host");
+ XEN_CALL_("host_cpu.get_vendor");
return session->ok;
}
bool
-xen_host_cpu_get_number(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
+xen_host_cpu_get_speed(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
@@ -185,13 +195,13 @@ xen_host_cpu_get_number(xen_session *session, int64_t *result, xen_host_cpu host
abstract_type result_type = abstract_type_int;
- XEN_CALL_("host_cpu.get_number");
+ XEN_CALL_("host_cpu.get_speed");
return session->ok;
}
bool
-xen_host_cpu_get_vendor(xen_session *session, char **result, xen_host_cpu host_cpu)
+xen_host_cpu_get_modelname(xen_session *session, char **result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
@@ -202,13 +212,13 @@ xen_host_cpu_get_vendor(xen_session *session, char **result, xen_host_cpu host_c
abstract_type result_type = abstract_type_string;
*result = NULL;
- XEN_CALL_("host_cpu.get_vendor");
+ XEN_CALL_("host_cpu.get_modelname");
return session->ok;
}
bool
-xen_host_cpu_get_speed(xen_session *session, int64_t *result, xen_host_cpu host_cpu)
+xen_host_cpu_get_stepping(xen_session *session, char **result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
@@ -216,15 +226,16 @@ xen_host_cpu_get_speed(xen_session *session, int64_t *result, xen_host_cpu host_
.u.string_val = host_cpu }
};
- abstract_type result_type = abstract_type_int;
+ abstract_type result_type = abstract_type_string;
- XEN_CALL_("host_cpu.get_speed");
+ *result = NULL;
+ XEN_CALL_("host_cpu.get_stepping");
return session->ok;
}
bool
-xen_host_cpu_get_modelname(xen_session *session, char **result, xen_host_cpu host_cpu)
+xen_host_cpu_get_flags(xen_session *session, char **result, xen_host_cpu host_cpu)
{
abstract_value param_values[] =
{
@@ -235,7 +246,7 @@ xen_host_cpu_get_modelname(xen_session *session, char **result, xen_host_cpu hos
abstract_type result_type = abstract_type_string;
*result = NULL;
- XEN_CALL_("host_cpu.get_modelname");
+ XEN_CALL_("host_cpu.get_flags");
return session->ok;
}
diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py
index 3926cd7d75..3562ba45f0 100644
--- a/tools/python/xen/xend/XendAPI.py
+++ b/tools/python/xen/xend/XendAPI.py
@@ -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 --git a/tools/python/xen/xend/XendNode.py b/tools/python/xen/xend/XendNode.py
index 4534dc57ff..f550a467a9 100644
--- a/tools/python/xen/xend/XendNode.py
+++ b/tools/python/xen/xend/XendNode.py
@@ -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: