ia64/xen-unstable

changeset 12630:fe565ac4bf25

[IA64] xenoprof linux/ia64 part

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author awilliam@xenbuild.aw
date Tue Nov 28 22:54:24 2006 -0700 (2006-11-28)
parents 8ab9b43ad557
children 775fea0a4f16
files linux-2.6-xen-sparse/arch/ia64/kernel/perfmon.c linux-2.6-xen-sparse/arch/ia64/oprofile/Makefile linux-2.6-xen-sparse/arch/ia64/oprofile/init.c linux-2.6-xen-sparse/arch/ia64/oprofile/oprofile_perfmon.h linux-2.6-xen-sparse/arch/ia64/oprofile/perfmon.c linux-2.6-xen-sparse/arch/ia64/oprofile/xenoprof.c linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c linux-2.6-xen-sparse/arch/ia64/xen/xcom_hcall.c linux-2.6-xen-sparse/arch/ia64/xen/xcom_mini.c linux-2.6-xen-sparse/include/asm-ia64/hypercall.h linux-2.6-xen-sparse/include/asm-ia64/xen/xcom_hcall.h linux-2.6-xen-sparse/include/asm-ia64/xenoprof.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/ia64/kernel/perfmon.c	Tue Nov 28 21:35:13 2006 -0700
     1.2 +++ b/linux-2.6-xen-sparse/arch/ia64/kernel/perfmon.c	Tue Nov 28 22:54:24 2006 -0700
     1.3 @@ -53,6 +53,28 @@
     1.4  #include <asm/delay.h>
     1.5  
     1.6  #ifdef CONFIG_PERFMON
     1.7 +#ifdef CONFIG_XEN
     1.8 +//#include <xen/xenoprof.h>
     1.9 +#include <xen/interface/xenoprof.h>
    1.10 +
    1.11 +static int xenoprof_is_primary = 0;
    1.12 +#define init_xenoprof_primary(is_primary)  (xenoprof_is_primary = (is_primary))
    1.13 +#define is_xenoprof_primary()	(xenoprof_is_primary)
    1.14 +#define XEN_NOT_SUPPORTED_YET						\
    1.15 +	do {								\
    1.16 +		if (is_running_on_xen()) {				\
    1.17 +			printk("%s is not supported yet under xen.\n",	\
    1.18 +			       __func__);				\
    1.19 +			return -ENOSYS;					\
    1.20 +		}							\
    1.21 +	} while (0)
    1.22 +#else
    1.23 +#define init_xenoprof_primary(is_primary)	do { } while (0)
    1.24 +#define is_xenoprof_primary()			(0)
    1.25 +#define XEN_NOT_SUPPORTED_YET			do { } while (0)
    1.26 +#define HYPERVISOR_perfmon_op(cmd, arg, count)	do { } while (0)
    1.27 +#endif
    1.28 +
    1.29  /*
    1.30   * perfmon context state
    1.31   */
    1.32 @@ -1515,6 +1537,7 @@ pfm_read(struct file *filp, char __user 
    1.33  	ssize_t ret;
    1.34  	unsigned long flags;
    1.35    	DECLARE_WAITQUEUE(wait, current);
    1.36 +	XEN_NOT_SUPPORTED_YET;
    1.37  	if (PFM_IS_FILE(filp) == 0) {
    1.38  		printk(KERN_ERR "perfmon: pfm_poll: bad magic [%d]\n", current->pid);
    1.39  		return -EINVAL;
    1.40 @@ -2113,6 +2136,15 @@ doit:
    1.41  	 */
    1.42  	if (free_possible) pfm_context_free(ctx);
    1.43  
    1.44 +	if (is_running_on_xen()) {
    1.45 +		if (is_xenoprof_primary()) {
    1.46 +			int ret = HYPERVISOR_perfmon_op(PFM_DESTROY_CONTEXT,
    1.47 +			                                NULL, 0);
    1.48 +			if (ret)
    1.49 +				printk("%s:%d PFM_DESTROY_CONTEXT hypercall "
    1.50 +				       "failed\n", __func__, __LINE__);
    1.51 +		}
    1.52 +	}
    1.53  	return 0;
    1.54  }
    1.55  
    1.56 @@ -2736,6 +2768,23 @@ pfm_context_create(pfm_context_t *ctx, v
    1.57  	 */
    1.58  	pfm_reset_pmu_state(ctx);
    1.59  
    1.60 +	if (is_running_on_xen()) {
    1.61 +		/*
    1.62 +		 * kludge to get xenoprof.is_primary.
    1.63 +		 * XENOPROF_init/ia64 is nop. so it is safe to call it here.
    1.64 +		 */
    1.65 +		struct xenoprof_init init;
    1.66 +		ret = HYPERVISOR_xenoprof_op(XENOPROF_init, &init);
    1.67 +		if (ret)
    1.68 +			goto buffer_error;
    1.69 +		init_xenoprof_primary(init.is_primary);
    1.70 +
    1.71 +		if (is_xenoprof_primary()) {
    1.72 +			ret = HYPERVISOR_perfmon_op(PFM_CREATE_CONTEXT, arg, 0);
    1.73 +			if (ret)
    1.74 +				goto buffer_error;
    1.75 +		}
    1.76 +	}
    1.77  	return 0;
    1.78  
    1.79  buffer_error:
    1.80 @@ -2872,6 +2921,12 @@ pfm_write_pmcs(pfm_context_t *ctx, void 
    1.81  	pfm_reg_check_t	wr_func;
    1.82  #define PFM_CHECK_PMC_PM(x, y, z) ((x)->ctx_fl_system ^ PMC_PM(y, z))
    1.83  
    1.84 +  	if (is_running_on_xen()) {
    1.85 +		if (is_xenoprof_primary())
    1.86 +			return HYPERVISOR_perfmon_op(PFM_WRITE_PMCS,
    1.87 +			                             arg, count);
    1.88 +		return 0;
    1.89 +  	}
    1.90  	state     = ctx->ctx_state;
    1.91  	is_loaded = state == PFM_CTX_LOADED ? 1 : 0;
    1.92  	is_system = ctx->ctx_fl_system;
    1.93 @@ -3112,6 +3167,12 @@ pfm_write_pmds(pfm_context_t *ctx, void 
    1.94  	int ret = -EINVAL;
    1.95  	pfm_reg_check_t wr_func;
    1.96  
    1.97 +  	if (is_running_on_xen()) {
    1.98 +		if (is_xenoprof_primary())
    1.99 +			return HYPERVISOR_perfmon_op(PFM_WRITE_PMDS,
   1.100 +			                             arg, count);
   1.101 +		return 0;
   1.102 +  	}
   1.103  
   1.104  	state     = ctx->ctx_state;
   1.105  	is_loaded = state == PFM_CTX_LOADED ? 1 : 0;
   1.106 @@ -3309,6 +3370,7 @@ pfm_read_pmds(pfm_context_t *ctx, void *
   1.107  	int is_loaded, is_system, is_counting, expert_mode;
   1.108  	int ret = -EINVAL;
   1.109  	pfm_reg_check_t rd_func;
   1.110 +	XEN_NOT_SUPPORTED_YET;
   1.111  
   1.112  	/*
   1.113  	 * access is possible when loaded only for
   1.114 @@ -3560,6 +3622,7 @@ pfm_restart(pfm_context_t *ctx, void *ar
   1.115  	pfm_ovfl_ctrl_t rst_ctrl;
   1.116  	int state, is_system;
   1.117  	int ret = 0;
   1.118 +	XEN_NOT_SUPPORTED_YET;
   1.119  
   1.120  	state     = ctx->ctx_state;
   1.121  	fmt       = ctx->ctx_buf_fmt;
   1.122 @@ -3709,6 +3772,7 @@ static int
   1.123  pfm_debug(pfm_context_t *ctx, void *arg, int count, struct pt_regs *regs)
   1.124  {
   1.125  	unsigned int m = *(unsigned int *)arg;
   1.126 +	XEN_NOT_SUPPORTED_YET;
   1.127  
   1.128  	pfm_sysctl.debug = m == 0 ? 0 : 1;
   1.129  
   1.130 @@ -3979,6 +4043,8 @@ pfm_get_features(pfm_context_t *ctx, voi
   1.131  {
   1.132  	pfarg_features_t *req = (pfarg_features_t *)arg;
   1.133  
   1.134 +	if (is_running_on_xen())
   1.135 +		return HYPERVISOR_perfmon_op(PFM_GET_FEATURES, &arg, 0);
   1.136  	req->ft_version = PFM_VERSION;
   1.137  	return 0;
   1.138  }
   1.139 @@ -3990,6 +4056,12 @@ pfm_stop(pfm_context_t *ctx, void *arg, 
   1.140  	struct task_struct *task = PFM_CTX_TASK(ctx);
   1.141  	int state, is_system;
   1.142  
   1.143 +  	if (is_running_on_xen()) {
   1.144 +		if (is_xenoprof_primary())
   1.145 +			return HYPERVISOR_perfmon_op(PFM_STOP, NULL, 0);
   1.146 +		return 0;
   1.147 +  	}
   1.148 +
   1.149  	state     = ctx->ctx_state;
   1.150  	is_system = ctx->ctx_fl_system;
   1.151  
   1.152 @@ -4078,6 +4150,12 @@ pfm_start(pfm_context_t *ctx, void *arg,
   1.153  	struct pt_regs *tregs;
   1.154  	int state, is_system;
   1.155  
   1.156 +  	if (is_running_on_xen()) {
   1.157 +  		XENPERFMON_PRINTD("PFM_START\n");
   1.158 +		if (is_xenoprof_primary())
   1.159 +			return HYPERVISOR_perfmon_op(PFM_START, NULL, 0);
   1.160 +		return 0;
   1.161 +  	}
   1.162  	state     = ctx->ctx_state;
   1.163  	is_system = ctx->ctx_fl_system;
   1.164  
   1.165 @@ -4160,6 +4238,7 @@ pfm_get_pmc_reset(pfm_context_t *ctx, vo
   1.166  	unsigned int cnum;
   1.167  	int i;
   1.168  	int ret = -EINVAL;
   1.169 +	XEN_NOT_SUPPORTED_YET;
   1.170  
   1.171  	for (i = 0; i < count; i++, req++) {
   1.172  
   1.173 @@ -4218,6 +4297,11 @@ pfm_context_load(pfm_context_t *ctx, voi
   1.174  	int ret = 0;
   1.175  	int state, is_system, set_dbregs = 0;
   1.176  
   1.177 +  	if (is_running_on_xen()) {
   1.178 +		if (is_xenoprof_primary())
   1.179 +			return HYPERVISOR_perfmon_op(PFM_LOAD_CONTEXT, arg, 0);
   1.180 +		return 0;
   1.181 +  	}
   1.182  	state     = ctx->ctx_state;
   1.183  	is_system = ctx->ctx_fl_system;
   1.184  	/*
   1.185 @@ -4466,6 +4550,12 @@ pfm_context_unload(pfm_context_t *ctx, v
   1.186  	int prev_state, is_system;
   1.187  	int ret;
   1.188  
   1.189 +  	if (is_running_on_xen()) {
   1.190 +		if (is_xenoprof_primary())
   1.191 +			return HYPERVISOR_perfmon_op(PFM_UNLOAD_CONTEXT,
   1.192 +			                             NULL, 0);
   1.193 +		return 0;
   1.194 +  	}
   1.195  	DPRINT(("ctx_state=%d task [%d]\n", ctx->ctx_state, task ? task->pid : -1));
   1.196  
   1.197  	prev_state = ctx->ctx_state;
     2.1 --- a/linux-2.6-xen-sparse/arch/ia64/oprofile/Makefile	Tue Nov 28 21:35:13 2006 -0700
     2.2 +++ b/linux-2.6-xen-sparse/arch/ia64/oprofile/Makefile	Tue Nov 28 22:54:24 2006 -0700
     2.3 @@ -8,3 +8,7 @@ DRIVER_OBJS := $(addprefix ../../../driv
     2.4  
     2.5  oprofile-y := $(DRIVER_OBJS) init.o backtrace.o
     2.6  oprofile-$(CONFIG_PERFMON) += perfmon.o
     2.7 +ifeq ($(CONFIG_XEN), y)
     2.8 +oprofile-$(CONFIG_PERFMON) += xenoprof.o \
     2.9 +	../../../drivers/xen/xenoprof/xenoprofile.o
    2.10 +endif
     3.1 --- a/linux-2.6-xen-sparse/arch/ia64/oprofile/init.c	Tue Nov 28 21:35:13 2006 -0700
     3.2 +++ b/linux-2.6-xen-sparse/arch/ia64/oprofile/init.c	Tue Nov 28 22:54:24 2006 -0700
     3.3 @@ -11,6 +11,7 @@
     3.4  #include <linux/oprofile.h>
     3.5  #include <linux/init.h>
     3.6  #include <linux/errno.h>
     3.7 +#include "oprofile_perfmon.h"
     3.8   
     3.9  extern int perfmon_init(struct oprofile_operations * ops);
    3.10  extern void perfmon_exit(void);
    3.11 @@ -20,6 +21,13 @@ int __init oprofile_arch_init(struct opr
    3.12  {
    3.13  	int ret = -ENODEV;
    3.14  
    3.15 +	if (is_running_on_xen()) {
    3.16 +		ret = xen_perfmon_init();
    3.17 +		if (ret)
    3.18 +			return ret;
    3.19 +		return xenoprofile_init(ops);
    3.20 +	}
    3.21 +
    3.22  #ifdef CONFIG_PERFMON
    3.23  	/* perfmon_init() can fail, but we have no way to report it */
    3.24  	ret = perfmon_init(ops);
    3.25 @@ -32,6 +40,12 @@ int __init oprofile_arch_init(struct opr
    3.26  
    3.27  void oprofile_arch_exit(void)
    3.28  {
    3.29 +	if (is_running_on_xen()) {
    3.30 +		xenoprofile_exit();
    3.31 +		xen_perfmon_exit();
    3.32 +		return;
    3.33 +	}
    3.34 +
    3.35  #ifdef CONFIG_PERFMON
    3.36  	perfmon_exit();
    3.37  #endif
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/linux-2.6-xen-sparse/arch/ia64/oprofile/oprofile_perfmon.h	Tue Nov 28 22:54:24 2006 -0700
     4.3 @@ -0,0 +1,30 @@
     4.4 +#ifndef OPROFILE_PERFMON_H
     4.5 +#define OPROFILE_PERFMON_H
     4.6 +
     4.7 +#include <linux/config.h>
     4.8 +
     4.9 +#ifdef CONFIG_PERFMON
    4.10 +int __perfmon_init(void);
    4.11 +void __perfmon_exit(void);
    4.12 +int perfmon_start(void);
    4.13 +void perfmon_stop(void);
    4.14 +#else
    4.15 +#define __perfmon_init()	(-ENOSYS)
    4.16 +#define __perfmon_exit()	do {} while (0)
    4.17 +#endif /* CONFIG_PERFMON */
    4.18 +
    4.19 +#ifdef CONFIG_XEN
    4.20 +#define STATIC_IF_NO_XEN	/* nothing */
    4.21 +#define xen_perfmon_init()	__perfmon_init()
    4.22 +#define xen_perfmon_exit()	__perfmon_exit()
    4.23 +extern int xenoprofile_init(struct oprofile_operations * ops);
    4.24 +extern void xenoprofile_exit(void);
    4.25 +#else
    4.26 +#define STATIC_IF_NO_XEN	static
    4.27 +#define xen_perfmon_init()	(-ENOSYS)
    4.28 +#define xen_perfmon_exit()	do {} while (0)
    4.29 +#define xenoprofile_init()	(-ENOSYS)
    4.30 +#define xenoprofile_exit()	do {} while (0)
    4.31 +#endif /* CONFIG_XEN */
    4.32 +
    4.33 +#endif /* OPROFILE_PERFMON_H */
     5.1 --- a/linux-2.6-xen-sparse/arch/ia64/oprofile/perfmon.c	Tue Nov 28 21:35:13 2006 -0700
     5.2 +++ b/linux-2.6-xen-sparse/arch/ia64/oprofile/perfmon.c	Tue Nov 28 22:54:24 2006 -0700
     5.3 @@ -14,6 +14,7 @@
     5.4  #include <asm/perfmon.h>
     5.5  #include <asm/ptrace.h>
     5.6  #include <asm/errno.h>
     5.7 +#include "oprofile_perfmon.h"
     5.8  
     5.9  static int allow_ints;
    5.10  
    5.11 @@ -34,14 +35,16 @@ perfmon_handler(struct task_struct *task
    5.12  }
    5.13  
    5.14  
    5.15 -static int perfmon_start(void)
    5.16 +STATIC_IF_NO_XEN
    5.17 +int perfmon_start(void)
    5.18  {
    5.19  	allow_ints = 1;
    5.20  	return 0;
    5.21  }
    5.22  
    5.23  
    5.24 -static void perfmon_stop(void)
    5.25 +STATIC_IF_NO_XEN
    5.26 +void perfmon_stop(void)
    5.27  {
    5.28  	allow_ints = 0;
    5.29  }
    5.30 @@ -76,16 +79,35 @@ static char * get_cpu_type(void)
    5.31  
    5.32  static int using_perfmon;
    5.33  
    5.34 +STATIC_IF_NO_XEN
    5.35 +int __perfmon_init(void)
    5.36 +{
    5.37 +	int ret = pfm_register_buffer_fmt(&oprofile_fmt);
    5.38 +	if (ret)
    5.39 +		return -ENODEV;
    5.40 +
    5.41 +	using_perfmon = 1;
    5.42 +	return 0;
    5.43 +}
    5.44 +
    5.45 +STATIC_IF_NO_XEN
    5.46 +void __perfmon_exit(void)
    5.47 +{
    5.48 +	if (!using_perfmon)
    5.49 +		return;
    5.50 +
    5.51 +	pfm_unregister_buffer_fmt(oprofile_fmt.fmt_uuid);
    5.52 +}
    5.53 +
    5.54  int perfmon_init(struct oprofile_operations * ops)
    5.55  {
    5.56 -	int ret = pfm_register_buffer_fmt(&oprofile_fmt);
    5.57 +	int ret = __perfmon_init();
    5.58  	if (ret)
    5.59  		return -ENODEV;
    5.60  
    5.61  	ops->cpu_type = get_cpu_type();
    5.62  	ops->start = perfmon_start;
    5.63  	ops->stop = perfmon_stop;
    5.64 -	using_perfmon = 1;
    5.65  	printk(KERN_INFO "oprofile: using perfmon.\n");
    5.66  	return 0;
    5.67  }
    5.68 @@ -93,8 +115,5 @@ int perfmon_init(struct oprofile_operati
    5.69  
    5.70  void perfmon_exit(void)
    5.71  {
    5.72 -	if (!using_perfmon)
    5.73 -		return;
    5.74 -
    5.75 -	pfm_unregister_buffer_fmt(oprofile_fmt.fmt_uuid);
    5.76 +	__perfmon_exit();
    5.77  }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/linux-2.6-xen-sparse/arch/ia64/oprofile/xenoprof.c	Tue Nov 28 22:54:24 2006 -0700
     6.3 @@ -0,0 +1,142 @@
     6.4 +/******************************************************************************
     6.5 + * xenoprof ia64 specific part
     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 +#include <linux/init.h>
    6.26 +#include <linux/oprofile.h>
    6.27 +#include <linux/ioport.h>
    6.28 +
    6.29 +#include <xen/driver_util.h>
    6.30 +#include <xen/interface/xen.h>
    6.31 +#include <xen/interface/xenoprof.h>
    6.32 +#include <xen/xenoprof.h>
    6.33 +
    6.34 +#include "oprofile_perfmon.h"
    6.35 +
    6.36 +void __init xenoprof_arch_init_counter(struct xenoprof_init *init)
    6.37 +{
    6.38 +	init->num_events = 0; /* perfmon manages. */
    6.39 +}
    6.40 +
    6.41 +void xenoprof_arch_counter(void)
    6.42 +{
    6.43 +	/* nothing. perfmon does. */
    6.44 +}
    6.45 +
    6.46 +void xenoprof_arch_start(void) 
    6.47 +{
    6.48 +	perfmon_start();
    6.49 +}
    6.50 +
    6.51 +void xenoprof_arch_stop(void)
    6.52 +{
    6.53 +	perfmon_stop();
    6.54 +}
    6.55 +
    6.56 +/* XXX move them to an appropriate header file. */
    6.57 +struct resource* xen_ia64_allocate_resource(unsigned long size); 
    6.58 +void xen_ia64_release_resource(struct resource* res); 
    6.59 +void xen_ia64_unmap_resource(struct resource* res); 
    6.60 +
    6.61 +struct resource*
    6.62 +xenoprof_ia64_allocate_resource(int32_t max_samples)
    6.63 +{
    6.64 +	unsigned long bufsize;
    6.65 +
    6.66 +	/* XXX add hypercall to get bufsize? */
    6.67 +	/*     this value is taken from alloc_xenoprof_struct(). */
    6.68 +#if 0
    6.69 +	bufsize = NR_CPUS * (sizeof(struct xenoprof_buf) +
    6.70 +			     (max_samples - 1) * sizeof(struct event_log));
    6.71 +	bufsize = PAGE_ALIGN(bufsize) + PAGE_SIZE;
    6.72 +#else
    6.73 +#define MAX_OPROF_SHARED_PAGES 32
    6.74 +	bufsize = (MAX_OPROF_SHARED_PAGES + 1) * PAGE_SIZE;
    6.75 +#endif
    6.76 +	return xen_ia64_allocate_resource(bufsize);
    6.77 +}
    6.78 +
    6.79 +void xenoprof_arch_unmap_shared_buffer(struct xenoprof_shared_buffer* sbuf)
    6.80 +{
    6.81 +	if (sbuf->buffer) {
    6.82 +		xen_ia64_unmap_resource(sbuf->arch.res);
    6.83 +		sbuf->buffer = NULL;
    6.84 +		sbuf->arch.res = NULL;
    6.85 +	}
    6.86 +}
    6.87 +
    6.88 +int xenoprof_arch_map_shared_buffer(struct xenoprof_get_buffer* get_buffer,
    6.89 +                                    struct xenoprof_shared_buffer* sbuf)
    6.90 +{
    6.91 +	int ret;
    6.92 +	struct resource* res;
    6.93 +
    6.94 +	sbuf->buffer = NULL;
    6.95 +	sbuf->arch.res = NULL;
    6.96 +
    6.97 +	res = xenoprof_ia64_allocate_resource(get_buffer->max_samples);
    6.98 +	if (IS_ERR(res))
    6.99 +		return PTR_ERR(res);
   6.100 +
   6.101 +	get_buffer->buf_gmaddr = res->start;
   6.102 +
   6.103 +	ret = HYPERVISOR_xenoprof_op(XENOPROF_get_buffer, get_buffer);
   6.104 +	if (ret) {
   6.105 +		xen_ia64_release_resource(res);
   6.106 +		return ret;
   6.107 +	}
   6.108 +
   6.109 +	BUG_ON((res->end - res->start + 1) <
   6.110 +	       get_buffer->bufsize * get_buffer->nbuf);
   6.111 +
   6.112 +	sbuf->buffer = __va(res->start);
   6.113 +	sbuf->arch.res = res;
   6.114 +
   6.115 +	return ret;
   6.116 +}
   6.117 +
   6.118 +int xenoprof_arch_set_passive(struct xenoprof_passive* pdomain,
   6.119 +                              struct xenoprof_shared_buffer* sbuf)
   6.120 +{
   6.121 +	int ret;
   6.122 +	struct resource* res;
   6.123 +
   6.124 +	sbuf->buffer = NULL;
   6.125 +	sbuf->arch.res = NULL;
   6.126 +
   6.127 +	res = xenoprof_ia64_allocate_resource(pdomain->max_samples);
   6.128 +	if (IS_ERR(res))
   6.129 +		return PTR_ERR(res);
   6.130 +
   6.131 +	pdomain->buf_gmaddr = res->start;
   6.132 +
   6.133 +	ret = HYPERVISOR_xenoprof_op(XENOPROF_set_passive, pdomain);
   6.134 +	if (ret) {
   6.135 +		xen_ia64_release_resource(res);
   6.136 +		return ret;
   6.137 +	}
   6.138 +
   6.139 +	BUG_ON((res->end - res->start + 1) < pdomain->bufsize * pdomain->nbuf);
   6.140 +
   6.141 +	sbuf->buffer = __va(res->start);
   6.142 +	sbuf->arch.res = res;
   6.143 +
   6.144 +	return ret;
   6.145 +}
     7.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c	Tue Nov 28 21:35:13 2006 -0700
     7.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c	Tue Nov 28 22:54:24 2006 -0700
     7.3 @@ -1050,3 +1050,55 @@ EXPORT_SYMBOL_GPL(p2m_convert_max_pfn);
     7.4  EXPORT_SYMBOL_GPL(p2m_pte);
     7.5  EXPORT_SYMBOL_GPL(p2m_phystomach);
     7.6  #endif
     7.7 +
     7.8 +///////////////////////////////////////////////////////////////////////////
     7.9 +// for xenoprof
    7.10 +
    7.11 +struct resource*
    7.12 +xen_ia64_allocate_resource(unsigned long size)
    7.13 +{
    7.14 +	struct resource* res;
    7.15 +	int error;
    7.16 +	
    7.17 +	res = kmalloc(sizeof(*res), GFP_KERNEL);
    7.18 +	if (res == NULL)
    7.19 +		return ERR_PTR(-ENOMEM);
    7.20 +
    7.21 +	res->name = "Xen";
    7.22 +	res->flags = IORESOURCE_MEM;
    7.23 +	error = allocate_resource(&iomem_resource, res, PAGE_ALIGN(size),
    7.24 +	                          privcmd_resource_min, privcmd_resource_max,
    7.25 +	                          IA64_GRANULE_SIZE, NULL, NULL);
    7.26 +	if (error) {
    7.27 +		kfree(res);
    7.28 +		return ERR_PTR(error);
    7.29 +	}
    7.30 +	return res;
    7.31 +}
    7.32 +EXPORT_SYMBOL_GPL(xen_ia64_allocate_resource);
    7.33 +
    7.34 +void
    7.35 +xen_ia64_release_resource(struct resource* res)
    7.36 +{
    7.37 +	release_resource(res);
    7.38 +	kfree(res);
    7.39 +}
    7.40 +EXPORT_SYMBOL_GPL(xen_ia64_release_resource);
    7.41 +
    7.42 +void
    7.43 +xen_ia64_unmap_resource(struct resource* res)
    7.44 +{
    7.45 +	unsigned long gpfn = res->start >> PAGE_SHIFT;
    7.46 +	unsigned long nr_pages = (res->end - res->start) >> PAGE_SHIFT;
    7.47 +	unsigned long i;
    7.48 +	
    7.49 +	for (i = 0; i < nr_pages; i++) {
    7.50 +		int error = HYPERVISOR_zap_physmap(gpfn + i, 0);
    7.51 +		if (error)
    7.52 +			printk(KERN_ERR
    7.53 +			       "%s:%d zap_phsymap failed %d gpfn %lx\n",
    7.54 +			       __func__, __LINE__, error, gpfn + i);
    7.55 +	}
    7.56 +	xen_ia64_release_resource(res);
    7.57 +}
    7.58 +EXPORT_SYMBOL_GPL(xen_ia64_unmap_resource);
     8.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/xcom_hcall.c	Tue Nov 28 21:35:13 2006 -0700
     8.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/xcom_hcall.c	Tue Nov 28 22:54:24 2006 -0700
     8.3 @@ -32,10 +32,12 @@
     8.4  #include <xen/interface/callback.h>
     8.5  #include <xen/interface/acm_ops.h>
     8.6  #include <xen/interface/hvm/params.h>
     8.7 +#include <xen/interface/xenoprof.h>
     8.8  #include <asm/hypercall.h>
     8.9  #include <asm/page.h>
    8.10  #include <asm/uaccess.h>
    8.11  #include <asm/xen/xencomm.h>
    8.12 +#include <asm/perfmon.h>
    8.13  
    8.14  /* Xencomm notes:
    8.15   * This file defines hypercalls to be used by xencomm.  The hypercalls simply
    8.16 @@ -301,3 +303,67 @@ xencomm_hypercall_suspend(unsigned long 
    8.17  
    8.18  	return xencomm_arch_hypercall_suspend(xencomm_create_inline(&arg));
    8.19  }
    8.20 +
    8.21 +#if defined(CONFIG_OPROFILE) || defined(CONFIG_OPROFILE_MODULE)
    8.22 +int
    8.23 +xencomm_hypercall_xenoprof_op(int op, void *arg)
    8.24 +{
    8.25 +	switch (op) {
    8.26 +	case XENOPROF_init:
    8.27 +	case XENOPROF_set_active:
    8.28 +	case XENOPROF_set_passive:
    8.29 +	case XENOPROF_counter:
    8.30 +	case XENOPROF_get_buffer:
    8.31 +		break;
    8.32 +
    8.33 +	case XENOPROF_reset_active_list:
    8.34 +	case XENOPROF_reset_passive_list:
    8.35 +	case XENOPROF_reserve_counters:
    8.36 +	case XENOPROF_setup_events:
    8.37 +	case XENOPROF_enable_virq:
    8.38 +	case XENOPROF_start:
    8.39 +	case XENOPROF_stop:
    8.40 +	case XENOPROF_disable_virq:
    8.41 +	case XENOPROF_release_counters:
    8.42 +	case XENOPROF_shutdown:
    8.43 +		return xencomm_arch_hypercall_xenoprof_op(op, arg);
    8.44 +		break;
    8.45 +
    8.46 +	default:
    8.47 +		printk("%s: op %d isn't supported\n", __func__, op);
    8.48 +		return -ENOSYS;
    8.49 +	}
    8.50 +	return xencomm_arch_hypercall_xenoprof_op(op,
    8.51 +						  xencomm_create_inline(arg));
    8.52 +}
    8.53 +#endif
    8.54 +
    8.55 +#ifdef CONFIG_PERFMON
    8.56 +int
    8.57 +xencomm_hypercall_perfmon_op(unsigned long cmd, void* arg, unsigned long count)
    8.58 +{
    8.59 +	switch (cmd) {
    8.60 +	case PFM_GET_FEATURES:
    8.61 +	case PFM_CREATE_CONTEXT:
    8.62 +	case PFM_WRITE_PMCS:
    8.63 +	case PFM_WRITE_PMDS:
    8.64 +	case PFM_LOAD_CONTEXT:
    8.65 +		break;
    8.66 +
    8.67 +	case PFM_DESTROY_CONTEXT:
    8.68 +	case PFM_UNLOAD_CONTEXT:
    8.69 +	case PFM_START:
    8.70 +	case PFM_STOP:
    8.71 +		return xencomm_arch_hypercall_perfmon_op(cmd, arg, count);
    8.72 +
    8.73 +	default:
    8.74 +		printk("%s:%d cmd %ld isn't supported\n",
    8.75 +		       __func__,__LINE__, cmd);
    8.76 +		BUG();
    8.77 +	}
    8.78 +
    8.79 +	return xencomm_arch_hypercall_perfmon_op(cmd,
    8.80 +	                                         xencomm_create_inline(arg),
    8.81 +	                                         count);
    8.82 +}
    8.83 +#endif
     9.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/xcom_mini.c	Tue Nov 28 21:35:13 2006 -0700
     9.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/xcom_mini.c	Tue Nov 28 22:54:24 2006 -0700
     9.3 @@ -28,12 +28,14 @@
     9.4  #include <xen/interface/physdev.h>
     9.5  #include <xen/interface/grant_table.h>
     9.6  #include <xen/interface/hvm/params.h>
     9.7 +#include <xen/interface/xenoprof.h>
     9.8  #ifdef CONFIG_VMX_GUEST
     9.9  #include <asm/hypervisor.h>
    9.10  #else
    9.11  #include <asm/hypercall.h>
    9.12  #endif
    9.13  #include <asm/xen/xencomm.h>
    9.14 +#include <asm/perfmon.h>
    9.15  
    9.16  int
    9.17  xencomm_mini_hypercall_event_channel_op(int cmd, void *op)
    9.18 @@ -320,3 +322,100 @@ xencomm_mini_hypercall_xen_version(int c
    9.19  	return xencomm_arch_hypercall_xen_version(cmd, desc);
    9.20  }
    9.21  EXPORT_SYMBOL(xencomm_mini_hypercall_xen_version);
    9.22 +
    9.23 +#if defined(CONFIG_OPROFILE) || defined(CONFIG_OPROFILE_MODULE)
    9.24 +int
    9.25 +xencomm_mini_hypercall_xenoprof_op(int op, void *arg)
    9.26 +{
    9.27 +	unsigned int argsize;
    9.28 +	struct xencomm_mini xc_area[2];
    9.29 +	int nbr_area = 2;
    9.30 +	struct xencomm_handle *desc;
    9.31 +	int rc;
    9.32 +
    9.33 +	switch (op) {
    9.34 +	case XENOPROF_init:
    9.35 +		argsize = sizeof(xenoprof_init_t);
    9.36 +		break;
    9.37 +	case XENOPROF_set_active:
    9.38 +		argsize = sizeof(domid_t);
    9.39 +		break;
    9.40 +	case XENOPROF_set_passive:
    9.41 +		argsize = sizeof(xenoprof_passive_t);
    9.42 +		break;
    9.43 +	case XENOPROF_counter:
    9.44 +		argsize = sizeof(xenoprof_counter_t);
    9.45 +		break;
    9.46 +	case XENOPROF_get_buffer:
    9.47 +		argsize = sizeof(xenoprof_get_buffer_t);
    9.48 +		break;
    9.49 +
    9.50 +	case XENOPROF_reset_active_list:
    9.51 +	case XENOPROF_reset_passive_list:
    9.52 +	case XENOPROF_reserve_counters:
    9.53 +	case XENOPROF_setup_events:
    9.54 +	case XENOPROF_enable_virq:
    9.55 +	case XENOPROF_start:
    9.56 +	case XENOPROF_stop:
    9.57 +	case XENOPROF_disable_virq:
    9.58 +	case XENOPROF_release_counters:
    9.59 +	case XENOPROF_shutdown:
    9.60 +		return xencomm_arch_hypercall_xenoprof_op(op, arg);
    9.61 +
    9.62 +	default:
    9.63 +		printk("%s: op %d isn't supported\n", __func__, op);
    9.64 +		return -ENOSYS;
    9.65 +	}
    9.66 +	rc = xencomm_create_mini(xc_area, &nbr_area, arg, argsize, &desc);
    9.67 +	if (rc)
    9.68 +		return rc;
    9.69 +	return xencomm_arch_hypercall_xenoprof_op(op, desc);
    9.70 +}
    9.71 +EXPORT_SYMBOL_GPL(xencomm_mini_hypercall_xenoprof_op);
    9.72 +#endif
    9.73 +
    9.74 +#ifdef CONFIG_PERFMON
    9.75 +int
    9.76 +xencomm_mini_hypercall_perfmon_op(unsigned long cmd, void* arg,
    9.77 +                                  unsigned long count)
    9.78 +{
    9.79 +	unsigned int argsize;
    9.80 +	struct xencomm_mini xc_area[2];
    9.81 +	int nbr_area = 2;
    9.82 +	struct xencomm_handle *desc;
    9.83 +	int rc;
    9.84 +
    9.85 +	switch (cmd) {
    9.86 +	case PFM_GET_FEATURES:
    9.87 +		argsize = sizeof(pfarg_features_t);
    9.88 +		break;
    9.89 +	case PFM_CREATE_CONTEXT:
    9.90 +		argsize = sizeof(pfarg_context_t);
    9.91 +		break;
    9.92 +	case PFM_LOAD_CONTEXT:
    9.93 +		argsize = sizeof(pfarg_load_t);
    9.94 +		break;
    9.95 +	case PFM_WRITE_PMCS:
    9.96 +	case PFM_WRITE_PMDS:
    9.97 +		argsize = sizeof(pfarg_reg_t) * count;
    9.98 +		break;
    9.99 +
   9.100 +	case PFM_DESTROY_CONTEXT:
   9.101 +	case PFM_UNLOAD_CONTEXT:
   9.102 +	case PFM_START:
   9.103 +	case PFM_STOP:
   9.104 +		return xencomm_arch_hypercall_perfmon_op(cmd, arg, count);
   9.105 +
   9.106 +	default:
   9.107 +		printk("%s:%d cmd %ld isn't supported\n",
   9.108 +		       __func__, __LINE__, cmd);
   9.109 +		BUG();
   9.110 +	}
   9.111 +
   9.112 +	rc = xencomm_create_mini(xc_area, &nbr_area, arg, argsize, &desc);
   9.113 +	if (rc)
   9.114 +		return rc;
   9.115 +	return xencomm_arch_hypercall_perfmon_op(cmd, desc, count);
   9.116 +}
   9.117 +EXPORT_SYMBOL_GPL(xencomm_mini_hypercall_perfmon_op);
   9.118 +#endif
    10.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h	Tue Nov 28 21:35:13 2006 -0700
    10.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h	Tue Nov 28 22:54:24 2006 -0700
    10.3 @@ -271,6 +271,12 @@ HYPERVISOR_physdev_op(int cmd, void *arg
    10.4  	}
    10.5  }
    10.6  
    10.7 +static inline int
    10.8 +xencomm_arch_hypercall_xenoprof_op(int op, struct xencomm_handle *arg)
    10.9 +{
   10.10 +	return _hypercall2(int, xenoprof_op, op, arg);
   10.11 +}
   10.12 +
   10.13  extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs);
   10.14  static inline void exit_idle(void) {}
   10.15  #define do_IRQ(irq, regs) ({			\
   10.16 @@ -393,6 +399,17 @@ HYPERVISOR_expose_p2m(unsigned long conv
   10.17  }
   10.18  #endif
   10.19  
   10.20 +#ifdef CONFIG_PERFMON
   10.21 +static inline int
   10.22 +xencomm_arch_hypercall_perfmon_op(unsigned long cmd,
   10.23 +                                  struct xencomm_handle *arg,
   10.24 +                                  unsigned long count)
   10.25 +{
   10.26 +	return _hypercall4(int, ia64_dom0vp_op,
   10.27 +			   IA64_DOM0VP_perfmon, cmd, arg, count);
   10.28 +}
   10.29 +#endif
   10.30 +
   10.31  // for balloon driver
   10.32  #define HYPERVISOR_update_va_mapping(va, new_val, flags) (0)
   10.33  
   10.34 @@ -406,6 +423,8 @@ HYPERVISOR_expose_p2m(unsigned long conv
   10.35  #define HYPERVISOR_console_io xencomm_mini_hypercall_console_io
   10.36  #define HYPERVISOR_hvm_op xencomm_mini_hypercall_hvm_op
   10.37  #define HYPERVISOR_memory_op xencomm_mini_hypercall_memory_op
   10.38 +#define HYPERVISOR_xenoprof_op xencomm_mini_hypercall_xenoprof_op
   10.39 +#define HYPERVISOR_perfmon_op xencomm_mini_hypercall_perfmon_op
   10.40  #else
   10.41  #define HYPERVISOR_sched_op xencomm_hypercall_sched_op
   10.42  #define HYPERVISOR_event_channel_op xencomm_hypercall_event_channel_op
   10.43 @@ -415,6 +434,8 @@ HYPERVISOR_expose_p2m(unsigned long conv
   10.44  #define HYPERVISOR_console_io xencomm_hypercall_console_io
   10.45  #define HYPERVISOR_hvm_op xencomm_hypercall_hvm_op
   10.46  #define HYPERVISOR_memory_op xencomm_hypercall_memory_op
   10.47 +#define HYPERVISOR_xenoprof_op xencomm_hypercall_xenoprof_op
   10.48 +#define HYPERVISOR_perfmon_op xencomm_hypercall_perfmon_op
   10.49  #endif
   10.50  
   10.51  #define HYPERVISOR_suspend xencomm_hypercall_suspend
    11.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/xen/xcom_hcall.h	Tue Nov 28 21:35:13 2006 -0700
    11.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/xen/xcom_hcall.h	Tue Nov 28 22:54:24 2006 -0700
    11.3 @@ -46,6 +46,15 @@ extern unsigned long xencomm_hypercall_h
    11.4  
    11.5  extern int xencomm_hypercall_suspend(unsigned long srec);
    11.6  
    11.7 +#if defined(CONFIG_OPROFILE) || defined(CONFIG_OPROFILE_MODULE)
    11.8 +extern int xencomm_hypercall_xenoprof_op(int op, void *arg);
    11.9 +#endif
   11.10 +
   11.11 +#ifdef CONFIG_PERFMON
   11.12 +extern int xencomm_hypercall_perfmon_op(unsigned long cmd, void* arg,
   11.13 +                                        unsigned long count);
   11.14 +#endif
   11.15 +
   11.16  /* Using mini xencomm.  */
   11.17  extern int xencomm_mini_hypercall_console_io(int cmd, int count, char *str);
   11.18  
   11.19 @@ -68,6 +77,15 @@ extern int xencomm_mini_hypercall_memory
   11.20  
   11.21  extern unsigned long xencomm_mini_hypercall_hvm_op(int cmd, void *arg);
   11.22  
   11.23 +#if defined(CONFIG_OPROFILE) || defined(CONFIG_OPROFILE_MODULE)
   11.24 +extern int xencomm_mini_hypercall_xenoprof_op(int op, void *arg);
   11.25 +#endif
   11.26 +
   11.27 +#ifdef CONFIG_PERFMON
   11.28 +extern int xencomm_mini_hypercall_perfmon_op(unsigned long cmd, void* arg,
   11.29 +                                             unsigned long count);
   11.30 +#endif
   11.31 +
   11.32  /* For privcmd.  Locally declare argument type to avoid include storm.
   11.33     Type coherency will be checked within privcmd.c  */
   11.34  struct privcmd_hypercall;
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/xenoprof.h	Tue Nov 28 22:54:24 2006 -0700
    12.3 @@ -0,0 +1,48 @@
    12.4 +/******************************************************************************
    12.5 + * asm-ia64/xenoprof.h
    12.6 + *
    12.7 + * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
    12.8 + *                    VA Linux Systems Japan K.K.
    12.9 + *
   12.10 + * This program is free software; you can redistribute it and/or modify
   12.11 + * it under the terms of the GNU General Public License as published by
   12.12 + * the Free Software Foundation; either version 2 of the License, or
   12.13 + * (at your option) any later version.
   12.14 + *
   12.15 + * This program is distributed in the hope that it will be useful,
   12.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.18 + * GNU General Public License for more details.
   12.19 + *
   12.20 + * You should have received a copy of the GNU General Public License
   12.21 + * along with this program; if not, write to the Free Software
   12.22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.23 + *
   12.24 + */
   12.25 +#ifndef __ASM_XENOPROF_H__
   12.26 +#define __ASM_XENOPROF_H__
   12.27 +#ifdef CONFIG_XEN
   12.28 +
   12.29 +#undef HAVE_XENOPROF_CREATE_FILES
   12.30 +
   12.31 +struct xenoprof_init;
   12.32 +void xenoprof_arch_init_counter(struct xenoprof_init *init);
   12.33 +void xenoprof_arch_counter(void);
   12.34 +void xenoprof_arch_start(void);
   12.35 +void xenoprof_arch_stop(void);
   12.36 +
   12.37 +struct xenoprof_arch_shared_buffer {
   12.38 +	struct resource*	res;
   12.39 +};
   12.40 +
   12.41 +struct xenoprof_shared_buffer;
   12.42 +void xenoprof_arch_unmap_shared_buffer(struct xenoprof_shared_buffer* sbuf);
   12.43 +struct xenoprof_get_buffer;
   12.44 +int xenoprof_arch_map_shared_buffer(struct xenoprof_get_buffer* get_buffer,
   12.45 +                                    struct xenoprof_shared_buffer* sbuf);
   12.46 +struct xenoprof_passive;
   12.47 +int xenoprof_arch_set_passive(struct xenoprof_passive* pdomain,
   12.48 +                              struct xenoprof_shared_buffer* sbuf);
   12.49 +
   12.50 +#endif /* CONFIG_XEN */
   12.51 +#endif /* __ASM_XENOPROF_H__ */