ia64/xen-unstable

changeset 12626:dc614bb5b0e8

[IA64] import linux/arch/ia64/oprofile/perfmon.c

To xen/arch/ia64/xen/oprofile/perfmon.c

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author awilliam@xenbuild.aw
date Tue Nov 28 11:26:14 2006 -0700 (2006-11-28)
parents da51aee40456
children d5a48cfc1db2
files xen/arch/ia64/xen/oprofile/perfmon.c
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xen/arch/ia64/xen/oprofile/perfmon.c	Tue Nov 28 11:26:14 2006 -0700
     1.3 @@ -0,0 +1,100 @@
     1.4 +/**
     1.5 + * @file perfmon.c
     1.6 + *
     1.7 + * @remark Copyright 2003 OProfile authors
     1.8 + * @remark Read the file COPYING
     1.9 + *
    1.10 + * @author John Levon <levon@movementarian.org>
    1.11 + */
    1.12 +
    1.13 +#include <linux/kernel.h>
    1.14 +#include <linux/config.h>
    1.15 +#include <linux/oprofile.h>
    1.16 +#include <linux/sched.h>
    1.17 +#include <asm/perfmon.h>
    1.18 +#include <asm/ptrace.h>
    1.19 +#include <asm/errno.h>
    1.20 +
    1.21 +static int allow_ints;
    1.22 +
    1.23 +static int
    1.24 +perfmon_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg,
    1.25 +                struct pt_regs *regs, unsigned long stamp)
    1.26 +{
    1.27 +	int event = arg->pmd_eventid;
    1.28 + 
    1.29 +	arg->ovfl_ctrl.bits.reset_ovfl_pmds = 1;
    1.30 +
    1.31 +	/* the owner of the oprofile event buffer may have exited
    1.32 +	 * without perfmon being shutdown (e.g. SIGSEGV)
    1.33 +	 */
    1.34 +	if (allow_ints)
    1.35 +		oprofile_add_sample(regs, event);
    1.36 +	return 0;
    1.37 +}
    1.38 +
    1.39 +
    1.40 +static int perfmon_start(void)
    1.41 +{
    1.42 +	allow_ints = 1;
    1.43 +	return 0;
    1.44 +}
    1.45 +
    1.46 +
    1.47 +static void perfmon_stop(void)
    1.48 +{
    1.49 +	allow_ints = 0;
    1.50 +}
    1.51 +
    1.52 +
    1.53 +#define OPROFILE_FMT_UUID { \
    1.54 +	0x77, 0x7a, 0x6e, 0x61, 0x20, 0x65, 0x73, 0x69, 0x74, 0x6e, 0x72, 0x20, 0x61, 0x65, 0x0a, 0x6c }
    1.55 +
    1.56 +static pfm_buffer_fmt_t oprofile_fmt = {
    1.57 + 	.fmt_name 	    = "oprofile_format",
    1.58 + 	.fmt_uuid	    = OPROFILE_FMT_UUID,
    1.59 + 	.fmt_handler	    = perfmon_handler,
    1.60 +};
    1.61 +
    1.62 +
    1.63 +static char * get_cpu_type(void)
    1.64 +{
    1.65 +	__u8 family = local_cpu_data->family;
    1.66 +
    1.67 +	switch (family) {
    1.68 +		case 0x07:
    1.69 +			return "ia64/itanium";
    1.70 +		case 0x1f:
    1.71 +			return "ia64/itanium2";
    1.72 +		default:
    1.73 +			return "ia64/ia64";
    1.74 +	}
    1.75 +}
    1.76 +
    1.77 +
    1.78 +/* all the ops are handled via userspace for IA64 perfmon */
    1.79 +
    1.80 +static int using_perfmon;
    1.81 +
    1.82 +int perfmon_init(struct oprofile_operations * ops)
    1.83 +{
    1.84 +	int ret = pfm_register_buffer_fmt(&oprofile_fmt);
    1.85 +	if (ret)
    1.86 +		return -ENODEV;
    1.87 +
    1.88 +	ops->cpu_type = get_cpu_type();
    1.89 +	ops->start = perfmon_start;
    1.90 +	ops->stop = perfmon_stop;
    1.91 +	using_perfmon = 1;
    1.92 +	printk(KERN_INFO "oprofile: using perfmon.\n");
    1.93 +	return 0;
    1.94 +}
    1.95 +
    1.96 +
    1.97 +void perfmon_exit(void)
    1.98 +{
    1.99 +	if (!using_perfmon)
   1.100 +		return;
   1.101 +
   1.102 +	pfm_unregister_buffer_fmt(oprofile_fmt.fmt_uuid);
   1.103 +}