2 * @file arch/alpha/oprofile/op_model_ev67.c
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author Richard Henderson <rth@twiddle.net>
8 * @author Falk Hueffner <falk@debian.org>
11 #include <linux/oprofile.h>
12 #include <linux/smp.h>
13 #include <asm/ptrace.h>
18 /* Compute all of the registers in preparation for enabling profiling. */
21 ev67_reg_setup(struct op_register_config
*reg
,
22 struct op_counter_config
*ctr
,
23 struct op_system_config
*sys
)
25 unsigned long ctl
, reset
, need_reset
, i
;
27 /* Select desired events. */
28 ctl
= 1UL << 4; /* Enable ProfileMe mode. */
30 /* The event numbers are chosen so we can use them directly if
33 ctl
|= (ctr
[1].event
& 3) << 2;
35 if (ctr
[0].event
== 0) /* cycles */
38 reg
->mux_select
= ctl
;
40 /* Select logging options. */
41 /* ??? Need to come up with some mechanism to trace only
42 selected processes. EV67 does not have a mechanism to
43 select kernel or user mode only. For now, enable always. */
46 /* EV67 cannot change the width of the counters as with the
47 other implementations. But fortunately, we can write to
48 the counters and set the value such that it will overflow
50 reset
= need_reset
= 0;
51 for (i
= 0; i
< 2; ++i
) {
52 unsigned long count
= ctr
[i
].count
;
59 reset
|= (0x100000 - count
) << (i
? 6 : 28);
60 if (count
!= 0x100000)
63 reg
->reset_values
= reset
;
64 reg
->need_reset
= need_reset
;
67 /* Program all of the registers in preparation for enabling profiling. */
70 ev67_cpu_setup (void *x
)
72 struct op_register_config
*reg
= x
;
74 wrperfmon(2, reg
->mux_select
);
75 wrperfmon(3, reg
->proc_mode
);
76 wrperfmon(6, reg
->reset_values
| 3);
79 /* CTR is a counter for which the user has requested an interrupt count
80 in between one of the widths selectable in hardware. Reset the count
81 for CTR to the value stored in REG->RESET_VALUES. */
84 ev67_reset_ctr(struct op_register_config
*reg
, unsigned long ctr
)
86 wrperfmon(6, reg
->reset_values
| (1 << ctr
));
89 /* ProfileMe conditions which will show up as counters. We can also
90 detect the following, but it seems unlikely that anybody is
91 interested in counting them:
93 * MT_FPCR (write to floating point control register)
96 * Machine Check (ECC fault, etc.)
97 * OPCDEC (illegal opcode)
98 * Floating point disabled
99 * Differentiate between DTB single/double misses and 3 or 4 level
101 * Istream access violation
103 * Icache Parity Error.
104 * Instruction killed (nop, trapb)
106 Unfortunately, there seems to be no way to detect Dcache and Bcache
107 misses; the latter could be approximated by making the counter
108 count Bcache misses, but that is not precise.
110 We model this as 20 counters:
113 * 9 ProfileMe events, induced by PCTR0
114 * 9 ProfileMe events, induced by PCTR1
117 enum profileme_counters
{
118 PM_STALLED
, /* Stalled for at least one cycle
119 between the fetch and map stages */
120 PM_TAKEN
, /* Conditional branch taken */
121 PM_MISPREDICT
, /* Branch caused mispredict trap */
122 PM_ITB_MISS
, /* ITB miss */
123 PM_DTB_MISS
, /* DTB miss */
124 PM_REPLAY
, /* Replay trap */
125 PM_LOAD_STORE
, /* Load-store order trap */
126 PM_ICACHE_MISS
, /* Icache miss */
127 PM_UNALIGNED
, /* Unaligned Load/Store */
132 op_add_pm(unsigned long pc
, int kern
, unsigned long counter
,
133 struct op_counter_config
*ctr
, unsigned long event
)
135 unsigned long fake_counter
= 2 + event
;
137 fake_counter
+= PM_NUM_COUNTERS
;
138 if (ctr
[fake_counter
].enabled
)
139 oprofile_add_pc(pc
, kern
, fake_counter
);
143 ev67_handle_interrupt(unsigned long which
, struct pt_regs
*regs
,
144 struct op_counter_config
*ctr
)
146 unsigned long pmpc
, pctr_ctl
;
147 int kern
= !user_mode(regs
);
152 unsigned reserved
: 30; /* 0-29 */
153 unsigned overcount
: 3; /* 30-32 */
154 unsigned icache_miss
: 1; /* 33 */
155 unsigned trap_type
: 4; /* 34-37 */
156 unsigned load_store
: 1; /* 38 */
157 unsigned trap
: 1; /* 39 */
158 unsigned mispredict
: 1; /* 40 */
165 TRAP_DTB_DOUBLE_MISS_3
,
166 TRAP_DTB_DOUBLE_MISS_4
,
169 TRAP_DTB_SINGLE_MISS
,
181 pmpc
= wrperfmon(9, 0);
182 /* ??? Don't know how to handle physical-mode PALcode address. */
185 pmpc
&= ~2; /* clear reserved bit */
187 i_stat
.v
= wrperfmon(8, 0);
188 if (i_stat
.fields
.trap
) {
189 switch (i_stat
.fields
.trap_type
) {
193 /* Pipeline redirection occurred. PMPC points
194 to PALcode. Recognize ITB miss by PALcode
195 offset address, and get actual PC from
197 oprofile_add_pc(regs
->pc
, kern
, which
);
198 if ((pmpc
& ((1 << 15) - 1)) == 581)
199 op_add_pm(regs
->pc
, kern
, which
,
201 /* Most other bit and counter values will be
202 those for the first instruction in the
203 fault handler, so we're done. */
206 op_add_pm(pmpc
, kern
, which
, ctr
,
207 (i_stat
.fields
.load_store
208 ? PM_LOAD_STORE
: PM_REPLAY
));
210 case TRAP_DTB_DOUBLE_MISS_3
:
211 case TRAP_DTB_DOUBLE_MISS_4
:
212 case TRAP_DTB_SINGLE_MISS
:
213 op_add_pm(pmpc
, kern
, which
, ctr
, PM_DTB_MISS
);
216 op_add_pm(pmpc
, kern
, which
, ctr
, PM_UNALIGNED
);
219 case TRAP_FP_DISABLED
:
220 case TRAP_DSTREAM_FAULT
:
222 case TRAP_MACHINE_CHECK
:
223 case TRAP_ARITHMETIC
:
229 /* ??? JSR/JMP/RET/COR or HW_JSR/HW_JMP/HW_RET/HW_COR
230 mispredicts do not set this bit but can be
231 recognized by the presence of one of these
232 instructions at the PMPC location with bit 39
234 if (i_stat
.fields
.mispredict
) {
236 op_add_pm(pmpc
, kern
, which
, ctr
, PM_MISPREDICT
);
240 oprofile_add_pc(pmpc
, kern
, which
);
242 pctr_ctl
= wrperfmon(5, 0);
243 if (pctr_ctl
& (1UL << 27))
244 op_add_pm(pmpc
, kern
, which
, ctr
, PM_STALLED
);
246 /* Unfortunately, TAK is undefined on mispredicted branches.
247 ??? It is also undefined for non-cbranch insns, should
249 if (!mispredict
&& pctr_ctl
& (1UL << 0))
250 op_add_pm(pmpc
, kern
, which
, ctr
, PM_TAKEN
);
253 struct op_axp_model op_model_ev67
= {
254 .reg_setup
= ev67_reg_setup
,
255 .cpu_setup
= ev67_cpu_setup
,
256 .reset_ctr
= ev67_reset_ctr
,
257 .handle_interrupt
= ev67_handle_interrupt
,
258 .cpu_type
= "alpha/ev67",
260 .can_set_proc_mode
= 0,