diff options
Diffstat (limited to 'arch/x86/oprofile')
-rw-r--r-- | arch/x86/oprofile/backtrace.c | 9 | ||||
-rw-r--r-- | arch/x86/oprofile/nmi_int.c | 20 | ||||
-rw-r--r-- | arch/x86/oprofile/op_model_amd.c | 261 | ||||
-rw-r--r-- | arch/x86/oprofile/op_model_p4.c | 6 | ||||
-rw-r--r-- | arch/x86/oprofile/op_model_ppro.c | 21 | ||||
-rw-r--r-- | arch/x86/oprofile/op_x86_model.h | 20 |
6 files changed, 210 insertions, 127 deletions
diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c index 044897be021f..3855096c59b8 100644 --- a/arch/x86/oprofile/backtrace.c +++ b/arch/x86/oprofile/backtrace.c | |||
@@ -41,10 +41,11 @@ static void backtrace_address(void *data, unsigned long addr, int reliable) | |||
41 | } | 41 | } |
42 | 42 | ||
43 | static struct stacktrace_ops backtrace_ops = { | 43 | static struct stacktrace_ops backtrace_ops = { |
44 | .warning = backtrace_warning, | 44 | .warning = backtrace_warning, |
45 | .warning_symbol = backtrace_warning_symbol, | 45 | .warning_symbol = backtrace_warning_symbol, |
46 | .stack = backtrace_stack, | 46 | .stack = backtrace_stack, |
47 | .address = backtrace_address, | 47 | .address = backtrace_address, |
48 | .walk_stack = print_context_stack, | ||
48 | }; | 49 | }; |
49 | 50 | ||
50 | struct frame_head { | 51 | struct frame_head { |
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c index cb88b1a0bd5f..2c505ee71014 100644 --- a/arch/x86/oprofile/nmi_int.c +++ b/arch/x86/oprofile/nmi_int.c | |||
@@ -159,7 +159,7 @@ static int nmi_setup_mux(void) | |||
159 | 159 | ||
160 | for_each_possible_cpu(i) { | 160 | for_each_possible_cpu(i) { |
161 | per_cpu(cpu_msrs, i).multiplex = | 161 | per_cpu(cpu_msrs, i).multiplex = |
162 | kmalloc(multiplex_size, GFP_KERNEL); | 162 | kzalloc(multiplex_size, GFP_KERNEL); |
163 | if (!per_cpu(cpu_msrs, i).multiplex) | 163 | if (!per_cpu(cpu_msrs, i).multiplex) |
164 | return 0; | 164 | return 0; |
165 | } | 165 | } |
@@ -179,7 +179,6 @@ static void nmi_cpu_setup_mux(int cpu, struct op_msrs const * const msrs) | |||
179 | if (counter_config[i].enabled) { | 179 | if (counter_config[i].enabled) { |
180 | multiplex[i].saved = -(u64)counter_config[i].count; | 180 | multiplex[i].saved = -(u64)counter_config[i].count; |
181 | } else { | 181 | } else { |
182 | multiplex[i].addr = 0; | ||
183 | multiplex[i].saved = 0; | 182 | multiplex[i].saved = 0; |
184 | } | 183 | } |
185 | } | 184 | } |
@@ -189,25 +188,27 @@ static void nmi_cpu_setup_mux(int cpu, struct op_msrs const * const msrs) | |||
189 | 188 | ||
190 | static void nmi_cpu_save_mpx_registers(struct op_msrs *msrs) | 189 | static void nmi_cpu_save_mpx_registers(struct op_msrs *msrs) |
191 | { | 190 | { |
191 | struct op_msr *counters = msrs->counters; | ||
192 | struct op_msr *multiplex = msrs->multiplex; | 192 | struct op_msr *multiplex = msrs->multiplex; |
193 | int i; | 193 | int i; |
194 | 194 | ||
195 | for (i = 0; i < model->num_counters; ++i) { | 195 | for (i = 0; i < model->num_counters; ++i) { |
196 | int virt = op_x86_phys_to_virt(i); | 196 | int virt = op_x86_phys_to_virt(i); |
197 | if (multiplex[virt].addr) | 197 | if (counters[i].addr) |
198 | rdmsrl(multiplex[virt].addr, multiplex[virt].saved); | 198 | rdmsrl(counters[i].addr, multiplex[virt].saved); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | static void nmi_cpu_restore_mpx_registers(struct op_msrs *msrs) | 202 | static void nmi_cpu_restore_mpx_registers(struct op_msrs *msrs) |
203 | { | 203 | { |
204 | struct op_msr *counters = msrs->counters; | ||
204 | struct op_msr *multiplex = msrs->multiplex; | 205 | struct op_msr *multiplex = msrs->multiplex; |
205 | int i; | 206 | int i; |
206 | 207 | ||
207 | for (i = 0; i < model->num_counters; ++i) { | 208 | for (i = 0; i < model->num_counters; ++i) { |
208 | int virt = op_x86_phys_to_virt(i); | 209 | int virt = op_x86_phys_to_virt(i); |
209 | if (multiplex[virt].addr) | 210 | if (counters[i].addr) |
210 | wrmsrl(multiplex[virt].addr, multiplex[virt].saved); | 211 | wrmsrl(counters[i].addr, multiplex[virt].saved); |
211 | } | 212 | } |
212 | } | 213 | } |
213 | 214 | ||
@@ -222,7 +223,7 @@ static void nmi_cpu_switch(void *dummy) | |||
222 | 223 | ||
223 | /* move to next set */ | 224 | /* move to next set */ |
224 | si += model->num_counters; | 225 | si += model->num_counters; |
225 | if ((si > model->num_virt_counters) || (counter_config[si].count == 0)) | 226 | if ((si >= model->num_virt_counters) || (counter_config[si].count == 0)) |
226 | per_cpu(switch_index, cpu) = 0; | 227 | per_cpu(switch_index, cpu) = 0; |
227 | else | 228 | else |
228 | per_cpu(switch_index, cpu) = si; | 229 | per_cpu(switch_index, cpu) = si; |
@@ -303,11 +304,11 @@ static int allocate_msrs(void) | |||
303 | 304 | ||
304 | int i; | 305 | int i; |
305 | for_each_possible_cpu(i) { | 306 | for_each_possible_cpu(i) { |
306 | per_cpu(cpu_msrs, i).counters = kmalloc(counters_size, | 307 | per_cpu(cpu_msrs, i).counters = kzalloc(counters_size, |
307 | GFP_KERNEL); | 308 | GFP_KERNEL); |
308 | if (!per_cpu(cpu_msrs, i).counters) | 309 | if (!per_cpu(cpu_msrs, i).counters) |
309 | return 0; | 310 | return 0; |
310 | per_cpu(cpu_msrs, i).controls = kmalloc(controls_size, | 311 | per_cpu(cpu_msrs, i).controls = kzalloc(controls_size, |
311 | GFP_KERNEL); | 312 | GFP_KERNEL); |
312 | if (!per_cpu(cpu_msrs, i).controls) | 313 | if (!per_cpu(cpu_msrs, i).controls) |
313 | return 0; | 314 | return 0; |
@@ -598,6 +599,7 @@ static int __init ppro_init(char **cpu_type) | |||
598 | case 15: case 23: | 599 | case 15: case 23: |
599 | *cpu_type = "i386/core_2"; | 600 | *cpu_type = "i386/core_2"; |
600 | break; | 601 | break; |
602 | case 0x2e: | ||
601 | case 26: | 603 | case 26: |
602 | spec = &op_arch_perfmon_spec; | 604 | spec = &op_arch_perfmon_spec; |
603 | *cpu_type = "i386/core_i7"; | 605 | *cpu_type = "i386/core_i7"; |
diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c index 39686c29f03a..090cbbec7dbd 100644 --- a/arch/x86/oprofile/op_model_amd.c +++ b/arch/x86/oprofile/op_model_amd.c | |||
@@ -22,6 +22,9 @@ | |||
22 | #include <asm/ptrace.h> | 22 | #include <asm/ptrace.h> |
23 | #include <asm/msr.h> | 23 | #include <asm/msr.h> |
24 | #include <asm/nmi.h> | 24 | #include <asm/nmi.h> |
25 | #include <asm/apic.h> | ||
26 | #include <asm/processor.h> | ||
27 | #include <asm/cpufeature.h> | ||
25 | 28 | ||
26 | #include "op_x86_model.h" | 29 | #include "op_x86_model.h" |
27 | #include "op_counter.h" | 30 | #include "op_counter.h" |
@@ -43,23 +46,10 @@ | |||
43 | 46 | ||
44 | static unsigned long reset_value[NUM_VIRT_COUNTERS]; | 47 | static unsigned long reset_value[NUM_VIRT_COUNTERS]; |
45 | 48 | ||
46 | #ifdef CONFIG_OPROFILE_IBS | ||
47 | |||
48 | /* IbsFetchCtl bits/masks */ | ||
49 | #define IBS_FETCH_RAND_EN (1ULL<<57) | ||
50 | #define IBS_FETCH_VAL (1ULL<<49) | ||
51 | #define IBS_FETCH_ENABLE (1ULL<<48) | ||
52 | #define IBS_FETCH_CNT_MASK 0xFFFF0000ULL | ||
53 | |||
54 | /*IbsOpCtl bits */ | ||
55 | #define IBS_OP_CNT_CTL (1ULL<<19) | ||
56 | #define IBS_OP_VAL (1ULL<<18) | ||
57 | #define IBS_OP_ENABLE (1ULL<<17) | ||
58 | |||
59 | #define IBS_FETCH_SIZE 6 | 49 | #define IBS_FETCH_SIZE 6 |
60 | #define IBS_OP_SIZE 12 | 50 | #define IBS_OP_SIZE 12 |
61 | 51 | ||
62 | static int has_ibs; /* AMD Family10h and later */ | 52 | static u32 ibs_caps; |
63 | 53 | ||
64 | struct op_ibs_config { | 54 | struct op_ibs_config { |
65 | unsigned long op_enabled; | 55 | unsigned long op_enabled; |
@@ -71,24 +61,52 @@ struct op_ibs_config { | |||
71 | }; | 61 | }; |
72 | 62 | ||
73 | static struct op_ibs_config ibs_config; | 63 | static struct op_ibs_config ibs_config; |
64 | static u64 ibs_op_ctl; | ||
74 | 65 | ||
75 | #endif | 66 | /* |
67 | * IBS cpuid feature detection | ||
68 | */ | ||
76 | 69 | ||
77 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX | 70 | #define IBS_CPUID_FEATURES 0x8000001b |
71 | |||
72 | /* | ||
73 | * Same bit mask as for IBS cpuid feature flags (Fn8000_001B_EAX), but | ||
74 | * bit 0 is used to indicate the existence of IBS. | ||
75 | */ | ||
76 | #define IBS_CAPS_AVAIL (1LL<<0) | ||
77 | #define IBS_CAPS_RDWROPCNT (1LL<<3) | ||
78 | #define IBS_CAPS_OPCNT (1LL<<4) | ||
78 | 79 | ||
79 | static void op_mux_fill_in_addresses(struct op_msrs * const msrs) | 80 | /* |
81 | * IBS randomization macros | ||
82 | */ | ||
83 | #define IBS_RANDOM_BITS 12 | ||
84 | #define IBS_RANDOM_MASK ((1ULL << IBS_RANDOM_BITS) - 1) | ||
85 | #define IBS_RANDOM_MAXCNT_OFFSET (1ULL << (IBS_RANDOM_BITS - 5)) | ||
86 | |||
87 | static u32 get_ibs_caps(void) | ||
80 | { | 88 | { |
81 | int i; | 89 | u32 ibs_caps; |
90 | unsigned int max_level; | ||
82 | 91 | ||
83 | for (i = 0; i < NUM_VIRT_COUNTERS; i++) { | 92 | if (!boot_cpu_has(X86_FEATURE_IBS)) |
84 | int hw_counter = op_x86_virt_to_phys(i); | 93 | return 0; |
85 | if (reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i)) | 94 | |
86 | msrs->multiplex[i].addr = MSR_K7_PERFCTR0 + hw_counter; | 95 | /* check IBS cpuid feature flags */ |
87 | else | 96 | max_level = cpuid_eax(0x80000000); |
88 | msrs->multiplex[i].addr = 0; | 97 | if (max_level < IBS_CPUID_FEATURES) |
89 | } | 98 | return IBS_CAPS_AVAIL; |
99 | |||
100 | ibs_caps = cpuid_eax(IBS_CPUID_FEATURES); | ||
101 | if (!(ibs_caps & IBS_CAPS_AVAIL)) | ||
102 | /* cpuid flags not valid */ | ||
103 | return IBS_CAPS_AVAIL; | ||
104 | |||
105 | return ibs_caps; | ||
90 | } | 106 | } |
91 | 107 | ||
108 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX | ||
109 | |||
92 | static void op_mux_switch_ctrl(struct op_x86_model_spec const *model, | 110 | static void op_mux_switch_ctrl(struct op_x86_model_spec const *model, |
93 | struct op_msrs const * const msrs) | 111 | struct op_msrs const * const msrs) |
94 | { | 112 | { |
@@ -98,7 +116,7 @@ static void op_mux_switch_ctrl(struct op_x86_model_spec const *model, | |||
98 | /* enable active counters */ | 116 | /* enable active counters */ |
99 | for (i = 0; i < NUM_COUNTERS; ++i) { | 117 | for (i = 0; i < NUM_COUNTERS; ++i) { |
100 | int virt = op_x86_phys_to_virt(i); | 118 | int virt = op_x86_phys_to_virt(i); |
101 | if (!counter_config[virt].enabled) | 119 | if (!reset_value[virt]) |
102 | continue; | 120 | continue; |
103 | rdmsrl(msrs->controls[i].addr, val); | 121 | rdmsrl(msrs->controls[i].addr, val); |
104 | val &= model->reserved; | 122 | val &= model->reserved; |
@@ -107,10 +125,6 @@ static void op_mux_switch_ctrl(struct op_x86_model_spec const *model, | |||
107 | } | 125 | } |
108 | } | 126 | } |
109 | 127 | ||
110 | #else | ||
111 | |||
112 | static inline void op_mux_fill_in_addresses(struct op_msrs * const msrs) { } | ||
113 | |||
114 | #endif | 128 | #endif |
115 | 129 | ||
116 | /* functions for op_amd_spec */ | 130 | /* functions for op_amd_spec */ |
@@ -122,18 +136,12 @@ static void op_amd_fill_in_addresses(struct op_msrs * const msrs) | |||
122 | for (i = 0; i < NUM_COUNTERS; i++) { | 136 | for (i = 0; i < NUM_COUNTERS; i++) { |
123 | if (reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i)) | 137 | if (reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i)) |
124 | msrs->counters[i].addr = MSR_K7_PERFCTR0 + i; | 138 | msrs->counters[i].addr = MSR_K7_PERFCTR0 + i; |
125 | else | ||
126 | msrs->counters[i].addr = 0; | ||
127 | } | 139 | } |
128 | 140 | ||
129 | for (i = 0; i < NUM_CONTROLS; i++) { | 141 | for (i = 0; i < NUM_CONTROLS; i++) { |
130 | if (reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i)) | 142 | if (reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i)) |
131 | msrs->controls[i].addr = MSR_K7_EVNTSEL0 + i; | 143 | msrs->controls[i].addr = MSR_K7_EVNTSEL0 + i; |
132 | else | ||
133 | msrs->controls[i].addr = 0; | ||
134 | } | 144 | } |
135 | |||
136 | op_mux_fill_in_addresses(msrs); | ||
137 | } | 145 | } |
138 | 146 | ||
139 | static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, | 147 | static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, |
@@ -144,7 +152,8 @@ static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, | |||
144 | 152 | ||
145 | /* setup reset_value */ | 153 | /* setup reset_value */ |
146 | for (i = 0; i < NUM_VIRT_COUNTERS; ++i) { | 154 | for (i = 0; i < NUM_VIRT_COUNTERS; ++i) { |
147 | if (counter_config[i].enabled) | 155 | if (counter_config[i].enabled |
156 | && msrs->counters[op_x86_virt_to_phys(i)].addr) | ||
148 | reset_value[i] = counter_config[i].count; | 157 | reset_value[i] = counter_config[i].count; |
149 | else | 158 | else |
150 | reset_value[i] = 0; | 159 | reset_value[i] = 0; |
@@ -152,9 +161,18 @@ static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, | |||
152 | 161 | ||
153 | /* clear all counters */ | 162 | /* clear all counters */ |
154 | for (i = 0; i < NUM_CONTROLS; ++i) { | 163 | for (i = 0; i < NUM_CONTROLS; ++i) { |
155 | if (unlikely(!msrs->controls[i].addr)) | 164 | if (unlikely(!msrs->controls[i].addr)) { |
165 | if (counter_config[i].enabled && !smp_processor_id()) | ||
166 | /* | ||
167 | * counter is reserved, this is on all | ||
168 | * cpus, so report only for cpu #0 | ||
169 | */ | ||
170 | op_x86_warn_reserved(i); | ||
156 | continue; | 171 | continue; |
172 | } | ||
157 | rdmsrl(msrs->controls[i].addr, val); | 173 | rdmsrl(msrs->controls[i].addr, val); |
174 | if (val & ARCH_PERFMON_EVENTSEL_ENABLE) | ||
175 | op_x86_warn_in_use(i); | ||
158 | val &= model->reserved; | 176 | val &= model->reserved; |
159 | wrmsrl(msrs->controls[i].addr, val); | 177 | wrmsrl(msrs->controls[i].addr, val); |
160 | } | 178 | } |
@@ -169,9 +187,7 @@ static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, | |||
169 | /* enable active counters */ | 187 | /* enable active counters */ |
170 | for (i = 0; i < NUM_COUNTERS; ++i) { | 188 | for (i = 0; i < NUM_COUNTERS; ++i) { |
171 | int virt = op_x86_phys_to_virt(i); | 189 | int virt = op_x86_phys_to_virt(i); |
172 | if (!counter_config[virt].enabled) | 190 | if (!reset_value[virt]) |
173 | continue; | ||
174 | if (!msrs->counters[i].addr) | ||
175 | continue; | 191 | continue; |
176 | 192 | ||
177 | /* setup counter registers */ | 193 | /* setup counter registers */ |
@@ -185,7 +201,60 @@ static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, | |||
185 | } | 201 | } |
186 | } | 202 | } |
187 | 203 | ||
188 | #ifdef CONFIG_OPROFILE_IBS | 204 | /* |
205 | * 16-bit Linear Feedback Shift Register (LFSR) | ||
206 | * | ||
207 | * 16 14 13 11 | ||
208 | * Feedback polynomial = X + X + X + X + 1 | ||
209 | */ | ||
210 | static unsigned int lfsr_random(void) | ||
211 | { | ||
212 | static unsigned int lfsr_value = 0xF00D; | ||
213 | unsigned int bit; | ||
214 | |||
215 | /* Compute next bit to shift in */ | ||
216 | bit = ((lfsr_value >> 0) ^ | ||
217 | (lfsr_value >> 2) ^ | ||
218 | (lfsr_value >> 3) ^ | ||
219 | (lfsr_value >> 5)) & 0x0001; | ||
220 | |||
221 | /* Advance to next register value */ | ||
222 | lfsr_value = (lfsr_value >> 1) | (bit << 15); | ||
223 | |||
224 | return lfsr_value; | ||
225 | } | ||
226 | |||
227 | /* | ||
228 | * IBS software randomization | ||
229 | * | ||
230 | * The IBS periodic op counter is randomized in software. The lower 12 | ||
231 | * bits of the 20 bit counter are randomized. IbsOpCurCnt is | ||
232 | * initialized with a 12 bit random value. | ||
233 | */ | ||
234 | static inline u64 op_amd_randomize_ibs_op(u64 val) | ||
235 | { | ||
236 | unsigned int random = lfsr_random(); | ||
237 | |||
238 | if (!(ibs_caps & IBS_CAPS_RDWROPCNT)) | ||
239 | /* | ||
240 | * Work around if the hw can not write to IbsOpCurCnt | ||
241 | * | ||
242 | * Randomize the lower 8 bits of the 16 bit | ||
243 | * IbsOpMaxCnt [15:0] value in the range of -128 to | ||
244 | * +127 by adding/subtracting an offset to the | ||
245 | * maximum count (IbsOpMaxCnt). | ||
246 | * | ||
247 | * To avoid over or underflows and protect upper bits | ||
248 | * starting at bit 16, the initial value for | ||
249 | * IbsOpMaxCnt must fit in the range from 0x0081 to | ||
250 | * 0xff80. | ||
251 | */ | ||
252 | val += (s8)(random >> 4); | ||
253 | else | ||
254 | val |= (u64)(random & IBS_RANDOM_MASK) << 32; | ||
255 | |||
256 | return val; | ||
257 | } | ||
189 | 258 | ||
190 | static inline void | 259 | static inline void |
191 | op_amd_handle_ibs(struct pt_regs * const regs, | 260 | op_amd_handle_ibs(struct pt_regs * const regs, |
@@ -194,7 +263,7 @@ op_amd_handle_ibs(struct pt_regs * const regs, | |||
194 | u64 val, ctl; | 263 | u64 val, ctl; |
195 | struct op_entry entry; | 264 | struct op_entry entry; |
196 | 265 | ||
197 | if (!has_ibs) | 266 | if (!ibs_caps) |
198 | return; | 267 | return; |
199 | 268 | ||
200 | if (ibs_config.fetch_enabled) { | 269 | if (ibs_config.fetch_enabled) { |
@@ -210,7 +279,7 @@ op_amd_handle_ibs(struct pt_regs * const regs, | |||
210 | oprofile_write_commit(&entry); | 279 | oprofile_write_commit(&entry); |
211 | 280 | ||
212 | /* reenable the IRQ */ | 281 | /* reenable the IRQ */ |
213 | ctl &= ~(IBS_FETCH_VAL | IBS_FETCH_CNT_MASK); | 282 | ctl &= ~(IBS_FETCH_VAL | IBS_FETCH_CNT); |
214 | ctl |= IBS_FETCH_ENABLE; | 283 | ctl |= IBS_FETCH_ENABLE; |
215 | wrmsrl(MSR_AMD64_IBSFETCHCTL, ctl); | 284 | wrmsrl(MSR_AMD64_IBSFETCHCTL, ctl); |
216 | } | 285 | } |
@@ -236,8 +305,7 @@ op_amd_handle_ibs(struct pt_regs * const regs, | |||
236 | oprofile_write_commit(&entry); | 305 | oprofile_write_commit(&entry); |
237 | 306 | ||
238 | /* reenable the IRQ */ | 307 | /* reenable the IRQ */ |
239 | ctl &= ~IBS_OP_VAL & 0xFFFFFFFF; | 308 | ctl = op_amd_randomize_ibs_op(ibs_op_ctl); |
240 | ctl |= IBS_OP_ENABLE; | ||
241 | wrmsrl(MSR_AMD64_IBSOPCTL, ctl); | 309 | wrmsrl(MSR_AMD64_IBSOPCTL, ctl); |
242 | } | 310 | } |
243 | } | 311 | } |
@@ -246,41 +314,57 @@ op_amd_handle_ibs(struct pt_regs * const regs, | |||
246 | static inline void op_amd_start_ibs(void) | 314 | static inline void op_amd_start_ibs(void) |
247 | { | 315 | { |
248 | u64 val; | 316 | u64 val; |
249 | if (has_ibs && ibs_config.fetch_enabled) { | 317 | |
250 | val = (ibs_config.max_cnt_fetch >> 4) & 0xFFFF; | 318 | if (!ibs_caps) |
319 | return; | ||
320 | |||
321 | if (ibs_config.fetch_enabled) { | ||
322 | val = (ibs_config.max_cnt_fetch >> 4) & IBS_FETCH_MAX_CNT; | ||
251 | val |= ibs_config.rand_en ? IBS_FETCH_RAND_EN : 0; | 323 | val |= ibs_config.rand_en ? IBS_FETCH_RAND_EN : 0; |
252 | val |= IBS_FETCH_ENABLE; | 324 | val |= IBS_FETCH_ENABLE; |
253 | wrmsrl(MSR_AMD64_IBSFETCHCTL, val); | 325 | wrmsrl(MSR_AMD64_IBSFETCHCTL, val); |
254 | } | 326 | } |
255 | 327 | ||
256 | if (has_ibs && ibs_config.op_enabled) { | 328 | if (ibs_config.op_enabled) { |
257 | val = (ibs_config.max_cnt_op >> 4) & 0xFFFF; | 329 | ibs_op_ctl = ibs_config.max_cnt_op >> 4; |
258 | val |= ibs_config.dispatched_ops ? IBS_OP_CNT_CTL : 0; | 330 | if (!(ibs_caps & IBS_CAPS_RDWROPCNT)) { |
259 | val |= IBS_OP_ENABLE; | 331 | /* |
332 | * IbsOpCurCnt not supported. See | ||
333 | * op_amd_randomize_ibs_op() for details. | ||
334 | */ | ||
335 | ibs_op_ctl = clamp(ibs_op_ctl, 0x0081ULL, 0xFF80ULL); | ||
336 | } else { | ||
337 | /* | ||
338 | * The start value is randomized with a | ||
339 | * positive offset, we need to compensate it | ||
340 | * with the half of the randomized range. Also | ||
341 | * avoid underflows. | ||
342 | */ | ||
343 | ibs_op_ctl = min(ibs_op_ctl + IBS_RANDOM_MAXCNT_OFFSET, | ||
344 | IBS_OP_MAX_CNT); | ||
345 | } | ||
346 | if (ibs_caps & IBS_CAPS_OPCNT && ibs_config.dispatched_ops) | ||
347 | ibs_op_ctl |= IBS_OP_CNT_CTL; | ||
348 | ibs_op_ctl |= IBS_OP_ENABLE; | ||
349 | val = op_amd_randomize_ibs_op(ibs_op_ctl); | ||
260 | wrmsrl(MSR_AMD64_IBSOPCTL, val); | 350 | wrmsrl(MSR_AMD64_IBSOPCTL, val); |
261 | } | 351 | } |
262 | } | 352 | } |
263 | 353 | ||
264 | static void op_amd_stop_ibs(void) | 354 | static void op_amd_stop_ibs(void) |
265 | { | 355 | { |
266 | if (has_ibs && ibs_config.fetch_enabled) | 356 | if (!ibs_caps) |
357 | return; | ||
358 | |||
359 | if (ibs_config.fetch_enabled) | ||
267 | /* clear max count and enable */ | 360 | /* clear max count and enable */ |
268 | wrmsrl(MSR_AMD64_IBSFETCHCTL, 0); | 361 | wrmsrl(MSR_AMD64_IBSFETCHCTL, 0); |
269 | 362 | ||
270 | if (has_ibs && ibs_config.op_enabled) | 363 | if (ibs_config.op_enabled) |
271 | /* clear max count and enable */ | 364 | /* clear max count and enable */ |
272 | wrmsrl(MSR_AMD64_IBSOPCTL, 0); | 365 | wrmsrl(MSR_AMD64_IBSOPCTL, 0); |
273 | } | 366 | } |
274 | 367 | ||
275 | #else | ||
276 | |||
277 | static inline void op_amd_handle_ibs(struct pt_regs * const regs, | ||
278 | struct op_msrs const * const msrs) { } | ||
279 | static inline void op_amd_start_ibs(void) { } | ||
280 | static inline void op_amd_stop_ibs(void) { } | ||
281 | |||
282 | #endif | ||
283 | |||
284 | static int op_amd_check_ctrs(struct pt_regs * const regs, | 368 | static int op_amd_check_ctrs(struct pt_regs * const regs, |
285 | struct op_msrs const * const msrs) | 369 | struct op_msrs const * const msrs) |
286 | { | 370 | { |
@@ -314,7 +398,7 @@ static void op_amd_start(struct op_msrs const * const msrs) | |||
314 | if (!reset_value[op_x86_phys_to_virt(i)]) | 398 | if (!reset_value[op_x86_phys_to_virt(i)]) |
315 | continue; | 399 | continue; |
316 | rdmsrl(msrs->controls[i].addr, val); | 400 | rdmsrl(msrs->controls[i].addr, val); |
317 | val |= ARCH_PERFMON_EVENTSEL0_ENABLE; | 401 | val |= ARCH_PERFMON_EVENTSEL_ENABLE; |
318 | wrmsrl(msrs->controls[i].addr, val); | 402 | wrmsrl(msrs->controls[i].addr, val); |
319 | } | 403 | } |
320 | 404 | ||
@@ -334,7 +418,7 @@ static void op_amd_stop(struct op_msrs const * const msrs) | |||
334 | if (!reset_value[op_x86_phys_to_virt(i)]) | 418 | if (!reset_value[op_x86_phys_to_virt(i)]) |
335 | continue; | 419 | continue; |
336 | rdmsrl(msrs->controls[i].addr, val); | 420 | rdmsrl(msrs->controls[i].addr, val); |
337 | val &= ~ARCH_PERFMON_EVENTSEL0_ENABLE; | 421 | val &= ~ARCH_PERFMON_EVENTSEL_ENABLE; |
338 | wrmsrl(msrs->controls[i].addr, val); | 422 | wrmsrl(msrs->controls[i].addr, val); |
339 | } | 423 | } |
340 | 424 | ||
@@ -355,8 +439,6 @@ static void op_amd_shutdown(struct op_msrs const * const msrs) | |||
355 | } | 439 | } |
356 | } | 440 | } |
357 | 441 | ||
358 | #ifdef CONFIG_OPROFILE_IBS | ||
359 | |||
360 | static u8 ibs_eilvt_off; | 442 | static u8 ibs_eilvt_off; |
361 | 443 | ||
362 | static inline void apic_init_ibs_nmi_per_cpu(void *arg) | 444 | static inline void apic_init_ibs_nmi_per_cpu(void *arg) |
@@ -405,45 +487,36 @@ static int init_ibs_nmi(void) | |||
405 | return 1; | 487 | return 1; |
406 | } | 488 | } |
407 | 489 | ||
408 | #ifdef CONFIG_NUMA | ||
409 | /* Sanity check */ | ||
410 | /* Works only for 64bit with proper numa implementation. */ | ||
411 | if (nodes != num_possible_nodes()) { | ||
412 | printk(KERN_DEBUG "Failed to setup CPU node(s) for IBS, " | ||
413 | "found: %d, expected %d", | ||
414 | nodes, num_possible_nodes()); | ||
415 | return 1; | ||
416 | } | ||
417 | #endif | ||
418 | return 0; | 490 | return 0; |
419 | } | 491 | } |
420 | 492 | ||
421 | /* uninitialize the APIC for the IBS interrupts if needed */ | 493 | /* uninitialize the APIC for the IBS interrupts if needed */ |
422 | static void clear_ibs_nmi(void) | 494 | static void clear_ibs_nmi(void) |
423 | { | 495 | { |
424 | if (has_ibs) | 496 | if (ibs_caps) |
425 | on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1); | 497 | on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1); |
426 | } | 498 | } |
427 | 499 | ||
428 | /* initialize the APIC for the IBS interrupts if available */ | 500 | /* initialize the APIC for the IBS interrupts if available */ |
429 | static void ibs_init(void) | 501 | static void ibs_init(void) |
430 | { | 502 | { |
431 | has_ibs = boot_cpu_has(X86_FEATURE_IBS); | 503 | ibs_caps = get_ibs_caps(); |
432 | 504 | ||
433 | if (!has_ibs) | 505 | if (!ibs_caps) |
434 | return; | 506 | return; |
435 | 507 | ||
436 | if (init_ibs_nmi()) { | 508 | if (init_ibs_nmi()) { |
437 | has_ibs = 0; | 509 | ibs_caps = 0; |
438 | return; | 510 | return; |
439 | } | 511 | } |
440 | 512 | ||
441 | printk(KERN_INFO "oprofile: AMD IBS detected\n"); | 513 | printk(KERN_INFO "oprofile: AMD IBS detected (0x%08x)\n", |
514 | (unsigned)ibs_caps); | ||
442 | } | 515 | } |
443 | 516 | ||
444 | static void ibs_exit(void) | 517 | static void ibs_exit(void) |
445 | { | 518 | { |
446 | if (!has_ibs) | 519 | if (!ibs_caps) |
447 | return; | 520 | return; |
448 | 521 | ||
449 | clear_ibs_nmi(); | 522 | clear_ibs_nmi(); |
@@ -463,7 +536,7 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root) | |||
463 | if (ret) | 536 | if (ret) |
464 | return ret; | 537 | return ret; |
465 | 538 | ||
466 | if (!has_ibs) | 539 | if (!ibs_caps) |
467 | return ret; | 540 | return ret; |
468 | 541 | ||
469 | /* model specific files */ | 542 | /* model specific files */ |
@@ -473,7 +546,7 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root) | |||
473 | ibs_config.fetch_enabled = 0; | 546 | ibs_config.fetch_enabled = 0; |
474 | ibs_config.max_cnt_op = 250000; | 547 | ibs_config.max_cnt_op = 250000; |
475 | ibs_config.op_enabled = 0; | 548 | ibs_config.op_enabled = 0; |
476 | ibs_config.dispatched_ops = 1; | 549 | ibs_config.dispatched_ops = 0; |
477 | 550 | ||
478 | dir = oprofilefs_mkdir(sb, root, "ibs_fetch"); | 551 | dir = oprofilefs_mkdir(sb, root, "ibs_fetch"); |
479 | oprofilefs_create_ulong(sb, dir, "enable", | 552 | oprofilefs_create_ulong(sb, dir, "enable", |
@@ -488,8 +561,9 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root) | |||
488 | &ibs_config.op_enabled); | 561 | &ibs_config.op_enabled); |
489 | oprofilefs_create_ulong(sb, dir, "max_count", | 562 | oprofilefs_create_ulong(sb, dir, "max_count", |
490 | &ibs_config.max_cnt_op); | 563 | &ibs_config.max_cnt_op); |
491 | oprofilefs_create_ulong(sb, dir, "dispatched_ops", | 564 | if (ibs_caps & IBS_CAPS_OPCNT) |
492 | &ibs_config.dispatched_ops); | 565 | oprofilefs_create_ulong(sb, dir, "dispatched_ops", |
566 | &ibs_config.dispatched_ops); | ||
493 | 567 | ||
494 | return 0; | 568 | return 0; |
495 | } | 569 | } |
@@ -507,19 +581,6 @@ static void op_amd_exit(void) | |||
507 | ibs_exit(); | 581 | ibs_exit(); |
508 | } | 582 | } |
509 | 583 | ||
510 | #else | ||
511 | |||
512 | /* no IBS support */ | ||
513 | |||
514 | static int op_amd_init(struct oprofile_operations *ops) | ||
515 | { | ||
516 | return 0; | ||
517 | } | ||
518 | |||
519 | static void op_amd_exit(void) {} | ||
520 | |||
521 | #endif /* CONFIG_OPROFILE_IBS */ | ||
522 | |||
523 | struct op_x86_model_spec op_amd_spec = { | 584 | struct op_x86_model_spec op_amd_spec = { |
524 | .num_counters = NUM_COUNTERS, | 585 | .num_counters = NUM_COUNTERS, |
525 | .num_controls = NUM_CONTROLS, | 586 | .num_controls = NUM_CONTROLS, |
diff --git a/arch/x86/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c index ac6b354becdf..e6a160a4684a 100644 --- a/arch/x86/oprofile/op_model_p4.c +++ b/arch/x86/oprofile/op_model_p4.c | |||
@@ -394,12 +394,6 @@ static void p4_fill_in_addresses(struct op_msrs * const msrs) | |||
394 | setup_num_counters(); | 394 | setup_num_counters(); |
395 | stag = get_stagger(); | 395 | stag = get_stagger(); |
396 | 396 | ||
397 | /* initialize some registers */ | ||
398 | for (i = 0; i < num_counters; ++i) | ||
399 | msrs->counters[i].addr = 0; | ||
400 | for (i = 0; i < num_controls; ++i) | ||
401 | msrs->controls[i].addr = 0; | ||
402 | |||
403 | /* the counter & cccr registers we pay attention to */ | 397 | /* the counter & cccr registers we pay attention to */ |
404 | for (i = 0; i < num_counters; ++i) { | 398 | for (i = 0; i < num_counters; ++i) { |
405 | addr = p4_counters[VIRT_CTR(stag, i)].counter_address; | 399 | addr = p4_counters[VIRT_CTR(stag, i)].counter_address; |
diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c index 8eb05878554c..2bf90fafa7b5 100644 --- a/arch/x86/oprofile/op_model_ppro.c +++ b/arch/x86/oprofile/op_model_ppro.c | |||
@@ -37,15 +37,11 @@ static void ppro_fill_in_addresses(struct op_msrs * const msrs) | |||
37 | for (i = 0; i < num_counters; i++) { | 37 | for (i = 0; i < num_counters; i++) { |
38 | if (reserve_perfctr_nmi(MSR_P6_PERFCTR0 + i)) | 38 | if (reserve_perfctr_nmi(MSR_P6_PERFCTR0 + i)) |
39 | msrs->counters[i].addr = MSR_P6_PERFCTR0 + i; | 39 | msrs->counters[i].addr = MSR_P6_PERFCTR0 + i; |
40 | else | ||
41 | msrs->counters[i].addr = 0; | ||
42 | } | 40 | } |
43 | 41 | ||
44 | for (i = 0; i < num_counters; i++) { | 42 | for (i = 0; i < num_counters; i++) { |
45 | if (reserve_evntsel_nmi(MSR_P6_EVNTSEL0 + i)) | 43 | if (reserve_evntsel_nmi(MSR_P6_EVNTSEL0 + i)) |
46 | msrs->controls[i].addr = MSR_P6_EVNTSEL0 + i; | 44 | msrs->controls[i].addr = MSR_P6_EVNTSEL0 + i; |
47 | else | ||
48 | msrs->controls[i].addr = 0; | ||
49 | } | 45 | } |
50 | } | 46 | } |
51 | 47 | ||
@@ -57,7 +53,7 @@ static void ppro_setup_ctrs(struct op_x86_model_spec const *model, | |||
57 | int i; | 53 | int i; |
58 | 54 | ||
59 | if (!reset_value) { | 55 | if (!reset_value) { |
60 | reset_value = kmalloc(sizeof(reset_value[0]) * num_counters, | 56 | reset_value = kzalloc(sizeof(reset_value[0]) * num_counters, |
61 | GFP_ATOMIC); | 57 | GFP_ATOMIC); |
62 | if (!reset_value) | 58 | if (!reset_value) |
63 | return; | 59 | return; |
@@ -82,9 +78,18 @@ static void ppro_setup_ctrs(struct op_x86_model_spec const *model, | |||
82 | 78 | ||
83 | /* clear all counters */ | 79 | /* clear all counters */ |
84 | for (i = 0; i < num_counters; ++i) { | 80 | for (i = 0; i < num_counters; ++i) { |
85 | if (unlikely(!msrs->controls[i].addr)) | 81 | if (unlikely(!msrs->controls[i].addr)) { |
82 | if (counter_config[i].enabled && !smp_processor_id()) | ||
83 | /* | ||
84 | * counter is reserved, this is on all | ||
85 | * cpus, so report only for cpu #0 | ||
86 | */ | ||
87 | op_x86_warn_reserved(i); | ||
86 | continue; | 88 | continue; |
89 | } | ||
87 | rdmsrl(msrs->controls[i].addr, val); | 90 | rdmsrl(msrs->controls[i].addr, val); |
91 | if (val & ARCH_PERFMON_EVENTSEL_ENABLE) | ||
92 | op_x86_warn_in_use(i); | ||
88 | val &= model->reserved; | 93 | val &= model->reserved; |
89 | wrmsrl(msrs->controls[i].addr, val); | 94 | wrmsrl(msrs->controls[i].addr, val); |
90 | } | 95 | } |
@@ -161,7 +166,7 @@ static void ppro_start(struct op_msrs const * const msrs) | |||
161 | for (i = 0; i < num_counters; ++i) { | 166 | for (i = 0; i < num_counters; ++i) { |
162 | if (reset_value[i]) { | 167 | if (reset_value[i]) { |
163 | rdmsrl(msrs->controls[i].addr, val); | 168 | rdmsrl(msrs->controls[i].addr, val); |
164 | val |= ARCH_PERFMON_EVENTSEL0_ENABLE; | 169 | val |= ARCH_PERFMON_EVENTSEL_ENABLE; |
165 | wrmsrl(msrs->controls[i].addr, val); | 170 | wrmsrl(msrs->controls[i].addr, val); |
166 | } | 171 | } |
167 | } | 172 | } |
@@ -179,7 +184,7 @@ static void ppro_stop(struct op_msrs const * const msrs) | |||
179 | if (!reset_value[i]) | 184 | if (!reset_value[i]) |
180 | continue; | 185 | continue; |
181 | rdmsrl(msrs->controls[i].addr, val); | 186 | rdmsrl(msrs->controls[i].addr, val); |
182 | val &= ~ARCH_PERFMON_EVENTSEL0_ENABLE; | 187 | val &= ~ARCH_PERFMON_EVENTSEL_ENABLE; |
183 | wrmsrl(msrs->controls[i].addr, val); | 188 | wrmsrl(msrs->controls[i].addr, val); |
184 | } | 189 | } |
185 | } | 190 | } |
diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h index 7b8e75d16081..ff82a755edd4 100644 --- a/arch/x86/oprofile/op_x86_model.h +++ b/arch/x86/oprofile/op_x86_model.h | |||
@@ -57,6 +57,26 @@ struct op_x86_model_spec { | |||
57 | 57 | ||
58 | struct op_counter_config; | 58 | struct op_counter_config; |
59 | 59 | ||
60 | static inline void op_x86_warn_in_use(int counter) | ||
61 | { | ||
62 | /* | ||
63 | * The warning indicates an already running counter. If | ||
64 | * oprofile doesn't collect data, then try using a different | ||
65 | * performance counter on your platform to monitor the desired | ||
66 | * event. Delete counter #%d from the desired event by editing | ||
67 | * the /usr/share/oprofile/%s/<cpu>/events file. If the event | ||
68 | * cannot be monitored by any other counter, contact your | ||
69 | * hardware or BIOS vendor. | ||
70 | */ | ||
71 | pr_warning("oprofile: counter #%d on cpu #%d may already be used\n", | ||
72 | counter, smp_processor_id()); | ||
73 | } | ||
74 | |||
75 | static inline void op_x86_warn_reserved(int counter) | ||
76 | { | ||
77 | pr_warning("oprofile: counter #%d is already reserved\n", counter); | ||
78 | } | ||
79 | |||
60 | extern u64 op_x86_get_ctrl(struct op_x86_model_spec const *model, | 80 | extern u64 op_x86_get_ctrl(struct op_x86_model_spec const *model, |
61 | struct op_counter_config *counter_config); | 81 | struct op_counter_config *counter_config); |
62 | extern int op_x86_phys_to_virt(int phys); | 82 | extern int op_x86_phys_to_virt(int phys); |