xm info
PATCH 2/2 xm info
This patch gets "xm info" shown some additional information such as xen version, xen builder, compile time, logical cpus, number of cores and Hyper threading support (finally works correctly). To do that, the patch extends the xen_version hypercall and adds a python wrapper for it.
Here is the ouput of "xm info":
system : Linux
host : ubuntuxen_release : 3.0-develxen_compile_by : root@localdomainxen_compiler : gcc version 3.3.5 (Debian 1:3.3.5-8ubuntu2)xen_compile_date : Mon Jun 20 00:57:59 EST 2005dom0_release : 2.6.11.12-xen0dom0_version : #2 Mon Jun 20 03:09:24 EST 2005
machine : i686logical_cpus : 1cores_per_socket : 1hyperthreads_per_core : 1cpu_mhz : 1094
memory : 511free_memory : 122
# diffstat xminfo3.patch tools/libxc/xc.h | 11 +++++++++++ tools/libxc/xc_misc.c | 18 ++++++++++++++++++ tools/python/xen/lowlevel/xc/xc.c | 29 +++++++++++++++++++++++++++++ tools/python/xen/xend/XendNode.py | 15 ++++++++++----- xen/common/kernel.c | 22 ++++++++++++++++++---- xen/include/public/version.h | 22 ++++++++++++++++++++++ 6 files changed, 108 insertions(+), 9 deletions(-)
tools/libxc/xc.h +11 -0
@@ -25,6 +25,7 @@ typedef int64_t s64;#include <xen/dom0_ops.h> #include <xen/event_channel.h> #include <xen/sched_ctl.h> +#include <xen/version.h> /* * DEFINITIONS FOR CPU BARRIERS
@@ -507,4 +508,14 @@ long xc_get_tot_pages(int xc_handle, u32/* Execute a privileged dom0 operation. */ int xc_dom0_op (int xc_handle,dom0_op_t *op); +/* This struct is for libxc to get xen version and extra stuffs. */ +typedef version_op_t xc_version_t ; + +/** +* Get xen version +* +* @return a long value which encodes XEN_VERSION and XEN_SUBVERSION on success, -1 on failure. +*/ +long xc_xen_version (int xc_handle,xc_version_t *version); +#endif /* __XC_H__ */
tools/libxc/xc_misc.c +18 -0
@@ -130,3 +130,21 @@ int xc_msr_write(int xc_handle, int cpu_return rc; } + +long xc_xen_version (int xc_handle,xc_version_t *v) +{ +long ret; +privcmd_hypercall_t hypercall; + + hypercall.op = __HYPERVISOR_xen_version; + hypercall.arg[0 ] = (unsigned long )v; + +if ((ret =do_xen_hypercall (xc_handle, &hypercall)) <0 ) + { +if (errno ==EACCES ) +PERROR ("Could not obtain xen version" ); +return -1 ; + } + +return ret; +}
tools/python/xen/lowlevel/xc/xc.c +29 -0
@@ -831,6 +831,29 @@ static PyObject *pyxc_domain_memory_incrreturn zero; } +static PyObject *pyxc_xen_version (PyObject *self, +PyObject *args, +PyObject *kwds) +{ +xc_version_t v; +long ret; +XcObject *xc = (XcObject *)self; + +if (!PyArg_ParseTuple (args,"" )) +return NULL ; + +if ((ret =xc_xen_version (xc->xc_handle, &v)) ==-1 ) +return PyErr_SetFromErrno (xc_error); + +return Py_BuildValue ("{s:i,s:i,s:s,s:s,s:s,s:s,s:s}" , +"version" , ret >>16 , +"subversion" , ret &0xFFFF , +"extraversion" , v.extraversion, +"compile_by" , v.compile_by, +"compile_domain" , v.compile_domain, +"compiler" , v.compiler, +"compile_date" , v.compile_date); +}static PyMethodDef pyxc_methods[] = { {"handle" ,
@@ -1115,6 +1138,12 @@ static PyMethodDef pyxc_methods[] = { " mem_kb [long]: .\n" "Returns: [int] 0 on success; -1 on error.\n" }, + {"xen_version" , + (PyCFunction )pyxc_xen_version, +METH_KEYWORDS ,"\n" +"Get Xen version\n" + "Returns: [dict] xen version and extra stuffs on success; empty list on error.\n" }, + { NULL, NULL, 0, NULL } };
tools/python/xen/xend/XendNode.py +10 -5
@@ -35,22 +35,27 @@ class XendNode: def nodeinfo(self): (sys, host, rel, ver, mch) = os.uname() + xen_ver = self.xc.xen_version() return [['system', sys], - ['host', host], - ['release', rel], - ['version', ver], + ['host', host], + ['xen_release', "%i.%i%s" %(xen_ver['version'], xen_ver['subversion'], xen_ver['extraversion'])], + ['xen_compile_by', "%s@%s" %(xen_ver['compile_by'], xen_ver['compile_domain'])], + ['xen_compiler', xen_ver['compiler']], + ['xen_compile_date', xen_ver['compile_date']], + ['dom0_release', rel], + ['dom0_version', ver], ['machine', mch]] def physinfo(self): pinfo = self.xc.physinfo() - info = [['cores', pinfo['cores']], + info = [['logical_cpus', pinfo['cores'] * pinfo['ht_per_core']], + ['cores_per_socket', pinfo['cores']], ['hyperthreads_per_core', pinfo['ht_per_core']], ['cpu_mhz', pinfo['cpu_khz']/1000], ['memory', pinfo['total_pages']/256], ['free_memory', pinfo['free_pages']/256]] return info - def instance(): global inst
xen/common/kernel.c +18 -4
@@ -15,6 +15,9 @@#include <xen/sched.h> #include <asm/current.h> +#include <public/version.h> +#include <xen/string.h> +void cmdline_parse (char *cmdline) {char opt[100 ], *optval, *p = cmdline, *q;
@@ -83,11 +86,22 @@ void cmdline_parse(char *cmdline)* Simple hypercalls. */ -long do_xen_version (int cmd) +long do_xen_version (version_op_t *op) { -if ( cmd !=0 ) -return -ENOSYS ; -return (XEN_VERSION <<16 ) | (XEN_SUBVERSION ); +version_op_t vop; +if (op !=NULL )/* return extra stuffs */ + { +if (copy_from_user (&vop, op,sizeof (vop)) !=0 ) +return -EFAULT ; +strncpy (vop.extraversion,XEN_EXTRAVERSION ,sizeof (vop.extraversion)); +strncpy (vop.compile_by,XEN_COMPILE_BY ,sizeof (vop.compile_by)); +strncpy (vop.compile_domain,XEN_COMPILE_DOMAIN ,sizeof (vop.compile_domain)); +strncpy (vop.compiler,XEN_COMPILER ,sizeof (vop.compiler)); +strncpy (vop.compile_date,XEN_COMPILE_DATE ,sizeof (vop.compile_date)); +if (copy_to_user (op, &vop,sizeof (vop)) !=0 ) +return -EFAULT ; + } +return (XEN_VERSION <<16 ) | (XEN_SUBVERSION );/* always return version & subversion */ }long do_vm_assist (unsigned int cmd,unsigned int type)
xen/include/public/version.h +22 -0
@@ -0,0 +1,22 @@ +/****************************************************************************** +* version.h +* +* Xen extraversion and stuffs. +* +* Copyright (c) 2005, Nguyen Anh Quynh <[email protected]> +*/ + +#ifndef __XEN_PUBLIC_VERSION_H__ +#define __XEN_PUBLIC_VERSION_H__ + +/* This struct is for xen hypercall only. Usually you dont need it. */ +typedef struct _version_op_st +{ +char extraversion[8 ];/* 0 */ +char compile_by[16 ];/* 8 */ +char compile_domain[32 ];/* 24 */ +char compiler[64 ];/* 56 */ +char compile_date[32 ];/* 120 */ +} PACKED version_op_t; /* 152 bytes */ + +#endif /* __XEN_PUBLIC_VERSION_H__ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel