ia64/xen-unstable

changeset 9915:7af8039b3c57

Fix perfc array range on reset.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue May 02 15:21:19 2006 +0100 (2006-05-02)
parents 24dbb153ab39
children 028f80cf0c99
files xen/common/perfc.c
line diff
     1.1 --- a/tools/xenstat/libxenstat/src/xen-interface.c	Tue May 02 15:12:06 2006 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,201 +0,0 @@
     1.4 -/* xen-interface.c
     1.5 - *
     1.6 - * Copyright (C) International Business Machines Corp., 2005
     1.7 - * Authors: Josh Triplett <josht@us.ibm.com>
     1.8 - *          Judy Fischbach <jfisch@us.ibm.com>
     1.9 - *
    1.10 - * This library is free software; you can redistribute it and/or
    1.11 - * modify it under the terms of the GNU Lesser General Public
    1.12 - * License as published by the Free Software Foundation; either
    1.13 - * version 2.1 of the License, or (at your option) any later version.
    1.14 - *
    1.15 - * This library is distributed in the hope that it will be useful,
    1.16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
    1.18 - * Lesser General Public License for more details.
    1.19 - */
    1.20 -
    1.21 -#include "xen-interface.h"
    1.22 -#include <fcntl.h>
    1.23 -#include <sys/ioctl.h>
    1.24 -#include <sys/mman.h>
    1.25 -#include <stdio.h>
    1.26 -#include <stdlib.h>
    1.27 -#include <string.h>
    1.28 -#include <unistd.h>
    1.29 -#include <xen/linux/privcmd.h>
    1.30 -
    1.31 -struct xi_handle {
    1.32 -	int fd;
    1.33 -};
    1.34 -
    1.35 -/* Initialize for xen-interface.  Returns a handle to be used with subsequent
    1.36 - * calls to the xen-interface functions or NULL if an error occurs. */
    1.37 -xi_handle *xi_init(void)
    1.38 -{
    1.39 -	xi_handle *handle;
    1.40 -
    1.41 -	handle = (xi_handle *)calloc(1, sizeof(xi_handle));
    1.42 -	if (handle == NULL)
    1.43 -		return NULL;
    1.44 -
    1.45 -	handle->fd = open("/proc/xen/privcmd", O_RDWR);
    1.46 -	if (handle->fd < 0) {
    1.47 -		perror("Couldn't open /proc/xen/privcmd");
    1.48 -		free(handle);
    1.49 -		return NULL;
    1.50 -	}
    1.51 -
    1.52 -	return handle;
    1.53 -}
    1.54 -
    1.55 -/* Release the handle to libxc, free resources, etc. */
    1.56 -void xi_uninit(xi_handle *handle)
    1.57 -{
    1.58 -	close (handle->fd);
    1.59 -	free (handle);
    1.60 -}
    1.61 -
    1.62 -/* Make simple xen version hypervisor calls */
    1.63 -static int xi_make_xen_version_hypercall(xi_handle *handle, long *vnum,
    1.64 -					 xen_extraversion_t *ver)
    1.65 -{
    1.66 -	privcmd_hypercall_t privcmd;
    1.67 -	int ret = 0;
    1.68 -
    1.69 -	if (mlock(&privcmd, sizeof(privcmd)) < 0) {
    1.70 -		perror("Failed to mlock privcmd structure");
    1.71 -		return -1;
    1.72 -	}
    1.73 -
    1.74 -	if (mlock(ver, sizeof(*ver)) < 0) {
    1.75 -		perror("Failed to mlock extraversion structure");
    1.76 -		munlock(&privcmd, sizeof(privcmd));
    1.77 -		return -1;
    1.78 -	}
    1.79 -
    1.80 -	privcmd.op = __HYPERVISOR_xen_version;
    1.81 -	privcmd.arg[0] = (unsigned long)XENVER_version;
    1.82 -	privcmd.arg[1] = 0;
    1.83 -
    1.84 -	*vnum = ioctl(handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd);
    1.85 -	if (*vnum < 0) {
    1.86 -		perror("Hypercall failed");
    1.87 -		ret = -1;
    1.88 -	}
    1.89 -
    1.90 -	privcmd.op = __HYPERVISOR_xen_version;
    1.91 -	privcmd.arg[0] = (unsigned long)XENVER_extraversion;
    1.92 -	privcmd.arg[1] = (unsigned long)ver;
    1.93 -
    1.94 -	if (ioctl(handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) {
    1.95 -		perror("Hypercall failed");
    1.96 -		ret = -1;
    1.97 -	}
    1.98 -
    1.99 -	munlock(&privcmd, sizeof(privcmd));
   1.100 -	munlock(ver, sizeof(*ver));
   1.101 -
   1.102 -	return ret;
   1.103 -}
   1.104 -
   1.105 -/* Make Xen Dom0 op hypervisor call */
   1.106 -static int xi_make_dom0_op(xi_handle *handle, dom0_op_t *dom_op,
   1.107 -			   int dom_opcode)
   1.108 -{
   1.109 -	privcmd_hypercall_t privcmd;
   1.110 -	int ret = 0;
   1.111 -
   1.112 -	/* set up for doing hypercall */
   1.113 -	privcmd.op = __HYPERVISOR_dom0_op;
   1.114 -	privcmd.arg[0] = (unsigned long)dom_op;
   1.115 -	dom_op->cmd = dom_opcode;
   1.116 -	dom_op->interface_version = DOM0_INTERFACE_VERSION;
   1.117 -
   1.118 -	if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) {
   1.119 -		perror("Failed to mlock privcmd structure");
   1.120 -		return -1;
   1.121 -	}
   1.122 -
   1.123 -	if (mlock( dom_op, sizeof(dom0_op_t)) < 0) {
   1.124 -		perror("Failed to mlock dom0_op structure");
   1.125 -		munlock( &privcmd, sizeof(privcmd_hypercall_t));
   1.126 -		return -1;
   1.127 -	}
   1.128 -
   1.129 -	if (ioctl( handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) {
   1.130 -		perror("Hypercall failed");
   1.131 -		ret = -1;
   1.132 -	}
   1.133 -
   1.134 -	munlock( &privcmd, sizeof(privcmd_hypercall_t));
   1.135 -	munlock( dom_op, sizeof(dom0_op_t));
   1.136 -
   1.137 -	return ret;
   1.138 -}
   1.139 -
   1.140 -/* Obtain domain data from dom0 */
   1.141 -int xi_get_physinfo(xi_handle *handle, dom0_physinfo_t *physinfo)
   1.142 -{
   1.143 -	dom0_op_t op;
   1.144 -
   1.145 -	if (xi_make_dom0_op(handle, &op, DOM0_PHYSINFO) < 0) {
   1.146 -		perror("DOM0_PHYSINFO Hypercall failed");
   1.147 -		return -1;
   1.148 -	}
   1.149 -
   1.150 -	*physinfo = op.u.physinfo;
   1.151 -	return 0;
   1.152 -}
   1.153 -
   1.154 -/* Obtain domain data from dom0 */
   1.155 -int xi_get_domaininfolist(xi_handle *handle, dom0_getdomaininfo_t *info,
   1.156 -                          unsigned int first_domain, unsigned int max_domains)
   1.157 -{
   1.158 -	dom0_op_t op;
   1.159 -	op.u.getdomaininfolist.first_domain = first_domain;
   1.160 -	op.u.getdomaininfolist.max_domains = max_domains;
   1.161 -	set_xen_guest_handle(op.u.getdomaininfolist.buffer, info);
   1.162 -
   1.163 -	if (mlock( info, max_domains * sizeof(dom0_getdomaininfo_t)) < 0) {
   1.164 -		perror("Failed to mlock domaininfo array");
   1.165 -		return -1;
   1.166 -	}
   1.167 -
   1.168 -	if (xi_make_dom0_op(handle, &op, DOM0_GETDOMAININFOLIST) < 0) {
   1.169 -		perror("DOM0_GETDOMAININFOLIST Hypercall failed");
   1.170 -		return -1;
   1.171 -	}
   1.172 -
   1.173 -	return op.u.getdomaininfolist.num_domains;
   1.174 -}
   1.175 -
   1.176 -/* Get vcpu info from a domain */
   1.177 -int xi_get_domain_vcpu_info(xi_handle *handle, unsigned int domain, 
   1.178 -                            unsigned int vcpu, dom0_getvcpuinfo_t *info)
   1.179 -{
   1.180 -	dom0_op_t op;
   1.181 -	op.u.getvcpuinfo.domain = domain;
   1.182 -	op.u.getvcpuinfo.vcpu   = vcpu;
   1.183 -
   1.184 -	if (xi_make_dom0_op(handle, &op, DOM0_GETVCPUINFO) < 0) {
   1.185 -		perror("DOM0_GETVCPUINFO Hypercall failed");
   1.186 -		return -1;
   1.187 -	}
   1.188 -
   1.189 -	memcpy(info, &op.u.getvcpuinfo, sizeof(dom0_getvcpuinfo_t));
   1.190 -
   1.191 -	return 0;
   1.192 -}
   1.193 -
   1.194 -/* gets xen version information from hypervisor */
   1.195 -int xi_get_xen_version(xi_handle *handle, long *vnum, xen_extraversion_t *ver)
   1.196 -{
   1.197 -	/* gets the XENVER_version and XENVER_extraversion */
   1.198 -	if (xi_make_xen_version_hypercall( handle, vnum, ver) < 0) {
   1.199 -		perror("XEN VERSION Hypercall failed");
   1.200 -		return -1;
   1.201 -	}
   1.202 -
   1.203 -	return 0;
   1.204 -}
     2.1 --- a/tools/xenstat/libxenstat/src/xen-interface.h	Tue May 02 15:12:06 2006 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,46 +0,0 @@
     2.4 -/* xen-interface.h
     2.5 - *
     2.6 - * Copyright (C) International Business Machines Corp., 2005
     2.7 - * Authors: Josh Triplett <josht@us.ibm.com>
     2.8 - *          Judy Fischbach <jfisch@us.ibm.com>
     2.9 - *
    2.10 - * This library is free software; you can redistribute it and/or
    2.11 - * modify it under the terms of the GNU Lesser General Public
    2.12 - * License as published by the Free Software Foundation; either
    2.13 - * version 2.1 of the License, or (at your option) any later version.
    2.14 - *
    2.15 - * This library is distributed in the hope that it will be useful,
    2.16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.18 - * Lesser General Public License for more details.
    2.19 - */
    2.20 -
    2.21 -#include <stdint.h>
    2.22 -#include <xen/xen.h>
    2.23 -#include <xen/dom0_ops.h>
    2.24 -#include <xen/sched.h>
    2.25 -#include <xen/version.h>
    2.26 -
    2.27 -/* Opaque handles */
    2.28 -typedef struct xi_handle xi_handle;
    2.29 -
    2.30 -/* Initialize for xen-interface.  Returns a handle to be used with subsequent
    2.31 - * calls to the xen-interface functions or NULL if an error occurs. */
    2.32 -xi_handle *xi_init(void);
    2.33 -
    2.34 -/* Release the handle to libxc, free resources, etc. */
    2.35 -void xi_uninit(xi_handle *handle);
    2.36 -
    2.37 -/* Obtain xen version information from hypervisor */
    2.38 -int xi_get_xen_version(xi_handle *, long *vnum, xen_extraversion_t *ver);
    2.39 -
    2.40 -/* Obtain physinfo data from dom0 */
    2.41 -int xi_get_physinfo(xi_handle *, dom0_physinfo_t *);
    2.42 -
    2.43 -/* Obtain domain data from dom0 */
    2.44 -int xi_get_domaininfolist(xi_handle *, dom0_getdomaininfo_t *, unsigned int,
    2.45 -                          unsigned int);
    2.46 -
    2.47 -/* Get vcpu info from a domain */
    2.48 -int xi_get_domain_vcpu_info(xi_handle *, unsigned int, unsigned int,
    2.49 -                            dom0_getvcpuinfo_t *);
     3.1 --- a/xen/common/perfc.c	Tue May 02 15:12:06 2006 +0100
     3.2 +++ b/xen/common/perfc.c	Tue May 02 15:21:19 2006 +0100
     3.3 @@ -116,7 +116,7 @@ void perfc_reset(unsigned char key)
     3.4              counters += NR_CPUS;
     3.5              break;
     3.6          case TYPE_ARRAY:
     3.7 -            for ( j = 0; j < NR_CPUS; j++ )
     3.8 +            for ( j = 0; j < perfc_info[i].nr_elements; j++ )
     3.9                  atomic_set(&counters[j],0);
    3.10          case TYPE_S_ARRAY:
    3.11              counters += perfc_info[i].nr_elements;