diff -r fc4e10d0455a tools/libxc/xc.h --- a/tools/libxc/xc.h Sat Jul 2 22:37:55 2005 +++ b/tools/libxc/xc.h Sun Jul 3 16:05:52 2005 @@ -4,6 +4,7 @@ * A library for low-level access to the Xen control interfaces. * * Copyright (c) 2003-2004, K A Fraser. + * Copyright (c) 2005, Nguyen Anh Quynh */ #ifndef __XC_H__ @@ -26,6 +27,7 @@ #include #include #include +#include /* * DEFINITIONS FOR CPU BARRIERS @@ -506,4 +508,22 @@ /* Execute a privileged dom0 operation. */ int xc_dom0_op(int xc_handle, dom0_op_t *op); +/* These structs are for libxc to get xen version and extra stuffs. */ +typedef xen_compile_info_t xc_xen_compile_info_t; +typedef xen_extraversion_t xc_xen_extraversion_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_xen_extraversion_t extraversion); + +/** + * Get xen compile info + * + * @return 0 on success, -1 on failure. + */ +int xc_xen_compile_info(int xc_handle, xc_xen_compile_info_t *version); + #endif /* __XC_H__ */ diff -r fc4e10d0455a tools/libxc/xc_misc.c --- a/tools/libxc/xc_misc.c Sat Jul 2 22:37:55 2005 +++ b/tools/libxc/xc_misc.c Sun Jul 3 16:05:52 2005 @@ -130,3 +130,43 @@ return rc; } + +long xc_xen_version(int xc_handle, xc_xen_extraversion_t extraversion) +{ + long ret; + privcmd_hypercall_t hypercall; + + hypercall.op = __HYPERVISOR_xen_version; + hypercall.arg[0] = XENVER_version; + ret = do_xen_hypercall(xc_handle, &hypercall); + + hypercall.arg[0] = XENVER_extraversion; + hypercall.arg[1] = (unsigned long)extraversion; + + if (do_xen_hypercall(xc_handle, &hypercall) < 0) + { + if (errno == EACCES) + PERROR("Could not obtain xen version"); + return -1; + } + + return ret; +} + +int xc_xen_compile_info(int xc_handle, xc_xen_compile_info_t *info) +{ + privcmd_hypercall_t hypercall; + + hypercall.op = __HYPERVISOR_xen_version; + hypercall.arg[0] = XENVER_compile_info; + hypercall.arg[1] = (unsigned long)info; + + if (do_xen_hypercall(xc_handle, &hypercall) < 0) + { + if (errno == EACCES) + PERROR("Could not obtain xen compile information"); + return -1; + } + + return 0; +} diff -r fc4e10d0455a tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Sat Jul 2 22:37:55 2005 +++ b/tools/python/xen/lowlevel/xc/xc.c Sun Jul 3 16:05:52 2005 @@ -2,6 +2,7 @@ * Xc.c * * Copyright (c) 2003-2004, K A Fraser (University of Cambridge) + * Copyright (c) 2005, Nguyen Anh Quynh */ #include @@ -686,9 +687,10 @@ if ( xc_physinfo(xc->xc_handle, &info) != 0 ) return PyErr_SetFromErrno(xc_error); - return Py_BuildValue("{s:i,s:i,s:l,s:l,s:l}", + return Py_BuildValue("{s:i,s:i,s:i,s:l,s:l,s:l}", "ht_per_core", info.ht_per_core, "cores", info.cores, + "sockets", info.sockets, "total_pages", info.total_pages, "free_pages", info.free_pages, "cpu_khz", info.cpu_khz); @@ -806,6 +808,45 @@ return zero; } +static PyObject *pyxc_xen_version(PyObject *self, + PyObject *args, + PyObject *kwds) +{ + xc_xen_extraversion_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}", + "version", ret >> 16, + "subversion", ret & 0xFFFF, + "extraversion", v); +} + +static PyObject *pyxc_xen_compile_info(PyObject *self, + PyObject *args, + PyObject *kwds) +{ + xc_xen_compile_info_t v; + XcObject *xc = (XcObject *)self; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + + if (xc_xen_compile_info(xc->xc_handle, &v) == -1) + return PyErr_SetFromErrno(xc_error); + + return Py_BuildValue("{s:s,s:s,s:s,s:s}", + "compile_by", v.compile_by, + "compile_domain", v.compile_domain, + "compiler", v.compiler, + "compile_date", v.compile_date); +} static PyMethodDef pyxc_methods[] = { { "handle", @@ -1081,6 +1122,18 @@ " 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 extraversion on success; empty list on error.\n" }, + + { "xen_compile_info", + (PyCFunction)pyxc_xen_compile_info, + METH_KEYWORDS, "\n" + "Get Xen compile information\n" + "Returns: [dict] xen compile information on success; empty list on error.\n" }, + { NULL, NULL, 0, NULL } }; diff -r fc4e10d0455a tools/python/xen/xend/XendNode.py --- a/tools/python/xen/xend/XendNode.py Sat Jul 2 22:37:55 2005 +++ b/tools/python/xen/xend/XendNode.py Sun Jul 3 16:05:52 2005 @@ -35,15 +35,23 @@ def nodeinfo(self): (sys, host, rel, ver, mch) = os.uname() + xen_ver = self.xc.xen_version() + xen_info = self.xc.xen_compile_info() 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_info['compile_by'], xen_info['compile_domain'])], + ['xen_compiler', xen_info['compiler']], + ['xen_compile_date', xen_info['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'] * pinfo['sockets']], + ['sockets', pinfo['sockets']], + ['cores_per_socket', pinfo['cores']], ['hyperthreads_per_core', pinfo['ht_per_core']], ['cpu_mhz', pinfo['cpu_khz']/1000], ['memory', pinfo['total_pages']/256], diff -r fc4e10d0455a xen/arch/x86/dom0_ops.c --- a/xen/arch/x86/dom0_ops.c Sat Jul 2 22:37:55 2005 +++ b/xen/arch/x86/dom0_ops.c Sun Jul 3 16:05:52 2005 @@ -181,6 +181,7 @@ pi->ht_per_core = smp_num_siblings; pi->cores = boot_cpu_data.x86_num_cores; + pi->sockets = num_online_cpus(); pi->total_pages = max_page; pi->free_pages = avail_domheap_pages(); pi->cpu_khz = cpu_khz; diff -r fc4e10d0455a xen/common/kernel.c --- a/xen/common/kernel.c Sat Jul 2 22:37:55 2005 +++ b/xen/common/kernel.c Sun Jul 3 16:05:52 2005 @@ -85,31 +85,31 @@ { switch ( cmd ) { - case XENVER_version: - { - return (XEN_VERSION<<16) | (XEN_SUBVERSION); - } + case XENVER_version: + { + return (XEN_VERSION<<16) | (XEN_SUBVERSION); + } - case XENVER_extraversion: - { - char extraversion[16]; - safe_strcpy(extraversion, XEN_EXTRAVERSION); - if ( copy_to_user(arg, extraversion, sizeof(extraversion)) ) - return -EFAULT; - return 0; - } + case XENVER_extraversion: + { + xen_extraversion_t extraversion; + safe_strcpy(extraversion, XEN_EXTRAVERSION); + if ( copy_to_user(arg, extraversion, sizeof(extraversion)) ) + return -EFAULT; + return 0; + } - case XENVER_compile_info: - { - struct xen_compile_info info; - safe_strcpy(info.compiler, XEN_COMPILER); - safe_strcpy(info.compile_by, XEN_COMPILE_BY); - safe_strcpy(info.compile_domain, XEN_COMPILE_DOMAIN); - safe_strcpy(info.compile_date, XEN_COMPILE_DATE); - if ( copy_to_user(arg, &info, sizeof(info)) ) - return -EFAULT; - return 0; - } + case XENVER_compile_info: + { + struct xen_compile_info info; + safe_strcpy(info.compiler, XEN_COMPILER); + safe_strcpy(info.compile_by, XEN_COMPILE_BY); + safe_strcpy(info.compile_domain, XEN_COMPILE_DOMAIN); + safe_strcpy(info.compile_date, XEN_COMPILE_DATE); + if ( copy_to_user(arg, &info, sizeof(info)) ) + return -EFAULT; + return 0; + } } return -ENOSYS; diff -r fc4e10d0455a xen/include/public/dom0_ops.h --- a/xen/include/public/dom0_ops.h Sat Jul 2 22:37:55 2005 +++ b/xen/include/public/dom0_ops.h Sun Jul 3 16:05:52 2005 @@ -208,6 +208,7 @@ typedef struct { u32 ht_per_core; u32 cores; + u32 sockets; u32 cpu_khz; memory_t total_pages; memory_t free_pages; diff -r fc4e10d0455a xen/include/public/version.h --- a/xen/include/public/version.h Sat Jul 2 22:37:55 2005 +++ b/xen/include/public/version.h Sun Jul 3 16:05:52 2005 @@ -20,6 +20,7 @@ /* arg == xenversion_compile_info_t. */ #define XENVER_compile_info 2 + typedef struct xen_compile_info { char compiler[64]; char compile_by[16]; @@ -27,4 +28,6 @@ char compile_date[32]; } xen_compile_info_t; +typedef char xen_extraversion_t[16]; + #endif /* __XEN_PUBLIC_VERSION_H__ */