ia64/xen-unstable

changeset 12538:2f15fce77758

[XENOPROFILE] Split linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c into
linux-2.6-xen-sparse/drivers/xen/xenoprof/xenoprofile.c
without code changes except slight adjustment to compile.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author kfraser@localhost.localdomain
date Wed Nov 22 09:49:55 2006 +0000 (2006-11-22)
parents da5c5fc8908f
children b63584cc9376
files linux-2.6-xen-sparse/arch/i386/oprofile/Makefile linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c linux-2.6-xen-sparse/arch/x86_64/oprofile/Makefile linux-2.6-xen-sparse/drivers/xen/xenoprof/xenoprofile.c linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/xenoprof.h linux-2.6-xen-sparse/include/xen/xenoprof.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/i386/oprofile/Makefile	Wed Nov 22 09:48:42 2006 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/i386/oprofile/Makefile	Wed Nov 22 09:49:55 2006 +0000
     1.3 @@ -7,7 +7,10 @@ DRIVER_OBJS = $(addprefix ../../../drive
     1.4  		timer_int.o )
     1.5  
     1.6  ifdef CONFIG_XEN
     1.7 -oprofile-y				:= $(DRIVER_OBJS) xenoprof.o
     1.8 +XENOPROF_COMMON_OBJS = $(addprefix ../../../drivers/xen/xenoprof/, \
     1.9 +			 xenoprofile.o)
    1.10 +oprofile-y				:= $(DRIVER_OBJS) \
    1.11 +					   $(XENOPROF_COMMON_OBJS) xenoprof.o
    1.12  else 
    1.13  oprofile-y				:= $(DRIVER_OBJS) init.o backtrace.o
    1.14  oprofile-$(CONFIG_X86_LOCAL_APIC) 	+= nmi_int.o op_model_athlon.o \
     2.1 --- a/linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c	Wed Nov 22 09:48:42 2006 +0000
     2.2 +++ b/linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c	Wed Nov 22 09:49:55 2006 +0000
     2.3 @@ -9,481 +9,21 @@
     2.4   * Modified by Aravind Menon and Jose Renato Santos for Xen
     2.5   * These modifications are:
     2.6   * Copyright (C) 2005 Hewlett-Packard Co.
     2.7 + *
     2.8 + * x86-specific part
     2.9 + * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
    2.10 + *                    VA Linux Systems Japan K.K.
    2.11   */
    2.12  
    2.13 -#include <linux/init.h>
    2.14 -#include <linux/notifier.h>
    2.15 -#include <linux/smp.h>
    2.16  #include <linux/oprofile.h>
    2.17 -#include <linux/sysdev.h>
    2.18 -#include <linux/slab.h>
    2.19 -#include <linux/interrupt.h>
    2.20 -#include <linux/vmalloc.h>
    2.21 -#include <asm/nmi.h>
    2.22 -#include <asm/msr.h>
    2.23 -#include <asm/apic.h>
    2.24 -#include <asm/pgtable.h>
    2.25 -#include <xen/evtchn.h>
    2.26 +
    2.27 +#include <xen/xenoprof.h>
    2.28  #include "op_counter.h"
    2.29  
    2.30 -#include <xen/driver_util.h>
    2.31 -#include <xen/interface/xen.h>
    2.32 -#include <xen/interface/xenoprof.h>
    2.33 -#include <../../../drivers/oprofile/cpu_buffer.h>
    2.34 -#include <../../../drivers/oprofile/event_buffer.h>
    2.35 -
    2.36 -#define MAX_XENOPROF_SAMPLES 16
    2.37 -
    2.38 -static int xenoprof_start(void);
    2.39 -static void xenoprof_stop(void);
    2.40 -
    2.41 -static int xenoprof_enabled = 0;
    2.42 -static unsigned int num_events = 0;
    2.43 -static int is_primary = 0;
    2.44 -static int active_defined;
    2.45 -
    2.46 -/* sample buffers shared with Xen */
    2.47 -xenoprof_buf_t * xenoprof_buf[MAX_VIRT_CPUS];
    2.48 -/* Shared buffer area */
    2.49 -char * shared_buffer = NULL;
    2.50 -/* Number of buffers in shared area (one per VCPU) */
    2.51 -int nbuf;
    2.52 -/* Mappings of VIRQ_XENOPROF to irq number (per cpu) */
    2.53 -int ovf_irq[NR_CPUS];
    2.54 -/* cpu model type string - copied from Xen memory space on XENOPROF_init command */
    2.55 -char cpu_type[XENOPROF_CPU_TYPE_SIZE];
    2.56 -
    2.57 -/* Passive sample buffers shared with Xen */
    2.58 -xenoprof_buf_t *p_xenoprof_buf[MAX_OPROF_DOMAINS][MAX_VIRT_CPUS];
    2.59 -/* Passive shared buffer area */
    2.60 -char *p_shared_buffer[MAX_OPROF_DOMAINS];
    2.61 -
    2.62 -#ifdef CONFIG_PM
    2.63 -
    2.64 -static int xenoprof_suspend(struct sys_device * dev, pm_message_t state)
    2.65 -{
    2.66 -	if (xenoprof_enabled == 1)
    2.67 -		xenoprof_stop();
    2.68 -	return 0;
    2.69 -}
    2.70 -
    2.71 -
    2.72 -static int xenoprof_resume(struct sys_device * dev)
    2.73 -{
    2.74 -	if (xenoprof_enabled == 1)
    2.75 -		xenoprof_start();
    2.76 -	return 0;
    2.77 -}
    2.78 -
    2.79 -
    2.80 -static struct sysdev_class oprofile_sysclass = {
    2.81 -	set_kset_name("oprofile"),
    2.82 -	.resume		= xenoprof_resume,
    2.83 -	.suspend	= xenoprof_suspend
    2.84 -};
    2.85 -
    2.86 -
    2.87 -static struct sys_device device_oprofile = {
    2.88 -	.id	= 0,
    2.89 -	.cls	= &oprofile_sysclass,
    2.90 -};
    2.91 -
    2.92 -
    2.93 -static int __init init_driverfs(void)
    2.94 -{
    2.95 -	int error;
    2.96 -	if (!(error = sysdev_class_register(&oprofile_sysclass)))
    2.97 -		error = sysdev_register(&device_oprofile);
    2.98 -	return error;
    2.99 -}
   2.100 -
   2.101 -
   2.102 -static void __exit exit_driverfs(void)
   2.103 -{
   2.104 -	sysdev_unregister(&device_oprofile);
   2.105 -	sysdev_class_unregister(&oprofile_sysclass);
   2.106 -}
   2.107 -
   2.108 -#else
   2.109 -#define init_driverfs() do { } while (0)
   2.110 -#define exit_driverfs() do { } while (0)
   2.111 -#endif /* CONFIG_PM */
   2.112 -
   2.113 -unsigned long long oprofile_samples = 0;
   2.114 -unsigned long long p_oprofile_samples = 0;
   2.115 -
   2.116 -unsigned int pdomains;
   2.117 -struct xenoprof_passive passive_domains[MAX_OPROF_DOMAINS];
   2.118 -
   2.119 -static void xenoprof_add_pc(xenoprof_buf_t *buf, int is_passive)
   2.120 -{
   2.121 -	int head, tail, size;
   2.122 -
   2.123 -	head = buf->event_head;
   2.124 -	tail = buf->event_tail;
   2.125 -	size = buf->event_size;
   2.126 -
   2.127 -	if (tail > head) {
   2.128 -		while (tail < size) {
   2.129 -			oprofile_add_pc(buf->event_log[tail].eip,
   2.130 -					buf->event_log[tail].mode,
   2.131 -					buf->event_log[tail].event);
   2.132 -			if (!is_passive)
   2.133 -				oprofile_samples++;
   2.134 -			else
   2.135 -				p_oprofile_samples++;
   2.136 -			tail++;
   2.137 -		}
   2.138 -		tail = 0;
   2.139 -	}
   2.140 -	while (tail < head) {
   2.141 -		oprofile_add_pc(buf->event_log[tail].eip,
   2.142 -				buf->event_log[tail].mode,
   2.143 -				buf->event_log[tail].event);
   2.144 -		if (!is_passive)
   2.145 -			oprofile_samples++;
   2.146 -		else
   2.147 -			p_oprofile_samples++;
   2.148 -		tail++;
   2.149 -	}
   2.150 -
   2.151 -	buf->event_tail = tail;
   2.152 -}
   2.153 -
   2.154 -static void xenoprof_handle_passive(void)
   2.155 -{
   2.156 -	int i, j;
   2.157 -	int flag_domain, flag_switch = 0;
   2.158 -	
   2.159 -	for (i = 0; i < pdomains; i++) {
   2.160 -		flag_domain = 0;
   2.161 -		for (j = 0; j < passive_domains[i].nbuf; j++) {
   2.162 -			xenoprof_buf_t *buf = p_xenoprof_buf[i][j];
   2.163 -			if (buf->event_head == buf->event_tail)
   2.164 -				continue;
   2.165 -			if (!flag_domain) {
   2.166 -				if (!oprofile_add_domain_switch(passive_domains[i].
   2.167 -								domain_id))
   2.168 -					goto done;
   2.169 -				flag_domain = 1;
   2.170 -			}
   2.171 -			xenoprof_add_pc(buf, 1);
   2.172 -			flag_switch = 1;
   2.173 -		}
   2.174 -	}
   2.175 -done:
   2.176 -	if (flag_switch)
   2.177 -		oprofile_add_domain_switch(COORDINATOR_DOMAIN);
   2.178 -}
   2.179 -
   2.180 -static irqreturn_t 
   2.181 -xenoprof_ovf_interrupt(int irq, void * dev_id, struct pt_regs * regs)
   2.182 -{
   2.183 -	struct xenoprof_buf * buf;
   2.184 -	int cpu;
   2.185 -	static unsigned long flag;
   2.186 -
   2.187 -	cpu = smp_processor_id();
   2.188 -	buf = xenoprof_buf[cpu];
   2.189 -
   2.190 -	xenoprof_add_pc(buf, 0);
   2.191 -
   2.192 -	if (is_primary && !test_and_set_bit(0, &flag)) {
   2.193 -		xenoprof_handle_passive();
   2.194 -		smp_mb__before_clear_bit();
   2.195 -		clear_bit(0, &flag);
   2.196 -	}
   2.197 -
   2.198 -	return IRQ_HANDLED;
   2.199 -}
   2.200 -
   2.201 -
   2.202 -static void unbind_virq(void)
   2.203 -{
   2.204 -	int i;
   2.205 -
   2.206 -	for_each_cpu(i) {
   2.207 -		if (ovf_irq[i] >= 0) {
   2.208 -			unbind_from_irqhandler(ovf_irq[i], NULL);
   2.209 -			ovf_irq[i] = -1;
   2.210 -		}
   2.211 -	}
   2.212 -}
   2.213 -
   2.214 -
   2.215 -static int bind_virq(void)
   2.216 -{
   2.217 -	int i, result;
   2.218 -
   2.219 -	for_each_cpu(i) {
   2.220 -		result = bind_virq_to_irqhandler(VIRQ_XENOPROF,
   2.221 -						 i,
   2.222 -						 xenoprof_ovf_interrupt,
   2.223 -						 SA_INTERRUPT,
   2.224 -						 "xenoprof",
   2.225 -						 NULL);
   2.226 -
   2.227 -		if (result < 0) {
   2.228 -			unbind_virq();
   2.229 -			return result;
   2.230 -		}
   2.231 -
   2.232 -		ovf_irq[i] = result;
   2.233 -	}
   2.234 -		
   2.235 -	return 0;
   2.236 -}
   2.237 -
   2.238 -
   2.239 -static int map_xenoprof_buffer(int max_samples)
   2.240 -{
   2.241 -	struct xenoprof_get_buffer get_buffer;
   2.242 -	struct xenoprof_buf *buf;
   2.243 -	int npages, ret, i;
   2.244 -	struct vm_struct *area;
   2.245 -
   2.246 -	if ( shared_buffer )
   2.247 -		return 0;
   2.248 -
   2.249 -	get_buffer.max_samples = max_samples;
   2.250 -
   2.251 -	if ( (ret = HYPERVISOR_xenoprof_op(XENOPROF_get_buffer, &get_buffer)) )
   2.252 -		return ret;
   2.253 -
   2.254 -	nbuf = get_buffer.nbuf;
   2.255 -	npages = (get_buffer.bufsize * nbuf - 1) / PAGE_SIZE + 1;
   2.256 -
   2.257 -	area = alloc_vm_area(npages * PAGE_SIZE);
   2.258 -	if (area == NULL)
   2.259 -		return -ENOMEM;
   2.260 -
   2.261 -	if ( (ret = direct_kernel_remap_pfn_range(
   2.262 -		      (unsigned long)area->addr,
   2.263 -		      get_buffer.buf_maddr >> PAGE_SHIFT,
   2.264 -		      npages * PAGE_SIZE, __pgprot(_KERNPG_TABLE), DOMID_SELF)) ) {
   2.265 -		vunmap(area->addr);
   2.266 -		return ret;
   2.267 -	}
   2.268 -
   2.269 -	shared_buffer = area->addr;
   2.270 -	for (i=0; i< nbuf; i++) {
   2.271 -		buf = (struct xenoprof_buf*) 
   2.272 -			&shared_buffer[i * get_buffer.bufsize];
   2.273 -		BUG_ON(buf->vcpu_id >= MAX_VIRT_CPUS);
   2.274 -		xenoprof_buf[buf->vcpu_id] = buf;
   2.275 -	}
   2.276 -
   2.277 -	return 0;
   2.278 -}
   2.279 -
   2.280 -
   2.281 -static int xenoprof_setup(void)
   2.282 -{
   2.283 -	int ret;
   2.284 -	int i;
   2.285 -
   2.286 -	if ( (ret = map_xenoprof_buffer(MAX_XENOPROF_SAMPLES)) )
   2.287 -		return ret;
   2.288 -
   2.289 -	if ( (ret = bind_virq()) )
   2.290 -		return ret;
   2.291 -
   2.292 -	if (is_primary) {
   2.293 -		struct xenoprof_counter counter;
   2.294 -
   2.295 -		/* Define dom0 as an active domain if not done yet */
   2.296 -		if (!active_defined) {
   2.297 -			domid_t domid;
   2.298 -			ret = HYPERVISOR_xenoprof_op(XENOPROF_reset_active_list, NULL);
   2.299 -			if (ret)
   2.300 -				goto err;
   2.301 -			domid = 0;
   2.302 -			ret = HYPERVISOR_xenoprof_op(XENOPROF_set_active, &domid);
   2.303 -			if (ret)
   2.304 -				goto err;
   2.305 -			active_defined = 1;
   2.306 -		}
   2.307 -
   2.308 -		ret = HYPERVISOR_xenoprof_op(XENOPROF_reserve_counters, NULL);
   2.309 -		if (ret)
   2.310 -			goto err;
   2.311 -		for (i=0; i<num_events; i++) {
   2.312 -			counter.ind       = i;
   2.313 -			counter.count     = (uint64_t)counter_config[i].count;
   2.314 -			counter.enabled   = (uint32_t)counter_config[i].enabled;
   2.315 -			counter.event     = (uint32_t)counter_config[i].event;
   2.316 -			counter.kernel    = (uint32_t)counter_config[i].kernel;
   2.317 -			counter.user      = (uint32_t)counter_config[i].user;
   2.318 -			counter.unit_mask = (uint64_t)counter_config[i].unit_mask;
   2.319 -			HYPERVISOR_xenoprof_op(XENOPROF_counter, 
   2.320 -					       &counter);
   2.321 -		}
   2.322 -		ret = HYPERVISOR_xenoprof_op(XENOPROF_setup_events, NULL);
   2.323 -
   2.324 -		if (ret)
   2.325 -			goto err;
   2.326 -	}
   2.327 -
   2.328 -	ret = HYPERVISOR_xenoprof_op(XENOPROF_enable_virq, NULL);
   2.329 -	if (ret)
   2.330 -		goto err;
   2.331 -
   2.332 -	xenoprof_enabled = 1;
   2.333 -	return 0;
   2.334 - err:
   2.335 -	unbind_virq();
   2.336 -	return ret;
   2.337 -}
   2.338 -
   2.339 -
   2.340 -static void xenoprof_shutdown(void)
   2.341 -{
   2.342 -	xenoprof_enabled = 0;
   2.343 -
   2.344 -	HYPERVISOR_xenoprof_op(XENOPROF_disable_virq, NULL);
   2.345 -
   2.346 -	if (is_primary) {
   2.347 -		HYPERVISOR_xenoprof_op(XENOPROF_release_counters, NULL);
   2.348 -		active_defined = 0;
   2.349 -	}
   2.350 -
   2.351 -	unbind_virq();
   2.352 -
   2.353 -}
   2.354 -
   2.355 -
   2.356 -static int xenoprof_start(void)
   2.357 -{
   2.358 -	int ret = 0;
   2.359 -
   2.360 -	if (is_primary)
   2.361 -		ret = HYPERVISOR_xenoprof_op(XENOPROF_start, NULL);
   2.362 -
   2.363 -	return ret;
   2.364 -}
   2.365 -
   2.366 -
   2.367 -static void xenoprof_stop(void)
   2.368 -{
   2.369 -	if (is_primary)
   2.370 -		HYPERVISOR_xenoprof_op(XENOPROF_stop, NULL);
   2.371 -}
   2.372 -
   2.373 -
   2.374 -static int xenoprof_set_active(int * active_domains,
   2.375 -			       unsigned int adomains)
   2.376 -{
   2.377 -	int ret = 0;
   2.378 -	int i;
   2.379 -	int set_dom0 = 0;
   2.380 -	domid_t domid;
   2.381 -
   2.382 -	if (!is_primary)
   2.383 -		return 0;
   2.384 -
   2.385 -	if (adomains > MAX_OPROF_DOMAINS)
   2.386 -		return -E2BIG;
   2.387 -
   2.388 -	ret = HYPERVISOR_xenoprof_op(XENOPROF_reset_active_list, NULL);
   2.389 -	if (ret)
   2.390 -		return ret;
   2.391 -
   2.392 -	for (i=0; i<adomains; i++) {
   2.393 -		domid = active_domains[i];
   2.394 -		if (domid != active_domains[i]) {
   2.395 -			ret = -EINVAL;
   2.396 -			goto out;
   2.397 -		}
   2.398 -		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_active, &domid);
   2.399 -		if (ret)
   2.400 -			goto out;
   2.401 -		if (active_domains[i] == 0)
   2.402 -			set_dom0 = 1;
   2.403 -	}
   2.404 -	/* dom0 must always be active but may not be in the list */ 
   2.405 -	if (!set_dom0) {
   2.406 -		domid = 0;
   2.407 -		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_active, &domid);
   2.408 -	}
   2.409 -
   2.410 -out:
   2.411 -	if (ret)
   2.412 -		HYPERVISOR_xenoprof_op(XENOPROF_reset_active_list, NULL);
   2.413 -	active_defined = !ret;
   2.414 -	return ret;
   2.415 -}
   2.416 -
   2.417 -static int xenoprof_set_passive(int * p_domains,
   2.418 -                                unsigned int pdoms)
   2.419 -{
   2.420 -	int ret;
   2.421 -	int i, j;
   2.422 -	int npages;
   2.423 -	struct xenoprof_buf *buf;
   2.424 -	struct vm_struct *area;
   2.425 -	pgprot_t prot = __pgprot(_KERNPG_TABLE);
   2.426 -
   2.427 -	if (!is_primary)
   2.428 -        	return 0;
   2.429 -
   2.430 -	if (pdoms > MAX_OPROF_DOMAINS)
   2.431 -		return -E2BIG;
   2.432 -
   2.433 -	ret = HYPERVISOR_xenoprof_op(XENOPROF_reset_passive_list, NULL);
   2.434 -	if (ret)
   2.435 -		return ret;
   2.436 -
   2.437 -	for (i = 0; i < pdoms; i++) {
   2.438 -		passive_domains[i].domain_id = p_domains[i];
   2.439 -		passive_domains[i].max_samples = 2048;
   2.440 -		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_passive,
   2.441 -					     &passive_domains[i]);
   2.442 -		if (ret)
   2.443 -			goto out;
   2.444 -
   2.445 -		npages = (passive_domains[i].bufsize * passive_domains[i].nbuf - 1) / PAGE_SIZE + 1;
   2.446 -
   2.447 -		area = alloc_vm_area(npages * PAGE_SIZE);
   2.448 -		if (area == NULL) {
   2.449 -			ret = -ENOMEM;
   2.450 -			goto out;
   2.451 -		}
   2.452 -
   2.453 -		ret = direct_kernel_remap_pfn_range(
   2.454 -			(unsigned long)area->addr,
   2.455 -			passive_domains[i].buf_maddr >> PAGE_SHIFT,
   2.456 -			npages * PAGE_SIZE, prot, DOMID_SELF);
   2.457 -		if (ret) {
   2.458 -			vunmap(area->addr);
   2.459 -			goto out;
   2.460 -		}
   2.461 -
   2.462 -		p_shared_buffer[i] = area->addr;
   2.463 -
   2.464 -		for (j = 0; j < passive_domains[i].nbuf; j++) {
   2.465 -			buf = (struct xenoprof_buf *)
   2.466 -				&p_shared_buffer[i][j * passive_domains[i].bufsize];
   2.467 -			BUG_ON(buf->vcpu_id >= MAX_VIRT_CPUS);
   2.468 -			p_xenoprof_buf[i][buf->vcpu_id] = buf;
   2.469 -		}
   2.470 -
   2.471 -	}
   2.472 -
   2.473 -	pdomains = pdoms;
   2.474 -	return 0;
   2.475 -
   2.476 -out:
   2.477 -	for (j = 0; j < i; j++) {
   2.478 -		vunmap(p_shared_buffer[j]);
   2.479 -		p_shared_buffer[j] = NULL;
   2.480 -	}
   2.481 -
   2.482 - 	return ret;
   2.483 -}
   2.484 -
   2.485 +unsigned int num_events = 0;
   2.486  struct op_counter_config counter_config[OP_MAX_COUNTER];
   2.487  
   2.488 -static int xenoprof_create_files(struct super_block * sb, struct dentry * root)
   2.489 +int xenoprof_create_files(struct super_block * sb, struct dentry * root)
   2.490  {
   2.491  	unsigned int i;
   2.492  
   2.493 @@ -509,76 +49,3 @@ static int xenoprof_create_files(struct 
   2.494  
   2.495  	return 0;
   2.496  }
   2.497 -
   2.498 -
   2.499 -struct oprofile_operations xenoprof_ops = {
   2.500 -	.create_files 	= xenoprof_create_files,
   2.501 -	.set_active	= xenoprof_set_active,
   2.502 -	.set_passive    = xenoprof_set_passive,
   2.503 -	.setup 		= xenoprof_setup,
   2.504 -	.shutdown	= xenoprof_shutdown,
   2.505 -	.start		= xenoprof_start,
   2.506 -	.stop		= xenoprof_stop
   2.507 -};
   2.508 -
   2.509 -
   2.510 -/* in order to get driverfs right */
   2.511 -static int using_xenoprof;
   2.512 -
   2.513 -int __init oprofile_arch_init(struct oprofile_operations * ops)
   2.514 -{
   2.515 -	struct xenoprof_init init;
   2.516 -	int ret, i;
   2.517 -
   2.518 -	ret = HYPERVISOR_xenoprof_op(XENOPROF_init, &init);
   2.519 -
   2.520 -	if (!ret) {
   2.521 -		num_events = init.num_events;
   2.522 -		is_primary = init.is_primary;
   2.523 -
   2.524 -		/* just in case - make sure we do not overflow event list 
   2.525 -		   (i.e. counter_config list) */
   2.526 -		if (num_events > OP_MAX_COUNTER)
   2.527 -			num_events = OP_MAX_COUNTER;
   2.528 -
   2.529 -		/*  cpu_type is detected by Xen */
   2.530 -		cpu_type[XENOPROF_CPU_TYPE_SIZE-1] = 0;
   2.531 -		strncpy(cpu_type, init.cpu_type, XENOPROF_CPU_TYPE_SIZE - 1);
   2.532 -		xenoprof_ops.cpu_type = cpu_type;
   2.533 -
   2.534 -		init_driverfs();
   2.535 -		using_xenoprof = 1;
   2.536 -		*ops = xenoprof_ops;
   2.537 -
   2.538 -		for (i=0; i<NR_CPUS; i++)
   2.539 -			ovf_irq[i] = -1;
   2.540 -
   2.541 -		active_defined = 0;
   2.542 -	}
   2.543 -	printk(KERN_INFO "oprofile_arch_init: ret %d, events %d, "
   2.544 -	       "is_primary %d\n", ret, num_events, is_primary);
   2.545 -	return ret;
   2.546 -}
   2.547 -
   2.548 -
   2.549 -void __exit oprofile_arch_exit(void)
   2.550 -{
   2.551 -	int i;
   2.552 -
   2.553 -	if (using_xenoprof)
   2.554 -		exit_driverfs();
   2.555 -
   2.556 -	if (shared_buffer) {
   2.557 -		vunmap(shared_buffer);
   2.558 -		shared_buffer = NULL;
   2.559 -	}
   2.560 -	if (is_primary) {
   2.561 -		for (i = 0; i < pdomains; i++)
   2.562 -			if (p_shared_buffer[i]) {
   2.563 -		                vunmap(p_shared_buffer[i]);
   2.564 -                		p_shared_buffer[i] = NULL;
   2.565 -			}
   2.566 -		HYPERVISOR_xenoprof_op(XENOPROF_shutdown, NULL);
   2.567 -        }
   2.568 -
   2.569 -}
     3.1 --- a/linux-2.6-xen-sparse/arch/x86_64/oprofile/Makefile	Wed Nov 22 09:48:42 2006 +0000
     3.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/oprofile/Makefile	Wed Nov 22 09:49:55 2006 +0000
     3.3 @@ -12,6 +12,8 @@ DRIVER_OBJS = $(addprefix ../../../drive
     3.4  	timer_int.o )
     3.5  
     3.6  ifdef CONFIG_XEN
     3.7 +XENOPROF_COMMON_OBJS = $(addprefix ../../../drivers/xen/xenoprof/, \
     3.8 +			 xenoprofile.o)
     3.9  OPROFILE-y := xenoprof.o
    3.10  else
    3.11  OPROFILE-y := init.o backtrace.o
    3.12 @@ -19,4 +21,5 @@ OPROFILE-$(CONFIG_X86_LOCAL_APIC) += nmi
    3.13  				     op_model_ppro.o
    3.14  OPROFILE-$(CONFIG_X86_IO_APIC)    += nmi_timer_int.o 
    3.15  endif
    3.16 -oprofile-y = $(DRIVER_OBJS) $(addprefix ../../i386/oprofile/, $(OPROFILE-y))
    3.17 +oprofile-y = $(DRIVER_OBJS) $(XENOPROF_COMMON_OBJS) \
    3.18 +	     $(addprefix ../../i386/oprofile/, $(OPROFILE-y))
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenoprof/xenoprofile.c	Wed Nov 22 09:49:55 2006 +0000
     4.3 @@ -0,0 +1,559 @@
     4.4 +/**
     4.5 + * @file xenoprof.c
     4.6 + *
     4.7 + * @remark Copyright 2002 OProfile authors
     4.8 + * @remark Read the file COPYING
     4.9 + *
    4.10 + * @author John Levon <levon@movementarian.org>
    4.11 + *
    4.12 + * Modified by Aravind Menon and Jose Renato Santos for Xen
    4.13 + * These modifications are:
    4.14 + * Copyright (C) 2005 Hewlett-Packard Co.
    4.15 + *
    4.16 + * Separated out arch-generic part
    4.17 + * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
    4.18 + *                    VA Linux Systems Japan K.K.
    4.19 + */
    4.20 +
    4.21 +#include <linux/init.h>
    4.22 +#include <linux/notifier.h>
    4.23 +#include <linux/smp.h>
    4.24 +#include <linux/oprofile.h>
    4.25 +#include <linux/sysdev.h>
    4.26 +#include <linux/slab.h>
    4.27 +#include <linux/interrupt.h>
    4.28 +#include <linux/vmalloc.h>
    4.29 +#include <asm/nmi.h>
    4.30 +#include <asm/msr.h>
    4.31 +#include <asm/apic.h>
    4.32 +#include <asm/pgtable.h>
    4.33 +#include <xen/evtchn.h>
    4.34 +#include <xen/xenoprof.h>
    4.35 +#include "../../../arch/i386/oprofile/op_counter.h"
    4.36 +
    4.37 +#include <xen/driver_util.h>
    4.38 +#include <xen/interface/xen.h>
    4.39 +#include <xen/interface/xenoprof.h>
    4.40 +#include "../../../drivers/oprofile/cpu_buffer.h"
    4.41 +#include "../../../drivers/oprofile/event_buffer.h"
    4.42 +
    4.43 +#define MAX_XENOPROF_SAMPLES 16
    4.44 +
    4.45 +static int xenoprof_start(void);
    4.46 +static void xenoprof_stop(void);
    4.47 +
    4.48 +static int xenoprof_enabled = 0;
    4.49 +extern unsigned int num_events;
    4.50 +static int is_primary = 0;
    4.51 +static int active_defined;
    4.52 +
    4.53 +/* sample buffers shared with Xen */
    4.54 +xenoprof_buf_t * xenoprof_buf[MAX_VIRT_CPUS];
    4.55 +/* Shared buffer area */
    4.56 +char * shared_buffer = NULL;
    4.57 +/* Number of buffers in shared area (one per VCPU) */
    4.58 +int nbuf;
    4.59 +/* Mappings of VIRQ_XENOPROF to irq number (per cpu) */
    4.60 +int ovf_irq[NR_CPUS];
    4.61 +/* cpu model type string - copied from Xen memory space on XENOPROF_init command */
    4.62 +char cpu_type[XENOPROF_CPU_TYPE_SIZE];
    4.63 +
    4.64 +/* Passive sample buffers shared with Xen */
    4.65 +xenoprof_buf_t *p_xenoprof_buf[MAX_OPROF_DOMAINS][MAX_VIRT_CPUS];
    4.66 +/* Passive shared buffer area */
    4.67 +char *p_shared_buffer[MAX_OPROF_DOMAINS];
    4.68 +
    4.69 +#ifdef CONFIG_PM
    4.70 +
    4.71 +static int xenoprof_suspend(struct sys_device * dev, pm_message_t state)
    4.72 +{
    4.73 +	if (xenoprof_enabled == 1)
    4.74 +		xenoprof_stop();
    4.75 +	return 0;
    4.76 +}
    4.77 +
    4.78 +
    4.79 +static int xenoprof_resume(struct sys_device * dev)
    4.80 +{
    4.81 +	if (xenoprof_enabled == 1)
    4.82 +		xenoprof_start();
    4.83 +	return 0;
    4.84 +}
    4.85 +
    4.86 +
    4.87 +static struct sysdev_class oprofile_sysclass = {
    4.88 +	set_kset_name("oprofile"),
    4.89 +	.resume		= xenoprof_resume,
    4.90 +	.suspend	= xenoprof_suspend
    4.91 +};
    4.92 +
    4.93 +
    4.94 +static struct sys_device device_oprofile = {
    4.95 +	.id	= 0,
    4.96 +	.cls	= &oprofile_sysclass,
    4.97 +};
    4.98 +
    4.99 +
   4.100 +static int __init init_driverfs(void)
   4.101 +{
   4.102 +	int error;
   4.103 +	if (!(error = sysdev_class_register(&oprofile_sysclass)))
   4.104 +		error = sysdev_register(&device_oprofile);
   4.105 +	return error;
   4.106 +}
   4.107 +
   4.108 +
   4.109 +static void __exit exit_driverfs(void)
   4.110 +{
   4.111 +	sysdev_unregister(&device_oprofile);
   4.112 +	sysdev_class_unregister(&oprofile_sysclass);
   4.113 +}
   4.114 +
   4.115 +#else
   4.116 +#define init_driverfs() do { } while (0)
   4.117 +#define exit_driverfs() do { } while (0)
   4.118 +#endif /* CONFIG_PM */
   4.119 +
   4.120 +unsigned long long oprofile_samples = 0;
   4.121 +unsigned long long p_oprofile_samples = 0;
   4.122 +
   4.123 +unsigned int pdomains;
   4.124 +struct xenoprof_passive passive_domains[MAX_OPROF_DOMAINS];
   4.125 +
   4.126 +static void xenoprof_add_pc(xenoprof_buf_t *buf, int is_passive)
   4.127 +{
   4.128 +	int head, tail, size;
   4.129 +
   4.130 +	head = buf->event_head;
   4.131 +	tail = buf->event_tail;
   4.132 +	size = buf->event_size;
   4.133 +
   4.134 +	if (tail > head) {
   4.135 +		while (tail < size) {
   4.136 +			oprofile_add_pc(buf->event_log[tail].eip,
   4.137 +					buf->event_log[tail].mode,
   4.138 +					buf->event_log[tail].event);
   4.139 +			if (!is_passive)
   4.140 +				oprofile_samples++;
   4.141 +			else
   4.142 +				p_oprofile_samples++;
   4.143 +			tail++;
   4.144 +		}
   4.145 +		tail = 0;
   4.146 +	}
   4.147 +	while (tail < head) {
   4.148 +		oprofile_add_pc(buf->event_log[tail].eip,
   4.149 +				buf->event_log[tail].mode,
   4.150 +				buf->event_log[tail].event);
   4.151 +		if (!is_passive)
   4.152 +			oprofile_samples++;
   4.153 +		else
   4.154 +			p_oprofile_samples++;
   4.155 +		tail++;
   4.156 +	}
   4.157 +
   4.158 +	buf->event_tail = tail;
   4.159 +}
   4.160 +
   4.161 +static void xenoprof_handle_passive(void)
   4.162 +{
   4.163 +	int i, j;
   4.164 +	int flag_domain, flag_switch = 0;
   4.165 +	
   4.166 +	for (i = 0; i < pdomains; i++) {
   4.167 +		flag_domain = 0;
   4.168 +		for (j = 0; j < passive_domains[i].nbuf; j++) {
   4.169 +			xenoprof_buf_t *buf = p_xenoprof_buf[i][j];
   4.170 +			if (buf->event_head == buf->event_tail)
   4.171 +				continue;
   4.172 +			if (!flag_domain) {
   4.173 +				if (!oprofile_add_domain_switch(passive_domains[i].
   4.174 +								domain_id))
   4.175 +					goto done;
   4.176 +				flag_domain = 1;
   4.177 +			}
   4.178 +			xenoprof_add_pc(buf, 1);
   4.179 +			flag_switch = 1;
   4.180 +		}
   4.181 +	}
   4.182 +done:
   4.183 +	if (flag_switch)
   4.184 +		oprofile_add_domain_switch(COORDINATOR_DOMAIN);
   4.185 +}
   4.186 +
   4.187 +static irqreturn_t 
   4.188 +xenoprof_ovf_interrupt(int irq, void * dev_id, struct pt_regs * regs)
   4.189 +{
   4.190 +	struct xenoprof_buf * buf;
   4.191 +	int cpu;
   4.192 +	static unsigned long flag;
   4.193 +
   4.194 +	cpu = smp_processor_id();
   4.195 +	buf = xenoprof_buf[cpu];
   4.196 +
   4.197 +	xenoprof_add_pc(buf, 0);
   4.198 +
   4.199 +	if (is_primary && !test_and_set_bit(0, &flag)) {
   4.200 +		xenoprof_handle_passive();
   4.201 +		smp_mb__before_clear_bit();
   4.202 +		clear_bit(0, &flag);
   4.203 +	}
   4.204 +
   4.205 +	return IRQ_HANDLED;
   4.206 +}
   4.207 +
   4.208 +
   4.209 +static void unbind_virq(void)
   4.210 +{
   4.211 +	int i;
   4.212 +
   4.213 +	for_each_cpu(i) {
   4.214 +		if (ovf_irq[i] >= 0) {
   4.215 +			unbind_from_irqhandler(ovf_irq[i], NULL);
   4.216 +			ovf_irq[i] = -1;
   4.217 +		}
   4.218 +	}
   4.219 +}
   4.220 +
   4.221 +
   4.222 +static int bind_virq(void)
   4.223 +{
   4.224 +	int i, result;
   4.225 +
   4.226 +	for_each_cpu(i) {
   4.227 +		result = bind_virq_to_irqhandler(VIRQ_XENOPROF,
   4.228 +						 i,
   4.229 +						 xenoprof_ovf_interrupt,
   4.230 +						 SA_INTERRUPT,
   4.231 +						 "xenoprof",
   4.232 +						 NULL);
   4.233 +
   4.234 +		if (result < 0) {
   4.235 +			unbind_virq();
   4.236 +			return result;
   4.237 +		}
   4.238 +
   4.239 +		ovf_irq[i] = result;
   4.240 +	}
   4.241 +		
   4.242 +	return 0;
   4.243 +}
   4.244 +
   4.245 +
   4.246 +static int map_xenoprof_buffer(int max_samples)
   4.247 +{
   4.248 +	struct xenoprof_get_buffer get_buffer;
   4.249 +	struct xenoprof_buf *buf;
   4.250 +	int npages, ret, i;
   4.251 +	struct vm_struct *area;
   4.252 +
   4.253 +	if ( shared_buffer )
   4.254 +		return 0;
   4.255 +
   4.256 +	get_buffer.max_samples = max_samples;
   4.257 +
   4.258 +	if ( (ret = HYPERVISOR_xenoprof_op(XENOPROF_get_buffer, &get_buffer)) )
   4.259 +		return ret;
   4.260 +
   4.261 +	nbuf = get_buffer.nbuf;
   4.262 +	npages = (get_buffer.bufsize * nbuf - 1) / PAGE_SIZE + 1;
   4.263 +
   4.264 +	area = alloc_vm_area(npages * PAGE_SIZE);
   4.265 +	if (area == NULL)
   4.266 +		return -ENOMEM;
   4.267 +
   4.268 +	if ( (ret = direct_kernel_remap_pfn_range(
   4.269 +		      (unsigned long)area->addr,
   4.270 +		      get_buffer.buf_maddr >> PAGE_SHIFT,
   4.271 +		      npages * PAGE_SIZE, __pgprot(_KERNPG_TABLE), DOMID_SELF)) ) {
   4.272 +		vunmap(area->addr);
   4.273 +		return ret;
   4.274 +	}
   4.275 +
   4.276 +	shared_buffer = area->addr;
   4.277 +	for (i=0; i< nbuf; i++) {
   4.278 +		buf = (struct xenoprof_buf*) 
   4.279 +			&shared_buffer[i * get_buffer.bufsize];
   4.280 +		BUG_ON(buf->vcpu_id >= MAX_VIRT_CPUS);
   4.281 +		xenoprof_buf[buf->vcpu_id] = buf;
   4.282 +	}
   4.283 +
   4.284 +	return 0;
   4.285 +}
   4.286 +
   4.287 +
   4.288 +static int xenoprof_setup(void)
   4.289 +{
   4.290 +	int ret;
   4.291 +	int i;
   4.292 +
   4.293 +	if ( (ret = map_xenoprof_buffer(MAX_XENOPROF_SAMPLES)) )
   4.294 +		return ret;
   4.295 +
   4.296 +	if ( (ret = bind_virq()) )
   4.297 +		return ret;
   4.298 +
   4.299 +	if (is_primary) {
   4.300 +		struct xenoprof_counter counter;
   4.301 +
   4.302 +		/* Define dom0 as an active domain if not done yet */
   4.303 +		if (!active_defined) {
   4.304 +			domid_t domid;
   4.305 +			ret = HYPERVISOR_xenoprof_op(XENOPROF_reset_active_list, NULL);
   4.306 +			if (ret)
   4.307 +				goto err;
   4.308 +			domid = 0;
   4.309 +			ret = HYPERVISOR_xenoprof_op(XENOPROF_set_active, &domid);
   4.310 +			if (ret)
   4.311 +				goto err;
   4.312 +			active_defined = 1;
   4.313 +		}
   4.314 +
   4.315 +		ret = HYPERVISOR_xenoprof_op(XENOPROF_reserve_counters, NULL);
   4.316 +		if (ret)
   4.317 +			goto err;
   4.318 +		for (i=0; i<num_events; i++) {
   4.319 +			counter.ind       = i;
   4.320 +			counter.count     = (uint64_t)counter_config[i].count;
   4.321 +			counter.enabled   = (uint32_t)counter_config[i].enabled;
   4.322 +			counter.event     = (uint32_t)counter_config[i].event;
   4.323 +			counter.kernel    = (uint32_t)counter_config[i].kernel;
   4.324 +			counter.user      = (uint32_t)counter_config[i].user;
   4.325 +			counter.unit_mask = (uint64_t)counter_config[i].unit_mask;
   4.326 +			HYPERVISOR_xenoprof_op(XENOPROF_counter, 
   4.327 +					       &counter);
   4.328 +		}
   4.329 +		ret = HYPERVISOR_xenoprof_op(XENOPROF_setup_events, NULL);
   4.330 +
   4.331 +		if (ret)
   4.332 +			goto err;
   4.333 +	}
   4.334 +
   4.335 +	ret = HYPERVISOR_xenoprof_op(XENOPROF_enable_virq, NULL);
   4.336 +	if (ret)
   4.337 +		goto err;
   4.338 +
   4.339 +	xenoprof_enabled = 1;
   4.340 +	return 0;
   4.341 + err:
   4.342 +	unbind_virq();
   4.343 +	return ret;
   4.344 +}
   4.345 +
   4.346 +
   4.347 +static void xenoprof_shutdown(void)
   4.348 +{
   4.349 +	xenoprof_enabled = 0;
   4.350 +
   4.351 +	HYPERVISOR_xenoprof_op(XENOPROF_disable_virq, NULL);
   4.352 +
   4.353 +	if (is_primary) {
   4.354 +		HYPERVISOR_xenoprof_op(XENOPROF_release_counters, NULL);
   4.355 +		active_defined = 0;
   4.356 +	}
   4.357 +
   4.358 +	unbind_virq();
   4.359 +
   4.360 +}
   4.361 +
   4.362 +
   4.363 +static int xenoprof_start(void)
   4.364 +{
   4.365 +	int ret = 0;
   4.366 +
   4.367 +	if (is_primary)
   4.368 +		ret = HYPERVISOR_xenoprof_op(XENOPROF_start, NULL);
   4.369 +
   4.370 +	return ret;
   4.371 +}
   4.372 +
   4.373 +
   4.374 +static void xenoprof_stop(void)
   4.375 +{
   4.376 +	if (is_primary)
   4.377 +		HYPERVISOR_xenoprof_op(XENOPROF_stop, NULL);
   4.378 +}
   4.379 +
   4.380 +
   4.381 +static int xenoprof_set_active(int * active_domains,
   4.382 +			       unsigned int adomains)
   4.383 +{
   4.384 +	int ret = 0;
   4.385 +	int i;
   4.386 +	int set_dom0 = 0;
   4.387 +	domid_t domid;
   4.388 +
   4.389 +	if (!is_primary)
   4.390 +		return 0;
   4.391 +
   4.392 +	if (adomains > MAX_OPROF_DOMAINS)
   4.393 +		return -E2BIG;
   4.394 +
   4.395 +	ret = HYPERVISOR_xenoprof_op(XENOPROF_reset_active_list, NULL);
   4.396 +	if (ret)
   4.397 +		return ret;
   4.398 +
   4.399 +	for (i=0; i<adomains; i++) {
   4.400 +		domid = active_domains[i];
   4.401 +		if (domid != active_domains[i]) {
   4.402 +			ret = -EINVAL;
   4.403 +			goto out;
   4.404 +		}
   4.405 +		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_active, &domid);
   4.406 +		if (ret)
   4.407 +			goto out;
   4.408 +		if (active_domains[i] == 0)
   4.409 +			set_dom0 = 1;
   4.410 +	}
   4.411 +	/* dom0 must always be active but may not be in the list */ 
   4.412 +	if (!set_dom0) {
   4.413 +		domid = 0;
   4.414 +		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_active, &domid);
   4.415 +	}
   4.416 +
   4.417 +out:
   4.418 +	if (ret)
   4.419 +		HYPERVISOR_xenoprof_op(XENOPROF_reset_active_list, NULL);
   4.420 +	active_defined = !ret;
   4.421 +	return ret;
   4.422 +}
   4.423 +
   4.424 +static int xenoprof_set_passive(int * p_domains,
   4.425 +                                unsigned int pdoms)
   4.426 +{
   4.427 +	int ret;
   4.428 +	int i, j;
   4.429 +	int npages;
   4.430 +	struct xenoprof_buf *buf;
   4.431 +	struct vm_struct *area;
   4.432 +	pgprot_t prot = __pgprot(_KERNPG_TABLE);
   4.433 +
   4.434 +	if (!is_primary)
   4.435 +        	return 0;
   4.436 +
   4.437 +	if (pdoms > MAX_OPROF_DOMAINS)
   4.438 +		return -E2BIG;
   4.439 +
   4.440 +	ret = HYPERVISOR_xenoprof_op(XENOPROF_reset_passive_list, NULL);
   4.441 +	if (ret)
   4.442 +		return ret;
   4.443 +
   4.444 +	for (i = 0; i < pdoms; i++) {
   4.445 +		passive_domains[i].domain_id = p_domains[i];
   4.446 +		passive_domains[i].max_samples = 2048;
   4.447 +		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_passive,
   4.448 +					     &passive_domains[i]);
   4.449 +		if (ret)
   4.450 +			goto out;
   4.451 +
   4.452 +		npages = (passive_domains[i].bufsize * passive_domains[i].nbuf - 1) / PAGE_SIZE + 1;
   4.453 +
   4.454 +		area = alloc_vm_area(npages * PAGE_SIZE);
   4.455 +		if (area == NULL) {
   4.456 +			ret = -ENOMEM;
   4.457 +			goto out;
   4.458 +		}
   4.459 +
   4.460 +		ret = direct_kernel_remap_pfn_range(
   4.461 +			(unsigned long)area->addr,
   4.462 +			passive_domains[i].buf_maddr >> PAGE_SHIFT,
   4.463 +			npages * PAGE_SIZE, prot, DOMID_SELF);
   4.464 +		if (ret) {
   4.465 +			vunmap(area->addr);
   4.466 +			goto out;
   4.467 +		}
   4.468 +
   4.469 +		p_shared_buffer[i] = area->addr;
   4.470 +
   4.471 +		for (j = 0; j < passive_domains[i].nbuf; j++) {
   4.472 +			buf = (struct xenoprof_buf *)
   4.473 +				&p_shared_buffer[i][j * passive_domains[i].bufsize];
   4.474 +			BUG_ON(buf->vcpu_id >= MAX_VIRT_CPUS);
   4.475 +			p_xenoprof_buf[i][buf->vcpu_id] = buf;
   4.476 +		}
   4.477 +
   4.478 +	}
   4.479 +
   4.480 +	pdomains = pdoms;
   4.481 +	return 0;
   4.482 +
   4.483 +out:
   4.484 +	for (j = 0; j < i; j++) {
   4.485 +		vunmap(p_shared_buffer[j]);
   4.486 +		p_shared_buffer[j] = NULL;
   4.487 +	}
   4.488 +
   4.489 + 	return ret;
   4.490 +}
   4.491 +
   4.492 +struct oprofile_operations xenoprof_ops = {
   4.493 +	.create_files 	= xenoprof_create_files,
   4.494 +	.set_active	= xenoprof_set_active,
   4.495 +	.set_passive    = xenoprof_set_passive,
   4.496 +	.setup 		= xenoprof_setup,
   4.497 +	.shutdown	= xenoprof_shutdown,
   4.498 +	.start		= xenoprof_start,
   4.499 +	.stop		= xenoprof_stop
   4.500 +};
   4.501 +
   4.502 +
   4.503 +/* in order to get driverfs right */
   4.504 +static int using_xenoprof;
   4.505 +
   4.506 +int __init oprofile_arch_init(struct oprofile_operations * ops)
   4.507 +{
   4.508 +	struct xenoprof_init init;
   4.509 +	int ret, i;
   4.510 +
   4.511 +	ret = HYPERVISOR_xenoprof_op(XENOPROF_init, &init);
   4.512 +
   4.513 +	if (!ret) {
   4.514 +		num_events = init.num_events;
   4.515 +		is_primary = init.is_primary;
   4.516 +
   4.517 +		/* just in case - make sure we do not overflow event list 
   4.518 +		   (i.e. counter_config list) */
   4.519 +		if (num_events > OP_MAX_COUNTER)
   4.520 +			num_events = OP_MAX_COUNTER;
   4.521 +
   4.522 +		/*  cpu_type is detected by Xen */
   4.523 +		cpu_type[XENOPROF_CPU_TYPE_SIZE-1] = 0;
   4.524 +		strncpy(cpu_type, init.cpu_type, XENOPROF_CPU_TYPE_SIZE - 1);
   4.525 +		xenoprof_ops.cpu_type = cpu_type;
   4.526 +
   4.527 +		init_driverfs();
   4.528 +		using_xenoprof = 1;
   4.529 +		*ops = xenoprof_ops;
   4.530 +
   4.531 +		for (i=0; i<NR_CPUS; i++)
   4.532 +			ovf_irq[i] = -1;
   4.533 +
   4.534 +		active_defined = 0;
   4.535 +	}
   4.536 +	printk(KERN_INFO "oprofile_arch_init: ret %d, events %d, "
   4.537 +	       "is_primary %d\n", ret, num_events, is_primary);
   4.538 +	return ret;
   4.539 +}
   4.540 +
   4.541 +
   4.542 +void __exit oprofile_arch_exit(void)
   4.543 +{
   4.544 +	int i;
   4.545 +
   4.546 +	if (using_xenoprof)
   4.547 +		exit_driverfs();
   4.548 +
   4.549 +	if (shared_buffer) {
   4.550 +		vunmap(shared_buffer);
   4.551 +		shared_buffer = NULL;
   4.552 +	}
   4.553 +	if (is_primary) {
   4.554 +		for (i = 0; i < pdomains; i++)
   4.555 +			if (p_shared_buffer[i]) {
   4.556 +		                vunmap(p_shared_buffer[i]);
   4.557 +                		p_shared_buffer[i] = NULL;
   4.558 +			}
   4.559 +		HYPERVISOR_xenoprof_op(XENOPROF_shutdown, NULL);
   4.560 +        }
   4.561 +
   4.562 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/xenoprof.h	Wed Nov 22 09:49:55 2006 +0000
     5.3 @@ -0,0 +1,31 @@
     5.4 +/******************************************************************************
     5.5 + * asm-i386/mach-xen/asm/xenoprof.h
     5.6 + *
     5.7 + * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
     5.8 + *                    VA Linux Systems Japan K.K.
     5.9 + *
    5.10 + * This program is free software; you can redistribute it and/or modify
    5.11 + * it under the terms of the GNU General Public License as published by
    5.12 + * the Free Software Foundation; either version 2 of the License, or
    5.13 + * (at your option) any later version.
    5.14 + *
    5.15 + * This program is distributed in the hope that it will be useful,
    5.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.18 + * GNU General Public License for more details.
    5.19 + *
    5.20 + * You should have received a copy of the GNU General Public License
    5.21 + * along with this program; if not, write to the Free Software
    5.22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.23 + *
    5.24 + */
    5.25 +#ifndef __ASM_XENOPROF_H__
    5.26 +#define __ASM_XENOPROF_H__
    5.27 +#ifdef CONFIG_OPROFILE 
    5.28 +
    5.29 +struct super_block;
    5.30 +struct dentry;
    5.31 +int xenoprof_create_files(struct super_block * sb, struct dentry * root);
    5.32 +
    5.33 +#endif /* CONFIG_OPROFILE */
    5.34 +#endif /* __ASM_XENOPROF_H__ */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/linux-2.6-xen-sparse/include/xen/xenoprof.h	Wed Nov 22 09:49:55 2006 +0000
     6.3 @@ -0,0 +1,30 @@
     6.4 +/******************************************************************************
     6.5 + * xen/xenoprof.h
     6.6 + *
     6.7 + * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
     6.8 + *                    VA Linux Systems Japan K.K.
     6.9 + *
    6.10 + * This program is free software; you can redistribute it and/or modify
    6.11 + * it under the terms of the GNU General Public License as published by
    6.12 + * the Free Software Foundation; either version 2 of the License, or
    6.13 + * (at your option) any later version.
    6.14 + *
    6.15 + * This program is distributed in the hope that it will be useful,
    6.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.18 + * GNU General Public License for more details.
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License
    6.21 + * along with this program; if not, write to the Free Software
    6.22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.23 + *
    6.24 + */
    6.25 +
    6.26 +#ifndef __XEN_XENOPROF_H__
    6.27 +#define __XEN_XENOPROF_H__
    6.28 +#ifdef CONFIG_OPROFILE
    6.29 +
    6.30 +#include <asm/xenoprof.h>
    6.31 +
    6.32 +#endif /* CONFIG_OPROFILE */
    6.33 +#endif /* __XEN_XENOPROF_H__ */