ia64/xen-unstable

changeset 6378:79df8d5fc424

Add xenversion support
author jfisch@us.ibm.com
date Tue Aug 23 02:10:59 2005 +0100 (2005-08-23)
parents 63cc61fafb28
children 6783e59e1c45
files tools/xenstat/libxenstat/src/xen-interface.c tools/xenstat/libxenstat/src/xen-interface.h tools/xenstat/libxenstat/src/xenstat.c tools/xenstat/libxenstat/src/xenstat.h
line diff
     1.1 --- a/tools/xenstat/libxenstat/src/xen-interface.c	Tue Aug 23 00:28:50 2005 +0100
     1.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.c	Tue Aug 23 02:10:59 2005 +0100
     1.3 @@ -21,7 +21,9 @@
     1.4  #include <sys/mman.h>
     1.5  #include <stdio.h>
     1.6  #include <stdlib.h>
     1.7 +#include <string.h>
     1.8  #include <unistd.h>
     1.9 +#include "version.h"
    1.10  #include "privcmd.h"
    1.11  #include "xen.h"
    1.12  
    1.13 @@ -56,24 +58,69 @@ void xi_uninit(xi_handle *handle)
    1.14  	free (handle);
    1.15  }
    1.16  
    1.17 -/* Make Xen hypervisor call */
    1.18 -int xi_make_dom0_op(xi_handle *handle, dom0_op_t *op, int opcode)
    1.19 +/* Make simple xen version hypervisor calls */
    1.20 +static int xi_make_xen_version_hypercall(xi_handle *handle, long *vnum, xen_extraversion_t *ver)
    1.21 +{
    1.22 +	privcmd_hypercall_t privcmd;
    1.23 +	multicall_entry_t multicall[2];
    1.24 +	int ret = 0;
    1.25 +
    1.26 +	/* set up for doing hypercall */
    1.27 +	privcmd.op = __HYPERVISOR_multicall; 
    1.28 +	privcmd.arg[0] = (unsigned long)multicall;
    1.29 +	privcmd.arg[1] = 2;
    1.30 +
    1.31 +	/* first one to get xen version number */
    1.32 +	multicall[0].op = __HYPERVISOR_xen_version;
    1.33 +	multicall[0].args[0] = (unsigned long)XENVER_version;
    1.34 +
    1.35 +	/* second to get xen version flag */
    1.36 +	multicall[1].op = __HYPERVISOR_xen_version; 
    1.37 +	multicall[1].args[0] = (unsigned long)XENVER_extraversion;
    1.38 +	multicall[1].args[1] = (unsigned long)ver;
    1.39 +
    1.40 +	if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) {
    1.41 +		perror("Failed to mlock privcmd structure");
    1.42 +		return -1;
    1.43 +	}
    1.44 +
    1.45 +	if (mlock( multicall, sizeof(multicall_entry_t)) < 0) {
    1.46 +		perror("Failed to mlock multicall_entry structure");
    1.47 +		munlock( &multicall, sizeof(multicall_entry_t));
    1.48 +		return -1;
    1.49 +	}
    1.50 +
    1.51 +	if (ioctl( handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) {
    1.52 +		perror("Hypercall failed");
    1.53 +		ret = -1;
    1.54 +	}
    1.55 +
    1.56 +	*vnum = multicall[0].result;
    1.57 +
    1.58 +	munlock( &privcmd, sizeof(privcmd_hypercall_t));
    1.59 +	munlock( &multicall, sizeof(multicall_entry_t));
    1.60 +
    1.61 +	return ret;
    1.62 +}
    1.63 +
    1.64 +/* Make Xen Dom0 op hypervisor call */
    1.65 +static int xi_make_dom0_op(xi_handle *handle, dom0_op_t *dom_op, int dom_opcode)
    1.66  {
    1.67  	privcmd_hypercall_t privcmd;
    1.68  	int ret = 0;
    1.69  
    1.70  	/* set up for doing hypercall */
    1.71  	privcmd.op = __HYPERVISOR_dom0_op;
    1.72 -	privcmd.arg[0] = (unsigned long)op;
    1.73 -	op->cmd = opcode;
    1.74 -	op->interface_version = DOM0_INTERFACE_VERSION;
    1.75 +	privcmd.arg[0] = (unsigned long)dom_op;
    1.76 +	dom_op->cmd = dom_opcode;
    1.77 +	dom_op->interface_version = DOM0_INTERFACE_VERSION;
    1.78  
    1.79  	if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) {
    1.80  		perror("Failed to mlock privcmd structure");
    1.81  		return -1;
    1.82  	}
    1.83  
    1.84 -	if (mlock( op, sizeof(dom0_op_t)) < 0) {
    1.85 +	if (mlock( dom_op, sizeof(dom0_op_t)) < 0) {
    1.86  		perror("Failed to mlock dom0_op structure");
    1.87  		munlock( &privcmd, sizeof(privcmd_hypercall_t));
    1.88  		return -1;
    1.89 @@ -85,7 +132,7 @@ int xi_make_dom0_op(xi_handle *handle, d
    1.90  	}
    1.91  
    1.92  	munlock( &privcmd, sizeof(privcmd_hypercall_t));
    1.93 -	munlock( op, sizeof(dom0_op_t));
    1.94 +	munlock( dom_op, sizeof(dom0_op_t));
    1.95  
    1.96  	return ret;
    1.97  }
    1.98 @@ -142,3 +189,16 @@ long long xi_get_vcpu_usage(xi_handle *h
    1.99  
   1.100  	return op.u.getvcpucontext.cpu_time;
   1.101  }
   1.102 +
   1.103 +/* gets xen version information from hypervisor */
   1.104 +int xi_get_xen_version(xi_handle *handle, long *vnum, xen_extraversion_t *ver) 
   1.105 +{
   1.106 +
   1.107 +        /* gets the XENVER_version and XENVER_extraversion */
   1.108 +	if (xi_make_xen_version_hypercall( handle, vnum, ver) < 0) {; 
   1.109 +		perror("XEN VERSION Hypercall failed");
   1.110 +		return -1;
   1.111 +	}
   1.112 +
   1.113 +	return 0;
   1.114 +}
     2.1 --- a/tools/xenstat/libxenstat/src/xen-interface.h	Tue Aug 23 00:28:50 2005 +0100
     2.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.h	Tue Aug 23 02:10:59 2005 +0100
     2.3 @@ -27,6 +27,7 @@ typedef uint32_t u32;
     2.4  typedef uint64_t u64;
     2.5  
     2.6  #include "dom0_ops.h"
     2.7 +#include "version.h"
     2.8  
     2.9  /* Opaque handles */
    2.10  typedef struct xi_handle xi_handle;
    2.11 @@ -38,6 +39,9 @@ xi_handle *xi_init();
    2.12  /* Release the handle to libxc, free resources, etc. */
    2.13  void xi_uninit(xi_handle *handle);
    2.14  
    2.15 +/* Obtain xen version information from hypervisor */
    2.16 +int xi_get_xen_version(xi_handle *, long *vnum, xen_extraversion_t *ver);
    2.17 +
    2.18  /* Obtain physinfo data from dom0 */
    2.19  int xi_get_physinfo(xi_handle *, dom0_physinfo_t *);
    2.20  
     3.1 --- a/tools/xenstat/libxenstat/src/xenstat.c	Tue Aug 23 00:28:50 2005 +0100
     3.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c	Tue Aug 23 02:10:59 2005 +0100
     3.3 @@ -22,6 +22,7 @@
     3.4  #include <unistd.h>
     3.5  #include <xen-interface.h>
     3.6  #include "xenstat.h"
     3.7 +#include "version.h"
     3.8  
     3.9  /*
    3.10   * Types
    3.11 @@ -32,6 +33,9 @@ struct xenstat_handle {
    3.12  	FILE *procnetdev;
    3.13  };
    3.14  
    3.15 +#define SHORT_ASC_LEN 5 		/* length of 65535 */
    3.16 +#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1)
    3.17 +
    3.18  struct xenstat_node {
    3.19  	unsigned int flags;
    3.20  	unsigned long long cpu_hz;
    3.21 @@ -39,6 +43,7 @@ struct xenstat_node {
    3.22  	unsigned long long tot_mem;
    3.23  	unsigned long long free_mem;
    3.24  	unsigned int num_domains;
    3.25 +	char xen_version[VERSION_SIZE]; /* xen version running on this node */
    3.26  	xenstat_domain *domains;	/* Array of length num_domains */
    3.27  };
    3.28  
    3.29 @@ -47,7 +52,7 @@ struct xenstat_domain {
    3.30  	unsigned int state;
    3.31  	unsigned long long cpu_ns;
    3.32  	unsigned int num_vcpus;
    3.33 -	xenstat_vcpu *vcpus;	/* Array of length num_vcpus */
    3.34 +	xenstat_vcpu *vcpus;		/* Array of length num_vcpus */
    3.35  	unsigned long long cur_mem;	/* Current memory reservation */
    3.36  	unsigned long long max_mem;	/* Total memory allowed */
    3.37  	unsigned int ssid;
    3.38 @@ -164,6 +169,8 @@ xenstat_node *xenstat_get_node(xenstat_h
    3.39  #define DOMAIN_CHUNK_SIZE 256
    3.40  	xenstat_node *node;
    3.41  	dom0_physinfo_t physinfo;
    3.42 +	xen_extraversion_t version;
    3.43 +	long vnum = 0; 
    3.44  	dom0_getdomaininfo_t domaininfo[DOMAIN_CHUNK_SIZE];
    3.45  	unsigned int num_domains, new_domains;
    3.46  	unsigned int i;
    3.47 @@ -179,6 +186,14 @@ xenstat_node *xenstat_get_node(xenstat_h
    3.48  		return NULL;
    3.49  	}
    3.50  
    3.51 +	/* Get the xen version number and xen version tag */
    3.52 +	if (xi_get_xen_version(handle->xihandle, &vnum, &version) < 0) {
    3.53 +		free(node); 
    3.54 +		return NULL;
    3.55 +	} 
    3.56 +	snprintf(node->xen_version, VERSION_SIZE,
    3.57 +		"%ld.%ld%s\n", ((vnum >> 16) & 0xFFFF), vnum & 0xFFFF, (char *)version); 
    3.58 +
    3.59  	node->cpu_hz = ((unsigned long long)physinfo.cpu_khz) * 1000ULL;
    3.60  	node->num_cpus =
    3.61  	    (physinfo.threads_per_core * physinfo.cores_per_socket *
    3.62 @@ -247,8 +262,8 @@ xenstat_node *xenstat_get_node(xenstat_h
    3.63  			if(collectors[i].collect(handle, node) == 0) {
    3.64  				xenstat_free_node(node);
    3.65  				return NULL;
    3.66 -                        }
    3.67 -                }
    3.68 +			}
    3.69 +		}
    3.70  	}
    3.71  
    3.72  	return node;
    3.73 @@ -291,6 +306,11 @@ xenstat_domain *xenstat_node_domain_by_i
    3.74  	return NULL;
    3.75  }
    3.76  
    3.77 +const char *xenstat_node_xen_ver(xenstat_node * node)
    3.78 +{
    3.79 +	return node->xen_version;
    3.80 +}
    3.81 +
    3.82  unsigned long long xenstat_node_tot_mem(xenstat_node * node)
    3.83  {
    3.84  	return node->tot_mem;
     4.1 --- a/tools/xenstat/libxenstat/src/xenstat.h	Tue Aug 23 00:28:50 2005 +0100
     4.2 +++ b/tools/xenstat/libxenstat/src/xenstat.h	Tue Aug 23 02:10:59 2005 +0100
     4.3 @@ -51,6 +51,8 @@ xenstat_domain *xenstat_node_domain(xens
     4.4  /* Get the domain with the given index; used to loop over all domains. */
     4.5  xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node,
     4.6  					     unsigned index);
     4.7 +/* Get xen version of the node */
     4.8 +const char *xenstat_node_xen_ver(xenstat_node * node);
     4.9  
    4.10  /* Get amount of total memory on a node */
    4.11  unsigned long long xenstat_node_tot_mem(xenstat_node * node);