ia64/xen-unstable
changeset 6379:6783e59e1c45
xenstat/xentop merge.
line diff
163.1 --- a/tools/xenstat/libxenstat/src/xen-interface.c Mon Aug 22 23:07:37 2005 +0000 163.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.c Tue Aug 23 18:25:51 2005 +0000 163.3 @@ -21,7 +21,9 @@ 163.4 #include <sys/mman.h> 163.5 #include <stdio.h> 163.6 #include <stdlib.h> 163.7 +#include <string.h> 163.8 #include <unistd.h> 163.9 +#include "version.h" 163.10 #include "privcmd.h" 163.11 #include "xen.h" 163.12 163.13 @@ -56,24 +58,69 @@ void xi_uninit(xi_handle *handle) 163.14 free (handle); 163.15 } 163.16 163.17 -/* Make Xen hypervisor call */ 163.18 -int xi_make_dom0_op(xi_handle *handle, dom0_op_t *op, int opcode) 163.19 +/* Make simple xen version hypervisor calls */ 163.20 +static int xi_make_xen_version_hypercall(xi_handle *handle, long *vnum, xen_extraversion_t *ver) 163.21 +{ 163.22 + privcmd_hypercall_t privcmd; 163.23 + multicall_entry_t multicall[2]; 163.24 + int ret = 0; 163.25 + 163.26 + /* set up for doing hypercall */ 163.27 + privcmd.op = __HYPERVISOR_multicall; 163.28 + privcmd.arg[0] = (unsigned long)multicall; 163.29 + privcmd.arg[1] = 2; 163.30 + 163.31 + /* first one to get xen version number */ 163.32 + multicall[0].op = __HYPERVISOR_xen_version; 163.33 + multicall[0].args[0] = (unsigned long)XENVER_version; 163.34 + 163.35 + /* second to get xen version flag */ 163.36 + multicall[1].op = __HYPERVISOR_xen_version; 163.37 + multicall[1].args[0] = (unsigned long)XENVER_extraversion; 163.38 + multicall[1].args[1] = (unsigned long)ver; 163.39 + 163.40 + if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) { 163.41 + perror("Failed to mlock privcmd structure"); 163.42 + return -1; 163.43 + } 163.44 + 163.45 + if (mlock( multicall, sizeof(multicall_entry_t)) < 0) { 163.46 + perror("Failed to mlock multicall_entry structure"); 163.47 + munlock( &multicall, sizeof(multicall_entry_t)); 163.48 + return -1; 163.49 + } 163.50 + 163.51 + if (ioctl( handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) { 163.52 + perror("Hypercall failed"); 163.53 + ret = -1; 163.54 + } 163.55 + 163.56 + *vnum = multicall[0].result; 163.57 + 163.58 + munlock( &privcmd, sizeof(privcmd_hypercall_t)); 163.59 + munlock( &multicall, sizeof(multicall_entry_t)); 163.60 + 163.61 + return ret; 163.62 +} 163.63 + 163.64 +/* Make Xen Dom0 op hypervisor call */ 163.65 +static int xi_make_dom0_op(xi_handle *handle, dom0_op_t *dom_op, int dom_opcode) 163.66 { 163.67 privcmd_hypercall_t privcmd; 163.68 int ret = 0; 163.69 163.70 /* set up for doing hypercall */ 163.71 privcmd.op = __HYPERVISOR_dom0_op; 163.72 - privcmd.arg[0] = (unsigned long)op; 163.73 - op->cmd = opcode; 163.74 - op->interface_version = DOM0_INTERFACE_VERSION; 163.75 + privcmd.arg[0] = (unsigned long)dom_op; 163.76 + dom_op->cmd = dom_opcode; 163.77 + dom_op->interface_version = DOM0_INTERFACE_VERSION; 163.78 163.79 if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) { 163.80 perror("Failed to mlock privcmd structure"); 163.81 return -1; 163.82 } 163.83 163.84 - if (mlock( op, sizeof(dom0_op_t)) < 0) { 163.85 + if (mlock( dom_op, sizeof(dom0_op_t)) < 0) { 163.86 perror("Failed to mlock dom0_op structure"); 163.87 munlock( &privcmd, sizeof(privcmd_hypercall_t)); 163.88 return -1; 163.89 @@ -85,7 +132,7 @@ int xi_make_dom0_op(xi_handle *handle, d 163.90 } 163.91 163.92 munlock( &privcmd, sizeof(privcmd_hypercall_t)); 163.93 - munlock( op, sizeof(dom0_op_t)); 163.94 + munlock( dom_op, sizeof(dom0_op_t)); 163.95 163.96 return ret; 163.97 } 163.98 @@ -142,3 +189,16 @@ long long xi_get_vcpu_usage(xi_handle *h 163.99 163.100 return op.u.getvcpucontext.cpu_time; 163.101 } 163.102 + 163.103 +/* gets xen version information from hypervisor */ 163.104 +int xi_get_xen_version(xi_handle *handle, long *vnum, xen_extraversion_t *ver) 163.105 +{ 163.106 + 163.107 + /* gets the XENVER_version and XENVER_extraversion */ 163.108 + if (xi_make_xen_version_hypercall( handle, vnum, ver) < 0) {; 163.109 + perror("XEN VERSION Hypercall failed"); 163.110 + return -1; 163.111 + } 163.112 + 163.113 + return 0; 163.114 +}
164.1 --- a/tools/xenstat/libxenstat/src/xen-interface.h Mon Aug 22 23:07:37 2005 +0000 164.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.h Tue Aug 23 18:25:51 2005 +0000 164.3 @@ -27,6 +27,7 @@ typedef uint32_t u32; 164.4 typedef uint64_t u64; 164.5 164.6 #include "dom0_ops.h" 164.7 +#include "version.h" 164.8 164.9 /* Opaque handles */ 164.10 typedef struct xi_handle xi_handle; 164.11 @@ -38,6 +39,9 @@ xi_handle *xi_init(); 164.12 /* Release the handle to libxc, free resources, etc. */ 164.13 void xi_uninit(xi_handle *handle); 164.14 164.15 +/* Obtain xen version information from hypervisor */ 164.16 +int xi_get_xen_version(xi_handle *, long *vnum, xen_extraversion_t *ver); 164.17 + 164.18 /* Obtain physinfo data from dom0 */ 164.19 int xi_get_physinfo(xi_handle *, dom0_physinfo_t *); 164.20
165.1 --- a/tools/xenstat/libxenstat/src/xenstat.c Mon Aug 22 23:07:37 2005 +0000 165.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c Tue Aug 23 18:25:51 2005 +0000 165.3 @@ -22,6 +22,7 @@ 165.4 #include <unistd.h> 165.5 #include <xen-interface.h> 165.6 #include "xenstat.h" 165.7 +#include "version.h" 165.8 165.9 /* 165.10 * Types 165.11 @@ -32,6 +33,9 @@ struct xenstat_handle { 165.12 FILE *procnetdev; 165.13 }; 165.14 165.15 +#define SHORT_ASC_LEN 5 /* length of 65535 */ 165.16 +#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1) 165.17 + 165.18 struct xenstat_node { 165.19 unsigned int flags; 165.20 unsigned long long cpu_hz; 165.21 @@ -39,6 +43,7 @@ struct xenstat_node { 165.22 unsigned long long tot_mem; 165.23 unsigned long long free_mem; 165.24 unsigned int num_domains; 165.25 + char xen_version[VERSION_SIZE]; /* xen version running on this node */ 165.26 xenstat_domain *domains; /* Array of length num_domains */ 165.27 }; 165.28 165.29 @@ -47,7 +52,7 @@ struct xenstat_domain { 165.30 unsigned int state; 165.31 unsigned long long cpu_ns; 165.32 unsigned int num_vcpus; 165.33 - xenstat_vcpu *vcpus; /* Array of length num_vcpus */ 165.34 + xenstat_vcpu *vcpus; /* Array of length num_vcpus */ 165.35 unsigned long long cur_mem; /* Current memory reservation */ 165.36 unsigned long long max_mem; /* Total memory allowed */ 165.37 unsigned int ssid; 165.38 @@ -164,6 +169,8 @@ xenstat_node *xenstat_get_node(xenstat_h 165.39 #define DOMAIN_CHUNK_SIZE 256 165.40 xenstat_node *node; 165.41 dom0_physinfo_t physinfo; 165.42 + xen_extraversion_t version; 165.43 + long vnum = 0; 165.44 dom0_getdomaininfo_t domaininfo[DOMAIN_CHUNK_SIZE]; 165.45 unsigned int num_domains, new_domains; 165.46 unsigned int i; 165.47 @@ -179,6 +186,14 @@ xenstat_node *xenstat_get_node(xenstat_h 165.48 return NULL; 165.49 } 165.50 165.51 + /* Get the xen version number and xen version tag */ 165.52 + if (xi_get_xen_version(handle->xihandle, &vnum, &version) < 0) { 165.53 + free(node); 165.54 + return NULL; 165.55 + } 165.56 + snprintf(node->xen_version, VERSION_SIZE, 165.57 + "%ld.%ld%s\n", ((vnum >> 16) & 0xFFFF), vnum & 0xFFFF, (char *)version); 165.58 + 165.59 node->cpu_hz = ((unsigned long long)physinfo.cpu_khz) * 1000ULL; 165.60 node->num_cpus = 165.61 (physinfo.threads_per_core * physinfo.cores_per_socket * 165.62 @@ -247,8 +262,8 @@ xenstat_node *xenstat_get_node(xenstat_h 165.63 if(collectors[i].collect(handle, node) == 0) { 165.64 xenstat_free_node(node); 165.65 return NULL; 165.66 - } 165.67 - } 165.68 + } 165.69 + } 165.70 } 165.71 165.72 return node; 165.73 @@ -291,6 +306,11 @@ xenstat_domain *xenstat_node_domain_by_i 165.74 return NULL; 165.75 } 165.76 165.77 +const char *xenstat_node_xen_ver(xenstat_node * node) 165.78 +{ 165.79 + return node->xen_version; 165.80 +} 165.81 + 165.82 unsigned long long xenstat_node_tot_mem(xenstat_node * node) 165.83 { 165.84 return node->tot_mem; 165.85 @@ -505,7 +525,7 @@ static int xenstat_collect_networks(xens 165.86 unsigned int domid; 165.87 int ret = fscanf(handle->procnetdev, 165.88 "vif%u.%u:%llu%llu%llu%llu%*u%*u%*u%*u" 165.89 - "%llu%llu%llu%llu%*u%*u%*u%*u", 165.90 + "%llu%llu%llu%llu%*u%*u%*u%*u\n", 165.91 &domid, &net.id, 165.92 &net.tbytes, &net.tpackets, &net.terrs, 165.93 &net.tdrop,
166.1 --- a/tools/xenstat/libxenstat/src/xenstat.h Mon Aug 22 23:07:37 2005 +0000 166.2 +++ b/tools/xenstat/libxenstat/src/xenstat.h Tue Aug 23 18:25:51 2005 +0000 166.3 @@ -51,6 +51,8 @@ xenstat_domain *xenstat_node_domain(xens 166.4 /* Get the domain with the given index; used to loop over all domains. */ 166.5 xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node, 166.6 unsigned index); 166.7 +/* Get xen version of the node */ 166.8 +const char *xenstat_node_xen_ver(xenstat_node * node); 166.9 166.10 /* Get amount of total memory on a node */ 166.11 unsigned long long xenstat_node_tot_mem(xenstat_node * node);
169.1 --- a/tools/xenstat/xentop/xentop.1 Mon Aug 22 23:07:37 2005 +0000 169.2 +++ b/tools/xenstat/xentop/xentop.1 Tue Aug 23 18:25:51 2005 +0000 169.3 @@ -40,7 +40,7 @@ display help and exit 169.4 output version information and exit 169.5 .TP 169.6 \fB\-d\fR, \fB\-\-delay\fR=\fISECONDS\fR 169.7 -seconds between updates (default 1) 169.8 +seconds between updates (default 3) 169.9 .TP 169.10 \fB\-n\fR, \fB\-\-networks\fR 169.11 output network information
170.1 --- a/tools/xenstat/xentop/xentop.c Mon Aug 22 23:07:37 2005 +0000 170.2 +++ b/tools/xenstat/xentop/xentop.c Tue Aug 23 18:25:51 2005 +0000 170.3 @@ -151,7 +151,7 @@ xenstat_node *prev_node = NULL; 170.4 xenstat_node *cur_node = NULL; 170.5 field_id sort_field = FIELD_DOMID; 170.6 unsigned int first_domain_index = 0; 170.7 -unsigned int delay = 1; 170.8 +unsigned int delay = 3; 170.9 int show_vcpus = 0; 170.10 int show_networks = 0; 170.11 int repeat_header = 0; 170.12 @@ -174,7 +174,7 @@ static void usage(const char *program) 170.13 "Displays ongoing information about xen vm resources \n\n" 170.14 "-h, --help display this help and exit\n" 170.15 "-V, --version output version information and exit\n" 170.16 - "-d, --delay=SECONDS seconds between updates (default 1)\n" 170.17 + "-d, --delay=SECONDS seconds between updates (default 3)\n" 170.18 "-n, --networks output vif network data\n" 170.19 "-r, --repeat-header repeat table header before each domain\n" 170.20 "-v, --vcpus output vcpu data\n" 170.21 @@ -254,7 +254,7 @@ static void attr_addstr(int attr, const 170.22 static void set_delay(char *value) 170.23 { 170.24 int new_delay; 170.25 - new_delay = atoi(prompt_val); 170.26 + new_delay = atoi(value); 170.27 if(new_delay > 0) 170.28 delay = new_delay; 170.29 }