2 * @file arch/alpha/oprofile/common.c
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author Richard Henderson <rth@twiddle.net>
10 #include <linux/oprofile.h>
11 #include <linux/init.h>
12 #include <linux/smp.h>
13 #include <linux/errno.h>
14 #include <asm/ptrace.h>
15 #include <asm/system.h>
19 extern struct op_axp_model op_model_ev4
__attribute__((weak
));
20 extern struct op_axp_model op_model_ev5
__attribute__((weak
));
21 extern struct op_axp_model op_model_pca56
__attribute__((weak
));
22 extern struct op_axp_model op_model_ev6
__attribute__((weak
));
23 extern struct op_axp_model op_model_ev67
__attribute__((weak
));
25 static struct op_axp_model
*model
;
27 extern void (*perf_irq
)(unsigned long, struct pt_regs
*);
28 static void (*save_perf_irq
)(unsigned long, struct pt_regs
*);
30 static struct op_counter_config ctr
[20];
31 static struct op_system_config sys
;
32 static struct op_register_config reg
;
34 /* Called from do_entInt to handle the performance monitor interrupt. */
37 op_handle_interrupt(unsigned long which
, struct pt_regs
*regs
)
39 model
->handle_interrupt(which
, regs
, ctr
);
41 /* If the user has selected an interrupt frequency that is
42 not exactly the width of the counter, write a new value
43 into the counter such that it'll overflow after N more
45 if ((reg
.need_reset
>> which
) & 1)
46 model
->reset_ctr(®
, which
);
54 /* Install our interrupt handler into the existing hook. */
55 save_perf_irq
= perf_irq
;
56 perf_irq
= op_handle_interrupt
;
58 /* Compute the mask of enabled counters. */
59 for (i
= e
= 0; i
< model
->num_counters
; ++i
)
64 /* Pre-compute the values to stuff in the hardware registers. */
65 model
->reg_setup(®
, ctr
, &sys
);
67 /* Configure the registers on all cpus. */
68 (void)smp_call_function(model
->cpu_setup
, ®
, 1);
69 model
->cpu_setup(®
);
76 /* Remove our interrupt handler. We may be removing this module. */
77 perf_irq
= save_perf_irq
;
81 op_axp_cpu_start(void *dummy
)
83 wrperfmon(1, reg
.enable
);
89 (void)smp_call_function(op_axp_cpu_start
, NULL
, 1);
90 op_axp_cpu_start(NULL
);
95 op_axp_cpu_stop(void *dummy
)
97 /* Disable performance monitoring for all counters. */
104 (void)smp_call_function(op_axp_cpu_stop
, NULL
, 1);
105 op_axp_cpu_stop(NULL
);
109 op_axp_create_files(struct super_block
*sb
, struct dentry
*root
)
113 for (i
= 0; i
< model
->num_counters
; ++i
) {
117 snprintf(buf
, sizeof buf
, "%d", i
);
118 dir
= oprofilefs_mkdir(sb
, root
, buf
);
120 oprofilefs_create_ulong(sb
, dir
, "enabled", &ctr
[i
].enabled
);
121 oprofilefs_create_ulong(sb
, dir
, "event", &ctr
[i
].event
);
122 oprofilefs_create_ulong(sb
, dir
, "count", &ctr
[i
].count
);
124 oprofilefs_create_ulong(sb
, dir
, "kernel", &ctr
[i
].kernel
);
125 oprofilefs_create_ulong(sb
, dir
, "user", &ctr
[i
].user
);
126 oprofilefs_create_ulong(sb
, dir
, "unit_mask", &ctr
[i
].unit_mask
);
129 if (model
->can_set_proc_mode
) {
130 oprofilefs_create_ulong(sb
, root
, "enable_pal",
132 oprofilefs_create_ulong(sb
, root
, "enable_kernel",
134 oprofilefs_create_ulong(sb
, root
, "enable_user",
142 oprofile_arch_init(struct oprofile_operations
*ops
)
144 struct op_axp_model
*lmodel
= NULL
;
148 lmodel
= &op_model_ev4
;
151 /* 21164PC has a slightly different set of events.
152 Recognize the chip by the presence of the MAX insns. */
153 if (!amask(AMASK_MAX
))
154 lmodel
= &op_model_pca56
;
156 lmodel
= &op_model_ev5
;
159 /* 21264A supports ProfileMe.
160 Recognize the chip by the presence of the CIX insns. */
161 if (!amask(AMASK_CIX
))
162 lmodel
= &op_model_ev67
;
164 lmodel
= &op_model_ev6
;
172 ops
->create_files
= op_axp_create_files
;
173 ops
->setup
= op_axp_setup
;
174 ops
->shutdown
= op_axp_shutdown
;
175 ops
->start
= op_axp_start
;
176 ops
->stop
= op_axp_stop
;
177 ops
->cpu_type
= lmodel
->cpu_type
;
179 printk(KERN_INFO
"oprofile: using %s performance monitoring.\n",
187 oprofile_arch_exit(void)