[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Cache the Xen version in the xenstat_handle, since it should never change.



# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID 9404574350ce3518052685cf5dd48c8aae415cf9
# Parent  af7251014caf505b58d470480fce04854d05e11e
Cache the Xen version in the xenstat_handle, since it should never change.
Use a collector and new flag for Xen version information, to avoid the
extra hypercall if the caller does not want the information.
Reference the xenstat_handle in the xenstat_node for ease of access
later, and update collectors accordingly.
Signed-off-by: Josh Triplett <josht@xxxxxxxxxx>
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>

diff -r af7251014caf -r 9404574350ce tools/xenstat/libxenstat/src/xenstat.c
--- a/tools/xenstat/libxenstat/src/xenstat.c    Fri Aug 26 08:47:49 2005
+++ b/tools/xenstat/libxenstat/src/xenstat.c    Fri Aug 26 08:48:59 2005
@@ -27,23 +27,24 @@
 /*
  * Types
  */
+#define SHORT_ASC_LEN 5                 /* length of 65535 */
+#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1)
+
 struct xenstat_handle {
        xi_handle *xihandle;
        int page_size;
        FILE *procnetdev;
+       char xen_version[VERSION_SIZE]; /* xen version running on this node */
 };
 
-#define SHORT_ASC_LEN 5                 /* length of 65535 */
-#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1)
-
 struct xenstat_node {
+       xenstat_handle *handle;
        unsigned int flags;
        unsigned long long cpu_hz;
        unsigned int num_cpus;
        unsigned long long tot_mem;
        unsigned long long free_mem;
        unsigned int num_domains;
-       char xen_version[VERSION_SIZE]; /* xen version running on this node */
        xenstat_domain *domains;        /* Array of length num_domains */
 };
 
@@ -83,8 +84,7 @@
  */
 /* Called to collect the information for the node and all the domains on
  * it. When called, the domain information has already been collected. */
-typedef int (*xenstat_collect_func)(xenstat_handle * handle,
-                                   xenstat_node * node);
+typedef int (*xenstat_collect_func)(xenstat_node * node);
 /* Called to free the information collected by the collect function.  The free
  * function will only be called on a xenstat_node if that node includes
  * information collected by the corresponding collector. */
@@ -101,20 +101,23 @@
        xenstat_uninit_func uninit;
 } xenstat_collector;
 
-static int  xenstat_collect_vcpus(xenstat_handle * handle,
-                                 xenstat_node * node);
-static int  xenstat_collect_networks(xenstat_handle * handle,
-                                   xenstat_node * node);
+static int  xenstat_collect_vcpus(xenstat_node * node);
+static int  xenstat_collect_networks(xenstat_node * node);
+static int  xenstat_collect_xen_version(xenstat_node * node);
 static void xenstat_free_vcpus(xenstat_node * node);
 static void xenstat_free_networks(xenstat_node * node);
+static void xenstat_free_xen_version(xenstat_node * node);
 static void xenstat_uninit_vcpus(xenstat_handle * handle);
 static void xenstat_uninit_networks(xenstat_handle * handle);
+static void xenstat_uninit_xen_version(xenstat_handle * handle);
 
 static xenstat_collector collectors[] = {
        { XENSTAT_VCPU, xenstat_collect_vcpus,
          xenstat_free_vcpus, xenstat_uninit_vcpus },
        { XENSTAT_NETWORK, xenstat_collect_networks,
-         xenstat_free_networks, xenstat_uninit_networks }
+         xenstat_free_networks, xenstat_uninit_networks },
+       { XENSTAT_XEN_VERSION, xenstat_collect_xen_version,
+         xenstat_free_xen_version, xenstat_uninit_xen_version }
 };
 
 #define NUM_COLLECTORS (sizeof(collectors)/sizeof(xenstat_collector))
@@ -169,8 +172,6 @@
 #define DOMAIN_CHUNK_SIZE 256
        xenstat_node *node;
        dom0_physinfo_t physinfo;
-       xen_extraversion_t version;
-       long vnum = 0;
        dom0_getdomaininfo_t domaininfo[DOMAIN_CHUNK_SIZE];
        unsigned int num_domains, new_domains;
        unsigned int i;
@@ -180,19 +181,14 @@
        if (node == NULL)
                return NULL;
 
+       /* Store the handle in the node for later access */
+       node->handle = handle;
+
        /* Get information about the physical system */
        if (xi_get_physinfo(handle->xihandle, &physinfo) < 0) {
                free(node);
                return NULL;
        }
-
-       /* Get the xen version number and xen version tag */
-       if (xi_get_xen_version(handle->xihandle, &vnum, &version) < 0) {
-               free(node);
-               return NULL;
-       }
-       snprintf(node->xen_version, VERSION_SIZE, "%ld.%ld%s\n",
-                ((vnum >> 16) & 0xFFFF), vnum & 0xFFFF, version);
 
        node->cpu_hz = ((unsigned long long)physinfo.cpu_khz) * 1000ULL;
        node->num_cpus =
@@ -259,7 +255,7 @@
        for (i = 0; i < NUM_COLLECTORS; i++) {
                if ((flags & collectors[i].flag) == collectors[i].flag) {
                        node->flags |= collectors[i].flag;
-                       if(collectors[i].collect(handle, node) == 0) {
+                       if(collectors[i].collect(node) == 0) {
                                xenstat_free_node(node);
                                return NULL;
                        }
@@ -306,9 +302,9 @@
        return NULL;
 }
 
-const char *xenstat_node_xen_ver(xenstat_node * node)
-{
-       return node->xen_version;
+const char *xenstat_node_xen_version(xenstat_node * node)
+{
+       return node->handle->xen_version;
 }
 
 unsigned long long xenstat_node_tot_mem(xenstat_node * node)
@@ -434,7 +430,7 @@
  * VCPU functions
  */
 /* Collect information about VCPUs */
-static int xenstat_collect_vcpus(xenstat_handle * handle, xenstat_node * node)
+static int xenstat_collect_vcpus(xenstat_node * node)
 {
        unsigned int i, vcpu;
        /* Fill in VCPU information */
@@ -447,10 +443,9 @@
                for (vcpu = 0; vcpu < node->domains[i].num_vcpus; vcpu++) {
                        /* FIXME: need to be using a more efficient mechanism*/
                        long long vcpu_time;
-                       vcpu_time =
-                           xi_get_vcpu_usage(handle->xihandle,
-                                             node->domains[i].id,
-                                             vcpu);
+                       vcpu_time = xi_get_vcpu_usage(node->handle->xihandle,
+                                                     node->domains[i].id,
+                                                     vcpu);
                        if (vcpu_time < 0)
                                return 0;
                        node->domains[i].vcpus[vcpu].ns = vcpu_time;
@@ -490,21 +485,20 @@
     "bytes    packets errs drop fifo colls carrier compressed\n";
 
 /* Collect information about networks */
-static int xenstat_collect_networks(xenstat_handle * handle,
-                                   xenstat_node * node)
+static int xenstat_collect_networks(xenstat_node * node)
 {
        /* Open and validate /proc/net/dev if we haven't already */
-       if (handle->procnetdev == NULL) {
+       if (node->handle->procnetdev == NULL) {
                char header[sizeof(PROCNETDEV_HEADER)];
-               handle->procnetdev = fopen("/proc/net/dev", "r");
-               if (handle->procnetdev == NULL) {
+               node->handle->procnetdev = fopen("/proc/net/dev", "r");
+               if (node->handle->procnetdev == NULL) {
                        perror("Error opening /proc/net/dev");
                        return 1;
                }
 
                /* Validate the format of /proc/net/dev */
                if (fread(header, sizeof(PROCNETDEV_HEADER) - 1, 1,
-                         handle->procnetdev) != 1) {
+                         node->handle->procnetdev) != 1) {
                        perror("Error reading /proc/net/dev header");
                        return 1;
                }
@@ -518,12 +512,13 @@
 
        /* Fill in networks */
        /* FIXME: optimize this */
-       fseek(handle->procnetdev, sizeof(PROCNETDEV_HEADER) - 1, SEEK_SET);
+       fseek(node->handle->procnetdev, sizeof(PROCNETDEV_HEADER) - 1,
+             SEEK_SET);
        while (1) {
                xenstat_domain *domain;
                xenstat_network net;
                unsigned int domid;
-               int ret = fscanf(handle->procnetdev,
+               int ret = fscanf(node->handle->procnetdev,
                                 "vif%u.%u:%llu%llu%llu%llu%*u%*u%*u%*u"
                                 "%llu%llu%llu%llu%*u%*u%*u%*u\n",
                                 &domid, &net.id,
@@ -536,7 +531,7 @@
                if (ret != 10) {
                        unsigned int c;
                        do {
-                               c = fgetc(handle->procnetdev);
+                               c = fgetc(node->handle->procnetdev);
                        } while (c != '\n' && c != EOF);
                        if (c == EOF)
                                break;
@@ -638,3 +633,37 @@
 {
        return network->tdrop;
 }
+
+/*
+ * Xen version functions
+ */
+
+/* Collect Xen version information */
+static int xenstat_collect_xen_version(xenstat_node * node)
+{
+       long vnum = 0;
+       xen_extraversion_t version;
+
+       /* Collect Xen version information if not already collected */
+       if (node->handle->xen_version[0] == '\0') {
+               /* Get the Xen version number and extraversion string */
+               if (xi_get_xen_version(node->handle->xihandle,
+                                      &vnum, &version) < 0)
+                       return 0;
+               /* Format the version information as a string and store it */
+               snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",
+                        ((vnum >> 16) & 0xFFFF), vnum & 0xFFFF, version);
+       }
+
+       return 1;
+}
+
+/* Free Xen version information in node - nothing to do */
+static void xenstat_free_xen_version(xenstat_node * node)
+{
+}
+
+/* Free Xen version information in handle - nothing to do */
+static void xenstat_uninit_xen_version(xenstat_handle * handle)
+{
+}
diff -r af7251014caf -r 9404574350ce tools/xenstat/libxenstat/src/xenstat.h
--- a/tools/xenstat/libxenstat/src/xenstat.h    Fri Aug 26 08:47:49 2005
+++ b/tools/xenstat/libxenstat/src/xenstat.h    Fri Aug 26 08:48:59 2005
@@ -31,10 +31,13 @@
 /* Release the handle to libxc, free resources, etc. */
 void xenstat_uninit(xenstat_handle * handle);
 
-/* Get all available information about a node */
+/* Flags for types of information to collect in xenstat_get_node */
 #define XENSTAT_VCPU 0x1
 #define XENSTAT_NETWORK 0x2
-#define XENSTAT_ALL (XENSTAT_VCPU|XENSTAT_NETWORK)
+#define XENSTAT_XEN_VERSION 0x4
+#define XENSTAT_ALL (XENSTAT_VCPU|XENSTAT_NETWORK|XENSTAT_XEN_VERSION)
+
+/* Get all available information about a node */
 xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags);
 
 /* Free the information */
@@ -53,7 +56,7 @@
                                             unsigned index);
 
 /* Get xen version of the node */
-const char *xenstat_node_xen_ver(xenstat_node * node);
+const char *xenstat_node_xen_version(xenstat_node * node);
 
 /* Get amount of total memory on a node */
 unsigned long long xenstat_node_tot_mem(xenstat_node * node);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.