diff options
103 files changed, 6699 insertions, 5482 deletions
diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt index 2f9115c0ae6..61c291cddf1 100644 --- a/Documentation/kprobes.txt +++ b/Documentation/kprobes.txt | |||
@@ -165,8 +165,8 @@ the user entry_handler invocation is also skipped. | |||
165 | 165 | ||
166 | 1.4 How Does Jump Optimization Work? | 166 | 1.4 How Does Jump Optimization Work? |
167 | 167 | ||
168 | If you configured your kernel with CONFIG_OPTPROBES=y (currently | 168 | If your kernel is built with CONFIG_OPTPROBES=y (currently this flag |
169 | this option is supported on x86/x86-64, non-preemptive kernel) and | 169 | is automatically set 'y' on x86/x86-64, non-preemptive kernel) and |
170 | the "debug.kprobes_optimization" kernel parameter is set to 1 (see | 170 | the "debug.kprobes_optimization" kernel parameter is set to 1 (see |
171 | sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump | 171 | sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump |
172 | instruction instead of a breakpoint instruction at each probepoint. | 172 | instruction instead of a breakpoint instruction at each probepoint. |
@@ -271,8 +271,6 @@ tweak the kernel's execution path, you need to suppress optimization, | |||
271 | using one of the following techniques: | 271 | using one of the following techniques: |
272 | - Specify an empty function for the kprobe's post_handler or break_handler. | 272 | - Specify an empty function for the kprobe's post_handler or break_handler. |
273 | or | 273 | or |
274 | - Config CONFIG_OPTPROBES=n. | ||
275 | or | ||
276 | - Execute 'sysctl -w debug.kprobes_optimization=n' | 274 | - Execute 'sysctl -w debug.kprobes_optimization=n' |
277 | 275 | ||
278 | 2. Architectures Supported | 276 | 2. Architectures Supported |
@@ -307,10 +305,6 @@ it useful to "Compile the kernel with debug info" (CONFIG_DEBUG_INFO), | |||
307 | so you can use "objdump -d -l vmlinux" to see the source-to-object | 305 | so you can use "objdump -d -l vmlinux" to see the source-to-object |
308 | code mapping. | 306 | code mapping. |
309 | 307 | ||
310 | If you want to reduce probing overhead, set "Kprobes jump optimization | ||
311 | support" (CONFIG_OPTPROBES) to "y". You can find this option under the | ||
312 | "Kprobes" line. | ||
313 | |||
314 | 4. API Reference | 308 | 4. API Reference |
315 | 309 | ||
316 | The Kprobes API includes a "register" function and an "unregister" | 310 | The Kprobes API includes a "register" function and an "unregister" |
diff --git a/MAINTAINERS b/MAINTAINERS index 7a9ccda2a30..c3e9c3633b7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -4343,13 +4343,13 @@ M: Paul Mackerras <paulus@samba.org> | |||
4343 | M: Ingo Molnar <mingo@elte.hu> | 4343 | M: Ingo Molnar <mingo@elte.hu> |
4344 | M: Arnaldo Carvalho de Melo <acme@redhat.com> | 4344 | M: Arnaldo Carvalho de Melo <acme@redhat.com> |
4345 | S: Supported | 4345 | S: Supported |
4346 | F: kernel/perf_event.c | 4346 | F: kernel/perf_event*.c |
4347 | F: include/linux/perf_event.h | 4347 | F: include/linux/perf_event.h |
4348 | F: arch/*/kernel/perf_event.c | 4348 | F: arch/*/kernel/perf_event*.c |
4349 | F: arch/*/kernel/*/perf_event.c | 4349 | F: arch/*/kernel/*/perf_event*.c |
4350 | F: arch/*/kernel/*/*/perf_event.c | 4350 | F: arch/*/kernel/*/*/perf_event*.c |
4351 | F: arch/*/include/asm/perf_event.h | 4351 | F: arch/*/include/asm/perf_event.h |
4352 | F: arch/*/lib/perf_event.c | 4352 | F: arch/*/lib/perf_event*.c |
4353 | F: arch/*/kernel/perf_callchain.c | 4353 | F: arch/*/kernel/perf_callchain.c |
4354 | F: tools/perf/ | 4354 | F: tools/perf/ |
4355 | 4355 | ||
diff --git a/arch/Kconfig b/arch/Kconfig index e5eb1337a53..f06010fb483 100644 --- a/arch/Kconfig +++ b/arch/Kconfig | |||
@@ -42,15 +42,10 @@ config KPROBES | |||
42 | If in doubt, say "N". | 42 | If in doubt, say "N". |
43 | 43 | ||
44 | config OPTPROBES | 44 | config OPTPROBES |
45 | bool "Kprobes jump optimization support (EXPERIMENTAL)" | 45 | def_bool y |
46 | default y | 46 | depends on KPROBES && HAVE_OPTPROBES |
47 | depends on KPROBES | ||
48 | depends on !PREEMPT | 47 | depends on !PREEMPT |
49 | depends on HAVE_OPTPROBES | ||
50 | select KALLSYMS_ALL | 48 | select KALLSYMS_ALL |
51 | help | ||
52 | This option will allow kprobes to optimize breakpoint to | ||
53 | a jump for reducing its overhead. | ||
54 | 49 | ||
55 | config HAVE_EFFICIENT_UNALIGNED_ACCESS | 50 | config HAVE_EFFICIENT_UNALIGNED_ACCESS |
56 | bool | 51 | bool |
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 9458685902b..97a95dfd118 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
@@ -58,6 +58,9 @@ config X86 | |||
58 | select HAVE_ARCH_KMEMCHECK | 58 | select HAVE_ARCH_KMEMCHECK |
59 | select HAVE_USER_RETURN_NOTIFIER | 59 | select HAVE_USER_RETURN_NOTIFIER |
60 | 60 | ||
61 | config INSTRUCTION_DECODER | ||
62 | def_bool (KPROBES || PERF_EVENTS) | ||
63 | |||
61 | config OUTPUT_FORMAT | 64 | config OUTPUT_FORMAT |
62 | string | 65 | string |
63 | default "elf32-i386" if X86_32 | 66 | default "elf32-i386" if X86_32 |
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu index a19829374e6..918fbb1855c 100644 --- a/arch/x86/Kconfig.cpu +++ b/arch/x86/Kconfig.cpu | |||
@@ -502,23 +502,3 @@ config CPU_SUP_UMC_32 | |||
502 | CPU might render the kernel unbootable. | 502 | CPU might render the kernel unbootable. |
503 | 503 | ||
504 | If unsure, say N. | 504 | If unsure, say N. |
505 | |||
506 | config X86_DS | ||
507 | def_bool X86_PTRACE_BTS | ||
508 | depends on X86_DEBUGCTLMSR | ||
509 | select HAVE_HW_BRANCH_TRACER | ||
510 | |||
511 | config X86_PTRACE_BTS | ||
512 | bool "Branch Trace Store" | ||
513 | default y | ||
514 | depends on X86_DEBUGCTLMSR | ||
515 | depends on BROKEN | ||
516 | ---help--- | ||
517 | This adds a ptrace interface to the hardware's branch trace store. | ||
518 | |||
519 | Debuggers may use it to collect an execution trace of the debugged | ||
520 | application in order to answer the question 'how did I get here?'. | ||
521 | Debuggers may trace user mode as well as kernel mode. | ||
522 | |||
523 | Say Y unless there is no application development on this machine | ||
524 | and you want to save a small amount of code size. | ||
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index bc01e3ebfeb..bd58c8abbfb 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug | |||
@@ -174,15 +174,6 @@ config IOMMU_LEAK | |||
174 | Add a simple leak tracer to the IOMMU code. This is useful when you | 174 | Add a simple leak tracer to the IOMMU code. This is useful when you |
175 | are debugging a buggy device driver that leaks IOMMU mappings. | 175 | are debugging a buggy device driver that leaks IOMMU mappings. |
176 | 176 | ||
177 | config X86_DS_SELFTEST | ||
178 | bool "DS selftest" | ||
179 | default y | ||
180 | depends on DEBUG_KERNEL | ||
181 | depends on X86_DS | ||
182 | ---help--- | ||
183 | Perform Debug Store selftests at boot time. | ||
184 | If in doubt, say "N". | ||
185 | |||
186 | config HAVE_MMIOTRACE_SUPPORT | 177 | config HAVE_MMIOTRACE_SUPPORT |
187 | def_bool y | 178 | def_bool y |
188 | 179 | ||
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index b4ac2cdcb64..1fa03e04ae4 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h | |||
@@ -373,6 +373,7 @@ extern atomic_t init_deasserted; | |||
373 | extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip); | 373 | extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip); |
374 | #endif | 374 | #endif |
375 | 375 | ||
376 | #ifdef CONFIG_X86_LOCAL_APIC | ||
376 | static inline u32 apic_read(u32 reg) | 377 | static inline u32 apic_read(u32 reg) |
377 | { | 378 | { |
378 | return apic->read(reg); | 379 | return apic->read(reg); |
@@ -403,10 +404,19 @@ static inline u32 safe_apic_wait_icr_idle(void) | |||
403 | return apic->safe_wait_icr_idle(); | 404 | return apic->safe_wait_icr_idle(); |
404 | } | 405 | } |
405 | 406 | ||
407 | #else /* CONFIG_X86_LOCAL_APIC */ | ||
408 | |||
409 | static inline u32 apic_read(u32 reg) { return 0; } | ||
410 | static inline void apic_write(u32 reg, u32 val) { } | ||
411 | static inline u64 apic_icr_read(void) { return 0; } | ||
412 | static inline void apic_icr_write(u32 low, u32 high) { } | ||
413 | static inline void apic_wait_icr_idle(void) { } | ||
414 | static inline u32 safe_apic_wait_icr_idle(void) { return 0; } | ||
415 | |||
416 | #endif /* CONFIG_X86_LOCAL_APIC */ | ||
406 | 417 | ||
407 | static inline void ack_APIC_irq(void) | 418 | static inline void ack_APIC_irq(void) |
408 | { | 419 | { |
409 | #ifdef CONFIG_X86_LOCAL_APIC | ||
410 | /* | 420 | /* |
411 | * ack_APIC_irq() actually gets compiled as a single instruction | 421 | * ack_APIC_irq() actually gets compiled as a single instruction |
412 | * ... yummie. | 422 | * ... yummie. |
@@ -414,7 +424,6 @@ static inline void ack_APIC_irq(void) | |||
414 | 424 | ||
415 | /* Docs say use 0 for future compatibility */ | 425 | /* Docs say use 0 for future compatibility */ |
416 | apic_write(APIC_EOI, 0); | 426 | apic_write(APIC_EOI, 0); |
417 | #endif | ||
418 | } | 427 | } |
419 | 428 | ||
420 | static inline unsigned default_get_apic_id(unsigned long x) | 429 | static inline unsigned default_get_apic_id(unsigned long x) |
diff --git a/arch/x86/include/asm/ds.h b/arch/x86/include/asm/ds.h deleted file mode 100644 index 70dac199b09..00000000000 --- a/arch/x86/include/asm/ds.h +++ /dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | /* | ||
2 | * Debug Store (DS) support | ||
3 | * | ||
4 | * This provides a low-level interface to the hardware's Debug Store | ||
5 | * feature that is used for branch trace store (BTS) and | ||
6 | * precise-event based sampling (PEBS). | ||
7 | * | ||
8 | * It manages: | ||
9 | * - DS and BTS hardware configuration | ||
10 | * - buffer overflow handling (to be done) | ||
11 | * - buffer access | ||
12 | * | ||
13 | * It does not do: | ||
14 | * - security checking (is the caller allowed to trace the task) | ||
15 | * - buffer allocation (memory accounting) | ||
16 | * | ||
17 | * | ||
18 | * Copyright (C) 2007-2009 Intel Corporation. | ||
19 | * Markus Metzger <markus.t.metzger@intel.com>, 2007-2009 | ||
20 | */ | ||
21 | |||
22 | #ifndef _ASM_X86_DS_H | ||
23 | #define _ASM_X86_DS_H | ||
24 | |||
25 | |||
26 | #include <linux/types.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/err.h> | ||
29 | |||
30 | |||
31 | #ifdef CONFIG_X86_DS | ||
32 | |||
33 | struct task_struct; | ||
34 | struct ds_context; | ||
35 | struct ds_tracer; | ||
36 | struct bts_tracer; | ||
37 | struct pebs_tracer; | ||
38 | |||
39 | typedef void (*bts_ovfl_callback_t)(struct bts_tracer *); | ||
40 | typedef void (*pebs_ovfl_callback_t)(struct pebs_tracer *); | ||
41 | |||
42 | |||
43 | /* | ||
44 | * A list of features plus corresponding macros to talk about them in | ||
45 | * the ds_request function's flags parameter. | ||
46 | * | ||
47 | * We use the enum to index an array of corresponding control bits; | ||
48 | * we use the macro to index a flags bit-vector. | ||
49 | */ | ||
50 | enum ds_feature { | ||
51 | dsf_bts = 0, | ||
52 | dsf_bts_kernel, | ||
53 | #define BTS_KERNEL (1 << dsf_bts_kernel) | ||
54 | /* trace kernel-mode branches */ | ||
55 | |||
56 | dsf_bts_user, | ||
57 | #define BTS_USER (1 << dsf_bts_user) | ||
58 | /* trace user-mode branches */ | ||
59 | |||
60 | dsf_bts_overflow, | ||
61 | dsf_bts_max, | ||
62 | dsf_pebs = dsf_bts_max, | ||
63 | |||
64 | dsf_pebs_max, | ||
65 | dsf_ctl_max = dsf_pebs_max, | ||
66 | dsf_bts_timestamps = dsf_ctl_max, | ||
67 | #define BTS_TIMESTAMPS (1 << dsf_bts_timestamps) | ||
68 | /* add timestamps into BTS trace */ | ||
69 | |||
70 | #define BTS_USER_FLAGS (BTS_KERNEL | BTS_USER | BTS_TIMESTAMPS) | ||
71 | }; | ||
72 | |||
73 | |||
74 | /* | ||
75 | * Request BTS or PEBS | ||
76 | * | ||
77 | * Due to alignement constraints, the actual buffer may be slightly | ||
78 | * smaller than the requested or provided buffer. | ||
79 | * | ||
80 | * Returns a pointer to a tracer structure on success, or | ||
81 | * ERR_PTR(errcode) on failure. | ||
82 | * | ||
83 | * The interrupt threshold is independent from the overflow callback | ||
84 | * to allow users to use their own overflow interrupt handling mechanism. | ||
85 | * | ||
86 | * The function might sleep. | ||
87 | * | ||
88 | * task: the task to request recording for | ||
89 | * cpu: the cpu to request recording for | ||
90 | * base: the base pointer for the (non-pageable) buffer; | ||
91 | * size: the size of the provided buffer in bytes | ||
92 | * ovfl: pointer to a function to be called on buffer overflow; | ||
93 | * NULL if cyclic buffer requested | ||
94 | * th: the interrupt threshold in records from the end of the buffer; | ||
95 | * -1 if no interrupt threshold is requested. | ||
96 | * flags: a bit-mask of the above flags | ||
97 | */ | ||
98 | extern struct bts_tracer *ds_request_bts_task(struct task_struct *task, | ||
99 | void *base, size_t size, | ||
100 | bts_ovfl_callback_t ovfl, | ||
101 | size_t th, unsigned int flags); | ||
102 | extern struct bts_tracer *ds_request_bts_cpu(int cpu, void *base, size_t size, | ||
103 | bts_ovfl_callback_t ovfl, | ||
104 | size_t th, unsigned int flags); | ||
105 | extern struct pebs_tracer *ds_request_pebs_task(struct task_struct *task, | ||
106 | void *base, size_t size, | ||
107 | pebs_ovfl_callback_t ovfl, | ||
108 | size_t th, unsigned int flags); | ||
109 | extern struct pebs_tracer *ds_request_pebs_cpu(int cpu, | ||
110 | void *base, size_t size, | ||
111 | pebs_ovfl_callback_t ovfl, | ||
112 | size_t th, unsigned int flags); | ||
113 | |||
114 | /* | ||
115 | * Release BTS or PEBS resources | ||
116 | * Suspend and resume BTS or PEBS tracing | ||
117 | * | ||
118 | * Must be called with irq's enabled. | ||
119 | * | ||
120 | * tracer: the tracer handle returned from ds_request_~() | ||
121 | */ | ||
122 | extern void ds_release_bts(struct bts_tracer *tracer); | ||
123 | extern void ds_suspend_bts(struct bts_tracer *tracer); | ||
124 | extern void ds_resume_bts(struct bts_tracer *tracer); | ||
125 | extern void ds_release_pebs(struct pebs_tracer *tracer); | ||
126 | extern void ds_suspend_pebs(struct pebs_tracer *tracer); | ||
127 | extern void ds_resume_pebs(struct pebs_tracer *tracer); | ||
128 | |||
129 | /* | ||
130 | * Release BTS or PEBS resources | ||
131 | * Suspend and resume BTS or PEBS tracing | ||
132 | * | ||
133 | * Cpu tracers must call this on the traced cpu. | ||
134 | * Task tracers must call ds_release_~_noirq() for themselves. | ||
135 | * | ||
136 | * May be called with irq's disabled. | ||
137 | * | ||
138 | * Returns 0 if successful; | ||
139 | * -EPERM if the cpu tracer does not trace the current cpu. | ||
140 | * -EPERM if the task tracer does not trace itself. | ||
141 | * | ||
142 | * tracer: the tracer handle returned from ds_request_~() | ||
143 | */ | ||
144 | extern int ds_release_bts_noirq(struct bts_tracer *tracer); | ||
145 | extern int ds_suspend_bts_noirq(struct bts_tracer *tracer); | ||
146 | extern int ds_resume_bts_noirq(struct bts_tracer *tracer); | ||
147 | extern int ds_release_pebs_noirq(struct pebs_tracer *tracer); | ||
148 | extern int ds_suspend_pebs_noirq(struct pebs_tracer *tracer); | ||
149 | extern int ds_resume_pebs_noirq(struct pebs_tracer *tracer); | ||
150 | |||
151 | |||
152 | /* | ||
153 | * The raw DS buffer state as it is used for BTS and PEBS recording. | ||
154 | * | ||
155 | * This is the low-level, arch-dependent interface for working | ||
156 | * directly on the raw trace data. | ||
157 | */ | ||
158 | struct ds_trace { | ||
159 | /* the number of bts/pebs records */ | ||
160 | size_t n; | ||
161 | /* the size of a bts/pebs record in bytes */ | ||
162 | size_t size; | ||
163 | /* pointers into the raw buffer: | ||
164 | - to the first entry */ | ||
165 | void *begin; | ||
166 | /* - one beyond the last entry */ | ||
167 | void *end; | ||
168 | /* - one beyond the newest entry */ | ||
169 | void *top; | ||
170 | /* - the interrupt threshold */ | ||
171 | void *ith; | ||
172 | /* flags given on ds_request() */ | ||
173 | unsigned int flags; | ||
174 | }; | ||
175 | |||
176 | /* | ||
177 | * An arch-independent view on branch trace data. | ||
178 | */ | ||
179 | enum bts_qualifier { | ||
180 | bts_invalid, | ||
181 | #define BTS_INVALID bts_invalid | ||
182 | |||
183 | bts_branch, | ||
184 | #define BTS_BRANCH bts_branch | ||
185 | |||
186 | bts_task_arrives, | ||
187 | #define BTS_TASK_ARRIVES bts_task_arrives | ||
188 | |||
189 | bts_task_departs, | ||
190 | #define BTS_TASK_DEPARTS bts_task_departs | ||
191 | |||
192 | bts_qual_bit_size = 4, | ||
193 | bts_qual_max = (1 << bts_qual_bit_size), | ||
194 | }; | ||
195 | |||
196 | struct bts_struct { | ||
197 | __u64 qualifier; | ||
198 | union { | ||
199 | /* BTS_BRANCH */ | ||
200 | struct { | ||
201 | __u64 from; | ||
202 | __u64 to; | ||
203 | } lbr; | ||
204 | /* BTS_TASK_ARRIVES or BTS_TASK_DEPARTS */ | ||
205 | struct { | ||
206 | __u64 clock; | ||
207 | pid_t pid; | ||
208 | } event; | ||
209 | } variant; | ||
210 | }; | ||
211 | |||
212 | |||
213 | /* | ||
214 | * The BTS state. | ||
215 | * | ||
216 | * This gives access to the raw DS state and adds functions to provide | ||
217 | * an arch-independent view of the BTS data. | ||
218 | */ | ||
219 | struct bts_trace { | ||
220 | struct ds_trace ds; | ||
221 | |||
222 | int (*read)(struct bts_tracer *tracer, const void *at, | ||
223 | struct bts_struct *out); | ||
224 | int (*write)(struct bts_tracer *tracer, const struct bts_struct *in); | ||
225 | }; | ||
226 | |||
227 | |||
228 | /* | ||
229 | * The PEBS state. | ||
230 | * | ||
231 | * This gives access to the raw DS state and the PEBS-specific counter | ||
232 | * reset value. | ||
233 | */ | ||
234 | struct pebs_trace { | ||
235 | struct ds_trace ds; | ||
236 | |||
237 | /* the number of valid counters in the below array */ | ||
238 | unsigned int counters; | ||
239 | |||
240 | #define MAX_PEBS_COUNTERS 4 | ||
241 | /* the counter reset value */ | ||
242 | unsigned long long counter_reset[MAX_PEBS_COUNTERS]; | ||
243 | }; | ||
244 | |||
245 | |||
246 | /* | ||
247 | * Read the BTS or PEBS trace. | ||
248 | * | ||
249 | * Returns a view on the trace collected for the parameter tracer. | ||
250 | * | ||
251 | * The view remains valid as long as the traced task is not running or | ||
252 | * the tracer is suspended. | ||
253 | * Writes into the trace buffer are not reflected. | ||
254 | * | ||
255 | * tracer: the tracer handle returned from ds_request_~() | ||
256 | */ | ||
257 | extern const struct bts_trace *ds_read_bts(struct bts_tracer *tracer); | ||
258 | extern const struct pebs_trace *ds_read_pebs(struct pebs_tracer *tracer); | ||
259 | |||
260 | |||
261 | /* | ||
262 | * Reset the write pointer of the BTS/PEBS buffer. | ||
263 | * | ||
264 | * Returns 0 on success; -Eerrno on error | ||
265 | * | ||
266 | * tracer: the tracer handle returned from ds_request_~() | ||
267 | */ | ||
268 | extern int ds_reset_bts(struct bts_tracer *tracer); | ||
269 | extern int ds_reset_pebs(struct pebs_tracer *tracer); | ||
270 | |||
271 | /* | ||
272 | * Set the PEBS counter reset value. | ||
273 | * | ||
274 | * Returns 0 on success; -Eerrno on error | ||
275 | * | ||
276 | * tracer: the tracer handle returned from ds_request_pebs() | ||
277 | * counter: the index of the counter | ||
278 | * value: the new counter reset value | ||
279 | */ | ||
280 | extern int ds_set_pebs_reset(struct pebs_tracer *tracer, | ||
281 | unsigned int counter, u64 value); | ||
282 | |||
283 | /* | ||
284 | * Initialization | ||
285 | */ | ||
286 | struct cpuinfo_x86; | ||
287 | extern void __cpuinit ds_init_intel(struct cpuinfo_x86 *); | ||
288 | |||
289 | /* | ||
290 | * Context switch work | ||
291 | */ | ||
292 | extern void ds_switch_to(struct task_struct *prev, struct task_struct *next); | ||
293 | |||
294 | #else /* CONFIG_X86_DS */ | ||
295 | |||
296 | struct cpuinfo_x86; | ||
297 | static inline void __cpuinit ds_init_intel(struct cpuinfo_x86 *ignored) {} | ||
298 | static inline void ds_switch_to(struct task_struct *prev, | ||
299 | struct task_struct *next) {} | ||
300 | |||
301 | #endif /* CONFIG_X86_DS */ | ||
302 | #endif /* _ASM_X86_DS_H */ | ||
diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 96c2e0ad04c..88c765e1641 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h | |||
@@ -68,6 +68,8 @@ struct insn { | |||
68 | const insn_byte_t *next_byte; | 68 | const insn_byte_t *next_byte; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | #define MAX_INSN_SIZE 16 | ||
72 | |||
71 | #define X86_MODRM_MOD(modrm) (((modrm) & 0xc0) >> 6) | 73 | #define X86_MODRM_MOD(modrm) (((modrm) & 0xc0) >> 6) |
72 | #define X86_MODRM_REG(modrm) (((modrm) & 0x38) >> 3) | 74 | #define X86_MODRM_REG(modrm) (((modrm) & 0x38) >> 3) |
73 | #define X86_MODRM_RM(modrm) ((modrm) & 0x07) | 75 | #define X86_MODRM_RM(modrm) ((modrm) & 0x07) |
diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h index 4ffa345a8cc..54788253915 100644 --- a/arch/x86/include/asm/kprobes.h +++ b/arch/x86/include/asm/kprobes.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/types.h> | 24 | #include <linux/types.h> |
25 | #include <linux/ptrace.h> | 25 | #include <linux/ptrace.h> |
26 | #include <linux/percpu.h> | 26 | #include <linux/percpu.h> |
27 | #include <asm/insn.h> | ||
27 | 28 | ||
28 | #define __ARCH_WANT_KPROBES_INSN_SLOT | 29 | #define __ARCH_WANT_KPROBES_INSN_SLOT |
29 | 30 | ||
@@ -36,7 +37,6 @@ typedef u8 kprobe_opcode_t; | |||
36 | #define RELATIVEJUMP_SIZE 5 | 37 | #define RELATIVEJUMP_SIZE 5 |
37 | #define RELATIVECALL_OPCODE 0xe8 | 38 | #define RELATIVECALL_OPCODE 0xe8 |
38 | #define RELATIVE_ADDR_SIZE 4 | 39 | #define RELATIVE_ADDR_SIZE 4 |
39 | #define MAX_INSN_SIZE 16 | ||
40 | #define MAX_STACK_SIZE 64 | 40 | #define MAX_STACK_SIZE 64 |
41 | #define MIN_STACK_SIZE(ADDR) \ | 41 | #define MIN_STACK_SIZE(ADDR) \ |
42 | (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \ | 42 | (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \ |
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 4604e6a54d3..bc473acfa7f 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h | |||
@@ -71,11 +71,14 @@ | |||
71 | #define MSR_IA32_LASTINTTOIP 0x000001de | 71 | #define MSR_IA32_LASTINTTOIP 0x000001de |
72 | 72 | ||
73 | /* DEBUGCTLMSR bits (others vary by model): */ | 73 | /* DEBUGCTLMSR bits (others vary by model): */ |
74 | #define _DEBUGCTLMSR_LBR 0 /* last branch recording */ | 74 | #define DEBUGCTLMSR_LBR (1UL << 0) /* last branch recording */ |
75 | #define _DEBUGCTLMSR_BTF 1 /* single-step on branches */ | 75 | #define DEBUGCTLMSR_BTF (1UL << 1) /* single-step on branches */ |
76 | 76 | #define DEBUGCTLMSR_TR (1UL << 6) | |
77 | #define DEBUGCTLMSR_LBR (1UL << _DEBUGCTLMSR_LBR) | 77 | #define DEBUGCTLMSR_BTS (1UL << 7) |
78 | #define DEBUGCTLMSR_BTF (1UL << _DEBUGCTLMSR_BTF) | 78 | #define DEBUGCTLMSR_BTINT (1UL << 8) |
79 | #define DEBUGCTLMSR_BTS_OFF_OS (1UL << 9) | ||
80 | #define DEBUGCTLMSR_BTS_OFF_USR (1UL << 10) | ||
81 | #define DEBUGCTLMSR_FREEZE_LBRS_ON_PMI (1UL << 11) | ||
79 | 82 | ||
80 | #define MSR_IA32_MC0_CTL 0x00000400 | 83 | #define MSR_IA32_MC0_CTL 0x00000400 |
81 | #define MSR_IA32_MC0_STATUS 0x00000401 | 84 | #define MSR_IA32_MC0_STATUS 0x00000401 |
@@ -359,6 +362,8 @@ | |||
359 | #define MSR_P4_U2L_ESCR0 0x000003b0 | 362 | #define MSR_P4_U2L_ESCR0 0x000003b0 |
360 | #define MSR_P4_U2L_ESCR1 0x000003b1 | 363 | #define MSR_P4_U2L_ESCR1 0x000003b1 |
361 | 364 | ||
365 | #define MSR_P4_PEBS_MATRIX_VERT 0x000003f2 | ||
366 | |||
362 | /* Intel Core-based CPU performance counters */ | 367 | /* Intel Core-based CPU performance counters */ |
363 | #define MSR_CORE_PERF_FIXED_CTR0 0x00000309 | 368 | #define MSR_CORE_PERF_FIXED_CTR0 0x00000309 |
364 | #define MSR_CORE_PERF_FIXED_CTR1 0x0000030a | 369 | #define MSR_CORE_PERF_FIXED_CTR1 0x0000030a |
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index db6109a885a..f6d43dbfd8e 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h | |||
@@ -5,7 +5,7 @@ | |||
5 | * Performance event hw details: | 5 | * Performance event hw details: |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #define X86_PMC_MAX_GENERIC 8 | 8 | #define X86_PMC_MAX_GENERIC 32 |
9 | #define X86_PMC_MAX_FIXED 3 | 9 | #define X86_PMC_MAX_FIXED 3 |
10 | 10 | ||
11 | #define X86_PMC_IDX_GENERIC 0 | 11 | #define X86_PMC_IDX_GENERIC 0 |
@@ -18,39 +18,31 @@ | |||
18 | #define MSR_ARCH_PERFMON_EVENTSEL0 0x186 | 18 | #define MSR_ARCH_PERFMON_EVENTSEL0 0x186 |
19 | #define MSR_ARCH_PERFMON_EVENTSEL1 0x187 | 19 | #define MSR_ARCH_PERFMON_EVENTSEL1 0x187 |
20 | 20 | ||
21 | #define ARCH_PERFMON_EVENTSEL_ENABLE (1 << 22) | 21 | #define ARCH_PERFMON_EVENTSEL_EVENT 0x000000FFULL |
22 | #define ARCH_PERFMON_EVENTSEL_ANY (1 << 21) | 22 | #define ARCH_PERFMON_EVENTSEL_UMASK 0x0000FF00ULL |
23 | #define ARCH_PERFMON_EVENTSEL_INT (1 << 20) | 23 | #define ARCH_PERFMON_EVENTSEL_USR (1ULL << 16) |
24 | #define ARCH_PERFMON_EVENTSEL_OS (1 << 17) | 24 | #define ARCH_PERFMON_EVENTSEL_OS (1ULL << 17) |
25 | #define ARCH_PERFMON_EVENTSEL_USR (1 << 16) | 25 | #define ARCH_PERFMON_EVENTSEL_EDGE (1ULL << 18) |
26 | 26 | #define ARCH_PERFMON_EVENTSEL_INT (1ULL << 20) | |
27 | /* | 27 | #define ARCH_PERFMON_EVENTSEL_ANY (1ULL << 21) |
28 | * Includes eventsel and unit mask as well: | 28 | #define ARCH_PERFMON_EVENTSEL_ENABLE (1ULL << 22) |
29 | */ | 29 | #define ARCH_PERFMON_EVENTSEL_INV (1ULL << 23) |
30 | 30 | #define ARCH_PERFMON_EVENTSEL_CMASK 0xFF000000ULL | |
31 | 31 | ||
32 | #define INTEL_ARCH_EVTSEL_MASK 0x000000FFULL | 32 | #define AMD64_EVENTSEL_EVENT \ |
33 | #define INTEL_ARCH_UNIT_MASK 0x0000FF00ULL | 33 | (ARCH_PERFMON_EVENTSEL_EVENT | (0x0FULL << 32)) |
34 | #define INTEL_ARCH_EDGE_MASK 0x00040000ULL | 34 | #define INTEL_ARCH_EVENT_MASK \ |
35 | #define INTEL_ARCH_INV_MASK 0x00800000ULL | 35 | (ARCH_PERFMON_EVENTSEL_UMASK | ARCH_PERFMON_EVENTSEL_EVENT) |
36 | #define INTEL_ARCH_CNT_MASK 0xFF000000ULL | 36 | |
37 | #define INTEL_ARCH_EVENT_MASK (INTEL_ARCH_UNIT_MASK|INTEL_ARCH_EVTSEL_MASK) | 37 | #define X86_RAW_EVENT_MASK \ |
38 | 38 | (ARCH_PERFMON_EVENTSEL_EVENT | \ | |
39 | /* | 39 | ARCH_PERFMON_EVENTSEL_UMASK | \ |
40 | * filter mask to validate fixed counter events. | 40 | ARCH_PERFMON_EVENTSEL_EDGE | \ |
41 | * the following filters disqualify for fixed counters: | 41 | ARCH_PERFMON_EVENTSEL_INV | \ |
42 | * - inv | 42 | ARCH_PERFMON_EVENTSEL_CMASK) |
43 | * - edge | 43 | #define AMD64_RAW_EVENT_MASK \ |
44 | * - cnt-mask | 44 | (X86_RAW_EVENT_MASK | \ |
45 | * The other filters are supported by fixed counters. | 45 | AMD64_EVENTSEL_EVENT) |
46 | * The any-thread option is supported starting with v3. | ||
47 | */ | ||
48 | #define INTEL_ARCH_FIXED_MASK \ | ||
49 | (INTEL_ARCH_CNT_MASK| \ | ||
50 | INTEL_ARCH_INV_MASK| \ | ||
51 | INTEL_ARCH_EDGE_MASK|\ | ||
52 | INTEL_ARCH_UNIT_MASK|\ | ||
53 | INTEL_ARCH_EVENT_MASK) | ||
54 | 46 | ||
55 | #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL 0x3c | 47 | #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL 0x3c |
56 | #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) | 48 | #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) |
@@ -67,7 +59,7 @@ | |||
67 | union cpuid10_eax { | 59 | union cpuid10_eax { |
68 | struct { | 60 | struct { |
69 | unsigned int version_id:8; | 61 | unsigned int version_id:8; |
70 | unsigned int num_events:8; | 62 | unsigned int num_counters:8; |
71 | unsigned int bit_width:8; | 63 | unsigned int bit_width:8; |
72 | unsigned int mask_length:8; | 64 | unsigned int mask_length:8; |
73 | } split; | 65 | } split; |
@@ -76,7 +68,7 @@ union cpuid10_eax { | |||
76 | 68 | ||
77 | union cpuid10_edx { | 69 | union cpuid10_edx { |
78 | struct { | 70 | struct { |
79 | unsigned int num_events_fixed:4; | 71 | unsigned int num_counters_fixed:4; |
80 | unsigned int reserved:28; | 72 | unsigned int reserved:28; |
81 | } split; | 73 | } split; |
82 | unsigned int full; | 74 | unsigned int full; |
@@ -136,6 +128,25 @@ extern void perf_events_lapic_init(void); | |||
136 | 128 | ||
137 | #define PERF_EVENT_INDEX_OFFSET 0 | 129 | #define PERF_EVENT_INDEX_OFFSET 0 |
138 | 130 | ||
131 | /* | ||
132 | * Abuse bit 3 of the cpu eflags register to indicate proper PEBS IP fixups. | ||
133 | * This flag is otherwise unused and ABI specified to be 0, so nobody should | ||
134 | * care what we do with it. | ||
135 | */ | ||
136 | #define PERF_EFLAGS_EXACT (1UL << 3) | ||
137 | |||
138 | #define perf_misc_flags(regs) \ | ||
139 | ({ int misc = 0; \ | ||
140 | if (user_mode(regs)) \ | ||
141 | misc |= PERF_RECORD_MISC_USER; \ | ||
142 | else \ | ||
143 | misc |= PERF_RECORD_MISC_KERNEL; \ | ||
144 | if (regs->flags & PERF_EFLAGS_EXACT) \ | ||
145 | misc |= PERF_RECORD_MISC_EXACT; \ | ||
146 | misc; }) | ||
147 | |||
148 | #define perf_instruction_pointer(regs) ((regs)->ip) | ||
149 | |||
139 | #else | 150 | #else |
140 | static inline void init_hw_perf_events(void) { } | 151 | static inline void init_hw_perf_events(void) { } |
141 | static inline void perf_events_lapic_init(void) { } | 152 | static inline void perf_events_lapic_init(void) { } |
diff --git a/arch/x86/include/asm/perf_event_p4.h b/arch/x86/include/asm/perf_event_p4.h new file mode 100644 index 00000000000..b05400a542f --- /dev/null +++ b/arch/x86/include/asm/perf_event_p4.h | |||
@@ -0,0 +1,794 @@ | |||
1 | /* | ||
2 | * Netburst Perfomance Events (P4, old Xeon) | ||
3 | */ | ||
4 | |||
5 | #ifndef PERF_EVENT_P4_H | ||
6 | #define PERF_EVENT_P4_H | ||
7 | |||
8 | #include <linux/cpu.h> | ||
9 | #include <linux/bitops.h> | ||
10 | |||
11 | /* | ||
12 | * NetBurst has perfomance MSRs shared between | ||
13 | * threads if HT is turned on, ie for both logical | ||
14 | * processors (mem: in turn in Atom with HT support | ||
15 | * perf-MSRs are not shared and every thread has its | ||
16 | * own perf-MSRs set) | ||
17 | */ | ||
18 | #define ARCH_P4_TOTAL_ESCR (46) | ||
19 | #define ARCH_P4_RESERVED_ESCR (2) /* IQ_ESCR(0,1) not always present */ | ||
20 | #define ARCH_P4_MAX_ESCR (ARCH_P4_TOTAL_ESCR - ARCH_P4_RESERVED_ESCR) | ||
21 | #define ARCH_P4_MAX_CCCR (18) | ||
22 | #define ARCH_P4_MAX_COUNTER (ARCH_P4_MAX_CCCR / 2) | ||
23 | |||
24 | #define P4_ESCR_EVENT_MASK 0x7e000000U | ||
25 | #define P4_ESCR_EVENT_SHIFT 25 | ||
26 | #define P4_ESCR_EVENTMASK_MASK 0x01fffe00U | ||
27 | #define P4_ESCR_EVENTMASK_SHIFT 9 | ||
28 | #define P4_ESCR_TAG_MASK 0x000001e0U | ||
29 | #define P4_ESCR_TAG_SHIFT 5 | ||
30 | #define P4_ESCR_TAG_ENABLE 0x00000010U | ||
31 | #define P4_ESCR_T0_OS 0x00000008U | ||
32 | #define P4_ESCR_T0_USR 0x00000004U | ||
33 | #define P4_ESCR_T1_OS 0x00000002U | ||
34 | #define P4_ESCR_T1_USR 0x00000001U | ||
35 | |||
36 | #define P4_ESCR_EVENT(v) ((v) << P4_ESCR_EVENT_SHIFT) | ||
37 | #define P4_ESCR_EMASK(v) ((v) << P4_ESCR_EVENTMASK_SHIFT) | ||
38 | #define P4_ESCR_TAG(v) ((v) << P4_ESCR_TAG_SHIFT) | ||
39 | |||
40 | /* Non HT mask */ | ||
41 | #define P4_ESCR_MASK \ | ||
42 | (P4_ESCR_EVENT_MASK | \ | ||
43 | P4_ESCR_EVENTMASK_MASK | \ | ||
44 | P4_ESCR_TAG_MASK | \ | ||
45 | P4_ESCR_TAG_ENABLE | \ | ||
46 | P4_ESCR_T0_OS | \ | ||
47 | P4_ESCR_T0_USR) | ||
48 | |||
49 | /* HT mask */ | ||
50 | #define P4_ESCR_MASK_HT \ | ||
51 | (P4_ESCR_MASK | P4_ESCR_T1_OS | P4_ESCR_T1_USR) | ||
52 | |||
53 | #define P4_CCCR_OVF 0x80000000U | ||
54 | #define P4_CCCR_CASCADE 0x40000000U | ||
55 | #define P4_CCCR_OVF_PMI_T0 0x04000000U | ||
56 | #define P4_CCCR_OVF_PMI_T1 0x08000000U | ||
57 | #define P4_CCCR_FORCE_OVF 0x02000000U | ||
58 | #define P4_CCCR_EDGE 0x01000000U | ||
59 | #define P4_CCCR_THRESHOLD_MASK 0x00f00000U | ||
60 | #define P4_CCCR_THRESHOLD_SHIFT 20 | ||
61 | #define P4_CCCR_COMPLEMENT 0x00080000U | ||
62 | #define P4_CCCR_COMPARE 0x00040000U | ||
63 | #define P4_CCCR_ESCR_SELECT_MASK 0x0000e000U | ||
64 | #define P4_CCCR_ESCR_SELECT_SHIFT 13 | ||
65 | #define P4_CCCR_ENABLE 0x00001000U | ||
66 | #define P4_CCCR_THREAD_SINGLE 0x00010000U | ||
67 | #define P4_CCCR_THREAD_BOTH 0x00020000U | ||
68 | #define P4_CCCR_THREAD_ANY 0x00030000U | ||
69 | #define P4_CCCR_RESERVED 0x00000fffU | ||
70 | |||
71 | #define P4_CCCR_THRESHOLD(v) ((v) << P4_CCCR_THRESHOLD_SHIFT) | ||
72 | #define P4_CCCR_ESEL(v) ((v) << P4_CCCR_ESCR_SELECT_SHIFT) | ||
73 | |||
74 | /* Custom bits in reerved CCCR area */ | ||
75 | #define P4_CCCR_CACHE_OPS_MASK 0x0000003fU | ||
76 | |||
77 | |||
78 | /* Non HT mask */ | ||
79 | #define P4_CCCR_MASK \ | ||
80 | (P4_CCCR_OVF | \ | ||
81 | P4_CCCR_CASCADE | \ | ||
82 | P4_CCCR_OVF_PMI_T0 | \ | ||
83 | P4_CCCR_FORCE_OVF | \ | ||
84 | P4_CCCR_EDGE | \ | ||
85 | P4_CCCR_THRESHOLD_MASK | \ | ||
86 | P4_CCCR_COMPLEMENT | \ | ||
87 | P4_CCCR_COMPARE | \ | ||
88 | P4_CCCR_ESCR_SELECT_MASK | \ | ||
89 | P4_CCCR_ENABLE) | ||
90 | |||
91 | /* HT mask */ | ||
92 | #define P4_CCCR_MASK_HT (P4_CCCR_MASK | P4_CCCR_THREAD_ANY) | ||
93 | |||
94 | #define P4_GEN_ESCR_EMASK(class, name, bit) \ | ||
95 | class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT) | ||
96 | #define P4_ESCR_EMASK_BIT(class, name) class##__##name | ||
97 | |||
98 | /* | ||
99 | * config field is 64bit width and consists of | ||
100 | * HT << 63 | ESCR << 32 | CCCR | ||
101 | * where HT is HyperThreading bit (since ESCR | ||
102 | * has it reserved we may use it for own purpose) | ||
103 | * | ||
104 | * note that this is NOT the addresses of respective | ||
105 | * ESCR and CCCR but rather an only packed value should | ||
106 | * be unpacked and written to a proper addresses | ||
107 | * | ||
108 | * the base idea is to pack as much info as | ||
109 | * possible | ||
110 | */ | ||
111 | #define p4_config_pack_escr(v) (((u64)(v)) << 32) | ||
112 | #define p4_config_pack_cccr(v) (((u64)(v)) & 0xffffffffULL) | ||
113 | #define p4_config_unpack_escr(v) (((u64)(v)) >> 32) | ||
114 | #define p4_config_unpack_cccr(v) (((u64)(v)) & 0xffffffffULL) | ||
115 | |||
116 | #define p4_config_unpack_emask(v) \ | ||
117 | ({ \ | ||
118 | u32 t = p4_config_unpack_escr((v)); \ | ||
119 | t = t & P4_ESCR_EVENTMASK_MASK; \ | ||
120 | t = t >> P4_ESCR_EVENTMASK_SHIFT; \ | ||
121 | t; \ | ||
122 | }) | ||
123 | |||
124 | #define p4_config_unpack_event(v) \ | ||
125 | ({ \ | ||
126 | u32 t = p4_config_unpack_escr((v)); \ | ||
127 | t = t & P4_ESCR_EVENT_MASK; \ | ||
128 | t = t >> P4_ESCR_EVENT_SHIFT; \ | ||
129 | t; \ | ||
130 | }) | ||
131 | |||
132 | #define p4_config_unpack_cache_event(v) (((u64)(v)) & P4_CCCR_CACHE_OPS_MASK) | ||
133 | |||
134 | #define P4_CONFIG_HT_SHIFT 63 | ||
135 | #define P4_CONFIG_HT (1ULL << P4_CONFIG_HT_SHIFT) | ||
136 | |||
137 | static inline bool p4_is_event_cascaded(u64 config) | ||
138 | { | ||
139 | u32 cccr = p4_config_unpack_cccr(config); | ||
140 | return !!(cccr & P4_CCCR_CASCADE); | ||
141 | } | ||
142 | |||
143 | static inline int p4_ht_config_thread(u64 config) | ||
144 | { | ||
145 | return !!(config & P4_CONFIG_HT); | ||
146 | } | ||
147 | |||
148 | static inline u64 p4_set_ht_bit(u64 config) | ||
149 | { | ||
150 | return config | P4_CONFIG_HT; | ||
151 | } | ||
152 | |||
153 | static inline u64 p4_clear_ht_bit(u64 config) | ||
154 | { | ||
155 | return config & ~P4_CONFIG_HT; | ||
156 | } | ||
157 | |||
158 | static inline int p4_ht_active(void) | ||
159 | { | ||
160 | #ifdef CONFIG_SMP | ||
161 | return smp_num_siblings > 1; | ||
162 | #endif | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | static inline int p4_ht_thread(int cpu) | ||
167 | { | ||
168 | #ifdef CONFIG_SMP | ||
169 | if (smp_num_siblings == 2) | ||
170 | return cpu != cpumask_first(__get_cpu_var(cpu_sibling_map)); | ||
171 | #endif | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static inline int p4_should_swap_ts(u64 config, int cpu) | ||
176 | { | ||
177 | return p4_ht_config_thread(config) ^ p4_ht_thread(cpu); | ||
178 | } | ||
179 | |||
180 | static inline u32 p4_default_cccr_conf(int cpu) | ||
181 | { | ||
182 | /* | ||
183 | * Note that P4_CCCR_THREAD_ANY is "required" on | ||
184 | * non-HT machines (on HT machines we count TS events | ||
185 | * regardless the state of second logical processor | ||
186 | */ | ||
187 | u32 cccr = P4_CCCR_THREAD_ANY; | ||
188 | |||
189 | if (!p4_ht_thread(cpu)) | ||
190 | cccr |= P4_CCCR_OVF_PMI_T0; | ||
191 | else | ||
192 | cccr |= P4_CCCR_OVF_PMI_T1; | ||
193 | |||
194 | return cccr; | ||
195 | } | ||
196 | |||
197 | static inline u32 p4_default_escr_conf(int cpu, int exclude_os, int exclude_usr) | ||
198 | { | ||
199 | u32 escr = 0; | ||
200 | |||
201 | if (!p4_ht_thread(cpu)) { | ||
202 | if (!exclude_os) | ||
203 | escr |= P4_ESCR_T0_OS; | ||
204 | if (!exclude_usr) | ||
205 | escr |= P4_ESCR_T0_USR; | ||
206 | } else { | ||
207 | if (!exclude_os) | ||
208 | escr |= P4_ESCR_T1_OS; | ||
209 | if (!exclude_usr) | ||
210 | escr |= P4_ESCR_T1_USR; | ||
211 | } | ||
212 | |||
213 | return escr; | ||
214 | } | ||
215 | |||
216 | enum P4_EVENTS { | ||
217 | P4_EVENT_TC_DELIVER_MODE, | ||
218 | P4_EVENT_BPU_FETCH_REQUEST, | ||
219 | P4_EVENT_ITLB_REFERENCE, | ||
220 | P4_EVENT_MEMORY_CANCEL, | ||
221 | P4_EVENT_MEMORY_COMPLETE, | ||
222 | P4_EVENT_LOAD_PORT_REPLAY, | ||
223 | P4_EVENT_STORE_PORT_REPLAY, | ||
224 | P4_EVENT_MOB_LOAD_REPLAY, | ||
225 | P4_EVENT_PAGE_WALK_TYPE, | ||
226 | P4_EVENT_BSQ_CACHE_REFERENCE, | ||
227 | P4_EVENT_IOQ_ALLOCATION, | ||
228 | P4_EVENT_IOQ_ACTIVE_ENTRIES, | ||
229 | P4_EVENT_FSB_DATA_ACTIVITY, | ||
230 | P4_EVENT_BSQ_ALLOCATION, | ||
231 | P4_EVENT_BSQ_ACTIVE_ENTRIES, | ||
232 | P4_EVENT_SSE_INPUT_ASSIST, | ||
233 | P4_EVENT_PACKED_SP_UOP, | ||
234 | P4_EVENT_PACKED_DP_UOP, | ||
235 | P4_EVENT_SCALAR_SP_UOP, | ||
236 | P4_EVENT_SCALAR_DP_UOP, | ||
237 | P4_EVENT_64BIT_MMX_UOP, | ||
238 | P4_EVENT_128BIT_MMX_UOP, | ||
239 | P4_EVENT_X87_FP_UOP, | ||
240 | P4_EVENT_TC_MISC, | ||
241 | P4_EVENT_GLOBAL_POWER_EVENTS, | ||
242 | P4_EVENT_TC_MS_XFER, | ||
243 | P4_EVENT_UOP_QUEUE_WRITES, | ||
244 | P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, | ||
245 | P4_EVENT_RETIRED_BRANCH_TYPE, | ||
246 | P4_EVENT_RESOURCE_STALL, | ||
247 | P4_EVENT_WC_BUFFER, | ||
248 | P4_EVENT_B2B_CYCLES, | ||
249 | P4_EVENT_BNR, | ||
250 | P4_EVENT_SNOOP, | ||
251 | P4_EVENT_RESPONSE, | ||
252 | P4_EVENT_FRONT_END_EVENT, | ||
253 | P4_EVENT_EXECUTION_EVENT, | ||
254 | P4_EVENT_REPLAY_EVENT, | ||
255 | P4_EVENT_INSTR_RETIRED, | ||
256 | P4_EVENT_UOPS_RETIRED, | ||
257 | P4_EVENT_UOP_TYPE, | ||
258 | P4_EVENT_BRANCH_RETIRED, | ||
259 | P4_EVENT_MISPRED_BRANCH_RETIRED, | ||
260 | P4_EVENT_X87_ASSIST, | ||
261 | P4_EVENT_MACHINE_CLEAR, | ||
262 | P4_EVENT_INSTR_COMPLETED, | ||
263 | }; | ||
264 | |||
265 | #define P4_OPCODE(event) event##_OPCODE | ||
266 | #define P4_OPCODE_ESEL(opcode) ((opcode & 0x00ff) >> 0) | ||
267 | #define P4_OPCODE_EVNT(opcode) ((opcode & 0xff00) >> 8) | ||
268 | #define P4_OPCODE_PACK(event, sel) (((event) << 8) | sel) | ||
269 | |||
270 | /* | ||
271 | * Comments below the event represent ESCR restriction | ||
272 | * for this event and counter index per ESCR | ||
273 | * | ||
274 | * MSR_P4_IQ_ESCR0 and MSR_P4_IQ_ESCR1 are available only on early | ||
275 | * processor builds (family 0FH, models 01H-02H). These MSRs | ||
276 | * are not available on later versions, so that we don't use | ||
277 | * them completely | ||
278 | * | ||
279 | * Also note that CCCR1 do not have P4_CCCR_ENABLE bit properly | ||
280 | * working so that we should not use this CCCR and respective | ||
281 | * counter as result | ||
282 | */ | ||
283 | enum P4_EVENT_OPCODES { | ||
284 | P4_OPCODE(P4_EVENT_TC_DELIVER_MODE) = P4_OPCODE_PACK(0x01, 0x01), | ||
285 | /* | ||
286 | * MSR_P4_TC_ESCR0: 4, 5 | ||
287 | * MSR_P4_TC_ESCR1: 6, 7 | ||
288 | */ | ||
289 | |||
290 | P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST) = P4_OPCODE_PACK(0x03, 0x00), | ||
291 | /* | ||
292 | * MSR_P4_BPU_ESCR0: 0, 1 | ||
293 | * MSR_P4_BPU_ESCR1: 2, 3 | ||
294 | */ | ||
295 | |||
296 | P4_OPCODE(P4_EVENT_ITLB_REFERENCE) = P4_OPCODE_PACK(0x18, 0x03), | ||
297 | /* | ||
298 | * MSR_P4_ITLB_ESCR0: 0, 1 | ||
299 | * MSR_P4_ITLB_ESCR1: 2, 3 | ||
300 | */ | ||
301 | |||
302 | P4_OPCODE(P4_EVENT_MEMORY_CANCEL) = P4_OPCODE_PACK(0x02, 0x05), | ||
303 | /* | ||
304 | * MSR_P4_DAC_ESCR0: 8, 9 | ||
305 | * MSR_P4_DAC_ESCR1: 10, 11 | ||
306 | */ | ||
307 | |||
308 | P4_OPCODE(P4_EVENT_MEMORY_COMPLETE) = P4_OPCODE_PACK(0x08, 0x02), | ||
309 | /* | ||
310 | * MSR_P4_SAAT_ESCR0: 8, 9 | ||
311 | * MSR_P4_SAAT_ESCR1: 10, 11 | ||
312 | */ | ||
313 | |||
314 | P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY) = P4_OPCODE_PACK(0x04, 0x02), | ||
315 | /* | ||
316 | * MSR_P4_SAAT_ESCR0: 8, 9 | ||
317 | * MSR_P4_SAAT_ESCR1: 10, 11 | ||
318 | */ | ||
319 | |||
320 | P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY) = P4_OPCODE_PACK(0x05, 0x02), | ||
321 | /* | ||
322 | * MSR_P4_SAAT_ESCR0: 8, 9 | ||
323 | * MSR_P4_SAAT_ESCR1: 10, 11 | ||
324 | */ | ||
325 | |||
326 | P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY) = P4_OPCODE_PACK(0x03, 0x02), | ||
327 | /* | ||
328 | * MSR_P4_MOB_ESCR0: 0, 1 | ||
329 | * MSR_P4_MOB_ESCR1: 2, 3 | ||
330 | */ | ||
331 | |||
332 | P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE) = P4_OPCODE_PACK(0x01, 0x04), | ||
333 | /* | ||
334 | * MSR_P4_PMH_ESCR0: 0, 1 | ||
335 | * MSR_P4_PMH_ESCR1: 2, 3 | ||
336 | */ | ||
337 | |||
338 | P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE) = P4_OPCODE_PACK(0x0c, 0x07), | ||
339 | /* | ||
340 | * MSR_P4_BSU_ESCR0: 0, 1 | ||
341 | * MSR_P4_BSU_ESCR1: 2, 3 | ||
342 | */ | ||
343 | |||
344 | P4_OPCODE(P4_EVENT_IOQ_ALLOCATION) = P4_OPCODE_PACK(0x03, 0x06), | ||
345 | /* | ||
346 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
347 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
348 | */ | ||
349 | |||
350 | P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES) = P4_OPCODE_PACK(0x1a, 0x06), | ||
351 | /* | ||
352 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
353 | */ | ||
354 | |||
355 | P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY) = P4_OPCODE_PACK(0x17, 0x06), | ||
356 | /* | ||
357 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
358 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
359 | */ | ||
360 | |||
361 | P4_OPCODE(P4_EVENT_BSQ_ALLOCATION) = P4_OPCODE_PACK(0x05, 0x07), | ||
362 | /* | ||
363 | * MSR_P4_BSU_ESCR0: 0, 1 | ||
364 | */ | ||
365 | |||
366 | P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES) = P4_OPCODE_PACK(0x06, 0x07), | ||
367 | /* | ||
368 | * NOTE: no ESCR name in docs, it's guessed | ||
369 | * MSR_P4_BSU_ESCR1: 2, 3 | ||
370 | */ | ||
371 | |||
372 | P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST) = P4_OPCODE_PACK(0x34, 0x01), | ||
373 | /* | ||
374 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
375 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
376 | */ | ||
377 | |||
378 | P4_OPCODE(P4_EVENT_PACKED_SP_UOP) = P4_OPCODE_PACK(0x08, 0x01), | ||
379 | /* | ||
380 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
381 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
382 | */ | ||
383 | |||
384 | P4_OPCODE(P4_EVENT_PACKED_DP_UOP) = P4_OPCODE_PACK(0x0c, 0x01), | ||
385 | /* | ||
386 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
387 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
388 | */ | ||
389 | |||
390 | P4_OPCODE(P4_EVENT_SCALAR_SP_UOP) = P4_OPCODE_PACK(0x0a, 0x01), | ||
391 | /* | ||
392 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
393 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
394 | */ | ||
395 | |||
396 | P4_OPCODE(P4_EVENT_SCALAR_DP_UOP) = P4_OPCODE_PACK(0x0e, 0x01), | ||
397 | /* | ||
398 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
399 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
400 | */ | ||
401 | |||
402 | P4_OPCODE(P4_EVENT_64BIT_MMX_UOP) = P4_OPCODE_PACK(0x02, 0x01), | ||
403 | /* | ||
404 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
405 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
406 | */ | ||
407 | |||
408 | P4_OPCODE(P4_EVENT_128BIT_MMX_UOP) = P4_OPCODE_PACK(0x1a, 0x01), | ||
409 | /* | ||
410 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
411 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
412 | */ | ||
413 | |||
414 | P4_OPCODE(P4_EVENT_X87_FP_UOP) = P4_OPCODE_PACK(0x04, 0x01), | ||
415 | /* | ||
416 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
417 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
418 | */ | ||
419 | |||
420 | P4_OPCODE(P4_EVENT_TC_MISC) = P4_OPCODE_PACK(0x06, 0x01), | ||
421 | /* | ||
422 | * MSR_P4_TC_ESCR0: 4, 5 | ||
423 | * MSR_P4_TC_ESCR1: 6, 7 | ||
424 | */ | ||
425 | |||
426 | P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS) = P4_OPCODE_PACK(0x13, 0x06), | ||
427 | /* | ||
428 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
429 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
430 | */ | ||
431 | |||
432 | P4_OPCODE(P4_EVENT_TC_MS_XFER) = P4_OPCODE_PACK(0x05, 0x00), | ||
433 | /* | ||
434 | * MSR_P4_MS_ESCR0: 4, 5 | ||
435 | * MSR_P4_MS_ESCR1: 6, 7 | ||
436 | */ | ||
437 | |||
438 | P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES) = P4_OPCODE_PACK(0x09, 0x00), | ||
439 | /* | ||
440 | * MSR_P4_MS_ESCR0: 4, 5 | ||
441 | * MSR_P4_MS_ESCR1: 6, 7 | ||
442 | */ | ||
443 | |||
444 | P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE) = P4_OPCODE_PACK(0x05, 0x02), | ||
445 | /* | ||
446 | * MSR_P4_TBPU_ESCR0: 4, 5 | ||
447 | * MSR_P4_TBPU_ESCR1: 6, 7 | ||
448 | */ | ||
449 | |||
450 | P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE) = P4_OPCODE_PACK(0x04, 0x02), | ||
451 | /* | ||
452 | * MSR_P4_TBPU_ESCR0: 4, 5 | ||
453 | * MSR_P4_TBPU_ESCR1: 6, 7 | ||
454 | */ | ||
455 | |||
456 | P4_OPCODE(P4_EVENT_RESOURCE_STALL) = P4_OPCODE_PACK(0x01, 0x01), | ||
457 | /* | ||
458 | * MSR_P4_ALF_ESCR0: 12, 13, 16 | ||
459 | * MSR_P4_ALF_ESCR1: 14, 15, 17 | ||
460 | */ | ||
461 | |||
462 | P4_OPCODE(P4_EVENT_WC_BUFFER) = P4_OPCODE_PACK(0x05, 0x05), | ||
463 | /* | ||
464 | * MSR_P4_DAC_ESCR0: 8, 9 | ||
465 | * MSR_P4_DAC_ESCR1: 10, 11 | ||
466 | */ | ||
467 | |||
468 | P4_OPCODE(P4_EVENT_B2B_CYCLES) = P4_OPCODE_PACK(0x16, 0x03), | ||
469 | /* | ||
470 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
471 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
472 | */ | ||
473 | |||
474 | P4_OPCODE(P4_EVENT_BNR) = P4_OPCODE_PACK(0x08, 0x03), | ||
475 | /* | ||
476 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
477 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
478 | */ | ||
479 | |||
480 | P4_OPCODE(P4_EVENT_SNOOP) = P4_OPCODE_PACK(0x06, 0x03), | ||
481 | /* | ||
482 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
483 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
484 | */ | ||
485 | |||
486 | P4_OPCODE(P4_EVENT_RESPONSE) = P4_OPCODE_PACK(0x04, 0x03), | ||
487 | /* | ||
488 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
489 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
490 | */ | ||
491 | |||
492 | P4_OPCODE(P4_EVENT_FRONT_END_EVENT) = P4_OPCODE_PACK(0x08, 0x05), | ||
493 | /* | ||
494 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
495 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
496 | */ | ||
497 | |||
498 | P4_OPCODE(P4_EVENT_EXECUTION_EVENT) = P4_OPCODE_PACK(0x0c, 0x05), | ||
499 | /* | ||
500 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
501 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
502 | */ | ||
503 | |||
504 | P4_OPCODE(P4_EVENT_REPLAY_EVENT) = P4_OPCODE_PACK(0x09, 0x05), | ||
505 | /* | ||
506 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
507 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
508 | */ | ||
509 | |||
510 | P4_OPCODE(P4_EVENT_INSTR_RETIRED) = P4_OPCODE_PACK(0x02, 0x04), | ||
511 | /* | ||
512 | * MSR_P4_CRU_ESCR0: 12, 13, 16 | ||
513 | * MSR_P4_CRU_ESCR1: 14, 15, 17 | ||
514 | */ | ||
515 | |||
516 | P4_OPCODE(P4_EVENT_UOPS_RETIRED) = P4_OPCODE_PACK(0x01, 0x04), | ||
517 | /* | ||
518 | * MSR_P4_CRU_ESCR0: 12, 13, 16 | ||
519 | * MSR_P4_CRU_ESCR1: 14, 15, 17 | ||
520 | */ | ||
521 | |||
522 | P4_OPCODE(P4_EVENT_UOP_TYPE) = P4_OPCODE_PACK(0x02, 0x02), | ||
523 | /* | ||
524 | * MSR_P4_RAT_ESCR0: 12, 13, 16 | ||
525 | * MSR_P4_RAT_ESCR1: 14, 15, 17 | ||
526 | */ | ||
527 | |||
528 | P4_OPCODE(P4_EVENT_BRANCH_RETIRED) = P4_OPCODE_PACK(0x06, 0x05), | ||
529 | /* | ||
530 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
531 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
532 | */ | ||
533 | |||
534 | P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED) = P4_OPCODE_PACK(0x03, 0x04), | ||
535 | /* | ||
536 | * MSR_P4_CRU_ESCR0: 12, 13, 16 | ||
537 | * MSR_P4_CRU_ESCR1: 14, 15, 17 | ||
538 | */ | ||
539 | |||
540 | P4_OPCODE(P4_EVENT_X87_ASSIST) = P4_OPCODE_PACK(0x03, 0x05), | ||
541 | /* | ||
542 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
543 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
544 | */ | ||
545 | |||
546 | P4_OPCODE(P4_EVENT_MACHINE_CLEAR) = P4_OPCODE_PACK(0x02, 0x05), | ||
547 | /* | ||
548 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
549 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
550 | */ | ||
551 | |||
552 | P4_OPCODE(P4_EVENT_INSTR_COMPLETED) = P4_OPCODE_PACK(0x07, 0x04), | ||
553 | /* | ||
554 | * MSR_P4_CRU_ESCR0: 12, 13, 16 | ||
555 | * MSR_P4_CRU_ESCR1: 14, 15, 17 | ||
556 | */ | ||
557 | }; | ||
558 | |||
559 | /* | ||
560 | * a caller should use P4_ESCR_EMASK_NAME helper to | ||
561 | * pick the EventMask needed, for example | ||
562 | * | ||
563 | * P4_ESCR_EMASK_NAME(P4_EVENT_TC_DELIVER_MODE, DD) | ||
564 | */ | ||
565 | enum P4_ESCR_EMASKS { | ||
566 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DD, 0), | ||
567 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DB, 1), | ||
568 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DI, 2), | ||
569 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BD, 3), | ||
570 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BB, 4), | ||
571 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BI, 5), | ||
572 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, ID, 6), | ||
573 | |||
574 | P4_GEN_ESCR_EMASK(P4_EVENT_BPU_FETCH_REQUEST, TCMISS, 0), | ||
575 | |||
576 | P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, HIT, 0), | ||
577 | P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, MISS, 1), | ||
578 | P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, HIT_UK, 2), | ||
579 | |||
580 | P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_CANCEL, ST_RB_FULL, 2), | ||
581 | P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_CANCEL, 64K_CONF, 3), | ||
582 | |||
583 | P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_COMPLETE, LSC, 0), | ||
584 | P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_COMPLETE, SSC, 1), | ||
585 | |||
586 | P4_GEN_ESCR_EMASK(P4_EVENT_LOAD_PORT_REPLAY, SPLIT_LD, 1), | ||
587 | |||
588 | P4_GEN_ESCR_EMASK(P4_EVENT_STORE_PORT_REPLAY, SPLIT_ST, 1), | ||
589 | |||
590 | P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, NO_STA, 1), | ||
591 | P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, NO_STD, 3), | ||
592 | P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, PARTIAL_DATA, 4), | ||
593 | P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, UNALGN_ADDR, 5), | ||
594 | |||
595 | P4_GEN_ESCR_EMASK(P4_EVENT_PAGE_WALK_TYPE, DTMISS, 0), | ||
596 | P4_GEN_ESCR_EMASK(P4_EVENT_PAGE_WALK_TYPE, ITMISS, 1), | ||
597 | |||
598 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS, 0), | ||
599 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE, 1), | ||
600 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM, 2), | ||
601 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS, 3), | ||
602 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE, 4), | ||
603 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM, 5), | ||
604 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS, 8), | ||
605 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS, 9), | ||
606 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS, 10), | ||
607 | |||
608 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, DEFAULT, 0), | ||
609 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, ALL_READ, 5), | ||
610 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, ALL_WRITE, 6), | ||
611 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_UC, 7), | ||
612 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WC, 8), | ||
613 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WT, 9), | ||
614 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WP, 10), | ||
615 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WB, 11), | ||
616 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, OWN, 13), | ||
617 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, OTHER, 14), | ||
618 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, PREFETCH, 15), | ||
619 | |||
620 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, DEFAULT, 0), | ||
621 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_READ, 5), | ||
622 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_WRITE, 6), | ||
623 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_UC, 7), | ||
624 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WC, 8), | ||
625 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WT, 9), | ||
626 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WP, 10), | ||
627 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WB, 11), | ||
628 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, OWN, 13), | ||
629 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, OTHER, 14), | ||
630 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, PREFETCH, 15), | ||
631 | |||
632 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV, 0), | ||
633 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN, 1), | ||
634 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OTHER, 2), | ||
635 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_DRV, 3), | ||
636 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OWN, 4), | ||
637 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OTHER, 5), | ||
638 | |||
639 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE0, 0), | ||
640 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE1, 1), | ||
641 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LEN0, 2), | ||
642 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LEN1, 3), | ||
643 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_IO_TYPE, 5), | ||
644 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LOCK_TYPE, 6), | ||
645 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_CACHE_TYPE, 7), | ||
646 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_SPLIT_TYPE, 8), | ||
647 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_DEM_TYPE, 9), | ||
648 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_ORD_TYPE, 10), | ||
649 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE0, 11), | ||
650 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE1, 12), | ||
651 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE2, 13), | ||
652 | |||
653 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE0, 0), | ||
654 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE1, 1), | ||
655 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN0, 2), | ||
656 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN1, 3), | ||
657 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_IO_TYPE, 5), | ||
658 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LOCK_TYPE, 6), | ||
659 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_CACHE_TYPE, 7), | ||
660 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_SPLIT_TYPE, 8), | ||
661 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_DEM_TYPE, 9), | ||
662 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_ORD_TYPE, 10), | ||
663 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE0, 11), | ||
664 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE1, 12), | ||
665 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE2, 13), | ||
666 | |||
667 | P4_GEN_ESCR_EMASK(P4_EVENT_SSE_INPUT_ASSIST, ALL, 15), | ||
668 | |||
669 | P4_GEN_ESCR_EMASK(P4_EVENT_PACKED_SP_UOP, ALL, 15), | ||
670 | |||
671 | P4_GEN_ESCR_EMASK(P4_EVENT_PACKED_DP_UOP, ALL, 15), | ||
672 | |||
673 | P4_GEN_ESCR_EMASK(P4_EVENT_SCALAR_SP_UOP, ALL, 15), | ||
674 | |||
675 | P4_GEN_ESCR_EMASK(P4_EVENT_SCALAR_DP_UOP, ALL, 15), | ||
676 | |||
677 | P4_GEN_ESCR_EMASK(P4_EVENT_64BIT_MMX_UOP, ALL, 15), | ||
678 | |||
679 | P4_GEN_ESCR_EMASK(P4_EVENT_128BIT_MMX_UOP, ALL, 15), | ||
680 | |||
681 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_FP_UOP, ALL, 15), | ||
682 | |||
683 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_MISC, FLUSH, 4), | ||
684 | |||
685 | P4_GEN_ESCR_EMASK(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING, 0), | ||
686 | |||
687 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_MS_XFER, CISC, 0), | ||
688 | |||
689 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_BUILD, 0), | ||
690 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_DELIVER, 1), | ||
691 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_ROM, 2), | ||
692 | |||
693 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CONDITIONAL, 1), | ||
694 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CALL, 2), | ||
695 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, RETURN, 3), | ||
696 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, INDIRECT, 4), | ||
697 | |||
698 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL, 1), | ||
699 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, CALL, 2), | ||
700 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN, 3), | ||
701 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT, 4), | ||
702 | |||
703 | P4_GEN_ESCR_EMASK(P4_EVENT_RESOURCE_STALL, SBFULL, 5), | ||
704 | |||
705 | P4_GEN_ESCR_EMASK(P4_EVENT_WC_BUFFER, WCB_EVICTS, 0), | ||
706 | P4_GEN_ESCR_EMASK(P4_EVENT_WC_BUFFER, WCB_FULL_EVICTS, 1), | ||
707 | |||
708 | P4_GEN_ESCR_EMASK(P4_EVENT_FRONT_END_EVENT, NBOGUS, 0), | ||
709 | P4_GEN_ESCR_EMASK(P4_EVENT_FRONT_END_EVENT, BOGUS, 1), | ||
710 | |||
711 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS0, 0), | ||
712 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS1, 1), | ||
713 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS2, 2), | ||
714 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS3, 3), | ||
715 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS0, 4), | ||
716 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS1, 5), | ||
717 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS2, 6), | ||
718 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS3, 7), | ||
719 | |||
720 | P4_GEN_ESCR_EMASK(P4_EVENT_REPLAY_EVENT, NBOGUS, 0), | ||
721 | P4_GEN_ESCR_EMASK(P4_EVENT_REPLAY_EVENT, BOGUS, 1), | ||
722 | |||
723 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG, 0), | ||
724 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, NBOGUSTAG, 1), | ||
725 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, BOGUSNTAG, 2), | ||
726 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, BOGUSTAG, 3), | ||
727 | |||
728 | P4_GEN_ESCR_EMASK(P4_EVENT_UOPS_RETIRED, NBOGUS, 0), | ||
729 | P4_GEN_ESCR_EMASK(P4_EVENT_UOPS_RETIRED, BOGUS, 1), | ||
730 | |||
731 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_TYPE, TAGLOADS, 1), | ||
732 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_TYPE, TAGSTORES, 2), | ||
733 | |||
734 | P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMNP, 0), | ||
735 | P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMNM, 1), | ||
736 | P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMTP, 2), | ||
737 | P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMTM, 3), | ||
738 | |||
739 | P4_GEN_ESCR_EMASK(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS, 0), | ||
740 | |||
741 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, FPSU, 0), | ||
742 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, FPSO, 1), | ||
743 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, POAO, 2), | ||
744 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, POAU, 3), | ||
745 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, PREA, 4), | ||
746 | |||
747 | P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, CLEAR, 0), | ||
748 | P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, MOCLEAR, 1), | ||
749 | P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, SMCLEAR, 2), | ||
750 | |||
751 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_COMPLETED, NBOGUS, 0), | ||
752 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_COMPLETED, BOGUS, 1), | ||
753 | }; | ||
754 | |||
755 | /* P4 PEBS: stale for a while */ | ||
756 | #define P4_PEBS_METRIC_MASK 0x00001fffU | ||
757 | #define P4_PEBS_UOB_TAG 0x01000000U | ||
758 | #define P4_PEBS_ENABLE 0x02000000U | ||
759 | |||
760 | /* Replay metrics for MSR_IA32_PEBS_ENABLE and MSR_P4_PEBS_MATRIX_VERT */ | ||
761 | #define P4_PEBS__1stl_cache_load_miss_retired 0x3000001 | ||
762 | #define P4_PEBS__2ndl_cache_load_miss_retired 0x3000002 | ||
763 | #define P4_PEBS__dtlb_load_miss_retired 0x3000004 | ||
764 | #define P4_PEBS__dtlb_store_miss_retired 0x3000004 | ||
765 | #define P4_PEBS__dtlb_all_miss_retired 0x3000004 | ||
766 | #define P4_PEBS__tagged_mispred_branch 0x3018000 | ||
767 | #define P4_PEBS__mob_load_replay_retired 0x3000200 | ||
768 | #define P4_PEBS__split_load_retired 0x3000400 | ||
769 | #define P4_PEBS__split_store_retired 0x3000400 | ||
770 | |||
771 | #define P4_VERT__1stl_cache_load_miss_retired 0x0000001 | ||
772 | #define P4_VERT__2ndl_cache_load_miss_retired 0x0000001 | ||
773 | #define P4_VERT__dtlb_load_miss_retired 0x0000001 | ||
774 | #define P4_VERT__dtlb_store_miss_retired 0x0000002 | ||
775 | #define P4_VERT__dtlb_all_miss_retired 0x0000003 | ||
776 | #define P4_VERT__tagged_mispred_branch 0x0000010 | ||
777 | #define P4_VERT__mob_load_replay_retired 0x0000001 | ||
778 | #define P4_VERT__split_load_retired 0x0000001 | ||
779 | #define P4_VERT__split_store_retired 0x0000002 | ||
780 | |||
781 | enum P4_CACHE_EVENTS { | ||
782 | P4_CACHE__NONE, | ||
783 | |||
784 | P4_CACHE__1stl_cache_load_miss_retired, | ||
785 | P4_CACHE__2ndl_cache_load_miss_retired, | ||
786 | P4_CACHE__dtlb_load_miss_retired, | ||
787 | P4_CACHE__dtlb_store_miss_retired, | ||
788 | P4_CACHE__itlb_reference_hit, | ||
789 | P4_CACHE__itlb_reference_miss, | ||
790 | |||
791 | P4_CACHE__MAX | ||
792 | }; | ||
793 | |||
794 | #endif /* PERF_EVENT_P4_H */ | ||
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index b753ea59703..32428b410b5 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h | |||
@@ -21,7 +21,6 @@ struct mm_struct; | |||
21 | #include <asm/msr.h> | 21 | #include <asm/msr.h> |
22 | #include <asm/desc_defs.h> | 22 | #include <asm/desc_defs.h> |
23 | #include <asm/nops.h> | 23 | #include <asm/nops.h> |
24 | #include <asm/ds.h> | ||
25 | 24 | ||
26 | #include <linux/personality.h> | 25 | #include <linux/personality.h> |
27 | #include <linux/cpumask.h> | 26 | #include <linux/cpumask.h> |
@@ -29,6 +28,7 @@ struct mm_struct; | |||
29 | #include <linux/threads.h> | 28 | #include <linux/threads.h> |
30 | #include <linux/math64.h> | 29 | #include <linux/math64.h> |
31 | #include <linux/init.h> | 30 | #include <linux/init.h> |
31 | #include <linux/err.h> | ||
32 | 32 | ||
33 | #define HBP_NUM 4 | 33 | #define HBP_NUM 4 |
34 | /* | 34 | /* |
@@ -473,10 +473,6 @@ struct thread_struct { | |||
473 | unsigned long iopl; | 473 | unsigned long iopl; |
474 | /* Max allowed port in the bitmap, in bytes: */ | 474 | /* Max allowed port in the bitmap, in bytes: */ |
475 | unsigned io_bitmap_max; | 475 | unsigned io_bitmap_max; |
476 | /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set. */ | ||
477 | unsigned long debugctlmsr; | ||
478 | /* Debug Store context; see asm/ds.h */ | ||
479 | struct ds_context *ds_ctx; | ||
480 | }; | 476 | }; |
481 | 477 | ||
482 | static inline unsigned long native_get_debugreg(int regno) | 478 | static inline unsigned long native_get_debugreg(int regno) |
@@ -803,7 +799,7 @@ extern void cpu_init(void); | |||
803 | 799 | ||
804 | static inline unsigned long get_debugctlmsr(void) | 800 | static inline unsigned long get_debugctlmsr(void) |
805 | { | 801 | { |
806 | unsigned long debugctlmsr = 0; | 802 | unsigned long debugctlmsr = 0; |
807 | 803 | ||
808 | #ifndef CONFIG_X86_DEBUGCTLMSR | 804 | #ifndef CONFIG_X86_DEBUGCTLMSR |
809 | if (boot_cpu_data.x86 < 6) | 805 | if (boot_cpu_data.x86 < 6) |
@@ -811,21 +807,6 @@ static inline unsigned long get_debugctlmsr(void) | |||
811 | #endif | 807 | #endif |
812 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); | 808 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); |
813 | 809 | ||
814 | return debugctlmsr; | ||
815 | } | ||
816 | |||
817 | static inline unsigned long get_debugctlmsr_on_cpu(int cpu) | ||
818 | { | ||
819 | u64 debugctlmsr = 0; | ||
820 | u32 val1, val2; | ||
821 | |||
822 | #ifndef CONFIG_X86_DEBUGCTLMSR | ||
823 | if (boot_cpu_data.x86 < 6) | ||
824 | return 0; | ||
825 | #endif | ||
826 | rdmsr_on_cpu(cpu, MSR_IA32_DEBUGCTLMSR, &val1, &val2); | ||
827 | debugctlmsr = val1 | ((u64)val2 << 32); | ||
828 | |||
829 | return debugctlmsr; | 810 | return debugctlmsr; |
830 | } | 811 | } |
831 | 812 | ||
@@ -838,18 +819,6 @@ static inline void update_debugctlmsr(unsigned long debugctlmsr) | |||
838 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); | 819 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); |
839 | } | 820 | } |
840 | 821 | ||
841 | static inline void update_debugctlmsr_on_cpu(int cpu, | ||
842 | unsigned long debugctlmsr) | ||
843 | { | ||
844 | #ifndef CONFIG_X86_DEBUGCTLMSR | ||
845 | if (boot_cpu_data.x86 < 6) | ||
846 | return; | ||
847 | #endif | ||
848 | wrmsr_on_cpu(cpu, MSR_IA32_DEBUGCTLMSR, | ||
849 | (u32)((u64)debugctlmsr), | ||
850 | (u32)((u64)debugctlmsr >> 32)); | ||
851 | } | ||
852 | |||
853 | /* | 822 | /* |
854 | * from system description table in BIOS. Mostly for MCA use, but | 823 | * from system description table in BIOS. Mostly for MCA use, but |
855 | * others may find it useful: | 824 | * others may find it useful: |
diff --git a/arch/x86/include/asm/ptrace-abi.h b/arch/x86/include/asm/ptrace-abi.h index 86723035a51..52b098a6eeb 100644 --- a/arch/x86/include/asm/ptrace-abi.h +++ b/arch/x86/include/asm/ptrace-abi.h | |||
@@ -82,61 +82,6 @@ | |||
82 | 82 | ||
83 | #ifndef __ASSEMBLY__ | 83 | #ifndef __ASSEMBLY__ |
84 | #include <linux/types.h> | 84 | #include <linux/types.h> |
85 | 85 | #endif | |
86 | /* configuration/status structure used in PTRACE_BTS_CONFIG and | ||
87 | PTRACE_BTS_STATUS commands. | ||
88 | */ | ||
89 | struct ptrace_bts_config { | ||
90 | /* requested or actual size of BTS buffer in bytes */ | ||
91 | __u32 size; | ||
92 | /* bitmask of below flags */ | ||
93 | __u32 flags; | ||
94 | /* buffer overflow signal */ | ||
95 | __u32 signal; | ||
96 | /* actual size of bts_struct in bytes */ | ||
97 | __u32 bts_size; | ||
98 | }; | ||
99 | #endif /* __ASSEMBLY__ */ | ||
100 | |||
101 | #define PTRACE_BTS_O_TRACE 0x1 /* branch trace */ | ||
102 | #define PTRACE_BTS_O_SCHED 0x2 /* scheduling events w/ jiffies */ | ||
103 | #define PTRACE_BTS_O_SIGNAL 0x4 /* send SIG<signal> on buffer overflow | ||
104 | instead of wrapping around */ | ||
105 | #define PTRACE_BTS_O_ALLOC 0x8 /* (re)allocate buffer */ | ||
106 | |||
107 | #define PTRACE_BTS_CONFIG 40 | ||
108 | /* Configure branch trace recording. | ||
109 | ADDR points to a struct ptrace_bts_config. | ||
110 | DATA gives the size of that buffer. | ||
111 | A new buffer is allocated, if requested in the flags. | ||
112 | An overflow signal may only be requested for new buffers. | ||
113 | Returns the number of bytes read. | ||
114 | */ | ||
115 | #define PTRACE_BTS_STATUS 41 | ||
116 | /* Return the current configuration in a struct ptrace_bts_config | ||
117 | pointed to by ADDR; DATA gives the size of that buffer. | ||
118 | Returns the number of bytes written. | ||
119 | */ | ||
120 | #define PTRACE_BTS_SIZE 42 | ||
121 | /* Return the number of available BTS records for draining. | ||
122 | DATA and ADDR are ignored. | ||
123 | */ | ||
124 | #define PTRACE_BTS_GET 43 | ||
125 | /* Get a single BTS record. | ||
126 | DATA defines the index into the BTS array, where 0 is the newest | ||
127 | entry, and higher indices refer to older entries. | ||
128 | ADDR is pointing to struct bts_struct (see asm/ds.h). | ||
129 | */ | ||
130 | #define PTRACE_BTS_CLEAR 44 | ||
131 | /* Clear the BTS buffer. | ||
132 | DATA and ADDR are ignored. | ||
133 | */ | ||
134 | #define PTRACE_BTS_DRAIN 45 | ||
135 | /* Read all available BTS records and clear the buffer. | ||
136 | ADDR points to an array of struct bts_struct. | ||
137 | DATA gives the size of that buffer. | ||
138 | BTS records are read from oldest to newest. | ||
139 | Returns number of BTS records drained. | ||
140 | */ | ||
141 | 86 | ||
142 | #endif /* _ASM_X86_PTRACE_ABI_H */ | 87 | #endif /* _ASM_X86_PTRACE_ABI_H */ |
diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h index 69a686a7dff..78cd1ea9450 100644 --- a/arch/x86/include/asm/ptrace.h +++ b/arch/x86/include/asm/ptrace.h | |||
@@ -289,12 +289,6 @@ extern int do_get_thread_area(struct task_struct *p, int idx, | |||
289 | extern int do_set_thread_area(struct task_struct *p, int idx, | 289 | extern int do_set_thread_area(struct task_struct *p, int idx, |
290 | struct user_desc __user *info, int can_allocate); | 290 | struct user_desc __user *info, int can_allocate); |
291 | 291 | ||
292 | #ifdef CONFIG_X86_PTRACE_BTS | ||
293 | extern void ptrace_bts_untrace(struct task_struct *tsk); | ||
294 | |||
295 | #define arch_ptrace_untrace(tsk) ptrace_bts_untrace(tsk) | ||
296 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
297 | |||
298 | #endif /* __KERNEL__ */ | 292 | #endif /* __KERNEL__ */ |
299 | 293 | ||
300 | #endif /* !__ASSEMBLY__ */ | 294 | #endif /* !__ASSEMBLY__ */ |
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index e0d28901e96..d017ed5502e 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h | |||
@@ -92,8 +92,7 @@ struct thread_info { | |||
92 | #define TIF_IO_BITMAP 22 /* uses I/O bitmap */ | 92 | #define TIF_IO_BITMAP 22 /* uses I/O bitmap */ |
93 | #define TIF_FREEZE 23 /* is freezing for suspend */ | 93 | #define TIF_FREEZE 23 /* is freezing for suspend */ |
94 | #define TIF_FORCED_TF 24 /* true if TF in eflags artificially */ | 94 | #define TIF_FORCED_TF 24 /* true if TF in eflags artificially */ |
95 | #define TIF_DEBUGCTLMSR 25 /* uses thread_struct.debugctlmsr */ | 95 | #define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */ |
96 | #define TIF_DS_AREA_MSR 26 /* uses thread_struct.ds_area_msr */ | ||
97 | #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */ | 96 | #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */ |
98 | #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */ | 97 | #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */ |
99 | 98 | ||
@@ -115,8 +114,7 @@ struct thread_info { | |||
115 | #define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP) | 114 | #define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP) |
116 | #define _TIF_FREEZE (1 << TIF_FREEZE) | 115 | #define _TIF_FREEZE (1 << TIF_FREEZE) |
117 | #define _TIF_FORCED_TF (1 << TIF_FORCED_TF) | 116 | #define _TIF_FORCED_TF (1 << TIF_FORCED_TF) |
118 | #define _TIF_DEBUGCTLMSR (1 << TIF_DEBUGCTLMSR) | 117 | #define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP) |
119 | #define _TIF_DS_AREA_MSR (1 << TIF_DS_AREA_MSR) | ||
120 | #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES) | 118 | #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES) |
121 | #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) | 119 | #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) |
122 | 120 | ||
@@ -147,7 +145,7 @@ struct thread_info { | |||
147 | 145 | ||
148 | /* flags to check in __switch_to() */ | 146 | /* flags to check in __switch_to() */ |
149 | #define _TIF_WORK_CTXSW \ | 147 | #define _TIF_WORK_CTXSW \ |
150 | (_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_NOTSC) | 148 | (_TIF_IO_BITMAP|_TIF_NOTSC|_TIF_BLOCKSTEP) |
151 | 149 | ||
152 | #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) | 150 | #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) |
153 | #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG) | 151 | #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG) |
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 4c58352209e..e77b2208372 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile | |||
@@ -47,8 +47,6 @@ obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o | |||
47 | obj-y += process.o | 47 | obj-y += process.o |
48 | obj-y += i387.o xsave.o | 48 | obj-y += i387.o xsave.o |
49 | obj-y += ptrace.o | 49 | obj-y += ptrace.o |
50 | obj-$(CONFIG_X86_DS) += ds.o | ||
51 | obj-$(CONFIG_X86_DS_SELFTEST) += ds_selftest.o | ||
52 | obj-$(CONFIG_X86_32) += tls.o | 50 | obj-$(CONFIG_X86_32) += tls.o |
53 | obj-$(CONFIG_IA32_EMULATION) += tls.o | 51 | obj-$(CONFIG_IA32_EMULATION) += tls.o |
54 | obj-y += step.o | 52 | obj-y += step.o |
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 7e1cca13af3..d72377c41c7 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <asm/processor.h> | 12 | #include <asm/processor.h> |
13 | #include <asm/pgtable.h> | 13 | #include <asm/pgtable.h> |
14 | #include <asm/msr.h> | 14 | #include <asm/msr.h> |
15 | #include <asm/ds.h> | ||
16 | #include <asm/bugs.h> | 15 | #include <asm/bugs.h> |
17 | #include <asm/cpu.h> | 16 | #include <asm/cpu.h> |
18 | 17 | ||
@@ -367,7 +366,6 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c) | |||
367 | set_cpu_cap(c, X86_FEATURE_BTS); | 366 | set_cpu_cap(c, X86_FEATURE_BTS); |
368 | if (!(l1 & (1<<12))) | 367 | if (!(l1 & (1<<12))) |
369 | set_cpu_cap(c, X86_FEATURE_PEBS); | 368 | set_cpu_cap(c, X86_FEATURE_PEBS); |
370 | ds_init_intel(c); | ||
371 | } | 369 | } |
372 | 370 | ||
373 | if (c->x86 == 6 && c->x86_model == 29 && cpu_has_clflush) | 371 | if (c->x86 == 6 && c->x86_model == 29 && cpu_has_clflush) |
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c index db5bdc8addf..626154a9f53 100644 --- a/arch/x86/kernel/cpu/perf_event.c +++ b/arch/x86/kernel/cpu/perf_event.c | |||
@@ -31,46 +31,51 @@ | |||
31 | #include <asm/nmi.h> | 31 | #include <asm/nmi.h> |
32 | #include <asm/compat.h> | 32 | #include <asm/compat.h> |
33 | 33 | ||
34 | static u64 perf_event_mask __read_mostly; | 34 | #if 0 |
35 | #undef wrmsrl | ||
36 | #define wrmsrl(msr, val) \ | ||
37 | do { \ | ||
38 | trace_printk("wrmsrl(%lx, %lx)\n", (unsigned long)(msr),\ | ||
39 | (unsigned long)(val)); \ | ||
40 | native_write_msr((msr), (u32)((u64)(val)), \ | ||
41 | (u32)((u64)(val) >> 32)); \ | ||
42 | } while (0) | ||
43 | #endif | ||
35 | 44 | ||
36 | /* The maximal number of PEBS events: */ | 45 | /* |
37 | #define MAX_PEBS_EVENTS 4 | 46 | * best effort, GUP based copy_from_user() that assumes IRQ or NMI context |
47 | */ | ||
48 | static unsigned long | ||
49 | copy_from_user_nmi(void *to, const void __user *from, unsigned long n) | ||
50 | { | ||
51 | unsigned long offset, addr = (unsigned long)from; | ||
52 | int type = in_nmi() ? KM_NMI : KM_IRQ0; | ||
53 | unsigned long size, len = 0; | ||
54 | struct page *page; | ||
55 | void *map; | ||
56 | int ret; | ||
38 | 57 | ||
39 | /* The size of a BTS record in bytes: */ | 58 | do { |
40 | #define BTS_RECORD_SIZE 24 | 59 | ret = __get_user_pages_fast(addr, 1, 0, &page); |
60 | if (!ret) | ||
61 | break; | ||
41 | 62 | ||
42 | /* The size of a per-cpu BTS buffer in bytes: */ | 63 | offset = addr & (PAGE_SIZE - 1); |
43 | #define BTS_BUFFER_SIZE (BTS_RECORD_SIZE * 2048) | 64 | size = min(PAGE_SIZE - offset, n - len); |
44 | 65 | ||
45 | /* The BTS overflow threshold in bytes from the end of the buffer: */ | 66 | map = kmap_atomic(page, type); |
46 | #define BTS_OVFL_TH (BTS_RECORD_SIZE * 128) | 67 | memcpy(to, map+offset, size); |
68 | kunmap_atomic(map, type); | ||
69 | put_page(page); | ||
47 | 70 | ||
71 | len += size; | ||
72 | to += size; | ||
73 | addr += size; | ||
48 | 74 | ||
49 | /* | 75 | } while (len < n); |
50 | * Bits in the debugctlmsr controlling branch tracing. | ||
51 | */ | ||
52 | #define X86_DEBUGCTL_TR (1 << 6) | ||
53 | #define X86_DEBUGCTL_BTS (1 << 7) | ||
54 | #define X86_DEBUGCTL_BTINT (1 << 8) | ||
55 | #define X86_DEBUGCTL_BTS_OFF_OS (1 << 9) | ||
56 | #define X86_DEBUGCTL_BTS_OFF_USR (1 << 10) | ||
57 | 76 | ||
58 | /* | 77 | return len; |
59 | * A debug store configuration. | 78 | } |
60 | * | ||
61 | * We only support architectures that use 64bit fields. | ||
62 | */ | ||
63 | struct debug_store { | ||
64 | u64 bts_buffer_base; | ||
65 | u64 bts_index; | ||
66 | u64 bts_absolute_maximum; | ||
67 | u64 bts_interrupt_threshold; | ||
68 | u64 pebs_buffer_base; | ||
69 | u64 pebs_index; | ||
70 | u64 pebs_absolute_maximum; | ||
71 | u64 pebs_interrupt_threshold; | ||
72 | u64 pebs_event_reset[MAX_PEBS_EVENTS]; | ||
73 | }; | ||
74 | 79 | ||
75 | struct event_constraint { | 80 | struct event_constraint { |
76 | union { | 81 | union { |
@@ -89,18 +94,39 @@ struct amd_nb { | |||
89 | struct event_constraint event_constraints[X86_PMC_IDX_MAX]; | 94 | struct event_constraint event_constraints[X86_PMC_IDX_MAX]; |
90 | }; | 95 | }; |
91 | 96 | ||
97 | #define MAX_LBR_ENTRIES 16 | ||
98 | |||
92 | struct cpu_hw_events { | 99 | struct cpu_hw_events { |
100 | /* | ||
101 | * Generic x86 PMC bits | ||
102 | */ | ||
93 | struct perf_event *events[X86_PMC_IDX_MAX]; /* in counter order */ | 103 | struct perf_event *events[X86_PMC_IDX_MAX]; /* in counter order */ |
94 | unsigned long active_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | 104 | unsigned long active_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; |
95 | unsigned long interrupts; | ||
96 | int enabled; | 105 | int enabled; |
97 | struct debug_store *ds; | ||
98 | 106 | ||
99 | int n_events; | 107 | int n_events; |
100 | int n_added; | 108 | int n_added; |
101 | int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */ | 109 | int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */ |
102 | u64 tags[X86_PMC_IDX_MAX]; | 110 | u64 tags[X86_PMC_IDX_MAX]; |
103 | struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */ | 111 | struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */ |
112 | |||
113 | /* | ||
114 | * Intel DebugStore bits | ||
115 | */ | ||
116 | struct debug_store *ds; | ||
117 | u64 pebs_enabled; | ||
118 | |||
119 | /* | ||
120 | * Intel LBR bits | ||
121 | */ | ||
122 | int lbr_users; | ||
123 | void *lbr_context; | ||
124 | struct perf_branch_stack lbr_stack; | ||
125 | struct perf_branch_entry lbr_entries[MAX_LBR_ENTRIES]; | ||
126 | |||
127 | /* | ||
128 | * AMD specific bits | ||
129 | */ | ||
104 | struct amd_nb *amd_nb; | 130 | struct amd_nb *amd_nb; |
105 | }; | 131 | }; |
106 | 132 | ||
@@ -114,11 +140,31 @@ struct cpu_hw_events { | |||
114 | #define EVENT_CONSTRAINT(c, n, m) \ | 140 | #define EVENT_CONSTRAINT(c, n, m) \ |
115 | __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n)) | 141 | __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n)) |
116 | 142 | ||
143 | /* | ||
144 | * Constraint on the Event code. | ||
145 | */ | ||
117 | #define INTEL_EVENT_CONSTRAINT(c, n) \ | 146 | #define INTEL_EVENT_CONSTRAINT(c, n) \ |
118 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVTSEL_MASK) | 147 | EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT) |
119 | 148 | ||
149 | /* | ||
150 | * Constraint on the Event code + UMask + fixed-mask | ||
151 | * | ||
152 | * filter mask to validate fixed counter events. | ||
153 | * the following filters disqualify for fixed counters: | ||
154 | * - inv | ||
155 | * - edge | ||
156 | * - cnt-mask | ||
157 | * The other filters are supported by fixed counters. | ||
158 | * The any-thread option is supported starting with v3. | ||
159 | */ | ||
120 | #define FIXED_EVENT_CONSTRAINT(c, n) \ | 160 | #define FIXED_EVENT_CONSTRAINT(c, n) \ |
121 | EVENT_CONSTRAINT(c, (1ULL << (32+n)), INTEL_ARCH_FIXED_MASK) | 161 | EVENT_CONSTRAINT(c, (1ULL << (32+n)), X86_RAW_EVENT_MASK) |
162 | |||
163 | /* | ||
164 | * Constraint on the Event code + UMask | ||
165 | */ | ||
166 | #define PEBS_EVENT_CONSTRAINT(c, n) \ | ||
167 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK) | ||
122 | 168 | ||
123 | #define EVENT_CONSTRAINT_END \ | 169 | #define EVENT_CONSTRAINT_END \ |
124 | EVENT_CONSTRAINT(0, 0, 0) | 170 | EVENT_CONSTRAINT(0, 0, 0) |
@@ -126,32 +172,43 @@ struct cpu_hw_events { | |||
126 | #define for_each_event_constraint(e, c) \ | 172 | #define for_each_event_constraint(e, c) \ |
127 | for ((e) = (c); (e)->cmask; (e)++) | 173 | for ((e) = (c); (e)->cmask; (e)++) |
128 | 174 | ||
175 | union perf_capabilities { | ||
176 | struct { | ||
177 | u64 lbr_format : 6; | ||
178 | u64 pebs_trap : 1; | ||
179 | u64 pebs_arch_reg : 1; | ||
180 | u64 pebs_format : 4; | ||
181 | u64 smm_freeze : 1; | ||
182 | }; | ||
183 | u64 capabilities; | ||
184 | }; | ||
185 | |||
129 | /* | 186 | /* |
130 | * struct x86_pmu - generic x86 pmu | 187 | * struct x86_pmu - generic x86 pmu |
131 | */ | 188 | */ |
132 | struct x86_pmu { | 189 | struct x86_pmu { |
190 | /* | ||
191 | * Generic x86 PMC bits | ||
192 | */ | ||
133 | const char *name; | 193 | const char *name; |
134 | int version; | 194 | int version; |
135 | int (*handle_irq)(struct pt_regs *); | 195 | int (*handle_irq)(struct pt_regs *); |
136 | void (*disable_all)(void); | 196 | void (*disable_all)(void); |
137 | void (*enable_all)(void); | 197 | void (*enable_all)(int added); |
138 | void (*enable)(struct perf_event *); | 198 | void (*enable)(struct perf_event *); |
139 | void (*disable)(struct perf_event *); | 199 | void (*disable)(struct perf_event *); |
200 | int (*hw_config)(struct perf_event *event); | ||
201 | int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign); | ||
140 | unsigned eventsel; | 202 | unsigned eventsel; |
141 | unsigned perfctr; | 203 | unsigned perfctr; |
142 | u64 (*event_map)(int); | 204 | u64 (*event_map)(int); |
143 | u64 (*raw_event)(u64); | ||
144 | int max_events; | 205 | int max_events; |
145 | int num_events; | 206 | int num_counters; |
146 | int num_events_fixed; | 207 | int num_counters_fixed; |
147 | int event_bits; | 208 | int cntval_bits; |
148 | u64 event_mask; | 209 | u64 cntval_mask; |
149 | int apic; | 210 | int apic; |
150 | u64 max_period; | 211 | u64 max_period; |
151 | u64 intel_ctrl; | ||
152 | void (*enable_bts)(u64 config); | ||
153 | void (*disable_bts)(void); | ||
154 | |||
155 | struct event_constraint * | 212 | struct event_constraint * |
156 | (*get_event_constraints)(struct cpu_hw_events *cpuc, | 213 | (*get_event_constraints)(struct cpu_hw_events *cpuc, |
157 | struct perf_event *event); | 214 | struct perf_event *event); |
@@ -159,11 +216,32 @@ struct x86_pmu { | |||
159 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, | 216 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, |
160 | struct perf_event *event); | 217 | struct perf_event *event); |
161 | struct event_constraint *event_constraints; | 218 | struct event_constraint *event_constraints; |
219 | void (*quirks)(void); | ||
162 | 220 | ||
163 | int (*cpu_prepare)(int cpu); | 221 | int (*cpu_prepare)(int cpu); |
164 | void (*cpu_starting)(int cpu); | 222 | void (*cpu_starting)(int cpu); |
165 | void (*cpu_dying)(int cpu); | 223 | void (*cpu_dying)(int cpu); |
166 | void (*cpu_dead)(int cpu); | 224 | void (*cpu_dead)(int cpu); |
225 | |||
226 | /* | ||
227 | * Intel Arch Perfmon v2+ | ||
228 | */ | ||
229 | u64 intel_ctrl; | ||
230 | union perf_capabilities intel_cap; | ||
231 | |||
232 | /* | ||
233 | * Intel DebugStore bits | ||
234 | */ | ||
235 | int bts, pebs; | ||
236 | int pebs_record_size; | ||
237 | void (*drain_pebs)(struct pt_regs *regs); | ||
238 | struct event_constraint *pebs_constraints; | ||
239 | |||
240 | /* | ||
241 | * Intel LBR | ||
242 | */ | ||
243 | unsigned long lbr_tos, lbr_from, lbr_to; /* MSR base regs */ | ||
244 | int lbr_nr; /* hardware stack size */ | ||
167 | }; | 245 | }; |
168 | 246 | ||
169 | static struct x86_pmu x86_pmu __read_mostly; | 247 | static struct x86_pmu x86_pmu __read_mostly; |
@@ -198,7 +276,7 @@ static u64 | |||
198 | x86_perf_event_update(struct perf_event *event) | 276 | x86_perf_event_update(struct perf_event *event) |
199 | { | 277 | { |
200 | struct hw_perf_event *hwc = &event->hw; | 278 | struct hw_perf_event *hwc = &event->hw; |
201 | int shift = 64 - x86_pmu.event_bits; | 279 | int shift = 64 - x86_pmu.cntval_bits; |
202 | u64 prev_raw_count, new_raw_count; | 280 | u64 prev_raw_count, new_raw_count; |
203 | int idx = hwc->idx; | 281 | int idx = hwc->idx; |
204 | s64 delta; | 282 | s64 delta; |
@@ -241,33 +319,32 @@ again: | |||
241 | static atomic_t active_events; | 319 | static atomic_t active_events; |
242 | static DEFINE_MUTEX(pmc_reserve_mutex); | 320 | static DEFINE_MUTEX(pmc_reserve_mutex); |
243 | 321 | ||
322 | #ifdef CONFIG_X86_LOCAL_APIC | ||
323 | |||
244 | static bool reserve_pmc_hardware(void) | 324 | static bool reserve_pmc_hardware(void) |
245 | { | 325 | { |
246 | #ifdef CONFIG_X86_LOCAL_APIC | ||
247 | int i; | 326 | int i; |
248 | 327 | ||
249 | if (nmi_watchdog == NMI_LOCAL_APIC) | 328 | if (nmi_watchdog == NMI_LOCAL_APIC) |
250 | disable_lapic_nmi_watchdog(); | 329 | disable_lapic_nmi_watchdog(); |
251 | 330 | ||
252 | for (i = 0; i < x86_pmu.num_events; i++) { | 331 | for (i = 0; i < x86_pmu.num_counters; i++) { |
253 | if (!reserve_perfctr_nmi(x86_pmu.perfctr + i)) | 332 | if (!reserve_perfctr_nmi(x86_pmu.perfctr + i)) |
254 | goto perfctr_fail; | 333 | goto perfctr_fail; |
255 | } | 334 | } |
256 | 335 | ||
257 | for (i = 0; i < x86_pmu.num_events; i++) { | 336 | for (i = 0; i < x86_pmu.num_counters; i++) { |
258 | if (!reserve_evntsel_nmi(x86_pmu.eventsel + i)) | 337 | if (!reserve_evntsel_nmi(x86_pmu.eventsel + i)) |
259 | goto eventsel_fail; | 338 | goto eventsel_fail; |
260 | } | 339 | } |
261 | #endif | ||
262 | 340 | ||
263 | return true; | 341 | return true; |
264 | 342 | ||
265 | #ifdef CONFIG_X86_LOCAL_APIC | ||
266 | eventsel_fail: | 343 | eventsel_fail: |
267 | for (i--; i >= 0; i--) | 344 | for (i--; i >= 0; i--) |
268 | release_evntsel_nmi(x86_pmu.eventsel + i); | 345 | release_evntsel_nmi(x86_pmu.eventsel + i); |
269 | 346 | ||
270 | i = x86_pmu.num_events; | 347 | i = x86_pmu.num_counters; |
271 | 348 | ||
272 | perfctr_fail: | 349 | perfctr_fail: |
273 | for (i--; i >= 0; i--) | 350 | for (i--; i >= 0; i--) |
@@ -277,128 +354,36 @@ perfctr_fail: | |||
277 | enable_lapic_nmi_watchdog(); | 354 | enable_lapic_nmi_watchdog(); |
278 | 355 | ||
279 | return false; | 356 | return false; |
280 | #endif | ||
281 | } | 357 | } |
282 | 358 | ||
283 | static void release_pmc_hardware(void) | 359 | static void release_pmc_hardware(void) |
284 | { | 360 | { |
285 | #ifdef CONFIG_X86_LOCAL_APIC | ||
286 | int i; | 361 | int i; |
287 | 362 | ||
288 | for (i = 0; i < x86_pmu.num_events; i++) { | 363 | for (i = 0; i < x86_pmu.num_counters; i++) { |
289 | release_perfctr_nmi(x86_pmu.perfctr + i); | 364 | release_perfctr_nmi(x86_pmu.perfctr + i); |
290 | release_evntsel_nmi(x86_pmu.eventsel + i); | 365 | release_evntsel_nmi(x86_pmu.eventsel + i); |
291 | } | 366 | } |
292 | 367 | ||
293 | if (nmi_watchdog == NMI_LOCAL_APIC) | 368 | if (nmi_watchdog == NMI_LOCAL_APIC) |
294 | enable_lapic_nmi_watchdog(); | 369 | enable_lapic_nmi_watchdog(); |
295 | #endif | ||
296 | } | ||
297 | |||
298 | static inline bool bts_available(void) | ||
299 | { | ||
300 | return x86_pmu.enable_bts != NULL; | ||
301 | } | ||
302 | |||
303 | static void init_debug_store_on_cpu(int cpu) | ||
304 | { | ||
305 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
306 | |||
307 | if (!ds) | ||
308 | return; | ||
309 | |||
310 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, | ||
311 | (u32)((u64)(unsigned long)ds), | ||
312 | (u32)((u64)(unsigned long)ds >> 32)); | ||
313 | } | ||
314 | |||
315 | static void fini_debug_store_on_cpu(int cpu) | ||
316 | { | ||
317 | if (!per_cpu(cpu_hw_events, cpu).ds) | ||
318 | return; | ||
319 | |||
320 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0); | ||
321 | } | ||
322 | |||
323 | static void release_bts_hardware(void) | ||
324 | { | ||
325 | int cpu; | ||
326 | |||
327 | if (!bts_available()) | ||
328 | return; | ||
329 | |||
330 | get_online_cpus(); | ||
331 | |||
332 | for_each_online_cpu(cpu) | ||
333 | fini_debug_store_on_cpu(cpu); | ||
334 | |||
335 | for_each_possible_cpu(cpu) { | ||
336 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
337 | |||
338 | if (!ds) | ||
339 | continue; | ||
340 | |||
341 | per_cpu(cpu_hw_events, cpu).ds = NULL; | ||
342 | |||
343 | kfree((void *)(unsigned long)ds->bts_buffer_base); | ||
344 | kfree(ds); | ||
345 | } | ||
346 | |||
347 | put_online_cpus(); | ||
348 | } | 370 | } |
349 | 371 | ||
350 | static int reserve_bts_hardware(void) | 372 | #else |
351 | { | ||
352 | int cpu, err = 0; | ||
353 | |||
354 | if (!bts_available()) | ||
355 | return 0; | ||
356 | |||
357 | get_online_cpus(); | ||
358 | |||
359 | for_each_possible_cpu(cpu) { | ||
360 | struct debug_store *ds; | ||
361 | void *buffer; | ||
362 | |||
363 | err = -ENOMEM; | ||
364 | buffer = kzalloc(BTS_BUFFER_SIZE, GFP_KERNEL); | ||
365 | if (unlikely(!buffer)) | ||
366 | break; | ||
367 | |||
368 | ds = kzalloc(sizeof(*ds), GFP_KERNEL); | ||
369 | if (unlikely(!ds)) { | ||
370 | kfree(buffer); | ||
371 | break; | ||
372 | } | ||
373 | |||
374 | ds->bts_buffer_base = (u64)(unsigned long)buffer; | ||
375 | ds->bts_index = ds->bts_buffer_base; | ||
376 | ds->bts_absolute_maximum = | ||
377 | ds->bts_buffer_base + BTS_BUFFER_SIZE; | ||
378 | ds->bts_interrupt_threshold = | ||
379 | ds->bts_absolute_maximum - BTS_OVFL_TH; | ||
380 | 373 | ||
381 | per_cpu(cpu_hw_events, cpu).ds = ds; | 374 | static bool reserve_pmc_hardware(void) { return true; } |
382 | err = 0; | 375 | static void release_pmc_hardware(void) {} |
383 | } | ||
384 | 376 | ||
385 | if (err) | 377 | #endif |
386 | release_bts_hardware(); | ||
387 | else { | ||
388 | for_each_online_cpu(cpu) | ||
389 | init_debug_store_on_cpu(cpu); | ||
390 | } | ||
391 | |||
392 | put_online_cpus(); | ||
393 | 378 | ||
394 | return err; | 379 | static int reserve_ds_buffers(void); |
395 | } | 380 | static void release_ds_buffers(void); |
396 | 381 | ||
397 | static void hw_perf_event_destroy(struct perf_event *event) | 382 | static void hw_perf_event_destroy(struct perf_event *event) |
398 | { | 383 | { |
399 | if (atomic_dec_and_mutex_lock(&active_events, &pmc_reserve_mutex)) { | 384 | if (atomic_dec_and_mutex_lock(&active_events, &pmc_reserve_mutex)) { |
400 | release_pmc_hardware(); | 385 | release_pmc_hardware(); |
401 | release_bts_hardware(); | 386 | release_ds_buffers(); |
402 | mutex_unlock(&pmc_reserve_mutex); | 387 | mutex_unlock(&pmc_reserve_mutex); |
403 | } | 388 | } |
404 | } | 389 | } |
@@ -441,6 +426,28 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event_attr *attr) | |||
441 | return 0; | 426 | return 0; |
442 | } | 427 | } |
443 | 428 | ||
429 | static int x86_pmu_hw_config(struct perf_event *event) | ||
430 | { | ||
431 | /* | ||
432 | * Generate PMC IRQs: | ||
433 | * (keep 'enabled' bit clear for now) | ||
434 | */ | ||
435 | event->hw.config = ARCH_PERFMON_EVENTSEL_INT; | ||
436 | |||
437 | /* | ||
438 | * Count user and OS events unless requested not to | ||
439 | */ | ||
440 | if (!event->attr.exclude_user) | ||
441 | event->hw.config |= ARCH_PERFMON_EVENTSEL_USR; | ||
442 | if (!event->attr.exclude_kernel) | ||
443 | event->hw.config |= ARCH_PERFMON_EVENTSEL_OS; | ||
444 | |||
445 | if (event->attr.type == PERF_TYPE_RAW) | ||
446 | event->hw.config |= event->attr.config & X86_RAW_EVENT_MASK; | ||
447 | |||
448 | return 0; | ||
449 | } | ||
450 | |||
444 | /* | 451 | /* |
445 | * Setup the hardware configuration for a given attr_type | 452 | * Setup the hardware configuration for a given attr_type |
446 | */ | 453 | */ |
@@ -460,8 +467,11 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
460 | if (atomic_read(&active_events) == 0) { | 467 | if (atomic_read(&active_events) == 0) { |
461 | if (!reserve_pmc_hardware()) | 468 | if (!reserve_pmc_hardware()) |
462 | err = -EBUSY; | 469 | err = -EBUSY; |
463 | else | 470 | else { |
464 | err = reserve_bts_hardware(); | 471 | err = reserve_ds_buffers(); |
472 | if (err) | ||
473 | release_pmc_hardware(); | ||
474 | } | ||
465 | } | 475 | } |
466 | if (!err) | 476 | if (!err) |
467 | atomic_inc(&active_events); | 477 | atomic_inc(&active_events); |
@@ -472,23 +482,14 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
472 | 482 | ||
473 | event->destroy = hw_perf_event_destroy; | 483 | event->destroy = hw_perf_event_destroy; |
474 | 484 | ||
475 | /* | ||
476 | * Generate PMC IRQs: | ||
477 | * (keep 'enabled' bit clear for now) | ||
478 | */ | ||
479 | hwc->config = ARCH_PERFMON_EVENTSEL_INT; | ||
480 | |||
481 | hwc->idx = -1; | 485 | hwc->idx = -1; |
482 | hwc->last_cpu = -1; | 486 | hwc->last_cpu = -1; |
483 | hwc->last_tag = ~0ULL; | 487 | hwc->last_tag = ~0ULL; |
484 | 488 | ||
485 | /* | 489 | /* Processor specifics */ |
486 | * Count user and OS events unless requested not to. | 490 | err = x86_pmu.hw_config(event); |
487 | */ | 491 | if (err) |
488 | if (!attr->exclude_user) | 492 | return err; |
489 | hwc->config |= ARCH_PERFMON_EVENTSEL_USR; | ||
490 | if (!attr->exclude_kernel) | ||
491 | hwc->config |= ARCH_PERFMON_EVENTSEL_OS; | ||
492 | 493 | ||
493 | if (!hwc->sample_period) { | 494 | if (!hwc->sample_period) { |
494 | hwc->sample_period = x86_pmu.max_period; | 495 | hwc->sample_period = x86_pmu.max_period; |
@@ -505,16 +506,8 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
505 | return -EOPNOTSUPP; | 506 | return -EOPNOTSUPP; |
506 | } | 507 | } |
507 | 508 | ||
508 | /* | 509 | if (attr->type == PERF_TYPE_RAW) |
509 | * Raw hw_event type provide the config in the hw_event structure | ||
510 | */ | ||
511 | if (attr->type == PERF_TYPE_RAW) { | ||
512 | hwc->config |= x86_pmu.raw_event(attr->config); | ||
513 | if ((hwc->config & ARCH_PERFMON_EVENTSEL_ANY) && | ||
514 | perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) | ||
515 | return -EACCES; | ||
516 | return 0; | 510 | return 0; |
517 | } | ||
518 | 511 | ||
519 | if (attr->type == PERF_TYPE_HW_CACHE) | 512 | if (attr->type == PERF_TYPE_HW_CACHE) |
520 | return set_ext_hw_attr(hwc, attr); | 513 | return set_ext_hw_attr(hwc, attr); |
@@ -539,11 +532,11 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
539 | if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) && | 532 | if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) && |
540 | (hwc->sample_period == 1)) { | 533 | (hwc->sample_period == 1)) { |
541 | /* BTS is not supported by this architecture. */ | 534 | /* BTS is not supported by this architecture. */ |
542 | if (!bts_available()) | 535 | if (!x86_pmu.bts) |
543 | return -EOPNOTSUPP; | 536 | return -EOPNOTSUPP; |
544 | 537 | ||
545 | /* BTS is currently only allowed for user-mode. */ | 538 | /* BTS is currently only allowed for user-mode. */ |
546 | if (hwc->config & ARCH_PERFMON_EVENTSEL_OS) | 539 | if (!attr->exclude_kernel) |
547 | return -EOPNOTSUPP; | 540 | return -EOPNOTSUPP; |
548 | } | 541 | } |
549 | 542 | ||
@@ -557,7 +550,7 @@ static void x86_pmu_disable_all(void) | |||
557 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 550 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
558 | int idx; | 551 | int idx; |
559 | 552 | ||
560 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 553 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
561 | u64 val; | 554 | u64 val; |
562 | 555 | ||
563 | if (!test_bit(idx, cpuc->active_mask)) | 556 | if (!test_bit(idx, cpuc->active_mask)) |
@@ -587,12 +580,12 @@ void hw_perf_disable(void) | |||
587 | x86_pmu.disable_all(); | 580 | x86_pmu.disable_all(); |
588 | } | 581 | } |
589 | 582 | ||
590 | static void x86_pmu_enable_all(void) | 583 | static void x86_pmu_enable_all(int added) |
591 | { | 584 | { |
592 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 585 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
593 | int idx; | 586 | int idx; |
594 | 587 | ||
595 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 588 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
596 | struct perf_event *event = cpuc->events[idx]; | 589 | struct perf_event *event = cpuc->events[idx]; |
597 | u64 val; | 590 | u64 val; |
598 | 591 | ||
@@ -667,14 +660,14 @@ static int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) | |||
667 | * assign events to counters starting with most | 660 | * assign events to counters starting with most |
668 | * constrained events. | 661 | * constrained events. |
669 | */ | 662 | */ |
670 | wmax = x86_pmu.num_events; | 663 | wmax = x86_pmu.num_counters; |
671 | 664 | ||
672 | /* | 665 | /* |
673 | * when fixed event counters are present, | 666 | * when fixed event counters are present, |
674 | * wmax is incremented by 1 to account | 667 | * wmax is incremented by 1 to account |
675 | * for one more choice | 668 | * for one more choice |
676 | */ | 669 | */ |
677 | if (x86_pmu.num_events_fixed) | 670 | if (x86_pmu.num_counters_fixed) |
678 | wmax++; | 671 | wmax++; |
679 | 672 | ||
680 | for (w = 1, num = n; num && w <= wmax; w++) { | 673 | for (w = 1, num = n; num && w <= wmax; w++) { |
@@ -724,7 +717,7 @@ static int collect_events(struct cpu_hw_events *cpuc, struct perf_event *leader, | |||
724 | struct perf_event *event; | 717 | struct perf_event *event; |
725 | int n, max_count; | 718 | int n, max_count; |
726 | 719 | ||
727 | max_count = x86_pmu.num_events + x86_pmu.num_events_fixed; | 720 | max_count = x86_pmu.num_counters + x86_pmu.num_counters_fixed; |
728 | 721 | ||
729 | /* current number of events already accepted */ | 722 | /* current number of events already accepted */ |
730 | n = cpuc->n_events; | 723 | n = cpuc->n_events; |
@@ -795,7 +788,7 @@ void hw_perf_enable(void) | |||
795 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 788 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
796 | struct perf_event *event; | 789 | struct perf_event *event; |
797 | struct hw_perf_event *hwc; | 790 | struct hw_perf_event *hwc; |
798 | int i; | 791 | int i, added = cpuc->n_added; |
799 | 792 | ||
800 | if (!x86_pmu_initialized()) | 793 | if (!x86_pmu_initialized()) |
801 | return; | 794 | return; |
@@ -847,19 +840,20 @@ void hw_perf_enable(void) | |||
847 | cpuc->enabled = 1; | 840 | cpuc->enabled = 1; |
848 | barrier(); | 841 | barrier(); |
849 | 842 | ||
850 | x86_pmu.enable_all(); | 843 | x86_pmu.enable_all(added); |
851 | } | 844 | } |
852 | 845 | ||
853 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc) | 846 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc) |
854 | { | 847 | { |
855 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | 848 | wrmsrl(hwc->config_base + hwc->idx, |
856 | hwc->config | ARCH_PERFMON_EVENTSEL_ENABLE); | 849 | hwc->config | ARCH_PERFMON_EVENTSEL_ENABLE); |
857 | } | 850 | } |
858 | 851 | ||
859 | static inline void x86_pmu_disable_event(struct perf_event *event) | 852 | static inline void x86_pmu_disable_event(struct perf_event *event) |
860 | { | 853 | { |
861 | struct hw_perf_event *hwc = &event->hw; | 854 | struct hw_perf_event *hwc = &event->hw; |
862 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, hwc->config); | 855 | |
856 | wrmsrl(hwc->config_base + hwc->idx, hwc->config); | ||
863 | } | 857 | } |
864 | 858 | ||
865 | static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); | 859 | static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); |
@@ -874,7 +868,7 @@ x86_perf_event_set_period(struct perf_event *event) | |||
874 | struct hw_perf_event *hwc = &event->hw; | 868 | struct hw_perf_event *hwc = &event->hw; |
875 | s64 left = atomic64_read(&hwc->period_left); | 869 | s64 left = atomic64_read(&hwc->period_left); |
876 | s64 period = hwc->sample_period; | 870 | s64 period = hwc->sample_period; |
877 | int err, ret = 0, idx = hwc->idx; | 871 | int ret = 0, idx = hwc->idx; |
878 | 872 | ||
879 | if (idx == X86_PMC_IDX_FIXED_BTS) | 873 | if (idx == X86_PMC_IDX_FIXED_BTS) |
880 | return 0; | 874 | return 0; |
@@ -912,8 +906,8 @@ x86_perf_event_set_period(struct perf_event *event) | |||
912 | */ | 906 | */ |
913 | atomic64_set(&hwc->prev_count, (u64)-left); | 907 | atomic64_set(&hwc->prev_count, (u64)-left); |
914 | 908 | ||
915 | err = checking_wrmsrl(hwc->event_base + idx, | 909 | wrmsrl(hwc->event_base + idx, |
916 | (u64)(-left) & x86_pmu.event_mask); | 910 | (u64)(-left) & x86_pmu.cntval_mask); |
917 | 911 | ||
918 | perf_event_update_userpage(event); | 912 | perf_event_update_userpage(event); |
919 | 913 | ||
@@ -950,7 +944,7 @@ static int x86_pmu_enable(struct perf_event *event) | |||
950 | if (n < 0) | 944 | if (n < 0) |
951 | return n; | 945 | return n; |
952 | 946 | ||
953 | ret = x86_schedule_events(cpuc, n, assign); | 947 | ret = x86_pmu.schedule_events(cpuc, n, assign); |
954 | if (ret) | 948 | if (ret) |
955 | return ret; | 949 | return ret; |
956 | /* | 950 | /* |
@@ -991,11 +985,12 @@ static void x86_pmu_unthrottle(struct perf_event *event) | |||
991 | void perf_event_print_debug(void) | 985 | void perf_event_print_debug(void) |
992 | { | 986 | { |
993 | u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed; | 987 | u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed; |
988 | u64 pebs; | ||
994 | struct cpu_hw_events *cpuc; | 989 | struct cpu_hw_events *cpuc; |
995 | unsigned long flags; | 990 | unsigned long flags; |
996 | int cpu, idx; | 991 | int cpu, idx; |
997 | 992 | ||
998 | if (!x86_pmu.num_events) | 993 | if (!x86_pmu.num_counters) |
999 | return; | 994 | return; |
1000 | 995 | ||
1001 | local_irq_save(flags); | 996 | local_irq_save(flags); |
@@ -1008,16 +1003,18 @@ void perf_event_print_debug(void) | |||
1008 | rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status); | 1003 | rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status); |
1009 | rdmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, overflow); | 1004 | rdmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, overflow); |
1010 | rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR_CTRL, fixed); | 1005 | rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR_CTRL, fixed); |
1006 | rdmsrl(MSR_IA32_PEBS_ENABLE, pebs); | ||
1011 | 1007 | ||
1012 | pr_info("\n"); | 1008 | pr_info("\n"); |
1013 | pr_info("CPU#%d: ctrl: %016llx\n", cpu, ctrl); | 1009 | pr_info("CPU#%d: ctrl: %016llx\n", cpu, ctrl); |
1014 | pr_info("CPU#%d: status: %016llx\n", cpu, status); | 1010 | pr_info("CPU#%d: status: %016llx\n", cpu, status); |
1015 | pr_info("CPU#%d: overflow: %016llx\n", cpu, overflow); | 1011 | pr_info("CPU#%d: overflow: %016llx\n", cpu, overflow); |
1016 | pr_info("CPU#%d: fixed: %016llx\n", cpu, fixed); | 1012 | pr_info("CPU#%d: fixed: %016llx\n", cpu, fixed); |
1013 | pr_info("CPU#%d: pebs: %016llx\n", cpu, pebs); | ||
1017 | } | 1014 | } |
1018 | pr_info("CPU#%d: active: %016llx\n", cpu, *(u64 *)cpuc->active_mask); | 1015 | pr_info("CPU#%d: active: %016llx\n", cpu, *(u64 *)cpuc->active_mask); |
1019 | 1016 | ||
1020 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 1017 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
1021 | rdmsrl(x86_pmu.eventsel + idx, pmc_ctrl); | 1018 | rdmsrl(x86_pmu.eventsel + idx, pmc_ctrl); |
1022 | rdmsrl(x86_pmu.perfctr + idx, pmc_count); | 1019 | rdmsrl(x86_pmu.perfctr + idx, pmc_count); |
1023 | 1020 | ||
@@ -1030,7 +1027,7 @@ void perf_event_print_debug(void) | |||
1030 | pr_info("CPU#%d: gen-PMC%d left: %016llx\n", | 1027 | pr_info("CPU#%d: gen-PMC%d left: %016llx\n", |
1031 | cpu, idx, prev_left); | 1028 | cpu, idx, prev_left); |
1032 | } | 1029 | } |
1033 | for (idx = 0; idx < x86_pmu.num_events_fixed; idx++) { | 1030 | for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) { |
1034 | rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, pmc_count); | 1031 | rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, pmc_count); |
1035 | 1032 | ||
1036 | pr_info("CPU#%d: fixed-PMC%d count: %016llx\n", | 1033 | pr_info("CPU#%d: fixed-PMC%d count: %016llx\n", |
@@ -1095,7 +1092,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1095 | 1092 | ||
1096 | cpuc = &__get_cpu_var(cpu_hw_events); | 1093 | cpuc = &__get_cpu_var(cpu_hw_events); |
1097 | 1094 | ||
1098 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 1095 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
1099 | if (!test_bit(idx, cpuc->active_mask)) | 1096 | if (!test_bit(idx, cpuc->active_mask)) |
1100 | continue; | 1097 | continue; |
1101 | 1098 | ||
@@ -1103,7 +1100,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1103 | hwc = &event->hw; | 1100 | hwc = &event->hw; |
1104 | 1101 | ||
1105 | val = x86_perf_event_update(event); | 1102 | val = x86_perf_event_update(event); |
1106 | if (val & (1ULL << (x86_pmu.event_bits - 1))) | 1103 | if (val & (1ULL << (x86_pmu.cntval_bits - 1))) |
1107 | continue; | 1104 | continue; |
1108 | 1105 | ||
1109 | /* | 1106 | /* |
@@ -1146,7 +1143,6 @@ void set_perf_event_pending(void) | |||
1146 | 1143 | ||
1147 | void perf_events_lapic_init(void) | 1144 | void perf_events_lapic_init(void) |
1148 | { | 1145 | { |
1149 | #ifdef CONFIG_X86_LOCAL_APIC | ||
1150 | if (!x86_pmu.apic || !x86_pmu_initialized()) | 1146 | if (!x86_pmu.apic || !x86_pmu_initialized()) |
1151 | return; | 1147 | return; |
1152 | 1148 | ||
@@ -1154,7 +1150,6 @@ void perf_events_lapic_init(void) | |||
1154 | * Always use NMI for PMU | 1150 | * Always use NMI for PMU |
1155 | */ | 1151 | */ |
1156 | apic_write(APIC_LVTPC, APIC_DM_NMI); | 1152 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
1157 | #endif | ||
1158 | } | 1153 | } |
1159 | 1154 | ||
1160 | static int __kprobes | 1155 | static int __kprobes |
@@ -1178,9 +1173,7 @@ perf_event_nmi_handler(struct notifier_block *self, | |||
1178 | 1173 | ||
1179 | regs = args->regs; | 1174 | regs = args->regs; |
1180 | 1175 | ||
1181 | #ifdef CONFIG_X86_LOCAL_APIC | ||
1182 | apic_write(APIC_LVTPC, APIC_DM_NMI); | 1176 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
1183 | #endif | ||
1184 | /* | 1177 | /* |
1185 | * Can't rely on the handled return value to say it was our NMI, two | 1178 | * Can't rely on the handled return value to say it was our NMI, two |
1186 | * events could trigger 'simultaneously' raising two back-to-back NMIs. | 1179 | * events could trigger 'simultaneously' raising two back-to-back NMIs. |
@@ -1274,12 +1267,15 @@ int hw_perf_group_sched_in(struct perf_event *leader, | |||
1274 | int assign[X86_PMC_IDX_MAX]; | 1267 | int assign[X86_PMC_IDX_MAX]; |
1275 | int n0, n1, ret; | 1268 | int n0, n1, ret; |
1276 | 1269 | ||
1270 | if (!x86_pmu_initialized()) | ||
1271 | return 0; | ||
1272 | |||
1277 | /* n0 = total number of events */ | 1273 | /* n0 = total number of events */ |
1278 | n0 = collect_events(cpuc, leader, true); | 1274 | n0 = collect_events(cpuc, leader, true); |
1279 | if (n0 < 0) | 1275 | if (n0 < 0) |
1280 | return n0; | 1276 | return n0; |
1281 | 1277 | ||
1282 | ret = x86_schedule_events(cpuc, n0, assign); | 1278 | ret = x86_pmu.schedule_events(cpuc, n0, assign); |
1283 | if (ret) | 1279 | if (ret) |
1284 | return ret; | 1280 | return ret; |
1285 | 1281 | ||
@@ -1329,6 +1325,9 @@ undo: | |||
1329 | 1325 | ||
1330 | #include "perf_event_amd.c" | 1326 | #include "perf_event_amd.c" |
1331 | #include "perf_event_p6.c" | 1327 | #include "perf_event_p6.c" |
1328 | #include "perf_event_p4.c" | ||
1329 | #include "perf_event_intel_lbr.c" | ||
1330 | #include "perf_event_intel_ds.c" | ||
1332 | #include "perf_event_intel.c" | 1331 | #include "perf_event_intel.c" |
1333 | 1332 | ||
1334 | static int __cpuinit | 1333 | static int __cpuinit |
@@ -1402,48 +1401,50 @@ void __init init_hw_perf_events(void) | |||
1402 | 1401 | ||
1403 | pr_cont("%s PMU driver.\n", x86_pmu.name); | 1402 | pr_cont("%s PMU driver.\n", x86_pmu.name); |
1404 | 1403 | ||
1405 | if (x86_pmu.num_events > X86_PMC_MAX_GENERIC) { | 1404 | if (x86_pmu.quirks) |
1405 | x86_pmu.quirks(); | ||
1406 | |||
1407 | if (x86_pmu.num_counters > X86_PMC_MAX_GENERIC) { | ||
1406 | WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", | 1408 | WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", |
1407 | x86_pmu.num_events, X86_PMC_MAX_GENERIC); | 1409 | x86_pmu.num_counters, X86_PMC_MAX_GENERIC); |
1408 | x86_pmu.num_events = X86_PMC_MAX_GENERIC; | 1410 | x86_pmu.num_counters = X86_PMC_MAX_GENERIC; |
1409 | } | 1411 | } |
1410 | perf_event_mask = (1 << x86_pmu.num_events) - 1; | 1412 | x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1; |
1411 | perf_max_events = x86_pmu.num_events; | 1413 | perf_max_events = x86_pmu.num_counters; |
1412 | 1414 | ||
1413 | if (x86_pmu.num_events_fixed > X86_PMC_MAX_FIXED) { | 1415 | if (x86_pmu.num_counters_fixed > X86_PMC_MAX_FIXED) { |
1414 | WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", | 1416 | WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", |
1415 | x86_pmu.num_events_fixed, X86_PMC_MAX_FIXED); | 1417 | x86_pmu.num_counters_fixed, X86_PMC_MAX_FIXED); |
1416 | x86_pmu.num_events_fixed = X86_PMC_MAX_FIXED; | 1418 | x86_pmu.num_counters_fixed = X86_PMC_MAX_FIXED; |
1417 | } | 1419 | } |
1418 | 1420 | ||
1419 | perf_event_mask |= | 1421 | x86_pmu.intel_ctrl |= |
1420 | ((1LL << x86_pmu.num_events_fixed)-1) << X86_PMC_IDX_FIXED; | 1422 | ((1LL << x86_pmu.num_counters_fixed)-1) << X86_PMC_IDX_FIXED; |
1421 | x86_pmu.intel_ctrl = perf_event_mask; | ||
1422 | 1423 | ||
1423 | perf_events_lapic_init(); | 1424 | perf_events_lapic_init(); |
1424 | register_die_notifier(&perf_event_nmi_notifier); | 1425 | register_die_notifier(&perf_event_nmi_notifier); |
1425 | 1426 | ||
1426 | unconstrained = (struct event_constraint) | 1427 | unconstrained = (struct event_constraint) |
1427 | __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_events) - 1, | 1428 | __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_counters) - 1, |
1428 | 0, x86_pmu.num_events); | 1429 | 0, x86_pmu.num_counters); |
1429 | 1430 | ||
1430 | if (x86_pmu.event_constraints) { | 1431 | if (x86_pmu.event_constraints) { |
1431 | for_each_event_constraint(c, x86_pmu.event_constraints) { | 1432 | for_each_event_constraint(c, x86_pmu.event_constraints) { |
1432 | if (c->cmask != INTEL_ARCH_FIXED_MASK) | 1433 | if (c->cmask != X86_RAW_EVENT_MASK) |
1433 | continue; | 1434 | continue; |
1434 | 1435 | ||
1435 | c->idxmsk64 |= (1ULL << x86_pmu.num_events) - 1; | 1436 | c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1; |
1436 | c->weight += x86_pmu.num_events; | 1437 | c->weight += x86_pmu.num_counters; |
1437 | } | 1438 | } |
1438 | } | 1439 | } |
1439 | 1440 | ||
1440 | pr_info("... version: %d\n", x86_pmu.version); | 1441 | pr_info("... version: %d\n", x86_pmu.version); |
1441 | pr_info("... bit width: %d\n", x86_pmu.event_bits); | 1442 | pr_info("... bit width: %d\n", x86_pmu.cntval_bits); |
1442 | pr_info("... generic registers: %d\n", x86_pmu.num_events); | 1443 | pr_info("... generic registers: %d\n", x86_pmu.num_counters); |
1443 | pr_info("... value mask: %016Lx\n", x86_pmu.event_mask); | 1444 | pr_info("... value mask: %016Lx\n", x86_pmu.cntval_mask); |
1444 | pr_info("... max period: %016Lx\n", x86_pmu.max_period); | 1445 | pr_info("... max period: %016Lx\n", x86_pmu.max_period); |
1445 | pr_info("... fixed-purpose events: %d\n", x86_pmu.num_events_fixed); | 1446 | pr_info("... fixed-purpose events: %d\n", x86_pmu.num_counters_fixed); |
1446 | pr_info("... event mask: %016Lx\n", perf_event_mask); | 1447 | pr_info("... event mask: %016Lx\n", x86_pmu.intel_ctrl); |
1447 | 1448 | ||
1448 | perf_cpu_notifier(x86_pmu_notifier); | 1449 | perf_cpu_notifier(x86_pmu_notifier); |
1449 | } | 1450 | } |
@@ -1463,6 +1464,32 @@ static const struct pmu pmu = { | |||
1463 | }; | 1464 | }; |
1464 | 1465 | ||
1465 | /* | 1466 | /* |
1467 | * validate that we can schedule this event | ||
1468 | */ | ||
1469 | static int validate_event(struct perf_event *event) | ||
1470 | { | ||
1471 | struct cpu_hw_events *fake_cpuc; | ||
1472 | struct event_constraint *c; | ||
1473 | int ret = 0; | ||
1474 | |||
1475 | fake_cpuc = kmalloc(sizeof(*fake_cpuc), GFP_KERNEL | __GFP_ZERO); | ||
1476 | if (!fake_cpuc) | ||
1477 | return -ENOMEM; | ||
1478 | |||
1479 | c = x86_pmu.get_event_constraints(fake_cpuc, event); | ||
1480 | |||
1481 | if (!c || !c->weight) | ||
1482 | ret = -ENOSPC; | ||
1483 | |||
1484 | if (x86_pmu.put_event_constraints) | ||
1485 | x86_pmu.put_event_constraints(fake_cpuc, event); | ||
1486 | |||
1487 | kfree(fake_cpuc); | ||
1488 | |||
1489 | return ret; | ||
1490 | } | ||
1491 | |||
1492 | /* | ||
1466 | * validate a single event group | 1493 | * validate a single event group |
1467 | * | 1494 | * |
1468 | * validation include: | 1495 | * validation include: |
@@ -1502,7 +1529,7 @@ static int validate_group(struct perf_event *event) | |||
1502 | 1529 | ||
1503 | fake_cpuc->n_events = n; | 1530 | fake_cpuc->n_events = n; |
1504 | 1531 | ||
1505 | ret = x86_schedule_events(fake_cpuc, n, NULL); | 1532 | ret = x86_pmu.schedule_events(fake_cpuc, n, NULL); |
1506 | 1533 | ||
1507 | out_free: | 1534 | out_free: |
1508 | kfree(fake_cpuc); | 1535 | kfree(fake_cpuc); |
@@ -1527,6 +1554,8 @@ const struct pmu *hw_perf_event_init(struct perf_event *event) | |||
1527 | 1554 | ||
1528 | if (event->group_leader != event) | 1555 | if (event->group_leader != event) |
1529 | err = validate_group(event); | 1556 | err = validate_group(event); |
1557 | else | ||
1558 | err = validate_event(event); | ||
1530 | 1559 | ||
1531 | event->pmu = tmp; | 1560 | event->pmu = tmp; |
1532 | } | 1561 | } |
@@ -1574,8 +1603,7 @@ static void backtrace_address(void *data, unsigned long addr, int reliable) | |||
1574 | { | 1603 | { |
1575 | struct perf_callchain_entry *entry = data; | 1604 | struct perf_callchain_entry *entry = data; |
1576 | 1605 | ||
1577 | if (reliable) | 1606 | callchain_store(entry, addr); |
1578 | callchain_store(entry, addr); | ||
1579 | } | 1607 | } |
1580 | 1608 | ||
1581 | static const struct stacktrace_ops backtrace_ops = { | 1609 | static const struct stacktrace_ops backtrace_ops = { |
@@ -1597,41 +1625,6 @@ perf_callchain_kernel(struct pt_regs *regs, struct perf_callchain_entry *entry) | |||
1597 | dump_trace(NULL, regs, NULL, regs->bp, &backtrace_ops, entry); | 1625 | dump_trace(NULL, regs, NULL, regs->bp, &backtrace_ops, entry); |
1598 | } | 1626 | } |
1599 | 1627 | ||
1600 | /* | ||
1601 | * best effort, GUP based copy_from_user() that assumes IRQ or NMI context | ||
1602 | */ | ||
1603 | static unsigned long | ||
1604 | copy_from_user_nmi(void *to, const void __user *from, unsigned long n) | ||
1605 | { | ||
1606 | unsigned long offset, addr = (unsigned long)from; | ||
1607 | int type = in_nmi() ? KM_NMI : KM_IRQ0; | ||
1608 | unsigned long size, len = 0; | ||
1609 | struct page *page; | ||
1610 | void *map; | ||
1611 | int ret; | ||
1612 | |||
1613 | do { | ||
1614 | ret = __get_user_pages_fast(addr, 1, 0, &page); | ||
1615 | if (!ret) | ||
1616 | break; | ||
1617 | |||
1618 | offset = addr & (PAGE_SIZE - 1); | ||
1619 | size = min(PAGE_SIZE - offset, n - len); | ||
1620 | |||
1621 | map = kmap_atomic(page, type); | ||
1622 | memcpy(to, map+offset, size); | ||
1623 | kunmap_atomic(map, type); | ||
1624 | put_page(page); | ||
1625 | |||
1626 | len += size; | ||
1627 | to += size; | ||
1628 | addr += size; | ||
1629 | |||
1630 | } while (len < n); | ||
1631 | |||
1632 | return len; | ||
1633 | } | ||
1634 | |||
1635 | #ifdef CONFIG_COMPAT | 1628 | #ifdef CONFIG_COMPAT |
1636 | static inline int | 1629 | static inline int |
1637 | perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) | 1630 | perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) |
diff --git a/arch/x86/kernel/cpu/perf_event_amd.c b/arch/x86/kernel/cpu/perf_event_amd.c index db6f7d4056e..611df11ba15 100644 --- a/arch/x86/kernel/cpu/perf_event_amd.c +++ b/arch/x86/kernel/cpu/perf_event_amd.c | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | static DEFINE_RAW_SPINLOCK(amd_nb_lock); | 3 | static DEFINE_RAW_SPINLOCK(amd_nb_lock); |
4 | 4 | ||
5 | static __initconst u64 amd_hw_cache_event_ids | 5 | static __initconst const u64 amd_hw_cache_event_ids |
6 | [PERF_COUNT_HW_CACHE_MAX] | 6 | [PERF_COUNT_HW_CACHE_MAX] |
7 | [PERF_COUNT_HW_CACHE_OP_MAX] | 7 | [PERF_COUNT_HW_CACHE_OP_MAX] |
8 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 8 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -111,22 +111,19 @@ static u64 amd_pmu_event_map(int hw_event) | |||
111 | return amd_perfmon_event_map[hw_event]; | 111 | return amd_perfmon_event_map[hw_event]; |
112 | } | 112 | } |
113 | 113 | ||
114 | static u64 amd_pmu_raw_event(u64 hw_event) | 114 | static int amd_pmu_hw_config(struct perf_event *event) |
115 | { | 115 | { |
116 | #define K7_EVNTSEL_EVENT_MASK 0xF000000FFULL | 116 | int ret = x86_pmu_hw_config(event); |
117 | #define K7_EVNTSEL_UNIT_MASK 0x00000FF00ULL | 117 | |
118 | #define K7_EVNTSEL_EDGE_MASK 0x000040000ULL | 118 | if (ret) |
119 | #define K7_EVNTSEL_INV_MASK 0x000800000ULL | 119 | return ret; |
120 | #define K7_EVNTSEL_REG_MASK 0x0FF000000ULL | 120 | |
121 | 121 | if (event->attr.type != PERF_TYPE_RAW) | |
122 | #define K7_EVNTSEL_MASK \ | 122 | return 0; |
123 | (K7_EVNTSEL_EVENT_MASK | \ | 123 | |
124 | K7_EVNTSEL_UNIT_MASK | \ | 124 | event->hw.config |= event->attr.config & AMD64_RAW_EVENT_MASK; |
125 | K7_EVNTSEL_EDGE_MASK | \ | 125 | |
126 | K7_EVNTSEL_INV_MASK | \ | 126 | return 0; |
127 | K7_EVNTSEL_REG_MASK) | ||
128 | |||
129 | return hw_event & K7_EVNTSEL_MASK; | ||
130 | } | 127 | } |
131 | 128 | ||
132 | /* | 129 | /* |
@@ -165,7 +162,7 @@ static void amd_put_event_constraints(struct cpu_hw_events *cpuc, | |||
165 | * be removed on one CPU at a time AND PMU is disabled | 162 | * be removed on one CPU at a time AND PMU is disabled |
166 | * when we come here | 163 | * when we come here |
167 | */ | 164 | */ |
168 | for (i = 0; i < x86_pmu.num_events; i++) { | 165 | for (i = 0; i < x86_pmu.num_counters; i++) { |
169 | if (nb->owners[i] == event) { | 166 | if (nb->owners[i] == event) { |
170 | cmpxchg(nb->owners+i, event, NULL); | 167 | cmpxchg(nb->owners+i, event, NULL); |
171 | break; | 168 | break; |
@@ -215,7 +212,7 @@ amd_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |||
215 | struct hw_perf_event *hwc = &event->hw; | 212 | struct hw_perf_event *hwc = &event->hw; |
216 | struct amd_nb *nb = cpuc->amd_nb; | 213 | struct amd_nb *nb = cpuc->amd_nb; |
217 | struct perf_event *old = NULL; | 214 | struct perf_event *old = NULL; |
218 | int max = x86_pmu.num_events; | 215 | int max = x86_pmu.num_counters; |
219 | int i, j, k = -1; | 216 | int i, j, k = -1; |
220 | 217 | ||
221 | /* | 218 | /* |
@@ -293,7 +290,7 @@ static struct amd_nb *amd_alloc_nb(int cpu, int nb_id) | |||
293 | /* | 290 | /* |
294 | * initialize all possible NB constraints | 291 | * initialize all possible NB constraints |
295 | */ | 292 | */ |
296 | for (i = 0; i < x86_pmu.num_events; i++) { | 293 | for (i = 0; i < x86_pmu.num_counters; i++) { |
297 | __set_bit(i, nb->event_constraints[i].idxmsk); | 294 | __set_bit(i, nb->event_constraints[i].idxmsk); |
298 | nb->event_constraints[i].weight = 1; | 295 | nb->event_constraints[i].weight = 1; |
299 | } | 296 | } |
@@ -371,21 +368,22 @@ static void amd_pmu_cpu_dead(int cpu) | |||
371 | raw_spin_unlock(&amd_nb_lock); | 368 | raw_spin_unlock(&amd_nb_lock); |
372 | } | 369 | } |
373 | 370 | ||
374 | static __initconst struct x86_pmu amd_pmu = { | 371 | static __initconst const struct x86_pmu amd_pmu = { |
375 | .name = "AMD", | 372 | .name = "AMD", |
376 | .handle_irq = x86_pmu_handle_irq, | 373 | .handle_irq = x86_pmu_handle_irq, |
377 | .disable_all = x86_pmu_disable_all, | 374 | .disable_all = x86_pmu_disable_all, |
378 | .enable_all = x86_pmu_enable_all, | 375 | .enable_all = x86_pmu_enable_all, |
379 | .enable = x86_pmu_enable_event, | 376 | .enable = x86_pmu_enable_event, |
380 | .disable = x86_pmu_disable_event, | 377 | .disable = x86_pmu_disable_event, |
378 | .hw_config = amd_pmu_hw_config, | ||
379 | .schedule_events = x86_schedule_events, | ||
381 | .eventsel = MSR_K7_EVNTSEL0, | 380 | .eventsel = MSR_K7_EVNTSEL0, |
382 | .perfctr = MSR_K7_PERFCTR0, | 381 | .perfctr = MSR_K7_PERFCTR0, |
383 | .event_map = amd_pmu_event_map, | 382 | .event_map = amd_pmu_event_map, |
384 | .raw_event = amd_pmu_raw_event, | ||
385 | .max_events = ARRAY_SIZE(amd_perfmon_event_map), | 383 | .max_events = ARRAY_SIZE(amd_perfmon_event_map), |
386 | .num_events = 4, | 384 | .num_counters = 4, |
387 | .event_bits = 48, | 385 | .cntval_bits = 48, |
388 | .event_mask = (1ULL << 48) - 1, | 386 | .cntval_mask = (1ULL << 48) - 1, |
389 | .apic = 1, | 387 | .apic = 1, |
390 | /* use highest bit to detect overflow */ | 388 | /* use highest bit to detect overflow */ |
391 | .max_period = (1ULL << 47) - 1, | 389 | .max_period = (1ULL << 47) - 1, |
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c index 9c794ac8783..a099df96f91 100644 --- a/arch/x86/kernel/cpu/perf_event_intel.c +++ b/arch/x86/kernel/cpu/perf_event_intel.c | |||
@@ -88,7 +88,7 @@ static u64 intel_pmu_event_map(int hw_event) | |||
88 | return intel_perfmon_event_map[hw_event]; | 88 | return intel_perfmon_event_map[hw_event]; |
89 | } | 89 | } |
90 | 90 | ||
91 | static __initconst u64 westmere_hw_cache_event_ids | 91 | static __initconst const u64 westmere_hw_cache_event_ids |
92 | [PERF_COUNT_HW_CACHE_MAX] | 92 | [PERF_COUNT_HW_CACHE_MAX] |
93 | [PERF_COUNT_HW_CACHE_OP_MAX] | 93 | [PERF_COUNT_HW_CACHE_OP_MAX] |
94 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 94 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -179,7 +179,7 @@ static __initconst u64 westmere_hw_cache_event_ids | |||
179 | }, | 179 | }, |
180 | }; | 180 | }; |
181 | 181 | ||
182 | static __initconst u64 nehalem_hw_cache_event_ids | 182 | static __initconst const u64 nehalem_hw_cache_event_ids |
183 | [PERF_COUNT_HW_CACHE_MAX] | 183 | [PERF_COUNT_HW_CACHE_MAX] |
184 | [PERF_COUNT_HW_CACHE_OP_MAX] | 184 | [PERF_COUNT_HW_CACHE_OP_MAX] |
185 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 185 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -270,7 +270,7 @@ static __initconst u64 nehalem_hw_cache_event_ids | |||
270 | }, | 270 | }, |
271 | }; | 271 | }; |
272 | 272 | ||
273 | static __initconst u64 core2_hw_cache_event_ids | 273 | static __initconst const u64 core2_hw_cache_event_ids |
274 | [PERF_COUNT_HW_CACHE_MAX] | 274 | [PERF_COUNT_HW_CACHE_MAX] |
275 | [PERF_COUNT_HW_CACHE_OP_MAX] | 275 | [PERF_COUNT_HW_CACHE_OP_MAX] |
276 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 276 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -361,7 +361,7 @@ static __initconst u64 core2_hw_cache_event_ids | |||
361 | }, | 361 | }, |
362 | }; | 362 | }; |
363 | 363 | ||
364 | static __initconst u64 atom_hw_cache_event_ids | 364 | static __initconst const u64 atom_hw_cache_event_ids |
365 | [PERF_COUNT_HW_CACHE_MAX] | 365 | [PERF_COUNT_HW_CACHE_MAX] |
366 | [PERF_COUNT_HW_CACHE_OP_MAX] | 366 | [PERF_COUNT_HW_CACHE_OP_MAX] |
367 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 367 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -452,60 +452,6 @@ static __initconst u64 atom_hw_cache_event_ids | |||
452 | }, | 452 | }, |
453 | }; | 453 | }; |
454 | 454 | ||
455 | static u64 intel_pmu_raw_event(u64 hw_event) | ||
456 | { | ||
457 | #define CORE_EVNTSEL_EVENT_MASK 0x000000FFULL | ||
458 | #define CORE_EVNTSEL_UNIT_MASK 0x0000FF00ULL | ||
459 | #define CORE_EVNTSEL_EDGE_MASK 0x00040000ULL | ||
460 | #define CORE_EVNTSEL_INV_MASK 0x00800000ULL | ||
461 | #define CORE_EVNTSEL_REG_MASK 0xFF000000ULL | ||
462 | |||
463 | #define CORE_EVNTSEL_MASK \ | ||
464 | (INTEL_ARCH_EVTSEL_MASK | \ | ||
465 | INTEL_ARCH_UNIT_MASK | \ | ||
466 | INTEL_ARCH_EDGE_MASK | \ | ||
467 | INTEL_ARCH_INV_MASK | \ | ||
468 | INTEL_ARCH_CNT_MASK) | ||
469 | |||
470 | return hw_event & CORE_EVNTSEL_MASK; | ||
471 | } | ||
472 | |||
473 | static void intel_pmu_enable_bts(u64 config) | ||
474 | { | ||
475 | unsigned long debugctlmsr; | ||
476 | |||
477 | debugctlmsr = get_debugctlmsr(); | ||
478 | |||
479 | debugctlmsr |= X86_DEBUGCTL_TR; | ||
480 | debugctlmsr |= X86_DEBUGCTL_BTS; | ||
481 | debugctlmsr |= X86_DEBUGCTL_BTINT; | ||
482 | |||
483 | if (!(config & ARCH_PERFMON_EVENTSEL_OS)) | ||
484 | debugctlmsr |= X86_DEBUGCTL_BTS_OFF_OS; | ||
485 | |||
486 | if (!(config & ARCH_PERFMON_EVENTSEL_USR)) | ||
487 | debugctlmsr |= X86_DEBUGCTL_BTS_OFF_USR; | ||
488 | |||
489 | update_debugctlmsr(debugctlmsr); | ||
490 | } | ||
491 | |||
492 | static void intel_pmu_disable_bts(void) | ||
493 | { | ||
494 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
495 | unsigned long debugctlmsr; | ||
496 | |||
497 | if (!cpuc->ds) | ||
498 | return; | ||
499 | |||
500 | debugctlmsr = get_debugctlmsr(); | ||
501 | |||
502 | debugctlmsr &= | ||
503 | ~(X86_DEBUGCTL_TR | X86_DEBUGCTL_BTS | X86_DEBUGCTL_BTINT | | ||
504 | X86_DEBUGCTL_BTS_OFF_OS | X86_DEBUGCTL_BTS_OFF_USR); | ||
505 | |||
506 | update_debugctlmsr(debugctlmsr); | ||
507 | } | ||
508 | |||
509 | static void intel_pmu_disable_all(void) | 455 | static void intel_pmu_disable_all(void) |
510 | { | 456 | { |
511 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 457 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
@@ -514,12 +460,17 @@ static void intel_pmu_disable_all(void) | |||
514 | 460 | ||
515 | if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) | 461 | if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) |
516 | intel_pmu_disable_bts(); | 462 | intel_pmu_disable_bts(); |
463 | |||
464 | intel_pmu_pebs_disable_all(); | ||
465 | intel_pmu_lbr_disable_all(); | ||
517 | } | 466 | } |
518 | 467 | ||
519 | static void intel_pmu_enable_all(void) | 468 | static void intel_pmu_enable_all(int added) |
520 | { | 469 | { |
521 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 470 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
522 | 471 | ||
472 | intel_pmu_pebs_enable_all(); | ||
473 | intel_pmu_lbr_enable_all(); | ||
523 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl); | 474 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl); |
524 | 475 | ||
525 | if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) { | 476 | if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) { |
@@ -533,6 +484,41 @@ static void intel_pmu_enable_all(void) | |||
533 | } | 484 | } |
534 | } | 485 | } |
535 | 486 | ||
487 | /* | ||
488 | * Workaround for: | ||
489 | * Intel Errata AAK100 (model 26) | ||
490 | * Intel Errata AAP53 (model 30) | ||
491 | * Intel Errata BD53 (model 44) | ||
492 | * | ||
493 | * These chips need to be 'reset' when adding counters by programming | ||
494 | * the magic three (non counting) events 0x4300D2, 0x4300B1 and 0x4300B5 | ||
495 | * either in sequence on the same PMC or on different PMCs. | ||
496 | */ | ||
497 | static void intel_pmu_nhm_enable_all(int added) | ||
498 | { | ||
499 | if (added) { | ||
500 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
501 | int i; | ||
502 | |||
503 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 0, 0x4300D2); | ||
504 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 1, 0x4300B1); | ||
505 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 2, 0x4300B5); | ||
506 | |||
507 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x3); | ||
508 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0); | ||
509 | |||
510 | for (i = 0; i < 3; i++) { | ||
511 | struct perf_event *event = cpuc->events[i]; | ||
512 | |||
513 | if (!event) | ||
514 | continue; | ||
515 | |||
516 | __x86_pmu_enable_event(&event->hw); | ||
517 | } | ||
518 | } | ||
519 | intel_pmu_enable_all(added); | ||
520 | } | ||
521 | |||
536 | static inline u64 intel_pmu_get_status(void) | 522 | static inline u64 intel_pmu_get_status(void) |
537 | { | 523 | { |
538 | u64 status; | 524 | u64 status; |
@@ -547,8 +533,7 @@ static inline void intel_pmu_ack_status(u64 ack) | |||
547 | wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack); | 533 | wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack); |
548 | } | 534 | } |
549 | 535 | ||
550 | static inline void | 536 | static void intel_pmu_disable_fixed(struct hw_perf_event *hwc) |
551 | intel_pmu_disable_fixed(struct hw_perf_event *hwc) | ||
552 | { | 537 | { |
553 | int idx = hwc->idx - X86_PMC_IDX_FIXED; | 538 | int idx = hwc->idx - X86_PMC_IDX_FIXED; |
554 | u64 ctrl_val, mask; | 539 | u64 ctrl_val, mask; |
@@ -557,71 +542,10 @@ intel_pmu_disable_fixed(struct hw_perf_event *hwc) | |||
557 | 542 | ||
558 | rdmsrl(hwc->config_base, ctrl_val); | 543 | rdmsrl(hwc->config_base, ctrl_val); |
559 | ctrl_val &= ~mask; | 544 | ctrl_val &= ~mask; |
560 | (void)checking_wrmsrl(hwc->config_base, ctrl_val); | 545 | wrmsrl(hwc->config_base, ctrl_val); |
561 | } | ||
562 | |||
563 | static void intel_pmu_drain_bts_buffer(void) | ||
564 | { | ||
565 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
566 | struct debug_store *ds = cpuc->ds; | ||
567 | struct bts_record { | ||
568 | u64 from; | ||
569 | u64 to; | ||
570 | u64 flags; | ||
571 | }; | ||
572 | struct perf_event *event = cpuc->events[X86_PMC_IDX_FIXED_BTS]; | ||
573 | struct bts_record *at, *top; | ||
574 | struct perf_output_handle handle; | ||
575 | struct perf_event_header header; | ||
576 | struct perf_sample_data data; | ||
577 | struct pt_regs regs; | ||
578 | |||
579 | if (!event) | ||
580 | return; | ||
581 | |||
582 | if (!ds) | ||
583 | return; | ||
584 | |||
585 | at = (struct bts_record *)(unsigned long)ds->bts_buffer_base; | ||
586 | top = (struct bts_record *)(unsigned long)ds->bts_index; | ||
587 | |||
588 | if (top <= at) | ||
589 | return; | ||
590 | |||
591 | ds->bts_index = ds->bts_buffer_base; | ||
592 | |||
593 | perf_sample_data_init(&data, 0); | ||
594 | |||
595 | data.period = event->hw.last_period; | ||
596 | regs.ip = 0; | ||
597 | |||
598 | /* | ||
599 | * Prepare a generic sample, i.e. fill in the invariant fields. | ||
600 | * We will overwrite the from and to address before we output | ||
601 | * the sample. | ||
602 | */ | ||
603 | perf_prepare_sample(&header, &data, event, ®s); | ||
604 | |||
605 | if (perf_output_begin(&handle, event, | ||
606 | header.size * (top - at), 1, 1)) | ||
607 | return; | ||
608 | |||
609 | for (; at < top; at++) { | ||
610 | data.ip = at->from; | ||
611 | data.addr = at->to; | ||
612 | |||
613 | perf_output_sample(&handle, &header, &data, event); | ||
614 | } | ||
615 | |||
616 | perf_output_end(&handle); | ||
617 | |||
618 | /* There's new data available. */ | ||
619 | event->hw.interrupts++; | ||
620 | event->pending_kill = POLL_IN; | ||
621 | } | 546 | } |
622 | 547 | ||
623 | static inline void | 548 | static void intel_pmu_disable_event(struct perf_event *event) |
624 | intel_pmu_disable_event(struct perf_event *event) | ||
625 | { | 549 | { |
626 | struct hw_perf_event *hwc = &event->hw; | 550 | struct hw_perf_event *hwc = &event->hw; |
627 | 551 | ||
@@ -637,14 +561,15 @@ intel_pmu_disable_event(struct perf_event *event) | |||
637 | } | 561 | } |
638 | 562 | ||
639 | x86_pmu_disable_event(event); | 563 | x86_pmu_disable_event(event); |
564 | |||
565 | if (unlikely(event->attr.precise)) | ||
566 | intel_pmu_pebs_disable(event); | ||
640 | } | 567 | } |
641 | 568 | ||
642 | static inline void | 569 | static void intel_pmu_enable_fixed(struct hw_perf_event *hwc) |
643 | intel_pmu_enable_fixed(struct hw_perf_event *hwc) | ||
644 | { | 570 | { |
645 | int idx = hwc->idx - X86_PMC_IDX_FIXED; | 571 | int idx = hwc->idx - X86_PMC_IDX_FIXED; |
646 | u64 ctrl_val, bits, mask; | 572 | u64 ctrl_val, bits, mask; |
647 | int err; | ||
648 | 573 | ||
649 | /* | 574 | /* |
650 | * Enable IRQ generation (0x8), | 575 | * Enable IRQ generation (0x8), |
@@ -669,7 +594,7 @@ intel_pmu_enable_fixed(struct hw_perf_event *hwc) | |||
669 | rdmsrl(hwc->config_base, ctrl_val); | 594 | rdmsrl(hwc->config_base, ctrl_val); |
670 | ctrl_val &= ~mask; | 595 | ctrl_val &= ~mask; |
671 | ctrl_val |= bits; | 596 | ctrl_val |= bits; |
672 | err = checking_wrmsrl(hwc->config_base, ctrl_val); | 597 | wrmsrl(hwc->config_base, ctrl_val); |
673 | } | 598 | } |
674 | 599 | ||
675 | static void intel_pmu_enable_event(struct perf_event *event) | 600 | static void intel_pmu_enable_event(struct perf_event *event) |
@@ -689,6 +614,9 @@ static void intel_pmu_enable_event(struct perf_event *event) | |||
689 | return; | 614 | return; |
690 | } | 615 | } |
691 | 616 | ||
617 | if (unlikely(event->attr.precise)) | ||
618 | intel_pmu_pebs_enable(event); | ||
619 | |||
692 | __x86_pmu_enable_event(hwc); | 620 | __x86_pmu_enable_event(hwc); |
693 | } | 621 | } |
694 | 622 | ||
@@ -708,20 +636,20 @@ static void intel_pmu_reset(void) | |||
708 | unsigned long flags; | 636 | unsigned long flags; |
709 | int idx; | 637 | int idx; |
710 | 638 | ||
711 | if (!x86_pmu.num_events) | 639 | if (!x86_pmu.num_counters) |
712 | return; | 640 | return; |
713 | 641 | ||
714 | local_irq_save(flags); | 642 | local_irq_save(flags); |
715 | 643 | ||
716 | printk("clearing PMU state on CPU#%d\n", smp_processor_id()); | 644 | printk("clearing PMU state on CPU#%d\n", smp_processor_id()); |
717 | 645 | ||
718 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 646 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
719 | checking_wrmsrl(x86_pmu.eventsel + idx, 0ull); | 647 | checking_wrmsrl(x86_pmu.eventsel + idx, 0ull); |
720 | checking_wrmsrl(x86_pmu.perfctr + idx, 0ull); | 648 | checking_wrmsrl(x86_pmu.perfctr + idx, 0ull); |
721 | } | 649 | } |
722 | for (idx = 0; idx < x86_pmu.num_events_fixed; idx++) { | 650 | for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) |
723 | checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull); | 651 | checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull); |
724 | } | 652 | |
725 | if (ds) | 653 | if (ds) |
726 | ds->bts_index = ds->bts_buffer_base; | 654 | ds->bts_index = ds->bts_buffer_base; |
727 | 655 | ||
@@ -747,7 +675,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) | |||
747 | intel_pmu_drain_bts_buffer(); | 675 | intel_pmu_drain_bts_buffer(); |
748 | status = intel_pmu_get_status(); | 676 | status = intel_pmu_get_status(); |
749 | if (!status) { | 677 | if (!status) { |
750 | intel_pmu_enable_all(); | 678 | intel_pmu_enable_all(0); |
751 | return 0; | 679 | return 0; |
752 | } | 680 | } |
753 | 681 | ||
@@ -762,6 +690,15 @@ again: | |||
762 | 690 | ||
763 | inc_irq_stat(apic_perf_irqs); | 691 | inc_irq_stat(apic_perf_irqs); |
764 | ack = status; | 692 | ack = status; |
693 | |||
694 | intel_pmu_lbr_read(); | ||
695 | |||
696 | /* | ||
697 | * PEBS overflow sets bit 62 in the global status register | ||
698 | */ | ||
699 | if (__test_and_clear_bit(62, (unsigned long *)&status)) | ||
700 | x86_pmu.drain_pebs(regs); | ||
701 | |||
765 | for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) { | 702 | for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) { |
766 | struct perf_event *event = cpuc->events[bit]; | 703 | struct perf_event *event = cpuc->events[bit]; |
767 | 704 | ||
@@ -787,26 +724,22 @@ again: | |||
787 | goto again; | 724 | goto again; |
788 | 725 | ||
789 | done: | 726 | done: |
790 | intel_pmu_enable_all(); | 727 | intel_pmu_enable_all(0); |
791 | return 1; | 728 | return 1; |
792 | } | 729 | } |
793 | 730 | ||
794 | static struct event_constraint bts_constraint = | ||
795 | EVENT_CONSTRAINT(0, 1ULL << X86_PMC_IDX_FIXED_BTS, 0); | ||
796 | |||
797 | static struct event_constraint * | 731 | static struct event_constraint * |
798 | intel_special_constraints(struct perf_event *event) | 732 | intel_bts_constraints(struct perf_event *event) |
799 | { | 733 | { |
800 | unsigned int hw_event; | 734 | struct hw_perf_event *hwc = &event->hw; |
801 | 735 | unsigned int hw_event, bts_event; | |
802 | hw_event = event->hw.config & INTEL_ARCH_EVENT_MASK; | ||
803 | 736 | ||
804 | if (unlikely((hw_event == | 737 | hw_event = hwc->config & INTEL_ARCH_EVENT_MASK; |
805 | x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS)) && | 738 | bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS); |
806 | (event->hw.sample_period == 1))) { | ||
807 | 739 | ||
740 | if (unlikely(hw_event == bts_event && hwc->sample_period == 1)) | ||
808 | return &bts_constraint; | 741 | return &bts_constraint; |
809 | } | 742 | |
810 | return NULL; | 743 | return NULL; |
811 | } | 744 | } |
812 | 745 | ||
@@ -815,24 +748,53 @@ intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event | |||
815 | { | 748 | { |
816 | struct event_constraint *c; | 749 | struct event_constraint *c; |
817 | 750 | ||
818 | c = intel_special_constraints(event); | 751 | c = intel_bts_constraints(event); |
752 | if (c) | ||
753 | return c; | ||
754 | |||
755 | c = intel_pebs_constraints(event); | ||
819 | if (c) | 756 | if (c) |
820 | return c; | 757 | return c; |
821 | 758 | ||
822 | return x86_get_event_constraints(cpuc, event); | 759 | return x86_get_event_constraints(cpuc, event); |
823 | } | 760 | } |
824 | 761 | ||
825 | static __initconst struct x86_pmu core_pmu = { | 762 | static int intel_pmu_hw_config(struct perf_event *event) |
763 | { | ||
764 | int ret = x86_pmu_hw_config(event); | ||
765 | |||
766 | if (ret) | ||
767 | return ret; | ||
768 | |||
769 | if (event->attr.type != PERF_TYPE_RAW) | ||
770 | return 0; | ||
771 | |||
772 | if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY)) | ||
773 | return 0; | ||
774 | |||
775 | if (x86_pmu.version < 3) | ||
776 | return -EINVAL; | ||
777 | |||
778 | if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) | ||
779 | return -EACCES; | ||
780 | |||
781 | event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY; | ||
782 | |||
783 | return 0; | ||
784 | } | ||
785 | |||
786 | static __initconst const struct x86_pmu core_pmu = { | ||
826 | .name = "core", | 787 | .name = "core", |
827 | .handle_irq = x86_pmu_handle_irq, | 788 | .handle_irq = x86_pmu_handle_irq, |
828 | .disable_all = x86_pmu_disable_all, | 789 | .disable_all = x86_pmu_disable_all, |
829 | .enable_all = x86_pmu_enable_all, | 790 | .enable_all = x86_pmu_enable_all, |
830 | .enable = x86_pmu_enable_event, | 791 | .enable = x86_pmu_enable_event, |
831 | .disable = x86_pmu_disable_event, | 792 | .disable = x86_pmu_disable_event, |
793 | .hw_config = x86_pmu_hw_config, | ||
794 | .schedule_events = x86_schedule_events, | ||
832 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, | 795 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, |
833 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, | 796 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, |
834 | .event_map = intel_pmu_event_map, | 797 | .event_map = intel_pmu_event_map, |
835 | .raw_event = intel_pmu_raw_event, | ||
836 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), | 798 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), |
837 | .apic = 1, | 799 | .apic = 1, |
838 | /* | 800 | /* |
@@ -845,17 +807,32 @@ static __initconst struct x86_pmu core_pmu = { | |||
845 | .event_constraints = intel_core_event_constraints, | 807 | .event_constraints = intel_core_event_constraints, |
846 | }; | 808 | }; |
847 | 809 | ||
848 | static __initconst struct x86_pmu intel_pmu = { | 810 | static void intel_pmu_cpu_starting(int cpu) |
811 | { | ||
812 | init_debug_store_on_cpu(cpu); | ||
813 | /* | ||
814 | * Deal with CPUs that don't clear their LBRs on power-up. | ||
815 | */ | ||
816 | intel_pmu_lbr_reset(); | ||
817 | } | ||
818 | |||
819 | static void intel_pmu_cpu_dying(int cpu) | ||
820 | { | ||
821 | fini_debug_store_on_cpu(cpu); | ||
822 | } | ||
823 | |||
824 | static __initconst const struct x86_pmu intel_pmu = { | ||
849 | .name = "Intel", | 825 | .name = "Intel", |
850 | .handle_irq = intel_pmu_handle_irq, | 826 | .handle_irq = intel_pmu_handle_irq, |
851 | .disable_all = intel_pmu_disable_all, | 827 | .disable_all = intel_pmu_disable_all, |
852 | .enable_all = intel_pmu_enable_all, | 828 | .enable_all = intel_pmu_enable_all, |
853 | .enable = intel_pmu_enable_event, | 829 | .enable = intel_pmu_enable_event, |
854 | .disable = intel_pmu_disable_event, | 830 | .disable = intel_pmu_disable_event, |
831 | .hw_config = intel_pmu_hw_config, | ||
832 | .schedule_events = x86_schedule_events, | ||
855 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, | 833 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, |
856 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, | 834 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, |
857 | .event_map = intel_pmu_event_map, | 835 | .event_map = intel_pmu_event_map, |
858 | .raw_event = intel_pmu_raw_event, | ||
859 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), | 836 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), |
860 | .apic = 1, | 837 | .apic = 1, |
861 | /* | 838 | /* |
@@ -864,14 +841,38 @@ static __initconst struct x86_pmu intel_pmu = { | |||
864 | * the generic event period: | 841 | * the generic event period: |
865 | */ | 842 | */ |
866 | .max_period = (1ULL << 31) - 1, | 843 | .max_period = (1ULL << 31) - 1, |
867 | .enable_bts = intel_pmu_enable_bts, | ||
868 | .disable_bts = intel_pmu_disable_bts, | ||
869 | .get_event_constraints = intel_get_event_constraints, | 844 | .get_event_constraints = intel_get_event_constraints, |
870 | 845 | ||
871 | .cpu_starting = init_debug_store_on_cpu, | 846 | .cpu_starting = intel_pmu_cpu_starting, |
872 | .cpu_dying = fini_debug_store_on_cpu, | 847 | .cpu_dying = intel_pmu_cpu_dying, |
873 | }; | 848 | }; |
874 | 849 | ||
850 | static void intel_clovertown_quirks(void) | ||
851 | { | ||
852 | /* | ||
853 | * PEBS is unreliable due to: | ||
854 | * | ||
855 | * AJ67 - PEBS may experience CPL leaks | ||
856 | * AJ68 - PEBS PMI may be delayed by one event | ||
857 | * AJ69 - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12] | ||
858 | * AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS | ||
859 | * | ||
860 | * AJ67 could be worked around by restricting the OS/USR flags. | ||
861 | * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI. | ||
862 | * | ||
863 | * AJ106 could possibly be worked around by not allowing LBR | ||
864 | * usage from PEBS, including the fixup. | ||
865 | * AJ68 could possibly be worked around by always programming | ||
866 | * a pebs_event_reset[0] value and coping with the lost events. | ||
867 | * | ||
868 | * But taken together it might just make sense to not enable PEBS on | ||
869 | * these chips. | ||
870 | */ | ||
871 | printk(KERN_WARNING "PEBS disabled due to CPU errata.\n"); | ||
872 | x86_pmu.pebs = 0; | ||
873 | x86_pmu.pebs_constraints = NULL; | ||
874 | } | ||
875 | |||
875 | static __init int intel_pmu_init(void) | 876 | static __init int intel_pmu_init(void) |
876 | { | 877 | { |
877 | union cpuid10_edx edx; | 878 | union cpuid10_edx edx; |
@@ -881,12 +882,13 @@ static __init int intel_pmu_init(void) | |||
881 | int version; | 882 | int version; |
882 | 883 | ||
883 | if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { | 884 | if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { |
884 | /* check for P6 processor family */ | 885 | switch (boot_cpu_data.x86) { |
885 | if (boot_cpu_data.x86 == 6) { | 886 | case 0x6: |
886 | return p6_pmu_init(); | 887 | return p6_pmu_init(); |
887 | } else { | 888 | case 0xf: |
889 | return p4_pmu_init(); | ||
890 | } | ||
888 | return -ENODEV; | 891 | return -ENODEV; |
889 | } | ||
890 | } | 892 | } |
891 | 893 | ||
892 | /* | 894 | /* |
@@ -904,16 +906,28 @@ static __init int intel_pmu_init(void) | |||
904 | x86_pmu = intel_pmu; | 906 | x86_pmu = intel_pmu; |
905 | 907 | ||
906 | x86_pmu.version = version; | 908 | x86_pmu.version = version; |
907 | x86_pmu.num_events = eax.split.num_events; | 909 | x86_pmu.num_counters = eax.split.num_counters; |
908 | x86_pmu.event_bits = eax.split.bit_width; | 910 | x86_pmu.cntval_bits = eax.split.bit_width; |
909 | x86_pmu.event_mask = (1ULL << eax.split.bit_width) - 1; | 911 | x86_pmu.cntval_mask = (1ULL << eax.split.bit_width) - 1; |
910 | 912 | ||
911 | /* | 913 | /* |
912 | * Quirk: v2 perfmon does not report fixed-purpose events, so | 914 | * Quirk: v2 perfmon does not report fixed-purpose events, so |
913 | * assume at least 3 events: | 915 | * assume at least 3 events: |
914 | */ | 916 | */ |
915 | if (version > 1) | 917 | if (version > 1) |
916 | x86_pmu.num_events_fixed = max((int)edx.split.num_events_fixed, 3); | 918 | x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3); |
919 | |||
920 | /* | ||
921 | * v2 and above have a perf capabilities MSR | ||
922 | */ | ||
923 | if (version > 1) { | ||
924 | u64 capabilities; | ||
925 | |||
926 | rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities); | ||
927 | x86_pmu.intel_cap.capabilities = capabilities; | ||
928 | } | ||
929 | |||
930 | intel_ds_init(); | ||
917 | 931 | ||
918 | /* | 932 | /* |
919 | * Install the hw-cache-events table: | 933 | * Install the hw-cache-events table: |
@@ -924,12 +938,15 @@ static __init int intel_pmu_init(void) | |||
924 | break; | 938 | break; |
925 | 939 | ||
926 | case 15: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */ | 940 | case 15: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */ |
941 | x86_pmu.quirks = intel_clovertown_quirks; | ||
927 | case 22: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */ | 942 | case 22: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */ |
928 | case 23: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */ | 943 | case 23: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */ |
929 | case 29: /* six-core 45 nm xeon "Dunnington" */ | 944 | case 29: /* six-core 45 nm xeon "Dunnington" */ |
930 | memcpy(hw_cache_event_ids, core2_hw_cache_event_ids, | 945 | memcpy(hw_cache_event_ids, core2_hw_cache_event_ids, |
931 | sizeof(hw_cache_event_ids)); | 946 | sizeof(hw_cache_event_ids)); |
932 | 947 | ||
948 | intel_pmu_lbr_init_core(); | ||
949 | |||
933 | x86_pmu.event_constraints = intel_core2_event_constraints; | 950 | x86_pmu.event_constraints = intel_core2_event_constraints; |
934 | pr_cont("Core2 events, "); | 951 | pr_cont("Core2 events, "); |
935 | break; | 952 | break; |
@@ -940,13 +957,19 @@ static __init int intel_pmu_init(void) | |||
940 | memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids, | 957 | memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids, |
941 | sizeof(hw_cache_event_ids)); | 958 | sizeof(hw_cache_event_ids)); |
942 | 959 | ||
960 | intel_pmu_lbr_init_nhm(); | ||
961 | |||
943 | x86_pmu.event_constraints = intel_nehalem_event_constraints; | 962 | x86_pmu.event_constraints = intel_nehalem_event_constraints; |
944 | pr_cont("Nehalem/Corei7 events, "); | 963 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; |
964 | pr_cont("Nehalem events, "); | ||
945 | break; | 965 | break; |
966 | |||
946 | case 28: /* Atom */ | 967 | case 28: /* Atom */ |
947 | memcpy(hw_cache_event_ids, atom_hw_cache_event_ids, | 968 | memcpy(hw_cache_event_ids, atom_hw_cache_event_ids, |
948 | sizeof(hw_cache_event_ids)); | 969 | sizeof(hw_cache_event_ids)); |
949 | 970 | ||
971 | intel_pmu_lbr_init_atom(); | ||
972 | |||
950 | x86_pmu.event_constraints = intel_gen_event_constraints; | 973 | x86_pmu.event_constraints = intel_gen_event_constraints; |
951 | pr_cont("Atom events, "); | 974 | pr_cont("Atom events, "); |
952 | break; | 975 | break; |
@@ -956,7 +979,10 @@ static __init int intel_pmu_init(void) | |||
956 | memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids, | 979 | memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids, |
957 | sizeof(hw_cache_event_ids)); | 980 | sizeof(hw_cache_event_ids)); |
958 | 981 | ||
982 | intel_pmu_lbr_init_nhm(); | ||
983 | |||
959 | x86_pmu.event_constraints = intel_westmere_event_constraints; | 984 | x86_pmu.event_constraints = intel_westmere_event_constraints; |
985 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; | ||
960 | pr_cont("Westmere events, "); | 986 | pr_cont("Westmere events, "); |
961 | break; | 987 | break; |
962 | 988 | ||
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c new file mode 100644 index 00000000000..ec8b2e12e10 --- /dev/null +++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c | |||
@@ -0,0 +1,664 @@ | |||
1 | #ifdef CONFIG_CPU_SUP_INTEL | ||
2 | |||
3 | /* The maximal number of PEBS events: */ | ||
4 | #define MAX_PEBS_EVENTS 4 | ||
5 | |||
6 | /* The size of a BTS record in bytes: */ | ||
7 | #define BTS_RECORD_SIZE 24 | ||
8 | |||
9 | #define BTS_BUFFER_SIZE (PAGE_SIZE << 4) | ||
10 | #define PEBS_BUFFER_SIZE PAGE_SIZE | ||
11 | |||
12 | /* | ||
13 | * pebs_record_32 for p4 and core not supported | ||
14 | |||
15 | struct pebs_record_32 { | ||
16 | u32 flags, ip; | ||
17 | u32 ax, bc, cx, dx; | ||
18 | u32 si, di, bp, sp; | ||
19 | }; | ||
20 | |||
21 | */ | ||
22 | |||
23 | struct pebs_record_core { | ||
24 | u64 flags, ip; | ||
25 | u64 ax, bx, cx, dx; | ||
26 | u64 si, di, bp, sp; | ||
27 | u64 r8, r9, r10, r11; | ||
28 | u64 r12, r13, r14, r15; | ||
29 | }; | ||
30 | |||
31 | struct pebs_record_nhm { | ||
32 | u64 flags, ip; | ||
33 | u64 ax, bx, cx, dx; | ||
34 | u64 si, di, bp, sp; | ||
35 | u64 r8, r9, r10, r11; | ||
36 | u64 r12, r13, r14, r15; | ||
37 | u64 status, dla, dse, lat; | ||
38 | }; | ||
39 | |||
40 | /* | ||
41 | * A debug store configuration. | ||
42 | * | ||
43 | * We only support architectures that use 64bit fields. | ||
44 | */ | ||
45 | struct debug_store { | ||
46 | u64 bts_buffer_base; | ||
47 | u64 bts_index; | ||
48 | u64 bts_absolute_maximum; | ||
49 | u64 bts_interrupt_threshold; | ||
50 | u64 pebs_buffer_base; | ||
51 | u64 pebs_index; | ||
52 | u64 pebs_absolute_maximum; | ||
53 | u64 pebs_interrupt_threshold; | ||
54 | u64 pebs_event_reset[MAX_PEBS_EVENTS]; | ||
55 | }; | ||
56 | |||
57 | static void init_debug_store_on_cpu(int cpu) | ||
58 | { | ||
59 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
60 | |||
61 | if (!ds) | ||
62 | return; | ||
63 | |||
64 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, | ||
65 | (u32)((u64)(unsigned long)ds), | ||
66 | (u32)((u64)(unsigned long)ds >> 32)); | ||
67 | } | ||
68 | |||
69 | static void fini_debug_store_on_cpu(int cpu) | ||
70 | { | ||
71 | if (!per_cpu(cpu_hw_events, cpu).ds) | ||
72 | return; | ||
73 | |||
74 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0); | ||
75 | } | ||
76 | |||
77 | static void release_ds_buffers(void) | ||
78 | { | ||
79 | int cpu; | ||
80 | |||
81 | if (!x86_pmu.bts && !x86_pmu.pebs) | ||
82 | return; | ||
83 | |||
84 | get_online_cpus(); | ||
85 | |||
86 | for_each_online_cpu(cpu) | ||
87 | fini_debug_store_on_cpu(cpu); | ||
88 | |||
89 | for_each_possible_cpu(cpu) { | ||
90 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
91 | |||
92 | if (!ds) | ||
93 | continue; | ||
94 | |||
95 | per_cpu(cpu_hw_events, cpu).ds = NULL; | ||
96 | |||
97 | kfree((void *)(unsigned long)ds->pebs_buffer_base); | ||
98 | kfree((void *)(unsigned long)ds->bts_buffer_base); | ||
99 | kfree(ds); | ||
100 | } | ||
101 | |||
102 | put_online_cpus(); | ||
103 | } | ||
104 | |||
105 | static int reserve_ds_buffers(void) | ||
106 | { | ||
107 | int cpu, err = 0; | ||
108 | |||
109 | if (!x86_pmu.bts && !x86_pmu.pebs) | ||
110 | return 0; | ||
111 | |||
112 | get_online_cpus(); | ||
113 | |||
114 | for_each_possible_cpu(cpu) { | ||
115 | struct debug_store *ds; | ||
116 | void *buffer; | ||
117 | int max, thresh; | ||
118 | |||
119 | err = -ENOMEM; | ||
120 | ds = kzalloc(sizeof(*ds), GFP_KERNEL); | ||
121 | if (unlikely(!ds)) | ||
122 | break; | ||
123 | per_cpu(cpu_hw_events, cpu).ds = ds; | ||
124 | |||
125 | if (x86_pmu.bts) { | ||
126 | buffer = kzalloc(BTS_BUFFER_SIZE, GFP_KERNEL); | ||
127 | if (unlikely(!buffer)) | ||
128 | break; | ||
129 | |||
130 | max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE; | ||
131 | thresh = max / 16; | ||
132 | |||
133 | ds->bts_buffer_base = (u64)(unsigned long)buffer; | ||
134 | ds->bts_index = ds->bts_buffer_base; | ||
135 | ds->bts_absolute_maximum = ds->bts_buffer_base + | ||
136 | max * BTS_RECORD_SIZE; | ||
137 | ds->bts_interrupt_threshold = ds->bts_absolute_maximum - | ||
138 | thresh * BTS_RECORD_SIZE; | ||
139 | } | ||
140 | |||
141 | if (x86_pmu.pebs) { | ||
142 | buffer = kzalloc(PEBS_BUFFER_SIZE, GFP_KERNEL); | ||
143 | if (unlikely(!buffer)) | ||
144 | break; | ||
145 | |||
146 | max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size; | ||
147 | |||
148 | ds->pebs_buffer_base = (u64)(unsigned long)buffer; | ||
149 | ds->pebs_index = ds->pebs_buffer_base; | ||
150 | ds->pebs_absolute_maximum = ds->pebs_buffer_base + | ||
151 | max * x86_pmu.pebs_record_size; | ||
152 | /* | ||
153 | * Always use single record PEBS | ||
154 | */ | ||
155 | ds->pebs_interrupt_threshold = ds->pebs_buffer_base + | ||
156 | x86_pmu.pebs_record_size; | ||
157 | } | ||
158 | |||
159 | err = 0; | ||
160 | } | ||
161 | |||
162 | if (err) | ||
163 | release_ds_buffers(); | ||
164 | else { | ||
165 | for_each_online_cpu(cpu) | ||
166 | init_debug_store_on_cpu(cpu); | ||
167 | } | ||
168 | |||
169 | put_online_cpus(); | ||
170 | |||
171 | return err; | ||
172 | } | ||
173 | |||
174 | /* | ||
175 | * BTS | ||
176 | */ | ||
177 | |||
178 | static struct event_constraint bts_constraint = | ||
179 | EVENT_CONSTRAINT(0, 1ULL << X86_PMC_IDX_FIXED_BTS, 0); | ||
180 | |||
181 | static void intel_pmu_enable_bts(u64 config) | ||
182 | { | ||
183 | unsigned long debugctlmsr; | ||
184 | |||
185 | debugctlmsr = get_debugctlmsr(); | ||
186 | |||
187 | debugctlmsr |= DEBUGCTLMSR_TR; | ||
188 | debugctlmsr |= DEBUGCTLMSR_BTS; | ||
189 | debugctlmsr |= DEBUGCTLMSR_BTINT; | ||
190 | |||
191 | if (!(config & ARCH_PERFMON_EVENTSEL_OS)) | ||
192 | debugctlmsr |= DEBUGCTLMSR_BTS_OFF_OS; | ||
193 | |||
194 | if (!(config & ARCH_PERFMON_EVENTSEL_USR)) | ||
195 | debugctlmsr |= DEBUGCTLMSR_BTS_OFF_USR; | ||
196 | |||
197 | update_debugctlmsr(debugctlmsr); | ||
198 | } | ||
199 | |||
200 | static void intel_pmu_disable_bts(void) | ||
201 | { | ||
202 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
203 | unsigned long debugctlmsr; | ||
204 | |||
205 | if (!cpuc->ds) | ||
206 | return; | ||
207 | |||
208 | debugctlmsr = get_debugctlmsr(); | ||
209 | |||
210 | debugctlmsr &= | ||
211 | ~(DEBUGCTLMSR_TR | DEBUGCTLMSR_BTS | DEBUGCTLMSR_BTINT | | ||
212 | DEBUGCTLMSR_BTS_OFF_OS | DEBUGCTLMSR_BTS_OFF_USR); | ||
213 | |||
214 | update_debugctlmsr(debugctlmsr); | ||
215 | } | ||
216 | |||
217 | static void intel_pmu_drain_bts_buffer(void) | ||
218 | { | ||
219 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
220 | struct debug_store *ds = cpuc->ds; | ||
221 | struct bts_record { | ||
222 | u64 from; | ||
223 | u64 to; | ||
224 | u64 flags; | ||
225 | }; | ||
226 | struct perf_event *event = cpuc->events[X86_PMC_IDX_FIXED_BTS]; | ||
227 | struct bts_record *at, *top; | ||
228 | struct perf_output_handle handle; | ||
229 | struct perf_event_header header; | ||
230 | struct perf_sample_data data; | ||
231 | struct pt_regs regs; | ||
232 | |||
233 | if (!event) | ||
234 | return; | ||
235 | |||
236 | if (!ds) | ||
237 | return; | ||
238 | |||
239 | at = (struct bts_record *)(unsigned long)ds->bts_buffer_base; | ||
240 | top = (struct bts_record *)(unsigned long)ds->bts_index; | ||
241 | |||
242 | if (top <= at) | ||
243 | return; | ||
244 | |||
245 | ds->bts_index = ds->bts_buffer_base; | ||
246 | |||
247 | perf_sample_data_init(&data, 0); | ||
248 | data.period = event->hw.last_period; | ||
249 | regs.ip = 0; | ||
250 | |||
251 | /* | ||
252 | * Prepare a generic sample, i.e. fill in the invariant fields. | ||
253 | * We will overwrite the from and to address before we output | ||
254 | * the sample. | ||
255 | */ | ||
256 | perf_prepare_sample(&header, &data, event, ®s); | ||
257 | |||
258 | if (perf_output_begin(&handle, event, header.size * (top - at), 1, 1)) | ||
259 | return; | ||
260 | |||
261 | for (; at < top; at++) { | ||
262 | data.ip = at->from; | ||
263 | data.addr = at->to; | ||
264 | |||
265 | perf_output_sample(&handle, &header, &data, event); | ||
266 | } | ||
267 | |||
268 | perf_output_end(&handle); | ||
269 | |||
270 | /* There's new data available. */ | ||
271 | event->hw.interrupts++; | ||
272 | event->pending_kill = POLL_IN; | ||
273 | } | ||
274 | |||
275 | /* | ||
276 | * PEBS | ||
277 | */ | ||
278 | |||
279 | static struct event_constraint intel_core_pebs_events[] = { | ||
280 | PEBS_EVENT_CONSTRAINT(0x00c0, 0x1), /* INSTR_RETIRED.ANY */ | ||
281 | PEBS_EVENT_CONSTRAINT(0xfec1, 0x1), /* X87_OPS_RETIRED.ANY */ | ||
282 | PEBS_EVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */ | ||
283 | PEBS_EVENT_CONSTRAINT(0x1fc7, 0x1), /* SIMD_INST_RETURED.ANY */ | ||
284 | PEBS_EVENT_CONSTRAINT(0x01cb, 0x1), /* MEM_LOAD_RETIRED.L1D_MISS */ | ||
285 | PEBS_EVENT_CONSTRAINT(0x02cb, 0x1), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */ | ||
286 | PEBS_EVENT_CONSTRAINT(0x04cb, 0x1), /* MEM_LOAD_RETIRED.L2_MISS */ | ||
287 | PEBS_EVENT_CONSTRAINT(0x08cb, 0x1), /* MEM_LOAD_RETIRED.L2_LINE_MISS */ | ||
288 | PEBS_EVENT_CONSTRAINT(0x10cb, 0x1), /* MEM_LOAD_RETIRED.DTLB_MISS */ | ||
289 | EVENT_CONSTRAINT_END | ||
290 | }; | ||
291 | |||
292 | static struct event_constraint intel_nehalem_pebs_events[] = { | ||
293 | PEBS_EVENT_CONSTRAINT(0x00c0, 0xf), /* INSTR_RETIRED.ANY */ | ||
294 | PEBS_EVENT_CONSTRAINT(0xfec1, 0xf), /* X87_OPS_RETIRED.ANY */ | ||
295 | PEBS_EVENT_CONSTRAINT(0x00c5, 0xf), /* BR_INST_RETIRED.MISPRED */ | ||
296 | PEBS_EVENT_CONSTRAINT(0x1fc7, 0xf), /* SIMD_INST_RETURED.ANY */ | ||
297 | PEBS_EVENT_CONSTRAINT(0x01cb, 0xf), /* MEM_LOAD_RETIRED.L1D_MISS */ | ||
298 | PEBS_EVENT_CONSTRAINT(0x02cb, 0xf), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */ | ||
299 | PEBS_EVENT_CONSTRAINT(0x04cb, 0xf), /* MEM_LOAD_RETIRED.L2_MISS */ | ||
300 | PEBS_EVENT_CONSTRAINT(0x08cb, 0xf), /* MEM_LOAD_RETIRED.L2_LINE_MISS */ | ||
301 | PEBS_EVENT_CONSTRAINT(0x10cb, 0xf), /* MEM_LOAD_RETIRED.DTLB_MISS */ | ||
302 | EVENT_CONSTRAINT_END | ||
303 | }; | ||
304 | |||
305 | static struct event_constraint * | ||
306 | intel_pebs_constraints(struct perf_event *event) | ||
307 | { | ||
308 | struct event_constraint *c; | ||
309 | |||
310 | if (!event->attr.precise) | ||
311 | return NULL; | ||
312 | |||
313 | if (x86_pmu.pebs_constraints) { | ||
314 | for_each_event_constraint(c, x86_pmu.pebs_constraints) { | ||
315 | if ((event->hw.config & c->cmask) == c->code) | ||
316 | return c; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return &emptyconstraint; | ||
321 | } | ||
322 | |||
323 | static void intel_pmu_pebs_enable(struct perf_event *event) | ||
324 | { | ||
325 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
326 | struct hw_perf_event *hwc = &event->hw; | ||
327 | |||
328 | hwc->config &= ~ARCH_PERFMON_EVENTSEL_INT; | ||
329 | |||
330 | cpuc->pebs_enabled |= 1ULL << hwc->idx; | ||
331 | WARN_ON_ONCE(cpuc->enabled); | ||
332 | |||
333 | if (x86_pmu.intel_cap.pebs_trap) | ||
334 | intel_pmu_lbr_enable(event); | ||
335 | } | ||
336 | |||
337 | static void intel_pmu_pebs_disable(struct perf_event *event) | ||
338 | { | ||
339 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
340 | struct hw_perf_event *hwc = &event->hw; | ||
341 | |||
342 | cpuc->pebs_enabled &= ~(1ULL << hwc->idx); | ||
343 | if (cpuc->enabled) | ||
344 | wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled); | ||
345 | |||
346 | hwc->config |= ARCH_PERFMON_EVENTSEL_INT; | ||
347 | |||
348 | if (x86_pmu.intel_cap.pebs_trap) | ||
349 | intel_pmu_lbr_disable(event); | ||
350 | } | ||
351 | |||
352 | static void intel_pmu_pebs_enable_all(void) | ||
353 | { | ||
354 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
355 | |||
356 | if (cpuc->pebs_enabled) | ||
357 | wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled); | ||
358 | } | ||
359 | |||
360 | static void intel_pmu_pebs_disable_all(void) | ||
361 | { | ||
362 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
363 | |||
364 | if (cpuc->pebs_enabled) | ||
365 | wrmsrl(MSR_IA32_PEBS_ENABLE, 0); | ||
366 | } | ||
367 | |||
368 | #include <asm/insn.h> | ||
369 | |||
370 | static inline bool kernel_ip(unsigned long ip) | ||
371 | { | ||
372 | #ifdef CONFIG_X86_32 | ||
373 | return ip > PAGE_OFFSET; | ||
374 | #else | ||
375 | return (long)ip < 0; | ||
376 | #endif | ||
377 | } | ||
378 | |||
379 | static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs) | ||
380 | { | ||
381 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
382 | unsigned long from = cpuc->lbr_entries[0].from; | ||
383 | unsigned long old_to, to = cpuc->lbr_entries[0].to; | ||
384 | unsigned long ip = regs->ip; | ||
385 | |||
386 | /* | ||
387 | * We don't need to fixup if the PEBS assist is fault like | ||
388 | */ | ||
389 | if (!x86_pmu.intel_cap.pebs_trap) | ||
390 | return 1; | ||
391 | |||
392 | /* | ||
393 | * No LBR entry, no basic block, no rewinding | ||
394 | */ | ||
395 | if (!cpuc->lbr_stack.nr || !from || !to) | ||
396 | return 0; | ||
397 | |||
398 | /* | ||
399 | * Basic blocks should never cross user/kernel boundaries | ||
400 | */ | ||
401 | if (kernel_ip(ip) != kernel_ip(to)) | ||
402 | return 0; | ||
403 | |||
404 | /* | ||
405 | * unsigned math, either ip is before the start (impossible) or | ||
406 | * the basic block is larger than 1 page (sanity) | ||
407 | */ | ||
408 | if ((ip - to) > PAGE_SIZE) | ||
409 | return 0; | ||
410 | |||
411 | /* | ||
412 | * We sampled a branch insn, rewind using the LBR stack | ||
413 | */ | ||
414 | if (ip == to) { | ||
415 | regs->ip = from; | ||
416 | return 1; | ||
417 | } | ||
418 | |||
419 | do { | ||
420 | struct insn insn; | ||
421 | u8 buf[MAX_INSN_SIZE]; | ||
422 | void *kaddr; | ||
423 | |||
424 | old_to = to; | ||
425 | if (!kernel_ip(ip)) { | ||
426 | int bytes, size = MAX_INSN_SIZE; | ||
427 | |||
428 | bytes = copy_from_user_nmi(buf, (void __user *)to, size); | ||
429 | if (bytes != size) | ||
430 | return 0; | ||
431 | |||
432 | kaddr = buf; | ||
433 | } else | ||
434 | kaddr = (void *)to; | ||
435 | |||
436 | kernel_insn_init(&insn, kaddr); | ||
437 | insn_get_length(&insn); | ||
438 | to += insn.length; | ||
439 | } while (to < ip); | ||
440 | |||
441 | if (to == ip) { | ||
442 | regs->ip = old_to; | ||
443 | return 1; | ||
444 | } | ||
445 | |||
446 | /* | ||
447 | * Even though we decoded the basic block, the instruction stream | ||
448 | * never matched the given IP, either the TO or the IP got corrupted. | ||
449 | */ | ||
450 | return 0; | ||
451 | } | ||
452 | |||
453 | static int intel_pmu_save_and_restart(struct perf_event *event); | ||
454 | |||
455 | static void intel_pmu_drain_pebs_core(struct pt_regs *iregs) | ||
456 | { | ||
457 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
458 | struct debug_store *ds = cpuc->ds; | ||
459 | struct perf_event *event = cpuc->events[0]; /* PMC0 only */ | ||
460 | struct pebs_record_core *at, *top; | ||
461 | struct perf_sample_data data; | ||
462 | struct perf_raw_record raw; | ||
463 | struct pt_regs regs; | ||
464 | int n; | ||
465 | |||
466 | if (!ds || !x86_pmu.pebs) | ||
467 | return; | ||
468 | |||
469 | at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base; | ||
470 | top = (struct pebs_record_core *)(unsigned long)ds->pebs_index; | ||
471 | |||
472 | /* | ||
473 | * Whatever else happens, drain the thing | ||
474 | */ | ||
475 | ds->pebs_index = ds->pebs_buffer_base; | ||
476 | |||
477 | if (!test_bit(0, cpuc->active_mask)) | ||
478 | return; | ||
479 | |||
480 | WARN_ON_ONCE(!event); | ||
481 | |||
482 | if (!event->attr.precise) | ||
483 | return; | ||
484 | |||
485 | n = top - at; | ||
486 | if (n <= 0) | ||
487 | return; | ||
488 | |||
489 | if (!intel_pmu_save_and_restart(event)) | ||
490 | return; | ||
491 | |||
492 | /* | ||
493 | * Should not happen, we program the threshold at 1 and do not | ||
494 | * set a reset value. | ||
495 | */ | ||
496 | WARN_ON_ONCE(n > 1); | ||
497 | at += n - 1; | ||
498 | |||
499 | perf_sample_data_init(&data, 0); | ||
500 | data.period = event->hw.last_period; | ||
501 | |||
502 | if (event->attr.sample_type & PERF_SAMPLE_RAW) { | ||
503 | raw.size = x86_pmu.pebs_record_size; | ||
504 | raw.data = at; | ||
505 | data.raw = &raw; | ||
506 | } | ||
507 | |||
508 | /* | ||
509 | * We use the interrupt regs as a base because the PEBS record | ||
510 | * does not contain a full regs set, specifically it seems to | ||
511 | * lack segment descriptors, which get used by things like | ||
512 | * user_mode(). | ||
513 | * | ||
514 | * In the simple case fix up only the IP and BP,SP regs, for | ||
515 | * PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly. | ||
516 | * A possible PERF_SAMPLE_REGS will have to transfer all regs. | ||
517 | */ | ||
518 | regs = *iregs; | ||
519 | regs.ip = at->ip; | ||
520 | regs.bp = at->bp; | ||
521 | regs.sp = at->sp; | ||
522 | |||
523 | if (intel_pmu_pebs_fixup_ip(®s)) | ||
524 | regs.flags |= PERF_EFLAGS_EXACT; | ||
525 | else | ||
526 | regs.flags &= ~PERF_EFLAGS_EXACT; | ||
527 | |||
528 | if (perf_event_overflow(event, 1, &data, ®s)) | ||
529 | x86_pmu_stop(event); | ||
530 | } | ||
531 | |||
532 | static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs) | ||
533 | { | ||
534 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
535 | struct debug_store *ds = cpuc->ds; | ||
536 | struct pebs_record_nhm *at, *top; | ||
537 | struct perf_sample_data data; | ||
538 | struct perf_event *event = NULL; | ||
539 | struct perf_raw_record raw; | ||
540 | struct pt_regs regs; | ||
541 | u64 status = 0; | ||
542 | int bit, n; | ||
543 | |||
544 | if (!ds || !x86_pmu.pebs) | ||
545 | return; | ||
546 | |||
547 | at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base; | ||
548 | top = (struct pebs_record_nhm *)(unsigned long)ds->pebs_index; | ||
549 | |||
550 | ds->pebs_index = ds->pebs_buffer_base; | ||
551 | |||
552 | n = top - at; | ||
553 | if (n <= 0) | ||
554 | return; | ||
555 | |||
556 | /* | ||
557 | * Should not happen, we program the threshold at 1 and do not | ||
558 | * set a reset value. | ||
559 | */ | ||
560 | WARN_ON_ONCE(n > MAX_PEBS_EVENTS); | ||
561 | |||
562 | for ( ; at < top; at++) { | ||
563 | for_each_set_bit(bit, (unsigned long *)&at->status, MAX_PEBS_EVENTS) { | ||
564 | event = cpuc->events[bit]; | ||
565 | if (!test_bit(bit, cpuc->active_mask)) | ||
566 | continue; | ||
567 | |||
568 | WARN_ON_ONCE(!event); | ||
569 | |||
570 | if (!event->attr.precise) | ||
571 | continue; | ||
572 | |||
573 | if (__test_and_set_bit(bit, (unsigned long *)&status)) | ||
574 | continue; | ||
575 | |||
576 | break; | ||
577 | } | ||
578 | |||
579 | if (!event || bit >= MAX_PEBS_EVENTS) | ||
580 | continue; | ||
581 | |||
582 | if (!intel_pmu_save_and_restart(event)) | ||
583 | continue; | ||
584 | |||
585 | perf_sample_data_init(&data, 0); | ||
586 | data.period = event->hw.last_period; | ||
587 | |||
588 | if (event->attr.sample_type & PERF_SAMPLE_RAW) { | ||
589 | raw.size = x86_pmu.pebs_record_size; | ||
590 | raw.data = at; | ||
591 | data.raw = &raw; | ||
592 | } | ||
593 | |||
594 | /* | ||
595 | * See the comment in intel_pmu_drain_pebs_core() | ||
596 | */ | ||
597 | regs = *iregs; | ||
598 | regs.ip = at->ip; | ||
599 | regs.bp = at->bp; | ||
600 | regs.sp = at->sp; | ||
601 | |||
602 | if (intel_pmu_pebs_fixup_ip(®s)) | ||
603 | regs.flags |= PERF_EFLAGS_EXACT; | ||
604 | else | ||
605 | regs.flags &= ~PERF_EFLAGS_EXACT; | ||
606 | |||
607 | if (perf_event_overflow(event, 1, &data, ®s)) | ||
608 | x86_pmu_stop(event); | ||
609 | } | ||
610 | } | ||
611 | |||
612 | /* | ||
613 | * BTS, PEBS probe and setup | ||
614 | */ | ||
615 | |||
616 | static void intel_ds_init(void) | ||
617 | { | ||
618 | /* | ||
619 | * No support for 32bit formats | ||
620 | */ | ||
621 | if (!boot_cpu_has(X86_FEATURE_DTES64)) | ||
622 | return; | ||
623 | |||
624 | x86_pmu.bts = boot_cpu_has(X86_FEATURE_BTS); | ||
625 | x86_pmu.pebs = boot_cpu_has(X86_FEATURE_PEBS); | ||
626 | if (x86_pmu.pebs) { | ||
627 | char pebs_type = x86_pmu.intel_cap.pebs_trap ? '+' : '-'; | ||
628 | int format = x86_pmu.intel_cap.pebs_format; | ||
629 | |||
630 | switch (format) { | ||
631 | case 0: | ||
632 | printk(KERN_CONT "PEBS fmt0%c, ", pebs_type); | ||
633 | x86_pmu.pebs_record_size = sizeof(struct pebs_record_core); | ||
634 | x86_pmu.drain_pebs = intel_pmu_drain_pebs_core; | ||
635 | x86_pmu.pebs_constraints = intel_core_pebs_events; | ||
636 | break; | ||
637 | |||
638 | case 1: | ||
639 | printk(KERN_CONT "PEBS fmt1%c, ", pebs_type); | ||
640 | x86_pmu.pebs_record_size = sizeof(struct pebs_record_nhm); | ||
641 | x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm; | ||
642 | x86_pmu.pebs_constraints = intel_nehalem_pebs_events; | ||
643 | break; | ||
644 | |||
645 | default: | ||
646 | printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type); | ||
647 | x86_pmu.pebs = 0; | ||
648 | break; | ||
649 | } | ||
650 | } | ||
651 | } | ||
652 | |||
653 | #else /* CONFIG_CPU_SUP_INTEL */ | ||
654 | |||
655 | static int reserve_ds_buffers(void) | ||
656 | { | ||
657 | return 0; | ||
658 | } | ||
659 | |||
660 | static void release_ds_buffers(void) | ||
661 | { | ||
662 | } | ||
663 | |||
664 | #endif /* CONFIG_CPU_SUP_INTEL */ | ||
diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c new file mode 100644 index 00000000000..d202c1bece1 --- /dev/null +++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c | |||
@@ -0,0 +1,218 @@ | |||
1 | #ifdef CONFIG_CPU_SUP_INTEL | ||
2 | |||
3 | enum { | ||
4 | LBR_FORMAT_32 = 0x00, | ||
5 | LBR_FORMAT_LIP = 0x01, | ||
6 | LBR_FORMAT_EIP = 0x02, | ||
7 | LBR_FORMAT_EIP_FLAGS = 0x03, | ||
8 | }; | ||
9 | |||
10 | /* | ||
11 | * We only support LBR implementations that have FREEZE_LBRS_ON_PMI | ||
12 | * otherwise it becomes near impossible to get a reliable stack. | ||
13 | */ | ||
14 | |||
15 | static void __intel_pmu_lbr_enable(void) | ||
16 | { | ||
17 | u64 debugctl; | ||
18 | |||
19 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); | ||
20 | debugctl |= (DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); | ||
21 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); | ||
22 | } | ||
23 | |||
24 | static void __intel_pmu_lbr_disable(void) | ||
25 | { | ||
26 | u64 debugctl; | ||
27 | |||
28 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); | ||
29 | debugctl &= ~(DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); | ||
30 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); | ||
31 | } | ||
32 | |||
33 | static void intel_pmu_lbr_reset_32(void) | ||
34 | { | ||
35 | int i; | ||
36 | |||
37 | for (i = 0; i < x86_pmu.lbr_nr; i++) | ||
38 | wrmsrl(x86_pmu.lbr_from + i, 0); | ||
39 | } | ||
40 | |||
41 | static void intel_pmu_lbr_reset_64(void) | ||
42 | { | ||
43 | int i; | ||
44 | |||
45 | for (i = 0; i < x86_pmu.lbr_nr; i++) { | ||
46 | wrmsrl(x86_pmu.lbr_from + i, 0); | ||
47 | wrmsrl(x86_pmu.lbr_to + i, 0); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | static void intel_pmu_lbr_reset(void) | ||
52 | { | ||
53 | if (!x86_pmu.lbr_nr) | ||
54 | return; | ||
55 | |||
56 | if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32) | ||
57 | intel_pmu_lbr_reset_32(); | ||
58 | else | ||
59 | intel_pmu_lbr_reset_64(); | ||
60 | } | ||
61 | |||
62 | static void intel_pmu_lbr_enable(struct perf_event *event) | ||
63 | { | ||
64 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
65 | |||
66 | if (!x86_pmu.lbr_nr) | ||
67 | return; | ||
68 | |||
69 | WARN_ON_ONCE(cpuc->enabled); | ||
70 | |||
71 | /* | ||
72 | * Reset the LBR stack if we changed task context to | ||
73 | * avoid data leaks. | ||
74 | */ | ||
75 | |||
76 | if (event->ctx->task && cpuc->lbr_context != event->ctx) { | ||
77 | intel_pmu_lbr_reset(); | ||
78 | cpuc->lbr_context = event->ctx; | ||
79 | } | ||
80 | |||
81 | cpuc->lbr_users++; | ||
82 | } | ||
83 | |||
84 | static void intel_pmu_lbr_disable(struct perf_event *event) | ||
85 | { | ||
86 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
87 | |||
88 | if (!x86_pmu.lbr_nr) | ||
89 | return; | ||
90 | |||
91 | cpuc->lbr_users--; | ||
92 | WARN_ON_ONCE(cpuc->lbr_users < 0); | ||
93 | |||
94 | if (cpuc->enabled && !cpuc->lbr_users) | ||
95 | __intel_pmu_lbr_disable(); | ||
96 | } | ||
97 | |||
98 | static void intel_pmu_lbr_enable_all(void) | ||
99 | { | ||
100 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
101 | |||
102 | if (cpuc->lbr_users) | ||
103 | __intel_pmu_lbr_enable(); | ||
104 | } | ||
105 | |||
106 | static void intel_pmu_lbr_disable_all(void) | ||
107 | { | ||
108 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
109 | |||
110 | if (cpuc->lbr_users) | ||
111 | __intel_pmu_lbr_disable(); | ||
112 | } | ||
113 | |||
114 | static inline u64 intel_pmu_lbr_tos(void) | ||
115 | { | ||
116 | u64 tos; | ||
117 | |||
118 | rdmsrl(x86_pmu.lbr_tos, tos); | ||
119 | |||
120 | return tos; | ||
121 | } | ||
122 | |||
123 | static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc) | ||
124 | { | ||
125 | unsigned long mask = x86_pmu.lbr_nr - 1; | ||
126 | u64 tos = intel_pmu_lbr_tos(); | ||
127 | int i; | ||
128 | |||
129 | for (i = 0; i < x86_pmu.lbr_nr; i++) { | ||
130 | unsigned long lbr_idx = (tos - i) & mask; | ||
131 | union { | ||
132 | struct { | ||
133 | u32 from; | ||
134 | u32 to; | ||
135 | }; | ||
136 | u64 lbr; | ||
137 | } msr_lastbranch; | ||
138 | |||
139 | rdmsrl(x86_pmu.lbr_from + lbr_idx, msr_lastbranch.lbr); | ||
140 | |||
141 | cpuc->lbr_entries[i].from = msr_lastbranch.from; | ||
142 | cpuc->lbr_entries[i].to = msr_lastbranch.to; | ||
143 | cpuc->lbr_entries[i].flags = 0; | ||
144 | } | ||
145 | cpuc->lbr_stack.nr = i; | ||
146 | } | ||
147 | |||
148 | #define LBR_FROM_FLAG_MISPRED (1ULL << 63) | ||
149 | |||
150 | /* | ||
151 | * Due to lack of segmentation in Linux the effective address (offset) | ||
152 | * is the same as the linear address, allowing us to merge the LIP and EIP | ||
153 | * LBR formats. | ||
154 | */ | ||
155 | static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc) | ||
156 | { | ||
157 | unsigned long mask = x86_pmu.lbr_nr - 1; | ||
158 | int lbr_format = x86_pmu.intel_cap.lbr_format; | ||
159 | u64 tos = intel_pmu_lbr_tos(); | ||
160 | int i; | ||
161 | |||
162 | for (i = 0; i < x86_pmu.lbr_nr; i++) { | ||
163 | unsigned long lbr_idx = (tos - i) & mask; | ||
164 | u64 from, to, flags = 0; | ||
165 | |||
166 | rdmsrl(x86_pmu.lbr_from + lbr_idx, from); | ||
167 | rdmsrl(x86_pmu.lbr_to + lbr_idx, to); | ||
168 | |||
169 | if (lbr_format == LBR_FORMAT_EIP_FLAGS) { | ||
170 | flags = !!(from & LBR_FROM_FLAG_MISPRED); | ||
171 | from = (u64)((((s64)from) << 1) >> 1); | ||
172 | } | ||
173 | |||
174 | cpuc->lbr_entries[i].from = from; | ||
175 | cpuc->lbr_entries[i].to = to; | ||
176 | cpuc->lbr_entries[i].flags = flags; | ||
177 | } | ||
178 | cpuc->lbr_stack.nr = i; | ||
179 | } | ||
180 | |||
181 | static void intel_pmu_lbr_read(void) | ||
182 | { | ||
183 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
184 | |||
185 | if (!cpuc->lbr_users) | ||
186 | return; | ||
187 | |||
188 | if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32) | ||
189 | intel_pmu_lbr_read_32(cpuc); | ||
190 | else | ||
191 | intel_pmu_lbr_read_64(cpuc); | ||
192 | } | ||
193 | |||
194 | static void intel_pmu_lbr_init_core(void) | ||
195 | { | ||
196 | x86_pmu.lbr_nr = 4; | ||
197 | x86_pmu.lbr_tos = 0x01c9; | ||
198 | x86_pmu.lbr_from = 0x40; | ||
199 | x86_pmu.lbr_to = 0x60; | ||
200 | } | ||
201 | |||
202 | static void intel_pmu_lbr_init_nhm(void) | ||
203 | { | ||
204 | x86_pmu.lbr_nr = 16; | ||
205 | x86_pmu.lbr_tos = 0x01c9; | ||
206 | x86_pmu.lbr_from = 0x680; | ||
207 | x86_pmu.lbr_to = 0x6c0; | ||
208 | } | ||
209 | |||
210 | static void intel_pmu_lbr_init_atom(void) | ||
211 | { | ||
212 | x86_pmu.lbr_nr = 8; | ||
213 | x86_pmu.lbr_tos = 0x01c9; | ||
214 | x86_pmu.lbr_from = 0x40; | ||
215 | x86_pmu.lbr_to = 0x60; | ||
216 | } | ||
217 | |||
218 | #endif /* CONFIG_CPU_SUP_INTEL */ | ||
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c new file mode 100644 index 00000000000..15367cce66b --- /dev/null +++ b/arch/x86/kernel/cpu/perf_event_p4.c | |||
@@ -0,0 +1,834 @@ | |||
1 | /* | ||
2 | * Netburst Perfomance Events (P4, old Xeon) | ||
3 | * | ||
4 | * Copyright (C) 2010 Parallels, Inc., Cyrill Gorcunov <gorcunov@openvz.org> | ||
5 | * Copyright (C) 2010 Intel Corporation, Lin Ming <ming.m.lin@intel.com> | ||
6 | * | ||
7 | * For licencing details see kernel-base/COPYING | ||
8 | */ | ||
9 | |||
10 | #ifdef CONFIG_CPU_SUP_INTEL | ||
11 | |||
12 | #include <asm/perf_event_p4.h> | ||
13 | |||
14 | #define P4_CNTR_LIMIT 3 | ||
15 | /* | ||
16 | * array indices: 0,1 - HT threads, used with HT enabled cpu | ||
17 | */ | ||
18 | struct p4_event_bind { | ||
19 | unsigned int opcode; /* Event code and ESCR selector */ | ||
20 | unsigned int escr_msr[2]; /* ESCR MSR for this event */ | ||
21 | unsigned char cntr[2][P4_CNTR_LIMIT]; /* counter index (offset), -1 on abscence */ | ||
22 | }; | ||
23 | |||
24 | struct p4_cache_event_bind { | ||
25 | unsigned int metric_pebs; | ||
26 | unsigned int metric_vert; | ||
27 | }; | ||
28 | |||
29 | #define P4_GEN_CACHE_EVENT_BIND(name) \ | ||
30 | [P4_CACHE__##name] = { \ | ||
31 | .metric_pebs = P4_PEBS__##name, \ | ||
32 | .metric_vert = P4_VERT__##name, \ | ||
33 | } | ||
34 | |||
35 | static struct p4_cache_event_bind p4_cache_event_bind_map[] = { | ||
36 | P4_GEN_CACHE_EVENT_BIND(1stl_cache_load_miss_retired), | ||
37 | P4_GEN_CACHE_EVENT_BIND(2ndl_cache_load_miss_retired), | ||
38 | P4_GEN_CACHE_EVENT_BIND(dtlb_load_miss_retired), | ||
39 | P4_GEN_CACHE_EVENT_BIND(dtlb_store_miss_retired), | ||
40 | }; | ||
41 | |||
42 | /* | ||
43 | * Note that we don't use CCCR1 here, there is an | ||
44 | * exception for P4_BSQ_ALLOCATION but we just have | ||
45 | * no workaround | ||
46 | * | ||
47 | * consider this binding as resources which particular | ||
48 | * event may borrow, it doesn't contain EventMask, | ||
49 | * Tags and friends -- they are left to a caller | ||
50 | */ | ||
51 | static struct p4_event_bind p4_event_bind_map[] = { | ||
52 | [P4_EVENT_TC_DELIVER_MODE] = { | ||
53 | .opcode = P4_OPCODE(P4_EVENT_TC_DELIVER_MODE), | ||
54 | .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 }, | ||
55 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
56 | }, | ||
57 | [P4_EVENT_BPU_FETCH_REQUEST] = { | ||
58 | .opcode = P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST), | ||
59 | .escr_msr = { MSR_P4_BPU_ESCR0, MSR_P4_BPU_ESCR1 }, | ||
60 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
61 | }, | ||
62 | [P4_EVENT_ITLB_REFERENCE] = { | ||
63 | .opcode = P4_OPCODE(P4_EVENT_ITLB_REFERENCE), | ||
64 | .escr_msr = { MSR_P4_ITLB_ESCR0, MSR_P4_ITLB_ESCR1 }, | ||
65 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
66 | }, | ||
67 | [P4_EVENT_MEMORY_CANCEL] = { | ||
68 | .opcode = P4_OPCODE(P4_EVENT_MEMORY_CANCEL), | ||
69 | .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 }, | ||
70 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
71 | }, | ||
72 | [P4_EVENT_MEMORY_COMPLETE] = { | ||
73 | .opcode = P4_OPCODE(P4_EVENT_MEMORY_COMPLETE), | ||
74 | .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 }, | ||
75 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
76 | }, | ||
77 | [P4_EVENT_LOAD_PORT_REPLAY] = { | ||
78 | .opcode = P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY), | ||
79 | .escr_msr = { MSR_P4_SAAT_ESCR0, MSR_P4_SAAT_ESCR1 }, | ||
80 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
81 | }, | ||
82 | [P4_EVENT_STORE_PORT_REPLAY] = { | ||
83 | .opcode = P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY), | ||
84 | .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 }, | ||
85 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
86 | }, | ||
87 | [P4_EVENT_MOB_LOAD_REPLAY] = { | ||
88 | .opcode = P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY), | ||
89 | .escr_msr = { MSR_P4_MOB_ESCR0, MSR_P4_MOB_ESCR1 }, | ||
90 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
91 | }, | ||
92 | [P4_EVENT_PAGE_WALK_TYPE] = { | ||
93 | .opcode = P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE), | ||
94 | .escr_msr = { MSR_P4_PMH_ESCR0, MSR_P4_PMH_ESCR1 }, | ||
95 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
96 | }, | ||
97 | [P4_EVENT_BSQ_CACHE_REFERENCE] = { | ||
98 | .opcode = P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE), | ||
99 | .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR1 }, | ||
100 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
101 | }, | ||
102 | [P4_EVENT_IOQ_ALLOCATION] = { | ||
103 | .opcode = P4_OPCODE(P4_EVENT_IOQ_ALLOCATION), | ||
104 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
105 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
106 | }, | ||
107 | [P4_EVENT_IOQ_ACTIVE_ENTRIES] = { /* shared ESCR */ | ||
108 | .opcode = P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES), | ||
109 | .escr_msr = { MSR_P4_FSB_ESCR1, MSR_P4_FSB_ESCR1 }, | ||
110 | .cntr = { {2, -1, -1}, {3, -1, -1} }, | ||
111 | }, | ||
112 | [P4_EVENT_FSB_DATA_ACTIVITY] = { | ||
113 | .opcode = P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY), | ||
114 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
115 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
116 | }, | ||
117 | [P4_EVENT_BSQ_ALLOCATION] = { /* shared ESCR, broken CCCR1 */ | ||
118 | .opcode = P4_OPCODE(P4_EVENT_BSQ_ALLOCATION), | ||
119 | .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR0 }, | ||
120 | .cntr = { {0, -1, -1}, {1, -1, -1} }, | ||
121 | }, | ||
122 | [P4_EVENT_BSQ_ACTIVE_ENTRIES] = { /* shared ESCR */ | ||
123 | .opcode = P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES), | ||
124 | .escr_msr = { MSR_P4_BSU_ESCR1 , MSR_P4_BSU_ESCR1 }, | ||
125 | .cntr = { {2, -1, -1}, {3, -1, -1} }, | ||
126 | }, | ||
127 | [P4_EVENT_SSE_INPUT_ASSIST] = { | ||
128 | .opcode = P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST), | ||
129 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
130 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
131 | }, | ||
132 | [P4_EVENT_PACKED_SP_UOP] = { | ||
133 | .opcode = P4_OPCODE(P4_EVENT_PACKED_SP_UOP), | ||
134 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
135 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
136 | }, | ||
137 | [P4_EVENT_PACKED_DP_UOP] = { | ||
138 | .opcode = P4_OPCODE(P4_EVENT_PACKED_DP_UOP), | ||
139 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
140 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
141 | }, | ||
142 | [P4_EVENT_SCALAR_SP_UOP] = { | ||
143 | .opcode = P4_OPCODE(P4_EVENT_SCALAR_SP_UOP), | ||
144 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
145 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
146 | }, | ||
147 | [P4_EVENT_SCALAR_DP_UOP] = { | ||
148 | .opcode = P4_OPCODE(P4_EVENT_SCALAR_DP_UOP), | ||
149 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
150 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
151 | }, | ||
152 | [P4_EVENT_64BIT_MMX_UOP] = { | ||
153 | .opcode = P4_OPCODE(P4_EVENT_64BIT_MMX_UOP), | ||
154 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
155 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
156 | }, | ||
157 | [P4_EVENT_128BIT_MMX_UOP] = { | ||
158 | .opcode = P4_OPCODE(P4_EVENT_128BIT_MMX_UOP), | ||
159 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
160 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
161 | }, | ||
162 | [P4_EVENT_X87_FP_UOP] = { | ||
163 | .opcode = P4_OPCODE(P4_EVENT_X87_FP_UOP), | ||
164 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
165 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
166 | }, | ||
167 | [P4_EVENT_TC_MISC] = { | ||
168 | .opcode = P4_OPCODE(P4_EVENT_TC_MISC), | ||
169 | .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 }, | ||
170 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
171 | }, | ||
172 | [P4_EVENT_GLOBAL_POWER_EVENTS] = { | ||
173 | .opcode = P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS), | ||
174 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
175 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
176 | }, | ||
177 | [P4_EVENT_TC_MS_XFER] = { | ||
178 | .opcode = P4_OPCODE(P4_EVENT_TC_MS_XFER), | ||
179 | .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 }, | ||
180 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
181 | }, | ||
182 | [P4_EVENT_UOP_QUEUE_WRITES] = { | ||
183 | .opcode = P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES), | ||
184 | .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 }, | ||
185 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
186 | }, | ||
187 | [P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE] = { | ||
188 | .opcode = P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE), | ||
189 | .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR0 }, | ||
190 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
191 | }, | ||
192 | [P4_EVENT_RETIRED_BRANCH_TYPE] = { | ||
193 | .opcode = P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE), | ||
194 | .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR1 }, | ||
195 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
196 | }, | ||
197 | [P4_EVENT_RESOURCE_STALL] = { | ||
198 | .opcode = P4_OPCODE(P4_EVENT_RESOURCE_STALL), | ||
199 | .escr_msr = { MSR_P4_ALF_ESCR0, MSR_P4_ALF_ESCR1 }, | ||
200 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
201 | }, | ||
202 | [P4_EVENT_WC_BUFFER] = { | ||
203 | .opcode = P4_OPCODE(P4_EVENT_WC_BUFFER), | ||
204 | .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 }, | ||
205 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
206 | }, | ||
207 | [P4_EVENT_B2B_CYCLES] = { | ||
208 | .opcode = P4_OPCODE(P4_EVENT_B2B_CYCLES), | ||
209 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
210 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
211 | }, | ||
212 | [P4_EVENT_BNR] = { | ||
213 | .opcode = P4_OPCODE(P4_EVENT_BNR), | ||
214 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
215 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
216 | }, | ||
217 | [P4_EVENT_SNOOP] = { | ||
218 | .opcode = P4_OPCODE(P4_EVENT_SNOOP), | ||
219 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
220 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
221 | }, | ||
222 | [P4_EVENT_RESPONSE] = { | ||
223 | .opcode = P4_OPCODE(P4_EVENT_RESPONSE), | ||
224 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
225 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
226 | }, | ||
227 | [P4_EVENT_FRONT_END_EVENT] = { | ||
228 | .opcode = P4_OPCODE(P4_EVENT_FRONT_END_EVENT), | ||
229 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
230 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
231 | }, | ||
232 | [P4_EVENT_EXECUTION_EVENT] = { | ||
233 | .opcode = P4_OPCODE(P4_EVENT_EXECUTION_EVENT), | ||
234 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
235 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
236 | }, | ||
237 | [P4_EVENT_REPLAY_EVENT] = { | ||
238 | .opcode = P4_OPCODE(P4_EVENT_REPLAY_EVENT), | ||
239 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
240 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
241 | }, | ||
242 | [P4_EVENT_INSTR_RETIRED] = { | ||
243 | .opcode = P4_OPCODE(P4_EVENT_INSTR_RETIRED), | ||
244 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | ||
245 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
246 | }, | ||
247 | [P4_EVENT_UOPS_RETIRED] = { | ||
248 | .opcode = P4_OPCODE(P4_EVENT_UOPS_RETIRED), | ||
249 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | ||
250 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
251 | }, | ||
252 | [P4_EVENT_UOP_TYPE] = { | ||
253 | .opcode = P4_OPCODE(P4_EVENT_UOP_TYPE), | ||
254 | .escr_msr = { MSR_P4_RAT_ESCR0, MSR_P4_RAT_ESCR1 }, | ||
255 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
256 | }, | ||
257 | [P4_EVENT_BRANCH_RETIRED] = { | ||
258 | .opcode = P4_OPCODE(P4_EVENT_BRANCH_RETIRED), | ||
259 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
260 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
261 | }, | ||
262 | [P4_EVENT_MISPRED_BRANCH_RETIRED] = { | ||
263 | .opcode = P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED), | ||
264 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | ||
265 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
266 | }, | ||
267 | [P4_EVENT_X87_ASSIST] = { | ||
268 | .opcode = P4_OPCODE(P4_EVENT_X87_ASSIST), | ||
269 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
270 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
271 | }, | ||
272 | [P4_EVENT_MACHINE_CLEAR] = { | ||
273 | .opcode = P4_OPCODE(P4_EVENT_MACHINE_CLEAR), | ||
274 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
275 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
276 | }, | ||
277 | [P4_EVENT_INSTR_COMPLETED] = { | ||
278 | .opcode = P4_OPCODE(P4_EVENT_INSTR_COMPLETED), | ||
279 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | ||
280 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
281 | }, | ||
282 | }; | ||
283 | |||
284 | #define P4_GEN_CACHE_EVENT(event, bit, cache_event) \ | ||
285 | p4_config_pack_escr(P4_ESCR_EVENT(event) | \ | ||
286 | P4_ESCR_EMASK_BIT(event, bit)) | \ | ||
287 | p4_config_pack_cccr(cache_event | \ | ||
288 | P4_CCCR_ESEL(P4_OPCODE_ESEL(P4_OPCODE(event)))) | ||
289 | |||
290 | static __initconst const u64 p4_hw_cache_event_ids | ||
291 | [PERF_COUNT_HW_CACHE_MAX] | ||
292 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
293 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | ||
294 | { | ||
295 | [ C(L1D ) ] = { | ||
296 | [ C(OP_READ) ] = { | ||
297 | [ C(RESULT_ACCESS) ] = 0x0, | ||
298 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS, | ||
299 | P4_CACHE__1stl_cache_load_miss_retired), | ||
300 | }, | ||
301 | }, | ||
302 | [ C(LL ) ] = { | ||
303 | [ C(OP_READ) ] = { | ||
304 | [ C(RESULT_ACCESS) ] = 0x0, | ||
305 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS, | ||
306 | P4_CACHE__2ndl_cache_load_miss_retired), | ||
307 | }, | ||
308 | }, | ||
309 | [ C(DTLB) ] = { | ||
310 | [ C(OP_READ) ] = { | ||
311 | [ C(RESULT_ACCESS) ] = 0x0, | ||
312 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS, | ||
313 | P4_CACHE__dtlb_load_miss_retired), | ||
314 | }, | ||
315 | [ C(OP_WRITE) ] = { | ||
316 | [ C(RESULT_ACCESS) ] = 0x0, | ||
317 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS, | ||
318 | P4_CACHE__dtlb_store_miss_retired), | ||
319 | }, | ||
320 | }, | ||
321 | [ C(ITLB) ] = { | ||
322 | [ C(OP_READ) ] = { | ||
323 | [ C(RESULT_ACCESS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE, HIT, | ||
324 | P4_CACHE__itlb_reference_hit), | ||
325 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE, MISS, | ||
326 | P4_CACHE__itlb_reference_miss), | ||
327 | }, | ||
328 | [ C(OP_WRITE) ] = { | ||
329 | [ C(RESULT_ACCESS) ] = -1, | ||
330 | [ C(RESULT_MISS) ] = -1, | ||
331 | }, | ||
332 | [ C(OP_PREFETCH) ] = { | ||
333 | [ C(RESULT_ACCESS) ] = -1, | ||
334 | [ C(RESULT_MISS) ] = -1, | ||
335 | }, | ||
336 | }, | ||
337 | }; | ||
338 | |||
339 | static u64 p4_general_events[PERF_COUNT_HW_MAX] = { | ||
340 | /* non-halted CPU clocks */ | ||
341 | [PERF_COUNT_HW_CPU_CYCLES] = | ||
342 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS) | | ||
343 | P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)), | ||
344 | |||
345 | /* | ||
346 | * retired instructions | ||
347 | * in a sake of simplicity we don't use the FSB tagging | ||
348 | */ | ||
349 | [PERF_COUNT_HW_INSTRUCTIONS] = | ||
350 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_INSTR_RETIRED) | | ||
351 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG) | | ||
352 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, BOGUSNTAG)), | ||
353 | |||
354 | /* cache hits */ | ||
355 | [PERF_COUNT_HW_CACHE_REFERENCES] = | ||
356 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE) | | ||
357 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS) | | ||
358 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE) | | ||
359 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM) | | ||
360 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS) | | ||
361 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE) | | ||
362 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM)), | ||
363 | |||
364 | /* cache misses */ | ||
365 | [PERF_COUNT_HW_CACHE_MISSES] = | ||
366 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE) | | ||
367 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS) | | ||
368 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS) | | ||
369 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS)), | ||
370 | |||
371 | /* branch instructions retired */ | ||
372 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = | ||
373 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_RETIRED_BRANCH_TYPE) | | ||
374 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL) | | ||
375 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CALL) | | ||
376 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN) | | ||
377 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT)), | ||
378 | |||
379 | /* mispredicted branches retired */ | ||
380 | [PERF_COUNT_HW_BRANCH_MISSES] = | ||
381 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_MISPRED_BRANCH_RETIRED) | | ||
382 | P4_ESCR_EMASK_BIT(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS)), | ||
383 | |||
384 | /* bus ready clocks (cpu is driving #DRDY_DRV\#DRDY_OWN): */ | ||
385 | [PERF_COUNT_HW_BUS_CYCLES] = | ||
386 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_FSB_DATA_ACTIVITY) | | ||
387 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV) | | ||
388 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN)) | | ||
389 | p4_config_pack_cccr(P4_CCCR_EDGE | P4_CCCR_COMPARE), | ||
390 | }; | ||
391 | |||
392 | static struct p4_event_bind *p4_config_get_bind(u64 config) | ||
393 | { | ||
394 | unsigned int evnt = p4_config_unpack_event(config); | ||
395 | struct p4_event_bind *bind = NULL; | ||
396 | |||
397 | if (evnt < ARRAY_SIZE(p4_event_bind_map)) | ||
398 | bind = &p4_event_bind_map[evnt]; | ||
399 | |||
400 | return bind; | ||
401 | } | ||
402 | |||
403 | static u64 p4_pmu_event_map(int hw_event) | ||
404 | { | ||
405 | struct p4_event_bind *bind; | ||
406 | unsigned int esel; | ||
407 | u64 config; | ||
408 | |||
409 | if (hw_event > ARRAY_SIZE(p4_general_events)) { | ||
410 | printk_once(KERN_ERR "P4 PMU: Bad index: %i\n", hw_event); | ||
411 | return 0; | ||
412 | } | ||
413 | |||
414 | config = p4_general_events[hw_event]; | ||
415 | bind = p4_config_get_bind(config); | ||
416 | esel = P4_OPCODE_ESEL(bind->opcode); | ||
417 | config |= p4_config_pack_cccr(P4_CCCR_ESEL(esel)); | ||
418 | |||
419 | return config; | ||
420 | } | ||
421 | |||
422 | static int p4_hw_config(struct perf_event *event) | ||
423 | { | ||
424 | int cpu = raw_smp_processor_id(); | ||
425 | u32 escr, cccr; | ||
426 | |||
427 | /* | ||
428 | * the reason we use cpu that early is that: if we get scheduled | ||
429 | * first time on the same cpu -- we will not need swap thread | ||
430 | * specific flags in config (and will save some cpu cycles) | ||
431 | */ | ||
432 | |||
433 | cccr = p4_default_cccr_conf(cpu); | ||
434 | escr = p4_default_escr_conf(cpu, event->attr.exclude_kernel, | ||
435 | event->attr.exclude_user); | ||
436 | event->hw.config = p4_config_pack_escr(escr) | | ||
437 | p4_config_pack_cccr(cccr); | ||
438 | |||
439 | if (p4_ht_active() && p4_ht_thread(cpu)) | ||
440 | event->hw.config = p4_set_ht_bit(event->hw.config); | ||
441 | |||
442 | if (event->attr.type != PERF_TYPE_RAW) | ||
443 | return 0; | ||
444 | |||
445 | /* | ||
446 | * We don't control raw events so it's up to the caller | ||
447 | * to pass sane values (and we don't count the thread number | ||
448 | * on HT machine but allow HT-compatible specifics to be | ||
449 | * passed on) | ||
450 | * | ||
451 | * XXX: HT wide things should check perf_paranoid_cpu() && | ||
452 | * CAP_SYS_ADMIN | ||
453 | */ | ||
454 | event->hw.config |= event->attr.config & | ||
455 | (p4_config_pack_escr(P4_ESCR_MASK_HT) | | ||
456 | p4_config_pack_cccr(P4_CCCR_MASK_HT)); | ||
457 | |||
458 | return 0; | ||
459 | } | ||
460 | |||
461 | static inline void p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) | ||
462 | { | ||
463 | unsigned long dummy; | ||
464 | |||
465 | rdmsrl(hwc->config_base + hwc->idx, dummy); | ||
466 | if (dummy & P4_CCCR_OVF) { | ||
467 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | ||
468 | ((u64)dummy) & ~P4_CCCR_OVF); | ||
469 | } | ||
470 | } | ||
471 | |||
472 | static inline void p4_pmu_disable_event(struct perf_event *event) | ||
473 | { | ||
474 | struct hw_perf_event *hwc = &event->hw; | ||
475 | |||
476 | /* | ||
477 | * If event gets disabled while counter is in overflowed | ||
478 | * state we need to clear P4_CCCR_OVF, otherwise interrupt get | ||
479 | * asserted again and again | ||
480 | */ | ||
481 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | ||
482 | (u64)(p4_config_unpack_cccr(hwc->config)) & | ||
483 | ~P4_CCCR_ENABLE & ~P4_CCCR_OVF & ~P4_CCCR_RESERVED); | ||
484 | } | ||
485 | |||
486 | static void p4_pmu_disable_all(void) | ||
487 | { | ||
488 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
489 | int idx; | ||
490 | |||
491 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | ||
492 | struct perf_event *event = cpuc->events[idx]; | ||
493 | if (!test_bit(idx, cpuc->active_mask)) | ||
494 | continue; | ||
495 | p4_pmu_disable_event(event); | ||
496 | } | ||
497 | } | ||
498 | |||
499 | static void p4_pmu_enable_event(struct perf_event *event) | ||
500 | { | ||
501 | struct hw_perf_event *hwc = &event->hw; | ||
502 | int thread = p4_ht_config_thread(hwc->config); | ||
503 | u64 escr_conf = p4_config_unpack_escr(p4_clear_ht_bit(hwc->config)); | ||
504 | unsigned int idx = p4_config_unpack_event(hwc->config); | ||
505 | unsigned int idx_cache = p4_config_unpack_cache_event(hwc->config); | ||
506 | struct p4_event_bind *bind; | ||
507 | struct p4_cache_event_bind *bind_cache; | ||
508 | u64 escr_addr, cccr; | ||
509 | |||
510 | bind = &p4_event_bind_map[idx]; | ||
511 | escr_addr = (u64)bind->escr_msr[thread]; | ||
512 | |||
513 | /* | ||
514 | * - we dont support cascaded counters yet | ||
515 | * - and counter 1 is broken (erratum) | ||
516 | */ | ||
517 | WARN_ON_ONCE(p4_is_event_cascaded(hwc->config)); | ||
518 | WARN_ON_ONCE(hwc->idx == 1); | ||
519 | |||
520 | /* we need a real Event value */ | ||
521 | escr_conf &= ~P4_ESCR_EVENT_MASK; | ||
522 | escr_conf |= P4_ESCR_EVENT(P4_OPCODE_EVNT(bind->opcode)); | ||
523 | |||
524 | cccr = p4_config_unpack_cccr(hwc->config); | ||
525 | |||
526 | /* | ||
527 | * it could be Cache event so that we need to | ||
528 | * set metrics into additional MSRs | ||
529 | */ | ||
530 | BUILD_BUG_ON(P4_CACHE__MAX > P4_CCCR_CACHE_OPS_MASK); | ||
531 | if (idx_cache > P4_CACHE__NONE && | ||
532 | idx_cache < ARRAY_SIZE(p4_cache_event_bind_map)) { | ||
533 | bind_cache = &p4_cache_event_bind_map[idx_cache]; | ||
534 | (void)checking_wrmsrl(MSR_IA32_PEBS_ENABLE, (u64)bind_cache->metric_pebs); | ||
535 | (void)checking_wrmsrl(MSR_P4_PEBS_MATRIX_VERT, (u64)bind_cache->metric_vert); | ||
536 | } | ||
537 | |||
538 | (void)checking_wrmsrl(escr_addr, escr_conf); | ||
539 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | ||
540 | (cccr & ~P4_CCCR_RESERVED) | P4_CCCR_ENABLE); | ||
541 | } | ||
542 | |||
543 | static void p4_pmu_enable_all(int added) | ||
544 | { | ||
545 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
546 | int idx; | ||
547 | |||
548 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | ||
549 | struct perf_event *event = cpuc->events[idx]; | ||
550 | if (!test_bit(idx, cpuc->active_mask)) | ||
551 | continue; | ||
552 | p4_pmu_enable_event(event); | ||
553 | } | ||
554 | } | ||
555 | |||
556 | static int p4_pmu_handle_irq(struct pt_regs *regs) | ||
557 | { | ||
558 | struct perf_sample_data data; | ||
559 | struct cpu_hw_events *cpuc; | ||
560 | struct perf_event *event; | ||
561 | struct hw_perf_event *hwc; | ||
562 | int idx, handled = 0; | ||
563 | u64 val; | ||
564 | |||
565 | data.addr = 0; | ||
566 | data.raw = NULL; | ||
567 | |||
568 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
569 | |||
570 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | ||
571 | |||
572 | if (!test_bit(idx, cpuc->active_mask)) | ||
573 | continue; | ||
574 | |||
575 | event = cpuc->events[idx]; | ||
576 | hwc = &event->hw; | ||
577 | |||
578 | WARN_ON_ONCE(hwc->idx != idx); | ||
579 | |||
580 | /* | ||
581 | * FIXME: Redundant call, actually not needed | ||
582 | * but just to check if we're screwed | ||
583 | */ | ||
584 | p4_pmu_clear_cccr_ovf(hwc); | ||
585 | |||
586 | val = x86_perf_event_update(event); | ||
587 | if (val & (1ULL << (x86_pmu.cntval_bits - 1))) | ||
588 | continue; | ||
589 | |||
590 | /* | ||
591 | * event overflow | ||
592 | */ | ||
593 | handled = 1; | ||
594 | data.period = event->hw.last_period; | ||
595 | |||
596 | if (!x86_perf_event_set_period(event)) | ||
597 | continue; | ||
598 | if (perf_event_overflow(event, 1, &data, regs)) | ||
599 | p4_pmu_disable_event(event); | ||
600 | } | ||
601 | |||
602 | if (handled) { | ||
603 | /* p4 quirk: unmask it again */ | ||
604 | apic_write(APIC_LVTPC, apic_read(APIC_LVTPC) & ~APIC_LVT_MASKED); | ||
605 | inc_irq_stat(apic_perf_irqs); | ||
606 | } | ||
607 | |||
608 | return handled; | ||
609 | } | ||
610 | |||
611 | /* | ||
612 | * swap thread specific fields according to a thread | ||
613 | * we are going to run on | ||
614 | */ | ||
615 | static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu) | ||
616 | { | ||
617 | u32 escr, cccr; | ||
618 | |||
619 | /* | ||
620 | * we either lucky and continue on same cpu or no HT support | ||
621 | */ | ||
622 | if (!p4_should_swap_ts(hwc->config, cpu)) | ||
623 | return; | ||
624 | |||
625 | /* | ||
626 | * the event is migrated from an another logical | ||
627 | * cpu, so we need to swap thread specific flags | ||
628 | */ | ||
629 | |||
630 | escr = p4_config_unpack_escr(hwc->config); | ||
631 | cccr = p4_config_unpack_cccr(hwc->config); | ||
632 | |||
633 | if (p4_ht_thread(cpu)) { | ||
634 | cccr &= ~P4_CCCR_OVF_PMI_T0; | ||
635 | cccr |= P4_CCCR_OVF_PMI_T1; | ||
636 | if (escr & P4_ESCR_T0_OS) { | ||
637 | escr &= ~P4_ESCR_T0_OS; | ||
638 | escr |= P4_ESCR_T1_OS; | ||
639 | } | ||
640 | if (escr & P4_ESCR_T0_USR) { | ||
641 | escr &= ~P4_ESCR_T0_USR; | ||
642 | escr |= P4_ESCR_T1_USR; | ||
643 | } | ||
644 | hwc->config = p4_config_pack_escr(escr); | ||
645 | hwc->config |= p4_config_pack_cccr(cccr); | ||
646 | hwc->config |= P4_CONFIG_HT; | ||
647 | } else { | ||
648 | cccr &= ~P4_CCCR_OVF_PMI_T1; | ||
649 | cccr |= P4_CCCR_OVF_PMI_T0; | ||
650 | if (escr & P4_ESCR_T1_OS) { | ||
651 | escr &= ~P4_ESCR_T1_OS; | ||
652 | escr |= P4_ESCR_T0_OS; | ||
653 | } | ||
654 | if (escr & P4_ESCR_T1_USR) { | ||
655 | escr &= ~P4_ESCR_T1_USR; | ||
656 | escr |= P4_ESCR_T0_USR; | ||
657 | } | ||
658 | hwc->config = p4_config_pack_escr(escr); | ||
659 | hwc->config |= p4_config_pack_cccr(cccr); | ||
660 | hwc->config &= ~P4_CONFIG_HT; | ||
661 | } | ||
662 | } | ||
663 | |||
664 | /* ESCRs are not sequential in memory so we need a map */ | ||
665 | static const unsigned int p4_escr_map[ARCH_P4_TOTAL_ESCR] = { | ||
666 | MSR_P4_ALF_ESCR0, /* 0 */ | ||
667 | MSR_P4_ALF_ESCR1, /* 1 */ | ||
668 | MSR_P4_BPU_ESCR0, /* 2 */ | ||
669 | MSR_P4_BPU_ESCR1, /* 3 */ | ||
670 | MSR_P4_BSU_ESCR0, /* 4 */ | ||
671 | MSR_P4_BSU_ESCR1, /* 5 */ | ||
672 | MSR_P4_CRU_ESCR0, /* 6 */ | ||
673 | MSR_P4_CRU_ESCR1, /* 7 */ | ||
674 | MSR_P4_CRU_ESCR2, /* 8 */ | ||
675 | MSR_P4_CRU_ESCR3, /* 9 */ | ||
676 | MSR_P4_CRU_ESCR4, /* 10 */ | ||
677 | MSR_P4_CRU_ESCR5, /* 11 */ | ||
678 | MSR_P4_DAC_ESCR0, /* 12 */ | ||
679 | MSR_P4_DAC_ESCR1, /* 13 */ | ||
680 | MSR_P4_FIRM_ESCR0, /* 14 */ | ||
681 | MSR_P4_FIRM_ESCR1, /* 15 */ | ||
682 | MSR_P4_FLAME_ESCR0, /* 16 */ | ||
683 | MSR_P4_FLAME_ESCR1, /* 17 */ | ||
684 | MSR_P4_FSB_ESCR0, /* 18 */ | ||
685 | MSR_P4_FSB_ESCR1, /* 19 */ | ||
686 | MSR_P4_IQ_ESCR0, /* 20 */ | ||
687 | MSR_P4_IQ_ESCR1, /* 21 */ | ||
688 | MSR_P4_IS_ESCR0, /* 22 */ | ||
689 | MSR_P4_IS_ESCR1, /* 23 */ | ||
690 | MSR_P4_ITLB_ESCR0, /* 24 */ | ||
691 | MSR_P4_ITLB_ESCR1, /* 25 */ | ||
692 | MSR_P4_IX_ESCR0, /* 26 */ | ||
693 | MSR_P4_IX_ESCR1, /* 27 */ | ||
694 | MSR_P4_MOB_ESCR0, /* 28 */ | ||
695 | MSR_P4_MOB_ESCR1, /* 29 */ | ||
696 | MSR_P4_MS_ESCR0, /* 30 */ | ||
697 | MSR_P4_MS_ESCR1, /* 31 */ | ||
698 | MSR_P4_PMH_ESCR0, /* 32 */ | ||
699 | MSR_P4_PMH_ESCR1, /* 33 */ | ||
700 | MSR_P4_RAT_ESCR0, /* 34 */ | ||
701 | MSR_P4_RAT_ESCR1, /* 35 */ | ||
702 | MSR_P4_SAAT_ESCR0, /* 36 */ | ||
703 | MSR_P4_SAAT_ESCR1, /* 37 */ | ||
704 | MSR_P4_SSU_ESCR0, /* 38 */ | ||
705 | MSR_P4_SSU_ESCR1, /* 39 */ | ||
706 | MSR_P4_TBPU_ESCR0, /* 40 */ | ||
707 | MSR_P4_TBPU_ESCR1, /* 41 */ | ||
708 | MSR_P4_TC_ESCR0, /* 42 */ | ||
709 | MSR_P4_TC_ESCR1, /* 43 */ | ||
710 | MSR_P4_U2L_ESCR0, /* 44 */ | ||
711 | MSR_P4_U2L_ESCR1, /* 45 */ | ||
712 | }; | ||
713 | |||
714 | static int p4_get_escr_idx(unsigned int addr) | ||
715 | { | ||
716 | unsigned int i; | ||
717 | |||
718 | for (i = 0; i < ARRAY_SIZE(p4_escr_map); i++) { | ||
719 | if (addr == p4_escr_map[i]) | ||
720 | return i; | ||
721 | } | ||
722 | |||
723 | return -1; | ||
724 | } | ||
725 | |||
726 | static int p4_next_cntr(int thread, unsigned long *used_mask, | ||
727 | struct p4_event_bind *bind) | ||
728 | { | ||
729 | int i = 0, j; | ||
730 | |||
731 | for (i = 0; i < P4_CNTR_LIMIT; i++) { | ||
732 | j = bind->cntr[thread][i++]; | ||
733 | if (j == -1 || !test_bit(j, used_mask)) | ||
734 | return j; | ||
735 | } | ||
736 | |||
737 | return -1; | ||
738 | } | ||
739 | |||
740 | static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) | ||
741 | { | ||
742 | unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | ||
743 | unsigned long escr_mask[BITS_TO_LONGS(ARCH_P4_TOTAL_ESCR)]; | ||
744 | int cpu = raw_smp_processor_id(); | ||
745 | struct hw_perf_event *hwc; | ||
746 | struct p4_event_bind *bind; | ||
747 | unsigned int i, thread, num; | ||
748 | int cntr_idx, escr_idx; | ||
749 | |||
750 | bitmap_zero(used_mask, X86_PMC_IDX_MAX); | ||
751 | bitmap_zero(escr_mask, ARCH_P4_TOTAL_ESCR); | ||
752 | |||
753 | for (i = 0, num = n; i < n; i++, num--) { | ||
754 | |||
755 | hwc = &cpuc->event_list[i]->hw; | ||
756 | thread = p4_ht_thread(cpu); | ||
757 | bind = p4_config_get_bind(hwc->config); | ||
758 | escr_idx = p4_get_escr_idx(bind->escr_msr[thread]); | ||
759 | |||
760 | if (hwc->idx != -1 && !p4_should_swap_ts(hwc->config, cpu)) { | ||
761 | cntr_idx = hwc->idx; | ||
762 | if (assign) | ||
763 | assign[i] = hwc->idx; | ||
764 | goto reserve; | ||
765 | } | ||
766 | |||
767 | cntr_idx = p4_next_cntr(thread, used_mask, bind); | ||
768 | if (cntr_idx == -1 || test_bit(escr_idx, escr_mask)) | ||
769 | goto done; | ||
770 | |||
771 | p4_pmu_swap_config_ts(hwc, cpu); | ||
772 | if (assign) | ||
773 | assign[i] = cntr_idx; | ||
774 | reserve: | ||
775 | set_bit(cntr_idx, used_mask); | ||
776 | set_bit(escr_idx, escr_mask); | ||
777 | } | ||
778 | |||
779 | done: | ||
780 | return num ? -ENOSPC : 0; | ||
781 | } | ||
782 | |||
783 | static __initconst const struct x86_pmu p4_pmu = { | ||
784 | .name = "Netburst P4/Xeon", | ||
785 | .handle_irq = p4_pmu_handle_irq, | ||
786 | .disable_all = p4_pmu_disable_all, | ||
787 | .enable_all = p4_pmu_enable_all, | ||
788 | .enable = p4_pmu_enable_event, | ||
789 | .disable = p4_pmu_disable_event, | ||
790 | .eventsel = MSR_P4_BPU_CCCR0, | ||
791 | .perfctr = MSR_P4_BPU_PERFCTR0, | ||
792 | .event_map = p4_pmu_event_map, | ||
793 | .max_events = ARRAY_SIZE(p4_general_events), | ||
794 | .get_event_constraints = x86_get_event_constraints, | ||
795 | /* | ||
796 | * IF HT disabled we may need to use all | ||
797 | * ARCH_P4_MAX_CCCR counters simulaneously | ||
798 | * though leave it restricted at moment assuming | ||
799 | * HT is on | ||
800 | */ | ||
801 | .num_counters = ARCH_P4_MAX_CCCR, | ||
802 | .apic = 1, | ||
803 | .cntval_bits = 40, | ||
804 | .cntval_mask = (1ULL << 40) - 1, | ||
805 | .max_period = (1ULL << 39) - 1, | ||
806 | .hw_config = p4_hw_config, | ||
807 | .schedule_events = p4_pmu_schedule_events, | ||
808 | }; | ||
809 | |||
810 | static __init int p4_pmu_init(void) | ||
811 | { | ||
812 | unsigned int low, high; | ||
813 | |||
814 | /* If we get stripped -- indexig fails */ | ||
815 | BUILD_BUG_ON(ARCH_P4_MAX_CCCR > X86_PMC_MAX_GENERIC); | ||
816 | |||
817 | rdmsr(MSR_IA32_MISC_ENABLE, low, high); | ||
818 | if (!(low & (1 << 7))) { | ||
819 | pr_cont("unsupported Netburst CPU model %d ", | ||
820 | boot_cpu_data.x86_model); | ||
821 | return -ENODEV; | ||
822 | } | ||
823 | |||
824 | memcpy(hw_cache_event_ids, p4_hw_cache_event_ids, | ||
825 | sizeof(hw_cache_event_ids)); | ||
826 | |||
827 | pr_cont("Netburst events, "); | ||
828 | |||
829 | x86_pmu = p4_pmu; | ||
830 | |||
831 | return 0; | ||
832 | } | ||
833 | |||
834 | #endif /* CONFIG_CPU_SUP_INTEL */ | ||
diff --git a/arch/x86/kernel/cpu/perf_event_p6.c b/arch/x86/kernel/cpu/perf_event_p6.c index a330485d14d..34ba07be2cd 100644 --- a/arch/x86/kernel/cpu/perf_event_p6.c +++ b/arch/x86/kernel/cpu/perf_event_p6.c | |||
@@ -27,24 +27,6 @@ static u64 p6_pmu_event_map(int hw_event) | |||
27 | */ | 27 | */ |
28 | #define P6_NOP_EVENT 0x0000002EULL | 28 | #define P6_NOP_EVENT 0x0000002EULL |
29 | 29 | ||
30 | static u64 p6_pmu_raw_event(u64 hw_event) | ||
31 | { | ||
32 | #define P6_EVNTSEL_EVENT_MASK 0x000000FFULL | ||
33 | #define P6_EVNTSEL_UNIT_MASK 0x0000FF00ULL | ||
34 | #define P6_EVNTSEL_EDGE_MASK 0x00040000ULL | ||
35 | #define P6_EVNTSEL_INV_MASK 0x00800000ULL | ||
36 | #define P6_EVNTSEL_REG_MASK 0xFF000000ULL | ||
37 | |||
38 | #define P6_EVNTSEL_MASK \ | ||
39 | (P6_EVNTSEL_EVENT_MASK | \ | ||
40 | P6_EVNTSEL_UNIT_MASK | \ | ||
41 | P6_EVNTSEL_EDGE_MASK | \ | ||
42 | P6_EVNTSEL_INV_MASK | \ | ||
43 | P6_EVNTSEL_REG_MASK) | ||
44 | |||
45 | return hw_event & P6_EVNTSEL_MASK; | ||
46 | } | ||
47 | |||
48 | static struct event_constraint p6_event_constraints[] = | 30 | static struct event_constraint p6_event_constraints[] = |
49 | { | 31 | { |
50 | INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FLOPS */ | 32 | INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FLOPS */ |
@@ -66,7 +48,7 @@ static void p6_pmu_disable_all(void) | |||
66 | wrmsrl(MSR_P6_EVNTSEL0, val); | 48 | wrmsrl(MSR_P6_EVNTSEL0, val); |
67 | } | 49 | } |
68 | 50 | ||
69 | static void p6_pmu_enable_all(void) | 51 | static void p6_pmu_enable_all(int added) |
70 | { | 52 | { |
71 | unsigned long val; | 53 | unsigned long val; |
72 | 54 | ||
@@ -102,22 +84,23 @@ static void p6_pmu_enable_event(struct perf_event *event) | |||
102 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, val); | 84 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, val); |
103 | } | 85 | } |
104 | 86 | ||
105 | static __initconst struct x86_pmu p6_pmu = { | 87 | static __initconst const struct x86_pmu p6_pmu = { |
106 | .name = "p6", | 88 | .name = "p6", |
107 | .handle_irq = x86_pmu_handle_irq, | 89 | .handle_irq = x86_pmu_handle_irq, |
108 | .disable_all = p6_pmu_disable_all, | 90 | .disable_all = p6_pmu_disable_all, |
109 | .enable_all = p6_pmu_enable_all, | 91 | .enable_all = p6_pmu_enable_all, |
110 | .enable = p6_pmu_enable_event, | 92 | .enable = p6_pmu_enable_event, |
111 | .disable = p6_pmu_disable_event, | 93 | .disable = p6_pmu_disable_event, |
94 | .hw_config = x86_pmu_hw_config, | ||
95 | .schedule_events = x86_schedule_events, | ||
112 | .eventsel = MSR_P6_EVNTSEL0, | 96 | .eventsel = MSR_P6_EVNTSEL0, |
113 | .perfctr = MSR_P6_PERFCTR0, | 97 | .perfctr = MSR_P6_PERFCTR0, |
114 | .event_map = p6_pmu_event_map, | 98 | .event_map = p6_pmu_event_map, |
115 | .raw_event = p6_pmu_raw_event, | ||
116 | .max_events = ARRAY_SIZE(p6_perfmon_event_map), | 99 | .max_events = ARRAY_SIZE(p6_perfmon_event_map), |
117 | .apic = 1, | 100 | .apic = 1, |
118 | .max_period = (1ULL << 31) - 1, | 101 | .max_period = (1ULL << 31) - 1, |
119 | .version = 0, | 102 | .version = 0, |
120 | .num_events = 2, | 103 | .num_counters = 2, |
121 | /* | 104 | /* |
122 | * Events have 40 bits implemented. However they are designed such | 105 | * Events have 40 bits implemented. However they are designed such |
123 | * that bits [32-39] are sign extensions of bit 31. As such the | 106 | * that bits [32-39] are sign extensions of bit 31. As such the |
@@ -125,8 +108,8 @@ static __initconst struct x86_pmu p6_pmu = { | |||
125 | * | 108 | * |
126 | * See IA-32 Intel Architecture Software developer manual Vol 3B | 109 | * See IA-32 Intel Architecture Software developer manual Vol 3B |
127 | */ | 110 | */ |
128 | .event_bits = 32, | 111 | .cntval_bits = 32, |
129 | .event_mask = (1ULL << 32) - 1, | 112 | .cntval_mask = (1ULL << 32) - 1, |
130 | .get_event_constraints = x86_get_event_constraints, | 113 | .get_event_constraints = x86_get_event_constraints, |
131 | .event_constraints = p6_event_constraints, | 114 | .event_constraints = p6_event_constraints, |
132 | }; | 115 | }; |
diff --git a/arch/x86/kernel/ds.c b/arch/x86/kernel/ds.c deleted file mode 100644 index 1c47390dd0e..00000000000 --- a/arch/x86/kernel/ds.c +++ /dev/null | |||
@@ -1,1437 +0,0 @@ | |||
1 | /* | ||
2 | * Debug Store support | ||
3 | * | ||
4 | * This provides a low-level interface to the hardware's Debug Store | ||
5 | * feature that is used for branch trace store (BTS) and | ||
6 | * precise-event based sampling (PEBS). | ||
7 | * | ||
8 | * It manages: | ||
9 | * - DS and BTS hardware configuration | ||
10 | * - buffer overflow handling (to be done) | ||
11 | * - buffer access | ||
12 | * | ||
13 | * It does not do: | ||
14 | * - security checking (is the caller allowed to trace the task) | ||
15 | * - buffer allocation (memory accounting) | ||
16 | * | ||
17 | * | ||
18 | * Copyright (C) 2007-2009 Intel Corporation. | ||
19 | * Markus Metzger <markus.t.metzger@intel.com>, 2007-2009 | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/string.h> | ||
24 | #include <linux/errno.h> | ||
25 | #include <linux/sched.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/mm.h> | ||
28 | #include <linux/trace_clock.h> | ||
29 | |||
30 | #include <asm/ds.h> | ||
31 | |||
32 | #include "ds_selftest.h" | ||
33 | |||
34 | /* | ||
35 | * The configuration for a particular DS hardware implementation: | ||
36 | */ | ||
37 | struct ds_configuration { | ||
38 | /* The name of the configuration: */ | ||
39 | const char *name; | ||
40 | |||
41 | /* The size of pointer-typed fields in DS, BTS, and PEBS: */ | ||
42 | unsigned char sizeof_ptr_field; | ||
43 | |||
44 | /* The size of a BTS/PEBS record in bytes: */ | ||
45 | unsigned char sizeof_rec[2]; | ||
46 | |||
47 | /* The number of pebs counter reset values in the DS structure. */ | ||
48 | unsigned char nr_counter_reset; | ||
49 | |||
50 | /* Control bit-masks indexed by enum ds_feature: */ | ||
51 | unsigned long ctl[dsf_ctl_max]; | ||
52 | }; | ||
53 | static struct ds_configuration ds_cfg __read_mostly; | ||
54 | |||
55 | |||
56 | /* Maximal size of a DS configuration: */ | ||
57 | #define MAX_SIZEOF_DS 0x80 | ||
58 | |||
59 | /* Maximal size of a BTS record: */ | ||
60 | #define MAX_SIZEOF_BTS (3 * 8) | ||
61 | |||
62 | /* BTS and PEBS buffer alignment: */ | ||
63 | #define DS_ALIGNMENT (1 << 3) | ||
64 | |||
65 | /* Number of buffer pointers in DS: */ | ||
66 | #define NUM_DS_PTR_FIELDS 8 | ||
67 | |||
68 | /* Size of a pebs reset value in DS: */ | ||
69 | #define PEBS_RESET_FIELD_SIZE 8 | ||
70 | |||
71 | /* Mask of control bits in the DS MSR register: */ | ||
72 | #define BTS_CONTROL \ | ||
73 | ( ds_cfg.ctl[dsf_bts] | \ | ||
74 | ds_cfg.ctl[dsf_bts_kernel] | \ | ||
75 | ds_cfg.ctl[dsf_bts_user] | \ | ||
76 | ds_cfg.ctl[dsf_bts_overflow] ) | ||
77 | |||
78 | /* | ||
79 | * A BTS or PEBS tracer. | ||
80 | * | ||
81 | * This holds the configuration of the tracer and serves as a handle | ||
82 | * to identify tracers. | ||
83 | */ | ||
84 | struct ds_tracer { | ||
85 | /* The DS context (partially) owned by this tracer. */ | ||
86 | struct ds_context *context; | ||
87 | /* The buffer provided on ds_request() and its size in bytes. */ | ||
88 | void *buffer; | ||
89 | size_t size; | ||
90 | }; | ||
91 | |||
92 | struct bts_tracer { | ||
93 | /* The common DS part: */ | ||
94 | struct ds_tracer ds; | ||
95 | |||
96 | /* The trace including the DS configuration: */ | ||
97 | struct bts_trace trace; | ||
98 | |||
99 | /* Buffer overflow notification function: */ | ||
100 | bts_ovfl_callback_t ovfl; | ||
101 | |||
102 | /* Active flags affecting trace collection. */ | ||
103 | unsigned int flags; | ||
104 | }; | ||
105 | |||
106 | struct pebs_tracer { | ||
107 | /* The common DS part: */ | ||
108 | struct ds_tracer ds; | ||
109 | |||
110 | /* The trace including the DS configuration: */ | ||
111 | struct pebs_trace trace; | ||
112 | |||
113 | /* Buffer overflow notification function: */ | ||
114 | pebs_ovfl_callback_t ovfl; | ||
115 | }; | ||
116 | |||
117 | /* | ||
118 | * Debug Store (DS) save area configuration (see Intel64 and IA32 | ||
119 | * Architectures Software Developer's Manual, section 18.5) | ||
120 | * | ||
121 | * The DS configuration consists of the following fields; different | ||
122 | * architetures vary in the size of those fields. | ||
123 | * | ||
124 | * - double-word aligned base linear address of the BTS buffer | ||
125 | * - write pointer into the BTS buffer | ||
126 | * - end linear address of the BTS buffer (one byte beyond the end of | ||
127 | * the buffer) | ||
128 | * - interrupt pointer into BTS buffer | ||
129 | * (interrupt occurs when write pointer passes interrupt pointer) | ||
130 | * - double-word aligned base linear address of the PEBS buffer | ||
131 | * - write pointer into the PEBS buffer | ||
132 | * - end linear address of the PEBS buffer (one byte beyond the end of | ||
133 | * the buffer) | ||
134 | * - interrupt pointer into PEBS buffer | ||
135 | * (interrupt occurs when write pointer passes interrupt pointer) | ||
136 | * - value to which counter is reset following counter overflow | ||
137 | * | ||
138 | * Later architectures use 64bit pointers throughout, whereas earlier | ||
139 | * architectures use 32bit pointers in 32bit mode. | ||
140 | * | ||
141 | * | ||
142 | * We compute the base address for the first 8 fields based on: | ||
143 | * - the field size stored in the DS configuration | ||
144 | * - the relative field position | ||
145 | * - an offset giving the start of the respective region | ||
146 | * | ||
147 | * This offset is further used to index various arrays holding | ||
148 | * information for BTS and PEBS at the respective index. | ||
149 | * | ||
150 | * On later 32bit processors, we only access the lower 32bit of the | ||
151 | * 64bit pointer fields. The upper halves will be zeroed out. | ||
152 | */ | ||
153 | |||
154 | enum ds_field { | ||
155 | ds_buffer_base = 0, | ||
156 | ds_index, | ||
157 | ds_absolute_maximum, | ||
158 | ds_interrupt_threshold, | ||
159 | }; | ||
160 | |||
161 | enum ds_qualifier { | ||
162 | ds_bts = 0, | ||
163 | ds_pebs | ||
164 | }; | ||
165 | |||
166 | static inline unsigned long | ||
167 | ds_get(const unsigned char *base, enum ds_qualifier qual, enum ds_field field) | ||
168 | { | ||
169 | base += (ds_cfg.sizeof_ptr_field * (field + (4 * qual))); | ||
170 | return *(unsigned long *)base; | ||
171 | } | ||
172 | |||
173 | static inline void | ||
174 | ds_set(unsigned char *base, enum ds_qualifier qual, enum ds_field field, | ||
175 | unsigned long value) | ||
176 | { | ||
177 | base += (ds_cfg.sizeof_ptr_field * (field + (4 * qual))); | ||
178 | (*(unsigned long *)base) = value; | ||
179 | } | ||
180 | |||
181 | |||
182 | /* | ||
183 | * Locking is done only for allocating BTS or PEBS resources. | ||
184 | */ | ||
185 | static DEFINE_SPINLOCK(ds_lock); | ||
186 | |||
187 | /* | ||
188 | * We either support (system-wide) per-cpu or per-thread allocation. | ||
189 | * We distinguish the two based on the task_struct pointer, where a | ||
190 | * NULL pointer indicates per-cpu allocation for the current cpu. | ||
191 | * | ||
192 | * Allocations are use-counted. As soon as resources are allocated, | ||
193 | * further allocations must be of the same type (per-cpu or | ||
194 | * per-thread). We model this by counting allocations (i.e. the number | ||
195 | * of tracers of a certain type) for one type negatively: | ||
196 | * =0 no tracers | ||
197 | * >0 number of per-thread tracers | ||
198 | * <0 number of per-cpu tracers | ||
199 | * | ||
200 | * Tracers essentially gives the number of ds contexts for a certain | ||
201 | * type of allocation. | ||
202 | */ | ||
203 | static atomic_t tracers = ATOMIC_INIT(0); | ||
204 | |||
205 | static inline int get_tracer(struct task_struct *task) | ||
206 | { | ||
207 | int error; | ||
208 | |||
209 | spin_lock_irq(&ds_lock); | ||
210 | |||
211 | if (task) { | ||
212 | error = -EPERM; | ||
213 | if (atomic_read(&tracers) < 0) | ||
214 | goto out; | ||
215 | atomic_inc(&tracers); | ||
216 | } else { | ||
217 | error = -EPERM; | ||
218 | if (atomic_read(&tracers) > 0) | ||
219 | goto out; | ||
220 | atomic_dec(&tracers); | ||
221 | } | ||
222 | |||
223 | error = 0; | ||
224 | out: | ||
225 | spin_unlock_irq(&ds_lock); | ||
226 | return error; | ||
227 | } | ||
228 | |||
229 | static inline void put_tracer(struct task_struct *task) | ||
230 | { | ||
231 | if (task) | ||
232 | atomic_dec(&tracers); | ||
233 | else | ||
234 | atomic_inc(&tracers); | ||
235 | } | ||
236 | |||
237 | /* | ||
238 | * The DS context is either attached to a thread or to a cpu: | ||
239 | * - in the former case, the thread_struct contains a pointer to the | ||
240 | * attached context. | ||
241 | * - in the latter case, we use a static array of per-cpu context | ||
242 | * pointers. | ||
243 | * | ||
244 | * Contexts are use-counted. They are allocated on first access and | ||
245 | * deallocated when the last user puts the context. | ||
246 | */ | ||
247 | struct ds_context { | ||
248 | /* The DS configuration; goes into MSR_IA32_DS_AREA: */ | ||
249 | unsigned char ds[MAX_SIZEOF_DS]; | ||
250 | |||
251 | /* The owner of the BTS and PEBS configuration, respectively: */ | ||
252 | struct bts_tracer *bts_master; | ||
253 | struct pebs_tracer *pebs_master; | ||
254 | |||
255 | /* Use count: */ | ||
256 | unsigned long count; | ||
257 | |||
258 | /* Pointer to the context pointer field: */ | ||
259 | struct ds_context **this; | ||
260 | |||
261 | /* The traced task; NULL for cpu tracing: */ | ||
262 | struct task_struct *task; | ||
263 | |||
264 | /* The traced cpu; only valid if task is NULL: */ | ||
265 | int cpu; | ||
266 | }; | ||
267 | |||
268 | static DEFINE_PER_CPU(struct ds_context *, cpu_ds_context); | ||
269 | |||
270 | |||
271 | static struct ds_context *ds_get_context(struct task_struct *task, int cpu) | ||
272 | { | ||
273 | struct ds_context **p_context = | ||
274 | (task ? &task->thread.ds_ctx : &per_cpu(cpu_ds_context, cpu)); | ||
275 | struct ds_context *context = NULL; | ||
276 | struct ds_context *new_context = NULL; | ||
277 | |||
278 | /* Chances are small that we already have a context. */ | ||
279 | new_context = kzalloc(sizeof(*new_context), GFP_KERNEL); | ||
280 | if (!new_context) | ||
281 | return NULL; | ||
282 | |||
283 | spin_lock_irq(&ds_lock); | ||
284 | |||
285 | context = *p_context; | ||
286 | if (likely(!context)) { | ||
287 | context = new_context; | ||
288 | |||
289 | context->this = p_context; | ||
290 | context->task = task; | ||
291 | context->cpu = cpu; | ||
292 | context->count = 0; | ||
293 | |||
294 | *p_context = context; | ||
295 | } | ||
296 | |||
297 | context->count++; | ||
298 | |||
299 | spin_unlock_irq(&ds_lock); | ||
300 | |||
301 | if (context != new_context) | ||
302 | kfree(new_context); | ||
303 | |||
304 | return context; | ||
305 | } | ||
306 | |||
307 | static void ds_put_context(struct ds_context *context) | ||
308 | { | ||
309 | struct task_struct *task; | ||
310 | unsigned long irq; | ||
311 | |||
312 | if (!context) | ||
313 | return; | ||
314 | |||
315 | spin_lock_irqsave(&ds_lock, irq); | ||
316 | |||
317 | if (--context->count) { | ||
318 | spin_unlock_irqrestore(&ds_lock, irq); | ||
319 | return; | ||
320 | } | ||
321 | |||
322 | *(context->this) = NULL; | ||
323 | |||
324 | task = context->task; | ||
325 | |||
326 | if (task) | ||
327 | clear_tsk_thread_flag(task, TIF_DS_AREA_MSR); | ||
328 | |||
329 | /* | ||
330 | * We leave the (now dangling) pointer to the DS configuration in | ||
331 | * the DS_AREA msr. This is as good or as bad as replacing it with | ||
332 | * NULL - the hardware would crash if we enabled tracing. | ||
333 | * | ||
334 | * This saves us some problems with having to write an msr on a | ||
335 | * different cpu while preventing others from doing the same for the | ||
336 | * next context for that same cpu. | ||
337 | */ | ||
338 | |||
339 | spin_unlock_irqrestore(&ds_lock, irq); | ||
340 | |||
341 | /* The context might still be in use for context switching. */ | ||
342 | if (task && (task != current)) | ||
343 | wait_task_context_switch(task); | ||
344 | |||
345 | kfree(context); | ||
346 | } | ||
347 | |||
348 | static void ds_install_ds_area(struct ds_context *context) | ||
349 | { | ||
350 | unsigned long ds; | ||
351 | |||
352 | ds = (unsigned long)context->ds; | ||
353 | |||
354 | /* | ||
355 | * There is a race between the bts master and the pebs master. | ||
356 | * | ||
357 | * The thread/cpu access is synchronized via get/put_cpu() for | ||
358 | * task tracing and via wrmsr_on_cpu for cpu tracing. | ||
359 | * | ||
360 | * If bts and pebs are collected for the same task or same cpu, | ||
361 | * the same confiuration is written twice. | ||
362 | */ | ||
363 | if (context->task) { | ||
364 | get_cpu(); | ||
365 | if (context->task == current) | ||
366 | wrmsrl(MSR_IA32_DS_AREA, ds); | ||
367 | set_tsk_thread_flag(context->task, TIF_DS_AREA_MSR); | ||
368 | put_cpu(); | ||
369 | } else | ||
370 | wrmsr_on_cpu(context->cpu, MSR_IA32_DS_AREA, | ||
371 | (u32)((u64)ds), (u32)((u64)ds >> 32)); | ||
372 | } | ||
373 | |||
374 | /* | ||
375 | * Call the tracer's callback on a buffer overflow. | ||
376 | * | ||
377 | * context: the ds context | ||
378 | * qual: the buffer type | ||
379 | */ | ||
380 | static void ds_overflow(struct ds_context *context, enum ds_qualifier qual) | ||
381 | { | ||
382 | switch (qual) { | ||
383 | case ds_bts: | ||
384 | if (context->bts_master && | ||
385 | context->bts_master->ovfl) | ||
386 | context->bts_master->ovfl(context->bts_master); | ||
387 | break; | ||
388 | case ds_pebs: | ||
389 | if (context->pebs_master && | ||
390 | context->pebs_master->ovfl) | ||
391 | context->pebs_master->ovfl(context->pebs_master); | ||
392 | break; | ||
393 | } | ||
394 | } | ||
395 | |||
396 | |||
397 | /* | ||
398 | * Write raw data into the BTS or PEBS buffer. | ||
399 | * | ||
400 | * The remainder of any partially written record is zeroed out. | ||
401 | * | ||
402 | * context: the DS context | ||
403 | * qual: the buffer type | ||
404 | * record: the data to write | ||
405 | * size: the size of the data | ||
406 | */ | ||
407 | static int ds_write(struct ds_context *context, enum ds_qualifier qual, | ||
408 | const void *record, size_t size) | ||
409 | { | ||
410 | int bytes_written = 0; | ||
411 | |||
412 | if (!record) | ||
413 | return -EINVAL; | ||
414 | |||
415 | while (size) { | ||
416 | unsigned long base, index, end, write_end, int_th; | ||
417 | unsigned long write_size, adj_write_size; | ||
418 | |||
419 | /* | ||
420 | * Write as much as possible without producing an | ||
421 | * overflow interrupt. | ||
422 | * | ||
423 | * Interrupt_threshold must either be | ||
424 | * - bigger than absolute_maximum or | ||
425 | * - point to a record between buffer_base and absolute_maximum | ||
426 | * | ||
427 | * Index points to a valid record. | ||
428 | */ | ||
429 | base = ds_get(context->ds, qual, ds_buffer_base); | ||
430 | index = ds_get(context->ds, qual, ds_index); | ||
431 | end = ds_get(context->ds, qual, ds_absolute_maximum); | ||
432 | int_th = ds_get(context->ds, qual, ds_interrupt_threshold); | ||
433 | |||
434 | write_end = min(end, int_th); | ||
435 | |||
436 | /* | ||
437 | * If we are already beyond the interrupt threshold, | ||
438 | * we fill the entire buffer. | ||
439 | */ | ||
440 | if (write_end <= index) | ||
441 | write_end = end; | ||
442 | |||
443 | if (write_end <= index) | ||
444 | break; | ||
445 | |||
446 | write_size = min((unsigned long) size, write_end - index); | ||
447 | memcpy((void *)index, record, write_size); | ||
448 | |||
449 | record = (const char *)record + write_size; | ||
450 | size -= write_size; | ||
451 | bytes_written += write_size; | ||
452 | |||
453 | adj_write_size = write_size / ds_cfg.sizeof_rec[qual]; | ||
454 | adj_write_size *= ds_cfg.sizeof_rec[qual]; | ||
455 | |||
456 | /* Zero out trailing bytes. */ | ||
457 | memset((char *)index + write_size, 0, | ||
458 | adj_write_size - write_size); | ||
459 | index += adj_write_size; | ||
460 | |||
461 | if (index >= end) | ||
462 | index = base; | ||
463 | ds_set(context->ds, qual, ds_index, index); | ||
464 | |||
465 | if (index >= int_th) | ||
466 | ds_overflow(context, qual); | ||
467 | } | ||
468 | |||
469 | return bytes_written; | ||
470 | } | ||
471 | |||
472 | |||
473 | /* | ||
474 | * Branch Trace Store (BTS) uses the following format. Different | ||
475 | * architectures vary in the size of those fields. | ||
476 | * - source linear address | ||
477 | * - destination linear address | ||
478 | * - flags | ||
479 | * | ||
480 | * Later architectures use 64bit pointers throughout, whereas earlier | ||
481 | * architectures use 32bit pointers in 32bit mode. | ||
482 | * | ||
483 | * We compute the base address for the fields based on: | ||
484 | * - the field size stored in the DS configuration | ||
485 | * - the relative field position | ||
486 | * | ||
487 | * In order to store additional information in the BTS buffer, we use | ||
488 | * a special source address to indicate that the record requires | ||
489 | * special interpretation. | ||
490 | * | ||
491 | * Netburst indicated via a bit in the flags field whether the branch | ||
492 | * was predicted; this is ignored. | ||
493 | * | ||
494 | * We use two levels of abstraction: | ||
495 | * - the raw data level defined here | ||
496 | * - an arch-independent level defined in ds.h | ||
497 | */ | ||
498 | |||
499 | enum bts_field { | ||
500 | bts_from, | ||
501 | bts_to, | ||
502 | bts_flags, | ||
503 | |||
504 | bts_qual = bts_from, | ||
505 | bts_clock = bts_to, | ||
506 | bts_pid = bts_flags, | ||
507 | |||
508 | bts_qual_mask = (bts_qual_max - 1), | ||
509 | bts_escape = ((unsigned long)-1 & ~bts_qual_mask) | ||
510 | }; | ||
511 | |||
512 | static inline unsigned long bts_get(const char *base, unsigned long field) | ||
513 | { | ||
514 | base += (ds_cfg.sizeof_ptr_field * field); | ||
515 | return *(unsigned long *)base; | ||
516 | } | ||
517 | |||
518 | static inline void bts_set(char *base, unsigned long field, unsigned long val) | ||
519 | { | ||
520 | base += (ds_cfg.sizeof_ptr_field * field); | ||
521 | (*(unsigned long *)base) = val; | ||
522 | } | ||
523 | |||
524 | |||
525 | /* | ||
526 | * The raw BTS data is architecture dependent. | ||
527 | * | ||
528 | * For higher-level users, we give an arch-independent view. | ||
529 | * - ds.h defines struct bts_struct | ||
530 | * - bts_read translates one raw bts record into a bts_struct | ||
531 | * - bts_write translates one bts_struct into the raw format and | ||
532 | * writes it into the top of the parameter tracer's buffer. | ||
533 | * | ||
534 | * return: bytes read/written on success; -Eerrno, otherwise | ||
535 | */ | ||
536 | static int | ||
537 | bts_read(struct bts_tracer *tracer, const void *at, struct bts_struct *out) | ||
538 | { | ||
539 | if (!tracer) | ||
540 | return -EINVAL; | ||
541 | |||
542 | if (at < tracer->trace.ds.begin) | ||
543 | return -EINVAL; | ||
544 | |||
545 | if (tracer->trace.ds.end < (at + tracer->trace.ds.size)) | ||
546 | return -EINVAL; | ||
547 | |||
548 | memset(out, 0, sizeof(*out)); | ||
549 | if ((bts_get(at, bts_qual) & ~bts_qual_mask) == bts_escape) { | ||
550 | out->qualifier = (bts_get(at, bts_qual) & bts_qual_mask); | ||
551 | out->variant.event.clock = bts_get(at, bts_clock); | ||
552 | out->variant.event.pid = bts_get(at, bts_pid); | ||
553 | } else { | ||
554 | out->qualifier = bts_branch; | ||
555 | out->variant.lbr.from = bts_get(at, bts_from); | ||
556 | out->variant.lbr.to = bts_get(at, bts_to); | ||
557 | |||
558 | if (!out->variant.lbr.from && !out->variant.lbr.to) | ||
559 | out->qualifier = bts_invalid; | ||
560 | } | ||
561 | |||
562 | return ds_cfg.sizeof_rec[ds_bts]; | ||
563 | } | ||
564 | |||
565 | static int bts_write(struct bts_tracer *tracer, const struct bts_struct *in) | ||
566 | { | ||
567 | unsigned char raw[MAX_SIZEOF_BTS]; | ||
568 | |||
569 | if (!tracer) | ||
570 | return -EINVAL; | ||
571 | |||
572 | if (MAX_SIZEOF_BTS < ds_cfg.sizeof_rec[ds_bts]) | ||
573 | return -EOVERFLOW; | ||
574 | |||
575 | switch (in->qualifier) { | ||
576 | case bts_invalid: | ||
577 | bts_set(raw, bts_from, 0); | ||
578 | bts_set(raw, bts_to, 0); | ||
579 | bts_set(raw, bts_flags, 0); | ||
580 | break; | ||
581 | case bts_branch: | ||
582 | bts_set(raw, bts_from, in->variant.lbr.from); | ||
583 | bts_set(raw, bts_to, in->variant.lbr.to); | ||
584 | bts_set(raw, bts_flags, 0); | ||
585 | break; | ||
586 | case bts_task_arrives: | ||
587 | case bts_task_departs: | ||
588 | bts_set(raw, bts_qual, (bts_escape | in->qualifier)); | ||
589 | bts_set(raw, bts_clock, in->variant.event.clock); | ||
590 | bts_set(raw, bts_pid, in->variant.event.pid); | ||
591 | break; | ||
592 | default: | ||
593 | return -EINVAL; | ||
594 | } | ||
595 | |||
596 | return ds_write(tracer->ds.context, ds_bts, raw, | ||
597 | ds_cfg.sizeof_rec[ds_bts]); | ||
598 | } | ||
599 | |||
600 | |||
601 | static void ds_write_config(struct ds_context *context, | ||
602 | struct ds_trace *cfg, enum ds_qualifier qual) | ||
603 | { | ||
604 | unsigned char *ds = context->ds; | ||
605 | |||
606 | ds_set(ds, qual, ds_buffer_base, (unsigned long)cfg->begin); | ||
607 | ds_set(ds, qual, ds_index, (unsigned long)cfg->top); | ||
608 | ds_set(ds, qual, ds_absolute_maximum, (unsigned long)cfg->end); | ||
609 | ds_set(ds, qual, ds_interrupt_threshold, (unsigned long)cfg->ith); | ||
610 | } | ||
611 | |||
612 | static void ds_read_config(struct ds_context *context, | ||
613 | struct ds_trace *cfg, enum ds_qualifier qual) | ||
614 | { | ||
615 | unsigned char *ds = context->ds; | ||
616 | |||
617 | cfg->begin = (void *)ds_get(ds, qual, ds_buffer_base); | ||
618 | cfg->top = (void *)ds_get(ds, qual, ds_index); | ||
619 | cfg->end = (void *)ds_get(ds, qual, ds_absolute_maximum); | ||
620 | cfg->ith = (void *)ds_get(ds, qual, ds_interrupt_threshold); | ||
621 | } | ||
622 | |||
623 | static void ds_init_ds_trace(struct ds_trace *trace, enum ds_qualifier qual, | ||
624 | void *base, size_t size, size_t ith, | ||
625 | unsigned int flags) { | ||
626 | unsigned long buffer, adj; | ||
627 | |||
628 | /* | ||
629 | * Adjust the buffer address and size to meet alignment | ||
630 | * constraints: | ||
631 | * - buffer is double-word aligned | ||
632 | * - size is multiple of record size | ||
633 | * | ||
634 | * We checked the size at the very beginning; we have enough | ||
635 | * space to do the adjustment. | ||
636 | */ | ||
637 | buffer = (unsigned long)base; | ||
638 | |||
639 | adj = ALIGN(buffer, DS_ALIGNMENT) - buffer; | ||
640 | buffer += adj; | ||
641 | size -= adj; | ||
642 | |||
643 | trace->n = size / ds_cfg.sizeof_rec[qual]; | ||
644 | trace->size = ds_cfg.sizeof_rec[qual]; | ||
645 | |||
646 | size = (trace->n * trace->size); | ||
647 | |||
648 | trace->begin = (void *)buffer; | ||
649 | trace->top = trace->begin; | ||
650 | trace->end = (void *)(buffer + size); | ||
651 | /* | ||
652 | * The value for 'no threshold' is -1, which will set the | ||
653 | * threshold outside of the buffer, just like we want it. | ||
654 | */ | ||
655 | ith *= ds_cfg.sizeof_rec[qual]; | ||
656 | trace->ith = (void *)(buffer + size - ith); | ||
657 | |||
658 | trace->flags = flags; | ||
659 | } | ||
660 | |||
661 | |||
662 | static int ds_request(struct ds_tracer *tracer, struct ds_trace *trace, | ||
663 | enum ds_qualifier qual, struct task_struct *task, | ||
664 | int cpu, void *base, size_t size, size_t th) | ||
665 | { | ||
666 | struct ds_context *context; | ||
667 | int error; | ||
668 | size_t req_size; | ||
669 | |||
670 | error = -EOPNOTSUPP; | ||
671 | if (!ds_cfg.sizeof_rec[qual]) | ||
672 | goto out; | ||
673 | |||
674 | error = -EINVAL; | ||
675 | if (!base) | ||
676 | goto out; | ||
677 | |||
678 | req_size = ds_cfg.sizeof_rec[qual]; | ||
679 | /* We might need space for alignment adjustments. */ | ||
680 | if (!IS_ALIGNED((unsigned long)base, DS_ALIGNMENT)) | ||
681 | req_size += DS_ALIGNMENT; | ||
682 | |||
683 | error = -EINVAL; | ||
684 | if (size < req_size) | ||
685 | goto out; | ||
686 | |||
687 | if (th != (size_t)-1) { | ||
688 | th *= ds_cfg.sizeof_rec[qual]; | ||
689 | |||
690 | error = -EINVAL; | ||
691 | if (size <= th) | ||
692 | goto out; | ||
693 | } | ||
694 | |||
695 | tracer->buffer = base; | ||
696 | tracer->size = size; | ||
697 | |||
698 | error = -ENOMEM; | ||
699 | context = ds_get_context(task, cpu); | ||
700 | if (!context) | ||
701 | goto out; | ||
702 | tracer->context = context; | ||
703 | |||
704 | /* | ||
705 | * Defer any tracer-specific initialization work for the context until | ||
706 | * context ownership has been clarified. | ||
707 | */ | ||
708 | |||
709 | error = 0; | ||
710 | out: | ||
711 | return error; | ||
712 | } | ||
713 | |||
714 | static struct bts_tracer *ds_request_bts(struct task_struct *task, int cpu, | ||
715 | void *base, size_t size, | ||
716 | bts_ovfl_callback_t ovfl, size_t th, | ||
717 | unsigned int flags) | ||
718 | { | ||
719 | struct bts_tracer *tracer; | ||
720 | int error; | ||
721 | |||
722 | /* Buffer overflow notification is not yet implemented. */ | ||
723 | error = -EOPNOTSUPP; | ||
724 | if (ovfl) | ||
725 | goto out; | ||
726 | |||
727 | error = get_tracer(task); | ||
728 | if (error < 0) | ||
729 | goto out; | ||
730 | |||
731 | error = -ENOMEM; | ||
732 | tracer = kzalloc(sizeof(*tracer), GFP_KERNEL); | ||
733 | if (!tracer) | ||
734 | goto out_put_tracer; | ||
735 | tracer->ovfl = ovfl; | ||
736 | |||
737 | /* Do some more error checking and acquire a tracing context. */ | ||
738 | error = ds_request(&tracer->ds, &tracer->trace.ds, | ||
739 | ds_bts, task, cpu, base, size, th); | ||
740 | if (error < 0) | ||
741 | goto out_tracer; | ||
742 | |||
743 | /* Claim the bts part of the tracing context we acquired above. */ | ||
744 | spin_lock_irq(&ds_lock); | ||
745 | |||
746 | error = -EPERM; | ||
747 | if (tracer->ds.context->bts_master) | ||
748 | goto out_unlock; | ||
749 | tracer->ds.context->bts_master = tracer; | ||
750 | |||
751 | spin_unlock_irq(&ds_lock); | ||
752 | |||
753 | /* | ||
754 | * Now that we own the bts part of the context, let's complete the | ||
755 | * initialization for that part. | ||
756 | */ | ||
757 | ds_init_ds_trace(&tracer->trace.ds, ds_bts, base, size, th, flags); | ||
758 | ds_write_config(tracer->ds.context, &tracer->trace.ds, ds_bts); | ||
759 | ds_install_ds_area(tracer->ds.context); | ||
760 | |||
761 | tracer->trace.read = bts_read; | ||
762 | tracer->trace.write = bts_write; | ||
763 | |||
764 | /* Start tracing. */ | ||
765 | ds_resume_bts(tracer); | ||
766 | |||
767 | return tracer; | ||
768 | |||
769 | out_unlock: | ||
770 | spin_unlock_irq(&ds_lock); | ||
771 | ds_put_context(tracer->ds.context); | ||
772 | out_tracer: | ||
773 | kfree(tracer); | ||
774 | out_put_tracer: | ||
775 | put_tracer(task); | ||
776 | out: | ||
777 | return ERR_PTR(error); | ||
778 | } | ||
779 | |||
780 | struct bts_tracer *ds_request_bts_task(struct task_struct *task, | ||
781 | void *base, size_t size, | ||
782 | bts_ovfl_callback_t ovfl, | ||
783 | size_t th, unsigned int flags) | ||
784 | { | ||
785 | return ds_request_bts(task, 0, base, size, ovfl, th, flags); | ||
786 | } | ||
787 | |||
788 | struct bts_tracer *ds_request_bts_cpu(int cpu, void *base, size_t size, | ||
789 | bts_ovfl_callback_t ovfl, | ||
790 | size_t th, unsigned int flags) | ||
791 | { | ||
792 | return ds_request_bts(NULL, cpu, base, size, ovfl, th, flags); | ||
793 | } | ||
794 | |||
795 | static struct pebs_tracer *ds_request_pebs(struct task_struct *task, int cpu, | ||
796 | void *base, size_t size, | ||
797 | pebs_ovfl_callback_t ovfl, size_t th, | ||
798 | unsigned int flags) | ||
799 | { | ||
800 | struct pebs_tracer *tracer; | ||
801 | int error; | ||
802 | |||
803 | /* Buffer overflow notification is not yet implemented. */ | ||
804 | error = -EOPNOTSUPP; | ||
805 | if (ovfl) | ||
806 | goto out; | ||
807 | |||
808 | error = get_tracer(task); | ||
809 | if (error < 0) | ||
810 | goto out; | ||
811 | |||
812 | error = -ENOMEM; | ||
813 | tracer = kzalloc(sizeof(*tracer), GFP_KERNEL); | ||
814 | if (!tracer) | ||
815 | goto out_put_tracer; | ||
816 | tracer->ovfl = ovfl; | ||
817 | |||
818 | /* Do some more error checking and acquire a tracing context. */ | ||
819 | error = ds_request(&tracer->ds, &tracer->trace.ds, | ||
820 | ds_pebs, task, cpu, base, size, th); | ||
821 | if (error < 0) | ||
822 | goto out_tracer; | ||
823 | |||
824 | /* Claim the pebs part of the tracing context we acquired above. */ | ||
825 | spin_lock_irq(&ds_lock); | ||
826 | |||
827 | error = -EPERM; | ||
828 | if (tracer->ds.context->pebs_master) | ||
829 | goto out_unlock; | ||
830 | tracer->ds.context->pebs_master = tracer; | ||
831 | |||
832 | spin_unlock_irq(&ds_lock); | ||
833 | |||
834 | /* | ||
835 | * Now that we own the pebs part of the context, let's complete the | ||
836 | * initialization for that part. | ||
837 | */ | ||
838 | ds_init_ds_trace(&tracer->trace.ds, ds_pebs, base, size, th, flags); | ||
839 | ds_write_config(tracer->ds.context, &tracer->trace.ds, ds_pebs); | ||
840 | ds_install_ds_area(tracer->ds.context); | ||
841 | |||
842 | /* Start tracing. */ | ||
843 | ds_resume_pebs(tracer); | ||
844 | |||
845 | return tracer; | ||
846 | |||
847 | out_unlock: | ||
848 | spin_unlock_irq(&ds_lock); | ||
849 | ds_put_context(tracer->ds.context); | ||
850 | out_tracer: | ||
851 | kfree(tracer); | ||
852 | out_put_tracer: | ||
853 | put_tracer(task); | ||
854 | out: | ||
855 | return ERR_PTR(error); | ||
856 | } | ||
857 | |||
858 | struct pebs_tracer *ds_request_pebs_task(struct task_struct *task, | ||
859 | void *base, size_t size, | ||
860 | pebs_ovfl_callback_t ovfl, | ||
861 | size_t th, unsigned int flags) | ||
862 | { | ||
863 | return ds_request_pebs(task, 0, base, size, ovfl, th, flags); | ||
864 | } | ||
865 | |||
866 | struct pebs_tracer *ds_request_pebs_cpu(int cpu, void *base, size_t size, | ||
867 | pebs_ovfl_callback_t ovfl, | ||
868 | size_t th, unsigned int flags) | ||
869 | { | ||
870 | return ds_request_pebs(NULL, cpu, base, size, ovfl, th, flags); | ||
871 | } | ||
872 | |||
873 | static void ds_free_bts(struct bts_tracer *tracer) | ||
874 | { | ||
875 | struct task_struct *task; | ||
876 | |||
877 | task = tracer->ds.context->task; | ||
878 | |||
879 | WARN_ON_ONCE(tracer->ds.context->bts_master != tracer); | ||
880 | tracer->ds.context->bts_master = NULL; | ||
881 | |||
882 | /* Make sure tracing stopped and the tracer is not in use. */ | ||
883 | if (task && (task != current)) | ||
884 | wait_task_context_switch(task); | ||
885 | |||
886 | ds_put_context(tracer->ds.context); | ||
887 | put_tracer(task); | ||
888 | |||
889 | kfree(tracer); | ||
890 | } | ||
891 | |||
892 | void ds_release_bts(struct bts_tracer *tracer) | ||
893 | { | ||
894 | might_sleep(); | ||
895 | |||
896 | if (!tracer) | ||
897 | return; | ||
898 | |||
899 | ds_suspend_bts(tracer); | ||
900 | ds_free_bts(tracer); | ||
901 | } | ||
902 | |||
903 | int ds_release_bts_noirq(struct bts_tracer *tracer) | ||
904 | { | ||
905 | struct task_struct *task; | ||
906 | unsigned long irq; | ||
907 | int error; | ||
908 | |||
909 | if (!tracer) | ||
910 | return 0; | ||
911 | |||
912 | task = tracer->ds.context->task; | ||
913 | |||
914 | local_irq_save(irq); | ||
915 | |||
916 | error = -EPERM; | ||
917 | if (!task && | ||
918 | (tracer->ds.context->cpu != smp_processor_id())) | ||
919 | goto out; | ||
920 | |||
921 | error = -EPERM; | ||
922 | if (task && (task != current)) | ||
923 | goto out; | ||
924 | |||
925 | ds_suspend_bts_noirq(tracer); | ||
926 | ds_free_bts(tracer); | ||
927 | |||
928 | error = 0; | ||
929 | out: | ||
930 | local_irq_restore(irq); | ||
931 | return error; | ||
932 | } | ||
933 | |||
934 | static void update_task_debugctlmsr(struct task_struct *task, | ||
935 | unsigned long debugctlmsr) | ||
936 | { | ||
937 | task->thread.debugctlmsr = debugctlmsr; | ||
938 | |||
939 | get_cpu(); | ||
940 | if (task == current) | ||
941 | update_debugctlmsr(debugctlmsr); | ||
942 | put_cpu(); | ||
943 | } | ||
944 | |||
945 | void ds_suspend_bts(struct bts_tracer *tracer) | ||
946 | { | ||
947 | struct task_struct *task; | ||
948 | unsigned long debugctlmsr; | ||
949 | int cpu; | ||
950 | |||
951 | if (!tracer) | ||
952 | return; | ||
953 | |||
954 | tracer->flags = 0; | ||
955 | |||
956 | task = tracer->ds.context->task; | ||
957 | cpu = tracer->ds.context->cpu; | ||
958 | |||
959 | WARN_ON(!task && irqs_disabled()); | ||
960 | |||
961 | debugctlmsr = (task ? | ||
962 | task->thread.debugctlmsr : | ||
963 | get_debugctlmsr_on_cpu(cpu)); | ||
964 | debugctlmsr &= ~BTS_CONTROL; | ||
965 | |||
966 | if (task) | ||
967 | update_task_debugctlmsr(task, debugctlmsr); | ||
968 | else | ||
969 | update_debugctlmsr_on_cpu(cpu, debugctlmsr); | ||
970 | } | ||
971 | |||
972 | int ds_suspend_bts_noirq(struct bts_tracer *tracer) | ||
973 | { | ||
974 | struct task_struct *task; | ||
975 | unsigned long debugctlmsr, irq; | ||
976 | int cpu, error = 0; | ||
977 | |||
978 | if (!tracer) | ||
979 | return 0; | ||
980 | |||
981 | tracer->flags = 0; | ||
982 | |||
983 | task = tracer->ds.context->task; | ||
984 | cpu = tracer->ds.context->cpu; | ||
985 | |||
986 | local_irq_save(irq); | ||
987 | |||
988 | error = -EPERM; | ||
989 | if (!task && (cpu != smp_processor_id())) | ||
990 | goto out; | ||
991 | |||
992 | debugctlmsr = (task ? | ||
993 | task->thread.debugctlmsr : | ||
994 | get_debugctlmsr()); | ||
995 | debugctlmsr &= ~BTS_CONTROL; | ||
996 | |||
997 | if (task) | ||
998 | update_task_debugctlmsr(task, debugctlmsr); | ||
999 | else | ||
1000 | update_debugctlmsr(debugctlmsr); | ||
1001 | |||
1002 | error = 0; | ||
1003 | out: | ||
1004 | local_irq_restore(irq); | ||
1005 | return error; | ||
1006 | } | ||
1007 | |||
1008 | static unsigned long ds_bts_control(struct bts_tracer *tracer) | ||
1009 | { | ||
1010 | unsigned long control; | ||
1011 | |||
1012 | control = ds_cfg.ctl[dsf_bts]; | ||
1013 | if (!(tracer->trace.ds.flags & BTS_KERNEL)) | ||
1014 | control |= ds_cfg.ctl[dsf_bts_kernel]; | ||
1015 | if (!(tracer->trace.ds.flags & BTS_USER)) | ||
1016 | control |= ds_cfg.ctl[dsf_bts_user]; | ||
1017 | |||
1018 | return control; | ||
1019 | } | ||
1020 | |||
1021 | void ds_resume_bts(struct bts_tracer *tracer) | ||
1022 | { | ||
1023 | struct task_struct *task; | ||
1024 | unsigned long debugctlmsr; | ||
1025 | int cpu; | ||
1026 | |||
1027 | if (!tracer) | ||
1028 | return; | ||
1029 | |||
1030 | tracer->flags = tracer->trace.ds.flags; | ||
1031 | |||
1032 | task = tracer->ds.context->task; | ||
1033 | cpu = tracer->ds.context->cpu; | ||
1034 | |||
1035 | WARN_ON(!task && irqs_disabled()); | ||
1036 | |||
1037 | debugctlmsr = (task ? | ||
1038 | task->thread.debugctlmsr : | ||
1039 | get_debugctlmsr_on_cpu(cpu)); | ||
1040 | debugctlmsr |= ds_bts_control(tracer); | ||
1041 | |||
1042 | if (task) | ||
1043 | update_task_debugctlmsr(task, debugctlmsr); | ||
1044 | else | ||
1045 | update_debugctlmsr_on_cpu(cpu, debugctlmsr); | ||
1046 | } | ||
1047 | |||
1048 | int ds_resume_bts_noirq(struct bts_tracer *tracer) | ||
1049 | { | ||
1050 | struct task_struct *task; | ||
1051 | unsigned long debugctlmsr, irq; | ||
1052 | int cpu, error = 0; | ||
1053 | |||
1054 | if (!tracer) | ||
1055 | return 0; | ||
1056 | |||
1057 | tracer->flags = tracer->trace.ds.flags; | ||
1058 | |||
1059 | task = tracer->ds.context->task; | ||
1060 | cpu = tracer->ds.context->cpu; | ||
1061 | |||
1062 | local_irq_save(irq); | ||
1063 | |||
1064 | error = -EPERM; | ||
1065 | if (!task && (cpu != smp_processor_id())) | ||
1066 | goto out; | ||
1067 | |||
1068 | debugctlmsr = (task ? | ||
1069 | task->thread.debugctlmsr : | ||
1070 | get_debugctlmsr()); | ||
1071 | debugctlmsr |= ds_bts_control(tracer); | ||
1072 | |||
1073 | if (task) | ||
1074 | update_task_debugctlmsr(task, debugctlmsr); | ||
1075 | else | ||
1076 | update_debugctlmsr(debugctlmsr); | ||
1077 | |||
1078 | error = 0; | ||
1079 | out: | ||
1080 | local_irq_restore(irq); | ||
1081 | return error; | ||
1082 | } | ||
1083 | |||
1084 | static void ds_free_pebs(struct pebs_tracer *tracer) | ||
1085 | { | ||
1086 | struct task_struct *task; | ||
1087 | |||
1088 | task = tracer->ds.context->task; | ||
1089 | |||
1090 | WARN_ON_ONCE(tracer->ds.context->pebs_master != tracer); | ||
1091 | tracer->ds.context->pebs_master = NULL; | ||
1092 | |||
1093 | ds_put_context(tracer->ds.context); | ||
1094 | put_tracer(task); | ||
1095 | |||
1096 | kfree(tracer); | ||
1097 | } | ||
1098 | |||
1099 | void ds_release_pebs(struct pebs_tracer *tracer) | ||
1100 | { | ||
1101 | might_sleep(); | ||
1102 | |||
1103 | if (!tracer) | ||
1104 | return; | ||
1105 | |||
1106 | ds_suspend_pebs(tracer); | ||
1107 | ds_free_pebs(tracer); | ||
1108 | } | ||
1109 | |||
1110 | int ds_release_pebs_noirq(struct pebs_tracer *tracer) | ||
1111 | { | ||
1112 | struct task_struct *task; | ||
1113 | unsigned long irq; | ||
1114 | int error; | ||
1115 | |||
1116 | if (!tracer) | ||
1117 | return 0; | ||
1118 | |||
1119 | task = tracer->ds.context->task; | ||
1120 | |||
1121 | local_irq_save(irq); | ||
1122 | |||
1123 | error = -EPERM; | ||
1124 | if (!task && | ||
1125 | (tracer->ds.context->cpu != smp_processor_id())) | ||
1126 | goto out; | ||
1127 | |||
1128 | error = -EPERM; | ||
1129 | if (task && (task != current)) | ||
1130 | goto out; | ||
1131 | |||
1132 | ds_suspend_pebs_noirq(tracer); | ||
1133 | ds_free_pebs(tracer); | ||
1134 | |||
1135 | error = 0; | ||
1136 | out: | ||
1137 | local_irq_restore(irq); | ||
1138 | return error; | ||
1139 | } | ||
1140 | |||
1141 | void ds_suspend_pebs(struct pebs_tracer *tracer) | ||
1142 | { | ||
1143 | |||
1144 | } | ||
1145 | |||
1146 | int ds_suspend_pebs_noirq(struct pebs_tracer *tracer) | ||
1147 | { | ||
1148 | return 0; | ||
1149 | } | ||
1150 | |||
1151 | void ds_resume_pebs(struct pebs_tracer *tracer) | ||
1152 | { | ||
1153 | |||
1154 | } | ||
1155 | |||
1156 | int ds_resume_pebs_noirq(struct pebs_tracer *tracer) | ||
1157 | { | ||
1158 | return 0; | ||
1159 | } | ||
1160 | |||
1161 | const struct bts_trace *ds_read_bts(struct bts_tracer *tracer) | ||
1162 | { | ||
1163 | if (!tracer) | ||
1164 | return NULL; | ||
1165 | |||
1166 | ds_read_config(tracer->ds.context, &tracer->trace.ds, ds_bts); | ||
1167 | return &tracer->trace; | ||
1168 | } | ||
1169 | |||
1170 | const struct pebs_trace *ds_read_pebs(struct pebs_tracer *tracer) | ||
1171 | { | ||
1172 | if (!tracer) | ||
1173 | return NULL; | ||
1174 | |||
1175 | ds_read_config(tracer->ds.context, &tracer->trace.ds, ds_pebs); | ||
1176 | |||
1177 | tracer->trace.counters = ds_cfg.nr_counter_reset; | ||
1178 | memcpy(tracer->trace.counter_reset, | ||
1179 | tracer->ds.context->ds + | ||
1180 | (NUM_DS_PTR_FIELDS * ds_cfg.sizeof_ptr_field), | ||
1181 | ds_cfg.nr_counter_reset * PEBS_RESET_FIELD_SIZE); | ||
1182 | |||
1183 | return &tracer->trace; | ||
1184 | } | ||
1185 | |||
1186 | int ds_reset_bts(struct bts_tracer *tracer) | ||
1187 | { | ||
1188 | if (!tracer) | ||
1189 | return -EINVAL; | ||
1190 | |||
1191 | tracer->trace.ds.top = tracer->trace.ds.begin; | ||
1192 | |||
1193 | ds_set(tracer->ds.context->ds, ds_bts, ds_index, | ||
1194 | (unsigned long)tracer->trace.ds.top); | ||
1195 | |||
1196 | return 0; | ||
1197 | } | ||
1198 | |||
1199 | int ds_reset_pebs(struct pebs_tracer *tracer) | ||
1200 | { | ||
1201 | if (!tracer) | ||
1202 | return -EINVAL; | ||
1203 | |||
1204 | tracer->trace.ds.top = tracer->trace.ds.begin; | ||
1205 | |||
1206 | ds_set(tracer->ds.context->ds, ds_pebs, ds_index, | ||
1207 | (unsigned long)tracer->trace.ds.top); | ||
1208 | |||
1209 | return 0; | ||
1210 | } | ||
1211 | |||
1212 | int ds_set_pebs_reset(struct pebs_tracer *tracer, | ||
1213 | unsigned int counter, u64 value) | ||
1214 | { | ||
1215 | if (!tracer) | ||
1216 | return -EINVAL; | ||
1217 | |||
1218 | if (ds_cfg.nr_counter_reset < counter) | ||
1219 | return -EINVAL; | ||
1220 | |||
1221 | *(u64 *)(tracer->ds.context->ds + | ||
1222 | (NUM_DS_PTR_FIELDS * ds_cfg.sizeof_ptr_field) + | ||
1223 | (counter * PEBS_RESET_FIELD_SIZE)) = value; | ||
1224 | |||
1225 | return 0; | ||
1226 | } | ||
1227 | |||
1228 | static const struct ds_configuration ds_cfg_netburst = { | ||
1229 | .name = "Netburst", | ||
1230 | .ctl[dsf_bts] = (1 << 2) | (1 << 3), | ||
1231 | .ctl[dsf_bts_kernel] = (1 << 5), | ||
1232 | .ctl[dsf_bts_user] = (1 << 6), | ||
1233 | .nr_counter_reset = 1, | ||
1234 | }; | ||
1235 | static const struct ds_configuration ds_cfg_pentium_m = { | ||
1236 | .name = "Pentium M", | ||
1237 | .ctl[dsf_bts] = (1 << 6) | (1 << 7), | ||
1238 | .nr_counter_reset = 1, | ||
1239 | }; | ||
1240 | static const struct ds_configuration ds_cfg_core2_atom = { | ||
1241 | .name = "Core 2/Atom", | ||
1242 | .ctl[dsf_bts] = (1 << 6) | (1 << 7), | ||
1243 | .ctl[dsf_bts_kernel] = (1 << 9), | ||
1244 | .ctl[dsf_bts_user] = (1 << 10), | ||
1245 | .nr_counter_reset = 1, | ||
1246 | }; | ||
1247 | static const struct ds_configuration ds_cfg_core_i7 = { | ||
1248 | .name = "Core i7", | ||
1249 | .ctl[dsf_bts] = (1 << 6) | (1 << 7), | ||
1250 | .ctl[dsf_bts_kernel] = (1 << 9), | ||
1251 | .ctl[dsf_bts_user] = (1 << 10), | ||
1252 | .nr_counter_reset = 4, | ||
1253 | }; | ||
1254 | |||
1255 | static void | ||
1256 | ds_configure(const struct ds_configuration *cfg, | ||
1257 | struct cpuinfo_x86 *cpu) | ||
1258 | { | ||
1259 | unsigned long nr_pebs_fields = 0; | ||
1260 | |||
1261 | printk(KERN_INFO "[ds] using %s configuration\n", cfg->name); | ||
1262 | |||
1263 | #ifdef __i386__ | ||
1264 | nr_pebs_fields = 10; | ||
1265 | #else | ||
1266 | nr_pebs_fields = 18; | ||
1267 | #endif | ||
1268 | |||
1269 | /* | ||
1270 | * Starting with version 2, architectural performance | ||
1271 | * monitoring supports a format specifier. | ||
1272 | */ | ||
1273 | if ((cpuid_eax(0xa) & 0xff) > 1) { | ||
1274 | unsigned long perf_capabilities, format; | ||
1275 | |||
1276 | rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_capabilities); | ||
1277 | |||
1278 | format = (perf_capabilities >> 8) & 0xf; | ||
1279 | |||
1280 | switch (format) { | ||
1281 | case 0: | ||
1282 | nr_pebs_fields = 18; | ||
1283 | break; | ||
1284 | case 1: | ||
1285 | nr_pebs_fields = 22; | ||
1286 | break; | ||
1287 | default: | ||
1288 | printk(KERN_INFO | ||
1289 | "[ds] unknown PEBS format: %lu\n", format); | ||
1290 | nr_pebs_fields = 0; | ||
1291 | break; | ||
1292 | } | ||
1293 | } | ||
1294 | |||
1295 | memset(&ds_cfg, 0, sizeof(ds_cfg)); | ||
1296 | ds_cfg = *cfg; | ||
1297 | |||
1298 | ds_cfg.sizeof_ptr_field = | ||
1299 | (cpu_has(cpu, X86_FEATURE_DTES64) ? 8 : 4); | ||
1300 | |||
1301 | ds_cfg.sizeof_rec[ds_bts] = ds_cfg.sizeof_ptr_field * 3; | ||
1302 | ds_cfg.sizeof_rec[ds_pebs] = ds_cfg.sizeof_ptr_field * nr_pebs_fields; | ||
1303 | |||
1304 | if (!cpu_has(cpu, X86_FEATURE_BTS)) { | ||
1305 | ds_cfg.sizeof_rec[ds_bts] = 0; | ||
1306 | printk(KERN_INFO "[ds] bts not available\n"); | ||
1307 | } | ||
1308 | if (!cpu_has(cpu, X86_FEATURE_PEBS)) { | ||
1309 | ds_cfg.sizeof_rec[ds_pebs] = 0; | ||
1310 | printk(KERN_INFO "[ds] pebs not available\n"); | ||
1311 | } | ||
1312 | |||
1313 | printk(KERN_INFO "[ds] sizes: address: %u bit, ", | ||
1314 | 8 * ds_cfg.sizeof_ptr_field); | ||
1315 | printk("bts/pebs record: %u/%u bytes\n", | ||
1316 | ds_cfg.sizeof_rec[ds_bts], ds_cfg.sizeof_rec[ds_pebs]); | ||
1317 | |||
1318 | WARN_ON_ONCE(MAX_PEBS_COUNTERS < ds_cfg.nr_counter_reset); | ||
1319 | } | ||
1320 | |||
1321 | void __cpuinit ds_init_intel(struct cpuinfo_x86 *c) | ||
1322 | { | ||
1323 | /* Only configure the first cpu. Others are identical. */ | ||
1324 | if (ds_cfg.name) | ||
1325 | return; | ||
1326 | |||
1327 | switch (c->x86) { | ||
1328 | case 0x6: | ||
1329 | switch (c->x86_model) { | ||
1330 | case 0x9: | ||
1331 | case 0xd: /* Pentium M */ | ||
1332 | ds_configure(&ds_cfg_pentium_m, c); | ||
1333 | break; | ||
1334 | case 0xf: | ||
1335 | case 0x17: /* Core2 */ | ||
1336 | case 0x1c: /* Atom */ | ||
1337 | ds_configure(&ds_cfg_core2_atom, c); | ||
1338 | break; | ||
1339 | case 0x1a: /* Core i7 */ | ||
1340 | ds_configure(&ds_cfg_core_i7, c); | ||
1341 | break; | ||
1342 | default: | ||
1343 | /* Sorry, don't know about them. */ | ||
1344 | break; | ||
1345 | } | ||
1346 | break; | ||
1347 | case 0xf: | ||
1348 | switch (c->x86_model) { | ||
1349 | case 0x0: | ||
1350 | case 0x1: | ||
1351 | case 0x2: /* Netburst */ | ||
1352 | ds_configure(&ds_cfg_netburst, c); | ||
1353 | break; | ||
1354 | default: | ||
1355 | /* Sorry, don't know about them. */ | ||
1356 | break; | ||
1357 | } | ||
1358 | break; | ||
1359 | default: | ||
1360 | /* Sorry, don't know about them. */ | ||
1361 | break; | ||
1362 | } | ||
1363 | } | ||
1364 | |||
1365 | static inline void ds_take_timestamp(struct ds_context *context, | ||
1366 | enum bts_qualifier qualifier, | ||
1367 | struct task_struct *task) | ||
1368 | { | ||
1369 | struct bts_tracer *tracer = context->bts_master; | ||
1370 | struct bts_struct ts; | ||
1371 | |||
1372 | /* Prevent compilers from reading the tracer pointer twice. */ | ||
1373 | barrier(); | ||
1374 | |||
1375 | if (!tracer || !(tracer->flags & BTS_TIMESTAMPS)) | ||
1376 | return; | ||
1377 | |||
1378 | memset(&ts, 0, sizeof(ts)); | ||
1379 | ts.qualifier = qualifier; | ||
1380 | ts.variant.event.clock = trace_clock_global(); | ||
1381 | ts.variant.event.pid = task->pid; | ||
1382 | |||
1383 | bts_write(tracer, &ts); | ||
1384 | } | ||
1385 | |||
1386 | /* | ||
1387 | * Change the DS configuration from tracing prev to tracing next. | ||
1388 | */ | ||
1389 | void ds_switch_to(struct task_struct *prev, struct task_struct *next) | ||
1390 | { | ||
1391 | struct ds_context *prev_ctx = prev->thread.ds_ctx; | ||
1392 | struct ds_context *next_ctx = next->thread.ds_ctx; | ||
1393 | unsigned long debugctlmsr = next->thread.debugctlmsr; | ||
1394 | |||
1395 | /* Make sure all data is read before we start. */ | ||
1396 | barrier(); | ||
1397 | |||
1398 | if (prev_ctx) { | ||
1399 | update_debugctlmsr(0); | ||
1400 | |||
1401 | ds_take_timestamp(prev_ctx, bts_task_departs, prev); | ||
1402 | } | ||
1403 | |||
1404 | if (next_ctx) { | ||
1405 | ds_take_timestamp(next_ctx, bts_task_arrives, next); | ||
1406 | |||
1407 | wrmsrl(MSR_IA32_DS_AREA, (unsigned long)next_ctx->ds); | ||
1408 | } | ||
1409 | |||
1410 | update_debugctlmsr(debugctlmsr); | ||
1411 | } | ||
1412 | |||
1413 | static __init int ds_selftest(void) | ||
1414 | { | ||
1415 | if (ds_cfg.sizeof_rec[ds_bts]) { | ||
1416 | int error; | ||
1417 | |||
1418 | error = ds_selftest_bts(); | ||
1419 | if (error) { | ||
1420 | WARN(1, "[ds] selftest failed. disabling bts.\n"); | ||
1421 | ds_cfg.sizeof_rec[ds_bts] = 0; | ||
1422 | } | ||
1423 | } | ||
1424 | |||
1425 | if (ds_cfg.sizeof_rec[ds_pebs]) { | ||
1426 | int error; | ||
1427 | |||
1428 | error = ds_selftest_pebs(); | ||
1429 | if (error) { | ||
1430 | WARN(1, "[ds] selftest failed. disabling pebs.\n"); | ||
1431 | ds_cfg.sizeof_rec[ds_pebs] = 0; | ||
1432 | } | ||
1433 | } | ||
1434 | |||
1435 | return 0; | ||
1436 | } | ||
1437 | device_initcall(ds_selftest); | ||
diff --git a/arch/x86/kernel/ds_selftest.c b/arch/x86/kernel/ds_selftest.c deleted file mode 100644 index 6bc7c199ab9..00000000000 --- a/arch/x86/kernel/ds_selftest.c +++ /dev/null | |||
@@ -1,408 +0,0 @@ | |||
1 | /* | ||
2 | * Debug Store support - selftest | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 2009 Intel Corporation. | ||
6 | * Markus Metzger <markus.t.metzger@intel.com>, 2009 | ||
7 | */ | ||
8 | |||
9 | #include "ds_selftest.h" | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/string.h> | ||
13 | #include <linux/smp.h> | ||
14 | #include <linux/cpu.h> | ||
15 | |||
16 | #include <asm/ds.h> | ||
17 | |||
18 | |||
19 | #define BUFFER_SIZE 521 /* Intentionally chose an odd size. */ | ||
20 | #define SMALL_BUFFER_SIZE 24 /* A single bts entry. */ | ||
21 | |||
22 | struct ds_selftest_bts_conf { | ||
23 | struct bts_tracer *tracer; | ||
24 | int error; | ||
25 | int (*suspend)(struct bts_tracer *); | ||
26 | int (*resume)(struct bts_tracer *); | ||
27 | }; | ||
28 | |||
29 | static int ds_selftest_bts_consistency(const struct bts_trace *trace) | ||
30 | { | ||
31 | int error = 0; | ||
32 | |||
33 | if (!trace) { | ||
34 | printk(KERN_CONT "failed to access trace..."); | ||
35 | /* Bail out. Other tests are pointless. */ | ||
36 | return -1; | ||
37 | } | ||
38 | |||
39 | if (!trace->read) { | ||
40 | printk(KERN_CONT "bts read not available..."); | ||
41 | error = -1; | ||
42 | } | ||
43 | |||
44 | /* Do some sanity checks on the trace configuration. */ | ||
45 | if (!trace->ds.n) { | ||
46 | printk(KERN_CONT "empty bts buffer..."); | ||
47 | error = -1; | ||
48 | } | ||
49 | if (!trace->ds.size) { | ||
50 | printk(KERN_CONT "bad bts trace setup..."); | ||
51 | error = -1; | ||
52 | } | ||
53 | if (trace->ds.end != | ||
54 | (char *)trace->ds.begin + (trace->ds.n * trace->ds.size)) { | ||
55 | printk(KERN_CONT "bad bts buffer setup..."); | ||
56 | error = -1; | ||
57 | } | ||
58 | /* | ||
59 | * We allow top in [begin; end], since its not clear when the | ||
60 | * overflow adjustment happens: after the increment or before the | ||
61 | * write. | ||
62 | */ | ||
63 | if ((trace->ds.top < trace->ds.begin) || | ||
64 | (trace->ds.end < trace->ds.top)) { | ||
65 | printk(KERN_CONT "bts top out of bounds..."); | ||
66 | error = -1; | ||
67 | } | ||
68 | |||
69 | return error; | ||
70 | } | ||
71 | |||
72 | static int ds_selftest_bts_read(struct bts_tracer *tracer, | ||
73 | const struct bts_trace *trace, | ||
74 | const void *from, const void *to) | ||
75 | { | ||
76 | const unsigned char *at; | ||
77 | |||
78 | /* | ||
79 | * Check a few things which do not belong to this test. | ||
80 | * They should be covered by other tests. | ||
81 | */ | ||
82 | if (!trace) | ||
83 | return -1; | ||
84 | |||
85 | if (!trace->read) | ||
86 | return -1; | ||
87 | |||
88 | if (to < from) | ||
89 | return -1; | ||
90 | |||
91 | if (from < trace->ds.begin) | ||
92 | return -1; | ||
93 | |||
94 | if (trace->ds.end < to) | ||
95 | return -1; | ||
96 | |||
97 | if (!trace->ds.size) | ||
98 | return -1; | ||
99 | |||
100 | /* Now to the test itself. */ | ||
101 | for (at = from; (void *)at < to; at += trace->ds.size) { | ||
102 | struct bts_struct bts; | ||
103 | unsigned long index; | ||
104 | int error; | ||
105 | |||
106 | if (((void *)at - trace->ds.begin) % trace->ds.size) { | ||
107 | printk(KERN_CONT | ||
108 | "read from non-integer index..."); | ||
109 | return -1; | ||
110 | } | ||
111 | index = ((void *)at - trace->ds.begin) / trace->ds.size; | ||
112 | |||
113 | memset(&bts, 0, sizeof(bts)); | ||
114 | error = trace->read(tracer, at, &bts); | ||
115 | if (error < 0) { | ||
116 | printk(KERN_CONT | ||
117 | "error reading bts trace at [%lu] (0x%p)...", | ||
118 | index, at); | ||
119 | return error; | ||
120 | } | ||
121 | |||
122 | switch (bts.qualifier) { | ||
123 | case BTS_BRANCH: | ||
124 | break; | ||
125 | default: | ||
126 | printk(KERN_CONT | ||
127 | "unexpected bts entry %llu at [%lu] (0x%p)...", | ||
128 | bts.qualifier, index, at); | ||
129 | return -1; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | static void ds_selftest_bts_cpu(void *arg) | ||
137 | { | ||
138 | struct ds_selftest_bts_conf *conf = arg; | ||
139 | const struct bts_trace *trace; | ||
140 | void *top; | ||
141 | |||
142 | if (IS_ERR(conf->tracer)) { | ||
143 | conf->error = PTR_ERR(conf->tracer); | ||
144 | conf->tracer = NULL; | ||
145 | |||
146 | printk(KERN_CONT | ||
147 | "initialization failed (err: %d)...", conf->error); | ||
148 | return; | ||
149 | } | ||
150 | |||
151 | /* We should meanwhile have enough trace. */ | ||
152 | conf->error = conf->suspend(conf->tracer); | ||
153 | if (conf->error < 0) | ||
154 | return; | ||
155 | |||
156 | /* Let's see if we can access the trace. */ | ||
157 | trace = ds_read_bts(conf->tracer); | ||
158 | |||
159 | conf->error = ds_selftest_bts_consistency(trace); | ||
160 | if (conf->error < 0) | ||
161 | return; | ||
162 | |||
163 | /* If everything went well, we should have a few trace entries. */ | ||
164 | if (trace->ds.top == trace->ds.begin) { | ||
165 | /* | ||
166 | * It is possible but highly unlikely that we got a | ||
167 | * buffer overflow and end up at exactly the same | ||
168 | * position we started from. | ||
169 | * Let's issue a warning, but continue. | ||
170 | */ | ||
171 | printk(KERN_CONT "no trace/overflow..."); | ||
172 | } | ||
173 | |||
174 | /* Let's try to read the trace we collected. */ | ||
175 | conf->error = | ||
176 | ds_selftest_bts_read(conf->tracer, trace, | ||
177 | trace->ds.begin, trace->ds.top); | ||
178 | if (conf->error < 0) | ||
179 | return; | ||
180 | |||
181 | /* | ||
182 | * Let's read the trace again. | ||
183 | * Since we suspended tracing, we should get the same result. | ||
184 | */ | ||
185 | top = trace->ds.top; | ||
186 | |||
187 | trace = ds_read_bts(conf->tracer); | ||
188 | conf->error = ds_selftest_bts_consistency(trace); | ||
189 | if (conf->error < 0) | ||
190 | return; | ||
191 | |||
192 | if (top != trace->ds.top) { | ||
193 | printk(KERN_CONT "suspend not working..."); | ||
194 | conf->error = -1; | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | /* Let's collect some more trace - see if resume is working. */ | ||
199 | conf->error = conf->resume(conf->tracer); | ||
200 | if (conf->error < 0) | ||
201 | return; | ||
202 | |||
203 | conf->error = conf->suspend(conf->tracer); | ||
204 | if (conf->error < 0) | ||
205 | return; | ||
206 | |||
207 | trace = ds_read_bts(conf->tracer); | ||
208 | |||
209 | conf->error = ds_selftest_bts_consistency(trace); | ||
210 | if (conf->error < 0) | ||
211 | return; | ||
212 | |||
213 | if (trace->ds.top == top) { | ||
214 | /* | ||
215 | * It is possible but highly unlikely that we got a | ||
216 | * buffer overflow and end up at exactly the same | ||
217 | * position we started from. | ||
218 | * Let's issue a warning and check the full trace. | ||
219 | */ | ||
220 | printk(KERN_CONT | ||
221 | "no resume progress/overflow..."); | ||
222 | |||
223 | conf->error = | ||
224 | ds_selftest_bts_read(conf->tracer, trace, | ||
225 | trace->ds.begin, trace->ds.end); | ||
226 | } else if (trace->ds.top < top) { | ||
227 | /* | ||
228 | * We had a buffer overflow - the entire buffer should | ||
229 | * contain trace records. | ||
230 | */ | ||
231 | conf->error = | ||
232 | ds_selftest_bts_read(conf->tracer, trace, | ||
233 | trace->ds.begin, trace->ds.end); | ||
234 | } else { | ||
235 | /* | ||
236 | * It is quite likely that the buffer did not overflow. | ||
237 | * Let's just check the delta trace. | ||
238 | */ | ||
239 | conf->error = | ||
240 | ds_selftest_bts_read(conf->tracer, trace, top, | ||
241 | trace->ds.top); | ||
242 | } | ||
243 | if (conf->error < 0) | ||
244 | return; | ||
245 | |||
246 | conf->error = 0; | ||
247 | } | ||
248 | |||
249 | static int ds_suspend_bts_wrap(struct bts_tracer *tracer) | ||
250 | { | ||
251 | ds_suspend_bts(tracer); | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | static int ds_resume_bts_wrap(struct bts_tracer *tracer) | ||
256 | { | ||
257 | ds_resume_bts(tracer); | ||
258 | return 0; | ||
259 | } | ||
260 | |||
261 | static void ds_release_bts_noirq_wrap(void *tracer) | ||
262 | { | ||
263 | (void)ds_release_bts_noirq(tracer); | ||
264 | } | ||
265 | |||
266 | static int ds_selftest_bts_bad_release_noirq(int cpu, | ||
267 | struct bts_tracer *tracer) | ||
268 | { | ||
269 | int error = -EPERM; | ||
270 | |||
271 | /* Try to release the tracer on the wrong cpu. */ | ||
272 | get_cpu(); | ||
273 | if (cpu != smp_processor_id()) { | ||
274 | error = ds_release_bts_noirq(tracer); | ||
275 | if (error != -EPERM) | ||
276 | printk(KERN_CONT "release on wrong cpu..."); | ||
277 | } | ||
278 | put_cpu(); | ||
279 | |||
280 | return error ? 0 : -1; | ||
281 | } | ||
282 | |||
283 | static int ds_selftest_bts_bad_request_cpu(int cpu, void *buffer) | ||
284 | { | ||
285 | struct bts_tracer *tracer; | ||
286 | int error; | ||
287 | |||
288 | /* Try to request cpu tracing while task tracing is active. */ | ||
289 | tracer = ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE, NULL, | ||
290 | (size_t)-1, BTS_KERNEL); | ||
291 | error = PTR_ERR(tracer); | ||
292 | if (!IS_ERR(tracer)) { | ||
293 | ds_release_bts(tracer); | ||
294 | error = 0; | ||
295 | } | ||
296 | |||
297 | if (error != -EPERM) | ||
298 | printk(KERN_CONT "cpu/task tracing overlap..."); | ||
299 | |||
300 | return error ? 0 : -1; | ||
301 | } | ||
302 | |||
303 | static int ds_selftest_bts_bad_request_task(void *buffer) | ||
304 | { | ||
305 | struct bts_tracer *tracer; | ||
306 | int error; | ||
307 | |||
308 | /* Try to request cpu tracing while task tracing is active. */ | ||
309 | tracer = ds_request_bts_task(current, buffer, BUFFER_SIZE, NULL, | ||
310 | (size_t)-1, BTS_KERNEL); | ||
311 | error = PTR_ERR(tracer); | ||
312 | if (!IS_ERR(tracer)) { | ||
313 | error = 0; | ||
314 | ds_release_bts(tracer); | ||
315 | } | ||
316 | |||
317 | if (error != -EPERM) | ||
318 | printk(KERN_CONT "task/cpu tracing overlap..."); | ||
319 | |||
320 | return error ? 0 : -1; | ||
321 | } | ||
322 | |||
323 | int ds_selftest_bts(void) | ||
324 | { | ||
325 | struct ds_selftest_bts_conf conf; | ||
326 | unsigned char buffer[BUFFER_SIZE], *small_buffer; | ||
327 | unsigned long irq; | ||
328 | int cpu; | ||
329 | |||
330 | printk(KERN_INFO "[ds] bts selftest..."); | ||
331 | conf.error = 0; | ||
332 | |||
333 | small_buffer = (unsigned char *)ALIGN((unsigned long)buffer, 8) + 8; | ||
334 | |||
335 | get_online_cpus(); | ||
336 | for_each_online_cpu(cpu) { | ||
337 | conf.suspend = ds_suspend_bts_wrap; | ||
338 | conf.resume = ds_resume_bts_wrap; | ||
339 | conf.tracer = | ||
340 | ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE, | ||
341 | NULL, (size_t)-1, BTS_KERNEL); | ||
342 | ds_selftest_bts_cpu(&conf); | ||
343 | if (conf.error >= 0) | ||
344 | conf.error = ds_selftest_bts_bad_request_task(buffer); | ||
345 | ds_release_bts(conf.tracer); | ||
346 | if (conf.error < 0) | ||
347 | goto out; | ||
348 | |||
349 | conf.suspend = ds_suspend_bts_noirq; | ||
350 | conf.resume = ds_resume_bts_noirq; | ||
351 | conf.tracer = | ||
352 | ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE, | ||
353 | NULL, (size_t)-1, BTS_KERNEL); | ||
354 | smp_call_function_single(cpu, ds_selftest_bts_cpu, &conf, 1); | ||
355 | if (conf.error >= 0) { | ||
356 | conf.error = | ||
357 | ds_selftest_bts_bad_release_noirq(cpu, | ||
358 | conf.tracer); | ||
359 | /* We must not release the tracer twice. */ | ||
360 | if (conf.error < 0) | ||
361 | conf.tracer = NULL; | ||
362 | } | ||
363 | if (conf.error >= 0) | ||
364 | conf.error = ds_selftest_bts_bad_request_task(buffer); | ||
365 | smp_call_function_single(cpu, ds_release_bts_noirq_wrap, | ||
366 | conf.tracer, 1); | ||
367 | if (conf.error < 0) | ||
368 | goto out; | ||
369 | } | ||
370 | |||
371 | conf.suspend = ds_suspend_bts_wrap; | ||
372 | conf.resume = ds_resume_bts_wrap; | ||
373 | conf.tracer = | ||
374 | ds_request_bts_task(current, buffer, BUFFER_SIZE, | ||
375 | NULL, (size_t)-1, BTS_KERNEL); | ||
376 | ds_selftest_bts_cpu(&conf); | ||
377 | if (conf.error >= 0) | ||
378 | conf.error = ds_selftest_bts_bad_request_cpu(0, buffer); | ||
379 | ds_release_bts(conf.tracer); | ||
380 | if (conf.error < 0) | ||
381 | goto out; | ||
382 | |||
383 | conf.suspend = ds_suspend_bts_noirq; | ||
384 | conf.resume = ds_resume_bts_noirq; | ||
385 | conf.tracer = | ||
386 | ds_request_bts_task(current, small_buffer, SMALL_BUFFER_SIZE, | ||
387 | NULL, (size_t)-1, BTS_KERNEL); | ||
388 | local_irq_save(irq); | ||
389 | ds_selftest_bts_cpu(&conf); | ||
390 | if (conf.error >= 0) | ||
391 | conf.error = ds_selftest_bts_bad_request_cpu(0, buffer); | ||
392 | ds_release_bts_noirq(conf.tracer); | ||
393 | local_irq_restore(irq); | ||
394 | if (conf.error < 0) | ||
395 | goto out; | ||
396 | |||
397 | conf.error = 0; | ||
398 | out: | ||
399 | put_online_cpus(); | ||
400 | printk(KERN_CONT "%s.\n", (conf.error ? "failed" : "passed")); | ||
401 | |||
402 | return conf.error; | ||
403 | } | ||
404 | |||
405 | int ds_selftest_pebs(void) | ||
406 | { | ||
407 | return 0; | ||
408 | } | ||
diff --git a/arch/x86/kernel/ds_selftest.h b/arch/x86/kernel/ds_selftest.h deleted file mode 100644 index 2ba8745c666..00000000000 --- a/arch/x86/kernel/ds_selftest.h +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | /* | ||
2 | * Debug Store support - selftest | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 2009 Intel Corporation. | ||
6 | * Markus Metzger <markus.t.metzger@intel.com>, 2009 | ||
7 | */ | ||
8 | |||
9 | #ifdef CONFIG_X86_DS_SELFTEST | ||
10 | extern int ds_selftest_bts(void); | ||
11 | extern int ds_selftest_pebs(void); | ||
12 | #else | ||
13 | static inline int ds_selftest_bts(void) { return 0; } | ||
14 | static inline int ds_selftest_pebs(void) { return 0; } | ||
15 | #endif | ||
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 6d817554780..c89a386930b 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c | |||
@@ -224,11 +224,6 @@ unsigned __kprobes long oops_begin(void) | |||
224 | int cpu; | 224 | int cpu; |
225 | unsigned long flags; | 225 | unsigned long flags; |
226 | 226 | ||
227 | /* notify the hw-branch tracer so it may disable tracing and | ||
228 | add the last trace to the trace buffer - | ||
229 | the earlier this happens, the more useful the trace. */ | ||
230 | trace_hw_branch_oops(); | ||
231 | |||
232 | oops_enter(); | 227 | oops_enter(); |
233 | 228 | ||
234 | /* racy, but better than risking deadlock. */ | 229 | /* racy, but better than risking deadlock. */ |
diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c index b43bbaebe2c..f2f56c0967b 100644 --- a/arch/x86/kernel/kprobes.c +++ b/arch/x86/kernel/kprobes.c | |||
@@ -422,14 +422,22 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs, | |||
422 | 422 | ||
423 | static void __kprobes clear_btf(void) | 423 | static void __kprobes clear_btf(void) |
424 | { | 424 | { |
425 | if (test_thread_flag(TIF_DEBUGCTLMSR)) | 425 | if (test_thread_flag(TIF_BLOCKSTEP)) { |
426 | update_debugctlmsr(0); | 426 | unsigned long debugctl = get_debugctlmsr(); |
427 | |||
428 | debugctl &= ~DEBUGCTLMSR_BTF; | ||
429 | update_debugctlmsr(debugctl); | ||
430 | } | ||
427 | } | 431 | } |
428 | 432 | ||
429 | static void __kprobes restore_btf(void) | 433 | static void __kprobes restore_btf(void) |
430 | { | 434 | { |
431 | if (test_thread_flag(TIF_DEBUGCTLMSR)) | 435 | if (test_thread_flag(TIF_BLOCKSTEP)) { |
432 | update_debugctlmsr(current->thread.debugctlmsr); | 436 | unsigned long debugctl = get_debugctlmsr(); |
437 | |||
438 | debugctl |= DEBUGCTLMSR_BTF; | ||
439 | update_debugctlmsr(debugctl); | ||
440 | } | ||
433 | } | 441 | } |
434 | 442 | ||
435 | void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri, | 443 | void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri, |
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 28ad9f4d8b9..eccdb57094e 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <asm/idle.h> | 20 | #include <asm/idle.h> |
21 | #include <asm/uaccess.h> | 21 | #include <asm/uaccess.h> |
22 | #include <asm/i387.h> | 22 | #include <asm/i387.h> |
23 | #include <asm/ds.h> | ||
24 | #include <asm/debugreg.h> | 23 | #include <asm/debugreg.h> |
25 | 24 | ||
26 | unsigned long idle_halt; | 25 | unsigned long idle_halt; |
@@ -50,8 +49,6 @@ void free_thread_xstate(struct task_struct *tsk) | |||
50 | kmem_cache_free(task_xstate_cachep, tsk->thread.xstate); | 49 | kmem_cache_free(task_xstate_cachep, tsk->thread.xstate); |
51 | tsk->thread.xstate = NULL; | 50 | tsk->thread.xstate = NULL; |
52 | } | 51 | } |
53 | |||
54 | WARN(tsk->thread.ds_ctx, "leaking DS context\n"); | ||
55 | } | 52 | } |
56 | 53 | ||
57 | void free_thread_info(struct thread_info *ti) | 54 | void free_thread_info(struct thread_info *ti) |
@@ -198,11 +195,16 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, | |||
198 | prev = &prev_p->thread; | 195 | prev = &prev_p->thread; |
199 | next = &next_p->thread; | 196 | next = &next_p->thread; |
200 | 197 | ||
201 | if (test_tsk_thread_flag(next_p, TIF_DS_AREA_MSR) || | 198 | if (test_tsk_thread_flag(prev_p, TIF_BLOCKSTEP) ^ |
202 | test_tsk_thread_flag(prev_p, TIF_DS_AREA_MSR)) | 199 | test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) { |
203 | ds_switch_to(prev_p, next_p); | 200 | unsigned long debugctl = get_debugctlmsr(); |
204 | else if (next->debugctlmsr != prev->debugctlmsr) | 201 | |
205 | update_debugctlmsr(next->debugctlmsr); | 202 | debugctl &= ~DEBUGCTLMSR_BTF; |
203 | if (test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) | ||
204 | debugctl |= DEBUGCTLMSR_BTF; | ||
205 | |||
206 | update_debugctlmsr(debugctl); | ||
207 | } | ||
206 | 208 | ||
207 | if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^ | 209 | if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^ |
208 | test_tsk_thread_flag(next_p, TIF_NOTSC)) { | 210 | test_tsk_thread_flag(next_p, TIF_NOTSC)) { |
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c index f6c62667e30..75090c589b7 100644 --- a/arch/x86/kernel/process_32.c +++ b/arch/x86/kernel/process_32.c | |||
@@ -55,7 +55,6 @@ | |||
55 | #include <asm/cpu.h> | 55 | #include <asm/cpu.h> |
56 | #include <asm/idle.h> | 56 | #include <asm/idle.h> |
57 | #include <asm/syscalls.h> | 57 | #include <asm/syscalls.h> |
58 | #include <asm/ds.h> | ||
59 | #include <asm/debugreg.h> | 58 | #include <asm/debugreg.h> |
60 | 59 | ||
61 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); | 60 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); |
@@ -238,13 +237,6 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, | |||
238 | kfree(p->thread.io_bitmap_ptr); | 237 | kfree(p->thread.io_bitmap_ptr); |
239 | p->thread.io_bitmap_max = 0; | 238 | p->thread.io_bitmap_max = 0; |
240 | } | 239 | } |
241 | |||
242 | clear_tsk_thread_flag(p, TIF_DS_AREA_MSR); | ||
243 | p->thread.ds_ctx = NULL; | ||
244 | |||
245 | clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR); | ||
246 | p->thread.debugctlmsr = 0; | ||
247 | |||
248 | return err; | 240 | return err; |
249 | } | 241 | } |
250 | 242 | ||
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index dc9690b4c4c..cc4258f2beb 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c | |||
@@ -49,7 +49,6 @@ | |||
49 | #include <asm/ia32.h> | 49 | #include <asm/ia32.h> |
50 | #include <asm/idle.h> | 50 | #include <asm/idle.h> |
51 | #include <asm/syscalls.h> | 51 | #include <asm/syscalls.h> |
52 | #include <asm/ds.h> | ||
53 | #include <asm/debugreg.h> | 52 | #include <asm/debugreg.h> |
54 | 53 | ||
55 | asmlinkage extern void ret_from_fork(void); | 54 | asmlinkage extern void ret_from_fork(void); |
@@ -313,13 +312,6 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, | |||
313 | if (err) | 312 | if (err) |
314 | goto out; | 313 | goto out; |
315 | } | 314 | } |
316 | |||
317 | clear_tsk_thread_flag(p, TIF_DS_AREA_MSR); | ||
318 | p->thread.ds_ctx = NULL; | ||
319 | |||
320 | clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR); | ||
321 | p->thread.debugctlmsr = 0; | ||
322 | |||
323 | err = 0; | 315 | err = 0; |
324 | out: | 316 | out: |
325 | if (err && p->thread.io_bitmap_ptr) { | 317 | if (err && p->thread.io_bitmap_ptr) { |
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index 2e9b55027b7..055be0afd33 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c | |||
@@ -2,9 +2,6 @@ | |||
2 | /* | 2 | /* |
3 | * Pentium III FXSR, SSE support | 3 | * Pentium III FXSR, SSE support |
4 | * Gareth Hughes <gareth@valinux.com>, May 2000 | 4 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
5 | * | ||
6 | * BTS tracing | ||
7 | * Markus Metzger <markus.t.metzger@intel.com>, Dec 2007 | ||
8 | */ | 5 | */ |
9 | 6 | ||
10 | #include <linux/kernel.h> | 7 | #include <linux/kernel.h> |
@@ -22,7 +19,6 @@ | |||
22 | #include <linux/audit.h> | 19 | #include <linux/audit.h> |
23 | #include <linux/seccomp.h> | 20 | #include <linux/seccomp.h> |
24 | #include <linux/signal.h> | 21 | #include <linux/signal.h> |
25 | #include <linux/workqueue.h> | ||
26 | #include <linux/perf_event.h> | 22 | #include <linux/perf_event.h> |
27 | #include <linux/hw_breakpoint.h> | 23 | #include <linux/hw_breakpoint.h> |
28 | 24 | ||
@@ -36,7 +32,6 @@ | |||
36 | #include <asm/desc.h> | 32 | #include <asm/desc.h> |
37 | #include <asm/prctl.h> | 33 | #include <asm/prctl.h> |
38 | #include <asm/proto.h> | 34 | #include <asm/proto.h> |
39 | #include <asm/ds.h> | ||
40 | #include <asm/hw_breakpoint.h> | 35 | #include <asm/hw_breakpoint.h> |
41 | 36 | ||
42 | #include "tls.h" | 37 | #include "tls.h" |
@@ -789,342 +784,6 @@ static int ioperm_get(struct task_struct *target, | |||
789 | 0, IO_BITMAP_BYTES); | 784 | 0, IO_BITMAP_BYTES); |
790 | } | 785 | } |
791 | 786 | ||
792 | #ifdef CONFIG_X86_PTRACE_BTS | ||
793 | /* | ||
794 | * A branch trace store context. | ||
795 | * | ||
796 | * Contexts may only be installed by ptrace_bts_config() and only for | ||
797 | * ptraced tasks. | ||
798 | * | ||
799 | * Contexts are destroyed when the tracee is detached from the tracer. | ||
800 | * The actual destruction work requires interrupts enabled, so the | ||
801 | * work is deferred and will be scheduled during __ptrace_unlink(). | ||
802 | * | ||
803 | * Contexts hold an additional task_struct reference on the traced | ||
804 | * task, as well as a reference on the tracer's mm. | ||
805 | * | ||
806 | * Ptrace already holds a task_struct for the duration of ptrace operations, | ||
807 | * but since destruction is deferred, it may be executed after both | ||
808 | * tracer and tracee exited. | ||
809 | */ | ||
810 | struct bts_context { | ||
811 | /* The branch trace handle. */ | ||
812 | struct bts_tracer *tracer; | ||
813 | |||
814 | /* The buffer used to store the branch trace and its size. */ | ||
815 | void *buffer; | ||
816 | unsigned int size; | ||
817 | |||
818 | /* The mm that paid for the above buffer. */ | ||
819 | struct mm_struct *mm; | ||
820 | |||
821 | /* The task this context belongs to. */ | ||
822 | struct task_struct *task; | ||
823 | |||
824 | /* The signal to send on a bts buffer overflow. */ | ||
825 | unsigned int bts_ovfl_signal; | ||
826 | |||
827 | /* The work struct to destroy a context. */ | ||
828 | struct work_struct work; | ||
829 | }; | ||
830 | |||
831 | static int alloc_bts_buffer(struct bts_context *context, unsigned int size) | ||
832 | { | ||
833 | void *buffer = NULL; | ||
834 | int err = -ENOMEM; | ||
835 | |||
836 | err = account_locked_memory(current->mm, current->signal->rlim, size); | ||
837 | if (err < 0) | ||
838 | return err; | ||
839 | |||
840 | buffer = kzalloc(size, GFP_KERNEL); | ||
841 | if (!buffer) | ||
842 | goto out_refund; | ||
843 | |||
844 | context->buffer = buffer; | ||
845 | context->size = size; | ||
846 | context->mm = get_task_mm(current); | ||
847 | |||
848 | return 0; | ||
849 | |||
850 | out_refund: | ||
851 | refund_locked_memory(current->mm, size); | ||
852 | return err; | ||
853 | } | ||
854 | |||
855 | static inline void free_bts_buffer(struct bts_context *context) | ||
856 | { | ||
857 | if (!context->buffer) | ||
858 | return; | ||
859 | |||
860 | kfree(context->buffer); | ||
861 | context->buffer = NULL; | ||
862 | |||
863 | refund_locked_memory(context->mm, context->size); | ||
864 | context->size = 0; | ||
865 | |||
866 | mmput(context->mm); | ||
867 | context->mm = NULL; | ||
868 | } | ||
869 | |||
870 | static void free_bts_context_work(struct work_struct *w) | ||
871 | { | ||
872 | struct bts_context *context; | ||
873 | |||
874 | context = container_of(w, struct bts_context, work); | ||
875 | |||
876 | ds_release_bts(context->tracer); | ||
877 | put_task_struct(context->task); | ||
878 | free_bts_buffer(context); | ||
879 | kfree(context); | ||
880 | } | ||
881 | |||
882 | static inline void free_bts_context(struct bts_context *context) | ||
883 | { | ||
884 | INIT_WORK(&context->work, free_bts_context_work); | ||
885 | schedule_work(&context->work); | ||
886 | } | ||
887 | |||
888 | static inline struct bts_context *alloc_bts_context(struct task_struct *task) | ||
889 | { | ||
890 | struct bts_context *context = kzalloc(sizeof(*context), GFP_KERNEL); | ||
891 | if (context) { | ||
892 | context->task = task; | ||
893 | task->bts = context; | ||
894 | |||
895 | get_task_struct(task); | ||
896 | } | ||
897 | |||
898 | return context; | ||
899 | } | ||
900 | |||
901 | static int ptrace_bts_read_record(struct task_struct *child, size_t index, | ||
902 | struct bts_struct __user *out) | ||
903 | { | ||
904 | struct bts_context *context; | ||
905 | const struct bts_trace *trace; | ||
906 | struct bts_struct bts; | ||
907 | const unsigned char *at; | ||
908 | int error; | ||
909 | |||
910 | context = child->bts; | ||
911 | if (!context) | ||
912 | return -ESRCH; | ||
913 | |||
914 | trace = ds_read_bts(context->tracer); | ||
915 | if (!trace) | ||
916 | return -ESRCH; | ||
917 | |||
918 | at = trace->ds.top - ((index + 1) * trace->ds.size); | ||
919 | if ((void *)at < trace->ds.begin) | ||
920 | at += (trace->ds.n * trace->ds.size); | ||
921 | |||
922 | if (!trace->read) | ||
923 | return -EOPNOTSUPP; | ||
924 | |||
925 | error = trace->read(context->tracer, at, &bts); | ||
926 | if (error < 0) | ||
927 | return error; | ||
928 | |||
929 | if (copy_to_user(out, &bts, sizeof(bts))) | ||
930 | return -EFAULT; | ||
931 | |||
932 | return sizeof(bts); | ||
933 | } | ||
934 | |||
935 | static int ptrace_bts_drain(struct task_struct *child, | ||
936 | long size, | ||
937 | struct bts_struct __user *out) | ||
938 | { | ||
939 | struct bts_context *context; | ||
940 | const struct bts_trace *trace; | ||
941 | const unsigned char *at; | ||
942 | int error, drained = 0; | ||
943 | |||
944 | context = child->bts; | ||
945 | if (!context) | ||
946 | return -ESRCH; | ||
947 | |||
948 | trace = ds_read_bts(context->tracer); | ||
949 | if (!trace) | ||
950 | return -ESRCH; | ||
951 | |||
952 | if (!trace->read) | ||
953 | return -EOPNOTSUPP; | ||
954 | |||
955 | if (size < (trace->ds.top - trace->ds.begin)) | ||
956 | return -EIO; | ||
957 | |||
958 | for (at = trace->ds.begin; (void *)at < trace->ds.top; | ||
959 | out++, drained++, at += trace->ds.size) { | ||
960 | struct bts_struct bts; | ||
961 | |||
962 | error = trace->read(context->tracer, at, &bts); | ||
963 | if (error < 0) | ||
964 | return error; | ||
965 | |||
966 | if (copy_to_user(out, &bts, sizeof(bts))) | ||
967 | return -EFAULT; | ||
968 | } | ||
969 | |||
970 | memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size); | ||
971 | |||
972 | error = ds_reset_bts(context->tracer); | ||
973 | if (error < 0) | ||
974 | return error; | ||
975 | |||
976 | return drained; | ||
977 | } | ||
978 | |||
979 | static int ptrace_bts_config(struct task_struct *child, | ||
980 | long cfg_size, | ||
981 | const struct ptrace_bts_config __user *ucfg) | ||
982 | { | ||
983 | struct bts_context *context; | ||
984 | struct ptrace_bts_config cfg; | ||
985 | unsigned int flags = 0; | ||
986 | |||
987 | if (cfg_size < sizeof(cfg)) | ||
988 | return -EIO; | ||
989 | |||
990 | if (copy_from_user(&cfg, ucfg, sizeof(cfg))) | ||
991 | return -EFAULT; | ||
992 | |||
993 | context = child->bts; | ||
994 | if (!context) | ||
995 | context = alloc_bts_context(child); | ||
996 | if (!context) | ||
997 | return -ENOMEM; | ||
998 | |||
999 | if (cfg.flags & PTRACE_BTS_O_SIGNAL) { | ||
1000 | if (!cfg.signal) | ||
1001 | return -EINVAL; | ||
1002 | |||
1003 | return -EOPNOTSUPP; | ||
1004 | context->bts_ovfl_signal = cfg.signal; | ||
1005 | } | ||
1006 | |||
1007 | ds_release_bts(context->tracer); | ||
1008 | context->tracer = NULL; | ||
1009 | |||
1010 | if ((cfg.flags & PTRACE_BTS_O_ALLOC) && (cfg.size != context->size)) { | ||
1011 | int err; | ||
1012 | |||
1013 | free_bts_buffer(context); | ||
1014 | if (!cfg.size) | ||
1015 | return 0; | ||
1016 | |||
1017 | err = alloc_bts_buffer(context, cfg.size); | ||
1018 | if (err < 0) | ||
1019 | return err; | ||
1020 | } | ||
1021 | |||
1022 | if (cfg.flags & PTRACE_BTS_O_TRACE) | ||
1023 | flags |= BTS_USER; | ||
1024 | |||
1025 | if (cfg.flags & PTRACE_BTS_O_SCHED) | ||
1026 | flags |= BTS_TIMESTAMPS; | ||
1027 | |||
1028 | context->tracer = | ||
1029 | ds_request_bts_task(child, context->buffer, context->size, | ||
1030 | NULL, (size_t)-1, flags); | ||
1031 | if (unlikely(IS_ERR(context->tracer))) { | ||
1032 | int error = PTR_ERR(context->tracer); | ||
1033 | |||
1034 | free_bts_buffer(context); | ||
1035 | context->tracer = NULL; | ||
1036 | return error; | ||
1037 | } | ||
1038 | |||
1039 | return sizeof(cfg); | ||
1040 | } | ||
1041 | |||
1042 | static int ptrace_bts_status(struct task_struct *child, | ||
1043 | long cfg_size, | ||
1044 | struct ptrace_bts_config __user *ucfg) | ||
1045 | { | ||
1046 | struct bts_context *context; | ||
1047 | const struct bts_trace *trace; | ||
1048 | struct ptrace_bts_config cfg; | ||
1049 | |||
1050 | context = child->bts; | ||
1051 | if (!context) | ||
1052 | return -ESRCH; | ||
1053 | |||
1054 | if (cfg_size < sizeof(cfg)) | ||
1055 | return -EIO; | ||
1056 | |||
1057 | trace = ds_read_bts(context->tracer); | ||
1058 | if (!trace) | ||
1059 | return -ESRCH; | ||
1060 | |||
1061 | memset(&cfg, 0, sizeof(cfg)); | ||
1062 | cfg.size = trace->ds.end - trace->ds.begin; | ||
1063 | cfg.signal = context->bts_ovfl_signal; | ||
1064 | cfg.bts_size = sizeof(struct bts_struct); | ||
1065 | |||
1066 | if (cfg.signal) | ||
1067 | cfg.flags |= PTRACE_BTS_O_SIGNAL; | ||
1068 | |||
1069 | if (trace->ds.flags & BTS_USER) | ||
1070 | cfg.flags |= PTRACE_BTS_O_TRACE; | ||
1071 | |||
1072 | if (trace->ds.flags & BTS_TIMESTAMPS) | ||
1073 | cfg.flags |= PTRACE_BTS_O_SCHED; | ||
1074 | |||
1075 | if (copy_to_user(ucfg, &cfg, sizeof(cfg))) | ||
1076 | return -EFAULT; | ||
1077 | |||
1078 | return sizeof(cfg); | ||
1079 | } | ||
1080 | |||
1081 | static int ptrace_bts_clear(struct task_struct *child) | ||
1082 | { | ||
1083 | struct bts_context *context; | ||
1084 | const struct bts_trace *trace; | ||
1085 | |||
1086 | context = child->bts; | ||
1087 | if (!context) | ||
1088 | return -ESRCH; | ||
1089 | |||
1090 | trace = ds_read_bts(context->tracer); | ||
1091 | if (!trace) | ||
1092 | return -ESRCH; | ||
1093 | |||
1094 | memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size); | ||
1095 | |||
1096 | return ds_reset_bts(context->tracer); | ||
1097 | } | ||
1098 | |||
1099 | static int ptrace_bts_size(struct task_struct *child) | ||
1100 | { | ||
1101 | struct bts_context *context; | ||
1102 | const struct bts_trace *trace; | ||
1103 | |||
1104 | context = child->bts; | ||
1105 | if (!context) | ||
1106 | return -ESRCH; | ||
1107 | |||
1108 | trace = ds_read_bts(context->tracer); | ||
1109 | if (!trace) | ||
1110 | return -ESRCH; | ||
1111 | |||
1112 | return (trace->ds.top - trace->ds.begin) / trace->ds.size; | ||
1113 | } | ||
1114 | |||
1115 | /* | ||
1116 | * Called from __ptrace_unlink() after the child has been moved back | ||
1117 | * to its original parent. | ||
1118 | */ | ||
1119 | void ptrace_bts_untrace(struct task_struct *child) | ||
1120 | { | ||
1121 | if (unlikely(child->bts)) { | ||
1122 | free_bts_context(child->bts); | ||
1123 | child->bts = NULL; | ||
1124 | } | ||
1125 | } | ||
1126 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
1127 | |||
1128 | /* | 787 | /* |
1129 | * Called by kernel/ptrace.c when detaching.. | 788 | * Called by kernel/ptrace.c when detaching.. |
1130 | * | 789 | * |
@@ -1252,39 +911,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
1252 | break; | 911 | break; |
1253 | #endif | 912 | #endif |
1254 | 913 | ||
1255 | /* | ||
1256 | * These bits need more cooking - not enabled yet: | ||
1257 | */ | ||
1258 | #ifdef CONFIG_X86_PTRACE_BTS | ||
1259 | case PTRACE_BTS_CONFIG: | ||
1260 | ret = ptrace_bts_config | ||
1261 | (child, data, (struct ptrace_bts_config __user *)addr); | ||
1262 | break; | ||
1263 | |||
1264 | case PTRACE_BTS_STATUS: | ||
1265 | ret = ptrace_bts_status | ||
1266 | (child, data, (struct ptrace_bts_config __user *)addr); | ||
1267 | break; | ||
1268 | |||
1269 | case PTRACE_BTS_SIZE: | ||
1270 | ret = ptrace_bts_size(child); | ||
1271 | break; | ||
1272 | |||
1273 | case PTRACE_BTS_GET: | ||
1274 | ret = ptrace_bts_read_record | ||
1275 | (child, data, (struct bts_struct __user *) addr); | ||
1276 | break; | ||
1277 | |||
1278 | case PTRACE_BTS_CLEAR: | ||
1279 | ret = ptrace_bts_clear(child); | ||
1280 | break; | ||
1281 | |||
1282 | case PTRACE_BTS_DRAIN: | ||
1283 | ret = ptrace_bts_drain | ||
1284 | (child, data, (struct bts_struct __user *) addr); | ||
1285 | break; | ||
1286 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
1287 | |||
1288 | default: | 914 | default: |
1289 | ret = ptrace_request(child, request, addr, data); | 915 | ret = ptrace_request(child, request, addr, data); |
1290 | break; | 916 | break; |
@@ -1544,14 +1170,6 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | |||
1544 | 1170 | ||
1545 | case PTRACE_GET_THREAD_AREA: | 1171 | case PTRACE_GET_THREAD_AREA: |
1546 | case PTRACE_SET_THREAD_AREA: | 1172 | case PTRACE_SET_THREAD_AREA: |
1547 | #ifdef CONFIG_X86_PTRACE_BTS | ||
1548 | case PTRACE_BTS_CONFIG: | ||
1549 | case PTRACE_BTS_STATUS: | ||
1550 | case PTRACE_BTS_SIZE: | ||
1551 | case PTRACE_BTS_GET: | ||
1552 | case PTRACE_BTS_CLEAR: | ||
1553 | case PTRACE_BTS_DRAIN: | ||
1554 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
1555 | return arch_ptrace(child, request, addr, data); | 1173 | return arch_ptrace(child, request, addr, data); |
1556 | 1174 | ||
1557 | default: | 1175 | default: |
diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c index 3149032ff10..58de45ee08b 100644 --- a/arch/x86/kernel/step.c +++ b/arch/x86/kernel/step.c | |||
@@ -158,22 +158,6 @@ static int enable_single_step(struct task_struct *child) | |||
158 | } | 158 | } |
159 | 159 | ||
160 | /* | 160 | /* |
161 | * Install this value in MSR_IA32_DEBUGCTLMSR whenever child is running. | ||
162 | */ | ||
163 | static void write_debugctlmsr(struct task_struct *child, unsigned long val) | ||
164 | { | ||
165 | if (child->thread.debugctlmsr == val) | ||
166 | return; | ||
167 | |||
168 | child->thread.debugctlmsr = val; | ||
169 | |||
170 | if (child != current) | ||
171 | return; | ||
172 | |||
173 | update_debugctlmsr(val); | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * Enable single or block step. | 161 | * Enable single or block step. |
178 | */ | 162 | */ |
179 | static void enable_step(struct task_struct *child, bool block) | 163 | static void enable_step(struct task_struct *child, bool block) |
@@ -186,15 +170,17 @@ static void enable_step(struct task_struct *child, bool block) | |||
186 | * that uses user-mode single stepping itself. | 170 | * that uses user-mode single stepping itself. |
187 | */ | 171 | */ |
188 | if (enable_single_step(child) && block) { | 172 | if (enable_single_step(child) && block) { |
189 | set_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 173 | unsigned long debugctl = get_debugctlmsr(); |
190 | write_debugctlmsr(child, | 174 | |
191 | child->thread.debugctlmsr | DEBUGCTLMSR_BTF); | 175 | debugctl |= DEBUGCTLMSR_BTF; |
192 | } else { | 176 | update_debugctlmsr(debugctl); |
193 | write_debugctlmsr(child, | 177 | set_tsk_thread_flag(child, TIF_BLOCKSTEP); |
194 | child->thread.debugctlmsr & ~DEBUGCTLMSR_BTF); | 178 | } else if (test_tsk_thread_flag(child, TIF_BLOCKSTEP)) { |
195 | 179 | unsigned long debugctl = get_debugctlmsr(); | |
196 | if (!child->thread.debugctlmsr) | 180 | |
197 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 181 | debugctl &= ~DEBUGCTLMSR_BTF; |
182 | update_debugctlmsr(debugctl); | ||
183 | clear_tsk_thread_flag(child, TIF_BLOCKSTEP); | ||
198 | } | 184 | } |
199 | } | 185 | } |
200 | 186 | ||
@@ -213,11 +199,13 @@ void user_disable_single_step(struct task_struct *child) | |||
213 | /* | 199 | /* |
214 | * Make sure block stepping (BTF) is disabled. | 200 | * Make sure block stepping (BTF) is disabled. |
215 | */ | 201 | */ |
216 | write_debugctlmsr(child, | 202 | if (test_tsk_thread_flag(child, TIF_BLOCKSTEP)) { |
217 | child->thread.debugctlmsr & ~DEBUGCTLMSR_BTF); | 203 | unsigned long debugctl = get_debugctlmsr(); |
218 | 204 | ||
219 | if (!child->thread.debugctlmsr) | 205 | debugctl &= ~DEBUGCTLMSR_BTF; |
220 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 206 | update_debugctlmsr(debugctl); |
207 | clear_tsk_thread_flag(child, TIF_BLOCKSTEP); | ||
208 | } | ||
221 | 209 | ||
222 | /* Always clear TIF_SINGLESTEP... */ | 210 | /* Always clear TIF_SINGLESTEP... */ |
223 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | 211 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); |
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 1168e445418..36f1bd9f8e7 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c | |||
@@ -543,11 +543,11 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code) | |||
543 | 543 | ||
544 | /* DR6 may or may not be cleared by the CPU */ | 544 | /* DR6 may or may not be cleared by the CPU */ |
545 | set_debugreg(0, 6); | 545 | set_debugreg(0, 6); |
546 | |||
546 | /* | 547 | /* |
547 | * The processor cleared BTF, so don't mark that we need it set. | 548 | * The processor cleared BTF, so don't mark that we need it set. |
548 | */ | 549 | */ |
549 | clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR); | 550 | clear_tsk_thread_flag(tsk, TIF_BLOCKSTEP); |
550 | tsk->thread.debugctlmsr = 0; | ||
551 | 551 | ||
552 | /* Store the virtualized DR6 value */ | 552 | /* Store the virtualized DR6 value */ |
553 | tsk->thread.debugreg6 = dr6; | 553 | tsk->thread.debugreg6 = dr6; |
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index 419386c24b8..cbaf8f2b83d 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile | |||
@@ -20,7 +20,7 @@ lib-y := delay.o | |||
20 | lib-y += thunk_$(BITS).o | 20 | lib-y += thunk_$(BITS).o |
21 | lib-y += usercopy_$(BITS).o getuser.o putuser.o | 21 | lib-y += usercopy_$(BITS).o getuser.o putuser.o |
22 | lib-y += memcpy_$(BITS).o | 22 | lib-y += memcpy_$(BITS).o |
23 | lib-$(CONFIG_KPROBES) += insn.o inat.o | 23 | lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o |
24 | 24 | ||
25 | obj-y += msr.o msr-reg.o msr-reg-export.o | 25 | obj-y += msr.o msr-reg.o msr-reg-export.o |
26 | 26 | ||
diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c index 2bf90fafa7b..c8abc4d1bf3 100644 --- a/arch/x86/oprofile/op_model_ppro.c +++ b/arch/x86/oprofile/op_model_ppro.c | |||
@@ -239,11 +239,11 @@ static void arch_perfmon_setup_counters(void) | |||
239 | if (eax.split.version_id == 0 && current_cpu_data.x86 == 6 && | 239 | if (eax.split.version_id == 0 && current_cpu_data.x86 == 6 && |
240 | current_cpu_data.x86_model == 15) { | 240 | current_cpu_data.x86_model == 15) { |
241 | eax.split.version_id = 2; | 241 | eax.split.version_id = 2; |
242 | eax.split.num_events = 2; | 242 | eax.split.num_counters = 2; |
243 | eax.split.bit_width = 40; | 243 | eax.split.bit_width = 40; |
244 | } | 244 | } |
245 | 245 | ||
246 | num_counters = eax.split.num_events; | 246 | num_counters = eax.split.num_counters; |
247 | 247 | ||
248 | op_arch_perfmon_spec.num_counters = num_counters; | 248 | op_arch_perfmon_spec.num_counters = num_counters; |
249 | op_arch_perfmon_spec.num_controls = num_counters; | 249 | op_arch_perfmon_spec.num_controls = num_counters; |
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 01e6adea07e..cc12b3c556b 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h | |||
@@ -504,18 +504,6 @@ extern int ftrace_dump_on_oops; | |||
504 | #define INIT_TRACE_RECURSION | 504 | #define INIT_TRACE_RECURSION |
505 | #endif | 505 | #endif |
506 | 506 | ||
507 | #ifdef CONFIG_HW_BRANCH_TRACER | ||
508 | |||
509 | void trace_hw_branch(u64 from, u64 to); | ||
510 | void trace_hw_branch_oops(void); | ||
511 | |||
512 | #else /* CONFIG_HW_BRANCH_TRACER */ | ||
513 | |||
514 | static inline void trace_hw_branch(u64 from, u64 to) {} | ||
515 | static inline void trace_hw_branch_oops(void) {} | ||
516 | |||
517 | #endif /* CONFIG_HW_BRANCH_TRACER */ | ||
518 | |||
519 | #ifdef CONFIG_FTRACE_SYSCALLS | 507 | #ifdef CONFIG_FTRACE_SYSCALLS |
520 | 508 | ||
521 | unsigned long arch_syscall_addr(int nr); | 509 | unsigned long arch_syscall_addr(int nr); |
diff --git a/include/linux/mm.h b/include/linux/mm.h index 462acaf36f3..fb19bb92b80 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -19,7 +19,6 @@ struct anon_vma; | |||
19 | struct file_ra_state; | 19 | struct file_ra_state; |
20 | struct user_struct; | 20 | struct user_struct; |
21 | struct writeback_control; | 21 | struct writeback_control; |
22 | struct rlimit; | ||
23 | 22 | ||
24 | #ifndef CONFIG_DISCONTIGMEM /* Don't use mapnrs, do it properly */ | 23 | #ifndef CONFIG_DISCONTIGMEM /* Don't use mapnrs, do it properly */ |
25 | extern unsigned long max_mapnr; | 24 | extern unsigned long max_mapnr; |
@@ -1449,9 +1448,6 @@ int vmemmap_populate_basepages(struct page *start_page, | |||
1449 | int vmemmap_populate(struct page *start_page, unsigned long pages, int node); | 1448 | int vmemmap_populate(struct page *start_page, unsigned long pages, int node); |
1450 | void vmemmap_populate_print_last(void); | 1449 | void vmemmap_populate_print_last(void); |
1451 | 1450 | ||
1452 | extern int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim, | ||
1453 | size_t size); | ||
1454 | extern void refund_locked_memory(struct mm_struct *mm, size_t size); | ||
1455 | 1451 | ||
1456 | enum mf_flags { | 1452 | enum mf_flags { |
1457 | MF_COUNT_INCREASED = 1 << 0, | 1453 | MF_COUNT_INCREASED = 1 << 0, |
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index c8e37544040..6e96cc8225d 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -203,8 +203,9 @@ struct perf_event_attr { | |||
203 | enable_on_exec : 1, /* next exec enables */ | 203 | enable_on_exec : 1, /* next exec enables */ |
204 | task : 1, /* trace fork/exit */ | 204 | task : 1, /* trace fork/exit */ |
205 | watermark : 1, /* wakeup_watermark */ | 205 | watermark : 1, /* wakeup_watermark */ |
206 | precise : 1, /* OoO invariant counter */ | ||
206 | 207 | ||
207 | __reserved_1 : 49; | 208 | __reserved_1 : 48; |
208 | 209 | ||
209 | union { | 210 | union { |
210 | __u32 wakeup_events; /* wakeup every n events */ | 211 | __u32 wakeup_events; /* wakeup every n events */ |
@@ -293,6 +294,12 @@ struct perf_event_mmap_page { | |||
293 | #define PERF_RECORD_MISC_USER (2 << 0) | 294 | #define PERF_RECORD_MISC_USER (2 << 0) |
294 | #define PERF_RECORD_MISC_HYPERVISOR (3 << 0) | 295 | #define PERF_RECORD_MISC_HYPERVISOR (3 << 0) |
295 | 296 | ||
297 | #define PERF_RECORD_MISC_EXACT (1 << 14) | ||
298 | /* | ||
299 | * Reserve the last bit to indicate some extended misc field | ||
300 | */ | ||
301 | #define PERF_RECORD_MISC_EXT_RESERVED (1 << 15) | ||
302 | |||
296 | struct perf_event_header { | 303 | struct perf_event_header { |
297 | __u32 type; | 304 | __u32 type; |
298 | __u16 misc; | 305 | __u16 misc; |
@@ -468,6 +475,17 @@ struct perf_raw_record { | |||
468 | void *data; | 475 | void *data; |
469 | }; | 476 | }; |
470 | 477 | ||
478 | struct perf_branch_entry { | ||
479 | __u64 from; | ||
480 | __u64 to; | ||
481 | __u64 flags; | ||
482 | }; | ||
483 | |||
484 | struct perf_branch_stack { | ||
485 | __u64 nr; | ||
486 | struct perf_branch_entry entries[0]; | ||
487 | }; | ||
488 | |||
471 | struct task_struct; | 489 | struct task_struct; |
472 | 490 | ||
473 | /** | 491 | /** |
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index e1fb6072997..4272521e29e 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h | |||
@@ -345,18 +345,6 @@ static inline void user_single_step_siginfo(struct task_struct *tsk, | |||
345 | #define arch_ptrace_stop(code, info) do { } while (0) | 345 | #define arch_ptrace_stop(code, info) do { } while (0) |
346 | #endif | 346 | #endif |
347 | 347 | ||
348 | #ifndef arch_ptrace_untrace | ||
349 | /* | ||
350 | * Do machine-specific work before untracing child. | ||
351 | * | ||
352 | * This is called for a normal detach as well as from ptrace_exit() | ||
353 | * when the tracing task dies. | ||
354 | * | ||
355 | * Called with write_lock(&tasklist_lock) held. | ||
356 | */ | ||
357 | #define arch_ptrace_untrace(task) do { } while (0) | ||
358 | #endif | ||
359 | |||
360 | extern int task_current_syscall(struct task_struct *target, long *callno, | 348 | extern int task_current_syscall(struct task_struct *target, long *callno, |
361 | unsigned long args[6], unsigned int maxargs, | 349 | unsigned long args[6], unsigned int maxargs, |
362 | unsigned long *sp, unsigned long *pc); | 350 | unsigned long *sp, unsigned long *pc); |
diff --git a/include/linux/sched.h b/include/linux/sched.h index dad7f668ebf..e0447c64af6 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -99,7 +99,6 @@ struct futex_pi_state; | |||
99 | struct robust_list_head; | 99 | struct robust_list_head; |
100 | struct bio_list; | 100 | struct bio_list; |
101 | struct fs_struct; | 101 | struct fs_struct; |
102 | struct bts_context; | ||
103 | struct perf_event_context; | 102 | struct perf_event_context; |
104 | 103 | ||
105 | /* | 104 | /* |
@@ -1272,12 +1271,6 @@ struct task_struct { | |||
1272 | struct list_head ptraced; | 1271 | struct list_head ptraced; |
1273 | struct list_head ptrace_entry; | 1272 | struct list_head ptrace_entry; |
1274 | 1273 | ||
1275 | /* | ||
1276 | * This is the tracer handle for the ptrace BTS extension. | ||
1277 | * This field actually belongs to the ptracer task. | ||
1278 | */ | ||
1279 | struct bts_context *bts; | ||
1280 | |||
1281 | /* PID/PID hash table linkage. */ | 1274 | /* PID/PID hash table linkage. */ |
1282 | struct pid_link pids[PIDTYPE_MAX]; | 1275 | struct pid_link pids[PIDTYPE_MAX]; |
1283 | struct list_head thread_group; | 1276 | struct list_head thread_group; |
@@ -2123,10 +2116,8 @@ extern void set_task_comm(struct task_struct *tsk, char *from); | |||
2123 | extern char *get_task_comm(char *to, struct task_struct *tsk); | 2116 | extern char *get_task_comm(char *to, struct task_struct *tsk); |
2124 | 2117 | ||
2125 | #ifdef CONFIG_SMP | 2118 | #ifdef CONFIG_SMP |
2126 | extern void wait_task_context_switch(struct task_struct *p); | ||
2127 | extern unsigned long wait_task_inactive(struct task_struct *, long match_state); | 2119 | extern unsigned long wait_task_inactive(struct task_struct *, long match_state); |
2128 | #else | 2120 | #else |
2129 | static inline void wait_task_context_switch(struct task_struct *p) {} | ||
2130 | static inline unsigned long wait_task_inactive(struct task_struct *p, | 2121 | static inline unsigned long wait_task_inactive(struct task_struct *p, |
2131 | long match_state) | 2122 | long match_state) |
2132 | { | 2123 | { |
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h index ea6f9d4a20e..882c64832ff 100644 --- a/include/trace/ftrace.h +++ b/include/trace/ftrace.h | |||
@@ -758,13 +758,12 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
758 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 758 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
759 | static notrace void \ | 759 | static notrace void \ |
760 | perf_trace_templ_##call(struct ftrace_event_call *event_call, \ | 760 | perf_trace_templ_##call(struct ftrace_event_call *event_call, \ |
761 | proto) \ | 761 | struct pt_regs *__regs, proto) \ |
762 | { \ | 762 | { \ |
763 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | 763 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
764 | struct ftrace_raw_##call *entry; \ | 764 | struct ftrace_raw_##call *entry; \ |
765 | u64 __addr = 0, __count = 1; \ | 765 | u64 __addr = 0, __count = 1; \ |
766 | unsigned long irq_flags; \ | 766 | unsigned long irq_flags; \ |
767 | struct pt_regs *__regs; \ | ||
768 | int __entry_size; \ | 767 | int __entry_size; \ |
769 | int __data_size; \ | 768 | int __data_size; \ |
770 | int rctx; \ | 769 | int rctx; \ |
@@ -785,20 +784,22 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call, \ | |||
785 | \ | 784 | \ |
786 | { assign; } \ | 785 | { assign; } \ |
787 | \ | 786 | \ |
788 | __regs = &__get_cpu_var(perf_trace_regs); \ | ||
789 | perf_fetch_caller_regs(__regs, 2); \ | ||
790 | \ | ||
791 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ | 787 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ |
792 | __count, irq_flags, __regs); \ | 788 | __count, irq_flags, __regs); \ |
793 | } | 789 | } |
794 | 790 | ||
795 | #undef DEFINE_EVENT | 791 | #undef DEFINE_EVENT |
796 | #define DEFINE_EVENT(template, call, proto, args) \ | 792 | #define DEFINE_EVENT(template, call, proto, args) \ |
797 | static notrace void perf_trace_##call(proto) \ | 793 | static notrace void perf_trace_##call(proto) \ |
798 | { \ | 794 | { \ |
799 | struct ftrace_event_call *event_call = &event_##call; \ | 795 | struct ftrace_event_call *event_call = &event_##call; \ |
800 | \ | 796 | struct pt_regs *__regs = &get_cpu_var(perf_trace_regs); \ |
801 | perf_trace_templ_##template(event_call, args); \ | 797 | \ |
798 | perf_fetch_caller_regs(__regs, 1); \ | ||
799 | \ | ||
800 | perf_trace_templ_##template(event_call, __regs, args); \ | ||
801 | \ | ||
802 | put_cpu_var(perf_trace_regs); \ | ||
802 | } | 803 | } |
803 | 804 | ||
804 | #undef DEFINE_EVENT_PRINT | 805 | #undef DEFINE_EVENT_PRINT |
diff --git a/kernel/fork.c b/kernel/fork.c index 44b0791b0a2..5d3592deaf7 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -1111,9 +1111,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1111 | p->memcg_batch.do_batch = 0; | 1111 | p->memcg_batch.do_batch = 0; |
1112 | p->memcg_batch.memcg = NULL; | 1112 | p->memcg_batch.memcg = NULL; |
1113 | #endif | 1113 | #endif |
1114 | |||
1115 | p->bts = NULL; | ||
1116 | |||
1117 | p->stack_start = stack_start; | 1114 | p->stack_start = stack_start; |
1118 | 1115 | ||
1119 | /* Perform scheduler related setup. Assign this task to a CPU. */ | 1116 | /* Perform scheduler related setup. Assign this task to a CPU. */ |
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index 2f3fbf84215..fcf42dcd608 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
@@ -1367,6 +1367,8 @@ void perf_event_task_sched_in(struct task_struct *task) | |||
1367 | if (cpuctx->task_ctx == ctx) | 1367 | if (cpuctx->task_ctx == ctx) |
1368 | return; | 1368 | return; |
1369 | 1369 | ||
1370 | perf_disable(); | ||
1371 | |||
1370 | /* | 1372 | /* |
1371 | * We want to keep the following priority order: | 1373 | * We want to keep the following priority order: |
1372 | * cpu pinned (that don't need to move), task pinned, | 1374 | * cpu pinned (that don't need to move), task pinned, |
@@ -1379,6 +1381,8 @@ void perf_event_task_sched_in(struct task_struct *task) | |||
1379 | ctx_sched_in(ctx, cpuctx, EVENT_FLEXIBLE); | 1381 | ctx_sched_in(ctx, cpuctx, EVENT_FLEXIBLE); |
1380 | 1382 | ||
1381 | cpuctx->task_ctx = ctx; | 1383 | cpuctx->task_ctx = ctx; |
1384 | |||
1385 | perf_enable(); | ||
1382 | } | 1386 | } |
1383 | 1387 | ||
1384 | #define MAX_INTERRUPTS (~0ULL) | 1388 | #define MAX_INTERRUPTS (~0ULL) |
@@ -2642,6 +2646,7 @@ static int perf_fasync(int fd, struct file *filp, int on) | |||
2642 | } | 2646 | } |
2643 | 2647 | ||
2644 | static const struct file_operations perf_fops = { | 2648 | static const struct file_operations perf_fops = { |
2649 | .llseek = no_llseek, | ||
2645 | .release = perf_release, | 2650 | .release = perf_release, |
2646 | .read = perf_read, | 2651 | .read = perf_read, |
2647 | .poll = perf_poll, | 2652 | .poll = perf_poll, |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 42ad8ae729a..9fb51237b18 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -76,7 +76,6 @@ void __ptrace_unlink(struct task_struct *child) | |||
76 | child->parent = child->real_parent; | 76 | child->parent = child->real_parent; |
77 | list_del_init(&child->ptrace_entry); | 77 | list_del_init(&child->ptrace_entry); |
78 | 78 | ||
79 | arch_ptrace_untrace(child); | ||
80 | if (task_is_traced(child)) | 79 | if (task_is_traced(child)) |
81 | ptrace_untrace(child); | 80 | ptrace_untrace(child); |
82 | } | 81 | } |
diff --git a/kernel/sched.c b/kernel/sched.c index a3dff1f3f9b..8cafe3ff558 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -2078,49 +2078,6 @@ migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req) | |||
2078 | } | 2078 | } |
2079 | 2079 | ||
2080 | /* | 2080 | /* |
2081 | * wait_task_context_switch - wait for a thread to complete at least one | ||
2082 | * context switch. | ||
2083 | * | ||
2084 | * @p must not be current. | ||
2085 | */ | ||
2086 | void wait_task_context_switch(struct task_struct *p) | ||
2087 | { | ||
2088 | unsigned long nvcsw, nivcsw, flags; | ||
2089 | int running; | ||
2090 | struct rq *rq; | ||
2091 | |||
2092 | nvcsw = p->nvcsw; | ||
2093 | nivcsw = p->nivcsw; | ||
2094 | for (;;) { | ||
2095 | /* | ||
2096 | * The runqueue is assigned before the actual context | ||
2097 | * switch. We need to take the runqueue lock. | ||
2098 | * | ||
2099 | * We could check initially without the lock but it is | ||
2100 | * very likely that we need to take the lock in every | ||
2101 | * iteration. | ||
2102 | */ | ||
2103 | rq = task_rq_lock(p, &flags); | ||
2104 | running = task_running(rq, p); | ||
2105 | task_rq_unlock(rq, &flags); | ||
2106 | |||
2107 | if (likely(!running)) | ||
2108 | break; | ||
2109 | /* | ||
2110 | * The switch count is incremented before the actual | ||
2111 | * context switch. We thus wait for two switches to be | ||
2112 | * sure at least one completed. | ||
2113 | */ | ||
2114 | if ((p->nvcsw - nvcsw) > 1) | ||
2115 | break; | ||
2116 | if ((p->nivcsw - nivcsw) > 1) | ||
2117 | break; | ||
2118 | |||
2119 | cpu_relax(); | ||
2120 | } | ||
2121 | } | ||
2122 | |||
2123 | /* | ||
2124 | * wait_task_inactive - wait for a thread to unschedule. | 2081 | * wait_task_inactive - wait for a thread to unschedule. |
2125 | * | 2082 | * |
2126 | * If @match_state is nonzero, it's the @p->state value just checked and | 2083 | * If @match_state is nonzero, it's the @p->state value just checked and |
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 13e13d428cd..8b1797c4545 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig | |||
@@ -44,9 +44,6 @@ config HAVE_FTRACE_MCOUNT_RECORD | |||
44 | help | 44 | help |
45 | See Documentation/trace/ftrace-design.txt | 45 | See Documentation/trace/ftrace-design.txt |
46 | 46 | ||
47 | config HAVE_HW_BRANCH_TRACER | ||
48 | bool | ||
49 | |||
50 | config HAVE_SYSCALL_TRACEPOINTS | 47 | config HAVE_SYSCALL_TRACEPOINTS |
51 | bool | 48 | bool |
52 | help | 49 | help |
@@ -374,14 +371,6 @@ config STACK_TRACER | |||
374 | 371 | ||
375 | Say N if unsure. | 372 | Say N if unsure. |
376 | 373 | ||
377 | config HW_BRANCH_TRACER | ||
378 | depends on HAVE_HW_BRANCH_TRACER | ||
379 | bool "Trace hw branches" | ||
380 | select GENERIC_TRACER | ||
381 | help | ||
382 | This tracer records all branches on the system in a circular | ||
383 | buffer, giving access to the last N branches for each cpu. | ||
384 | |||
385 | config KMEMTRACE | 374 | config KMEMTRACE |
386 | bool "Trace SLAB allocations" | 375 | bool "Trace SLAB allocations" |
387 | select GENERIC_TRACER | 376 | select GENERIC_TRACER |
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 78edc649003..ffb1a5b0550 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile | |||
@@ -41,7 +41,6 @@ obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o | |||
41 | obj-$(CONFIG_BOOT_TRACER) += trace_boot.o | 41 | obj-$(CONFIG_BOOT_TRACER) += trace_boot.o |
42 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o | 42 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o |
43 | obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o | 43 | obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o |
44 | obj-$(CONFIG_HW_BRANCH_TRACER) += trace_hw_branches.o | ||
45 | obj-$(CONFIG_KMEMTRACE) += kmemtrace.o | 44 | obj-$(CONFIG_KMEMTRACE) += kmemtrace.o |
46 | obj-$(CONFIG_WORKQUEUE_TRACER) += trace_workqueue.o | 45 | obj-$(CONFIG_WORKQUEUE_TRACER) += trace_workqueue.o |
47 | obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o | 46 | obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o |
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 2825ef2c0b1..bec2c973ff0 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
@@ -34,7 +34,6 @@ enum trace_type { | |||
34 | TRACE_GRAPH_RET, | 34 | TRACE_GRAPH_RET, |
35 | TRACE_GRAPH_ENT, | 35 | TRACE_GRAPH_ENT, |
36 | TRACE_USER_STACK, | 36 | TRACE_USER_STACK, |
37 | TRACE_HW_BRANCHES, | ||
38 | TRACE_KMEM_ALLOC, | 37 | TRACE_KMEM_ALLOC, |
39 | TRACE_KMEM_FREE, | 38 | TRACE_KMEM_FREE, |
40 | TRACE_BLK, | 39 | TRACE_BLK, |
@@ -229,7 +228,6 @@ extern void __ftrace_bad_type(void); | |||
229 | TRACE_GRAPH_ENT); \ | 228 | TRACE_GRAPH_ENT); \ |
230 | IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \ | 229 | IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \ |
231 | TRACE_GRAPH_RET); \ | 230 | TRACE_GRAPH_RET); \ |
232 | IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\ | ||
233 | IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \ | 231 | IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \ |
234 | TRACE_KMEM_ALLOC); \ | 232 | TRACE_KMEM_ALLOC); \ |
235 | IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \ | 233 | IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \ |
@@ -467,8 +465,6 @@ extern int trace_selftest_startup_sysprof(struct tracer *trace, | |||
467 | struct trace_array *tr); | 465 | struct trace_array *tr); |
468 | extern int trace_selftest_startup_branch(struct tracer *trace, | 466 | extern int trace_selftest_startup_branch(struct tracer *trace, |
469 | struct trace_array *tr); | 467 | struct trace_array *tr); |
470 | extern int trace_selftest_startup_hw_branches(struct tracer *trace, | ||
471 | struct trace_array *tr); | ||
472 | extern int trace_selftest_startup_ksym(struct tracer *trace, | 468 | extern int trace_selftest_startup_ksym(struct tracer *trace, |
473 | struct trace_array *tr); | 469 | struct trace_array *tr); |
474 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ | 470 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h index c16a08f399d..dc008c1240d 100644 --- a/kernel/trace/trace_entries.h +++ b/kernel/trace/trace_entries.h | |||
@@ -318,18 +318,6 @@ FTRACE_ENTRY(branch, trace_branch, | |||
318 | __entry->func, __entry->file, __entry->correct) | 318 | __entry->func, __entry->file, __entry->correct) |
319 | ); | 319 | ); |
320 | 320 | ||
321 | FTRACE_ENTRY(hw_branch, hw_branch_entry, | ||
322 | |||
323 | TRACE_HW_BRANCHES, | ||
324 | |||
325 | F_STRUCT( | ||
326 | __field( u64, from ) | ||
327 | __field( u64, to ) | ||
328 | ), | ||
329 | |||
330 | F_printk("from: %llx to: %llx", __entry->from, __entry->to) | ||
331 | ); | ||
332 | |||
333 | FTRACE_ENTRY(kmem_alloc, kmemtrace_alloc_entry, | 321 | FTRACE_ENTRY(kmem_alloc, kmemtrace_alloc_entry, |
334 | 322 | ||
335 | TRACE_KMEM_ALLOC, | 323 | TRACE_KMEM_ALLOC, |
diff --git a/kernel/trace/trace_hw_branches.c b/kernel/trace/trace_hw_branches.c deleted file mode 100644 index 7b97000745f..00000000000 --- a/kernel/trace/trace_hw_branches.c +++ /dev/null | |||
@@ -1,312 +0,0 @@ | |||
1 | /* | ||
2 | * h/w branch tracer for x86 based on BTS | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Intel Corporation. | ||
5 | * Markus Metzger <markus.t.metzger@gmail.com>, 2008-2009 | ||
6 | */ | ||
7 | #include <linux/kallsyms.h> | ||
8 | #include <linux/debugfs.h> | ||
9 | #include <linux/ftrace.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/cpu.h> | ||
12 | #include <linux/smp.h> | ||
13 | #include <linux/fs.h> | ||
14 | |||
15 | #include <asm/ds.h> | ||
16 | |||
17 | #include "trace_output.h" | ||
18 | #include "trace.h" | ||
19 | |||
20 | |||
21 | #define BTS_BUFFER_SIZE (1 << 13) | ||
22 | |||
23 | static DEFINE_PER_CPU(struct bts_tracer *, hwb_tracer); | ||
24 | static DEFINE_PER_CPU(unsigned char[BTS_BUFFER_SIZE], hwb_buffer); | ||
25 | |||
26 | #define this_tracer per_cpu(hwb_tracer, smp_processor_id()) | ||
27 | |||
28 | static int trace_hw_branches_enabled __read_mostly; | ||
29 | static int trace_hw_branches_suspended __read_mostly; | ||
30 | static struct trace_array *hw_branch_trace __read_mostly; | ||
31 | |||
32 | |||
33 | static void bts_trace_init_cpu(int cpu) | ||
34 | { | ||
35 | per_cpu(hwb_tracer, cpu) = | ||
36 | ds_request_bts_cpu(cpu, per_cpu(hwb_buffer, cpu), | ||
37 | BTS_BUFFER_SIZE, NULL, (size_t)-1, | ||
38 | BTS_KERNEL); | ||
39 | |||
40 | if (IS_ERR(per_cpu(hwb_tracer, cpu))) | ||
41 | per_cpu(hwb_tracer, cpu) = NULL; | ||
42 | } | ||
43 | |||
44 | static int bts_trace_init(struct trace_array *tr) | ||
45 | { | ||
46 | int cpu; | ||
47 | |||
48 | hw_branch_trace = tr; | ||
49 | trace_hw_branches_enabled = 0; | ||
50 | |||
51 | get_online_cpus(); | ||
52 | for_each_online_cpu(cpu) { | ||
53 | bts_trace_init_cpu(cpu); | ||
54 | |||
55 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
56 | trace_hw_branches_enabled = 1; | ||
57 | } | ||
58 | trace_hw_branches_suspended = 0; | ||
59 | put_online_cpus(); | ||
60 | |||
61 | /* If we could not enable tracing on a single cpu, we fail. */ | ||
62 | return trace_hw_branches_enabled ? 0 : -EOPNOTSUPP; | ||
63 | } | ||
64 | |||
65 | static void bts_trace_reset(struct trace_array *tr) | ||
66 | { | ||
67 | int cpu; | ||
68 | |||
69 | get_online_cpus(); | ||
70 | for_each_online_cpu(cpu) { | ||
71 | if (likely(per_cpu(hwb_tracer, cpu))) { | ||
72 | ds_release_bts(per_cpu(hwb_tracer, cpu)); | ||
73 | per_cpu(hwb_tracer, cpu) = NULL; | ||
74 | } | ||
75 | } | ||
76 | trace_hw_branches_enabled = 0; | ||
77 | trace_hw_branches_suspended = 0; | ||
78 | put_online_cpus(); | ||
79 | } | ||
80 | |||
81 | static void bts_trace_start(struct trace_array *tr) | ||
82 | { | ||
83 | int cpu; | ||
84 | |||
85 | get_online_cpus(); | ||
86 | for_each_online_cpu(cpu) | ||
87 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
88 | ds_resume_bts(per_cpu(hwb_tracer, cpu)); | ||
89 | trace_hw_branches_suspended = 0; | ||
90 | put_online_cpus(); | ||
91 | } | ||
92 | |||
93 | static void bts_trace_stop(struct trace_array *tr) | ||
94 | { | ||
95 | int cpu; | ||
96 | |||
97 | get_online_cpus(); | ||
98 | for_each_online_cpu(cpu) | ||
99 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
100 | ds_suspend_bts(per_cpu(hwb_tracer, cpu)); | ||
101 | trace_hw_branches_suspended = 1; | ||
102 | put_online_cpus(); | ||
103 | } | ||
104 | |||
105 | static int __cpuinit bts_hotcpu_handler(struct notifier_block *nfb, | ||
106 | unsigned long action, void *hcpu) | ||
107 | { | ||
108 | int cpu = (long)hcpu; | ||
109 | |||
110 | switch (action) { | ||
111 | case CPU_ONLINE: | ||
112 | case CPU_DOWN_FAILED: | ||
113 | /* The notification is sent with interrupts enabled. */ | ||
114 | if (trace_hw_branches_enabled) { | ||
115 | bts_trace_init_cpu(cpu); | ||
116 | |||
117 | if (trace_hw_branches_suspended && | ||
118 | likely(per_cpu(hwb_tracer, cpu))) | ||
119 | ds_suspend_bts(per_cpu(hwb_tracer, cpu)); | ||
120 | } | ||
121 | break; | ||
122 | |||
123 | case CPU_DOWN_PREPARE: | ||
124 | /* The notification is sent with interrupts enabled. */ | ||
125 | if (likely(per_cpu(hwb_tracer, cpu))) { | ||
126 | ds_release_bts(per_cpu(hwb_tracer, cpu)); | ||
127 | per_cpu(hwb_tracer, cpu) = NULL; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | return NOTIFY_DONE; | ||
132 | } | ||
133 | |||
134 | static struct notifier_block bts_hotcpu_notifier __cpuinitdata = { | ||
135 | .notifier_call = bts_hotcpu_handler | ||
136 | }; | ||
137 | |||
138 | static void bts_trace_print_header(struct seq_file *m) | ||
139 | { | ||
140 | seq_puts(m, "# CPU# TO <- FROM\n"); | ||
141 | } | ||
142 | |||
143 | static enum print_line_t bts_trace_print_line(struct trace_iterator *iter) | ||
144 | { | ||
145 | unsigned long symflags = TRACE_ITER_SYM_OFFSET; | ||
146 | struct trace_entry *entry = iter->ent; | ||
147 | struct trace_seq *seq = &iter->seq; | ||
148 | struct hw_branch_entry *it; | ||
149 | |||
150 | trace_assign_type(it, entry); | ||
151 | |||
152 | if (entry->type == TRACE_HW_BRANCHES) { | ||
153 | if (trace_seq_printf(seq, "%4d ", iter->cpu) && | ||
154 | seq_print_ip_sym(seq, it->to, symflags) && | ||
155 | trace_seq_printf(seq, "\t <- ") && | ||
156 | seq_print_ip_sym(seq, it->from, symflags) && | ||
157 | trace_seq_printf(seq, "\n")) | ||
158 | return TRACE_TYPE_HANDLED; | ||
159 | return TRACE_TYPE_PARTIAL_LINE; | ||
160 | } | ||
161 | return TRACE_TYPE_UNHANDLED; | ||
162 | } | ||
163 | |||
164 | void trace_hw_branch(u64 from, u64 to) | ||
165 | { | ||
166 | struct ftrace_event_call *call = &event_hw_branch; | ||
167 | struct trace_array *tr = hw_branch_trace; | ||
168 | struct ring_buffer_event *event; | ||
169 | struct ring_buffer *buf; | ||
170 | struct hw_branch_entry *entry; | ||
171 | unsigned long irq1; | ||
172 | int cpu; | ||
173 | |||
174 | if (unlikely(!tr)) | ||
175 | return; | ||
176 | |||
177 | if (unlikely(!trace_hw_branches_enabled)) | ||
178 | return; | ||
179 | |||
180 | local_irq_save(irq1); | ||
181 | cpu = raw_smp_processor_id(); | ||
182 | if (atomic_inc_return(&tr->data[cpu]->disabled) != 1) | ||
183 | goto out; | ||
184 | |||
185 | buf = tr->buffer; | ||
186 | event = trace_buffer_lock_reserve(buf, TRACE_HW_BRANCHES, | ||
187 | sizeof(*entry), 0, 0); | ||
188 | if (!event) | ||
189 | goto out; | ||
190 | entry = ring_buffer_event_data(event); | ||
191 | tracing_generic_entry_update(&entry->ent, 0, from); | ||
192 | entry->ent.type = TRACE_HW_BRANCHES; | ||
193 | entry->from = from; | ||
194 | entry->to = to; | ||
195 | if (!filter_check_discard(call, entry, buf, event)) | ||
196 | trace_buffer_unlock_commit(buf, event, 0, 0); | ||
197 | |||
198 | out: | ||
199 | atomic_dec(&tr->data[cpu]->disabled); | ||
200 | local_irq_restore(irq1); | ||
201 | } | ||
202 | |||
203 | static void trace_bts_at(const struct bts_trace *trace, void *at) | ||
204 | { | ||
205 | struct bts_struct bts; | ||
206 | int err = 0; | ||
207 | |||
208 | WARN_ON_ONCE(!trace->read); | ||
209 | if (!trace->read) | ||
210 | return; | ||
211 | |||
212 | err = trace->read(this_tracer, at, &bts); | ||
213 | if (err < 0) | ||
214 | return; | ||
215 | |||
216 | switch (bts.qualifier) { | ||
217 | case BTS_BRANCH: | ||
218 | trace_hw_branch(bts.variant.lbr.from, bts.variant.lbr.to); | ||
219 | break; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | /* | ||
224 | * Collect the trace on the current cpu and write it into the ftrace buffer. | ||
225 | * | ||
226 | * pre: tracing must be suspended on the current cpu | ||
227 | */ | ||
228 | static void trace_bts_cpu(void *arg) | ||
229 | { | ||
230 | struct trace_array *tr = (struct trace_array *)arg; | ||
231 | const struct bts_trace *trace; | ||
232 | unsigned char *at; | ||
233 | |||
234 | if (unlikely(!tr)) | ||
235 | return; | ||
236 | |||
237 | if (unlikely(atomic_read(&tr->data[raw_smp_processor_id()]->disabled))) | ||
238 | return; | ||
239 | |||
240 | if (unlikely(!this_tracer)) | ||
241 | return; | ||
242 | |||
243 | trace = ds_read_bts(this_tracer); | ||
244 | if (!trace) | ||
245 | return; | ||
246 | |||
247 | for (at = trace->ds.top; (void *)at < trace->ds.end; | ||
248 | at += trace->ds.size) | ||
249 | trace_bts_at(trace, at); | ||
250 | |||
251 | for (at = trace->ds.begin; (void *)at < trace->ds.top; | ||
252 | at += trace->ds.size) | ||
253 | trace_bts_at(trace, at); | ||
254 | } | ||
255 | |||
256 | static void trace_bts_prepare(struct trace_iterator *iter) | ||
257 | { | ||
258 | int cpu; | ||
259 | |||
260 | get_online_cpus(); | ||
261 | for_each_online_cpu(cpu) | ||
262 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
263 | ds_suspend_bts(per_cpu(hwb_tracer, cpu)); | ||
264 | /* | ||
265 | * We need to collect the trace on the respective cpu since ftrace | ||
266 | * implicitly adds the record for the current cpu. | ||
267 | * Once that is more flexible, we could collect the data from any cpu. | ||
268 | */ | ||
269 | on_each_cpu(trace_bts_cpu, iter->tr, 1); | ||
270 | |||
271 | for_each_online_cpu(cpu) | ||
272 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
273 | ds_resume_bts(per_cpu(hwb_tracer, cpu)); | ||
274 | put_online_cpus(); | ||
275 | } | ||
276 | |||
277 | static void trace_bts_close(struct trace_iterator *iter) | ||
278 | { | ||
279 | tracing_reset_online_cpus(iter->tr); | ||
280 | } | ||
281 | |||
282 | void trace_hw_branch_oops(void) | ||
283 | { | ||
284 | if (this_tracer) { | ||
285 | ds_suspend_bts_noirq(this_tracer); | ||
286 | trace_bts_cpu(hw_branch_trace); | ||
287 | ds_resume_bts_noirq(this_tracer); | ||
288 | } | ||
289 | } | ||
290 | |||
291 | struct tracer bts_tracer __read_mostly = | ||
292 | { | ||
293 | .name = "hw-branch-tracer", | ||
294 | .init = bts_trace_init, | ||
295 | .reset = bts_trace_reset, | ||
296 | .print_header = bts_trace_print_header, | ||
297 | .print_line = bts_trace_print_line, | ||
298 | .start = bts_trace_start, | ||
299 | .stop = bts_trace_stop, | ||
300 | .open = trace_bts_prepare, | ||
301 | .close = trace_bts_close, | ||
302 | #ifdef CONFIG_FTRACE_SELFTEST | ||
303 | .selftest = trace_selftest_startup_hw_branches, | ||
304 | #endif /* CONFIG_FTRACE_SELFTEST */ | ||
305 | }; | ||
306 | |||
307 | __init static int init_bts_trace(void) | ||
308 | { | ||
309 | register_hotcpu_notifier(&bts_hotcpu_notifier); | ||
310 | return register_tracer(&bts_tracer); | ||
311 | } | ||
312 | device_initcall(init_bts_trace); | ||
diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index 81003b4d617..1cc9858258b 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c | |||
@@ -17,7 +17,6 @@ static inline int trace_valid_entry(struct trace_entry *entry) | |||
17 | case TRACE_BRANCH: | 17 | case TRACE_BRANCH: |
18 | case TRACE_GRAPH_ENT: | 18 | case TRACE_GRAPH_ENT: |
19 | case TRACE_GRAPH_RET: | 19 | case TRACE_GRAPH_RET: |
20 | case TRACE_HW_BRANCHES: | ||
21 | case TRACE_KSYM: | 20 | case TRACE_KSYM: |
22 | return 1; | 21 | return 1; |
23 | } | 22 | } |
@@ -755,62 +754,6 @@ trace_selftest_startup_branch(struct tracer *trace, struct trace_array *tr) | |||
755 | } | 754 | } |
756 | #endif /* CONFIG_BRANCH_TRACER */ | 755 | #endif /* CONFIG_BRANCH_TRACER */ |
757 | 756 | ||
758 | #ifdef CONFIG_HW_BRANCH_TRACER | ||
759 | int | ||
760 | trace_selftest_startup_hw_branches(struct tracer *trace, | ||
761 | struct trace_array *tr) | ||
762 | { | ||
763 | struct trace_iterator *iter; | ||
764 | struct tracer tracer; | ||
765 | unsigned long count; | ||
766 | int ret; | ||
767 | |||
768 | if (!trace->open) { | ||
769 | printk(KERN_CONT "missing open function..."); | ||
770 | return -1; | ||
771 | } | ||
772 | |||
773 | ret = tracer_init(trace, tr); | ||
774 | if (ret) { | ||
775 | warn_failed_init_tracer(trace, ret); | ||
776 | return ret; | ||
777 | } | ||
778 | |||
779 | /* | ||
780 | * The hw-branch tracer needs to collect the trace from the various | ||
781 | * cpu trace buffers - before tracing is stopped. | ||
782 | */ | ||
783 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); | ||
784 | if (!iter) | ||
785 | return -ENOMEM; | ||
786 | |||
787 | memcpy(&tracer, trace, sizeof(tracer)); | ||
788 | |||
789 | iter->trace = &tracer; | ||
790 | iter->tr = tr; | ||
791 | iter->pos = -1; | ||
792 | mutex_init(&iter->mutex); | ||
793 | |||
794 | trace->open(iter); | ||
795 | |||
796 | mutex_destroy(&iter->mutex); | ||
797 | kfree(iter); | ||
798 | |||
799 | tracing_stop(); | ||
800 | |||
801 | ret = trace_test_buffer(tr, &count); | ||
802 | trace->reset(tr); | ||
803 | tracing_start(); | ||
804 | |||
805 | if (!ret && !count) { | ||
806 | printk(KERN_CONT "no entries found.."); | ||
807 | ret = -1; | ||
808 | } | ||
809 | |||
810 | return ret; | ||
811 | } | ||
812 | #endif /* CONFIG_HW_BRANCH_TRACER */ | ||
813 | |||
814 | #ifdef CONFIG_KSYM_TRACER | 757 | #ifdef CONFIG_KSYM_TRACER |
815 | static int ksym_selftest_dummy; | 758 | static int ksym_selftest_dummy; |
816 | 759 | ||
diff --git a/mm/mlock.c b/mm/mlock.c index 8f4e2dfceec..3f82720e051 100644 --- a/mm/mlock.c +++ b/mm/mlock.c | |||
@@ -607,44 +607,3 @@ void user_shm_unlock(size_t size, struct user_struct *user) | |||
607 | spin_unlock(&shmlock_user_lock); | 607 | spin_unlock(&shmlock_user_lock); |
608 | free_uid(user); | 608 | free_uid(user); |
609 | } | 609 | } |
610 | |||
611 | int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim, | ||
612 | size_t size) | ||
613 | { | ||
614 | unsigned long lim, vm, pgsz; | ||
615 | int error = -ENOMEM; | ||
616 | |||
617 | pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT; | ||
618 | |||
619 | down_write(&mm->mmap_sem); | ||
620 | |||
621 | lim = ACCESS_ONCE(rlim[RLIMIT_AS].rlim_cur) >> PAGE_SHIFT; | ||
622 | vm = mm->total_vm + pgsz; | ||
623 | if (lim < vm) | ||
624 | goto out; | ||
625 | |||
626 | lim = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur) >> PAGE_SHIFT; | ||
627 | vm = mm->locked_vm + pgsz; | ||
628 | if (lim < vm) | ||
629 | goto out; | ||
630 | |||
631 | mm->total_vm += pgsz; | ||
632 | mm->locked_vm += pgsz; | ||
633 | |||
634 | error = 0; | ||
635 | out: | ||
636 | up_write(&mm->mmap_sem); | ||
637 | return error; | ||
638 | } | ||
639 | |||
640 | void refund_locked_memory(struct mm_struct *mm, size_t size) | ||
641 | { | ||
642 | unsigned long pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT; | ||
643 | |||
644 | down_write(&mm->mmap_sem); | ||
645 | |||
646 | mm->total_vm -= pgsz; | ||
647 | mm->locked_vm -= pgsz; | ||
648 | |||
649 | up_write(&mm->mmap_sem); | ||
650 | } | ||
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index 34202b1be0b..bb671b34677 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt | |||
@@ -57,6 +57,11 @@ OPTIONS | |||
57 | --force:: | 57 | --force:: |
58 | Forcibly add events with existing name. | 58 | Forcibly add events with existing name. |
59 | 59 | ||
60 | -n:: | ||
61 | --dry-run:: | ||
62 | Dry run. With this option, --add and --del doesn't execute actual | ||
63 | adding and removal operations. | ||
64 | |||
60 | PROBE SYNTAX | 65 | PROBE SYNTAX |
61 | ------------ | 66 | ------------ |
62 | Probe points are defined by following syntax. | 67 | Probe points are defined by following syntax. |
@@ -80,7 +85,7 @@ LINE SYNTAX | |||
80 | ----------- | 85 | ----------- |
81 | Line range is descripted by following syntax. | 86 | Line range is descripted by following syntax. |
82 | 87 | ||
83 | "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]" | 88 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]" |
84 | 89 | ||
85 | FUNC specifies the function name of showing lines. 'RLN' is the start line | 90 | FUNC specifies the function name of showing lines. 'RLN' is the start line |
86 | number from function entry line, and 'RLN2' is the end line number. As same as | 91 | number from function entry line, and 'RLN2' is the end line number. As same as |
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index bc0f670a833..f578b05a30e 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -1,3 +1,7 @@ | |||
1 | ifeq ("$(origin O)", "command line") | ||
2 | OUTPUT := $(O)/ | ||
3 | endif | ||
4 | |||
1 | # The default target of this Makefile is... | 5 | # The default target of this Makefile is... |
2 | all:: | 6 | all:: |
3 | 7 | ||
@@ -150,10 +154,16 @@ all:: | |||
150 | # Define LDFLAGS=-static to build a static binary. | 154 | # Define LDFLAGS=-static to build a static binary. |
151 | # | 155 | # |
152 | # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds. | 156 | # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds. |
157 | # | ||
158 | # Define NO_DWARF if you do not want debug-info analysis feature at all. | ||
153 | 159 | ||
154 | PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE | 160 | $(shell sh -c 'mkdir -p $(OUTPUT)scripts/python/Perf-Trace-Util/' 2> /dev/null) |
155 | @$(SHELL_PATH) util/PERF-VERSION-GEN | 161 | $(shell sh -c 'mkdir -p $(OUTPUT)util/scripting-engines/' 2> /dev/null) |
156 | -include PERF-VERSION-FILE | 162 | $(shell sh -c 'mkdir $(OUTPUT)bench' 2> /dev/null) |
163 | |||
164 | $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE | ||
165 | @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) | ||
166 | -include $(OUTPUT)PERF-VERSION-FILE | ||
157 | 167 | ||
158 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') | 168 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') |
159 | uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') | 169 | uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') |
@@ -308,7 +318,7 @@ PROGRAMS += $(EXTRA_PROGRAMS) | |||
308 | # | 318 | # |
309 | # Single 'perf' binary right now: | 319 | # Single 'perf' binary right now: |
310 | # | 320 | # |
311 | PROGRAMS += perf | 321 | PROGRAMS += $(OUTPUT)perf |
312 | 322 | ||
313 | # List built-in command $C whose implementation cmd_$C() is not in | 323 | # List built-in command $C whose implementation cmd_$C() is not in |
314 | # builtin-$C.o but is linked in as part of some other command. | 324 | # builtin-$C.o but is linked in as part of some other command. |
@@ -318,7 +328,7 @@ PROGRAMS += perf | |||
318 | ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) | 328 | ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) |
319 | 329 | ||
320 | # what 'all' will build but not install in perfexecdir | 330 | # what 'all' will build but not install in perfexecdir |
321 | OTHER_PROGRAMS = perf$X | 331 | OTHER_PROGRAMS = $(OUTPUT)perf$X |
322 | 332 | ||
323 | # Set paths to tools early so that they can be used for version tests. | 333 | # Set paths to tools early so that they can be used for version tests. |
324 | ifndef SHELL_PATH | 334 | ifndef SHELL_PATH |
@@ -330,7 +340,7 @@ endif | |||
330 | 340 | ||
331 | export PERL_PATH | 341 | export PERL_PATH |
332 | 342 | ||
333 | LIB_FILE=libperf.a | 343 | LIB_FILE=$(OUTPUT)libperf.a |
334 | 344 | ||
335 | LIB_H += ../../include/linux/perf_event.h | 345 | LIB_H += ../../include/linux/perf_event.h |
336 | LIB_H += ../../include/linux/rbtree.h | 346 | LIB_H += ../../include/linux/rbtree.h |
@@ -375,7 +385,6 @@ LIB_H += util/header.h | |||
375 | LIB_H += util/help.h | 385 | LIB_H += util/help.h |
376 | LIB_H += util/session.h | 386 | LIB_H += util/session.h |
377 | LIB_H += util/strbuf.h | 387 | LIB_H += util/strbuf.h |
378 | LIB_H += util/string.h | ||
379 | LIB_H += util/strlist.h | 388 | LIB_H += util/strlist.h |
380 | LIB_H += util/svghelper.h | 389 | LIB_H += util/svghelper.h |
381 | LIB_H += util/run-command.h | 390 | LIB_H += util/run-command.h |
@@ -391,77 +400,77 @@ LIB_H += util/probe-finder.h | |||
391 | LIB_H += util/probe-event.h | 400 | LIB_H += util/probe-event.h |
392 | LIB_H += util/cpumap.h | 401 | LIB_H += util/cpumap.h |
393 | 402 | ||
394 | LIB_OBJS += util/abspath.o | 403 | LIB_OBJS += $(OUTPUT)util/abspath.o |
395 | LIB_OBJS += util/alias.o | 404 | LIB_OBJS += $(OUTPUT)util/alias.o |
396 | LIB_OBJS += util/build-id.o | 405 | LIB_OBJS += $(OUTPUT)util/build-id.o |
397 | LIB_OBJS += util/config.o | 406 | LIB_OBJS += $(OUTPUT)util/config.o |
398 | LIB_OBJS += util/ctype.o | 407 | LIB_OBJS += $(OUTPUT)util/ctype.o |
399 | LIB_OBJS += util/debugfs.o | 408 | LIB_OBJS += $(OUTPUT)util/debugfs.o |
400 | LIB_OBJS += util/environment.o | 409 | LIB_OBJS += $(OUTPUT)util/environment.o |
401 | LIB_OBJS += util/event.o | 410 | LIB_OBJS += $(OUTPUT)util/event.o |
402 | LIB_OBJS += util/exec_cmd.o | 411 | LIB_OBJS += $(OUTPUT)util/exec_cmd.o |
403 | LIB_OBJS += util/help.o | 412 | LIB_OBJS += $(OUTPUT)util/help.o |
404 | LIB_OBJS += util/levenshtein.o | 413 | LIB_OBJS += $(OUTPUT)util/levenshtein.o |
405 | LIB_OBJS += util/parse-options.o | 414 | LIB_OBJS += $(OUTPUT)util/parse-options.o |
406 | LIB_OBJS += util/parse-events.o | 415 | LIB_OBJS += $(OUTPUT)util/parse-events.o |
407 | LIB_OBJS += util/path.o | 416 | LIB_OBJS += $(OUTPUT)util/path.o |
408 | LIB_OBJS += util/rbtree.o | 417 | LIB_OBJS += $(OUTPUT)util/rbtree.o |
409 | LIB_OBJS += util/bitmap.o | 418 | LIB_OBJS += $(OUTPUT)util/bitmap.o |
410 | LIB_OBJS += util/hweight.o | 419 | LIB_OBJS += $(OUTPUT)util/hweight.o |
411 | LIB_OBJS += util/find_next_bit.o | 420 | LIB_OBJS += $(OUTPUT)util/find_next_bit.o |
412 | LIB_OBJS += util/run-command.o | 421 | LIB_OBJS += $(OUTPUT)util/run-command.o |
413 | LIB_OBJS += util/quote.o | 422 | LIB_OBJS += $(OUTPUT)util/quote.o |
414 | LIB_OBJS += util/strbuf.o | 423 | LIB_OBJS += $(OUTPUT)util/strbuf.o |
415 | LIB_OBJS += util/string.o | 424 | LIB_OBJS += $(OUTPUT)util/string.o |
416 | LIB_OBJS += util/strlist.o | 425 | LIB_OBJS += $(OUTPUT)util/strlist.o |
417 | LIB_OBJS += util/usage.o | 426 | LIB_OBJS += $(OUTPUT)util/usage.o |
418 | LIB_OBJS += util/wrapper.o | 427 | LIB_OBJS += $(OUTPUT)util/wrapper.o |
419 | LIB_OBJS += util/sigchain.o | 428 | LIB_OBJS += $(OUTPUT)util/sigchain.o |
420 | LIB_OBJS += util/symbol.o | 429 | LIB_OBJS += $(OUTPUT)util/symbol.o |
421 | LIB_OBJS += util/color.o | 430 | LIB_OBJS += $(OUTPUT)util/color.o |
422 | LIB_OBJS += util/pager.o | 431 | LIB_OBJS += $(OUTPUT)util/pager.o |
423 | LIB_OBJS += util/header.o | 432 | LIB_OBJS += $(OUTPUT)util/header.o |
424 | LIB_OBJS += util/callchain.o | 433 | LIB_OBJS += $(OUTPUT)util/callchain.o |
425 | LIB_OBJS += util/values.o | 434 | LIB_OBJS += $(OUTPUT)util/values.o |
426 | LIB_OBJS += util/debug.o | 435 | LIB_OBJS += $(OUTPUT)util/debug.o |
427 | LIB_OBJS += util/map.o | 436 | LIB_OBJS += $(OUTPUT)util/map.o |
428 | LIB_OBJS += util/session.o | 437 | LIB_OBJS += $(OUTPUT)util/session.o |
429 | LIB_OBJS += util/thread.o | 438 | LIB_OBJS += $(OUTPUT)util/thread.o |
430 | LIB_OBJS += util/trace-event-parse.o | 439 | LIB_OBJS += $(OUTPUT)util/trace-event-parse.o |
431 | LIB_OBJS += util/trace-event-read.o | 440 | LIB_OBJS += $(OUTPUT)util/trace-event-read.o |
432 | LIB_OBJS += util/trace-event-info.o | 441 | LIB_OBJS += $(OUTPUT)util/trace-event-info.o |
433 | LIB_OBJS += util/trace-event-scripting.o | 442 | LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o |
434 | LIB_OBJS += util/svghelper.o | 443 | LIB_OBJS += $(OUTPUT)util/svghelper.o |
435 | LIB_OBJS += util/sort.o | 444 | LIB_OBJS += $(OUTPUT)util/sort.o |
436 | LIB_OBJS += util/hist.o | 445 | LIB_OBJS += $(OUTPUT)util/hist.o |
437 | LIB_OBJS += util/probe-event.o | 446 | LIB_OBJS += $(OUTPUT)util/probe-event.o |
438 | LIB_OBJS += util/util.o | 447 | LIB_OBJS += $(OUTPUT)util/util.o |
439 | LIB_OBJS += util/cpumap.o | 448 | LIB_OBJS += $(OUTPUT)util/cpumap.o |
440 | 449 | ||
441 | BUILTIN_OBJS += builtin-annotate.o | 450 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o |
442 | 451 | ||
443 | BUILTIN_OBJS += builtin-bench.o | 452 | BUILTIN_OBJS += $(OUTPUT)builtin-bench.o |
444 | 453 | ||
445 | # Benchmark modules | 454 | # Benchmark modules |
446 | BUILTIN_OBJS += bench/sched-messaging.o | 455 | BUILTIN_OBJS += $(OUTPUT)bench/sched-messaging.o |
447 | BUILTIN_OBJS += bench/sched-pipe.o | 456 | BUILTIN_OBJS += $(OUTPUT)bench/sched-pipe.o |
448 | BUILTIN_OBJS += bench/mem-memcpy.o | 457 | BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o |
449 | 458 | ||
450 | BUILTIN_OBJS += builtin-diff.o | 459 | BUILTIN_OBJS += $(OUTPUT)builtin-diff.o |
451 | BUILTIN_OBJS += builtin-help.o | 460 | BUILTIN_OBJS += $(OUTPUT)builtin-help.o |
452 | BUILTIN_OBJS += builtin-sched.o | 461 | BUILTIN_OBJS += $(OUTPUT)builtin-sched.o |
453 | BUILTIN_OBJS += builtin-buildid-list.o | 462 | BUILTIN_OBJS += $(OUTPUT)builtin-buildid-list.o |
454 | BUILTIN_OBJS += builtin-buildid-cache.o | 463 | BUILTIN_OBJS += $(OUTPUT)builtin-buildid-cache.o |
455 | BUILTIN_OBJS += builtin-list.o | 464 | BUILTIN_OBJS += $(OUTPUT)builtin-list.o |
456 | BUILTIN_OBJS += builtin-record.o | 465 | BUILTIN_OBJS += $(OUTPUT)builtin-record.o |
457 | BUILTIN_OBJS += builtin-report.o | 466 | BUILTIN_OBJS += $(OUTPUT)builtin-report.o |
458 | BUILTIN_OBJS += builtin-stat.o | 467 | BUILTIN_OBJS += $(OUTPUT)builtin-stat.o |
459 | BUILTIN_OBJS += builtin-timechart.o | 468 | BUILTIN_OBJS += $(OUTPUT)builtin-timechart.o |
460 | BUILTIN_OBJS += builtin-top.o | 469 | BUILTIN_OBJS += $(OUTPUT)builtin-top.o |
461 | BUILTIN_OBJS += builtin-trace.o | 470 | BUILTIN_OBJS += $(OUTPUT)builtin-trace.o |
462 | BUILTIN_OBJS += builtin-probe.o | 471 | BUILTIN_OBJS += $(OUTPUT)builtin-probe.o |
463 | BUILTIN_OBJS += builtin-kmem.o | 472 | BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o |
464 | BUILTIN_OBJS += builtin-lock.o | 473 | BUILTIN_OBJS += $(OUTPUT)builtin-lock.o |
465 | 474 | ||
466 | PERFLIBS = $(LIB_FILE) | 475 | PERFLIBS = $(LIB_FILE) |
467 | 476 | ||
@@ -492,6 +501,10 @@ ifeq ($(uname_S),Darwin) | |||
492 | PTHREAD_LIBS = | 501 | PTHREAD_LIBS = |
493 | endif | 502 | endif |
494 | 503 | ||
504 | ifneq ($(OUTPUT),) | ||
505 | BASIC_CFLAGS += -I$(OUTPUT) | ||
506 | endif | ||
507 | |||
495 | ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | 508 | ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) |
496 | ifneq ($(shell sh -c "(echo '\#include <gnu/libc-version.h>'; echo 'int main(void) { const char * version = gnu_get_libc_version(); return (long)version; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | 509 | ifneq ($(shell sh -c "(echo '\#include <gnu/libc-version.h>'; echo 'int main(void) { const char * version = gnu_get_libc_version(); return (long)version; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) |
497 | msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static); | 510 | msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static); |
@@ -506,11 +519,20 @@ endif | |||
506 | 519 | ||
507 | ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | 520 | ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) |
508 | msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev); | 521 | msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev); |
509 | BASIC_CFLAGS += -DNO_DWARF_SUPPORT | ||
510 | else | 522 | else |
511 | BASIC_CFLAGS += -I/usr/include/elfutils | 523 | ifndef NO_DWARF |
524 | BASIC_CFLAGS += -I/usr/include/elfutils -DDWARF_SUPPORT | ||
512 | EXTLIBS += -lelf -ldw | 525 | EXTLIBS += -lelf -ldw |
513 | LIB_OBJS += util/probe-finder.o | 526 | LIB_OBJS += $(OUTPUT)util/probe-finder.o |
527 | endif | ||
528 | endif | ||
529 | |||
530 | ifneq ($(shell sh -c "(echo '\#include <newt.h>'; echo 'int main(void) { newtInit(); newtCls(); return newtFinished(); }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -lnewt -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | ||
531 | msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev); | ||
532 | BASIC_CFLAGS += -DNO_NEWT_SUPPORT | ||
533 | else | ||
534 | EXTLIBS += -lnewt | ||
535 | LIB_OBJS += $(OUTPUT)util/newt.o | ||
514 | endif | 536 | endif |
515 | 537 | ||
516 | ifndef NO_LIBPERL | 538 | ifndef NO_LIBPERL |
@@ -522,8 +544,8 @@ ifneq ($(shell sh -c "(echo '\#include <EXTERN.h>'; echo '\#include <perl.h>'; e | |||
522 | BASIC_CFLAGS += -DNO_LIBPERL | 544 | BASIC_CFLAGS += -DNO_LIBPERL |
523 | else | 545 | else |
524 | ALL_LDFLAGS += $(PERL_EMBED_LDOPTS) | 546 | ALL_LDFLAGS += $(PERL_EMBED_LDOPTS) |
525 | LIB_OBJS += util/scripting-engines/trace-event-perl.o | 547 | LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o |
526 | LIB_OBJS += scripts/perl/Perf-Trace-Util/Context.o | 548 | LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o |
527 | endif | 549 | endif |
528 | 550 | ||
529 | ifndef NO_LIBPYTHON | 551 | ifndef NO_LIBPYTHON |
@@ -531,12 +553,12 @@ PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null` | |||
531 | PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null` | 553 | PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null` |
532 | endif | 554 | endif |
533 | 555 | ||
534 | ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o /dev/null $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y) | 556 | ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o $(BITBUCKET) $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y) |
535 | BASIC_CFLAGS += -DNO_LIBPYTHON | 557 | BASIC_CFLAGS += -DNO_LIBPYTHON |
536 | else | 558 | else |
537 | ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS) | 559 | ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS) |
538 | LIB_OBJS += util/scripting-engines/trace-event-python.o | 560 | LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o |
539 | LIB_OBJS += scripts/python/Perf-Trace-Util/Context.o | 561 | LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o |
540 | endif | 562 | endif |
541 | 563 | ||
542 | ifdef NO_DEMANGLE | 564 | ifdef NO_DEMANGLE |
@@ -607,53 +629,53 @@ ifdef NO_C99_FORMAT | |||
607 | endif | 629 | endif |
608 | ifdef SNPRINTF_RETURNS_BOGUS | 630 | ifdef SNPRINTF_RETURNS_BOGUS |
609 | COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS | 631 | COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS |
610 | COMPAT_OBJS += compat/snprintf.o | 632 | COMPAT_OBJS += $(OUTPUT)compat/snprintf.o |
611 | endif | 633 | endif |
612 | ifdef FREAD_READS_DIRECTORIES | 634 | ifdef FREAD_READS_DIRECTORIES |
613 | COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES | 635 | COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES |
614 | COMPAT_OBJS += compat/fopen.o | 636 | COMPAT_OBJS += $(OUTPUT)compat/fopen.o |
615 | endif | 637 | endif |
616 | ifdef NO_SYMLINK_HEAD | 638 | ifdef NO_SYMLINK_HEAD |
617 | BASIC_CFLAGS += -DNO_SYMLINK_HEAD | 639 | BASIC_CFLAGS += -DNO_SYMLINK_HEAD |
618 | endif | 640 | endif |
619 | ifdef NO_STRCASESTR | 641 | ifdef NO_STRCASESTR |
620 | COMPAT_CFLAGS += -DNO_STRCASESTR | 642 | COMPAT_CFLAGS += -DNO_STRCASESTR |
621 | COMPAT_OBJS += compat/strcasestr.o | 643 | COMPAT_OBJS += $(OUTPUT)compat/strcasestr.o |
622 | endif | 644 | endif |
623 | ifdef NO_STRTOUMAX | 645 | ifdef NO_STRTOUMAX |
624 | COMPAT_CFLAGS += -DNO_STRTOUMAX | 646 | COMPAT_CFLAGS += -DNO_STRTOUMAX |
625 | COMPAT_OBJS += compat/strtoumax.o | 647 | COMPAT_OBJS += $(OUTPUT)compat/strtoumax.o |
626 | endif | 648 | endif |
627 | ifdef NO_STRTOULL | 649 | ifdef NO_STRTOULL |
628 | COMPAT_CFLAGS += -DNO_STRTOULL | 650 | COMPAT_CFLAGS += -DNO_STRTOULL |
629 | endif | 651 | endif |
630 | ifdef NO_SETENV | 652 | ifdef NO_SETENV |
631 | COMPAT_CFLAGS += -DNO_SETENV | 653 | COMPAT_CFLAGS += -DNO_SETENV |
632 | COMPAT_OBJS += compat/setenv.o | 654 | COMPAT_OBJS += $(OUTPUT)compat/setenv.o |
633 | endif | 655 | endif |
634 | ifdef NO_MKDTEMP | 656 | ifdef NO_MKDTEMP |
635 | COMPAT_CFLAGS += -DNO_MKDTEMP | 657 | COMPAT_CFLAGS += -DNO_MKDTEMP |
636 | COMPAT_OBJS += compat/mkdtemp.o | 658 | COMPAT_OBJS += $(OUTPUT)compat/mkdtemp.o |
637 | endif | 659 | endif |
638 | ifdef NO_UNSETENV | 660 | ifdef NO_UNSETENV |
639 | COMPAT_CFLAGS += -DNO_UNSETENV | 661 | COMPAT_CFLAGS += -DNO_UNSETENV |
640 | COMPAT_OBJS += compat/unsetenv.o | 662 | COMPAT_OBJS += $(OUTPUT)compat/unsetenv.o |
641 | endif | 663 | endif |
642 | ifdef NO_SYS_SELECT_H | 664 | ifdef NO_SYS_SELECT_H |
643 | BASIC_CFLAGS += -DNO_SYS_SELECT_H | 665 | BASIC_CFLAGS += -DNO_SYS_SELECT_H |
644 | endif | 666 | endif |
645 | ifdef NO_MMAP | 667 | ifdef NO_MMAP |
646 | COMPAT_CFLAGS += -DNO_MMAP | 668 | COMPAT_CFLAGS += -DNO_MMAP |
647 | COMPAT_OBJS += compat/mmap.o | 669 | COMPAT_OBJS += $(OUTPUT)compat/mmap.o |
648 | else | 670 | else |
649 | ifdef USE_WIN32_MMAP | 671 | ifdef USE_WIN32_MMAP |
650 | COMPAT_CFLAGS += -DUSE_WIN32_MMAP | 672 | COMPAT_CFLAGS += -DUSE_WIN32_MMAP |
651 | COMPAT_OBJS += compat/win32mmap.o | 673 | COMPAT_OBJS += $(OUTPUT)compat/win32mmap.o |
652 | endif | 674 | endif |
653 | endif | 675 | endif |
654 | ifdef NO_PREAD | 676 | ifdef NO_PREAD |
655 | COMPAT_CFLAGS += -DNO_PREAD | 677 | COMPAT_CFLAGS += -DNO_PREAD |
656 | COMPAT_OBJS += compat/pread.o | 678 | COMPAT_OBJS += $(OUTPUT)compat/pread.o |
657 | endif | 679 | endif |
658 | ifdef NO_FAST_WORKING_DIRECTORY | 680 | ifdef NO_FAST_WORKING_DIRECTORY |
659 | BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY | 681 | BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY |
@@ -675,10 +697,10 @@ else | |||
675 | endif | 697 | endif |
676 | endif | 698 | endif |
677 | ifdef NO_INET_NTOP | 699 | ifdef NO_INET_NTOP |
678 | LIB_OBJS += compat/inet_ntop.o | 700 | LIB_OBJS += $(OUTPUT)compat/inet_ntop.o |
679 | endif | 701 | endif |
680 | ifdef NO_INET_PTON | 702 | ifdef NO_INET_PTON |
681 | LIB_OBJS += compat/inet_pton.o | 703 | LIB_OBJS += $(OUTPUT)compat/inet_pton.o |
682 | endif | 704 | endif |
683 | 705 | ||
684 | ifdef NO_ICONV | 706 | ifdef NO_ICONV |
@@ -695,15 +717,15 @@ endif | |||
695 | 717 | ||
696 | ifdef PPC_SHA1 | 718 | ifdef PPC_SHA1 |
697 | SHA1_HEADER = "ppc/sha1.h" | 719 | SHA1_HEADER = "ppc/sha1.h" |
698 | LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o | 720 | LIB_OBJS += $(OUTPUT)ppc/sha1.o ppc/sha1ppc.o |
699 | else | 721 | else |
700 | ifdef ARM_SHA1 | 722 | ifdef ARM_SHA1 |
701 | SHA1_HEADER = "arm/sha1.h" | 723 | SHA1_HEADER = "arm/sha1.h" |
702 | LIB_OBJS += arm/sha1.o arm/sha1_arm.o | 724 | LIB_OBJS += $(OUTPUT)arm/sha1.o $(OUTPUT)arm/sha1_arm.o |
703 | else | 725 | else |
704 | ifdef MOZILLA_SHA1 | 726 | ifdef MOZILLA_SHA1 |
705 | SHA1_HEADER = "mozilla-sha1/sha1.h" | 727 | SHA1_HEADER = "mozilla-sha1/sha1.h" |
706 | LIB_OBJS += mozilla-sha1/sha1.o | 728 | LIB_OBJS += $(OUTPUT)mozilla-sha1/sha1.o |
707 | else | 729 | else |
708 | SHA1_HEADER = <openssl/sha.h> | 730 | SHA1_HEADER = <openssl/sha.h> |
709 | EXTLIBS += $(LIB_4_CRYPTO) | 731 | EXTLIBS += $(LIB_4_CRYPTO) |
@@ -715,15 +737,15 @@ ifdef NO_PERL_MAKEMAKER | |||
715 | endif | 737 | endif |
716 | ifdef NO_HSTRERROR | 738 | ifdef NO_HSTRERROR |
717 | COMPAT_CFLAGS += -DNO_HSTRERROR | 739 | COMPAT_CFLAGS += -DNO_HSTRERROR |
718 | COMPAT_OBJS += compat/hstrerror.o | 740 | COMPAT_OBJS += $(OUTPUT)compat/hstrerror.o |
719 | endif | 741 | endif |
720 | ifdef NO_MEMMEM | 742 | ifdef NO_MEMMEM |
721 | COMPAT_CFLAGS += -DNO_MEMMEM | 743 | COMPAT_CFLAGS += -DNO_MEMMEM |
722 | COMPAT_OBJS += compat/memmem.o | 744 | COMPAT_OBJS += $(OUTPUT)compat/memmem.o |
723 | endif | 745 | endif |
724 | ifdef INTERNAL_QSORT | 746 | ifdef INTERNAL_QSORT |
725 | COMPAT_CFLAGS += -DINTERNAL_QSORT | 747 | COMPAT_CFLAGS += -DINTERNAL_QSORT |
726 | COMPAT_OBJS += compat/qsort.o | 748 | COMPAT_OBJS += $(OUTPUT)compat/qsort.o |
727 | endif | 749 | endif |
728 | ifdef RUNTIME_PREFIX | 750 | ifdef RUNTIME_PREFIX |
729 | COMPAT_CFLAGS += -DRUNTIME_PREFIX | 751 | COMPAT_CFLAGS += -DRUNTIME_PREFIX |
@@ -803,7 +825,7 @@ export TAR INSTALL DESTDIR SHELL_PATH | |||
803 | 825 | ||
804 | SHELL = $(SHELL_PATH) | 826 | SHELL = $(SHELL_PATH) |
805 | 827 | ||
806 | all:: .perf.dev.null shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) PERF-BUILD-OPTIONS | 828 | all:: .perf.dev.null shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) $(OUTPUT)PERF-BUILD-OPTIONS |
807 | ifneq (,$X) | 829 | ifneq (,$X) |
808 | $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) perf$X)), test '$p' -ef '$p$X' || $(RM) '$p';) | 830 | $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) perf$X)), test '$p' -ef '$p$X' || $(RM) '$p';) |
809 | endif | 831 | endif |
@@ -815,39 +837,39 @@ please_set_SHELL_PATH_to_a_more_modern_shell: | |||
815 | 837 | ||
816 | shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell | 838 | shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell |
817 | 839 | ||
818 | strip: $(PROGRAMS) perf$X | 840 | strip: $(PROGRAMS) $(OUTPUT)perf$X |
819 | $(STRIP) $(STRIP_OPTS) $(PROGRAMS) perf$X | 841 | $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf$X |
820 | 842 | ||
821 | perf.o: perf.c common-cmds.h PERF-CFLAGS | 843 | $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS |
822 | $(QUIET_CC)$(CC) -DPERF_VERSION='"$(PERF_VERSION)"' \ | 844 | $(QUIET_CC)$(CC) -DPERF_VERSION='"$(PERF_VERSION)"' \ |
823 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ | 845 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ |
824 | $(ALL_CFLAGS) -c $(filter %.c,$^) | 846 | $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@ |
825 | 847 | ||
826 | perf$X: perf.o $(BUILTIN_OBJS) $(PERFLIBS) | 848 | $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) |
827 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ perf.o \ | 849 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \ |
828 | $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) | 850 | $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) |
829 | 851 | ||
830 | builtin-help.o: builtin-help.c common-cmds.h PERF-CFLAGS | 852 | $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS |
831 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \ | 853 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ |
832 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ | 854 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ |
833 | '-DPERF_MAN_PATH="$(mandir_SQ)"' \ | 855 | '-DPERF_MAN_PATH="$(mandir_SQ)"' \ |
834 | '-DPERF_INFO_PATH="$(infodir_SQ)"' $< | 856 | '-DPERF_INFO_PATH="$(infodir_SQ)"' $< |
835 | 857 | ||
836 | builtin-timechart.o: builtin-timechart.c common-cmds.h PERF-CFLAGS | 858 | $(OUTPUT)builtin-timechart.o: builtin-timechart.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS |
837 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \ | 859 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ |
838 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ | 860 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ |
839 | '-DPERF_MAN_PATH="$(mandir_SQ)"' \ | 861 | '-DPERF_MAN_PATH="$(mandir_SQ)"' \ |
840 | '-DPERF_INFO_PATH="$(infodir_SQ)"' $< | 862 | '-DPERF_INFO_PATH="$(infodir_SQ)"' $< |
841 | 863 | ||
842 | $(BUILT_INS): perf$X | 864 | $(BUILT_INS): $(OUTPUT)perf$X |
843 | $(QUIET_BUILT_IN)$(RM) $@ && \ | 865 | $(QUIET_BUILT_IN)$(RM) $@ && \ |
844 | ln perf$X $@ 2>/dev/null || \ | 866 | ln perf$X $@ 2>/dev/null || \ |
845 | ln -s perf$X $@ 2>/dev/null || \ | 867 | ln -s perf$X $@ 2>/dev/null || \ |
846 | cp perf$X $@ | 868 | cp perf$X $@ |
847 | 869 | ||
848 | common-cmds.h: util/generate-cmdlist.sh command-list.txt | 870 | $(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt |
849 | 871 | ||
850 | common-cmds.h: $(wildcard Documentation/perf-*.txt) | 872 | $(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt) |
851 | $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@ | 873 | $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@ |
852 | 874 | ||
853 | $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh | 875 | $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh |
@@ -859,7 +881,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh | |||
859 | -e 's/@@NO_CURL@@/$(NO_CURL)/g' \ | 881 | -e 's/@@NO_CURL@@/$(NO_CURL)/g' \ |
860 | $@.sh >$@+ && \ | 882 | $@.sh >$@+ && \ |
861 | chmod +x $@+ && \ | 883 | chmod +x $@+ && \ |
862 | mv $@+ $@ | 884 | mv $@+ $(OUTPUT)$@ |
863 | 885 | ||
864 | configure: configure.ac | 886 | configure: configure.ac |
865 | $(QUIET_GEN)$(RM) $@ $<+ && \ | 887 | $(QUIET_GEN)$(RM) $@ $<+ && \ |
@@ -869,60 +891,60 @@ configure: configure.ac | |||
869 | $(RM) $<+ | 891 | $(RM) $<+ |
870 | 892 | ||
871 | # These can record PERF_VERSION | 893 | # These can record PERF_VERSION |
872 | perf.o perf.spec \ | 894 | $(OUTPUT)perf.o perf.spec \ |
873 | $(patsubst %.sh,%,$(SCRIPT_SH)) \ | 895 | $(patsubst %.sh,%,$(SCRIPT_SH)) \ |
874 | $(patsubst %.perl,%,$(SCRIPT_PERL)) \ | 896 | $(patsubst %.perl,%,$(SCRIPT_PERL)) \ |
875 | : PERF-VERSION-FILE | 897 | : $(OUTPUT)PERF-VERSION-FILE |
876 | 898 | ||
877 | %.o: %.c PERF-CFLAGS | 899 | $(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS |
878 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< | 900 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< |
879 | %.s: %.c PERF-CFLAGS | 901 | $(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS |
880 | $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< | 902 | $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< |
881 | %.o: %.S | 903 | $(OUTPUT)%.o: %.S |
882 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< | 904 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< |
883 | 905 | ||
884 | util/exec_cmd.o: util/exec_cmd.c PERF-CFLAGS | 906 | $(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS |
885 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \ | 907 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ |
886 | '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \ | 908 | '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \ |
887 | '-DBINDIR="$(bindir_relative_SQ)"' \ | 909 | '-DBINDIR="$(bindir_relative_SQ)"' \ |
888 | '-DPREFIX="$(prefix_SQ)"' \ | 910 | '-DPREFIX="$(prefix_SQ)"' \ |
889 | $< | 911 | $< |
890 | 912 | ||
891 | builtin-init-db.o: builtin-init-db.c PERF-CFLAGS | 913 | $(OUTPUT)builtin-init-db.o: builtin-init-db.c $(OUTPUT)PERF-CFLAGS |
892 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_PERF_TEMPLATE_DIR='"$(template_dir_SQ)"' $< | 914 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DDEFAULT_PERF_TEMPLATE_DIR='"$(template_dir_SQ)"' $< |
893 | 915 | ||
894 | util/config.o: util/config.c PERF-CFLAGS | 916 | $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS |
895 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 917 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
896 | 918 | ||
897 | util/rbtree.o: ../../lib/rbtree.c PERF-CFLAGS | 919 | $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS |
898 | $(QUIET_CC)$(CC) -o util/rbtree.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 920 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
899 | 921 | ||
900 | # some perf warning policies can't fit to lib/bitmap.c, eg: it warns about variable shadowing | 922 | # some perf warning policies can't fit to lib/bitmap.c, eg: it warns about variable shadowing |
901 | # from <string.h> that comes from kernel headers wrapping. | 923 | # from <string.h> that comes from kernel headers wrapping. |
902 | KBITMAP_FLAGS=`echo $(ALL_CFLAGS) | sed s/-Wshadow// | sed s/-Wswitch-default// | sed s/-Wextra//` | 924 | KBITMAP_FLAGS=`echo $(ALL_CFLAGS) | sed s/-Wshadow// | sed s/-Wswitch-default// | sed s/-Wextra//` |
903 | 925 | ||
904 | util/bitmap.o: ../../lib/bitmap.c PERF-CFLAGS | 926 | $(OUTPUT)util/bitmap.o: ../../lib/bitmap.c $(OUTPUT)PERF-CFLAGS |
905 | $(QUIET_CC)$(CC) -o util/bitmap.o -c $(KBITMAP_FLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 927 | $(QUIET_CC)$(CC) -o $@ -c $(KBITMAP_FLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
906 | 928 | ||
907 | util/hweight.o: ../../lib/hweight.c PERF-CFLAGS | 929 | $(OUTPUT)util/hweight.o: ../../lib/hweight.c $(OUTPUT)PERF-CFLAGS |
908 | $(QUIET_CC)$(CC) -o util/hweight.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 930 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
909 | 931 | ||
910 | util/find_next_bit.o: ../../lib/find_next_bit.c PERF-CFLAGS | 932 | $(OUTPUT)util/find_next_bit.o: ../../lib/find_next_bit.c $(OUTPUT)PERF-CFLAGS |
911 | $(QUIET_CC)$(CC) -o util/find_next_bit.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 933 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
912 | 934 | ||
913 | util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c PERF-CFLAGS | 935 | $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS |
914 | $(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-perl.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< | 936 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< |
915 | 937 | ||
916 | scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c PERF-CFLAGS | 938 | $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS |
917 | $(QUIET_CC)$(CC) -o scripts/perl/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< | 939 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< |
918 | 940 | ||
919 | util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c PERF-CFLAGS | 941 | $(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c $(OUTPUT)PERF-CFLAGS |
920 | $(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-python.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< | 942 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< |
921 | 943 | ||
922 | scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c PERF-CFLAGS | 944 | $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS |
923 | $(QUIET_CC)$(CC) -o scripts/python/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< | 945 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< |
924 | 946 | ||
925 | perf-%$X: %.o $(PERFLIBS) | 947 | $(OUTPUT)perf-%$X: %.o $(PERFLIBS) |
926 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) | 948 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) |
927 | 949 | ||
928 | $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) | 950 | $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) |
@@ -963,17 +985,17 @@ cscope: | |||
963 | TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ | 985 | TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ |
964 | $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ) | 986 | $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ) |
965 | 987 | ||
966 | PERF-CFLAGS: .FORCE-PERF-CFLAGS | 988 | $(OUTPUT)PERF-CFLAGS: .FORCE-PERF-CFLAGS |
967 | @FLAGS='$(TRACK_CFLAGS)'; \ | 989 | @FLAGS='$(TRACK_CFLAGS)'; \ |
968 | if test x"$$FLAGS" != x"`cat PERF-CFLAGS 2>/dev/null`" ; then \ | 990 | if test x"$$FLAGS" != x"`cat $(OUTPUT)PERF-CFLAGS 2>/dev/null`" ; then \ |
969 | echo 1>&2 " * new build flags or prefix"; \ | 991 | echo 1>&2 " * new build flags or prefix"; \ |
970 | echo "$$FLAGS" >PERF-CFLAGS; \ | 992 | echo "$$FLAGS" >$(OUTPUT)PERF-CFLAGS; \ |
971 | fi | 993 | fi |
972 | 994 | ||
973 | # We need to apply sq twice, once to protect from the shell | 995 | # We need to apply sq twice, once to protect from the shell |
974 | # that runs PERF-BUILD-OPTIONS, and then again to protect it | 996 | # that runs $(OUTPUT)PERF-BUILD-OPTIONS, and then again to protect it |
975 | # and the first level quoting from the shell that runs "echo". | 997 | # and the first level quoting from the shell that runs "echo". |
976 | PERF-BUILD-OPTIONS: .FORCE-PERF-BUILD-OPTIONS | 998 | $(OUTPUT)PERF-BUILD-OPTIONS: .FORCE-PERF-BUILD-OPTIONS |
977 | @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@ | 999 | @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@ |
978 | @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@ | 1000 | @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@ |
979 | @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@ | 1001 | @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@ |
@@ -994,7 +1016,7 @@ all:: $(TEST_PROGRAMS) | |||
994 | 1016 | ||
995 | export NO_SVN_TESTS | 1017 | export NO_SVN_TESTS |
996 | 1018 | ||
997 | check: common-cmds.h | 1019 | check: $(OUTPUT)common-cmds.h |
998 | if sparse; \ | 1020 | if sparse; \ |
999 | then \ | 1021 | then \ |
1000 | for i in *.c */*.c; \ | 1022 | for i in *.c */*.c; \ |
@@ -1028,10 +1050,10 @@ export perfexec_instdir | |||
1028 | 1050 | ||
1029 | install: all | 1051 | install: all |
1030 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)' | 1052 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)' |
1031 | $(INSTALL) perf$X '$(DESTDIR_SQ)$(bindir_SQ)' | 1053 | $(INSTALL) $(OUTPUT)perf$X '$(DESTDIR_SQ)$(bindir_SQ)' |
1032 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' | 1054 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' |
1033 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' | 1055 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' |
1034 | $(INSTALL) perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 1056 | $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
1035 | $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' | 1057 | $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' |
1036 | $(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl' | 1058 | $(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl' |
1037 | $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' | 1059 | $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' |
@@ -1045,7 +1067,7 @@ ifdef BUILT_INS | |||
1045 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 1067 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
1046 | $(INSTALL) $(BUILT_INS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 1068 | $(INSTALL) $(BUILT_INS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
1047 | ifneq (,$X) | 1069 | ifneq (,$X) |
1048 | $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) perf$X)), $(RM) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$p';) | 1070 | $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) $(OUTPUT)perf$X)), $(RM) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$p';) |
1049 | endif | 1071 | endif |
1050 | endif | 1072 | endif |
1051 | 1073 | ||
@@ -1129,14 +1151,14 @@ clean: | |||
1129 | $(RM) *.o */*.o */*/*.o */*/*/*.o $(LIB_FILE) | 1151 | $(RM) *.o */*.o */*/*.o */*/*/*.o $(LIB_FILE) |
1130 | $(RM) $(ALL_PROGRAMS) $(BUILT_INS) perf$X | 1152 | $(RM) $(ALL_PROGRAMS) $(BUILT_INS) perf$X |
1131 | $(RM) $(TEST_PROGRAMS) | 1153 | $(RM) $(TEST_PROGRAMS) |
1132 | $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope* | 1154 | $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* |
1133 | $(RM) -r autom4te.cache | 1155 | $(RM) -r autom4te.cache |
1134 | $(RM) config.log config.mak.autogen config.mak.append config.status config.cache | 1156 | $(RM) config.log config.mak.autogen config.mak.append config.status config.cache |
1135 | $(RM) -r $(PERF_TARNAME) .doc-tmp-dir | 1157 | $(RM) -r $(PERF_TARNAME) .doc-tmp-dir |
1136 | $(RM) $(PERF_TARNAME).tar.gz perf-core_$(PERF_VERSION)-*.tar.gz | 1158 | $(RM) $(PERF_TARNAME).tar.gz perf-core_$(PERF_VERSION)-*.tar.gz |
1137 | $(RM) $(htmldocs).tar.gz $(manpages).tar.gz | 1159 | $(RM) $(htmldocs).tar.gz $(manpages).tar.gz |
1138 | $(MAKE) -C Documentation/ clean | 1160 | $(MAKE) -C Documentation/ clean |
1139 | $(RM) PERF-VERSION-FILE PERF-CFLAGS PERF-BUILD-OPTIONS | 1161 | $(RM) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)PERF-BUILD-OPTIONS |
1140 | 1162 | ||
1141 | .PHONY: all install clean strip | 1163 | .PHONY: all install clean strip |
1142 | .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell | 1164 | .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell |
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c index 89773178e89..52e646e3e87 100644 --- a/tools/perf/bench/mem-memcpy.c +++ b/tools/perf/bench/mem-memcpy.c | |||
@@ -10,7 +10,6 @@ | |||
10 | #include "../perf.h" | 10 | #include "../perf.h" |
11 | #include "../util/util.h" | 11 | #include "../util/util.h" |
12 | #include "../util/parse-options.h" | 12 | #include "../util/parse-options.h" |
13 | #include "../util/string.h" | ||
14 | #include "../util/header.h" | 13 | #include "../util/header.h" |
15 | #include "bench.h" | 14 | #include "bench.h" |
16 | 15 | ||
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 6ad7148451c..ee0d9172699 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include "util/cache.h" | 14 | #include "util/cache.h" |
15 | #include <linux/rbtree.h> | 15 | #include <linux/rbtree.h> |
16 | #include "util/symbol.h" | 16 | #include "util/symbol.h" |
17 | #include "util/string.h" | ||
18 | 17 | ||
19 | #include "perf.h" | 18 | #include "perf.h" |
20 | #include "util/debug.h" | 19 | #include "util/debug.h" |
@@ -69,13 +68,13 @@ static int sym__alloc_hist(struct symbol *self) | |||
69 | static int annotate__hist_hit(struct hist_entry *he, u64 ip) | 68 | static int annotate__hist_hit(struct hist_entry *he, u64 ip) |
70 | { | 69 | { |
71 | unsigned int sym_size, offset; | 70 | unsigned int sym_size, offset; |
72 | struct symbol *sym = he->sym; | 71 | struct symbol *sym = he->ms.sym; |
73 | struct sym_priv *priv; | 72 | struct sym_priv *priv; |
74 | struct sym_hist *h; | 73 | struct sym_hist *h; |
75 | 74 | ||
76 | he->count++; | 75 | he->count++; |
77 | 76 | ||
78 | if (!sym || !he->map) | 77 | if (!sym || !he->ms.map) |
79 | return 0; | 78 | return 0; |
80 | 79 | ||
81 | priv = symbol__priv(sym); | 80 | priv = symbol__priv(sym); |
@@ -85,7 +84,7 @@ static int annotate__hist_hit(struct hist_entry *he, u64 ip) | |||
85 | sym_size = sym->end - sym->start; | 84 | sym_size = sym->end - sym->start; |
86 | offset = ip - sym->start; | 85 | offset = ip - sym->start; |
87 | 86 | ||
88 | pr_debug3("%s: ip=%#Lx\n", __func__, he->map->unmap_ip(he->map, ip)); | 87 | pr_debug3("%s: ip=%#Lx\n", __func__, he->ms.map->unmap_ip(he->ms.map, ip)); |
89 | 88 | ||
90 | if (offset >= sym_size) | 89 | if (offset >= sym_size) |
91 | return 0; | 90 | return 0; |
@@ -94,8 +93,8 @@ static int annotate__hist_hit(struct hist_entry *he, u64 ip) | |||
94 | h->sum++; | 93 | h->sum++; |
95 | h->ip[offset]++; | 94 | h->ip[offset]++; |
96 | 95 | ||
97 | pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->sym->start, | 96 | pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->ms.sym->start, |
98 | he->sym->name, ip, ip - he->sym->start, h->ip[offset]); | 97 | he->ms.sym->name, ip, ip - he->ms.sym->start, h->ip[offset]); |
99 | return 0; | 98 | return 0; |
100 | } | 99 | } |
101 | 100 | ||
@@ -187,7 +186,7 @@ static struct objdump_line *objdump__get_next_ip_line(struct list_head *head, | |||
187 | static int parse_line(FILE *file, struct hist_entry *he, | 186 | static int parse_line(FILE *file, struct hist_entry *he, |
188 | struct list_head *head) | 187 | struct list_head *head) |
189 | { | 188 | { |
190 | struct symbol *sym = he->sym; | 189 | struct symbol *sym = he->ms.sym; |
191 | struct objdump_line *objdump_line; | 190 | struct objdump_line *objdump_line; |
192 | char *line = NULL, *tmp, *tmp2; | 191 | char *line = NULL, *tmp, *tmp2; |
193 | size_t line_len; | 192 | size_t line_len; |
@@ -226,7 +225,7 @@ static int parse_line(FILE *file, struct hist_entry *he, | |||
226 | } | 225 | } |
227 | 226 | ||
228 | if (line_ip != -1) { | 227 | if (line_ip != -1) { |
229 | u64 start = map__rip_2objdump(he->map, sym->start); | 228 | u64 start = map__rip_2objdump(he->ms.map, sym->start); |
230 | offset = line_ip - start; | 229 | offset = line_ip - start; |
231 | } | 230 | } |
232 | 231 | ||
@@ -244,7 +243,7 @@ static int objdump_line__print(struct objdump_line *self, | |||
244 | struct list_head *head, | 243 | struct list_head *head, |
245 | struct hist_entry *he, u64 len) | 244 | struct hist_entry *he, u64 len) |
246 | { | 245 | { |
247 | struct symbol *sym = he->sym; | 246 | struct symbol *sym = he->ms.sym; |
248 | static const char *prev_line; | 247 | static const char *prev_line; |
249 | static const char *prev_color; | 248 | static const char *prev_color; |
250 | 249 | ||
@@ -327,7 +326,7 @@ static void insert_source_line(struct sym_ext *sym_ext) | |||
327 | 326 | ||
328 | static void free_source_line(struct hist_entry *he, int len) | 327 | static void free_source_line(struct hist_entry *he, int len) |
329 | { | 328 | { |
330 | struct sym_priv *priv = symbol__priv(he->sym); | 329 | struct sym_priv *priv = symbol__priv(he->ms.sym); |
331 | struct sym_ext *sym_ext = priv->ext; | 330 | struct sym_ext *sym_ext = priv->ext; |
332 | int i; | 331 | int i; |
333 | 332 | ||
@@ -346,7 +345,7 @@ static void free_source_line(struct hist_entry *he, int len) | |||
346 | static void | 345 | static void |
347 | get_source_line(struct hist_entry *he, int len, const char *filename) | 346 | get_source_line(struct hist_entry *he, int len, const char *filename) |
348 | { | 347 | { |
349 | struct symbol *sym = he->sym; | 348 | struct symbol *sym = he->ms.sym; |
350 | u64 start; | 349 | u64 start; |
351 | int i; | 350 | int i; |
352 | char cmd[PATH_MAX * 2]; | 351 | char cmd[PATH_MAX * 2]; |
@@ -361,7 +360,7 @@ get_source_line(struct hist_entry *he, int len, const char *filename) | |||
361 | if (!priv->ext) | 360 | if (!priv->ext) |
362 | return; | 361 | return; |
363 | 362 | ||
364 | start = he->map->unmap_ip(he->map, sym->start); | 363 | start = he->ms.map->unmap_ip(he->ms.map, sym->start); |
365 | 364 | ||
366 | for (i = 0; i < len; i++) { | 365 | for (i = 0; i < len; i++) { |
367 | char *path = NULL; | 366 | char *path = NULL; |
@@ -425,7 +424,7 @@ static void print_summary(const char *filename) | |||
425 | 424 | ||
426 | static void hist_entry__print_hits(struct hist_entry *self) | 425 | static void hist_entry__print_hits(struct hist_entry *self) |
427 | { | 426 | { |
428 | struct symbol *sym = self->sym; | 427 | struct symbol *sym = self->ms.sym; |
429 | struct sym_priv *priv = symbol__priv(sym); | 428 | struct sym_priv *priv = symbol__priv(sym); |
430 | struct sym_hist *h = priv->hist; | 429 | struct sym_hist *h = priv->hist; |
431 | u64 len = sym->end - sym->start, offset; | 430 | u64 len = sym->end - sym->start, offset; |
@@ -439,9 +438,9 @@ static void hist_entry__print_hits(struct hist_entry *self) | |||
439 | 438 | ||
440 | static void annotate_sym(struct hist_entry *he) | 439 | static void annotate_sym(struct hist_entry *he) |
441 | { | 440 | { |
442 | struct map *map = he->map; | 441 | struct map *map = he->ms.map; |
443 | struct dso *dso = map->dso; | 442 | struct dso *dso = map->dso; |
444 | struct symbol *sym = he->sym; | 443 | struct symbol *sym = he->ms.sym; |
445 | const char *filename = dso->long_name, *d_filename; | 444 | const char *filename = dso->long_name, *d_filename; |
446 | u64 len; | 445 | u64 len; |
447 | char command[PATH_MAX*2]; | 446 | char command[PATH_MAX*2]; |
@@ -452,6 +451,16 @@ static void annotate_sym(struct hist_entry *he) | |||
452 | if (!filename) | 451 | if (!filename) |
453 | return; | 452 | return; |
454 | 453 | ||
454 | if (dso->origin == DSO__ORIG_KERNEL) { | ||
455 | if (dso->annotate_warned) | ||
456 | return; | ||
457 | dso->annotate_warned = 1; | ||
458 | pr_err("Can't annotate %s: No vmlinux file was found in the " | ||
459 | "path:\n", sym->name); | ||
460 | vmlinux_path__fprintf(stderr); | ||
461 | return; | ||
462 | } | ||
463 | |||
455 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, | 464 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, |
456 | filename, sym->name, map->unmap_ip(map, sym->start), | 465 | filename, sym->name, map->unmap_ip(map, sym->start), |
457 | map->unmap_ip(map, sym->end)); | 466 | map->unmap_ip(map, sym->end)); |
@@ -516,17 +525,17 @@ static void perf_session__find_annotations(struct perf_session *self) | |||
516 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | 525 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
517 | struct sym_priv *priv; | 526 | struct sym_priv *priv; |
518 | 527 | ||
519 | if (he->sym == NULL) | 528 | if (he->ms.sym == NULL) |
520 | continue; | 529 | continue; |
521 | 530 | ||
522 | priv = symbol__priv(he->sym); | 531 | priv = symbol__priv(he->ms.sym); |
523 | if (priv->hist == NULL) | 532 | if (priv->hist == NULL) |
524 | continue; | 533 | continue; |
525 | 534 | ||
526 | annotate_sym(he); | 535 | annotate_sym(he); |
527 | /* | 536 | /* |
528 | * Since we have a hist_entry per IP for the same symbol, free | 537 | * Since we have a hist_entry per IP for the same symbol, free |
529 | * he->sym->hist to signal we already processed this symbol. | 538 | * he->ms.sym->hist to signal we already processed this symbol. |
530 | */ | 539 | */ |
531 | free(priv->hist); | 540 | free(priv->hist); |
532 | priv->hist = NULL; | 541 | priv->hist = NULL; |
@@ -581,6 +590,8 @@ static const char * const annotate_usage[] = { | |||
581 | static const struct option options[] = { | 590 | static const struct option options[] = { |
582 | OPT_STRING('i', "input", &input_name, "file", | 591 | OPT_STRING('i', "input", &input_name, "file", |
583 | "input file name"), | 592 | "input file name"), |
593 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", | ||
594 | "only consider symbols in these dsos"), | ||
584 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", | 595 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", |
585 | "symbol to annotate"), | 596 | "symbol to annotate"), |
586 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), | 597 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 924a9518931..513aa8a55db 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -363,19 +363,21 @@ static void __print_result(struct rb_root *root, struct perf_session *session, | |||
363 | struct alloc_stat *data = rb_entry(next, struct alloc_stat, | 363 | struct alloc_stat *data = rb_entry(next, struct alloc_stat, |
364 | node); | 364 | node); |
365 | struct symbol *sym = NULL; | 365 | struct symbol *sym = NULL; |
366 | struct map *map; | ||
366 | char buf[BUFSIZ]; | 367 | char buf[BUFSIZ]; |
367 | u64 addr; | 368 | u64 addr; |
368 | 369 | ||
369 | if (is_caller) { | 370 | if (is_caller) { |
370 | addr = data->call_site; | 371 | addr = data->call_site; |
371 | if (!raw_ip) | 372 | if (!raw_ip) |
372 | sym = map_groups__find_function(&session->kmaps, addr, NULL); | 373 | sym = map_groups__find_function(&session->kmaps, |
374 | addr, &map, NULL); | ||
373 | } else | 375 | } else |
374 | addr = data->ptr; | 376 | addr = data->ptr; |
375 | 377 | ||
376 | if (sym != NULL) | 378 | if (sym != NULL) |
377 | snprintf(buf, sizeof(buf), "%s+%Lx", sym->name, | 379 | snprintf(buf, sizeof(buf), "%s+%Lx", sym->name, |
378 | addr - sym->start); | 380 | addr - map->unmap_ip(map, sym->start)); |
379 | else | 381 | else |
380 | snprintf(buf, sizeof(buf), "%#Lx", addr); | 382 | snprintf(buf, sizeof(buf), "%#Lx", addr); |
381 | printf(" %-34s |", buf); | 383 | printf(" %-34s |", buf); |
@@ -488,6 +490,9 @@ static int __cmd_kmem(void) | |||
488 | if (session == NULL) | 490 | if (session == NULL) |
489 | return -ENOMEM; | 491 | return -ENOMEM; |
490 | 492 | ||
493 | if (perf_session__create_kernel_maps(session) < 0) | ||
494 | goto out_delete; | ||
495 | |||
491 | if (!perf_session__has_traces(session, "kmem record")) | 496 | if (!perf_session__has_traces(session, "kmem record")) |
492 | goto out_delete; | 497 | goto out_delete; |
493 | 498 | ||
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 152d6c9b1fa..b3ba25a910f 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -36,11 +36,9 @@ | |||
36 | #include "builtin.h" | 36 | #include "builtin.h" |
37 | #include "util/util.h" | 37 | #include "util/util.h" |
38 | #include "util/strlist.h" | 38 | #include "util/strlist.h" |
39 | #include "util/event.h" | 39 | #include "util/symbol.h" |
40 | #include "util/debug.h" | 40 | #include "util/debug.h" |
41 | #include "util/debugfs.h" | 41 | #include "util/debugfs.h" |
42 | #include "util/symbol.h" | ||
43 | #include "util/thread.h" | ||
44 | #include "util/parse-options.h" | 42 | #include "util/parse-options.h" |
45 | #include "util/parse-events.h" /* For debugfs_path */ | 43 | #include "util/parse-events.h" /* For debugfs_path */ |
46 | #include "util/probe-finder.h" | 44 | #include "util/probe-finder.h" |
@@ -50,32 +48,29 @@ | |||
50 | 48 | ||
51 | /* Session management structure */ | 49 | /* Session management structure */ |
52 | static struct { | 50 | static struct { |
53 | bool need_dwarf; | ||
54 | bool list_events; | 51 | bool list_events; |
55 | bool force_add; | 52 | bool force_add; |
56 | bool show_lines; | 53 | bool show_lines; |
57 | int nr_probe; | 54 | int nevents; |
58 | struct probe_point probes[MAX_PROBES]; | 55 | struct perf_probe_event events[MAX_PROBES]; |
59 | struct strlist *dellist; | 56 | struct strlist *dellist; |
60 | struct map_groups kmap_groups; | ||
61 | struct map *kmaps[MAP__NR_TYPES]; | ||
62 | struct line_range line_range; | 57 | struct line_range line_range; |
63 | } session; | 58 | } params; |
64 | 59 | ||
65 | 60 | ||
66 | /* Parse an event definition. Note that any error must die. */ | 61 | /* Parse an event definition. Note that any error must die. */ |
67 | static void parse_probe_event(const char *str) | 62 | static void parse_probe_event(const char *str) |
68 | { | 63 | { |
69 | struct probe_point *pp = &session.probes[session.nr_probe]; | 64 | struct perf_probe_event *pev = ¶ms.events[params.nevents]; |
70 | 65 | ||
71 | pr_debug("probe-definition(%d): %s\n", session.nr_probe, str); | 66 | pr_debug("probe-definition(%d): %s\n", params.nevents, str); |
72 | if (++session.nr_probe == MAX_PROBES) | 67 | if (++params.nevents == MAX_PROBES) |
73 | die("Too many probes (> %d) are specified.", MAX_PROBES); | 68 | die("Too many probes (> %d) are specified.", MAX_PROBES); |
74 | 69 | ||
75 | /* Parse perf-probe event into probe_point */ | 70 | /* Parse a perf-probe command into event */ |
76 | parse_perf_probe_event(str, pp, &session.need_dwarf); | 71 | parse_perf_probe_command(str, pev); |
77 | 72 | ||
78 | pr_debug("%d arguments\n", pp->nr_args); | 73 | pr_debug("%d arguments\n", pev->nargs); |
79 | } | 74 | } |
80 | 75 | ||
81 | static void parse_probe_event_argv(int argc, const char **argv) | 76 | static void parse_probe_event_argv(int argc, const char **argv) |
@@ -87,9 +82,7 @@ static void parse_probe_event_argv(int argc, const char **argv) | |||
87 | len = 0; | 82 | len = 0; |
88 | for (i = 0; i < argc; i++) | 83 | for (i = 0; i < argc; i++) |
89 | len += strlen(argv[i]) + 1; | 84 | len += strlen(argv[i]) + 1; |
90 | buf = zalloc(len + 1); | 85 | buf = xzalloc(len + 1); |
91 | if (!buf) | ||
92 | die("Failed to allocate memory for binding arguments."); | ||
93 | len = 0; | 86 | len = 0; |
94 | for (i = 0; i < argc; i++) | 87 | for (i = 0; i < argc; i++) |
95 | len += sprintf(&buf[len], "%s ", argv[i]); | 88 | len += sprintf(&buf[len], "%s ", argv[i]); |
@@ -109,43 +102,21 @@ static int opt_del_probe_event(const struct option *opt __used, | |||
109 | const char *str, int unset __used) | 102 | const char *str, int unset __used) |
110 | { | 103 | { |
111 | if (str) { | 104 | if (str) { |
112 | if (!session.dellist) | 105 | if (!params.dellist) |
113 | session.dellist = strlist__new(true, NULL); | 106 | params.dellist = strlist__new(true, NULL); |
114 | strlist__add(session.dellist, str); | 107 | strlist__add(params.dellist, str); |
115 | } | 108 | } |
116 | return 0; | 109 | return 0; |
117 | } | 110 | } |
118 | 111 | ||
119 | /* Currently just checking function name from symbol map */ | 112 | #ifdef DWARF_SUPPORT |
120 | static void evaluate_probe_point(struct probe_point *pp) | ||
121 | { | ||
122 | struct symbol *sym; | ||
123 | sym = map__find_symbol_by_name(session.kmaps[MAP__FUNCTION], | ||
124 | pp->function, NULL); | ||
125 | if (!sym) | ||
126 | die("Kernel symbol \'%s\' not found - probe not added.", | ||
127 | pp->function); | ||
128 | } | ||
129 | |||
130 | #ifndef NO_DWARF_SUPPORT | ||
131 | static int open_vmlinux(void) | ||
132 | { | ||
133 | if (map__load(session.kmaps[MAP__FUNCTION], NULL) < 0) { | ||
134 | pr_debug("Failed to load kernel map.\n"); | ||
135 | return -EINVAL; | ||
136 | } | ||
137 | pr_debug("Try to open %s\n", | ||
138 | session.kmaps[MAP__FUNCTION]->dso->long_name); | ||
139 | return open(session.kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY); | ||
140 | } | ||
141 | |||
142 | static int opt_show_lines(const struct option *opt __used, | 113 | static int opt_show_lines(const struct option *opt __used, |
143 | const char *str, int unset __used) | 114 | const char *str, int unset __used) |
144 | { | 115 | { |
145 | if (str) | 116 | if (str) |
146 | parse_line_range_desc(str, &session.line_range); | 117 | parse_line_range_desc(str, ¶ms.line_range); |
147 | INIT_LIST_HEAD(&session.line_range.line_list); | 118 | INIT_LIST_HEAD(¶ms.line_range.line_list); |
148 | session.show_lines = true; | 119 | params.show_lines = true; |
149 | return 0; | 120 | return 0; |
150 | } | 121 | } |
151 | #endif | 122 | #endif |
@@ -155,7 +126,7 @@ static const char * const probe_usage[] = { | |||
155 | "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]", | 126 | "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]", |
156 | "perf probe [<options>] --del '[GROUP:]EVENT' ...", | 127 | "perf probe [<options>] --del '[GROUP:]EVENT' ...", |
157 | "perf probe --list", | 128 | "perf probe --list", |
158 | #ifndef NO_DWARF_SUPPORT | 129 | #ifdef DWARF_SUPPORT |
159 | "perf probe --line 'LINEDESC'", | 130 | "perf probe --line 'LINEDESC'", |
160 | #endif | 131 | #endif |
161 | NULL | 132 | NULL |
@@ -164,20 +135,16 @@ static const char * const probe_usage[] = { | |||
164 | static const struct option options[] = { | 135 | static const struct option options[] = { |
165 | OPT_BOOLEAN('v', "verbose", &verbose, | 136 | OPT_BOOLEAN('v', "verbose", &verbose, |
166 | "be more verbose (show parsed arguments, etc)"), | 137 | "be more verbose (show parsed arguments, etc)"), |
167 | #ifndef NO_DWARF_SUPPORT | 138 | OPT_BOOLEAN('l', "list", ¶ms.list_events, |
168 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, | ||
169 | "file", "vmlinux pathname"), | ||
170 | #endif | ||
171 | OPT_BOOLEAN('l', "list", &session.list_events, | ||
172 | "list up current probe events"), | 139 | "list up current probe events"), |
173 | OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.", | 140 | OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.", |
174 | opt_del_probe_event), | 141 | opt_del_probe_event), |
175 | OPT_CALLBACK('a', "add", NULL, | 142 | OPT_CALLBACK('a', "add", NULL, |
176 | #ifdef NO_DWARF_SUPPORT | 143 | #ifdef DWARF_SUPPORT |
177 | "[EVENT=]FUNC[+OFF|%return] [ARG ...]", | ||
178 | #else | ||
179 | "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT" | 144 | "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT" |
180 | " [ARG ...]", | 145 | " [ARG ...]", |
146 | #else | ||
147 | "[EVENT=]FUNC[+OFF|%return] [ARG ...]", | ||
181 | #endif | 148 | #endif |
182 | "probe point definition, where\n" | 149 | "probe point definition, where\n" |
183 | "\t\tGROUP:\tGroup name (optional)\n" | 150 | "\t\tGROUP:\tGroup name (optional)\n" |
@@ -185,52 +152,32 @@ static const struct option options[] = { | |||
185 | "\t\tFUNC:\tFunction name\n" | 152 | "\t\tFUNC:\tFunction name\n" |
186 | "\t\tOFF:\tOffset from function entry (in byte)\n" | 153 | "\t\tOFF:\tOffset from function entry (in byte)\n" |
187 | "\t\t%return:\tPut the probe at function return\n" | 154 | "\t\t%return:\tPut the probe at function return\n" |
188 | #ifdef NO_DWARF_SUPPORT | 155 | #ifdef DWARF_SUPPORT |
189 | "\t\tARG:\tProbe argument (only \n" | ||
190 | #else | ||
191 | "\t\tSRC:\tSource code path\n" | 156 | "\t\tSRC:\tSource code path\n" |
192 | "\t\tRL:\tRelative line number from function entry.\n" | 157 | "\t\tRL:\tRelative line number from function entry.\n" |
193 | "\t\tAL:\tAbsolute line number in file.\n" | 158 | "\t\tAL:\tAbsolute line number in file.\n" |
194 | "\t\tPT:\tLazy expression of line code.\n" | 159 | "\t\tPT:\tLazy expression of line code.\n" |
195 | "\t\tARG:\tProbe argument (local variable name or\n" | 160 | "\t\tARG:\tProbe argument (local variable name or\n" |
196 | #endif | ||
197 | "\t\t\tkprobe-tracer argument format.)\n", | 161 | "\t\t\tkprobe-tracer argument format.)\n", |
162 | #else | ||
163 | "\t\tARG:\tProbe argument (kprobe-tracer argument format.)\n", | ||
164 | #endif | ||
198 | opt_add_probe_event), | 165 | opt_add_probe_event), |
199 | OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events" | 166 | OPT_BOOLEAN('f', "force", ¶ms.force_add, "forcibly add events" |
200 | " with existing name"), | 167 | " with existing name"), |
201 | #ifndef NO_DWARF_SUPPORT | 168 | #ifdef DWARF_SUPPORT |
202 | OPT_CALLBACK('L', "line", NULL, | 169 | OPT_CALLBACK('L', "line", NULL, |
203 | "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]", | 170 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]", |
204 | "Show source code lines.", opt_show_lines), | 171 | "Show source code lines.", opt_show_lines), |
172 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, | ||
173 | "file", "vmlinux pathname"), | ||
205 | #endif | 174 | #endif |
175 | OPT__DRY_RUN(&probe_event_dry_run), | ||
206 | OPT_END() | 176 | OPT_END() |
207 | }; | 177 | }; |
208 | 178 | ||
209 | /* Initialize symbol maps for vmlinux */ | ||
210 | static void init_vmlinux(void) | ||
211 | { | ||
212 | symbol_conf.sort_by_name = true; | ||
213 | if (symbol_conf.vmlinux_name == NULL) | ||
214 | symbol_conf.try_vmlinux_path = true; | ||
215 | else | ||
216 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); | ||
217 | if (symbol__init() < 0) | ||
218 | die("Failed to init symbol map."); | ||
219 | |||
220 | map_groups__init(&session.kmap_groups); | ||
221 | if (map_groups__create_kernel_maps(&session.kmap_groups, | ||
222 | session.kmaps) < 0) | ||
223 | die("Failed to create kernel maps."); | ||
224 | } | ||
225 | |||
226 | int cmd_probe(int argc, const char **argv, const char *prefix __used) | 179 | int cmd_probe(int argc, const char **argv, const char *prefix __used) |
227 | { | 180 | { |
228 | int i, ret; | ||
229 | #ifndef NO_DWARF_SUPPORT | ||
230 | int fd; | ||
231 | #endif | ||
232 | struct probe_point *pp; | ||
233 | |||
234 | argc = parse_options(argc, argv, options, probe_usage, | 181 | argc = parse_options(argc, argv, options, probe_usage, |
235 | PARSE_OPT_STOP_AT_NON_OPTION); | 182 | PARSE_OPT_STOP_AT_NON_OPTION); |
236 | if (argc > 0) { | 183 | if (argc > 0) { |
@@ -241,20 +188,20 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
241 | parse_probe_event_argv(argc, argv); | 188 | parse_probe_event_argv(argc, argv); |
242 | } | 189 | } |
243 | 190 | ||
244 | if ((!session.nr_probe && !session.dellist && !session.list_events && | 191 | if ((!params.nevents && !params.dellist && !params.list_events && |
245 | !session.show_lines)) | 192 | !params.show_lines)) |
246 | usage_with_options(probe_usage, options); | 193 | usage_with_options(probe_usage, options); |
247 | 194 | ||
248 | if (debugfs_valid_mountpoint(debugfs_path) < 0) | 195 | if (debugfs_valid_mountpoint(debugfs_path) < 0) |
249 | die("Failed to find debugfs path."); | 196 | die("Failed to find debugfs path."); |
250 | 197 | ||
251 | if (session.list_events) { | 198 | if (params.list_events) { |
252 | if (session.nr_probe != 0 || session.dellist) { | 199 | if (params.nevents != 0 || params.dellist) { |
253 | pr_warning(" Error: Don't use --list with" | 200 | pr_warning(" Error: Don't use --list with" |
254 | " --add/--del.\n"); | 201 | " --add/--del.\n"); |
255 | usage_with_options(probe_usage, options); | 202 | usage_with_options(probe_usage, options); |
256 | } | 203 | } |
257 | if (session.show_lines) { | 204 | if (params.show_lines) { |
258 | pr_warning(" Error: Don't use --list with --line.\n"); | 205 | pr_warning(" Error: Don't use --list with --line.\n"); |
259 | usage_with_options(probe_usage, options); | 206 | usage_with_options(probe_usage, options); |
260 | } | 207 | } |
@@ -262,99 +209,27 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
262 | return 0; | 209 | return 0; |
263 | } | 210 | } |
264 | 211 | ||
265 | #ifndef NO_DWARF_SUPPORT | 212 | #ifdef DWARF_SUPPORT |
266 | if (session.show_lines) { | 213 | if (params.show_lines) { |
267 | if (session.nr_probe != 0 || session.dellist) { | 214 | if (params.nevents != 0 || params.dellist) { |
268 | pr_warning(" Error: Don't use --line with" | 215 | pr_warning(" Error: Don't use --line with" |
269 | " --add/--del.\n"); | 216 | " --add/--del.\n"); |
270 | usage_with_options(probe_usage, options); | 217 | usage_with_options(probe_usage, options); |
271 | } | 218 | } |
272 | init_vmlinux(); | 219 | |
273 | fd = open_vmlinux(); | 220 | show_line_range(¶ms.line_range); |
274 | if (fd < 0) | ||
275 | die("Could not open debuginfo file."); | ||
276 | ret = find_line_range(fd, &session.line_range); | ||
277 | if (ret <= 0) | ||
278 | die("Source line is not found.\n"); | ||
279 | close(fd); | ||
280 | show_line_range(&session.line_range); | ||
281 | return 0; | 221 | return 0; |
282 | } | 222 | } |
283 | #endif | 223 | #endif |
284 | 224 | ||
285 | if (session.dellist) { | 225 | if (params.dellist) { |
286 | del_trace_kprobe_events(session.dellist); | 226 | del_perf_probe_events(params.dellist); |
287 | strlist__delete(session.dellist); | 227 | strlist__delete(params.dellist); |
288 | if (session.nr_probe == 0) | 228 | if (params.nevents == 0) |
289 | return 0; | 229 | return 0; |
290 | } | 230 | } |
291 | 231 | ||
292 | /* Add probes */ | 232 | add_perf_probe_events(params.events, params.nevents, params.force_add); |
293 | init_vmlinux(); | ||
294 | |||
295 | if (session.need_dwarf) | ||
296 | #ifdef NO_DWARF_SUPPORT | ||
297 | die("Debuginfo-analysis is not supported"); | ||
298 | #else /* !NO_DWARF_SUPPORT */ | ||
299 | pr_debug("Some probes require debuginfo.\n"); | ||
300 | |||
301 | fd = open_vmlinux(); | ||
302 | if (fd < 0) { | ||
303 | if (session.need_dwarf) | ||
304 | die("Could not open debuginfo file."); | ||
305 | |||
306 | pr_debug("Could not open vmlinux/module file." | ||
307 | " Try to use symbols.\n"); | ||
308 | goto end_dwarf; | ||
309 | } | ||
310 | |||
311 | /* Searching probe points */ | ||
312 | for (i = 0; i < session.nr_probe; i++) { | ||
313 | pp = &session.probes[i]; | ||
314 | if (pp->found) | ||
315 | continue; | ||
316 | |||
317 | lseek(fd, SEEK_SET, 0); | ||
318 | ret = find_probe_point(fd, pp); | ||
319 | if (ret > 0) | ||
320 | continue; | ||
321 | if (ret == 0) { /* No error but failed to find probe point. */ | ||
322 | synthesize_perf_probe_point(pp); | ||
323 | die("Probe point '%s' not found. - probe not added.", | ||
324 | pp->probes[0]); | ||
325 | } | ||
326 | /* Error path */ | ||
327 | if (session.need_dwarf) { | ||
328 | if (ret == -ENOENT) | ||
329 | pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
330 | die("Could not analyze debuginfo."); | ||
331 | } | ||
332 | pr_debug("An error occurred in debuginfo analysis." | ||
333 | " Try to use symbols.\n"); | ||
334 | break; | ||
335 | } | ||
336 | close(fd); | ||
337 | |||
338 | end_dwarf: | ||
339 | #endif /* !NO_DWARF_SUPPORT */ | ||
340 | |||
341 | /* Synthesize probes without dwarf */ | ||
342 | for (i = 0; i < session.nr_probe; i++) { | ||
343 | pp = &session.probes[i]; | ||
344 | if (pp->found) /* This probe is already found. */ | ||
345 | continue; | ||
346 | |||
347 | evaluate_probe_point(pp); | ||
348 | ret = synthesize_trace_kprobe_event(pp); | ||
349 | if (ret == -E2BIG) | ||
350 | die("probe point definition becomes too long."); | ||
351 | else if (ret < 0) | ||
352 | die("Failed to synthesize a probe point."); | ||
353 | } | ||
354 | |||
355 | /* Settng up probe points */ | ||
356 | add_trace_kprobe_events(session.probes, session.nr_probe, | ||
357 | session.force_add); | ||
358 | return 0; | 233 | return 0; |
359 | } | 234 | } |
360 | 235 | ||
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 3b8b6387c47..dc61f1b68b4 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include "util/util.h" | 15 | #include "util/util.h" |
16 | #include "util/parse-options.h" | 16 | #include "util/parse-options.h" |
17 | #include "util/parse-events.h" | 17 | #include "util/parse-events.h" |
18 | #include "util/string.h" | ||
19 | 18 | ||
20 | #include "util/header.h" | 19 | #include "util/header.h" |
21 | #include "util/event.h" | 20 | #include "util/event.h" |
@@ -27,7 +26,7 @@ | |||
27 | #include <unistd.h> | 26 | #include <unistd.h> |
28 | #include <sched.h> | 27 | #include <sched.h> |
29 | 28 | ||
30 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; | 29 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
31 | 30 | ||
32 | static long default_interval = 0; | 31 | static long default_interval = 0; |
33 | 32 | ||
@@ -43,6 +42,9 @@ static int raw_samples = 0; | |||
43 | static int system_wide = 0; | 42 | static int system_wide = 0; |
44 | static int profile_cpu = -1; | 43 | static int profile_cpu = -1; |
45 | static pid_t target_pid = -1; | 44 | static pid_t target_pid = -1; |
45 | static pid_t target_tid = -1; | ||
46 | static pid_t *all_tids = NULL; | ||
47 | static int thread_num = 0; | ||
46 | static pid_t child_pid = -1; | 48 | static pid_t child_pid = -1; |
47 | static int inherit = 1; | 49 | static int inherit = 1; |
48 | static int force = 0; | 50 | static int force = 0; |
@@ -60,7 +62,7 @@ static struct timeval this_read; | |||
60 | 62 | ||
61 | static u64 bytes_written = 0; | 63 | static u64 bytes_written = 0; |
62 | 64 | ||
63 | static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS]; | 65 | static struct pollfd *event_array; |
64 | 66 | ||
65 | static int nr_poll = 0; | 67 | static int nr_poll = 0; |
66 | static int nr_cpu = 0; | 68 | static int nr_cpu = 0; |
@@ -77,7 +79,7 @@ struct mmap_data { | |||
77 | unsigned int prev; | 79 | unsigned int prev; |
78 | }; | 80 | }; |
79 | 81 | ||
80 | static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | 82 | static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; |
81 | 83 | ||
82 | static unsigned long mmap_read_head(struct mmap_data *md) | 84 | static unsigned long mmap_read_head(struct mmap_data *md) |
83 | { | 85 | { |
@@ -225,12 +227,13 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n | |||
225 | return h_attr; | 227 | return h_attr; |
226 | } | 228 | } |
227 | 229 | ||
228 | static void create_counter(int counter, int cpu, pid_t pid) | 230 | static void create_counter(int counter, int cpu) |
229 | { | 231 | { |
230 | char *filter = filters[counter]; | 232 | char *filter = filters[counter]; |
231 | struct perf_event_attr *attr = attrs + counter; | 233 | struct perf_event_attr *attr = attrs + counter; |
232 | struct perf_header_attr *h_attr; | 234 | struct perf_header_attr *h_attr; |
233 | int track = !counter; /* only the first counter needs these */ | 235 | int track = !counter; /* only the first counter needs these */ |
236 | int thread_index; | ||
234 | int ret; | 237 | int ret; |
235 | struct { | 238 | struct { |
236 | u64 count; | 239 | u64 count; |
@@ -275,118 +278,129 @@ static void create_counter(int counter, int cpu, pid_t pid) | |||
275 | attr->mmap = track; | 278 | attr->mmap = track; |
276 | attr->comm = track; | 279 | attr->comm = track; |
277 | attr->inherit = inherit; | 280 | attr->inherit = inherit; |
278 | attr->disabled = 1; | 281 | if (target_pid == -1 && !system_wide) { |
282 | attr->disabled = 1; | ||
283 | attr->enable_on_exec = 1; | ||
284 | } | ||
279 | 285 | ||
286 | for (thread_index = 0; thread_index < thread_num; thread_index++) { | ||
280 | try_again: | 287 | try_again: |
281 | fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0); | 288 | fd[nr_cpu][counter][thread_index] = sys_perf_event_open(attr, |
282 | 289 | all_tids[thread_index], cpu, group_fd, 0); | |
283 | if (fd[nr_cpu][counter] < 0) { | 290 | |
284 | int err = errno; | 291 | if (fd[nr_cpu][counter][thread_index] < 0) { |
285 | 292 | int err = errno; | |
286 | if (err == EPERM || err == EACCES) | 293 | |
287 | die("Permission error - are you root?\n"); | 294 | if (err == EPERM || err == EACCES) |
288 | else if (err == ENODEV && profile_cpu != -1) | 295 | die("Permission error - are you root?\n" |
289 | die("No such device - did you specify an out-of-range profile CPU?\n"); | 296 | "\t Consider tweaking" |
297 | " /proc/sys/kernel/perf_event_paranoid.\n"); | ||
298 | else if (err == ENODEV && profile_cpu != -1) { | ||
299 | die("No such device - did you specify" | ||
300 | " an out-of-range profile CPU?\n"); | ||
301 | } | ||
290 | 302 | ||
291 | /* | 303 | /* |
292 | * If it's cycles then fall back to hrtimer | 304 | * If it's cycles then fall back to hrtimer |
293 | * based cpu-clock-tick sw counter, which | 305 | * based cpu-clock-tick sw counter, which |
294 | * is always available even if no PMU support: | 306 | * is always available even if no PMU support: |
295 | */ | 307 | */ |
296 | if (attr->type == PERF_TYPE_HARDWARE | 308 | if (attr->type == PERF_TYPE_HARDWARE |
297 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { | 309 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { |
298 | 310 | ||
299 | if (verbose) | 311 | if (verbose) |
300 | warning(" ... trying to fall back to cpu-clock-ticks\n"); | 312 | warning(" ... trying to fall back to cpu-clock-ticks\n"); |
301 | attr->type = PERF_TYPE_SOFTWARE; | 313 | attr->type = PERF_TYPE_SOFTWARE; |
302 | attr->config = PERF_COUNT_SW_CPU_CLOCK; | 314 | attr->config = PERF_COUNT_SW_CPU_CLOCK; |
303 | goto try_again; | 315 | goto try_again; |
304 | } | 316 | } |
305 | printf("\n"); | 317 | printf("\n"); |
306 | error("perfcounter syscall returned with %d (%s)\n", | 318 | error("perfcounter syscall returned with %d (%s)\n", |
307 | fd[nr_cpu][counter], strerror(err)); | 319 | fd[nr_cpu][counter][thread_index], strerror(err)); |
308 | 320 | ||
309 | #if defined(__i386__) || defined(__x86_64__) | 321 | #if defined(__i386__) || defined(__x86_64__) |
310 | if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP) | 322 | if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP) |
311 | die("No hardware sampling interrupt available. No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.\n"); | 323 | die("No hardware sampling interrupt available." |
324 | " No APIC? If so then you can boot the kernel" | ||
325 | " with the \"lapic\" boot parameter to" | ||
326 | " force-enable it.\n"); | ||
312 | #endif | 327 | #endif |
313 | 328 | ||
314 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | 329 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); |
315 | exit(-1); | 330 | exit(-1); |
316 | } | 331 | } |
317 | 332 | ||
318 | h_attr = get_header_attr(attr, counter); | 333 | h_attr = get_header_attr(attr, counter); |
319 | if (h_attr == NULL) | 334 | if (h_attr == NULL) |
320 | die("nomem\n"); | 335 | die("nomem\n"); |
321 | 336 | ||
322 | if (!file_new) { | 337 | if (!file_new) { |
323 | if (memcmp(&h_attr->attr, attr, sizeof(*attr))) { | 338 | if (memcmp(&h_attr->attr, attr, sizeof(*attr))) { |
324 | fprintf(stderr, "incompatible append\n"); | 339 | fprintf(stderr, "incompatible append\n"); |
325 | exit(-1); | 340 | exit(-1); |
341 | } | ||
326 | } | 342 | } |
327 | } | ||
328 | 343 | ||
329 | if (read(fd[nr_cpu][counter], &read_data, sizeof(read_data)) == -1) { | 344 | if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) { |
330 | perror("Unable to read perf file descriptor\n"); | 345 | perror("Unable to read perf file descriptor\n"); |
331 | exit(-1); | 346 | exit(-1); |
332 | } | 347 | } |
333 | 348 | ||
334 | if (perf_header_attr__add_id(h_attr, read_data.id) < 0) { | 349 | if (perf_header_attr__add_id(h_attr, read_data.id) < 0) { |
335 | pr_warning("Not enough memory to add id\n"); | 350 | pr_warning("Not enough memory to add id\n"); |
336 | exit(-1); | 351 | exit(-1); |
337 | } | 352 | } |
338 | 353 | ||
339 | assert(fd[nr_cpu][counter] >= 0); | 354 | assert(fd[nr_cpu][counter][thread_index] >= 0); |
340 | fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK); | 355 | fcntl(fd[nr_cpu][counter][thread_index], F_SETFL, O_NONBLOCK); |
341 | 356 | ||
342 | /* | 357 | /* |
343 | * First counter acts as the group leader: | 358 | * First counter acts as the group leader: |
344 | */ | 359 | */ |
345 | if (group && group_fd == -1) | 360 | if (group && group_fd == -1) |
346 | group_fd = fd[nr_cpu][counter]; | 361 | group_fd = fd[nr_cpu][counter][thread_index]; |
347 | if (multiplex && multiplex_fd == -1) | 362 | if (multiplex && multiplex_fd == -1) |
348 | multiplex_fd = fd[nr_cpu][counter]; | 363 | multiplex_fd = fd[nr_cpu][counter][thread_index]; |
349 | 364 | ||
350 | if (multiplex && fd[nr_cpu][counter] != multiplex_fd) { | 365 | if (multiplex && fd[nr_cpu][counter][thread_index] != multiplex_fd) { |
351 | 366 | ||
352 | ret = ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd); | 367 | ret = ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd); |
353 | assert(ret != -1); | 368 | assert(ret != -1); |
354 | } else { | 369 | } else { |
355 | event_array[nr_poll].fd = fd[nr_cpu][counter]; | 370 | event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; |
356 | event_array[nr_poll].events = POLLIN; | 371 | event_array[nr_poll].events = POLLIN; |
357 | nr_poll++; | 372 | nr_poll++; |
358 | 373 | ||
359 | mmap_array[nr_cpu][counter].counter = counter; | 374 | mmap_array[nr_cpu][counter][thread_index].counter = counter; |
360 | mmap_array[nr_cpu][counter].prev = 0; | 375 | mmap_array[nr_cpu][counter][thread_index].prev = 0; |
361 | mmap_array[nr_cpu][counter].mask = mmap_pages*page_size - 1; | 376 | mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1; |
362 | mmap_array[nr_cpu][counter].base = mmap(NULL, (mmap_pages+1)*page_size, | 377 | mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, |
363 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter], 0); | 378 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); |
364 | if (mmap_array[nr_cpu][counter].base == MAP_FAILED) { | 379 | if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) { |
365 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); | 380 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
366 | exit(-1); | 381 | exit(-1); |
382 | } | ||
367 | } | 383 | } |
368 | } | ||
369 | 384 | ||
370 | if (filter != NULL) { | 385 | if (filter != NULL) { |
371 | ret = ioctl(fd[nr_cpu][counter], | 386 | ret = ioctl(fd[nr_cpu][counter][thread_index], |
372 | PERF_EVENT_IOC_SET_FILTER, filter); | 387 | PERF_EVENT_IOC_SET_FILTER, filter); |
373 | if (ret) { | 388 | if (ret) { |
374 | error("failed to set filter with %d (%s)\n", errno, | 389 | error("failed to set filter with %d (%s)\n", errno, |
375 | strerror(errno)); | 390 | strerror(errno)); |
376 | exit(-1); | 391 | exit(-1); |
392 | } | ||
377 | } | 393 | } |
378 | } | 394 | } |
379 | |||
380 | ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE); | ||
381 | } | 395 | } |
382 | 396 | ||
383 | static void open_counters(int cpu, pid_t pid) | 397 | static void open_counters(int cpu) |
384 | { | 398 | { |
385 | int counter; | 399 | int counter; |
386 | 400 | ||
387 | group_fd = -1; | 401 | group_fd = -1; |
388 | for (counter = 0; counter < nr_counters; counter++) | 402 | for (counter = 0; counter < nr_counters; counter++) |
389 | create_counter(counter, cpu, pid); | 403 | create_counter(counter, cpu); |
390 | 404 | ||
391 | nr_cpu++; | 405 | nr_cpu++; |
392 | } | 406 | } |
@@ -421,7 +435,7 @@ static int __cmd_record(int argc, const char **argv) | |||
421 | int err; | 435 | int err; |
422 | unsigned long waking = 0; | 436 | unsigned long waking = 0; |
423 | int child_ready_pipe[2], go_pipe[2]; | 437 | int child_ready_pipe[2], go_pipe[2]; |
424 | const bool forks = target_pid == -1 && argc > 0; | 438 | const bool forks = argc > 0; |
425 | char buf; | 439 | char buf; |
426 | 440 | ||
427 | page_size = sysconf(_SC_PAGE_SIZE); | 441 | page_size = sysconf(_SC_PAGE_SIZE); |
@@ -492,13 +506,13 @@ static int __cmd_record(int argc, const char **argv) | |||
492 | atexit(atexit_header); | 506 | atexit(atexit_header); |
493 | 507 | ||
494 | if (forks) { | 508 | if (forks) { |
495 | pid = fork(); | 509 | child_pid = fork(); |
496 | if (pid < 0) { | 510 | if (pid < 0) { |
497 | perror("failed to fork"); | 511 | perror("failed to fork"); |
498 | exit(-1); | 512 | exit(-1); |
499 | } | 513 | } |
500 | 514 | ||
501 | if (!pid) { | 515 | if (!child_pid) { |
502 | close(child_ready_pipe[0]); | 516 | close(child_ready_pipe[0]); |
503 | close(go_pipe[1]); | 517 | close(go_pipe[1]); |
504 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); | 518 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); |
@@ -527,10 +541,8 @@ static int __cmd_record(int argc, const char **argv) | |||
527 | exit(-1); | 541 | exit(-1); |
528 | } | 542 | } |
529 | 543 | ||
530 | child_pid = pid; | 544 | if (!system_wide && target_tid == -1 && target_pid == -1) |
531 | 545 | all_tids[0] = child_pid; | |
532 | if (!system_wide) | ||
533 | target_pid = pid; | ||
534 | 546 | ||
535 | close(child_ready_pipe[1]); | 547 | close(child_ready_pipe[1]); |
536 | close(go_pipe[0]); | 548 | close(go_pipe[0]); |
@@ -544,13 +556,12 @@ static int __cmd_record(int argc, const char **argv) | |||
544 | close(child_ready_pipe[0]); | 556 | close(child_ready_pipe[0]); |
545 | } | 557 | } |
546 | 558 | ||
547 | |||
548 | if ((!system_wide && !inherit) || profile_cpu != -1) { | 559 | if ((!system_wide && !inherit) || profile_cpu != -1) { |
549 | open_counters(profile_cpu, target_pid); | 560 | open_counters(profile_cpu); |
550 | } else { | 561 | } else { |
551 | nr_cpus = read_cpu_map(); | 562 | nr_cpus = read_cpu_map(); |
552 | for (i = 0; i < nr_cpus; i++) | 563 | for (i = 0; i < nr_cpus; i++) |
553 | open_counters(cpumap[i], target_pid); | 564 | open_counters(cpumap[i]); |
554 | } | 565 | } |
555 | 566 | ||
556 | if (file_new) { | 567 | if (file_new) { |
@@ -563,6 +574,9 @@ static int __cmd_record(int argc, const char **argv) | |||
563 | 574 | ||
564 | err = event__synthesize_kernel_mmap(process_synthesized_event, | 575 | err = event__synthesize_kernel_mmap(process_synthesized_event, |
565 | session, "_text"); | 576 | session, "_text"); |
577 | if (err < 0) | ||
578 | err = event__synthesize_kernel_mmap(process_synthesized_event, | ||
579 | session, "_stext"); | ||
566 | if (err < 0) { | 580 | if (err < 0) { |
567 | pr_err("Couldn't record kernel reference relocation symbol.\n"); | 581 | pr_err("Couldn't record kernel reference relocation symbol.\n"); |
568 | return err; | 582 | return err; |
@@ -575,7 +589,7 @@ static int __cmd_record(int argc, const char **argv) | |||
575 | } | 589 | } |
576 | 590 | ||
577 | if (!system_wide && profile_cpu == -1) | 591 | if (!system_wide && profile_cpu == -1) |
578 | event__synthesize_thread(target_pid, process_synthesized_event, | 592 | event__synthesize_thread(target_tid, process_synthesized_event, |
579 | session); | 593 | session); |
580 | else | 594 | else |
581 | event__synthesize_threads(process_synthesized_event, session); | 595 | event__synthesize_threads(process_synthesized_event, session); |
@@ -598,11 +612,16 @@ static int __cmd_record(int argc, const char **argv) | |||
598 | 612 | ||
599 | for (;;) { | 613 | for (;;) { |
600 | int hits = samples; | 614 | int hits = samples; |
615 | int thread; | ||
601 | 616 | ||
602 | for (i = 0; i < nr_cpu; i++) { | 617 | for (i = 0; i < nr_cpu; i++) { |
603 | for (counter = 0; counter < nr_counters; counter++) { | 618 | for (counter = 0; counter < nr_counters; counter++) { |
604 | if (mmap_array[i][counter].base) | 619 | for (thread = 0; |
605 | mmap_read(&mmap_array[i][counter]); | 620 | thread < thread_num; thread++) { |
621 | if (mmap_array[i][counter][thread].base) | ||
622 | mmap_read(&mmap_array[i][counter][thread]); | ||
623 | } | ||
624 | |||
606 | } | 625 | } |
607 | } | 626 | } |
608 | 627 | ||
@@ -615,8 +634,15 @@ static int __cmd_record(int argc, const char **argv) | |||
615 | 634 | ||
616 | if (done) { | 635 | if (done) { |
617 | for (i = 0; i < nr_cpu; i++) { | 636 | for (i = 0; i < nr_cpu; i++) { |
618 | for (counter = 0; counter < nr_counters; counter++) | 637 | for (counter = 0; |
619 | ioctl(fd[i][counter], PERF_EVENT_IOC_DISABLE); | 638 | counter < nr_counters; |
639 | counter++) { | ||
640 | for (thread = 0; | ||
641 | thread < thread_num; | ||
642 | thread++) | ||
643 | ioctl(fd[i][counter][thread], | ||
644 | PERF_EVENT_IOC_DISABLE); | ||
645 | } | ||
620 | } | 646 | } |
621 | } | 647 | } |
622 | } | 648 | } |
@@ -648,7 +674,9 @@ static const struct option options[] = { | |||
648 | OPT_CALLBACK(0, "filter", NULL, "filter", | 674 | OPT_CALLBACK(0, "filter", NULL, "filter", |
649 | "event filter", parse_filter), | 675 | "event filter", parse_filter), |
650 | OPT_INTEGER('p', "pid", &target_pid, | 676 | OPT_INTEGER('p', "pid", &target_pid, |
651 | "record events on existing pid"), | 677 | "record events on existing process id"), |
678 | OPT_INTEGER('t', "tid", &target_tid, | ||
679 | "record events on existing thread id"), | ||
652 | OPT_INTEGER('r', "realtime", &realtime_prio, | 680 | OPT_INTEGER('r', "realtime", &realtime_prio, |
653 | "collect data with this RT SCHED_FIFO priority"), | 681 | "collect data with this RT SCHED_FIFO priority"), |
654 | OPT_BOOLEAN('R', "raw-samples", &raw_samples, | 682 | OPT_BOOLEAN('R', "raw-samples", &raw_samples, |
@@ -689,10 +717,12 @@ static const struct option options[] = { | |||
689 | int cmd_record(int argc, const char **argv, const char *prefix __used) | 717 | int cmd_record(int argc, const char **argv, const char *prefix __used) |
690 | { | 718 | { |
691 | int counter; | 719 | int counter; |
720 | int i,j; | ||
692 | 721 | ||
693 | argc = parse_options(argc, argv, options, record_usage, | 722 | argc = parse_options(argc, argv, options, record_usage, |
694 | PARSE_OPT_STOP_AT_NON_OPTION); | 723 | PARSE_OPT_STOP_AT_NON_OPTION); |
695 | if (!argc && target_pid == -1 && !system_wide && profile_cpu == -1) | 724 | if (!argc && target_pid == -1 && target_tid == -1 && |
725 | !system_wide && profile_cpu == -1) | ||
696 | usage_with_options(record_usage, options); | 726 | usage_with_options(record_usage, options); |
697 | 727 | ||
698 | symbol__init(); | 728 | symbol__init(); |
@@ -703,6 +733,37 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
703 | attrs[0].config = PERF_COUNT_HW_CPU_CYCLES; | 733 | attrs[0].config = PERF_COUNT_HW_CPU_CYCLES; |
704 | } | 734 | } |
705 | 735 | ||
736 | if (target_pid != -1) { | ||
737 | target_tid = target_pid; | ||
738 | thread_num = find_all_tid(target_pid, &all_tids); | ||
739 | if (thread_num <= 0) { | ||
740 | fprintf(stderr, "Can't find all threads of pid %d\n", | ||
741 | target_pid); | ||
742 | usage_with_options(record_usage, options); | ||
743 | } | ||
744 | } else { | ||
745 | all_tids=malloc(sizeof(pid_t)); | ||
746 | if (!all_tids) | ||
747 | return -ENOMEM; | ||
748 | |||
749 | all_tids[0] = target_tid; | ||
750 | thread_num = 1; | ||
751 | } | ||
752 | |||
753 | for (i = 0; i < MAX_NR_CPUS; i++) { | ||
754 | for (j = 0; j < MAX_COUNTERS; j++) { | ||
755 | fd[i][j] = malloc(sizeof(int)*thread_num); | ||
756 | mmap_array[i][j] = zalloc( | ||
757 | sizeof(struct mmap_data)*thread_num); | ||
758 | if (!fd[i][j] || !mmap_array[i][j]) | ||
759 | return -ENOMEM; | ||
760 | } | ||
761 | } | ||
762 | event_array = malloc( | ||
763 | sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num); | ||
764 | if (!event_array) | ||
765 | return -ENOMEM; | ||
766 | |||
706 | /* | 767 | /* |
707 | * User specified count overrides default frequency. | 768 | * User specified count overrides default frequency. |
708 | */ | 769 | */ |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index f815de25d0f..e93c69a8e72 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include "util/cache.h" | 14 | #include "util/cache.h" |
15 | #include <linux/rbtree.h> | 15 | #include <linux/rbtree.h> |
16 | #include "util/symbol.h" | 16 | #include "util/symbol.h" |
17 | #include "util/string.h" | ||
18 | #include "util/callchain.h" | 17 | #include "util/callchain.h" |
19 | #include "util/strlist.h" | 18 | #include "util/strlist.h" |
20 | #include "util/values.h" | 19 | #include "util/values.h" |
@@ -81,15 +80,20 @@ static int perf_session__add_hist_entry(struct perf_session *self, | |||
81 | struct addr_location *al, | 80 | struct addr_location *al, |
82 | struct sample_data *data) | 81 | struct sample_data *data) |
83 | { | 82 | { |
84 | struct symbol **syms = NULL, *parent = NULL; | 83 | struct map_symbol *syms = NULL; |
84 | struct symbol *parent = NULL; | ||
85 | bool hit; | 85 | bool hit; |
86 | int err; | ||
86 | struct hist_entry *he; | 87 | struct hist_entry *he; |
87 | struct event_stat_id *stats; | 88 | struct event_stat_id *stats; |
88 | struct perf_event_attr *attr; | 89 | struct perf_event_attr *attr; |
89 | 90 | ||
90 | if ((sort__has_parent || symbol_conf.use_callchain) && data->callchain) | 91 | if ((sort__has_parent || symbol_conf.use_callchain) && data->callchain) { |
91 | syms = perf_session__resolve_callchain(self, al->thread, | 92 | syms = perf_session__resolve_callchain(self, al->thread, |
92 | data->callchain, &parent); | 93 | data->callchain, &parent); |
94 | if (syms == NULL) | ||
95 | return -ENOMEM; | ||
96 | } | ||
93 | 97 | ||
94 | attr = perf_header__find_attr(data->id, &self->header); | 98 | attr = perf_header__find_attr(data->id, &self->header); |
95 | if (attr) | 99 | if (attr) |
@@ -108,9 +112,12 @@ static int perf_session__add_hist_entry(struct perf_session *self, | |||
108 | 112 | ||
109 | if (symbol_conf.use_callchain) { | 113 | if (symbol_conf.use_callchain) { |
110 | if (!hit) | 114 | if (!hit) |
111 | callchain_init(&he->callchain); | 115 | callchain_init(he->callchain); |
112 | append_chain(&he->callchain, data->callchain, syms); | 116 | err = append_chain(he->callchain, data->callchain, syms); |
113 | free(syms); | 117 | free(syms); |
118 | |||
119 | if (err) | ||
120 | return err; | ||
114 | } | 121 | } |
115 | 122 | ||
116 | return 0; | 123 | return 0; |
@@ -267,6 +274,7 @@ static int __cmd_report(void) | |||
267 | int ret = -EINVAL; | 274 | int ret = -EINVAL; |
268 | struct perf_session *session; | 275 | struct perf_session *session; |
269 | struct rb_node *next; | 276 | struct rb_node *next; |
277 | const char *help = "For a higher level overview, try: perf report --sort comm,dso"; | ||
270 | 278 | ||
271 | session = perf_session__new(input_name, O_RDONLY, force); | 279 | session = perf_session__new(input_name, O_RDONLY, force); |
272 | if (session == NULL) | 280 | if (session == NULL) |
@@ -297,34 +305,44 @@ static int __cmd_report(void) | |||
297 | next = rb_first(&session->stats_by_id); | 305 | next = rb_first(&session->stats_by_id); |
298 | while (next) { | 306 | while (next) { |
299 | struct event_stat_id *stats; | 307 | struct event_stat_id *stats; |
308 | u64 nr_hists; | ||
300 | 309 | ||
301 | stats = rb_entry(next, struct event_stat_id, rb_node); | 310 | stats = rb_entry(next, struct event_stat_id, rb_node); |
302 | perf_session__collapse_resort(&stats->hists); | 311 | perf_session__collapse_resort(&stats->hists); |
303 | perf_session__output_resort(&stats->hists, stats->stats.total); | 312 | nr_hists = perf_session__output_resort(&stats->hists, |
304 | if (rb_first(&session->stats_by_id) == | 313 | stats->stats.total); |
305 | rb_last(&session->stats_by_id)) | 314 | if (use_browser) |
306 | fprintf(stdout, "# Samples: %Ld\n#\n", | 315 | perf_session__browse_hists(&stats->hists, nr_hists, |
307 | stats->stats.total); | 316 | stats->stats.total, help, |
308 | else | 317 | input_name); |
309 | fprintf(stdout, "# Samples: %Ld %s\n#\n", | 318 | else { |
310 | stats->stats.total, | 319 | if (rb_first(&session->stats_by_id) == |
311 | __event_name(stats->type, stats->config)); | 320 | rb_last(&session->stats_by_id)) |
312 | 321 | fprintf(stdout, "# Samples: %Ld\n#\n", | |
313 | perf_session__fprintf_hists(&stats->hists, NULL, false, stdout, | 322 | stats->stats.total); |
323 | else | ||
324 | fprintf(stdout, "# Samples: %Ld %s\n#\n", | ||
325 | stats->stats.total, | ||
326 | __event_name(stats->type, stats->config)); | ||
327 | |||
328 | perf_session__fprintf_hists(&stats->hists, NULL, false, stdout, | ||
314 | stats->stats.total); | 329 | stats->stats.total); |
315 | fprintf(stdout, "\n\n"); | 330 | fprintf(stdout, "\n\n"); |
331 | } | ||
332 | |||
316 | next = rb_next(&stats->rb_node); | 333 | next = rb_next(&stats->rb_node); |
317 | } | 334 | } |
318 | 335 | ||
319 | if (sort_order == default_sort_order && | 336 | if (!use_browser && sort_order == default_sort_order && |
320 | parent_pattern == default_parent_pattern) | 337 | parent_pattern == default_parent_pattern) { |
321 | fprintf(stdout, "#\n# (For a higher level overview, try: perf report --sort comm,dso)\n#\n"); | 338 | fprintf(stdout, "#\n# (%s)\n#\n", help); |
322 | 339 | ||
323 | if (show_threads) { | 340 | if (show_threads) { |
324 | bool raw_printing_style = !strcmp(pretty_printing_style, "raw"); | 341 | bool style = !strcmp(pretty_printing_style, "raw"); |
325 | perf_read_values_display(stdout, &show_threads_values, | 342 | perf_read_values_display(stdout, &show_threads_values, |
326 | raw_printing_style); | 343 | style); |
327 | perf_read_values_destroy(&show_threads_values); | 344 | perf_read_values_destroy(&show_threads_values); |
345 | } | ||
328 | } | 346 | } |
329 | out_delete: | 347 | out_delete: |
330 | perf_session__delete(session); | 348 | perf_session__delete(session); |
@@ -447,7 +465,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) | |||
447 | { | 465 | { |
448 | argc = parse_options(argc, argv, options, report_usage, 0); | 466 | argc = parse_options(argc, argv, options, report_usage, 0); |
449 | 467 | ||
450 | setup_pager(); | 468 | setup_browser(); |
451 | 469 | ||
452 | if (symbol__init() < 0) | 470 | if (symbol__init() < 0) |
453 | return -1; | 471 | return -1; |
@@ -455,7 +473,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) | |||
455 | setup_sorting(report_usage, options); | 473 | setup_sorting(report_usage, options); |
456 | 474 | ||
457 | if (parent_pattern != default_parent_pattern) { | 475 | if (parent_pattern != default_parent_pattern) { |
458 | sort_dimension__add("parent"); | 476 | if (sort_dimension__add("parent") < 0) |
477 | return -1; | ||
459 | sort_parent.elide = 1; | 478 | sort_parent.elide = 1; |
460 | } else | 479 | } else |
461 | symbol_conf.exclude_other = false; | 480 | symbol_conf.exclude_other = false; |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 95db31cff6f..1036ca739e6 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include "util/debug.h" | 46 | #include "util/debug.h" |
47 | #include "util/header.h" | 47 | #include "util/header.h" |
48 | #include "util/cpumap.h" | 48 | #include "util/cpumap.h" |
49 | #include "util/thread.h" | ||
49 | 50 | ||
50 | #include <sys/prctl.h> | 51 | #include <sys/prctl.h> |
51 | #include <math.h> | 52 | #include <math.h> |
@@ -74,10 +75,13 @@ static int run_count = 1; | |||
74 | static int inherit = 1; | 75 | static int inherit = 1; |
75 | static int scale = 1; | 76 | static int scale = 1; |
76 | static pid_t target_pid = -1; | 77 | static pid_t target_pid = -1; |
78 | static pid_t target_tid = -1; | ||
79 | static pid_t *all_tids = NULL; | ||
80 | static int thread_num = 0; | ||
77 | static pid_t child_pid = -1; | 81 | static pid_t child_pid = -1; |
78 | static int null_run = 0; | 82 | static int null_run = 0; |
79 | 83 | ||
80 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; | 84 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
81 | 85 | ||
82 | static int event_scaled[MAX_COUNTERS]; | 86 | static int event_scaled[MAX_COUNTERS]; |
83 | 87 | ||
@@ -140,9 +144,11 @@ struct stats runtime_branches_stats; | |||
140 | #define ERR_PERF_OPEN \ | 144 | #define ERR_PERF_OPEN \ |
141 | "Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n" | 145 | "Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n" |
142 | 146 | ||
143 | static void create_perf_stat_counter(int counter, int pid) | 147 | static int create_perf_stat_counter(int counter) |
144 | { | 148 | { |
145 | struct perf_event_attr *attr = attrs + counter; | 149 | struct perf_event_attr *attr = attrs + counter; |
150 | int thread; | ||
151 | int ncreated = 0; | ||
146 | 152 | ||
147 | if (scale) | 153 | if (scale) |
148 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | | 154 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | |
@@ -152,21 +158,33 @@ static void create_perf_stat_counter(int counter, int pid) | |||
152 | unsigned int cpu; | 158 | unsigned int cpu; |
153 | 159 | ||
154 | for (cpu = 0; cpu < nr_cpus; cpu++) { | 160 | for (cpu = 0; cpu < nr_cpus; cpu++) { |
155 | fd[cpu][counter] = sys_perf_event_open(attr, -1, cpumap[cpu], -1, 0); | 161 | fd[cpu][counter][0] = sys_perf_event_open(attr, |
156 | if (fd[cpu][counter] < 0 && verbose) | 162 | -1, cpumap[cpu], -1, 0); |
157 | fprintf(stderr, ERR_PERF_OPEN, counter, | 163 | if (fd[cpu][counter][0] < 0) |
158 | fd[cpu][counter], strerror(errno)); | 164 | pr_debug(ERR_PERF_OPEN, counter, |
165 | fd[cpu][counter][0], strerror(errno)); | ||
166 | else | ||
167 | ++ncreated; | ||
159 | } | 168 | } |
160 | } else { | 169 | } else { |
161 | attr->inherit = inherit; | 170 | attr->inherit = inherit; |
162 | attr->disabled = 1; | 171 | if (target_pid == -1) { |
163 | attr->enable_on_exec = 1; | 172 | attr->disabled = 1; |
164 | 173 | attr->enable_on_exec = 1; | |
165 | fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0); | 174 | } |
166 | if (fd[0][counter] < 0 && verbose) | 175 | for (thread = 0; thread < thread_num; thread++) { |
167 | fprintf(stderr, ERR_PERF_OPEN, counter, | 176 | fd[0][counter][thread] = sys_perf_event_open(attr, |
168 | fd[0][counter], strerror(errno)); | 177 | all_tids[thread], -1, -1, 0); |
178 | if (fd[0][counter][thread] < 0) | ||
179 | pr_debug(ERR_PERF_OPEN, counter, | ||
180 | fd[0][counter][thread], | ||
181 | strerror(errno)); | ||
182 | else | ||
183 | ++ncreated; | ||
184 | } | ||
169 | } | 185 | } |
186 | |||
187 | return ncreated; | ||
170 | } | 188 | } |
171 | 189 | ||
172 | /* | 190 | /* |
@@ -190,25 +208,28 @@ static void read_counter(int counter) | |||
190 | unsigned int cpu; | 208 | unsigned int cpu; |
191 | size_t res, nv; | 209 | size_t res, nv; |
192 | int scaled; | 210 | int scaled; |
193 | int i; | 211 | int i, thread; |
194 | 212 | ||
195 | count[0] = count[1] = count[2] = 0; | 213 | count[0] = count[1] = count[2] = 0; |
196 | 214 | ||
197 | nv = scale ? 3 : 1; | 215 | nv = scale ? 3 : 1; |
198 | for (cpu = 0; cpu < nr_cpus; cpu++) { | 216 | for (cpu = 0; cpu < nr_cpus; cpu++) { |
199 | if (fd[cpu][counter] < 0) | 217 | for (thread = 0; thread < thread_num; thread++) { |
200 | continue; | 218 | if (fd[cpu][counter][thread] < 0) |
201 | 219 | continue; | |
202 | res = read(fd[cpu][counter], single_count, nv * sizeof(u64)); | 220 | |
203 | assert(res == nv * sizeof(u64)); | 221 | res = read(fd[cpu][counter][thread], |
204 | 222 | single_count, nv * sizeof(u64)); | |
205 | close(fd[cpu][counter]); | 223 | assert(res == nv * sizeof(u64)); |
206 | fd[cpu][counter] = -1; | 224 | |
207 | 225 | close(fd[cpu][counter][thread]); | |
208 | count[0] += single_count[0]; | 226 | fd[cpu][counter][thread] = -1; |
209 | if (scale) { | 227 | |
210 | count[1] += single_count[1]; | 228 | count[0] += single_count[0]; |
211 | count[2] += single_count[2]; | 229 | if (scale) { |
230 | count[1] += single_count[1]; | ||
231 | count[2] += single_count[2]; | ||
232 | } | ||
212 | } | 233 | } |
213 | } | 234 | } |
214 | 235 | ||
@@ -250,10 +271,9 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
250 | { | 271 | { |
251 | unsigned long long t0, t1; | 272 | unsigned long long t0, t1; |
252 | int status = 0; | 273 | int status = 0; |
253 | int counter; | 274 | int counter, ncreated = 0; |
254 | int pid = target_pid; | ||
255 | int child_ready_pipe[2], go_pipe[2]; | 275 | int child_ready_pipe[2], go_pipe[2]; |
256 | const bool forks = (target_pid == -1 && argc > 0); | 276 | const bool forks = (argc > 0); |
257 | char buf; | 277 | char buf; |
258 | 278 | ||
259 | if (!system_wide) | 279 | if (!system_wide) |
@@ -265,10 +285,10 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
265 | } | 285 | } |
266 | 286 | ||
267 | if (forks) { | 287 | if (forks) { |
268 | if ((pid = fork()) < 0) | 288 | if ((child_pid = fork()) < 0) |
269 | perror("failed to fork"); | 289 | perror("failed to fork"); |
270 | 290 | ||
271 | if (!pid) { | 291 | if (!child_pid) { |
272 | close(child_ready_pipe[0]); | 292 | close(child_ready_pipe[0]); |
273 | close(go_pipe[1]); | 293 | close(go_pipe[1]); |
274 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); | 294 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); |
@@ -297,7 +317,8 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
297 | exit(-1); | 317 | exit(-1); |
298 | } | 318 | } |
299 | 319 | ||
300 | child_pid = pid; | 320 | if (target_tid == -1 && target_pid == -1 && !system_wide) |
321 | all_tids[0] = child_pid; | ||
301 | 322 | ||
302 | /* | 323 | /* |
303 | * Wait for the child to be ready to exec. | 324 | * Wait for the child to be ready to exec. |
@@ -310,7 +331,16 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
310 | } | 331 | } |
311 | 332 | ||
312 | for (counter = 0; counter < nr_counters; counter++) | 333 | for (counter = 0; counter < nr_counters; counter++) |
313 | create_perf_stat_counter(counter, pid); | 334 | ncreated += create_perf_stat_counter(counter); |
335 | |||
336 | if (ncreated == 0) { | ||
337 | pr_err("No permission to collect %sstats.\n" | ||
338 | "Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n", | ||
339 | system_wide ? "system-wide " : ""); | ||
340 | if (child_pid != -1) | ||
341 | kill(child_pid, SIGTERM); | ||
342 | return -1; | ||
343 | } | ||
314 | 344 | ||
315 | /* | 345 | /* |
316 | * Enable counters and exec the command: | 346 | * Enable counters and exec the command: |
@@ -321,7 +351,7 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
321 | close(go_pipe[1]); | 351 | close(go_pipe[1]); |
322 | wait(&status); | 352 | wait(&status); |
323 | } else { | 353 | } else { |
324 | while(!done); | 354 | while(!done) sleep(1); |
325 | } | 355 | } |
326 | 356 | ||
327 | t1 = rdclock(); | 357 | t1 = rdclock(); |
@@ -429,12 +459,14 @@ static void print_stat(int argc, const char **argv) | |||
429 | 459 | ||
430 | fprintf(stderr, "\n"); | 460 | fprintf(stderr, "\n"); |
431 | fprintf(stderr, " Performance counter stats for "); | 461 | fprintf(stderr, " Performance counter stats for "); |
432 | if(target_pid == -1) { | 462 | if(target_pid == -1 && target_tid == -1) { |
433 | fprintf(stderr, "\'%s", argv[0]); | 463 | fprintf(stderr, "\'%s", argv[0]); |
434 | for (i = 1; i < argc; i++) | 464 | for (i = 1; i < argc; i++) |
435 | fprintf(stderr, " %s", argv[i]); | 465 | fprintf(stderr, " %s", argv[i]); |
436 | }else | 466 | } else if (target_pid != -1) |
437 | fprintf(stderr, "task pid \'%d", target_pid); | 467 | fprintf(stderr, "process id \'%d", target_pid); |
468 | else | ||
469 | fprintf(stderr, "thread id \'%d", target_tid); | ||
438 | 470 | ||
439 | fprintf(stderr, "\'"); | 471 | fprintf(stderr, "\'"); |
440 | if (run_count > 1) | 472 | if (run_count > 1) |
@@ -459,7 +491,7 @@ static volatile int signr = -1; | |||
459 | 491 | ||
460 | static void skip_signal(int signo) | 492 | static void skip_signal(int signo) |
461 | { | 493 | { |
462 | if(target_pid != -1) | 494 | if(child_pid == -1) |
463 | done = 1; | 495 | done = 1; |
464 | 496 | ||
465 | signr = signo; | 497 | signr = signo; |
@@ -489,7 +521,9 @@ static const struct option options[] = { | |||
489 | OPT_BOOLEAN('i', "inherit", &inherit, | 521 | OPT_BOOLEAN('i', "inherit", &inherit, |
490 | "child tasks inherit counters"), | 522 | "child tasks inherit counters"), |
491 | OPT_INTEGER('p', "pid", &target_pid, | 523 | OPT_INTEGER('p', "pid", &target_pid, |
492 | "stat events on existing pid"), | 524 | "stat events on existing process id"), |
525 | OPT_INTEGER('t', "tid", &target_tid, | ||
526 | "stat events on existing thread id"), | ||
493 | OPT_BOOLEAN('a', "all-cpus", &system_wide, | 527 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
494 | "system-wide collection from all CPUs"), | 528 | "system-wide collection from all CPUs"), |
495 | OPT_BOOLEAN('c', "scale", &scale, | 529 | OPT_BOOLEAN('c', "scale", &scale, |
@@ -506,10 +540,11 @@ static const struct option options[] = { | |||
506 | int cmd_stat(int argc, const char **argv, const char *prefix __used) | 540 | int cmd_stat(int argc, const char **argv, const char *prefix __used) |
507 | { | 541 | { |
508 | int status; | 542 | int status; |
543 | int i,j; | ||
509 | 544 | ||
510 | argc = parse_options(argc, argv, options, stat_usage, | 545 | argc = parse_options(argc, argv, options, stat_usage, |
511 | PARSE_OPT_STOP_AT_NON_OPTION); | 546 | PARSE_OPT_STOP_AT_NON_OPTION); |
512 | if (!argc && target_pid == -1) | 547 | if (!argc && target_pid == -1 && target_tid == -1) |
513 | usage_with_options(stat_usage, options); | 548 | usage_with_options(stat_usage, options); |
514 | if (run_count <= 0) | 549 | if (run_count <= 0) |
515 | usage_with_options(stat_usage, options); | 550 | usage_with_options(stat_usage, options); |
@@ -525,6 +560,31 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
525 | else | 560 | else |
526 | nr_cpus = 1; | 561 | nr_cpus = 1; |
527 | 562 | ||
563 | if (target_pid != -1) { | ||
564 | target_tid = target_pid; | ||
565 | thread_num = find_all_tid(target_pid, &all_tids); | ||
566 | if (thread_num <= 0) { | ||
567 | fprintf(stderr, "Can't find all threads of pid %d\n", | ||
568 | target_pid); | ||
569 | usage_with_options(stat_usage, options); | ||
570 | } | ||
571 | } else { | ||
572 | all_tids=malloc(sizeof(pid_t)); | ||
573 | if (!all_tids) | ||
574 | return -ENOMEM; | ||
575 | |||
576 | all_tids[0] = target_tid; | ||
577 | thread_num = 1; | ||
578 | } | ||
579 | |||
580 | for (i = 0; i < MAX_NR_CPUS; i++) { | ||
581 | for (j = 0; j < MAX_COUNTERS; j++) { | ||
582 | fd[i][j] = malloc(sizeof(int)*thread_num); | ||
583 | if (!fd[i][j]) | ||
584 | return -ENOMEM; | ||
585 | } | ||
586 | } | ||
587 | |||
528 | /* | 588 | /* |
529 | * We dont want to block the signals - that would cause | 589 | * We dont want to block the signals - that would cause |
530 | * child tasks to inherit that and Ctrl-C would not work. | 590 | * child tasks to inherit that and Ctrl-C would not work. |
@@ -543,7 +603,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
543 | status = run_perf_stat(argc, argv); | 603 | status = run_perf_stat(argc, argv); |
544 | } | 604 | } |
545 | 605 | ||
546 | print_stat(argc, argv); | 606 | if (status != -1) |
607 | print_stat(argc, argv); | ||
547 | 608 | ||
548 | return status; | 609 | return status; |
549 | } | 610 | } |
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 0d4d8ff7914..266e7aa996d 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include "util/cache.h" | 21 | #include "util/cache.h" |
22 | #include <linux/rbtree.h> | 22 | #include <linux/rbtree.h> |
23 | #include "util/symbol.h" | 23 | #include "util/symbol.h" |
24 | #include "util/string.h" | ||
25 | #include "util/callchain.h" | 24 | #include "util/callchain.h" |
26 | #include "util/strlist.h" | 25 | #include "util/strlist.h" |
27 | 26 | ||
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 1f529321607..4abdd9b646b 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -55,7 +55,7 @@ | |||
55 | #include <linux/unistd.h> | 55 | #include <linux/unistd.h> |
56 | #include <linux/types.h> | 56 | #include <linux/types.h> |
57 | 57 | ||
58 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; | 58 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
59 | 59 | ||
60 | static int system_wide = 0; | 60 | static int system_wide = 0; |
61 | 61 | ||
@@ -65,6 +65,9 @@ static int count_filter = 5; | |||
65 | static int print_entries; | 65 | static int print_entries; |
66 | 66 | ||
67 | static int target_pid = -1; | 67 | static int target_pid = -1; |
68 | static int target_tid = -1; | ||
69 | static pid_t *all_tids = NULL; | ||
70 | static int thread_num = 0; | ||
68 | static int inherit = 0; | 71 | static int inherit = 0; |
69 | static int profile_cpu = -1; | 72 | static int profile_cpu = -1; |
70 | static int nr_cpus = 0; | 73 | static int nr_cpus = 0; |
@@ -133,7 +136,7 @@ static inline struct symbol *sym_entry__symbol(struct sym_entry *self) | |||
133 | return ((void *)self) + symbol_conf.priv_size; | 136 | return ((void *)self) + symbol_conf.priv_size; |
134 | } | 137 | } |
135 | 138 | ||
136 | static void get_term_dimensions(struct winsize *ws) | 139 | void get_term_dimensions(struct winsize *ws) |
137 | { | 140 | { |
138 | char *s = getenv("LINES"); | 141 | char *s = getenv("LINES"); |
139 | 142 | ||
@@ -169,7 +172,7 @@ static void sig_winch_handler(int sig __used) | |||
169 | update_print_entries(&winsize); | 172 | update_print_entries(&winsize); |
170 | } | 173 | } |
171 | 174 | ||
172 | static void parse_source(struct sym_entry *syme) | 175 | static int parse_source(struct sym_entry *syme) |
173 | { | 176 | { |
174 | struct symbol *sym; | 177 | struct symbol *sym; |
175 | struct sym_entry_source *source; | 178 | struct sym_entry_source *source; |
@@ -180,12 +183,21 @@ static void parse_source(struct sym_entry *syme) | |||
180 | u64 len; | 183 | u64 len; |
181 | 184 | ||
182 | if (!syme) | 185 | if (!syme) |
183 | return; | 186 | return -1; |
187 | |||
188 | sym = sym_entry__symbol(syme); | ||
189 | map = syme->map; | ||
190 | |||
191 | /* | ||
192 | * We can't annotate with just /proc/kallsyms | ||
193 | */ | ||
194 | if (map->dso->origin == DSO__ORIG_KERNEL) | ||
195 | return -1; | ||
184 | 196 | ||
185 | if (syme->src == NULL) { | 197 | if (syme->src == NULL) { |
186 | syme->src = zalloc(sizeof(*source)); | 198 | syme->src = zalloc(sizeof(*source)); |
187 | if (syme->src == NULL) | 199 | if (syme->src == NULL) |
188 | return; | 200 | return -1; |
189 | pthread_mutex_init(&syme->src->lock, NULL); | 201 | pthread_mutex_init(&syme->src->lock, NULL); |
190 | } | 202 | } |
191 | 203 | ||
@@ -195,9 +207,6 @@ static void parse_source(struct sym_entry *syme) | |||
195 | pthread_mutex_lock(&source->lock); | 207 | pthread_mutex_lock(&source->lock); |
196 | goto out_assign; | 208 | goto out_assign; |
197 | } | 209 | } |
198 | |||
199 | sym = sym_entry__symbol(syme); | ||
200 | map = syme->map; | ||
201 | path = map->dso->long_name; | 210 | path = map->dso->long_name; |
202 | 211 | ||
203 | len = sym->end - sym->start; | 212 | len = sym->end - sym->start; |
@@ -209,7 +218,7 @@ static void parse_source(struct sym_entry *syme) | |||
209 | 218 | ||
210 | file = popen(command, "r"); | 219 | file = popen(command, "r"); |
211 | if (!file) | 220 | if (!file) |
212 | return; | 221 | return -1; |
213 | 222 | ||
214 | pthread_mutex_lock(&source->lock); | 223 | pthread_mutex_lock(&source->lock); |
215 | source->lines_tail = &source->lines; | 224 | source->lines_tail = &source->lines; |
@@ -245,6 +254,7 @@ static void parse_source(struct sym_entry *syme) | |||
245 | out_assign: | 254 | out_assign: |
246 | sym_filter_entry = syme; | 255 | sym_filter_entry = syme; |
247 | pthread_mutex_unlock(&source->lock); | 256 | pthread_mutex_unlock(&source->lock); |
257 | return 0; | ||
248 | } | 258 | } |
249 | 259 | ||
250 | static void __zero_source_counters(struct sym_entry *syme) | 260 | static void __zero_source_counters(struct sym_entry *syme) |
@@ -411,6 +421,7 @@ static double sym_weight(const struct sym_entry *sym) | |||
411 | 421 | ||
412 | static long samples; | 422 | static long samples; |
413 | static long userspace_samples; | 423 | static long userspace_samples; |
424 | static long exact_samples; | ||
414 | static const char CONSOLE_CLEAR[] = "[H[2J"; | 425 | static const char CONSOLE_CLEAR[] = "[H[2J"; |
415 | 426 | ||
416 | static void __list_insert_active_sym(struct sym_entry *syme) | 427 | static void __list_insert_active_sym(struct sym_entry *syme) |
@@ -451,6 +462,7 @@ static void print_sym_table(void) | |||
451 | int counter, snap = !display_weighted ? sym_counter : 0; | 462 | int counter, snap = !display_weighted ? sym_counter : 0; |
452 | float samples_per_sec = samples/delay_secs; | 463 | float samples_per_sec = samples/delay_secs; |
453 | float ksamples_per_sec = (samples-userspace_samples)/delay_secs; | 464 | float ksamples_per_sec = (samples-userspace_samples)/delay_secs; |
465 | float esamples_percent = (100.0*exact_samples)/samples; | ||
454 | float sum_ksamples = 0.0; | 466 | float sum_ksamples = 0.0; |
455 | struct sym_entry *syme, *n; | 467 | struct sym_entry *syme, *n; |
456 | struct rb_root tmp = RB_ROOT; | 468 | struct rb_root tmp = RB_ROOT; |
@@ -458,7 +470,7 @@ static void print_sym_table(void) | |||
458 | int sym_width = 0, dso_width = 0, dso_short_width = 0; | 470 | int sym_width = 0, dso_width = 0, dso_short_width = 0; |
459 | const int win_width = winsize.ws_col - 1; | 471 | const int win_width = winsize.ws_col - 1; |
460 | 472 | ||
461 | samples = userspace_samples = 0; | 473 | samples = userspace_samples = exact_samples = 0; |
462 | 474 | ||
463 | /* Sort the active symbols */ | 475 | /* Sort the active symbols */ |
464 | pthread_mutex_lock(&active_symbols_lock); | 476 | pthread_mutex_lock(&active_symbols_lock); |
@@ -489,9 +501,10 @@ static void print_sym_table(void) | |||
489 | puts(CONSOLE_CLEAR); | 501 | puts(CONSOLE_CLEAR); |
490 | 502 | ||
491 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); | 503 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); |
492 | printf( " PerfTop:%8.0f irqs/sec kernel:%4.1f%% [", | 504 | printf( " PerfTop:%8.0f irqs/sec kernel:%4.1f%% exact: %4.1f%% [", |
493 | samples_per_sec, | 505 | samples_per_sec, |
494 | 100.0 - (100.0*((samples_per_sec-ksamples_per_sec)/samples_per_sec))); | 506 | 100.0 - (100.0*((samples_per_sec-ksamples_per_sec)/samples_per_sec)), |
507 | esamples_percent); | ||
495 | 508 | ||
496 | if (nr_counters == 1 || !display_weighted) { | 509 | if (nr_counters == 1 || !display_weighted) { |
497 | printf("%Ld", (u64)attrs[0].sample_period); | 510 | printf("%Ld", (u64)attrs[0].sample_period); |
@@ -514,13 +527,15 @@ static void print_sym_table(void) | |||
514 | 527 | ||
515 | if (target_pid != -1) | 528 | if (target_pid != -1) |
516 | printf(" (target_pid: %d", target_pid); | 529 | printf(" (target_pid: %d", target_pid); |
530 | else if (target_tid != -1) | ||
531 | printf(" (target_tid: %d", target_tid); | ||
517 | else | 532 | else |
518 | printf(" (all"); | 533 | printf(" (all"); |
519 | 534 | ||
520 | if (profile_cpu != -1) | 535 | if (profile_cpu != -1) |
521 | printf(", cpu: %d)\n", profile_cpu); | 536 | printf(", cpu: %d)\n", profile_cpu); |
522 | else { | 537 | else { |
523 | if (target_pid != -1) | 538 | if (target_tid != -1) |
524 | printf(")\n"); | 539 | printf(")\n"); |
525 | else | 540 | else |
526 | printf(", %d CPUs)\n", nr_cpus); | 541 | printf(", %d CPUs)\n", nr_cpus); |
@@ -960,6 +975,9 @@ static void event__process_sample(const event_t *self, | |||
960 | return; | 975 | return; |
961 | } | 976 | } |
962 | 977 | ||
978 | if (self->header.misc & PERF_RECORD_MISC_EXACT) | ||
979 | exact_samples++; | ||
980 | |||
963 | if (event__preprocess_sample(self, session, &al, symbol_filter) < 0 || | 981 | if (event__preprocess_sample(self, session, &al, symbol_filter) < 0 || |
964 | al.filtered) | 982 | al.filtered) |
965 | return; | 983 | return; |
@@ -990,7 +1008,17 @@ static void event__process_sample(const event_t *self, | |||
990 | if (sym_filter_entry_sched) { | 1008 | if (sym_filter_entry_sched) { |
991 | sym_filter_entry = sym_filter_entry_sched; | 1009 | sym_filter_entry = sym_filter_entry_sched; |
992 | sym_filter_entry_sched = NULL; | 1010 | sym_filter_entry_sched = NULL; |
993 | parse_source(sym_filter_entry); | 1011 | if (parse_source(sym_filter_entry) < 0) { |
1012 | struct symbol *sym = sym_entry__symbol(sym_filter_entry); | ||
1013 | |||
1014 | pr_err("Can't annotate %s", sym->name); | ||
1015 | if (sym_filter_entry->map->dso->origin == DSO__ORIG_KERNEL) { | ||
1016 | pr_err(": No vmlinux file was found in the path:\n"); | ||
1017 | vmlinux_path__fprintf(stderr); | ||
1018 | } else | ||
1019 | pr_err(".\n"); | ||
1020 | exit(1); | ||
1021 | } | ||
994 | } | 1022 | } |
995 | 1023 | ||
996 | syme = symbol__priv(al.sym); | 1024 | syme = symbol__priv(al.sym); |
@@ -1106,16 +1134,21 @@ static void perf_session__mmap_read_counter(struct perf_session *self, | |||
1106 | md->prev = old; | 1134 | md->prev = old; |
1107 | } | 1135 | } |
1108 | 1136 | ||
1109 | static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS]; | 1137 | static struct pollfd *event_array; |
1110 | static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | 1138 | static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; |
1111 | 1139 | ||
1112 | static void perf_session__mmap_read(struct perf_session *self) | 1140 | static void perf_session__mmap_read(struct perf_session *self) |
1113 | { | 1141 | { |
1114 | int i, counter; | 1142 | int i, counter, thread_index; |
1115 | 1143 | ||
1116 | for (i = 0; i < nr_cpus; i++) { | 1144 | for (i = 0; i < nr_cpus; i++) { |
1117 | for (counter = 0; counter < nr_counters; counter++) | 1145 | for (counter = 0; counter < nr_counters; counter++) |
1118 | perf_session__mmap_read_counter(self, &mmap_array[i][counter]); | 1146 | for (thread_index = 0; |
1147 | thread_index < thread_num; | ||
1148 | thread_index++) { | ||
1149 | perf_session__mmap_read_counter(self, | ||
1150 | &mmap_array[i][counter][thread_index]); | ||
1151 | } | ||
1119 | } | 1152 | } |
1120 | } | 1153 | } |
1121 | 1154 | ||
@@ -1126,9 +1159,10 @@ static void start_counter(int i, int counter) | |||
1126 | { | 1159 | { |
1127 | struct perf_event_attr *attr; | 1160 | struct perf_event_attr *attr; |
1128 | int cpu; | 1161 | int cpu; |
1162 | int thread_index; | ||
1129 | 1163 | ||
1130 | cpu = profile_cpu; | 1164 | cpu = profile_cpu; |
1131 | if (target_pid == -1 && profile_cpu == -1) | 1165 | if (target_tid == -1 && profile_cpu == -1) |
1132 | cpu = cpumap[i]; | 1166 | cpu = cpumap[i]; |
1133 | 1167 | ||
1134 | attr = attrs + counter; | 1168 | attr = attrs + counter; |
@@ -1144,55 +1178,58 @@ static void start_counter(int i, int counter) | |||
1144 | attr->inherit = (cpu < 0) && inherit; | 1178 | attr->inherit = (cpu < 0) && inherit; |
1145 | attr->mmap = 1; | 1179 | attr->mmap = 1; |
1146 | 1180 | ||
1181 | for (thread_index = 0; thread_index < thread_num; thread_index++) { | ||
1147 | try_again: | 1182 | try_again: |
1148 | fd[i][counter] = sys_perf_event_open(attr, target_pid, cpu, group_fd, 0); | 1183 | fd[i][counter][thread_index] = sys_perf_event_open(attr, |
1149 | 1184 | all_tids[thread_index], cpu, group_fd, 0); | |
1150 | if (fd[i][counter] < 0) { | 1185 | |
1151 | int err = errno; | 1186 | if (fd[i][counter][thread_index] < 0) { |
1187 | int err = errno; | ||
1188 | |||
1189 | if (err == EPERM || err == EACCES) | ||
1190 | die("No permission - are you root?\n"); | ||
1191 | /* | ||
1192 | * If it's cycles then fall back to hrtimer | ||
1193 | * based cpu-clock-tick sw counter, which | ||
1194 | * is always available even if no PMU support: | ||
1195 | */ | ||
1196 | if (attr->type == PERF_TYPE_HARDWARE | ||
1197 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { | ||
1198 | |||
1199 | if (verbose) | ||
1200 | warning(" ... trying to fall back to cpu-clock-ticks\n"); | ||
1201 | |||
1202 | attr->type = PERF_TYPE_SOFTWARE; | ||
1203 | attr->config = PERF_COUNT_SW_CPU_CLOCK; | ||
1204 | goto try_again; | ||
1205 | } | ||
1206 | printf("\n"); | ||
1207 | error("perfcounter syscall returned with %d (%s)\n", | ||
1208 | fd[i][counter][thread_index], strerror(err)); | ||
1209 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | ||
1210 | exit(-1); | ||
1211 | } | ||
1212 | assert(fd[i][counter][thread_index] >= 0); | ||
1213 | fcntl(fd[i][counter][thread_index], F_SETFL, O_NONBLOCK); | ||
1152 | 1214 | ||
1153 | if (err == EPERM || err == EACCES) | ||
1154 | die("No permission - are you root?\n"); | ||
1155 | /* | 1215 | /* |
1156 | * If it's cycles then fall back to hrtimer | 1216 | * First counter acts as the group leader: |
1157 | * based cpu-clock-tick sw counter, which | ||
1158 | * is always available even if no PMU support: | ||
1159 | */ | 1217 | */ |
1160 | if (attr->type == PERF_TYPE_HARDWARE | 1218 | if (group && group_fd == -1) |
1161 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { | 1219 | group_fd = fd[i][counter][thread_index]; |
1162 | 1220 | ||
1163 | if (verbose) | 1221 | event_array[nr_poll].fd = fd[i][counter][thread_index]; |
1164 | warning(" ... trying to fall back to cpu-clock-ticks\n"); | 1222 | event_array[nr_poll].events = POLLIN; |
1165 | 1223 | nr_poll++; | |
1166 | attr->type = PERF_TYPE_SOFTWARE; | 1224 | |
1167 | attr->config = PERF_COUNT_SW_CPU_CLOCK; | 1225 | mmap_array[i][counter][thread_index].counter = counter; |
1168 | goto try_again; | 1226 | mmap_array[i][counter][thread_index].prev = 0; |
1169 | } | 1227 | mmap_array[i][counter][thread_index].mask = mmap_pages*page_size - 1; |
1170 | printf("\n"); | 1228 | mmap_array[i][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, |
1171 | error("perfcounter syscall returned with %d (%s)\n", | 1229 | PROT_READ, MAP_SHARED, fd[i][counter][thread_index], 0); |
1172 | fd[i][counter], strerror(err)); | 1230 | if (mmap_array[i][counter][thread_index].base == MAP_FAILED) |
1173 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | 1231 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
1174 | exit(-1); | ||
1175 | } | 1232 | } |
1176 | assert(fd[i][counter] >= 0); | ||
1177 | fcntl(fd[i][counter], F_SETFL, O_NONBLOCK); | ||
1178 | |||
1179 | /* | ||
1180 | * First counter acts as the group leader: | ||
1181 | */ | ||
1182 | if (group && group_fd == -1) | ||
1183 | group_fd = fd[i][counter]; | ||
1184 | |||
1185 | event_array[nr_poll].fd = fd[i][counter]; | ||
1186 | event_array[nr_poll].events = POLLIN; | ||
1187 | nr_poll++; | ||
1188 | |||
1189 | mmap_array[i][counter].counter = counter; | ||
1190 | mmap_array[i][counter].prev = 0; | ||
1191 | mmap_array[i][counter].mask = mmap_pages*page_size - 1; | ||
1192 | mmap_array[i][counter].base = mmap(NULL, (mmap_pages+1)*page_size, | ||
1193 | PROT_READ, MAP_SHARED, fd[i][counter], 0); | ||
1194 | if (mmap_array[i][counter].base == MAP_FAILED) | ||
1195 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); | ||
1196 | } | 1233 | } |
1197 | 1234 | ||
1198 | static int __cmd_top(void) | 1235 | static int __cmd_top(void) |
@@ -1208,8 +1245,8 @@ static int __cmd_top(void) | |||
1208 | if (session == NULL) | 1245 | if (session == NULL) |
1209 | return -ENOMEM; | 1246 | return -ENOMEM; |
1210 | 1247 | ||
1211 | if (target_pid != -1) | 1248 | if (target_tid != -1) |
1212 | event__synthesize_thread(target_pid, event__process, session); | 1249 | event__synthesize_thread(target_tid, event__process, session); |
1213 | else | 1250 | else |
1214 | event__synthesize_threads(event__process, session); | 1251 | event__synthesize_threads(event__process, session); |
1215 | 1252 | ||
@@ -1220,7 +1257,7 @@ static int __cmd_top(void) | |||
1220 | } | 1257 | } |
1221 | 1258 | ||
1222 | /* Wait for a minimal set of events before starting the snapshot */ | 1259 | /* Wait for a minimal set of events before starting the snapshot */ |
1223 | poll(event_array, nr_poll, 100); | 1260 | poll(&event_array[0], nr_poll, 100); |
1224 | 1261 | ||
1225 | perf_session__mmap_read(session); | 1262 | perf_session__mmap_read(session); |
1226 | 1263 | ||
@@ -1263,7 +1300,9 @@ static const struct option options[] = { | |||
1263 | OPT_INTEGER('c', "count", &default_interval, | 1300 | OPT_INTEGER('c', "count", &default_interval, |
1264 | "event period to sample"), | 1301 | "event period to sample"), |
1265 | OPT_INTEGER('p', "pid", &target_pid, | 1302 | OPT_INTEGER('p', "pid", &target_pid, |
1266 | "profile events on existing pid"), | 1303 | "profile events on existing process id"), |
1304 | OPT_INTEGER('t', "tid", &target_tid, | ||
1305 | "profile events on existing thread id"), | ||
1267 | OPT_BOOLEAN('a', "all-cpus", &system_wide, | 1306 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
1268 | "system-wide collection from all CPUs"), | 1307 | "system-wide collection from all CPUs"), |
1269 | OPT_INTEGER('C', "CPU", &profile_cpu, | 1308 | OPT_INTEGER('C', "CPU", &profile_cpu, |
@@ -1304,6 +1343,7 @@ static const struct option options[] = { | |||
1304 | int cmd_top(int argc, const char **argv, const char *prefix __used) | 1343 | int cmd_top(int argc, const char **argv, const char *prefix __used) |
1305 | { | 1344 | { |
1306 | int counter; | 1345 | int counter; |
1346 | int i,j; | ||
1307 | 1347 | ||
1308 | page_size = sysconf(_SC_PAGE_SIZE); | 1348 | page_size = sysconf(_SC_PAGE_SIZE); |
1309 | 1349 | ||
@@ -1311,8 +1351,39 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) | |||
1311 | if (argc) | 1351 | if (argc) |
1312 | usage_with_options(top_usage, options); | 1352 | usage_with_options(top_usage, options); |
1313 | 1353 | ||
1354 | if (target_pid != -1) { | ||
1355 | target_tid = target_pid; | ||
1356 | thread_num = find_all_tid(target_pid, &all_tids); | ||
1357 | if (thread_num <= 0) { | ||
1358 | fprintf(stderr, "Can't find all threads of pid %d\n", | ||
1359 | target_pid); | ||
1360 | usage_with_options(top_usage, options); | ||
1361 | } | ||
1362 | } else { | ||
1363 | all_tids=malloc(sizeof(pid_t)); | ||
1364 | if (!all_tids) | ||
1365 | return -ENOMEM; | ||
1366 | |||
1367 | all_tids[0] = target_tid; | ||
1368 | thread_num = 1; | ||
1369 | } | ||
1370 | |||
1371 | for (i = 0; i < MAX_NR_CPUS; i++) { | ||
1372 | for (j = 0; j < MAX_COUNTERS; j++) { | ||
1373 | fd[i][j] = malloc(sizeof(int)*thread_num); | ||
1374 | mmap_array[i][j] = zalloc( | ||
1375 | sizeof(struct mmap_data)*thread_num); | ||
1376 | if (!fd[i][j] || !mmap_array[i][j]) | ||
1377 | return -ENOMEM; | ||
1378 | } | ||
1379 | } | ||
1380 | event_array = malloc( | ||
1381 | sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num); | ||
1382 | if (!event_array) | ||
1383 | return -ENOMEM; | ||
1384 | |||
1314 | /* CPU and PID are mutually exclusive */ | 1385 | /* CPU and PID are mutually exclusive */ |
1315 | if (target_pid != -1 && profile_cpu != -1) { | 1386 | if (target_tid > 0 && profile_cpu != -1) { |
1316 | printf("WARNING: PID switch overriding CPU\n"); | 1387 | printf("WARNING: PID switch overriding CPU\n"); |
1317 | sleep(1); | 1388 | sleep(1); |
1318 | profile_cpu = -1; | 1389 | profile_cpu = -1; |
@@ -1353,7 +1424,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) | |||
1353 | attrs[counter].sample_period = default_interval; | 1424 | attrs[counter].sample_period = default_interval; |
1354 | } | 1425 | } |
1355 | 1426 | ||
1356 | if (target_pid != -1 || profile_cpu != -1) | 1427 | if (target_tid != -1 || profile_cpu != -1) |
1357 | nr_cpus = 1; | 1428 | nr_cpus = 1; |
1358 | else | 1429 | else |
1359 | nr_cpus = read_cpu_map(); | 1430 | nr_cpus = read_cpu_map(); |
diff --git a/tools/perf/perf-archive.sh b/tools/perf/perf-archive.sh index 910468e6e01..2e7a4f417e2 100644 --- a/tools/perf/perf-archive.sh +++ b/tools/perf/perf-archive.sh | |||
@@ -30,4 +30,7 @@ done | |||
30 | 30 | ||
31 | tar cfj $PERF_DATA.tar.bz2 -C $DEBUGDIR -T $MANIFEST | 31 | tar cfj $PERF_DATA.tar.bz2 -C $DEBUGDIR -T $MANIFEST |
32 | rm -f $MANIFEST $BUILDIDS | 32 | rm -f $MANIFEST $BUILDIDS |
33 | echo -e "Now please run:\n" | ||
34 | echo -e "$ tar xvf $PERF_DATA.tar.bz2 -C ~/.debug\n" | ||
35 | echo "wherever you need to run 'perf report' on." | ||
33 | exit 0 | 36 | exit 0 |
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index cd32c200cdb..d4be55b6cd3 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -13,9 +13,10 @@ | |||
13 | #include "util/quote.h" | 13 | #include "util/quote.h" |
14 | #include "util/run-command.h" | 14 | #include "util/run-command.h" |
15 | #include "util/parse-events.h" | 15 | #include "util/parse-events.h" |
16 | #include "util/string.h" | ||
17 | #include "util/debugfs.h" | 16 | #include "util/debugfs.h" |
18 | 17 | ||
18 | bool use_browser; | ||
19 | |||
19 | const char perf_usage_string[] = | 20 | const char perf_usage_string[] = |
20 | "perf [--version] [--help] COMMAND [ARGS]"; | 21 | "perf [--version] [--help] COMMAND [ARGS]"; |
21 | 22 | ||
@@ -262,6 +263,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
262 | set_debugfs_path(); | 263 | set_debugfs_path(); |
263 | 264 | ||
264 | status = p->fn(argc, argv, prefix); | 265 | status = p->fn(argc, argv, prefix); |
266 | exit_browser(status); | ||
267 | |||
265 | if (status) | 268 | if (status) |
266 | return status & 0xff; | 269 | return status & 0xff; |
267 | 270 | ||
diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 6fb379bc1d1..ec212748d65 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h | |||
@@ -1,6 +1,10 @@ | |||
1 | #ifndef _PERF_PERF_H | 1 | #ifndef _PERF_PERF_H |
2 | #define _PERF_PERF_H | 2 | #define _PERF_PERF_H |
3 | 3 | ||
4 | struct winsize; | ||
5 | |||
6 | void get_term_dimensions(struct winsize *ws); | ||
7 | |||
4 | #if defined(__i386__) | 8 | #if defined(__i386__) |
5 | #include "../../arch/x86/include/asm/unistd.h" | 9 | #include "../../arch/x86/include/asm/unistd.h" |
6 | #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") | 10 | #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") |
@@ -102,8 +106,6 @@ static inline unsigned long long rdclock(void) | |||
102 | #define __user | 106 | #define __user |
103 | #define asmlinkage | 107 | #define asmlinkage |
104 | 108 | ||
105 | #define __used __attribute__((__unused__)) | ||
106 | |||
107 | #define unlikely(x) __builtin_expect(!!(x), 0) | 109 | #define unlikely(x) __builtin_expect(!!(x), 0) |
108 | #define min(x, y) ({ \ | 110 | #define min(x, y) ({ \ |
109 | typeof(x) _min1 = (x); \ | 111 | typeof(x) _min1 = (x); \ |
diff --git a/tools/perf/util/PERF-VERSION-GEN b/tools/perf/util/PERF-VERSION-GEN index 54552a00a11..49ece792191 100755 --- a/tools/perf/util/PERF-VERSION-GEN +++ b/tools/perf/util/PERF-VERSION-GEN | |||
@@ -1,6 +1,10 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | GVF=PERF-VERSION-FILE | 3 | if [ $# -eq 1 ] ; then |
4 | OUTPUT=$1 | ||
5 | fi | ||
6 | |||
7 | GVF=${OUTPUT}PERF-VERSION-FILE | ||
4 | DEF_VER=v0.0.2.PERF | 8 | DEF_VER=v0.0.2.PERF |
5 | 9 | ||
6 | LF=' | 10 | LF=' |
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 918eb376abe..4b9aab7f040 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef __PERF_CACHE_H | 1 | #ifndef __PERF_CACHE_H |
2 | #define __PERF_CACHE_H | 2 | #define __PERF_CACHE_H |
3 | 3 | ||
4 | #include <stdbool.h> | ||
4 | #include "util.h" | 5 | #include "util.h" |
5 | #include "strbuf.h" | 6 | #include "strbuf.h" |
6 | #include "../perf.h" | 7 | #include "../perf.h" |
@@ -69,6 +70,19 @@ extern const char *pager_program; | |||
69 | extern int pager_in_use(void); | 70 | extern int pager_in_use(void); |
70 | extern int pager_use_color; | 71 | extern int pager_use_color; |
71 | 72 | ||
73 | extern bool use_browser; | ||
74 | |||
75 | #ifdef NO_NEWT_SUPPORT | ||
76 | static inline void setup_browser(void) | ||
77 | { | ||
78 | setup_pager(); | ||
79 | } | ||
80 | static inline void exit_browser(bool wait_for_ok __used) {} | ||
81 | #else | ||
82 | void setup_browser(void); | ||
83 | void exit_browser(bool wait_for_ok); | ||
84 | #endif | ||
85 | |||
72 | extern const char *editor_program; | 86 | extern const char *editor_program; |
73 | extern const char *excludes_file; | 87 | extern const char *excludes_file; |
74 | 88 | ||
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index b3b71258272..db628af6d20 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2009, Frederic Weisbecker <fweisbec@gmail.com> | 2 | * Copyright (C) 2009-2010, Frederic Weisbecker <fweisbec@gmail.com> |
3 | * | 3 | * |
4 | * Handle the callchains from the stream in an ad-hoc radix tree and then | 4 | * Handle the callchains from the stream in an ad-hoc radix tree and then |
5 | * sort them in an rbtree. | 5 | * sort them in an rbtree. |
@@ -183,12 +183,23 @@ create_child(struct callchain_node *parent, bool inherit_children) | |||
183 | return new; | 183 | return new; |
184 | } | 184 | } |
185 | 185 | ||
186 | |||
187 | struct resolved_ip { | ||
188 | u64 ip; | ||
189 | struct map_symbol ms; | ||
190 | }; | ||
191 | |||
192 | struct resolved_chain { | ||
193 | u64 nr; | ||
194 | struct resolved_ip ips[0]; | ||
195 | }; | ||
196 | |||
197 | |||
186 | /* | 198 | /* |
187 | * Fill the node with callchain values | 199 | * Fill the node with callchain values |
188 | */ | 200 | */ |
189 | static void | 201 | static void |
190 | fill_node(struct callchain_node *node, struct ip_callchain *chain, | 202 | fill_node(struct callchain_node *node, struct resolved_chain *chain, int start) |
191 | int start, struct symbol **syms) | ||
192 | { | 203 | { |
193 | unsigned int i; | 204 | unsigned int i; |
194 | 205 | ||
@@ -200,8 +211,8 @@ fill_node(struct callchain_node *node, struct ip_callchain *chain, | |||
200 | perror("not enough memory for the code path tree"); | 211 | perror("not enough memory for the code path tree"); |
201 | return; | 212 | return; |
202 | } | 213 | } |
203 | call->ip = chain->ips[i]; | 214 | call->ip = chain->ips[i].ip; |
204 | call->sym = syms[i]; | 215 | call->ms = chain->ips[i].ms; |
205 | list_add_tail(&call->list, &node->val); | 216 | list_add_tail(&call->list, &node->val); |
206 | } | 217 | } |
207 | node->val_nr = chain->nr - start; | 218 | node->val_nr = chain->nr - start; |
@@ -210,13 +221,13 @@ fill_node(struct callchain_node *node, struct ip_callchain *chain, | |||
210 | } | 221 | } |
211 | 222 | ||
212 | static void | 223 | static void |
213 | add_child(struct callchain_node *parent, struct ip_callchain *chain, | 224 | add_child(struct callchain_node *parent, struct resolved_chain *chain, |
214 | int start, struct symbol **syms) | 225 | int start) |
215 | { | 226 | { |
216 | struct callchain_node *new; | 227 | struct callchain_node *new; |
217 | 228 | ||
218 | new = create_child(parent, false); | 229 | new = create_child(parent, false); |
219 | fill_node(new, chain, start, syms); | 230 | fill_node(new, chain, start); |
220 | 231 | ||
221 | new->children_hit = 0; | 232 | new->children_hit = 0; |
222 | new->hit = 1; | 233 | new->hit = 1; |
@@ -228,9 +239,8 @@ add_child(struct callchain_node *parent, struct ip_callchain *chain, | |||
228 | * Then create another child to host the given callchain of new branch | 239 | * Then create another child to host the given callchain of new branch |
229 | */ | 240 | */ |
230 | static void | 241 | static void |
231 | split_add_child(struct callchain_node *parent, struct ip_callchain *chain, | 242 | split_add_child(struct callchain_node *parent, struct resolved_chain *chain, |
232 | struct callchain_list *to_split, int idx_parents, int idx_local, | 243 | struct callchain_list *to_split, int idx_parents, int idx_local) |
233 | struct symbol **syms) | ||
234 | { | 244 | { |
235 | struct callchain_node *new; | 245 | struct callchain_node *new; |
236 | struct list_head *old_tail; | 246 | struct list_head *old_tail; |
@@ -257,7 +267,7 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain, | |||
257 | /* create a new child for the new branch if any */ | 267 | /* create a new child for the new branch if any */ |
258 | if (idx_total < chain->nr) { | 268 | if (idx_total < chain->nr) { |
259 | parent->hit = 0; | 269 | parent->hit = 0; |
260 | add_child(parent, chain, idx_total, syms); | 270 | add_child(parent, chain, idx_total); |
261 | parent->children_hit++; | 271 | parent->children_hit++; |
262 | } else { | 272 | } else { |
263 | parent->hit = 1; | 273 | parent->hit = 1; |
@@ -265,32 +275,33 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain, | |||
265 | } | 275 | } |
266 | 276 | ||
267 | static int | 277 | static int |
268 | __append_chain(struct callchain_node *root, struct ip_callchain *chain, | 278 | __append_chain(struct callchain_node *root, struct resolved_chain *chain, |
269 | unsigned int start, struct symbol **syms); | 279 | unsigned int start); |
270 | 280 | ||
271 | static void | 281 | static void |
272 | __append_chain_children(struct callchain_node *root, struct ip_callchain *chain, | 282 | __append_chain_children(struct callchain_node *root, |
273 | struct symbol **syms, unsigned int start) | 283 | struct resolved_chain *chain, |
284 | unsigned int start) | ||
274 | { | 285 | { |
275 | struct callchain_node *rnode; | 286 | struct callchain_node *rnode; |
276 | 287 | ||
277 | /* lookup in childrens */ | 288 | /* lookup in childrens */ |
278 | chain_for_each_child(rnode, root) { | 289 | chain_for_each_child(rnode, root) { |
279 | unsigned int ret = __append_chain(rnode, chain, start, syms); | 290 | unsigned int ret = __append_chain(rnode, chain, start); |
280 | 291 | ||
281 | if (!ret) | 292 | if (!ret) |
282 | goto inc_children_hit; | 293 | goto inc_children_hit; |
283 | } | 294 | } |
284 | /* nothing in children, add to the current node */ | 295 | /* nothing in children, add to the current node */ |
285 | add_child(root, chain, start, syms); | 296 | add_child(root, chain, start); |
286 | 297 | ||
287 | inc_children_hit: | 298 | inc_children_hit: |
288 | root->children_hit++; | 299 | root->children_hit++; |
289 | } | 300 | } |
290 | 301 | ||
291 | static int | 302 | static int |
292 | __append_chain(struct callchain_node *root, struct ip_callchain *chain, | 303 | __append_chain(struct callchain_node *root, struct resolved_chain *chain, |
293 | unsigned int start, struct symbol **syms) | 304 | unsigned int start) |
294 | { | 305 | { |
295 | struct callchain_list *cnode; | 306 | struct callchain_list *cnode; |
296 | unsigned int i = start; | 307 | unsigned int i = start; |
@@ -302,13 +313,19 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain, | |||
302 | * anywhere inside a function. | 313 | * anywhere inside a function. |
303 | */ | 314 | */ |
304 | list_for_each_entry(cnode, &root->val, list) { | 315 | list_for_each_entry(cnode, &root->val, list) { |
316 | struct symbol *sym; | ||
317 | |||
305 | if (i == chain->nr) | 318 | if (i == chain->nr) |
306 | break; | 319 | break; |
307 | if (cnode->sym && syms[i]) { | 320 | |
308 | if (cnode->sym->start != syms[i]->start) | 321 | sym = chain->ips[i].ms.sym; |
322 | |||
323 | if (cnode->ms.sym && sym) { | ||
324 | if (cnode->ms.sym->start != sym->start) | ||
309 | break; | 325 | break; |
310 | } else if (cnode->ip != chain->ips[i]) | 326 | } else if (cnode->ip != chain->ips[i].ip) |
311 | break; | 327 | break; |
328 | |||
312 | if (!found) | 329 | if (!found) |
313 | found = true; | 330 | found = true; |
314 | i++; | 331 | i++; |
@@ -320,7 +337,7 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain, | |||
320 | 337 | ||
321 | /* we match only a part of the node. Split it and add the new chain */ | 338 | /* we match only a part of the node. Split it and add the new chain */ |
322 | if (i - start < root->val_nr) { | 339 | if (i - start < root->val_nr) { |
323 | split_add_child(root, chain, cnode, start, i - start, syms); | 340 | split_add_child(root, chain, cnode, start, i - start); |
324 | return 0; | 341 | return 0; |
325 | } | 342 | } |
326 | 343 | ||
@@ -331,15 +348,50 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain, | |||
331 | } | 348 | } |
332 | 349 | ||
333 | /* We match the node and still have a part remaining */ | 350 | /* We match the node and still have a part remaining */ |
334 | __append_chain_children(root, chain, syms, i); | 351 | __append_chain_children(root, chain, i); |
335 | 352 | ||
336 | return 0; | 353 | return 0; |
337 | } | 354 | } |
338 | 355 | ||
339 | void append_chain(struct callchain_node *root, struct ip_callchain *chain, | 356 | static void filter_context(struct ip_callchain *old, struct resolved_chain *new, |
340 | struct symbol **syms) | 357 | struct map_symbol *syms) |
358 | { | ||
359 | int i, j = 0; | ||
360 | |||
361 | for (i = 0; i < (int)old->nr; i++) { | ||
362 | if (old->ips[i] >= PERF_CONTEXT_MAX) | ||
363 | continue; | ||
364 | |||
365 | new->ips[j].ip = old->ips[i]; | ||
366 | new->ips[j].ms = syms[i]; | ||
367 | j++; | ||
368 | } | ||
369 | |||
370 | new->nr = j; | ||
371 | } | ||
372 | |||
373 | |||
374 | int append_chain(struct callchain_node *root, struct ip_callchain *chain, | ||
375 | struct map_symbol *syms) | ||
341 | { | 376 | { |
377 | struct resolved_chain *filtered; | ||
378 | |||
342 | if (!chain->nr) | 379 | if (!chain->nr) |
343 | return; | 380 | return 0; |
344 | __append_chain_children(root, chain, syms, 0); | 381 | |
382 | filtered = malloc(sizeof(*filtered) + | ||
383 | chain->nr * sizeof(struct resolved_ip)); | ||
384 | if (!filtered) | ||
385 | return -ENOMEM; | ||
386 | |||
387 | filter_context(chain, filtered, syms); | ||
388 | |||
389 | if (!filtered->nr) | ||
390 | goto end; | ||
391 | |||
392 | __append_chain_children(root, filtered, 0); | ||
393 | end: | ||
394 | free(filtered); | ||
395 | |||
396 | return 0; | ||
345 | } | 397 | } |
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index ad4626de4c2..8a7e8bbd0fd 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
@@ -39,7 +39,7 @@ struct callchain_param { | |||
39 | 39 | ||
40 | struct callchain_list { | 40 | struct callchain_list { |
41 | u64 ip; | 41 | u64 ip; |
42 | struct symbol *sym; | 42 | struct map_symbol ms; |
43 | struct list_head list; | 43 | struct list_head list; |
44 | }; | 44 | }; |
45 | 45 | ||
@@ -56,6 +56,6 @@ static inline u64 cumul_hits(struct callchain_node *node) | |||
56 | } | 56 | } |
57 | 57 | ||
58 | int register_callchain_param(struct callchain_param *param); | 58 | int register_callchain_param(struct callchain_param *param); |
59 | void append_chain(struct callchain_node *root, struct ip_callchain *chain, | 59 | int append_chain(struct callchain_node *root, struct ip_callchain *chain, |
60 | struct symbol **syms); | 60 | struct map_symbol *syms); |
61 | #endif /* __PERF_CALLCHAIN_H */ | 61 | #endif /* __PERF_CALLCHAIN_H */ |
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c index e88bca55a59..e191eb9a667 100644 --- a/tools/perf/util/color.c +++ b/tools/perf/util/color.c | |||
@@ -166,6 +166,31 @@ int perf_color_default_config(const char *var, const char *value, void *cb) | |||
166 | return perf_default_config(var, value, cb); | 166 | return perf_default_config(var, value, cb); |
167 | } | 167 | } |
168 | 168 | ||
169 | static int __color_vsnprintf(char *bf, size_t size, const char *color, | ||
170 | const char *fmt, va_list args, const char *trail) | ||
171 | { | ||
172 | int r = 0; | ||
173 | |||
174 | /* | ||
175 | * Auto-detect: | ||
176 | */ | ||
177 | if (perf_use_color_default < 0) { | ||
178 | if (isatty(1) || pager_in_use()) | ||
179 | perf_use_color_default = 1; | ||
180 | else | ||
181 | perf_use_color_default = 0; | ||
182 | } | ||
183 | |||
184 | if (perf_use_color_default && *color) | ||
185 | r += snprintf(bf, size, "%s", color); | ||
186 | r += vsnprintf(bf + r, size - r, fmt, args); | ||
187 | if (perf_use_color_default && *color) | ||
188 | r += snprintf(bf + r, size - r, "%s", PERF_COLOR_RESET); | ||
189 | if (trail) | ||
190 | r += snprintf(bf + r, size - r, "%s", trail); | ||
191 | return r; | ||
192 | } | ||
193 | |||
169 | static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, | 194 | static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, |
170 | va_list args, const char *trail) | 195 | va_list args, const char *trail) |
171 | { | 196 | { |
@@ -191,11 +216,28 @@ static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, | |||
191 | return r; | 216 | return r; |
192 | } | 217 | } |
193 | 218 | ||
219 | int color_vsnprintf(char *bf, size_t size, const char *color, | ||
220 | const char *fmt, va_list args) | ||
221 | { | ||
222 | return __color_vsnprintf(bf, size, color, fmt, args, NULL); | ||
223 | } | ||
224 | |||
194 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args) | 225 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args) |
195 | { | 226 | { |
196 | return __color_vfprintf(fp, color, fmt, args, NULL); | 227 | return __color_vfprintf(fp, color, fmt, args, NULL); |
197 | } | 228 | } |
198 | 229 | ||
230 | int color_snprintf(char *bf, size_t size, const char *color, | ||
231 | const char *fmt, ...) | ||
232 | { | ||
233 | va_list args; | ||
234 | int r; | ||
235 | |||
236 | va_start(args, fmt); | ||
237 | r = color_vsnprintf(bf, size, color, fmt, args); | ||
238 | va_end(args); | ||
239 | return r; | ||
240 | } | ||
199 | 241 | ||
200 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) | 242 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) |
201 | { | 243 | { |
@@ -274,3 +316,9 @@ int percent_color_fprintf(FILE *fp, const char *fmt, double percent) | |||
274 | 316 | ||
275 | return r; | 317 | return r; |
276 | } | 318 | } |
319 | |||
320 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent) | ||
321 | { | ||
322 | const char *color = get_percent_color(percent); | ||
323 | return color_snprintf(bf, size, color, fmt, percent); | ||
324 | } | ||
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h index 24e8809210b..dea082b7960 100644 --- a/tools/perf/util/color.h +++ b/tools/perf/util/color.h | |||
@@ -32,10 +32,14 @@ int perf_color_default_config(const char *var, const char *value, void *cb); | |||
32 | int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty); | 32 | int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty); |
33 | void color_parse(const char *value, const char *var, char *dst); | 33 | void color_parse(const char *value, const char *var, char *dst); |
34 | void color_parse_mem(const char *value, int len, const char *var, char *dst); | 34 | void color_parse_mem(const char *value, int len, const char *var, char *dst); |
35 | int color_vsnprintf(char *bf, size_t size, const char *color, | ||
36 | const char *fmt, va_list args); | ||
35 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args); | 37 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args); |
36 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); | 38 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); |
39 | int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...); | ||
37 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); | 40 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); |
38 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); | 41 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); |
42 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent); | ||
39 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); | 43 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); |
40 | const char *get_percent_color(double percent); | 44 | const char *get_percent_color(double percent); |
41 | 45 | ||
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 0905600c385..033d66db863 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <stdarg.h> | 6 | #include <stdarg.h> |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | 8 | ||
9 | #include "cache.h" | ||
9 | #include "color.h" | 10 | #include "color.h" |
10 | #include "event.h" | 11 | #include "event.h" |
11 | #include "debug.h" | 12 | #include "debug.h" |
@@ -21,7 +22,10 @@ int eprintf(int level, const char *fmt, ...) | |||
21 | 22 | ||
22 | if (verbose >= level) { | 23 | if (verbose >= level) { |
23 | va_start(args, fmt); | 24 | va_start(args, fmt); |
24 | ret = vfprintf(stderr, fmt, args); | 25 | if (use_browser) |
26 | ret = browser__show_help(fmt, args); | ||
27 | else | ||
28 | ret = vfprintf(stderr, fmt, args); | ||
25 | va_end(args); | 29 | va_end(args); |
26 | } | 30 | } |
27 | 31 | ||
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index c6c24c522de..5cb0a1b1401 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
@@ -7,9 +7,32 @@ | |||
7 | extern int verbose; | 7 | extern int verbose; |
8 | extern int dump_trace; | 8 | extern int dump_trace; |
9 | 9 | ||
10 | int eprintf(int level, | ||
11 | const char *fmt, ...) __attribute__((format(printf, 2, 3))); | ||
12 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); | 10 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); |
13 | void trace_event(event_t *event); | 11 | void trace_event(event_t *event); |
14 | 12 | ||
13 | struct ui_progress; | ||
14 | |||
15 | #ifdef NO_NEWT_SUPPORT | ||
16 | static inline int browser__show_help(const char *format __used, va_list ap __used) | ||
17 | { | ||
18 | return 0; | ||
19 | } | ||
20 | |||
21 | static inline struct ui_progress *ui_progress__new(const char *title __used, | ||
22 | u64 total __used) | ||
23 | { | ||
24 | return (struct ui_progress *)1; | ||
25 | } | ||
26 | |||
27 | static inline void ui_progress__update(struct ui_progress *self __used, | ||
28 | u64 curr __used) {} | ||
29 | |||
30 | static inline void ui_progress__delete(struct ui_progress *self __used) {} | ||
31 | #else | ||
32 | int browser__show_help(const char *format, va_list ap); | ||
33 | struct ui_progress *ui_progress__new(const char *title, u64 total); | ||
34 | void ui_progress__update(struct ui_progress *self, u64 curr); | ||
35 | void ui_progress__delete(struct ui_progress *self); | ||
36 | #endif | ||
37 | |||
15 | #endif /* __PERF_DEBUG_H */ | 38 | #endif /* __PERF_DEBUG_H */ |
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 705ec63548b..571fb25f7eb 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -130,6 +130,7 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, | |||
130 | continue; | 130 | continue; |
131 | pbf += n + 3; | 131 | pbf += n + 3; |
132 | if (*pbf == 'x') { /* vm_exec */ | 132 | if (*pbf == 'x') { /* vm_exec */ |
133 | u64 vm_pgoff; | ||
133 | char *execname = strchr(bf, '/'); | 134 | char *execname = strchr(bf, '/'); |
134 | 135 | ||
135 | /* Catch VDSO */ | 136 | /* Catch VDSO */ |
@@ -139,6 +140,14 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, | |||
139 | if (execname == NULL) | 140 | if (execname == NULL) |
140 | continue; | 141 | continue; |
141 | 142 | ||
143 | pbf += 3; | ||
144 | n = hex2u64(pbf, &vm_pgoff); | ||
145 | /* pgoff is in bytes, not pages */ | ||
146 | if (n >= 0) | ||
147 | ev.mmap.pgoff = vm_pgoff << getpagesize(); | ||
148 | else | ||
149 | ev.mmap.pgoff = 0; | ||
150 | |||
142 | size = strlen(execname); | 151 | size = strlen(execname); |
143 | execname[size - 1] = '\0'; /* Remove \n */ | 152 | execname[size - 1] = '\0'; /* Remove \n */ |
144 | memcpy(ev.mmap.filename, execname, size); | 153 | memcpy(ev.mmap.filename, execname, size); |
@@ -393,7 +402,8 @@ int event__process_mmap(event_t *self, struct perf_session *session) | |||
393 | } | 402 | } |
394 | 403 | ||
395 | thread = perf_session__findnew(session, self->mmap.pid); | 404 | thread = perf_session__findnew(session, self->mmap.pid); |
396 | map = map__new(&self->mmap, MAP__FUNCTION, | 405 | map = map__new(self->mmap.start, self->mmap.len, self->mmap.pgoff, |
406 | self->mmap.pid, self->mmap.filename, MAP__FUNCTION, | ||
397 | session->cwd, session->cwdlen); | 407 | session->cwd, session->cwdlen); |
398 | 408 | ||
399 | if (thread == NULL || map == NULL) | 409 | if (thread == NULL || map == NULL) |
@@ -513,24 +523,32 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session, | |||
513 | 523 | ||
514 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); | 524 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
515 | 525 | ||
516 | thread__find_addr_location(thread, session, cpumode, MAP__FUNCTION, | 526 | thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, |
517 | self->ip.ip, al, filter); | 527 | self->ip.ip, al); |
518 | dump_printf(" ...... dso: %s\n", | 528 | dump_printf(" ...... dso: %s\n", |
519 | al->map ? al->map->dso->long_name : | 529 | al->map ? al->map->dso->long_name : |
520 | al->level == 'H' ? "[hypervisor]" : "<not found>"); | 530 | al->level == 'H' ? "[hypervisor]" : "<not found>"); |
521 | /* | 531 | al->sym = NULL; |
522 | * We have to do this here as we may have a dso with no symbol hit that | 532 | |
523 | * has a name longer than the ones with symbols sampled. | 533 | if (al->map) { |
524 | */ | 534 | if (symbol_conf.dso_list && |
525 | if (al->map && !sort_dso.elide && !al->map->dso->slen_calculated) | 535 | (!al->map || !al->map->dso || |
526 | dso__calc_col_width(al->map->dso); | 536 | !(strlist__has_entry(symbol_conf.dso_list, |
527 | 537 | al->map->dso->short_name) || | |
528 | if (symbol_conf.dso_list && | 538 | (al->map->dso->short_name != al->map->dso->long_name && |
529 | (!al->map || !al->map->dso || | 539 | strlist__has_entry(symbol_conf.dso_list, |
530 | !(strlist__has_entry(symbol_conf.dso_list, al->map->dso->short_name) || | 540 | al->map->dso->long_name))))) |
531 | (al->map->dso->short_name != al->map->dso->long_name && | 541 | goto out_filtered; |
532 | strlist__has_entry(symbol_conf.dso_list, al->map->dso->long_name))))) | 542 | /* |
533 | goto out_filtered; | 543 | * We have to do this here as we may have a dso with no symbol |
544 | * hit that has a name longer than the ones with symbols | ||
545 | * sampled. | ||
546 | */ | ||
547 | if (!sort_dso.elide && !al->map->dso->slen_calculated) | ||
548 | dso__calc_col_width(al->map->dso); | ||
549 | |||
550 | al->sym = map__find_symbol(al->map, al->addr, filter); | ||
551 | } | ||
534 | 552 | ||
535 | if (symbol_conf.sym_list && al->sym && | 553 | if (symbol_conf.sym_list && al->sym && |
536 | !strlist__has_entry(symbol_conf.sym_list, al->sym->name)) | 554 | !strlist__has_entry(symbol_conf.sym_list, al->sym->name)) |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 2be33c7dbf0..18cf8b32160 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -22,8 +22,10 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, | |||
22 | struct hist_entry *he; | 22 | struct hist_entry *he; |
23 | struct hist_entry entry = { | 23 | struct hist_entry entry = { |
24 | .thread = al->thread, | 24 | .thread = al->thread, |
25 | .map = al->map, | 25 | .ms = { |
26 | .sym = al->sym, | 26 | .map = al->map, |
27 | .sym = al->sym, | ||
28 | }, | ||
27 | .ip = al->addr, | 29 | .ip = al->addr, |
28 | .level = al->level, | 30 | .level = al->level, |
29 | .count = count, | 31 | .count = count, |
@@ -48,7 +50,8 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, | |||
48 | p = &(*p)->rb_right; | 50 | p = &(*p)->rb_right; |
49 | } | 51 | } |
50 | 52 | ||
51 | he = malloc(sizeof(*he)); | 53 | he = malloc(sizeof(*he) + (symbol_conf.use_callchain ? |
54 | sizeof(struct callchain_node) : 0)); | ||
52 | if (!he) | 55 | if (!he) |
53 | return NULL; | 56 | return NULL; |
54 | *he = entry; | 57 | *he = entry; |
@@ -166,7 +169,7 @@ static void perf_session__insert_output_hist_entry(struct rb_root *root, | |||
166 | struct hist_entry *iter; | 169 | struct hist_entry *iter; |
167 | 170 | ||
168 | if (symbol_conf.use_callchain) | 171 | if (symbol_conf.use_callchain) |
169 | callchain_param.sort(&he->sorted_chain, &he->callchain, | 172 | callchain_param.sort(&he->sorted_chain, he->callchain, |
170 | min_callchain_hits, &callchain_param); | 173 | min_callchain_hits, &callchain_param); |
171 | 174 | ||
172 | while (*p != NULL) { | 175 | while (*p != NULL) { |
@@ -183,12 +186,13 @@ static void perf_session__insert_output_hist_entry(struct rb_root *root, | |||
183 | rb_insert_color(&he->rb_node, root); | 186 | rb_insert_color(&he->rb_node, root); |
184 | } | 187 | } |
185 | 188 | ||
186 | void perf_session__output_resort(struct rb_root *hists, u64 total_samples) | 189 | u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples) |
187 | { | 190 | { |
188 | struct rb_root tmp; | 191 | struct rb_root tmp; |
189 | struct rb_node *next; | 192 | struct rb_node *next; |
190 | struct hist_entry *n; | 193 | struct hist_entry *n; |
191 | u64 min_callchain_hits; | 194 | u64 min_callchain_hits; |
195 | u64 nr_hists = 0; | ||
192 | 196 | ||
193 | min_callchain_hits = | 197 | min_callchain_hits = |
194 | total_samples * (callchain_param.min_percent / 100); | 198 | total_samples * (callchain_param.min_percent / 100); |
@@ -203,9 +207,11 @@ void perf_session__output_resort(struct rb_root *hists, u64 total_samples) | |||
203 | rb_erase(&n->rb_node, hists); | 207 | rb_erase(&n->rb_node, hists); |
204 | perf_session__insert_output_hist_entry(&tmp, n, | 208 | perf_session__insert_output_hist_entry(&tmp, n, |
205 | min_callchain_hits); | 209 | min_callchain_hits); |
210 | ++nr_hists; | ||
206 | } | 211 | } |
207 | 212 | ||
208 | *hists = tmp; | 213 | *hists = tmp; |
214 | return nr_hists; | ||
209 | } | 215 | } |
210 | 216 | ||
211 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) | 217 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) |
@@ -258,8 +264,8 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | |||
258 | } else | 264 | } else |
259 | ret += fprintf(fp, "%s", " "); | 265 | ret += fprintf(fp, "%s", " "); |
260 | } | 266 | } |
261 | if (chain->sym) | 267 | if (chain->ms.sym) |
262 | ret += fprintf(fp, "%s\n", chain->sym->name); | 268 | ret += fprintf(fp, "%s\n", chain->ms.sym->name); |
263 | else | 269 | else |
264 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); | 270 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); |
265 | 271 | ||
@@ -278,7 +284,7 @@ static void init_rem_hits(void) | |||
278 | } | 284 | } |
279 | 285 | ||
280 | strcpy(rem_sq_bracket->name, "[...]"); | 286 | strcpy(rem_sq_bracket->name, "[...]"); |
281 | rem_hits.sym = rem_sq_bracket; | 287 | rem_hits.ms.sym = rem_sq_bracket; |
282 | } | 288 | } |
283 | 289 | ||
284 | static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | 290 | static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
@@ -328,8 +334,6 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |||
328 | left_margin); | 334 | left_margin); |
329 | i = 0; | 335 | i = 0; |
330 | list_for_each_entry(chain, &child->val, list) { | 336 | list_for_each_entry(chain, &child->val, list) { |
331 | if (chain->ip >= PERF_CONTEXT_MAX) | ||
332 | continue; | ||
333 | ret += ipchain__fprintf_graph(fp, chain, depth, | 337 | ret += ipchain__fprintf_graph(fp, chain, depth, |
334 | new_depth_mask, i++, | 338 | new_depth_mask, i++, |
335 | new_total, | 339 | new_total, |
@@ -368,9 +372,6 @@ static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |||
368 | int ret = 0; | 372 | int ret = 0; |
369 | 373 | ||
370 | list_for_each_entry(chain, &self->val, list) { | 374 | list_for_each_entry(chain, &self->val, list) { |
371 | if (chain->ip >= PERF_CONTEXT_MAX) | ||
372 | continue; | ||
373 | |||
374 | if (!i++ && sort__first_dimension == SORT_SYM) | 375 | if (!i++ && sort__first_dimension == SORT_SYM) |
375 | continue; | 376 | continue; |
376 | 377 | ||
@@ -385,8 +386,8 @@ static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |||
385 | } else | 386 | } else |
386 | ret += callchain__fprintf_left_margin(fp, left_margin); | 387 | ret += callchain__fprintf_left_margin(fp, left_margin); |
387 | 388 | ||
388 | if (chain->sym) | 389 | if (chain->ms.sym) |
389 | ret += fprintf(fp, " %s\n", chain->sym->name); | 390 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
390 | else | 391 | else |
391 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); | 392 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
392 | } | 393 | } |
@@ -411,8 +412,8 @@ static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self, | |||
411 | list_for_each_entry(chain, &self->val, list) { | 412 | list_for_each_entry(chain, &self->val, list) { |
412 | if (chain->ip >= PERF_CONTEXT_MAX) | 413 | if (chain->ip >= PERF_CONTEXT_MAX) |
413 | continue; | 414 | continue; |
414 | if (chain->sym) | 415 | if (chain->ms.sym) |
415 | ret += fprintf(fp, " %s\n", chain->sym->name); | 416 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
416 | else | 417 | else |
417 | ret += fprintf(fp, " %p\n", | 418 | ret += fprintf(fp, " %p\n", |
418 | (void *)(long)chain->ip); | 419 | (void *)(long)chain->ip); |
@@ -455,16 +456,17 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, | |||
455 | return ret; | 456 | return ret; |
456 | } | 457 | } |
457 | 458 | ||
458 | static size_t hist_entry__fprintf(struct hist_entry *self, | 459 | int hist_entry__snprintf(struct hist_entry *self, |
459 | struct perf_session *pair_session, | 460 | char *s, size_t size, |
460 | bool show_displacement, | 461 | struct perf_session *pair_session, |
461 | long displacement, FILE *fp, | 462 | bool show_displacement, |
462 | u64 session_total) | 463 | long displacement, bool color, |
464 | u64 session_total) | ||
463 | { | 465 | { |
464 | struct sort_entry *se; | 466 | struct sort_entry *se; |
465 | u64 count, total; | 467 | u64 count, total; |
466 | const char *sep = symbol_conf.field_sep; | 468 | const char *sep = symbol_conf.field_sep; |
467 | size_t ret; | 469 | int ret; |
468 | 470 | ||
469 | if (symbol_conf.exclude_other && !self->parent) | 471 | if (symbol_conf.exclude_other && !self->parent) |
470 | return 0; | 472 | return 0; |
@@ -477,17 +479,22 @@ static size_t hist_entry__fprintf(struct hist_entry *self, | |||
477 | total = session_total; | 479 | total = session_total; |
478 | } | 480 | } |
479 | 481 | ||
480 | if (total) | 482 | if (total) { |
481 | ret = percent_color_fprintf(fp, sep ? "%.2f" : " %6.2f%%", | 483 | if (color) |
482 | (count * 100.0) / total); | 484 | ret = percent_color_snprintf(s, size, |
483 | else | 485 | sep ? "%.2f" : " %6.2f%%", |
484 | ret = fprintf(fp, sep ? "%lld" : "%12lld ", count); | 486 | (count * 100.0) / total); |
487 | else | ||
488 | ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%", | ||
489 | (count * 100.0) / total); | ||
490 | } else | ||
491 | ret = snprintf(s, size, sep ? "%lld" : "%12lld ", count); | ||
485 | 492 | ||
486 | if (symbol_conf.show_nr_samples) { | 493 | if (symbol_conf.show_nr_samples) { |
487 | if (sep) | 494 | if (sep) |
488 | fprintf(fp, "%c%lld", *sep, count); | 495 | ret += snprintf(s + ret, size - ret, "%c%lld", *sep, count); |
489 | else | 496 | else |
490 | fprintf(fp, "%11lld", count); | 497 | ret += snprintf(s + ret, size - ret, "%11lld", count); |
491 | } | 498 | } |
492 | 499 | ||
493 | if (pair_session) { | 500 | if (pair_session) { |
@@ -507,9 +514,9 @@ static size_t hist_entry__fprintf(struct hist_entry *self, | |||
507 | snprintf(bf, sizeof(bf), " "); | 514 | snprintf(bf, sizeof(bf), " "); |
508 | 515 | ||
509 | if (sep) | 516 | if (sep) |
510 | ret += fprintf(fp, "%c%s", *sep, bf); | 517 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); |
511 | else | 518 | else |
512 | ret += fprintf(fp, "%11.11s", bf); | 519 | ret += snprintf(s + ret, size - ret, "%11.11s", bf); |
513 | 520 | ||
514 | if (show_displacement) { | 521 | if (show_displacement) { |
515 | if (displacement) | 522 | if (displacement) |
@@ -518,9 +525,9 @@ static size_t hist_entry__fprintf(struct hist_entry *self, | |||
518 | snprintf(bf, sizeof(bf), " "); | 525 | snprintf(bf, sizeof(bf), " "); |
519 | 526 | ||
520 | if (sep) | 527 | if (sep) |
521 | fprintf(fp, "%c%s", *sep, bf); | 528 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); |
522 | else | 529 | else |
523 | fprintf(fp, "%6.6s", bf); | 530 | ret += snprintf(s + ret, size - ret, "%6.6s", bf); |
524 | } | 531 | } |
525 | } | 532 | } |
526 | 533 | ||
@@ -528,27 +535,41 @@ static size_t hist_entry__fprintf(struct hist_entry *self, | |||
528 | if (se->elide) | 535 | if (se->elide) |
529 | continue; | 536 | continue; |
530 | 537 | ||
531 | fprintf(fp, "%s", sep ?: " "); | 538 | ret += snprintf(s + ret, size - ret, "%s", sep ?: " "); |
532 | ret += se->print(fp, self, se->width ? *se->width : 0); | 539 | ret += se->snprintf(self, s + ret, size - ret, |
540 | se->width ? *se->width : 0); | ||
533 | } | 541 | } |
534 | 542 | ||
535 | ret += fprintf(fp, "\n"); | 543 | return ret; |
544 | } | ||
536 | 545 | ||
537 | if (symbol_conf.use_callchain) { | 546 | int hist_entry__fprintf(struct hist_entry *self, |
538 | int left_margin = 0; | 547 | struct perf_session *pair_session, |
548 | bool show_displacement, | ||
549 | long displacement, FILE *fp, | ||
550 | u64 session_total) | ||
551 | { | ||
552 | char bf[512]; | ||
553 | hist_entry__snprintf(self, bf, sizeof(bf), pair_session, | ||
554 | show_displacement, displacement, | ||
555 | true, session_total); | ||
556 | return fprintf(fp, "%s\n", bf); | ||
557 | } | ||
539 | 558 | ||
540 | if (sort__first_dimension == SORT_COMM) { | 559 | static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp, |
541 | se = list_first_entry(&hist_entry__sort_list, typeof(*se), | 560 | u64 session_total) |
542 | list); | 561 | { |
543 | left_margin = se->width ? *se->width : 0; | 562 | int left_margin = 0; |
544 | left_margin -= thread__comm_len(self->thread); | ||
545 | } | ||
546 | 563 | ||
547 | hist_entry_callchain__fprintf(fp, self, session_total, | 564 | if (sort__first_dimension == SORT_COMM) { |
548 | left_margin); | 565 | struct sort_entry *se = list_first_entry(&hist_entry__sort_list, |
566 | typeof(*se), list); | ||
567 | left_margin = se->width ? *se->width : 0; | ||
568 | left_margin -= thread__comm_len(self->thread); | ||
549 | } | 569 | } |
550 | 570 | ||
551 | return ret; | 571 | return hist_entry_callchain__fprintf(fp, self, session_total, |
572 | left_margin); | ||
552 | } | 573 | } |
553 | 574 | ||
554 | size_t perf_session__fprintf_hists(struct rb_root *hists, | 575 | size_t perf_session__fprintf_hists(struct rb_root *hists, |
@@ -655,9 +676,13 @@ print_entries: | |||
655 | } | 676 | } |
656 | ret += hist_entry__fprintf(h, pair, show_displacement, | 677 | ret += hist_entry__fprintf(h, pair, show_displacement, |
657 | displacement, fp, session_total); | 678 | displacement, fp, session_total); |
658 | if (h->map == NULL && verbose > 1) { | 679 | |
680 | if (symbol_conf.use_callchain) | ||
681 | ret += hist_entry__fprintf_callchain(h, fp, session_total); | ||
682 | |||
683 | if (h->ms.map == NULL && verbose > 1) { | ||
659 | __map_groups__fprintf_maps(&h->thread->mg, | 684 | __map_groups__fprintf_maps(&h->thread->mg, |
660 | MAP__FUNCTION, fp); | 685 | MAP__FUNCTION, verbose, fp); |
661 | fprintf(fp, "%.10s end\n", graph_dotted_line); | 686 | fprintf(fp, "%.10s end\n", graph_dotted_line); |
662 | } | 687 | } |
663 | } | 688 | } |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 16f360cce5b..ad17f0ad798 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -18,9 +18,19 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, | |||
18 | u64 count, bool *hit); | 18 | u64 count, bool *hit); |
19 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); | 19 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); |
20 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); | 20 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); |
21 | int hist_entry__fprintf(struct hist_entry *self, | ||
22 | struct perf_session *pair_session, | ||
23 | bool show_displacement, | ||
24 | long displacement, FILE *fp, | ||
25 | u64 session_total); | ||
26 | int hist_entry__snprintf(struct hist_entry *self, | ||
27 | char *bf, size_t size, | ||
28 | struct perf_session *pair_session, | ||
29 | bool show_displacement, long displacement, | ||
30 | bool color, u64 session_total); | ||
21 | void hist_entry__free(struct hist_entry *); | 31 | void hist_entry__free(struct hist_entry *); |
22 | 32 | ||
23 | void perf_session__output_resort(struct rb_root *hists, u64 total_samples); | 33 | u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples); |
24 | void perf_session__collapse_resort(struct rb_root *hists); | 34 | void perf_session__collapse_resort(struct rb_root *hists); |
25 | size_t perf_session__fprintf_hists(struct rb_root *hists, | 35 | size_t perf_session__fprintf_hists(struct rb_root *hists, |
26 | struct perf_session *pair, | 36 | struct perf_session *pair, |
diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h index dfb0713ed47..791f9dd27eb 100644 --- a/tools/perf/util/include/linux/compiler.h +++ b/tools/perf/util/include/linux/compiler.h | |||
@@ -7,4 +7,6 @@ | |||
7 | #define __user | 7 | #define __user |
8 | #define __attribute_const__ | 8 | #define __attribute_const__ |
9 | 9 | ||
10 | #define __used __attribute__((__unused__)) | ||
11 | |||
10 | #endif | 12 | #endif |
diff --git a/tools/perf/util/include/linux/kernel.h b/tools/perf/util/include/linux/kernel.h index f2611655ab5..388ab1bfd11 100644 --- a/tools/perf/util/include/linux/kernel.h +++ b/tools/perf/util/include/linux/kernel.h | |||
@@ -85,16 +85,19 @@ simple_strtoul(const char *nptr, char **endptr, int base) | |||
85 | return strtoul(nptr, endptr, base); | 85 | return strtoul(nptr, endptr, base); |
86 | } | 86 | } |
87 | 87 | ||
88 | int eprintf(int level, | ||
89 | const char *fmt, ...) __attribute__((format(printf, 2, 3))); | ||
90 | |||
88 | #ifndef pr_fmt | 91 | #ifndef pr_fmt |
89 | #define pr_fmt(fmt) fmt | 92 | #define pr_fmt(fmt) fmt |
90 | #endif | 93 | #endif |
91 | 94 | ||
92 | #define pr_err(fmt, ...) \ | 95 | #define pr_err(fmt, ...) \ |
93 | do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0) | 96 | eprintf(0, pr_fmt(fmt), ##__VA_ARGS__) |
94 | #define pr_warning(fmt, ...) \ | 97 | #define pr_warning(fmt, ...) \ |
95 | do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0) | 98 | eprintf(0, pr_fmt(fmt), ##__VA_ARGS__) |
96 | #define pr_info(fmt, ...) \ | 99 | #define pr_info(fmt, ...) \ |
97 | do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0) | 100 | eprintf(0, pr_fmt(fmt), ##__VA_ARGS__) |
98 | #define pr_debug(fmt, ...) \ | 101 | #define pr_debug(fmt, ...) \ |
99 | eprintf(1, pr_fmt(fmt), ##__VA_ARGS__) | 102 | eprintf(1, pr_fmt(fmt), ##__VA_ARGS__) |
100 | #define pr_debugN(n, fmt, ...) \ | 103 | #define pr_debugN(n, fmt, ...) \ |
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index e509cd59c67..37913b241bd 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -1,9 +1,10 @@ | |||
1 | #include "event.h" | ||
2 | #include "symbol.h" | 1 | #include "symbol.h" |
2 | #include <errno.h> | ||
3 | #include <limits.h> | ||
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <string.h> | 5 | #include <string.h> |
5 | #include <stdio.h> | 6 | #include <stdio.h> |
6 | #include "debug.h" | 7 | #include "map.h" |
7 | 8 | ||
8 | const char *map_type__name[MAP__NR_TYPES] = { | 9 | const char *map_type__name[MAP__NR_TYPES] = { |
9 | [MAP__FUNCTION] = "Functions", | 10 | [MAP__FUNCTION] = "Functions", |
@@ -38,13 +39,12 @@ void map__init(struct map *self, enum map_type type, | |||
38 | RB_CLEAR_NODE(&self->rb_node); | 39 | RB_CLEAR_NODE(&self->rb_node); |
39 | } | 40 | } |
40 | 41 | ||
41 | struct map *map__new(struct mmap_event *event, enum map_type type, | 42 | struct map *map__new(u64 start, u64 len, u64 pgoff, u32 pid, char *filename, |
42 | char *cwd, int cwdlen) | 43 | enum map_type type, char *cwd, int cwdlen) |
43 | { | 44 | { |
44 | struct map *self = malloc(sizeof(*self)); | 45 | struct map *self = malloc(sizeof(*self)); |
45 | 46 | ||
46 | if (self != NULL) { | 47 | if (self != NULL) { |
47 | const char *filename = event->filename; | ||
48 | char newfilename[PATH_MAX]; | 48 | char newfilename[PATH_MAX]; |
49 | struct dso *dso; | 49 | struct dso *dso; |
50 | int anon; | 50 | int anon; |
@@ -62,7 +62,7 @@ struct map *map__new(struct mmap_event *event, enum map_type type, | |||
62 | anon = is_anon_memory(filename); | 62 | anon = is_anon_memory(filename); |
63 | 63 | ||
64 | if (anon) { | 64 | if (anon) { |
65 | snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", event->pid); | 65 | snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", pid); |
66 | filename = newfilename; | 66 | filename = newfilename; |
67 | } | 67 | } |
68 | 68 | ||
@@ -70,8 +70,7 @@ struct map *map__new(struct mmap_event *event, enum map_type type, | |||
70 | if (dso == NULL) | 70 | if (dso == NULL) |
71 | goto out_delete; | 71 | goto out_delete; |
72 | 72 | ||
73 | map__init(self, type, event->start, event->start + event->len, | 73 | map__init(self, type, start, start + len, pgoff, dso); |
74 | event->pgoff, dso); | ||
75 | 74 | ||
76 | if (anon) { | 75 | if (anon) { |
77 | set_identity: | 76 | set_identity: |
@@ -235,3 +234,277 @@ u64 map__objdump_2ip(struct map *map, u64 addr) | |||
235 | map->unmap_ip(map, addr); /* RIP -> IP */ | 234 | map->unmap_ip(map, addr); /* RIP -> IP */ |
236 | return ip; | 235 | return ip; |
237 | } | 236 | } |
237 | |||
238 | void map_groups__init(struct map_groups *self) | ||
239 | { | ||
240 | int i; | ||
241 | for (i = 0; i < MAP__NR_TYPES; ++i) { | ||
242 | self->maps[i] = RB_ROOT; | ||
243 | INIT_LIST_HEAD(&self->removed_maps[i]); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | void map_groups__flush(struct map_groups *self) | ||
248 | { | ||
249 | int type; | ||
250 | |||
251 | for (type = 0; type < MAP__NR_TYPES; type++) { | ||
252 | struct rb_root *root = &self->maps[type]; | ||
253 | struct rb_node *next = rb_first(root); | ||
254 | |||
255 | while (next) { | ||
256 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
257 | next = rb_next(&pos->rb_node); | ||
258 | rb_erase(&pos->rb_node, root); | ||
259 | /* | ||
260 | * We may have references to this map, for | ||
261 | * instance in some hist_entry instances, so | ||
262 | * just move them to a separate list. | ||
263 | */ | ||
264 | list_add_tail(&pos->node, &self->removed_maps[pos->type]); | ||
265 | } | ||
266 | } | ||
267 | } | ||
268 | |||
269 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
270 | enum map_type type, u64 addr, | ||
271 | struct map **mapp, | ||
272 | symbol_filter_t filter) | ||
273 | { | ||
274 | struct map *map = map_groups__find(self, type, addr); | ||
275 | |||
276 | if (map != NULL) { | ||
277 | if (mapp != NULL) | ||
278 | *mapp = map; | ||
279 | return map__find_symbol(map, map->map_ip(map, addr), filter); | ||
280 | } | ||
281 | |||
282 | return NULL; | ||
283 | } | ||
284 | |||
285 | struct symbol *map_groups__find_symbol_by_name(struct map_groups *self, | ||
286 | enum map_type type, | ||
287 | const char *name, | ||
288 | struct map **mapp, | ||
289 | symbol_filter_t filter) | ||
290 | { | ||
291 | struct rb_node *nd; | ||
292 | |||
293 | for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) { | ||
294 | struct map *pos = rb_entry(nd, struct map, rb_node); | ||
295 | struct symbol *sym = map__find_symbol_by_name(pos, name, filter); | ||
296 | |||
297 | if (sym == NULL) | ||
298 | continue; | ||
299 | if (mapp != NULL) | ||
300 | *mapp = pos; | ||
301 | return sym; | ||
302 | } | ||
303 | |||
304 | return NULL; | ||
305 | } | ||
306 | |||
307 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
308 | enum map_type type, int verbose, FILE *fp) | ||
309 | { | ||
310 | size_t printed = fprintf(fp, "%s:\n", map_type__name[type]); | ||
311 | struct rb_node *nd; | ||
312 | |||
313 | for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) { | ||
314 | struct map *pos = rb_entry(nd, struct map, rb_node); | ||
315 | printed += fprintf(fp, "Map:"); | ||
316 | printed += map__fprintf(pos, fp); | ||
317 | if (verbose > 2) { | ||
318 | printed += dso__fprintf(pos->dso, type, fp); | ||
319 | printed += fprintf(fp, "--\n"); | ||
320 | } | ||
321 | } | ||
322 | |||
323 | return printed; | ||
324 | } | ||
325 | |||
326 | size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp) | ||
327 | { | ||
328 | size_t printed = 0, i; | ||
329 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
330 | printed += __map_groups__fprintf_maps(self, i, verbose, fp); | ||
331 | return printed; | ||
332 | } | ||
333 | |||
334 | static size_t __map_groups__fprintf_removed_maps(struct map_groups *self, | ||
335 | enum map_type type, | ||
336 | int verbose, FILE *fp) | ||
337 | { | ||
338 | struct map *pos; | ||
339 | size_t printed = 0; | ||
340 | |||
341 | list_for_each_entry(pos, &self->removed_maps[type], node) { | ||
342 | printed += fprintf(fp, "Map:"); | ||
343 | printed += map__fprintf(pos, fp); | ||
344 | if (verbose > 1) { | ||
345 | printed += dso__fprintf(pos->dso, type, fp); | ||
346 | printed += fprintf(fp, "--\n"); | ||
347 | } | ||
348 | } | ||
349 | return printed; | ||
350 | } | ||
351 | |||
352 | static size_t map_groups__fprintf_removed_maps(struct map_groups *self, | ||
353 | int verbose, FILE *fp) | ||
354 | { | ||
355 | size_t printed = 0, i; | ||
356 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
357 | printed += __map_groups__fprintf_removed_maps(self, i, verbose, fp); | ||
358 | return printed; | ||
359 | } | ||
360 | |||
361 | size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp) | ||
362 | { | ||
363 | size_t printed = map_groups__fprintf_maps(self, verbose, fp); | ||
364 | printed += fprintf(fp, "Removed maps:\n"); | ||
365 | return printed + map_groups__fprintf_removed_maps(self, verbose, fp); | ||
366 | } | ||
367 | |||
368 | int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, | ||
369 | int verbose, FILE *fp) | ||
370 | { | ||
371 | struct rb_root *root = &self->maps[map->type]; | ||
372 | struct rb_node *next = rb_first(root); | ||
373 | |||
374 | while (next) { | ||
375 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
376 | next = rb_next(&pos->rb_node); | ||
377 | |||
378 | if (!map__overlap(pos, map)) | ||
379 | continue; | ||
380 | |||
381 | if (verbose >= 2) { | ||
382 | fputs("overlapping maps:\n", fp); | ||
383 | map__fprintf(map, fp); | ||
384 | map__fprintf(pos, fp); | ||
385 | } | ||
386 | |||
387 | rb_erase(&pos->rb_node, root); | ||
388 | /* | ||
389 | * We may have references to this map, for instance in some | ||
390 | * hist_entry instances, so just move them to a separate | ||
391 | * list. | ||
392 | */ | ||
393 | list_add_tail(&pos->node, &self->removed_maps[map->type]); | ||
394 | /* | ||
395 | * Now check if we need to create new maps for areas not | ||
396 | * overlapped by the new map: | ||
397 | */ | ||
398 | if (map->start > pos->start) { | ||
399 | struct map *before = map__clone(pos); | ||
400 | |||
401 | if (before == NULL) | ||
402 | return -ENOMEM; | ||
403 | |||
404 | before->end = map->start - 1; | ||
405 | map_groups__insert(self, before); | ||
406 | if (verbose >= 2) | ||
407 | map__fprintf(before, fp); | ||
408 | } | ||
409 | |||
410 | if (map->end < pos->end) { | ||
411 | struct map *after = map__clone(pos); | ||
412 | |||
413 | if (after == NULL) | ||
414 | return -ENOMEM; | ||
415 | |||
416 | after->start = map->end + 1; | ||
417 | map_groups__insert(self, after); | ||
418 | if (verbose >= 2) | ||
419 | map__fprintf(after, fp); | ||
420 | } | ||
421 | } | ||
422 | |||
423 | return 0; | ||
424 | } | ||
425 | |||
426 | /* | ||
427 | * XXX This should not really _copy_ te maps, but refcount them. | ||
428 | */ | ||
429 | int map_groups__clone(struct map_groups *self, | ||
430 | struct map_groups *parent, enum map_type type) | ||
431 | { | ||
432 | struct rb_node *nd; | ||
433 | for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) { | ||
434 | struct map *map = rb_entry(nd, struct map, rb_node); | ||
435 | struct map *new = map__clone(map); | ||
436 | if (new == NULL) | ||
437 | return -ENOMEM; | ||
438 | map_groups__insert(self, new); | ||
439 | } | ||
440 | return 0; | ||
441 | } | ||
442 | |||
443 | static u64 map__reloc_map_ip(struct map *map, u64 ip) | ||
444 | { | ||
445 | return ip + (s64)map->pgoff; | ||
446 | } | ||
447 | |||
448 | static u64 map__reloc_unmap_ip(struct map *map, u64 ip) | ||
449 | { | ||
450 | return ip - (s64)map->pgoff; | ||
451 | } | ||
452 | |||
453 | void map__reloc_vmlinux(struct map *self) | ||
454 | { | ||
455 | struct kmap *kmap = map__kmap(self); | ||
456 | s64 reloc; | ||
457 | |||
458 | if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->unrelocated_addr) | ||
459 | return; | ||
460 | |||
461 | reloc = (kmap->ref_reloc_sym->unrelocated_addr - | ||
462 | kmap->ref_reloc_sym->addr); | ||
463 | |||
464 | if (!reloc) | ||
465 | return; | ||
466 | |||
467 | self->map_ip = map__reloc_map_ip; | ||
468 | self->unmap_ip = map__reloc_unmap_ip; | ||
469 | self->pgoff = reloc; | ||
470 | } | ||
471 | |||
472 | void maps__insert(struct rb_root *maps, struct map *map) | ||
473 | { | ||
474 | struct rb_node **p = &maps->rb_node; | ||
475 | struct rb_node *parent = NULL; | ||
476 | const u64 ip = map->start; | ||
477 | struct map *m; | ||
478 | |||
479 | while (*p != NULL) { | ||
480 | parent = *p; | ||
481 | m = rb_entry(parent, struct map, rb_node); | ||
482 | if (ip < m->start) | ||
483 | p = &(*p)->rb_left; | ||
484 | else | ||
485 | p = &(*p)->rb_right; | ||
486 | } | ||
487 | |||
488 | rb_link_node(&map->rb_node, parent, p); | ||
489 | rb_insert_color(&map->rb_node, maps); | ||
490 | } | ||
491 | |||
492 | struct map *maps__find(struct rb_root *maps, u64 ip) | ||
493 | { | ||
494 | struct rb_node **p = &maps->rb_node; | ||
495 | struct rb_node *parent = NULL; | ||
496 | struct map *m; | ||
497 | |||
498 | while (*p != NULL) { | ||
499 | parent = *p; | ||
500 | m = rb_entry(parent, struct map, rb_node); | ||
501 | if (ip < m->start) | ||
502 | p = &(*p)->rb_left; | ||
503 | else if (ip > m->end) | ||
504 | p = &(*p)->rb_right; | ||
505 | else | ||
506 | return m; | ||
507 | } | ||
508 | |||
509 | return NULL; | ||
510 | } | ||
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index b756368076c..2031278cc06 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -4,7 +4,8 @@ | |||
4 | #include <linux/compiler.h> | 4 | #include <linux/compiler.h> |
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/rbtree.h> | 6 | #include <linux/rbtree.h> |
7 | #include <linux/types.h> | 7 | #include <stdio.h> |
8 | #include "types.h" | ||
8 | 9 | ||
9 | enum map_type { | 10 | enum map_type { |
10 | MAP__FUNCTION = 0, | 11 | MAP__FUNCTION = 0, |
@@ -68,14 +69,13 @@ u64 map__rip_2objdump(struct map *map, u64 rip); | |||
68 | u64 map__objdump_2ip(struct map *map, u64 addr); | 69 | u64 map__objdump_2ip(struct map *map, u64 addr); |
69 | 70 | ||
70 | struct symbol; | 71 | struct symbol; |
71 | struct mmap_event; | ||
72 | 72 | ||
73 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); | 73 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); |
74 | 74 | ||
75 | void map__init(struct map *self, enum map_type type, | 75 | void map__init(struct map *self, enum map_type type, |
76 | u64 start, u64 end, u64 pgoff, struct dso *dso); | 76 | u64 start, u64 end, u64 pgoff, struct dso *dso); |
77 | struct map *map__new(struct mmap_event *event, enum map_type, | 77 | struct map *map__new(u64 start, u64 len, u64 pgoff, u32 pid, char *filename, |
78 | char *cwd, int cwdlen); | 78 | enum map_type type, char *cwd, int cwdlen); |
79 | void map__delete(struct map *self); | 79 | void map__delete(struct map *self); |
80 | struct map *map__clone(struct map *self); | 80 | struct map *map__clone(struct map *self); |
81 | int map__overlap(struct map *l, struct map *r); | 81 | int map__overlap(struct map *l, struct map *r); |
@@ -91,4 +91,70 @@ void map__fixup_end(struct map *self); | |||
91 | 91 | ||
92 | void map__reloc_vmlinux(struct map *self); | 92 | void map__reloc_vmlinux(struct map *self); |
93 | 93 | ||
94 | struct map_groups { | ||
95 | struct rb_root maps[MAP__NR_TYPES]; | ||
96 | struct list_head removed_maps[MAP__NR_TYPES]; | ||
97 | }; | ||
98 | |||
99 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
100 | enum map_type type, int verbose, FILE *fp); | ||
101 | void maps__insert(struct rb_root *maps, struct map *map); | ||
102 | struct map *maps__find(struct rb_root *maps, u64 addr); | ||
103 | void map_groups__init(struct map_groups *self); | ||
104 | int map_groups__clone(struct map_groups *self, | ||
105 | struct map_groups *parent, enum map_type type); | ||
106 | size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp); | ||
107 | size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp); | ||
108 | |||
109 | static inline void map_groups__insert(struct map_groups *self, struct map *map) | ||
110 | { | ||
111 | maps__insert(&self->maps[map->type], map); | ||
112 | } | ||
113 | |||
114 | static inline struct map *map_groups__find(struct map_groups *self, | ||
115 | enum map_type type, u64 addr) | ||
116 | { | ||
117 | return maps__find(&self->maps[type], addr); | ||
118 | } | ||
119 | |||
120 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
121 | enum map_type type, u64 addr, | ||
122 | struct map **mapp, | ||
123 | symbol_filter_t filter); | ||
124 | |||
125 | struct symbol *map_groups__find_symbol_by_name(struct map_groups *self, | ||
126 | enum map_type type, | ||
127 | const char *name, | ||
128 | struct map **mapp, | ||
129 | symbol_filter_t filter); | ||
130 | |||
131 | static inline | ||
132 | struct symbol *map_groups__find_function(struct map_groups *self, u64 addr, | ||
133 | struct map **mapp, symbol_filter_t filter) | ||
134 | { | ||
135 | return map_groups__find_symbol(self, MAP__FUNCTION, addr, mapp, filter); | ||
136 | } | ||
137 | |||
138 | static inline | ||
139 | struct symbol *map_groups__find_function_by_name(struct map_groups *self, | ||
140 | const char *name, struct map **mapp, | ||
141 | symbol_filter_t filter) | ||
142 | { | ||
143 | return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter); | ||
144 | } | ||
145 | |||
146 | int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, | ||
147 | int verbose, FILE *fp); | ||
148 | |||
149 | struct map *map_groups__find_by_name(struct map_groups *self, | ||
150 | enum map_type type, const char *name); | ||
151 | int __map_groups__create_kernel_maps(struct map_groups *self, | ||
152 | struct map *vmlinux_maps[MAP__NR_TYPES], | ||
153 | struct dso *kernel); | ||
154 | int map_groups__create_kernel_maps(struct map_groups *self, | ||
155 | struct map *vmlinux_maps[MAP__NR_TYPES]); | ||
156 | struct map *map_groups__new_module(struct map_groups *self, u64 start, | ||
157 | const char *filename); | ||
158 | void map_groups__flush(struct map_groups *self); | ||
159 | |||
94 | #endif /* __PERF_MAP_H */ | 160 | #endif /* __PERF_MAP_H */ |
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c new file mode 100644 index 00000000000..6d6e022d770 --- /dev/null +++ b/tools/perf/util/newt.c | |||
@@ -0,0 +1,685 @@ | |||
1 | #define _GNU_SOURCE | ||
2 | #include <stdio.h> | ||
3 | #undef _GNU_SOURCE | ||
4 | |||
5 | #include <stdlib.h> | ||
6 | #include <newt.h> | ||
7 | #include <sys/ttydefaults.h> | ||
8 | |||
9 | #include "cache.h" | ||
10 | #include "hist.h" | ||
11 | #include "session.h" | ||
12 | #include "sort.h" | ||
13 | #include "symbol.h" | ||
14 | |||
15 | struct ui_progress { | ||
16 | newtComponent form, scale; | ||
17 | }; | ||
18 | |||
19 | struct ui_progress *ui_progress__new(const char *title, u64 total) | ||
20 | { | ||
21 | struct ui_progress *self = malloc(sizeof(*self)); | ||
22 | |||
23 | if (self != NULL) { | ||
24 | int cols; | ||
25 | newtGetScreenSize(&cols, NULL); | ||
26 | cols -= 4; | ||
27 | newtCenteredWindow(cols, 1, title); | ||
28 | self->form = newtForm(NULL, NULL, 0); | ||
29 | if (self->form == NULL) | ||
30 | goto out_free_self; | ||
31 | self->scale = newtScale(0, 0, cols, total); | ||
32 | if (self->scale == NULL) | ||
33 | goto out_free_form; | ||
34 | newtFormAddComponents(self->form, self->scale, NULL); | ||
35 | newtRefresh(); | ||
36 | } | ||
37 | |||
38 | return self; | ||
39 | |||
40 | out_free_form: | ||
41 | newtFormDestroy(self->form); | ||
42 | out_free_self: | ||
43 | free(self); | ||
44 | return NULL; | ||
45 | } | ||
46 | |||
47 | void ui_progress__update(struct ui_progress *self, u64 curr) | ||
48 | { | ||
49 | newtScaleSet(self->scale, curr); | ||
50 | newtRefresh(); | ||
51 | } | ||
52 | |||
53 | void ui_progress__delete(struct ui_progress *self) | ||
54 | { | ||
55 | newtFormDestroy(self->form); | ||
56 | newtPopWindow(); | ||
57 | free(self); | ||
58 | } | ||
59 | |||
60 | static char browser__last_msg[1024]; | ||
61 | |||
62 | int browser__show_help(const char *format, va_list ap) | ||
63 | { | ||
64 | int ret; | ||
65 | static int backlog; | ||
66 | |||
67 | ret = vsnprintf(browser__last_msg + backlog, | ||
68 | sizeof(browser__last_msg) - backlog, format, ap); | ||
69 | backlog += ret; | ||
70 | |||
71 | if (browser__last_msg[backlog - 1] == '\n') { | ||
72 | newtPopHelpLine(); | ||
73 | newtPushHelpLine(browser__last_msg); | ||
74 | newtRefresh(); | ||
75 | backlog = 0; | ||
76 | } | ||
77 | |||
78 | return ret; | ||
79 | } | ||
80 | |||
81 | static void newt_form__set_exit_keys(newtComponent self) | ||
82 | { | ||
83 | newtFormAddHotKey(self, NEWT_KEY_ESCAPE); | ||
84 | newtFormAddHotKey(self, 'Q'); | ||
85 | newtFormAddHotKey(self, 'q'); | ||
86 | newtFormAddHotKey(self, CTRL('c')); | ||
87 | } | ||
88 | |||
89 | static newtComponent newt_form__new(void) | ||
90 | { | ||
91 | newtComponent self = newtForm(NULL, NULL, 0); | ||
92 | if (self) | ||
93 | newt_form__set_exit_keys(self); | ||
94 | return self; | ||
95 | } | ||
96 | |||
97 | static int popup_menu(int argc, char * const argv[]) | ||
98 | { | ||
99 | struct newtExitStruct es; | ||
100 | int i, rc = -1, max_len = 5; | ||
101 | newtComponent listbox, form = newt_form__new(); | ||
102 | |||
103 | if (form == NULL) | ||
104 | return -1; | ||
105 | |||
106 | listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); | ||
107 | if (listbox == NULL) | ||
108 | goto out_destroy_form; | ||
109 | |||
110 | newtFormAddComponents(form, listbox, NULL); | ||
111 | |||
112 | for (i = 0; i < argc; ++i) { | ||
113 | int len = strlen(argv[i]); | ||
114 | if (len > max_len) | ||
115 | max_len = len; | ||
116 | if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i)) | ||
117 | goto out_destroy_form; | ||
118 | } | ||
119 | |||
120 | newtCenteredWindow(max_len, argc, NULL); | ||
121 | newtFormRun(form, &es); | ||
122 | rc = newtListboxGetCurrent(listbox) - NULL; | ||
123 | if (es.reason == NEWT_EXIT_HOTKEY) | ||
124 | rc = -1; | ||
125 | newtPopWindow(); | ||
126 | out_destroy_form: | ||
127 | newtFormDestroy(form); | ||
128 | return rc; | ||
129 | } | ||
130 | |||
131 | static bool dialog_yesno(const char *msg) | ||
132 | { | ||
133 | /* newtWinChoice should really be accepting const char pointers... */ | ||
134 | char yes[] = "Yes", no[] = "No"; | ||
135 | return newtWinChoice(NULL, no, yes, (char *)msg) == 2; | ||
136 | } | ||
137 | |||
138 | /* | ||
139 | * When debugging newt problems it was useful to be able to "unroll" | ||
140 | * the calls to newtCheckBoxTreeAdd{Array,Item}, so that we can generate | ||
141 | * a source file with the sequence of calls to these methods, to then | ||
142 | * tweak the arrays to get the intended results, so I'm keeping this code | ||
143 | * here, may be useful again in the future. | ||
144 | */ | ||
145 | #undef NEWT_DEBUG | ||
146 | |||
147 | static void newt_checkbox_tree__add(newtComponent tree, const char *str, | ||
148 | void *priv, int *indexes) | ||
149 | { | ||
150 | #ifdef NEWT_DEBUG | ||
151 | /* Print the newtCheckboxTreeAddArray to tinker with its index arrays */ | ||
152 | int i = 0, len = 40 - strlen(str); | ||
153 | |||
154 | fprintf(stderr, | ||
155 | "\tnewtCheckboxTreeAddItem(tree, %*.*s\"%s\", (void *)%p, 0, ", | ||
156 | len, len, " ", str, priv); | ||
157 | while (indexes[i] != NEWT_ARG_LAST) { | ||
158 | if (indexes[i] != NEWT_ARG_APPEND) | ||
159 | fprintf(stderr, " %d,", indexes[i]); | ||
160 | else | ||
161 | fprintf(stderr, " %s,", "NEWT_ARG_APPEND"); | ||
162 | ++i; | ||
163 | } | ||
164 | fprintf(stderr, " %s", " NEWT_ARG_LAST);\n"); | ||
165 | fflush(stderr); | ||
166 | #endif | ||
167 | newtCheckboxTreeAddArray(tree, str, priv, 0, indexes); | ||
168 | } | ||
169 | |||
170 | static char *callchain_list__sym_name(struct callchain_list *self, | ||
171 | char *bf, size_t bfsize) | ||
172 | { | ||
173 | if (self->ms.sym) | ||
174 | return self->ms.sym->name; | ||
175 | |||
176 | snprintf(bf, bfsize, "%#Lx", self->ip); | ||
177 | return bf; | ||
178 | } | ||
179 | |||
180 | static void __callchain__append_graph_browser(struct callchain_node *self, | ||
181 | newtComponent tree, u64 total, | ||
182 | int *indexes, int depth) | ||
183 | { | ||
184 | struct rb_node *node; | ||
185 | u64 new_total, remaining; | ||
186 | int idx = 0; | ||
187 | |||
188 | if (callchain_param.mode == CHAIN_GRAPH_REL) | ||
189 | new_total = self->children_hit; | ||
190 | else | ||
191 | new_total = total; | ||
192 | |||
193 | remaining = new_total; | ||
194 | node = rb_first(&self->rb_root); | ||
195 | while (node) { | ||
196 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); | ||
197 | struct rb_node *next = rb_next(node); | ||
198 | u64 cumul = cumul_hits(child); | ||
199 | struct callchain_list *chain; | ||
200 | int first = true, printed = 0; | ||
201 | int chain_idx = -1; | ||
202 | remaining -= cumul; | ||
203 | |||
204 | indexes[depth] = NEWT_ARG_APPEND; | ||
205 | indexes[depth + 1] = NEWT_ARG_LAST; | ||
206 | |||
207 | list_for_each_entry(chain, &child->val, list) { | ||
208 | char ipstr[BITS_PER_LONG / 4 + 1], | ||
209 | *alloc_str = NULL; | ||
210 | const char *str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); | ||
211 | |||
212 | if (first) { | ||
213 | double percent = cumul * 100.0 / new_total; | ||
214 | |||
215 | first = false; | ||
216 | if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0) | ||
217 | str = "Not enough memory!"; | ||
218 | else | ||
219 | str = alloc_str; | ||
220 | } else { | ||
221 | indexes[depth] = idx; | ||
222 | indexes[depth + 1] = NEWT_ARG_APPEND; | ||
223 | indexes[depth + 2] = NEWT_ARG_LAST; | ||
224 | ++chain_idx; | ||
225 | } | ||
226 | newt_checkbox_tree__add(tree, str, &chain->ms, indexes); | ||
227 | free(alloc_str); | ||
228 | ++printed; | ||
229 | } | ||
230 | |||
231 | indexes[depth] = idx; | ||
232 | if (chain_idx != -1) | ||
233 | indexes[depth + 1] = chain_idx; | ||
234 | if (printed != 0) | ||
235 | ++idx; | ||
236 | __callchain__append_graph_browser(child, tree, new_total, indexes, | ||
237 | depth + (chain_idx != -1 ? 2 : 1)); | ||
238 | node = next; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | static void callchain__append_graph_browser(struct callchain_node *self, | ||
243 | newtComponent tree, u64 total, | ||
244 | int *indexes, int parent_idx) | ||
245 | { | ||
246 | struct callchain_list *chain; | ||
247 | int i = 0; | ||
248 | |||
249 | indexes[1] = NEWT_ARG_APPEND; | ||
250 | indexes[2] = NEWT_ARG_LAST; | ||
251 | |||
252 | list_for_each_entry(chain, &self->val, list) { | ||
253 | char ipstr[BITS_PER_LONG / 4 + 1], *str; | ||
254 | |||
255 | if (chain->ip >= PERF_CONTEXT_MAX) | ||
256 | continue; | ||
257 | |||
258 | if (!i++ && sort__first_dimension == SORT_SYM) | ||
259 | continue; | ||
260 | |||
261 | str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); | ||
262 | newt_checkbox_tree__add(tree, str, &chain->ms, indexes); | ||
263 | } | ||
264 | |||
265 | indexes[1] = parent_idx; | ||
266 | indexes[2] = NEWT_ARG_APPEND; | ||
267 | indexes[3] = NEWT_ARG_LAST; | ||
268 | __callchain__append_graph_browser(self, tree, total, indexes, 2); | ||
269 | } | ||
270 | |||
271 | static void hist_entry__append_callchain_browser(struct hist_entry *self, | ||
272 | newtComponent tree, u64 total, int parent_idx) | ||
273 | { | ||
274 | struct rb_node *rb_node; | ||
275 | int indexes[1024] = { [0] = parent_idx, }; | ||
276 | int idx = 0; | ||
277 | struct callchain_node *chain; | ||
278 | |||
279 | rb_node = rb_first(&self->sorted_chain); | ||
280 | while (rb_node) { | ||
281 | chain = rb_entry(rb_node, struct callchain_node, rb_node); | ||
282 | switch (callchain_param.mode) { | ||
283 | case CHAIN_FLAT: | ||
284 | break; | ||
285 | case CHAIN_GRAPH_ABS: /* falldown */ | ||
286 | case CHAIN_GRAPH_REL: | ||
287 | callchain__append_graph_browser(chain, tree, total, indexes, idx++); | ||
288 | break; | ||
289 | case CHAIN_NONE: | ||
290 | default: | ||
291 | break; | ||
292 | } | ||
293 | rb_node = rb_next(rb_node); | ||
294 | } | ||
295 | } | ||
296 | |||
297 | static size_t hist_entry__append_browser(struct hist_entry *self, | ||
298 | newtComponent tree, u64 total) | ||
299 | { | ||
300 | char s[256]; | ||
301 | size_t ret; | ||
302 | |||
303 | if (symbol_conf.exclude_other && !self->parent) | ||
304 | return 0; | ||
305 | |||
306 | ret = hist_entry__snprintf(self, s, sizeof(s), NULL, | ||
307 | false, 0, false, total); | ||
308 | if (symbol_conf.use_callchain) { | ||
309 | int indexes[2]; | ||
310 | |||
311 | indexes[0] = NEWT_ARG_APPEND; | ||
312 | indexes[1] = NEWT_ARG_LAST; | ||
313 | newt_checkbox_tree__add(tree, s, &self->ms, indexes); | ||
314 | } else | ||
315 | newtListboxAppendEntry(tree, s, &self->ms); | ||
316 | |||
317 | return ret; | ||
318 | } | ||
319 | |||
320 | static void map_symbol__annotate_browser(const struct map_symbol *self, | ||
321 | const char *input_name) | ||
322 | { | ||
323 | FILE *fp; | ||
324 | int cols, rows; | ||
325 | newtComponent form, tree; | ||
326 | struct newtExitStruct es; | ||
327 | char *str; | ||
328 | size_t line_len, max_line_len = 0; | ||
329 | size_t max_usable_width; | ||
330 | char *line = NULL; | ||
331 | |||
332 | if (self->sym == NULL) | ||
333 | return; | ||
334 | |||
335 | if (asprintf(&str, "perf annotate -i \"%s\" -d \"%s\" %s 2>&1 | expand", | ||
336 | input_name, self->map->dso->name, self->sym->name) < 0) | ||
337 | return; | ||
338 | |||
339 | fp = popen(str, "r"); | ||
340 | if (fp == NULL) | ||
341 | goto out_free_str; | ||
342 | |||
343 | newtPushHelpLine("Press ESC to exit"); | ||
344 | newtGetScreenSize(&cols, &rows); | ||
345 | tree = newtListbox(0, 0, rows - 5, NEWT_FLAG_SCROLL); | ||
346 | |||
347 | while (!feof(fp)) { | ||
348 | if (getline(&line, &line_len, fp) < 0 || !line_len) | ||
349 | break; | ||
350 | while (line_len != 0 && isspace(line[line_len - 1])) | ||
351 | line[--line_len] = '\0'; | ||
352 | |||
353 | if (line_len > max_line_len) | ||
354 | max_line_len = line_len; | ||
355 | newtListboxAppendEntry(tree, line, NULL); | ||
356 | } | ||
357 | fclose(fp); | ||
358 | free(line); | ||
359 | |||
360 | max_usable_width = cols - 22; | ||
361 | if (max_line_len > max_usable_width) | ||
362 | max_line_len = max_usable_width; | ||
363 | |||
364 | newtListboxSetWidth(tree, max_line_len); | ||
365 | |||
366 | newtCenteredWindow(max_line_len + 2, rows - 5, self->sym->name); | ||
367 | form = newt_form__new(); | ||
368 | newtFormAddComponents(form, tree, NULL); | ||
369 | |||
370 | newtFormRun(form, &es); | ||
371 | newtFormDestroy(form); | ||
372 | newtPopWindow(); | ||
373 | newtPopHelpLine(); | ||
374 | out_free_str: | ||
375 | free(str); | ||
376 | } | ||
377 | |||
378 | static const void *newt__symbol_tree_get_current(newtComponent self) | ||
379 | { | ||
380 | if (symbol_conf.use_callchain) | ||
381 | return newtCheckboxTreeGetCurrent(self); | ||
382 | return newtListboxGetCurrent(self); | ||
383 | } | ||
384 | |||
385 | static void hist_browser__selection(newtComponent self, void *data) | ||
386 | { | ||
387 | const struct map_symbol **symbol_ptr = data; | ||
388 | *symbol_ptr = newt__symbol_tree_get_current(self); | ||
389 | } | ||
390 | |||
391 | struct hist_browser { | ||
392 | newtComponent form, tree; | ||
393 | const struct map_symbol *selection; | ||
394 | }; | ||
395 | |||
396 | static struct hist_browser *hist_browser__new(void) | ||
397 | { | ||
398 | struct hist_browser *self = malloc(sizeof(*self)); | ||
399 | |||
400 | if (self != NULL) | ||
401 | self->form = NULL; | ||
402 | |||
403 | return self; | ||
404 | } | ||
405 | |||
406 | static void hist_browser__delete(struct hist_browser *self) | ||
407 | { | ||
408 | newtFormDestroy(self->form); | ||
409 | newtPopWindow(); | ||
410 | free(self); | ||
411 | } | ||
412 | |||
413 | static int hist_browser__populate(struct hist_browser *self, struct rb_root *hists, | ||
414 | u64 nr_hists, u64 session_total) | ||
415 | { | ||
416 | int max_len = 0, idx, cols, rows; | ||
417 | struct ui_progress *progress; | ||
418 | struct rb_node *nd; | ||
419 | u64 curr_hist = 0; | ||
420 | char seq[] = "."; | ||
421 | char str[256]; | ||
422 | |||
423 | if (self->form) { | ||
424 | newtFormDestroy(self->form); | ||
425 | newtPopWindow(); | ||
426 | } | ||
427 | |||
428 | snprintf(str, sizeof(str), "Samples: %Ld ", | ||
429 | session_total); | ||
430 | newtDrawRootText(0, 0, str); | ||
431 | |||
432 | newtGetScreenSize(NULL, &rows); | ||
433 | |||
434 | if (symbol_conf.use_callchain) | ||
435 | self->tree = newtCheckboxTreeMulti(0, 0, rows - 5, seq, | ||
436 | NEWT_FLAG_SCROLL); | ||
437 | else | ||
438 | self->tree = newtListbox(0, 0, rows - 5, | ||
439 | (NEWT_FLAG_SCROLL | | ||
440 | NEWT_FLAG_RETURNEXIT)); | ||
441 | |||
442 | newtComponentAddCallback(self->tree, hist_browser__selection, | ||
443 | &self->selection); | ||
444 | |||
445 | progress = ui_progress__new("Adding entries to the browser...", nr_hists); | ||
446 | if (progress == NULL) | ||
447 | return -1; | ||
448 | |||
449 | idx = 0; | ||
450 | for (nd = rb_first(hists); nd; nd = rb_next(nd)) { | ||
451 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | ||
452 | int len; | ||
453 | |||
454 | if (h->filtered) | ||
455 | continue; | ||
456 | |||
457 | len = hist_entry__append_browser(h, self->tree, session_total); | ||
458 | if (len > max_len) | ||
459 | max_len = len; | ||
460 | if (symbol_conf.use_callchain) | ||
461 | hist_entry__append_callchain_browser(h, self->tree, | ||
462 | session_total, idx++); | ||
463 | ++curr_hist; | ||
464 | if (curr_hist % 5) | ||
465 | ui_progress__update(progress, curr_hist); | ||
466 | } | ||
467 | |||
468 | ui_progress__delete(progress); | ||
469 | |||
470 | newtGetScreenSize(&cols, &rows); | ||
471 | |||
472 | if (max_len > cols) | ||
473 | max_len = cols - 3; | ||
474 | |||
475 | if (!symbol_conf.use_callchain) | ||
476 | newtListboxSetWidth(self->tree, max_len); | ||
477 | |||
478 | newtCenteredWindow(max_len + (symbol_conf.use_callchain ? 5 : 0), | ||
479 | rows - 5, "Report"); | ||
480 | self->form = newt_form__new(); | ||
481 | if (self->form == NULL) | ||
482 | return -1; | ||
483 | |||
484 | newtFormAddHotKey(self->form, 'A'); | ||
485 | newtFormAddHotKey(self->form, 'a'); | ||
486 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); | ||
487 | newtFormAddComponents(self->form, self->tree, NULL); | ||
488 | self->selection = newt__symbol_tree_get_current(self->tree); | ||
489 | |||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | enum hist_filter { | ||
494 | HIST_FILTER__DSO, | ||
495 | HIST_FILTER__THREAD, | ||
496 | }; | ||
497 | |||
498 | static u64 hists__filter_by_dso(struct rb_root *hists, struct dso *dso, | ||
499 | u64 *session_total) | ||
500 | { | ||
501 | struct rb_node *nd; | ||
502 | u64 nr_hists = 0; | ||
503 | |||
504 | *session_total = 0; | ||
505 | |||
506 | for (nd = rb_first(hists); nd; nd = rb_next(nd)) { | ||
507 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | ||
508 | |||
509 | if (dso != NULL && (h->ms.map == NULL || h->ms.map->dso != dso)) { | ||
510 | h->filtered |= (1 << HIST_FILTER__DSO); | ||
511 | continue; | ||
512 | } | ||
513 | h->filtered &= ~(1 << HIST_FILTER__DSO); | ||
514 | ++nr_hists; | ||
515 | *session_total += h->count; | ||
516 | } | ||
517 | |||
518 | return nr_hists; | ||
519 | } | ||
520 | |||
521 | static u64 hists__filter_by_thread(struct rb_root *hists, const struct thread *thread, | ||
522 | u64 *session_total) | ||
523 | { | ||
524 | struct rb_node *nd; | ||
525 | u64 nr_hists = 0; | ||
526 | |||
527 | *session_total = 0; | ||
528 | |||
529 | for (nd = rb_first(hists); nd; nd = rb_next(nd)) { | ||
530 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | ||
531 | |||
532 | if (thread != NULL && h->thread != thread) { | ||
533 | h->filtered |= (1 << HIST_FILTER__THREAD); | ||
534 | continue; | ||
535 | } | ||
536 | h->filtered &= ~(1 << HIST_FILTER__THREAD); | ||
537 | ++nr_hists; | ||
538 | *session_total += h->count; | ||
539 | } | ||
540 | |||
541 | return nr_hists; | ||
542 | } | ||
543 | |||
544 | static struct thread *hist_browser__selected_thread(struct hist_browser *self) | ||
545 | { | ||
546 | int *indexes; | ||
547 | |||
548 | if (!symbol_conf.use_callchain) | ||
549 | goto out; | ||
550 | |||
551 | indexes = newtCheckboxTreeFindItem(self->tree, (void *)self->selection); | ||
552 | if (indexes) { | ||
553 | bool is_hist_entry = indexes[1] == NEWT_ARG_LAST; | ||
554 | free(indexes); | ||
555 | if (is_hist_entry) | ||
556 | goto out; | ||
557 | } | ||
558 | return NULL; | ||
559 | out: | ||
560 | return *(struct thread **)(self->selection + 1); | ||
561 | } | ||
562 | |||
563 | int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists, | ||
564 | u64 session_total, const char *helpline, | ||
565 | const char *input_name) | ||
566 | { | ||
567 | struct newtExitStruct es; | ||
568 | bool dso_filtered = false, thread_filtered = false; | ||
569 | int err = -1; | ||
570 | struct hist_browser *browser = hist_browser__new(); | ||
571 | |||
572 | if (browser == NULL) | ||
573 | return -1; | ||
574 | |||
575 | newtPushHelpLine(helpline); | ||
576 | |||
577 | if (hist_browser__populate(browser, hists, nr_hists, session_total) < 0) | ||
578 | goto out; | ||
579 | |||
580 | while (1) { | ||
581 | const struct thread *thread; | ||
582 | char *options[16]; | ||
583 | int nr_options = 0, choice = 0, i, | ||
584 | annotate = -2, zoom_dso = -2, zoom_thread = -2; | ||
585 | |||
586 | newtFormRun(browser->form, &es); | ||
587 | if (es.reason == NEWT_EXIT_HOTKEY) { | ||
588 | if (toupper(es.u.key) == 'A') | ||
589 | goto do_annotate; | ||
590 | if (es.u.key == NEWT_KEY_ESCAPE || | ||
591 | toupper(es.u.key) == 'Q' || | ||
592 | es.u.key == CTRL('c')) { | ||
593 | if (dialog_yesno("Do you really want to exit?")) | ||
594 | break; | ||
595 | else | ||
596 | continue; | ||
597 | } | ||
598 | } | ||
599 | |||
600 | if (browser->selection->sym != NULL && | ||
601 | asprintf(&options[nr_options], "Annotate %s", | ||
602 | browser->selection->sym->name) > 0) | ||
603 | annotate = nr_options++; | ||
604 | |||
605 | if (browser->selection->map != NULL && | ||
606 | asprintf(&options[nr_options], "Zoom %s %s DSO", | ||
607 | dso_filtered ? "out of" : "into", | ||
608 | (browser->selection->map->dso->kernel ? "the Kernel" : | ||
609 | browser->selection->map->dso->short_name)) > 0) | ||
610 | zoom_dso = nr_options++; | ||
611 | |||
612 | thread = hist_browser__selected_thread(browser); | ||
613 | if (thread != NULL && | ||
614 | asprintf(&options[nr_options], "Zoom %s %s(%d) thread", | ||
615 | (thread_filtered ? "out of" : "into"), | ||
616 | (thread->comm_set ? thread->comm : ""), thread->pid) > 0) | ||
617 | zoom_thread = nr_options++; | ||
618 | |||
619 | options[nr_options++] = (char *)"Exit"; | ||
620 | |||
621 | choice = popup_menu(nr_options, options); | ||
622 | |||
623 | for (i = 0; i < nr_options - 1; ++i) | ||
624 | free(options[i]); | ||
625 | |||
626 | if (choice == nr_options - 1) | ||
627 | break; | ||
628 | |||
629 | if (choice == -1) | ||
630 | continue; | ||
631 | do_annotate: | ||
632 | if (choice == annotate) { | ||
633 | if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) { | ||
634 | newtPopHelpLine(); | ||
635 | newtPushHelpLine("No vmlinux file found, can't " | ||
636 | "annotate with just a " | ||
637 | "kallsyms file"); | ||
638 | continue; | ||
639 | } | ||
640 | map_symbol__annotate_browser(browser->selection, | ||
641 | input_name); | ||
642 | } else if (choice == zoom_dso) { | ||
643 | nr_hists = hists__filter_by_dso(hists, | ||
644 | (dso_filtered ? NULL : | ||
645 | browser->selection->map->dso), | ||
646 | &session_total); | ||
647 | dso_filtered = !dso_filtered; | ||
648 | if (hist_browser__populate(browser, hists, nr_hists, session_total) < 0) | ||
649 | goto out; | ||
650 | } else if (choice == zoom_thread) { | ||
651 | nr_hists = hists__filter_by_thread(hists, | ||
652 | (thread_filtered ? NULL : thread), | ||
653 | &session_total); | ||
654 | thread_filtered = !thread_filtered; | ||
655 | if (hist_browser__populate(browser, hists, nr_hists, session_total) < 0) | ||
656 | goto out; | ||
657 | } | ||
658 | } | ||
659 | err = 0; | ||
660 | out: | ||
661 | hist_browser__delete(browser); | ||
662 | return err; | ||
663 | } | ||
664 | |||
665 | void setup_browser(void) | ||
666 | { | ||
667 | if (!isatty(1)) | ||
668 | return; | ||
669 | |||
670 | use_browser = true; | ||
671 | newtInit(); | ||
672 | newtCls(); | ||
673 | newtPushHelpLine(" "); | ||
674 | } | ||
675 | |||
676 | void exit_browser(bool wait_for_ok) | ||
677 | { | ||
678 | if (use_browser) { | ||
679 | if (wait_for_ok) { | ||
680 | char title[] = "Fatal Error", ok[] = "Ok"; | ||
681 | newtWinMessage(title, ok, browser__last_msg); | ||
682 | } | ||
683 | newtFinished(); | ||
684 | } | ||
685 | } | ||
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 05d0c5c2030..435781e0c20 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "parse-events.h" | 5 | #include "parse-events.h" |
6 | #include "exec_cmd.h" | 6 | #include "exec_cmd.h" |
7 | #include "string.h" | 7 | #include "string.h" |
8 | #include "symbol.h" | ||
8 | #include "cache.h" | 9 | #include "cache.h" |
9 | #include "header.h" | 10 | #include "header.h" |
10 | #include "debugfs.h" | 11 | #include "debugfs.h" |
@@ -656,6 +657,10 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr) | |||
656 | return EVT_FAILED; | 657 | return EVT_FAILED; |
657 | n = hex2u64(str + 1, &config); | 658 | n = hex2u64(str + 1, &config); |
658 | if (n > 0) { | 659 | if (n > 0) { |
660 | if (str[n+1] == 'p') { | ||
661 | attr->precise = 1; | ||
662 | n++; | ||
663 | } | ||
659 | *strp = str + n + 1; | 664 | *strp = str + n + 1; |
660 | attr->type = PERF_TYPE_RAW; | 665 | attr->type = PERF_TYPE_RAW; |
661 | attr->config = config; | 666 | attr->config = config; |
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index efebd5b476b..79dfa0c34b3 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c | |||
@@ -500,6 +500,7 @@ int usage_with_options_internal(const char * const *usagestr, | |||
500 | void usage_with_options(const char * const *usagestr, | 500 | void usage_with_options(const char * const *usagestr, |
501 | const struct option *opts) | 501 | const struct option *opts) |
502 | { | 502 | { |
503 | exit_browser(false); | ||
503 | usage_with_options_internal(usagestr, opts, 0); | 504 | usage_with_options_internal(usagestr, opts, 0); |
504 | exit(129); | 505 | exit(129); |
505 | } | 506 | } |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 7c004b6ef24..3fc0be741b8 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -33,19 +33,26 @@ | |||
33 | #include <limits.h> | 33 | #include <limits.h> |
34 | 34 | ||
35 | #undef _GNU_SOURCE | 35 | #undef _GNU_SOURCE |
36 | #include "util.h" | ||
36 | #include "event.h" | 37 | #include "event.h" |
37 | #include "string.h" | 38 | #include "string.h" |
38 | #include "strlist.h" | 39 | #include "strlist.h" |
39 | #include "debug.h" | 40 | #include "debug.h" |
40 | #include "cache.h" | 41 | #include "cache.h" |
41 | #include "color.h" | 42 | #include "color.h" |
42 | #include "parse-events.h" /* For debugfs_path */ | 43 | #include "symbol.h" |
44 | #include "thread.h" | ||
45 | #include "trace-event.h" /* For __unused */ | ||
46 | #include "parse-events.h" /* For debugfs_path */ | ||
43 | #include "probe-event.h" | 47 | #include "probe-event.h" |
48 | #include "probe-finder.h" | ||
44 | 49 | ||
45 | #define MAX_CMDLEN 256 | 50 | #define MAX_CMDLEN 256 |
46 | #define MAX_PROBE_ARGS 128 | 51 | #define MAX_PROBE_ARGS 128 |
47 | #define PERFPROBE_GROUP "probe" | 52 | #define PERFPROBE_GROUP "probe" |
48 | 53 | ||
54 | bool probe_event_dry_run; /* Dry run flag */ | ||
55 | |||
49 | #define semantic_error(msg ...) die("Semantic error :" msg) | 56 | #define semantic_error(msg ...) die("Semantic error :" msg) |
50 | 57 | ||
51 | /* If there is no space to write, returns -E2BIG. */ | 58 | /* If there is no space to write, returns -E2BIG. */ |
@@ -64,6 +71,208 @@ static int e_snprintf(char *str, size_t size, const char *format, ...) | |||
64 | return ret; | 71 | return ret; |
65 | } | 72 | } |
66 | 73 | ||
74 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); | ||
75 | static struct map_groups kmap_groups; | ||
76 | static struct map *kmaps[MAP__NR_TYPES]; | ||
77 | |||
78 | /* Initialize symbol maps and path of vmlinux */ | ||
79 | static void init_vmlinux(void) | ||
80 | { | ||
81 | symbol_conf.sort_by_name = true; | ||
82 | if (symbol_conf.vmlinux_name == NULL) | ||
83 | symbol_conf.try_vmlinux_path = true; | ||
84 | else | ||
85 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); | ||
86 | if (symbol__init() < 0) | ||
87 | die("Failed to init symbol map."); | ||
88 | |||
89 | map_groups__init(&kmap_groups); | ||
90 | if (map_groups__create_kernel_maps(&kmap_groups, kmaps) < 0) | ||
91 | die("Failed to create kernel maps."); | ||
92 | } | ||
93 | |||
94 | #ifdef DWARF_SUPPORT | ||
95 | static int open_vmlinux(void) | ||
96 | { | ||
97 | if (map__load(kmaps[MAP__FUNCTION], NULL) < 0) { | ||
98 | pr_debug("Failed to load kernel map.\n"); | ||
99 | return -EINVAL; | ||
100 | } | ||
101 | pr_debug("Try to open %s\n", kmaps[MAP__FUNCTION]->dso->long_name); | ||
102 | return open(kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY); | ||
103 | } | ||
104 | |||
105 | static void convert_to_perf_probe_point(struct kprobe_trace_point *tp, | ||
106 | struct perf_probe_point *pp) | ||
107 | { | ||
108 | struct symbol *sym; | ||
109 | int fd, ret = 0; | ||
110 | |||
111 | sym = map__find_symbol_by_name(kmaps[MAP__FUNCTION], | ||
112 | tp->symbol, NULL); | ||
113 | if (sym) { | ||
114 | fd = open_vmlinux(); | ||
115 | ret = find_perf_probe_point(fd, sym->start + tp->offset, pp); | ||
116 | close(fd); | ||
117 | } | ||
118 | if (ret <= 0) { | ||
119 | pp->function = xstrdup(tp->symbol); | ||
120 | pp->offset = tp->offset; | ||
121 | } | ||
122 | pp->retprobe = tp->retprobe; | ||
123 | } | ||
124 | |||
125 | /* Try to find perf_probe_event with debuginfo */ | ||
126 | static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev, | ||
127 | struct kprobe_trace_event **tevs) | ||
128 | { | ||
129 | bool need_dwarf = perf_probe_event_need_dwarf(pev); | ||
130 | int fd, ntevs; | ||
131 | |||
132 | fd = open_vmlinux(); | ||
133 | if (fd < 0) { | ||
134 | if (need_dwarf) | ||
135 | die("Could not open debuginfo file."); | ||
136 | |||
137 | pr_debug("Could not open vmlinux. Try to use symbols.\n"); | ||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | /* Searching trace events corresponding to probe event */ | ||
142 | ntevs = find_kprobe_trace_events(fd, pev, tevs); | ||
143 | close(fd); | ||
144 | |||
145 | if (ntevs > 0) /* Succeeded to find trace events */ | ||
146 | return ntevs; | ||
147 | |||
148 | if (ntevs == 0) /* No error but failed to find probe point. */ | ||
149 | die("Probe point '%s' not found. - probe not added.", | ||
150 | synthesize_perf_probe_point(&pev->point)); | ||
151 | |||
152 | /* Error path */ | ||
153 | if (need_dwarf) { | ||
154 | if (ntevs == -ENOENT) | ||
155 | pr_warning("No dwarf info found in the vmlinux - " | ||
156 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
157 | die("Could not analyze debuginfo."); | ||
158 | } | ||
159 | pr_debug("An error occurred in debuginfo analysis." | ||
160 | " Try to use symbols.\n"); | ||
161 | return 0; | ||
162 | |||
163 | } | ||
164 | |||
165 | #define LINEBUF_SIZE 256 | ||
166 | #define NR_ADDITIONAL_LINES 2 | ||
167 | |||
168 | static void show_one_line(FILE *fp, unsigned int l, bool skip, bool show_num) | ||
169 | { | ||
170 | char buf[LINEBUF_SIZE]; | ||
171 | const char *color = PERF_COLOR_BLUE; | ||
172 | |||
173 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) | ||
174 | goto error; | ||
175 | if (!skip) { | ||
176 | if (show_num) | ||
177 | fprintf(stdout, "%7u %s", l, buf); | ||
178 | else | ||
179 | color_fprintf(stdout, color, " %s", buf); | ||
180 | } | ||
181 | |||
182 | while (strlen(buf) == LINEBUF_SIZE - 1 && | ||
183 | buf[LINEBUF_SIZE - 2] != '\n') { | ||
184 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) | ||
185 | goto error; | ||
186 | if (!skip) { | ||
187 | if (show_num) | ||
188 | fprintf(stdout, "%s", buf); | ||
189 | else | ||
190 | color_fprintf(stdout, color, "%s", buf); | ||
191 | } | ||
192 | } | ||
193 | return; | ||
194 | error: | ||
195 | if (feof(fp)) | ||
196 | die("Source file is shorter than expected."); | ||
197 | else | ||
198 | die("File read error: %s", strerror(errno)); | ||
199 | } | ||
200 | |||
201 | /* | ||
202 | * Show line-range always requires debuginfo to find source file and | ||
203 | * line number. | ||
204 | */ | ||
205 | void show_line_range(struct line_range *lr) | ||
206 | { | ||
207 | unsigned int l = 1; | ||
208 | struct line_node *ln; | ||
209 | FILE *fp; | ||
210 | int fd, ret; | ||
211 | |||
212 | /* Search a line range */ | ||
213 | init_vmlinux(); | ||
214 | fd = open_vmlinux(); | ||
215 | if (fd < 0) | ||
216 | die("Could not open debuginfo file."); | ||
217 | ret = find_line_range(fd, lr); | ||
218 | if (ret <= 0) | ||
219 | die("Source line is not found.\n"); | ||
220 | close(fd); | ||
221 | |||
222 | setup_pager(); | ||
223 | |||
224 | if (lr->function) | ||
225 | fprintf(stdout, "<%s:%d>\n", lr->function, | ||
226 | lr->start - lr->offset); | ||
227 | else | ||
228 | fprintf(stdout, "<%s:%d>\n", lr->file, lr->start); | ||
229 | |||
230 | fp = fopen(lr->path, "r"); | ||
231 | if (fp == NULL) | ||
232 | die("Failed to open %s: %s", lr->path, strerror(errno)); | ||
233 | /* Skip to starting line number */ | ||
234 | while (l < lr->start) | ||
235 | show_one_line(fp, l++, true, false); | ||
236 | |||
237 | list_for_each_entry(ln, &lr->line_list, list) { | ||
238 | while (ln->line > l) | ||
239 | show_one_line(fp, (l++) - lr->offset, false, false); | ||
240 | show_one_line(fp, (l++) - lr->offset, false, true); | ||
241 | } | ||
242 | |||
243 | if (lr->end == INT_MAX) | ||
244 | lr->end = l + NR_ADDITIONAL_LINES; | ||
245 | while (l < lr->end && !feof(fp)) | ||
246 | show_one_line(fp, (l++) - lr->offset, false, false); | ||
247 | |||
248 | fclose(fp); | ||
249 | } | ||
250 | |||
251 | #else /* !DWARF_SUPPORT */ | ||
252 | |||
253 | static void convert_to_perf_probe_point(struct kprobe_trace_point *tp, | ||
254 | struct perf_probe_point *pp) | ||
255 | { | ||
256 | pp->function = xstrdup(tp->symbol); | ||
257 | pp->offset = tp->offset; | ||
258 | pp->retprobe = tp->retprobe; | ||
259 | } | ||
260 | |||
261 | static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev, | ||
262 | struct kprobe_trace_event **tevs __unused) | ||
263 | { | ||
264 | if (perf_probe_event_need_dwarf(pev)) | ||
265 | die("Debuginfo-analysis is not supported"); | ||
266 | return 0; | ||
267 | } | ||
268 | |||
269 | void show_line_range(struct line_range *lr __unused) | ||
270 | { | ||
271 | die("Debuginfo-analysis is not supported"); | ||
272 | } | ||
273 | |||
274 | #endif | ||
275 | |||
67 | void parse_line_range_desc(const char *arg, struct line_range *lr) | 276 | void parse_line_range_desc(const char *arg, struct line_range *lr) |
68 | { | 277 | { |
69 | const char *ptr; | 278 | const char *ptr; |
@@ -90,9 +299,9 @@ void parse_line_range_desc(const char *arg, struct line_range *lr) | |||
90 | if (*tmp != '\0') | 299 | if (*tmp != '\0') |
91 | semantic_error("Tailing with invalid character '%d'.", | 300 | semantic_error("Tailing with invalid character '%d'.", |
92 | *tmp); | 301 | *tmp); |
93 | tmp = strndup(arg, (ptr - arg)); | 302 | tmp = xstrndup(arg, (ptr - arg)); |
94 | } else | 303 | } else |
95 | tmp = strdup(arg); | 304 | tmp = xstrdup(arg); |
96 | 305 | ||
97 | if (strchr(tmp, '.')) | 306 | if (strchr(tmp, '.')) |
98 | lr->file = tmp; | 307 | lr->file = tmp; |
@@ -113,8 +322,9 @@ static bool check_event_name(const char *name) | |||
113 | } | 322 | } |
114 | 323 | ||
115 | /* Parse probepoint definition. */ | 324 | /* Parse probepoint definition. */ |
116 | static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | 325 | static void parse_perf_probe_point(char *arg, struct perf_probe_event *pev) |
117 | { | 326 | { |
327 | struct perf_probe_point *pp = &pev->point; | ||
118 | char *ptr, *tmp; | 328 | char *ptr, *tmp; |
119 | char c, nc = 0; | 329 | char c, nc = 0; |
120 | /* | 330 | /* |
@@ -135,7 +345,8 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | |||
135 | if (!check_event_name(arg)) | 345 | if (!check_event_name(arg)) |
136 | semantic_error("%s is bad for event name -it must " | 346 | semantic_error("%s is bad for event name -it must " |
137 | "follow C symbol-naming rule.", arg); | 347 | "follow C symbol-naming rule.", arg); |
138 | pp->event = strdup(arg); | 348 | pev->event = xstrdup(arg); |
349 | pev->group = NULL; | ||
139 | arg = tmp; | 350 | arg = tmp; |
140 | } | 351 | } |
141 | 352 | ||
@@ -147,17 +358,16 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | |||
147 | 358 | ||
148 | /* Check arg is function or file and copy it */ | 359 | /* Check arg is function or file and copy it */ |
149 | if (strchr(arg, '.')) /* File */ | 360 | if (strchr(arg, '.')) /* File */ |
150 | pp->file = strdup(arg); | 361 | pp->file = xstrdup(arg); |
151 | else /* Function */ | 362 | else /* Function */ |
152 | pp->function = strdup(arg); | 363 | pp->function = xstrdup(arg); |
153 | DIE_IF(pp->file == NULL && pp->function == NULL); | ||
154 | 364 | ||
155 | /* Parse other options */ | 365 | /* Parse other options */ |
156 | while (ptr) { | 366 | while (ptr) { |
157 | arg = ptr; | 367 | arg = ptr; |
158 | c = nc; | 368 | c = nc; |
159 | if (c == ';') { /* Lazy pattern must be the last part */ | 369 | if (c == ';') { /* Lazy pattern must be the last part */ |
160 | pp->lazy_line = strdup(arg); | 370 | pp->lazy_line = xstrdup(arg); |
161 | break; | 371 | break; |
162 | } | 372 | } |
163 | ptr = strpbrk(arg, ";:+@%"); | 373 | ptr = strpbrk(arg, ";:+@%"); |
@@ -181,8 +391,7 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | |||
181 | case '@': /* File name */ | 391 | case '@': /* File name */ |
182 | if (pp->file) | 392 | if (pp->file) |
183 | semantic_error("SRC@SRC is not allowed."); | 393 | semantic_error("SRC@SRC is not allowed."); |
184 | pp->file = strdup(arg); | 394 | pp->file = xstrdup(arg); |
185 | DIE_IF(pp->file == NULL); | ||
186 | break; | 395 | break; |
187 | case '%': /* Probe places */ | 396 | case '%': /* Probe places */ |
188 | if (strcmp(arg, "return") == 0) { | 397 | if (strcmp(arg, "return") == 0) { |
@@ -220,59 +429,108 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | |||
220 | semantic_error("Offset/Line/Lazy pattern can't be used with " | 429 | semantic_error("Offset/Line/Lazy pattern can't be used with " |
221 | "return probe."); | 430 | "return probe."); |
222 | 431 | ||
223 | pr_debug("symbol:%s file:%s line:%d offset:%d return:%d lazy:%s\n", | 432 | pr_debug("symbol:%s file:%s line:%d offset:%lu return:%d lazy:%s\n", |
224 | pp->function, pp->file, pp->line, pp->offset, pp->retprobe, | 433 | pp->function, pp->file, pp->line, pp->offset, pp->retprobe, |
225 | pp->lazy_line); | 434 | pp->lazy_line); |
226 | } | 435 | } |
227 | 436 | ||
228 | /* Parse perf-probe event definition */ | 437 | /* Parse perf-probe event argument */ |
229 | void parse_perf_probe_event(const char *str, struct probe_point *pp, | 438 | static void parse_perf_probe_arg(const char *str, struct perf_probe_arg *arg) |
230 | bool *need_dwarf) | 439 | { |
440 | const char *tmp; | ||
441 | struct perf_probe_arg_field **fieldp; | ||
442 | |||
443 | pr_debug("parsing arg: %s into ", str); | ||
444 | |||
445 | tmp = strpbrk(str, "-."); | ||
446 | if (!is_c_varname(str) || !tmp) { | ||
447 | /* A variable, register, symbol or special value */ | ||
448 | arg->name = xstrdup(str); | ||
449 | pr_debug("%s\n", arg->name); | ||
450 | return; | ||
451 | } | ||
452 | |||
453 | /* Structure fields */ | ||
454 | arg->name = xstrndup(str, tmp - str); | ||
455 | pr_debug("%s, ", arg->name); | ||
456 | fieldp = &arg->field; | ||
457 | |||
458 | do { | ||
459 | *fieldp = xzalloc(sizeof(struct perf_probe_arg_field)); | ||
460 | if (*tmp == '.') { | ||
461 | str = tmp + 1; | ||
462 | (*fieldp)->ref = false; | ||
463 | } else if (tmp[1] == '>') { | ||
464 | str = tmp + 2; | ||
465 | (*fieldp)->ref = true; | ||
466 | } else | ||
467 | semantic_error("Argument parse error: %s", str); | ||
468 | |||
469 | tmp = strpbrk(str, "-."); | ||
470 | if (tmp) { | ||
471 | (*fieldp)->name = xstrndup(str, tmp - str); | ||
472 | pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); | ||
473 | fieldp = &(*fieldp)->next; | ||
474 | } | ||
475 | } while (tmp); | ||
476 | (*fieldp)->name = xstrdup(str); | ||
477 | pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); | ||
478 | } | ||
479 | |||
480 | /* Parse perf-probe event command */ | ||
481 | void parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev) | ||
231 | { | 482 | { |
232 | char **argv; | 483 | char **argv; |
233 | int argc, i; | 484 | int argc, i; |
234 | 485 | ||
235 | *need_dwarf = false; | 486 | argv = argv_split(cmd, &argc); |
236 | |||
237 | argv = argv_split(str, &argc); | ||
238 | if (!argv) | 487 | if (!argv) |
239 | die("argv_split failed."); | 488 | die("argv_split failed."); |
240 | if (argc > MAX_PROBE_ARGS + 1) | 489 | if (argc > MAX_PROBE_ARGS + 1) |
241 | semantic_error("Too many arguments"); | 490 | semantic_error("Too many arguments"); |
242 | 491 | ||
243 | /* Parse probe point */ | 492 | /* Parse probe point */ |
244 | parse_perf_probe_probepoint(argv[0], pp); | 493 | parse_perf_probe_point(argv[0], pev); |
245 | if (pp->file || pp->line || pp->lazy_line) | ||
246 | *need_dwarf = true; | ||
247 | 494 | ||
248 | /* Copy arguments and ensure return probe has no C argument */ | 495 | /* Copy arguments and ensure return probe has no C argument */ |
249 | pp->nr_args = argc - 1; | 496 | pev->nargs = argc - 1; |
250 | pp->args = zalloc(sizeof(char *) * pp->nr_args); | 497 | pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs); |
251 | for (i = 0; i < pp->nr_args; i++) { | 498 | for (i = 0; i < pev->nargs; i++) { |
252 | pp->args[i] = strdup(argv[i + 1]); | 499 | parse_perf_probe_arg(argv[i + 1], &pev->args[i]); |
253 | if (!pp->args[i]) | 500 | if (is_c_varname(pev->args[i].name) && pev->point.retprobe) |
254 | die("Failed to copy argument."); | 501 | semantic_error("You can't specify local variable for" |
255 | if (is_c_varname(pp->args[i])) { | 502 | " kretprobe"); |
256 | if (pp->retprobe) | ||
257 | semantic_error("You can't specify local" | ||
258 | " variable for kretprobe"); | ||
259 | *need_dwarf = true; | ||
260 | } | ||
261 | } | 503 | } |
262 | 504 | ||
263 | argv_free(argv); | 505 | argv_free(argv); |
264 | } | 506 | } |
265 | 507 | ||
508 | /* Return true if this perf_probe_event requires debuginfo */ | ||
509 | bool perf_probe_event_need_dwarf(struct perf_probe_event *pev) | ||
510 | { | ||
511 | int i; | ||
512 | |||
513 | if (pev->point.file || pev->point.line || pev->point.lazy_line) | ||
514 | return true; | ||
515 | |||
516 | for (i = 0; i < pev->nargs; i++) | ||
517 | if (is_c_varname(pev->args[i].name)) | ||
518 | return true; | ||
519 | |||
520 | return false; | ||
521 | } | ||
522 | |||
266 | /* Parse kprobe_events event into struct probe_point */ | 523 | /* Parse kprobe_events event into struct probe_point */ |
267 | void parse_trace_kprobe_event(const char *str, struct probe_point *pp) | 524 | void parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev) |
268 | { | 525 | { |
526 | struct kprobe_trace_point *tp = &tev->point; | ||
269 | char pr; | 527 | char pr; |
270 | char *p; | 528 | char *p; |
271 | int ret, i, argc; | 529 | int ret, i, argc; |
272 | char **argv; | 530 | char **argv; |
273 | 531 | ||
274 | pr_debug("Parsing kprobe_events: %s\n", str); | 532 | pr_debug("Parsing kprobe_events: %s\n", cmd); |
275 | argv = argv_split(str, &argc); | 533 | argv = argv_split(cmd, &argc); |
276 | if (!argv) | 534 | if (!argv) |
277 | die("argv_split failed."); | 535 | die("argv_split failed."); |
278 | if (argc < 2) | 536 | if (argc < 2) |
@@ -280,132 +538,314 @@ void parse_trace_kprobe_event(const char *str, struct probe_point *pp) | |||
280 | 538 | ||
281 | /* Scan event and group name. */ | 539 | /* Scan event and group name. */ |
282 | ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]", | 540 | ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]", |
283 | &pr, (float *)(void *)&pp->group, | 541 | &pr, (float *)(void *)&tev->group, |
284 | (float *)(void *)&pp->event); | 542 | (float *)(void *)&tev->event); |
285 | if (ret != 3) | 543 | if (ret != 3) |
286 | semantic_error("Failed to parse event name: %s", argv[0]); | 544 | semantic_error("Failed to parse event name: %s", argv[0]); |
287 | pr_debug("Group:%s Event:%s probe:%c\n", pp->group, pp->event, pr); | 545 | pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr); |
288 | 546 | ||
289 | pp->retprobe = (pr == 'r'); | 547 | tp->retprobe = (pr == 'r'); |
290 | 548 | ||
291 | /* Scan function name and offset */ | 549 | /* Scan function name and offset */ |
292 | ret = sscanf(argv[1], "%a[^+]+%d", (float *)(void *)&pp->function, | 550 | ret = sscanf(argv[1], "%a[^+]+%lu", (float *)(void *)&tp->symbol, |
293 | &pp->offset); | 551 | &tp->offset); |
294 | if (ret == 1) | 552 | if (ret == 1) |
295 | pp->offset = 0; | 553 | tp->offset = 0; |
296 | |||
297 | /* kprobe_events doesn't have this information */ | ||
298 | pp->line = 0; | ||
299 | pp->file = NULL; | ||
300 | 554 | ||
301 | pp->nr_args = argc - 2; | 555 | tev->nargs = argc - 2; |
302 | pp->args = zalloc(sizeof(char *) * pp->nr_args); | 556 | tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); |
303 | for (i = 0; i < pp->nr_args; i++) { | 557 | for (i = 0; i < tev->nargs; i++) { |
304 | p = strchr(argv[i + 2], '='); | 558 | p = strchr(argv[i + 2], '='); |
305 | if (p) /* We don't need which register is assigned. */ | 559 | if (p) /* We don't need which register is assigned. */ |
306 | *p = '\0'; | 560 | *p++ = '\0'; |
307 | pp->args[i] = strdup(argv[i + 2]); | 561 | else |
308 | if (!pp->args[i]) | 562 | p = argv[i + 2]; |
309 | die("Failed to copy argument."); | 563 | tev->args[i].name = xstrdup(argv[i + 2]); |
564 | /* TODO: parse regs and offset */ | ||
565 | tev->args[i].value = xstrdup(p); | ||
310 | } | 566 | } |
311 | 567 | ||
312 | argv_free(argv); | 568 | argv_free(argv); |
313 | } | 569 | } |
314 | 570 | ||
315 | /* Synthesize only probe point (not argument) */ | 571 | /* Compose only probe arg */ |
316 | int synthesize_perf_probe_point(struct probe_point *pp) | 572 | int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len) |
317 | { | 573 | { |
318 | char *buf; | 574 | struct perf_probe_arg_field *field = pa->field; |
319 | char offs[64] = "", line[64] = ""; | ||
320 | int ret; | 575 | int ret; |
576 | char *tmp = buf; | ||
321 | 577 | ||
322 | pp->probes[0] = buf = zalloc(MAX_CMDLEN); | 578 | ret = e_snprintf(tmp, len, "%s", pa->name); |
323 | pp->found = 1; | 579 | if (ret <= 0) |
324 | if (!buf) | 580 | goto error; |
325 | die("Failed to allocate memory by zalloc."); | 581 | tmp += ret; |
582 | len -= ret; | ||
583 | |||
584 | while (field) { | ||
585 | ret = e_snprintf(tmp, len, "%s%s", field->ref ? "->" : ".", | ||
586 | field->name); | ||
587 | if (ret <= 0) | ||
588 | goto error; | ||
589 | tmp += ret; | ||
590 | len -= ret; | ||
591 | field = field->next; | ||
592 | } | ||
593 | return tmp - buf; | ||
594 | error: | ||
595 | die("Failed to synthesize perf probe argument: %s", strerror(-ret)); | ||
596 | } | ||
597 | |||
598 | /* Compose only probe point (not argument) */ | ||
599 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp) | ||
600 | { | ||
601 | char *buf, *tmp; | ||
602 | char offs[32] = "", line[32] = "", file[32] = ""; | ||
603 | int ret, len; | ||
604 | |||
605 | buf = xzalloc(MAX_CMDLEN); | ||
326 | if (pp->offset) { | 606 | if (pp->offset) { |
327 | ret = e_snprintf(offs, 64, "+%d", pp->offset); | 607 | ret = e_snprintf(offs, 32, "+%lu", pp->offset); |
328 | if (ret <= 0) | 608 | if (ret <= 0) |
329 | goto error; | 609 | goto error; |
330 | } | 610 | } |
331 | if (pp->line) { | 611 | if (pp->line) { |
332 | ret = e_snprintf(line, 64, ":%d", pp->line); | 612 | ret = e_snprintf(line, 32, ":%d", pp->line); |
613 | if (ret <= 0) | ||
614 | goto error; | ||
615 | } | ||
616 | if (pp->file) { | ||
617 | len = strlen(pp->file) - 32; | ||
618 | if (len < 0) | ||
619 | len = 0; | ||
620 | tmp = strchr(pp->file + len, '/'); | ||
621 | if (!tmp) | ||
622 | tmp = pp->file + len - 1; | ||
623 | ret = e_snprintf(file, 32, "@%s", tmp + 1); | ||
333 | if (ret <= 0) | 624 | if (ret <= 0) |
334 | goto error; | 625 | goto error; |
335 | } | 626 | } |
336 | 627 | ||
337 | if (pp->function) | 628 | if (pp->function) |
338 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s", pp->function, | 629 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function, |
339 | offs, pp->retprobe ? "%return" : "", line); | 630 | offs, pp->retprobe ? "%return" : "", line, |
631 | file); | ||
340 | else | 632 | else |
341 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", pp->file, line); | 633 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line); |
342 | if (ret <= 0) { | 634 | if (ret <= 0) |
635 | goto error; | ||
636 | |||
637 | return buf; | ||
343 | error: | 638 | error: |
344 | free(pp->probes[0]); | 639 | die("Failed to synthesize perf probe point: %s", strerror(-ret)); |
345 | pp->probes[0] = NULL; | ||
346 | pp->found = 0; | ||
347 | } | ||
348 | return ret; | ||
349 | } | 640 | } |
350 | 641 | ||
351 | int synthesize_perf_probe_event(struct probe_point *pp) | 642 | #if 0 |
643 | char *synthesize_perf_probe_command(struct perf_probe_event *pev) | ||
352 | { | 644 | { |
353 | char *buf; | 645 | char *buf; |
354 | int i, len, ret; | 646 | int i, len, ret; |
355 | 647 | ||
356 | len = synthesize_perf_probe_point(pp); | 648 | buf = synthesize_perf_probe_point(&pev->point); |
357 | if (len < 0) | 649 | if (!buf) |
358 | return 0; | 650 | return NULL; |
359 | 651 | ||
360 | buf = pp->probes[0]; | 652 | len = strlen(buf); |
361 | for (i = 0; i < pp->nr_args; i++) { | 653 | for (i = 0; i < pev->nargs; i++) { |
362 | ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s", | 654 | ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s", |
363 | pp->args[i]); | 655 | pev->args[i].name); |
364 | if (ret <= 0) | 656 | if (ret <= 0) { |
365 | goto error; | 657 | free(buf); |
658 | return NULL; | ||
659 | } | ||
366 | len += ret; | 660 | len += ret; |
367 | } | 661 | } |
368 | pp->found = 1; | ||
369 | 662 | ||
370 | return pp->found; | 663 | return buf; |
371 | error: | 664 | } |
372 | free(pp->probes[0]); | 665 | #endif |
373 | pp->probes[0] = NULL; | ||
374 | 666 | ||
375 | return ret; | 667 | static int __synthesize_kprobe_trace_arg_ref(struct kprobe_trace_arg_ref *ref, |
668 | char **buf, size_t *buflen, | ||
669 | int depth) | ||
670 | { | ||
671 | int ret; | ||
672 | if (ref->next) { | ||
673 | depth = __synthesize_kprobe_trace_arg_ref(ref->next, buf, | ||
674 | buflen, depth + 1); | ||
675 | if (depth < 0) | ||
676 | goto out; | ||
677 | } | ||
678 | |||
679 | ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset); | ||
680 | if (ret < 0) | ||
681 | depth = ret; | ||
682 | else { | ||
683 | *buf += ret; | ||
684 | *buflen -= ret; | ||
685 | } | ||
686 | out: | ||
687 | return depth; | ||
688 | |||
689 | } | ||
690 | |||
691 | static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg, | ||
692 | char *buf, size_t buflen) | ||
693 | { | ||
694 | int ret, depth = 0; | ||
695 | char *tmp = buf; | ||
696 | |||
697 | /* Argument name or separator */ | ||
698 | if (arg->name) | ||
699 | ret = e_snprintf(buf, buflen, " %s=", arg->name); | ||
700 | else | ||
701 | ret = e_snprintf(buf, buflen, " "); | ||
702 | if (ret < 0) | ||
703 | return ret; | ||
704 | buf += ret; | ||
705 | buflen -= ret; | ||
706 | |||
707 | /* Dereferencing arguments */ | ||
708 | if (arg->ref) { | ||
709 | depth = __synthesize_kprobe_trace_arg_ref(arg->ref, &buf, | ||
710 | &buflen, 1); | ||
711 | if (depth < 0) | ||
712 | return depth; | ||
713 | } | ||
714 | |||
715 | /* Print argument value */ | ||
716 | ret = e_snprintf(buf, buflen, "%s", arg->value); | ||
717 | if (ret < 0) | ||
718 | return ret; | ||
719 | buf += ret; | ||
720 | buflen -= ret; | ||
721 | |||
722 | /* Closing */ | ||
723 | while (depth--) { | ||
724 | ret = e_snprintf(buf, buflen, ")"); | ||
725 | if (ret < 0) | ||
726 | return ret; | ||
727 | buf += ret; | ||
728 | buflen -= ret; | ||
729 | } | ||
730 | |||
731 | return buf - tmp; | ||
376 | } | 732 | } |
377 | 733 | ||
378 | int synthesize_trace_kprobe_event(struct probe_point *pp) | 734 | char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev) |
379 | { | 735 | { |
736 | struct kprobe_trace_point *tp = &tev->point; | ||
380 | char *buf; | 737 | char *buf; |
381 | int i, len, ret; | 738 | int i, len, ret; |
382 | 739 | ||
383 | pp->probes[0] = buf = zalloc(MAX_CMDLEN); | 740 | buf = xzalloc(MAX_CMDLEN); |
384 | if (!buf) | 741 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu", |
385 | die("Failed to allocate memory by zalloc."); | 742 | tp->retprobe ? 'r' : 'p', |
386 | ret = e_snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset); | 743 | tev->group, tev->event, |
387 | if (ret <= 0) | 744 | tp->symbol, tp->offset); |
745 | if (len <= 0) | ||
388 | goto error; | 746 | goto error; |
389 | len = ret; | ||
390 | 747 | ||
391 | for (i = 0; i < pp->nr_args; i++) { | 748 | for (i = 0; i < tev->nargs; i++) { |
392 | ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s", | 749 | ret = synthesize_kprobe_trace_arg(&tev->args[i], buf + len, |
393 | pp->args[i]); | 750 | MAX_CMDLEN - len); |
394 | if (ret <= 0) | 751 | if (ret <= 0) |
395 | goto error; | 752 | goto error; |
396 | len += ret; | 753 | len += ret; |
397 | } | 754 | } |
398 | pp->found = 1; | ||
399 | 755 | ||
400 | return pp->found; | 756 | return buf; |
401 | error: | 757 | error: |
402 | free(pp->probes[0]); | 758 | free(buf); |
403 | pp->probes[0] = NULL; | 759 | return NULL; |
760 | } | ||
404 | 761 | ||
405 | return ret; | 762 | void convert_to_perf_probe_event(struct kprobe_trace_event *tev, |
763 | struct perf_probe_event *pev) | ||
764 | { | ||
765 | char buf[64]; | ||
766 | int i; | ||
767 | |||
768 | /* Convert event/group name */ | ||
769 | pev->event = xstrdup(tev->event); | ||
770 | pev->group = xstrdup(tev->group); | ||
771 | |||
772 | /* Convert trace_point to probe_point */ | ||
773 | convert_to_perf_probe_point(&tev->point, &pev->point); | ||
774 | |||
775 | /* Convert trace_arg to probe_arg */ | ||
776 | pev->nargs = tev->nargs; | ||
777 | pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs); | ||
778 | for (i = 0; i < tev->nargs; i++) | ||
779 | if (tev->args[i].name) | ||
780 | pev->args[i].name = xstrdup(tev->args[i].name); | ||
781 | else { | ||
782 | synthesize_kprobe_trace_arg(&tev->args[i], buf, 64); | ||
783 | pev->args[i].name = xstrdup(buf); | ||
784 | } | ||
785 | } | ||
786 | |||
787 | void clear_perf_probe_event(struct perf_probe_event *pev) | ||
788 | { | ||
789 | struct perf_probe_point *pp = &pev->point; | ||
790 | struct perf_probe_arg_field *field, *next; | ||
791 | int i; | ||
792 | |||
793 | if (pev->event) | ||
794 | free(pev->event); | ||
795 | if (pev->group) | ||
796 | free(pev->group); | ||
797 | if (pp->file) | ||
798 | free(pp->file); | ||
799 | if (pp->function) | ||
800 | free(pp->function); | ||
801 | if (pp->lazy_line) | ||
802 | free(pp->lazy_line); | ||
803 | for (i = 0; i < pev->nargs; i++) { | ||
804 | if (pev->args[i].name) | ||
805 | free(pev->args[i].name); | ||
806 | field = pev->args[i].field; | ||
807 | while (field) { | ||
808 | next = field->next; | ||
809 | if (field->name) | ||
810 | free(field->name); | ||
811 | free(field); | ||
812 | field = next; | ||
813 | } | ||
814 | } | ||
815 | if (pev->args) | ||
816 | free(pev->args); | ||
817 | memset(pev, 0, sizeof(*pev)); | ||
406 | } | 818 | } |
407 | 819 | ||
408 | static int open_kprobe_events(int flags, int mode) | 820 | void clear_kprobe_trace_event(struct kprobe_trace_event *tev) |
821 | { | ||
822 | struct kprobe_trace_arg_ref *ref, *next; | ||
823 | int i; | ||
824 | |||
825 | if (tev->event) | ||
826 | free(tev->event); | ||
827 | if (tev->group) | ||
828 | free(tev->group); | ||
829 | if (tev->point.symbol) | ||
830 | free(tev->point.symbol); | ||
831 | for (i = 0; i < tev->nargs; i++) { | ||
832 | if (tev->args[i].name) | ||
833 | free(tev->args[i].name); | ||
834 | if (tev->args[i].value) | ||
835 | free(tev->args[i].value); | ||
836 | ref = tev->args[i].ref; | ||
837 | while (ref) { | ||
838 | next = ref->next; | ||
839 | free(ref); | ||
840 | ref = next; | ||
841 | } | ||
842 | } | ||
843 | if (tev->args) | ||
844 | free(tev->args); | ||
845 | memset(tev, 0, sizeof(*tev)); | ||
846 | } | ||
847 | |||
848 | static int open_kprobe_events(bool readwrite) | ||
409 | { | 849 | { |
410 | char buf[PATH_MAX]; | 850 | char buf[PATH_MAX]; |
411 | int ret; | 851 | int ret; |
@@ -414,7 +854,11 @@ static int open_kprobe_events(int flags, int mode) | |||
414 | if (ret < 0) | 854 | if (ret < 0) |
415 | die("Failed to make kprobe_events path."); | 855 | die("Failed to make kprobe_events path."); |
416 | 856 | ||
417 | ret = open(buf, flags, mode); | 857 | if (readwrite && !probe_event_dry_run) |
858 | ret = open(buf, O_RDWR, O_APPEND); | ||
859 | else | ||
860 | ret = open(buf, O_RDONLY, 0); | ||
861 | |||
418 | if (ret < 0) { | 862 | if (ret < 0) { |
419 | if (errno == ENOENT) | 863 | if (errno == ENOENT) |
420 | die("kprobe_events file does not exist -" | 864 | die("kprobe_events file does not exist -" |
@@ -427,7 +871,7 @@ static int open_kprobe_events(int flags, int mode) | |||
427 | } | 871 | } |
428 | 872 | ||
429 | /* Get raw string list of current kprobe_events */ | 873 | /* Get raw string list of current kprobe_events */ |
430 | static struct strlist *get_trace_kprobe_event_rawlist(int fd) | 874 | static struct strlist *get_kprobe_trace_command_rawlist(int fd) |
431 | { | 875 | { |
432 | int ret, idx; | 876 | int ret, idx; |
433 | FILE *fp; | 877 | FILE *fp; |
@@ -455,99 +899,85 @@ static struct strlist *get_trace_kprobe_event_rawlist(int fd) | |||
455 | return sl; | 899 | return sl; |
456 | } | 900 | } |
457 | 901 | ||
458 | /* Free and zero clear probe_point */ | ||
459 | static void clear_probe_point(struct probe_point *pp) | ||
460 | { | ||
461 | int i; | ||
462 | |||
463 | if (pp->event) | ||
464 | free(pp->event); | ||
465 | if (pp->group) | ||
466 | free(pp->group); | ||
467 | if (pp->function) | ||
468 | free(pp->function); | ||
469 | if (pp->file) | ||
470 | free(pp->file); | ||
471 | if (pp->lazy_line) | ||
472 | free(pp->lazy_line); | ||
473 | for (i = 0; i < pp->nr_args; i++) | ||
474 | free(pp->args[i]); | ||
475 | if (pp->args) | ||
476 | free(pp->args); | ||
477 | for (i = 0; i < pp->found; i++) | ||
478 | free(pp->probes[i]); | ||
479 | memset(pp, 0, sizeof(*pp)); | ||
480 | } | ||
481 | |||
482 | /* Show an event */ | 902 | /* Show an event */ |
483 | static void show_perf_probe_event(const char *event, const char *place, | 903 | static void show_perf_probe_event(struct perf_probe_event *pev) |
484 | struct probe_point *pp) | ||
485 | { | 904 | { |
486 | int i, ret; | 905 | int i, ret; |
487 | char buf[128]; | 906 | char buf[128]; |
907 | char *place; | ||
488 | 908 | ||
489 | ret = e_snprintf(buf, 128, "%s:%s", pp->group, event); | 909 | /* Synthesize only event probe point */ |
910 | place = synthesize_perf_probe_point(&pev->point); | ||
911 | |||
912 | ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event); | ||
490 | if (ret < 0) | 913 | if (ret < 0) |
491 | die("Failed to copy event: %s", strerror(-ret)); | 914 | die("Failed to copy event: %s", strerror(-ret)); |
492 | printf(" %-40s (on %s", buf, place); | 915 | printf(" %-20s (on %s", buf, place); |
493 | 916 | ||
494 | if (pp->nr_args > 0) { | 917 | if (pev->nargs > 0) { |
495 | printf(" with"); | 918 | printf(" with"); |
496 | for (i = 0; i < pp->nr_args; i++) | 919 | for (i = 0; i < pev->nargs; i++) { |
497 | printf(" %s", pp->args[i]); | 920 | synthesize_perf_probe_arg(&pev->args[i], buf, 128); |
921 | printf(" %s", buf); | ||
922 | } | ||
498 | } | 923 | } |
499 | printf(")\n"); | 924 | printf(")\n"); |
925 | free(place); | ||
500 | } | 926 | } |
501 | 927 | ||
502 | /* List up current perf-probe events */ | 928 | /* List up current perf-probe events */ |
503 | void show_perf_probe_events(void) | 929 | void show_perf_probe_events(void) |
504 | { | 930 | { |
505 | int fd; | 931 | int fd; |
506 | struct probe_point pp; | 932 | struct kprobe_trace_event tev; |
933 | struct perf_probe_event pev; | ||
507 | struct strlist *rawlist; | 934 | struct strlist *rawlist; |
508 | struct str_node *ent; | 935 | struct str_node *ent; |
509 | 936 | ||
510 | setup_pager(); | 937 | setup_pager(); |
511 | memset(&pp, 0, sizeof(pp)); | 938 | init_vmlinux(); |
939 | |||
940 | memset(&tev, 0, sizeof(tev)); | ||
941 | memset(&pev, 0, sizeof(pev)); | ||
512 | 942 | ||
513 | fd = open_kprobe_events(O_RDONLY, 0); | 943 | fd = open_kprobe_events(false); |
514 | rawlist = get_trace_kprobe_event_rawlist(fd); | 944 | rawlist = get_kprobe_trace_command_rawlist(fd); |
515 | close(fd); | 945 | close(fd); |
516 | 946 | ||
517 | strlist__for_each(ent, rawlist) { | 947 | strlist__for_each(ent, rawlist) { |
518 | parse_trace_kprobe_event(ent->s, &pp); | 948 | parse_kprobe_trace_command(ent->s, &tev); |
519 | /* Synthesize only event probe point */ | 949 | convert_to_perf_probe_event(&tev, &pev); |
520 | synthesize_perf_probe_point(&pp); | ||
521 | /* Show an event */ | 950 | /* Show an event */ |
522 | show_perf_probe_event(pp.event, pp.probes[0], &pp); | 951 | show_perf_probe_event(&pev); |
523 | clear_probe_point(&pp); | 952 | clear_perf_probe_event(&pev); |
953 | clear_kprobe_trace_event(&tev); | ||
524 | } | 954 | } |
525 | 955 | ||
526 | strlist__delete(rawlist); | 956 | strlist__delete(rawlist); |
527 | } | 957 | } |
528 | 958 | ||
529 | /* Get current perf-probe event names */ | 959 | /* Get current perf-probe event names */ |
530 | static struct strlist *get_perf_event_names(int fd, bool include_group) | 960 | static struct strlist *get_kprobe_trace_event_names(int fd, bool include_group) |
531 | { | 961 | { |
532 | char buf[128]; | 962 | char buf[128]; |
533 | struct strlist *sl, *rawlist; | 963 | struct strlist *sl, *rawlist; |
534 | struct str_node *ent; | 964 | struct str_node *ent; |
535 | struct probe_point pp; | 965 | struct kprobe_trace_event tev; |
536 | 966 | ||
537 | memset(&pp, 0, sizeof(pp)); | 967 | memset(&tev, 0, sizeof(tev)); |
538 | rawlist = get_trace_kprobe_event_rawlist(fd); | ||
539 | 968 | ||
969 | rawlist = get_kprobe_trace_command_rawlist(fd); | ||
540 | sl = strlist__new(true, NULL); | 970 | sl = strlist__new(true, NULL); |
541 | strlist__for_each(ent, rawlist) { | 971 | strlist__for_each(ent, rawlist) { |
542 | parse_trace_kprobe_event(ent->s, &pp); | 972 | parse_kprobe_trace_command(ent->s, &tev); |
543 | if (include_group) { | 973 | if (include_group) { |
544 | if (e_snprintf(buf, 128, "%s:%s", pp.group, | 974 | if (e_snprintf(buf, 128, "%s:%s", tev.group, |
545 | pp.event) < 0) | 975 | tev.event) < 0) |
546 | die("Failed to copy group:event name."); | 976 | die("Failed to copy group:event name."); |
547 | strlist__add(sl, buf); | 977 | strlist__add(sl, buf); |
548 | } else | 978 | } else |
549 | strlist__add(sl, pp.event); | 979 | strlist__add(sl, tev.event); |
550 | clear_probe_point(&pp); | 980 | clear_kprobe_trace_event(&tev); |
551 | } | 981 | } |
552 | 982 | ||
553 | strlist__delete(rawlist); | 983 | strlist__delete(rawlist); |
@@ -555,14 +985,18 @@ static struct strlist *get_perf_event_names(int fd, bool include_group) | |||
555 | return sl; | 985 | return sl; |
556 | } | 986 | } |
557 | 987 | ||
558 | static void write_trace_kprobe_event(int fd, const char *buf) | 988 | static void write_kprobe_trace_event(int fd, struct kprobe_trace_event *tev) |
559 | { | 989 | { |
560 | int ret; | 990 | int ret; |
991 | char *buf = synthesize_kprobe_trace_command(tev); | ||
561 | 992 | ||
562 | pr_debug("Writing event: %s\n", buf); | 993 | pr_debug("Writing event: %s\n", buf); |
563 | ret = write(fd, buf, strlen(buf)); | 994 | if (!probe_event_dry_run) { |
564 | if (ret <= 0) | 995 | ret = write(fd, buf, strlen(buf)); |
565 | die("Failed to write event: %s", strerror(errno)); | 996 | if (ret <= 0) |
997 | die("Failed to write event: %s", strerror(errno)); | ||
998 | } | ||
999 | free(buf); | ||
566 | } | 1000 | } |
567 | 1001 | ||
568 | static void get_new_event_name(char *buf, size_t len, const char *base, | 1002 | static void get_new_event_name(char *buf, size_t len, const char *base, |
@@ -595,65 +1029,145 @@ static void get_new_event_name(char *buf, size_t len, const char *base, | |||
595 | die("Too many events are on the same function."); | 1029 | die("Too many events are on the same function."); |
596 | } | 1030 | } |
597 | 1031 | ||
598 | void add_trace_kprobe_events(struct probe_point *probes, int nr_probes, | 1032 | static void __add_kprobe_trace_events(struct perf_probe_event *pev, |
599 | bool force_add) | 1033 | struct kprobe_trace_event *tevs, |
1034 | int ntevs, bool allow_suffix) | ||
600 | { | 1035 | { |
601 | int i, j, fd; | 1036 | int i, fd; |
602 | struct probe_point *pp; | 1037 | struct kprobe_trace_event *tev = NULL; |
603 | char buf[MAX_CMDLEN]; | 1038 | char buf[64]; |
604 | char event[64]; | 1039 | const char *event, *group; |
605 | struct strlist *namelist; | 1040 | struct strlist *namelist; |
606 | bool allow_suffix; | ||
607 | 1041 | ||
608 | fd = open_kprobe_events(O_RDWR, O_APPEND); | 1042 | fd = open_kprobe_events(true); |
609 | /* Get current event names */ | 1043 | /* Get current event names */ |
610 | namelist = get_perf_event_names(fd, false); | 1044 | namelist = get_kprobe_trace_event_names(fd, false); |
611 | 1045 | ||
612 | for (j = 0; j < nr_probes; j++) { | 1046 | printf("Add new event%s\n", (ntevs > 1) ? "s:" : ":"); |
613 | pp = probes + j; | 1047 | for (i = 0; i < ntevs; i++) { |
614 | if (!pp->event) | 1048 | tev = &tevs[i]; |
615 | pp->event = strdup(pp->function); | 1049 | if (pev->event) |
616 | if (!pp->group) | 1050 | event = pev->event; |
617 | pp->group = strdup(PERFPROBE_GROUP); | 1051 | else |
618 | DIE_IF(!pp->event || !pp->group); | 1052 | if (pev->point.function) |
619 | /* If force_add is true, suffix search is allowed */ | 1053 | event = pev->point.function; |
620 | allow_suffix = force_add; | 1054 | else |
621 | for (i = 0; i < pp->found; i++) { | 1055 | event = tev->point.symbol; |
622 | /* Get an unused new event name */ | 1056 | if (pev->group) |
623 | get_new_event_name(event, 64, pp->event, namelist, | 1057 | group = pev->group; |
624 | allow_suffix); | 1058 | else |
625 | snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n", | 1059 | group = PERFPROBE_GROUP; |
626 | pp->retprobe ? 'r' : 'p', | 1060 | |
627 | pp->group, event, | 1061 | /* Get an unused new event name */ |
628 | pp->probes[i]); | 1062 | get_new_event_name(buf, 64, event, namelist, allow_suffix); |
629 | write_trace_kprobe_event(fd, buf); | 1063 | event = buf; |
630 | printf("Added new event:\n"); | 1064 | |
631 | /* Get the first parameter (probe-point) */ | 1065 | tev->event = xstrdup(event); |
632 | sscanf(pp->probes[i], "%s", buf); | 1066 | tev->group = xstrdup(group); |
633 | show_perf_probe_event(event, buf, pp); | 1067 | write_kprobe_trace_event(fd, tev); |
634 | /* Add added event name to namelist */ | 1068 | /* Add added event name to namelist */ |
635 | strlist__add(namelist, event); | 1069 | strlist__add(namelist, event); |
636 | /* | 1070 | |
637 | * Probes after the first probe which comes from same | 1071 | /* Trick here - save current event/group */ |
638 | * user input are always allowed to add suffix, because | 1072 | event = pev->event; |
639 | * there might be several addresses corresponding to | 1073 | group = pev->group; |
640 | * one code line. | 1074 | pev->event = tev->event; |
641 | */ | 1075 | pev->group = tev->group; |
642 | allow_suffix = true; | 1076 | show_perf_probe_event(pev); |
643 | } | 1077 | /* Trick here - restore current event/group */ |
1078 | pev->event = (char *)event; | ||
1079 | pev->group = (char *)group; | ||
1080 | |||
1081 | /* | ||
1082 | * Probes after the first probe which comes from same | ||
1083 | * user input are always allowed to add suffix, because | ||
1084 | * there might be several addresses corresponding to | ||
1085 | * one code line. | ||
1086 | */ | ||
1087 | allow_suffix = true; | ||
644 | } | 1088 | } |
645 | /* Show how to use the event. */ | 1089 | /* Show how to use the event. */ |
646 | printf("\nYou can now use it on all perf tools, such as:\n\n"); | 1090 | printf("\nYou can now use it on all perf tools, such as:\n\n"); |
647 | printf("\tperf record -e %s:%s -a sleep 1\n\n", PERFPROBE_GROUP, event); | 1091 | printf("\tperf record -e %s:%s -a sleep 1\n\n", tev->group, tev->event); |
648 | 1092 | ||
649 | strlist__delete(namelist); | 1093 | strlist__delete(namelist); |
650 | close(fd); | 1094 | close(fd); |
651 | } | 1095 | } |
652 | 1096 | ||
1097 | static int convert_to_kprobe_trace_events(struct perf_probe_event *pev, | ||
1098 | struct kprobe_trace_event **tevs) | ||
1099 | { | ||
1100 | struct symbol *sym; | ||
1101 | int ntevs = 0, i; | ||
1102 | struct kprobe_trace_event *tev; | ||
1103 | |||
1104 | /* Convert perf_probe_event with debuginfo */ | ||
1105 | ntevs = try_to_find_kprobe_trace_events(pev, tevs); | ||
1106 | if (ntevs > 0) | ||
1107 | return ntevs; | ||
1108 | |||
1109 | /* Allocate trace event buffer */ | ||
1110 | ntevs = 1; | ||
1111 | tev = *tevs = xzalloc(sizeof(struct kprobe_trace_event)); | ||
1112 | |||
1113 | /* Copy parameters */ | ||
1114 | tev->point.symbol = xstrdup(pev->point.function); | ||
1115 | tev->point.offset = pev->point.offset; | ||
1116 | tev->nargs = pev->nargs; | ||
1117 | if (tev->nargs) { | ||
1118 | tev->args = xzalloc(sizeof(struct kprobe_trace_arg) | ||
1119 | * tev->nargs); | ||
1120 | for (i = 0; i < tev->nargs; i++) | ||
1121 | tev->args[i].value = xstrdup(pev->args[i].name); | ||
1122 | } | ||
1123 | |||
1124 | /* Currently just checking function name from symbol map */ | ||
1125 | sym = map__find_symbol_by_name(kmaps[MAP__FUNCTION], | ||
1126 | tev->point.symbol, NULL); | ||
1127 | if (!sym) | ||
1128 | die("Kernel symbol \'%s\' not found - probe not added.", | ||
1129 | tev->point.symbol); | ||
1130 | |||
1131 | return ntevs; | ||
1132 | } | ||
1133 | |||
1134 | struct __event_package { | ||
1135 | struct perf_probe_event *pev; | ||
1136 | struct kprobe_trace_event *tevs; | ||
1137 | int ntevs; | ||
1138 | }; | ||
1139 | |||
1140 | void add_perf_probe_events(struct perf_probe_event *pevs, int npevs, | ||
1141 | bool force_add) | ||
1142 | { | ||
1143 | int i; | ||
1144 | struct __event_package *pkgs; | ||
1145 | |||
1146 | pkgs = xzalloc(sizeof(struct __event_package) * npevs); | ||
1147 | |||
1148 | /* Init vmlinux path */ | ||
1149 | init_vmlinux(); | ||
1150 | |||
1151 | /* Loop 1: convert all events */ | ||
1152 | for (i = 0; i < npevs; i++) { | ||
1153 | pkgs[i].pev = &pevs[i]; | ||
1154 | /* Convert with or without debuginfo */ | ||
1155 | pkgs[i].ntevs = convert_to_kprobe_trace_events(pkgs[i].pev, | ||
1156 | &pkgs[i].tevs); | ||
1157 | } | ||
1158 | |||
1159 | /* Loop 2: add all events */ | ||
1160 | for (i = 0; i < npevs; i++) | ||
1161 | __add_kprobe_trace_events(pkgs[i].pev, pkgs[i].tevs, | ||
1162 | pkgs[i].ntevs, force_add); | ||
1163 | /* TODO: cleanup all trace events? */ | ||
1164 | } | ||
1165 | |||
653 | static void __del_trace_kprobe_event(int fd, struct str_node *ent) | 1166 | static void __del_trace_kprobe_event(int fd, struct str_node *ent) |
654 | { | 1167 | { |
655 | char *p; | 1168 | char *p; |
656 | char buf[128]; | 1169 | char buf[128]; |
1170 | int ret; | ||
657 | 1171 | ||
658 | /* Convert from perf-probe event to trace-kprobe event */ | 1172 | /* Convert from perf-probe event to trace-kprobe event */ |
659 | if (e_snprintf(buf, 128, "-:%s", ent->s) < 0) | 1173 | if (e_snprintf(buf, 128, "-:%s", ent->s) < 0) |
@@ -663,7 +1177,10 @@ static void __del_trace_kprobe_event(int fd, struct str_node *ent) | |||
663 | die("Internal error: %s should have ':' but not.", ent->s); | 1177 | die("Internal error: %s should have ':' but not.", ent->s); |
664 | *p = '/'; | 1178 | *p = '/'; |
665 | 1179 | ||
666 | write_trace_kprobe_event(fd, buf); | 1180 | pr_debug("Writing event: %s\n", buf); |
1181 | ret = write(fd, buf, strlen(buf)); | ||
1182 | if (ret <= 0) | ||
1183 | die("Failed to write event: %s", strerror(errno)); | ||
667 | printf("Remove event: %s\n", ent->s); | 1184 | printf("Remove event: %s\n", ent->s); |
668 | } | 1185 | } |
669 | 1186 | ||
@@ -696,7 +1213,7 @@ static void del_trace_kprobe_event(int fd, const char *group, | |||
696 | pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf); | 1213 | pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf); |
697 | } | 1214 | } |
698 | 1215 | ||
699 | void del_trace_kprobe_events(struct strlist *dellist) | 1216 | void del_perf_probe_events(struct strlist *dellist) |
700 | { | 1217 | { |
701 | int fd; | 1218 | int fd; |
702 | const char *group, *event; | 1219 | const char *group, *event; |
@@ -704,14 +1221,12 @@ void del_trace_kprobe_events(struct strlist *dellist) | |||
704 | struct str_node *ent; | 1221 | struct str_node *ent; |
705 | struct strlist *namelist; | 1222 | struct strlist *namelist; |
706 | 1223 | ||
707 | fd = open_kprobe_events(O_RDWR, O_APPEND); | 1224 | fd = open_kprobe_events(true); |
708 | /* Get current event names */ | 1225 | /* Get current event names */ |
709 | namelist = get_perf_event_names(fd, true); | 1226 | namelist = get_kprobe_trace_event_names(fd, true); |
710 | 1227 | ||
711 | strlist__for_each(ent, dellist) { | 1228 | strlist__for_each(ent, dellist) { |
712 | str = strdup(ent->s); | 1229 | str = xstrdup(ent->s); |
713 | if (!str) | ||
714 | die("Failed to copy event."); | ||
715 | pr_debug("Parsing: %s\n", str); | 1230 | pr_debug("Parsing: %s\n", str); |
716 | p = strchr(str, ':'); | 1231 | p = strchr(str, ':'); |
717 | if (p) { | 1232 | if (p) { |
@@ -730,73 +1245,3 @@ void del_trace_kprobe_events(struct strlist *dellist) | |||
730 | close(fd); | 1245 | close(fd); |
731 | } | 1246 | } |
732 | 1247 | ||
733 | #define LINEBUF_SIZE 256 | ||
734 | #define NR_ADDITIONAL_LINES 2 | ||
735 | |||
736 | static void show_one_line(FILE *fp, unsigned int l, bool skip, bool show_num) | ||
737 | { | ||
738 | char buf[LINEBUF_SIZE]; | ||
739 | const char *color = PERF_COLOR_BLUE; | ||
740 | |||
741 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) | ||
742 | goto error; | ||
743 | if (!skip) { | ||
744 | if (show_num) | ||
745 | fprintf(stdout, "%7u %s", l, buf); | ||
746 | else | ||
747 | color_fprintf(stdout, color, " %s", buf); | ||
748 | } | ||
749 | |||
750 | while (strlen(buf) == LINEBUF_SIZE - 1 && | ||
751 | buf[LINEBUF_SIZE - 2] != '\n') { | ||
752 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) | ||
753 | goto error; | ||
754 | if (!skip) { | ||
755 | if (show_num) | ||
756 | fprintf(stdout, "%s", buf); | ||
757 | else | ||
758 | color_fprintf(stdout, color, "%s", buf); | ||
759 | } | ||
760 | } | ||
761 | return; | ||
762 | error: | ||
763 | if (feof(fp)) | ||
764 | die("Source file is shorter than expected."); | ||
765 | else | ||
766 | die("File read error: %s", strerror(errno)); | ||
767 | } | ||
768 | |||
769 | void show_line_range(struct line_range *lr) | ||
770 | { | ||
771 | unsigned int l = 1; | ||
772 | struct line_node *ln; | ||
773 | FILE *fp; | ||
774 | |||
775 | setup_pager(); | ||
776 | |||
777 | if (lr->function) | ||
778 | fprintf(stdout, "<%s:%d>\n", lr->function, | ||
779 | lr->start - lr->offset); | ||
780 | else | ||
781 | fprintf(stdout, "<%s:%d>\n", lr->file, lr->start); | ||
782 | |||
783 | fp = fopen(lr->path, "r"); | ||
784 | if (fp == NULL) | ||
785 | die("Failed to open %s: %s", lr->path, strerror(errno)); | ||
786 | /* Skip to starting line number */ | ||
787 | while (l < lr->start) | ||
788 | show_one_line(fp, l++, true, false); | ||
789 | |||
790 | list_for_each_entry(ln, &lr->line_list, list) { | ||
791 | while (ln->line > l) | ||
792 | show_one_line(fp, (l++) - lr->offset, false, false); | ||
793 | show_one_line(fp, (l++) - lr->offset, false, true); | ||
794 | } | ||
795 | |||
796 | if (lr->end == INT_MAX) | ||
797 | lr->end = l + NR_ADDITIONAL_LINES; | ||
798 | while (l < lr->end && !feof(fp)) | ||
799 | show_one_line(fp, (l++) - lr->offset, false, false); | ||
800 | |||
801 | fclose(fp); | ||
802 | } | ||
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 711287d4bae..cd308b0a4d9 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h | |||
@@ -2,22 +2,123 @@ | |||
2 | #define _PROBE_EVENT_H | 2 | #define _PROBE_EVENT_H |
3 | 3 | ||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include "probe-finder.h" | ||
6 | #include "strlist.h" | 5 | #include "strlist.h" |
7 | 6 | ||
8 | extern void parse_line_range_desc(const char *arg, struct line_range *lr); | 7 | extern bool probe_event_dry_run; |
9 | extern void parse_perf_probe_event(const char *str, struct probe_point *pp, | 8 | |
10 | bool *need_dwarf); | 9 | /* kprobe-tracer tracing point */ |
11 | extern int synthesize_perf_probe_point(struct probe_point *pp); | 10 | struct kprobe_trace_point { |
12 | extern int synthesize_perf_probe_event(struct probe_point *pp); | 11 | char *symbol; /* Base symbol */ |
13 | extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp); | 12 | unsigned long offset; /* Offset from symbol */ |
14 | extern int synthesize_trace_kprobe_event(struct probe_point *pp); | 13 | bool retprobe; /* Return probe flag */ |
15 | extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes, | 14 | }; |
16 | bool force_add); | 15 | |
17 | extern void del_trace_kprobe_events(struct strlist *dellist); | 16 | /* kprobe-tracer tracing argument referencing offset */ |
17 | struct kprobe_trace_arg_ref { | ||
18 | struct kprobe_trace_arg_ref *next; /* Next reference */ | ||
19 | long offset; /* Offset value */ | ||
20 | }; | ||
21 | |||
22 | /* kprobe-tracer tracing argument */ | ||
23 | struct kprobe_trace_arg { | ||
24 | char *name; /* Argument name */ | ||
25 | char *value; /* Base value */ | ||
26 | struct kprobe_trace_arg_ref *ref; /* Referencing offset */ | ||
27 | }; | ||
28 | |||
29 | /* kprobe-tracer tracing event (point + arg) */ | ||
30 | struct kprobe_trace_event { | ||
31 | char *event; /* Event name */ | ||
32 | char *group; /* Group name */ | ||
33 | struct kprobe_trace_point point; /* Trace point */ | ||
34 | int nargs; /* Number of args */ | ||
35 | struct kprobe_trace_arg *args; /* Arguments */ | ||
36 | }; | ||
37 | |||
38 | /* Perf probe probing point */ | ||
39 | struct perf_probe_point { | ||
40 | char *file; /* File path */ | ||
41 | char *function; /* Function name */ | ||
42 | int line; /* Line number */ | ||
43 | char *lazy_line; /* Lazy matching pattern */ | ||
44 | unsigned long offset; /* Offset from function entry */ | ||
45 | bool retprobe; /* Return probe flag */ | ||
46 | }; | ||
47 | |||
48 | /* Perf probe probing argument field chain */ | ||
49 | struct perf_probe_arg_field { | ||
50 | struct perf_probe_arg_field *next; /* Next field */ | ||
51 | char *name; /* Name of the field */ | ||
52 | bool ref; /* Referencing flag */ | ||
53 | }; | ||
54 | |||
55 | /* Perf probe probing argument */ | ||
56 | struct perf_probe_arg { | ||
57 | char *name; /* Argument name */ | ||
58 | struct perf_probe_arg_field *field; /* Structure fields */ | ||
59 | }; | ||
60 | |||
61 | /* Perf probe probing event (point + arg) */ | ||
62 | struct perf_probe_event { | ||
63 | char *event; /* Event name */ | ||
64 | char *group; /* Group name */ | ||
65 | struct perf_probe_point point; /* Probe point */ | ||
66 | int nargs; /* Number of arguments */ | ||
67 | struct perf_probe_arg *args; /* Arguments */ | ||
68 | }; | ||
69 | |||
70 | |||
71 | /* Line number container */ | ||
72 | struct line_node { | ||
73 | struct list_head list; | ||
74 | unsigned int line; | ||
75 | }; | ||
76 | |||
77 | /* Line range */ | ||
78 | struct line_range { | ||
79 | char *file; /* File name */ | ||
80 | char *function; /* Function name */ | ||
81 | unsigned int start; /* Start line number */ | ||
82 | unsigned int end; /* End line number */ | ||
83 | int offset; /* Start line offset */ | ||
84 | char *path; /* Real path name */ | ||
85 | struct list_head line_list; /* Visible lines */ | ||
86 | }; | ||
87 | |||
88 | /* Command string to events */ | ||
89 | extern void parse_perf_probe_command(const char *cmd, | ||
90 | struct perf_probe_event *pev); | ||
91 | extern void parse_kprobe_trace_command(const char *cmd, | ||
92 | struct kprobe_trace_event *tev); | ||
93 | |||
94 | /* Events to command string */ | ||
95 | extern char *synthesize_perf_probe_command(struct perf_probe_event *pev); | ||
96 | extern char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev); | ||
97 | extern int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, | ||
98 | size_t len); | ||
99 | |||
100 | /* Check the perf_probe_event needs debuginfo */ | ||
101 | extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev); | ||
102 | |||
103 | /* Convert from kprobe_trace_event to perf_probe_event */ | ||
104 | extern void convert_to_perf_probe_event(struct kprobe_trace_event *tev, | ||
105 | struct perf_probe_event *pev); | ||
106 | |||
107 | /* Release event contents */ | ||
108 | extern void clear_perf_probe_event(struct perf_probe_event *pev); | ||
109 | extern void clear_kprobe_trace_event(struct kprobe_trace_event *tev); | ||
110 | |||
111 | /* Command string to line-range */ | ||
112 | extern void parse_line_range_desc(const char *cmd, struct line_range *lr); | ||
113 | |||
114 | |||
115 | extern void add_perf_probe_events(struct perf_probe_event *pevs, int ntevs, | ||
116 | bool force_add); | ||
117 | extern void del_perf_probe_events(struct strlist *dellist); | ||
18 | extern void show_perf_probe_events(void); | 118 | extern void show_perf_probe_events(void); |
19 | extern void show_line_range(struct line_range *lr); | 119 | extern void show_line_range(struct line_range *lr); |
20 | 120 | ||
121 | |||
21 | /* Maximum index number of event-name postfix */ | 122 | /* Maximum index number of event-name postfix */ |
22 | #define MAX_EVENT_INDEX 1024 | 123 | #define MAX_EVENT_INDEX 1024 |
23 | 124 | ||
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index c171a243d05..a8513772df0 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -125,8 +125,7 @@ static void line_list__add_line(struct list_head *head, unsigned int line) | |||
125 | p = head; | 125 | p = head; |
126 | found: | 126 | found: |
127 | pr_debug("line list: add a line %u\n", line); | 127 | pr_debug("line list: add a line %u\n", line); |
128 | ln = zalloc(sizeof(struct line_node)); | 128 | ln = xzalloc(sizeof(struct line_node)); |
129 | DIE_IF(ln == NULL); | ||
130 | ln->line = line; | 129 | ln->line = line; |
131 | INIT_LIST_HEAD(&ln->list); | 130 | INIT_LIST_HEAD(&ln->list); |
132 | list_add(&ln->list, p); | 131 | list_add(&ln->list, p); |
@@ -184,9 +183,89 @@ static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname) | |||
184 | if (strtailcmp(src, fname) == 0) | 183 | if (strtailcmp(src, fname) == 0) |
185 | break; | 184 | break; |
186 | } | 185 | } |
186 | if (i == nfiles) | ||
187 | return NULL; | ||
187 | return src; | 188 | return src; |
188 | } | 189 | } |
189 | 190 | ||
191 | /* Compare diename and tname */ | ||
192 | static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) | ||
193 | { | ||
194 | const char *name; | ||
195 | name = dwarf_diename(dw_die); | ||
196 | DIE_IF(name == NULL); | ||
197 | return strcmp(tname, name); | ||
198 | } | ||
199 | |||
200 | /* Get entry pc(or low pc, 1st entry of ranges) of the die */ | ||
201 | static Dwarf_Addr die_get_entrypc(Dwarf_Die *dw_die) | ||
202 | { | ||
203 | Dwarf_Addr epc; | ||
204 | int ret; | ||
205 | |||
206 | ret = dwarf_entrypc(dw_die, &epc); | ||
207 | DIE_IF(ret == -1); | ||
208 | return epc; | ||
209 | } | ||
210 | |||
211 | /* Get type die, but skip qualifiers and typedef */ | ||
212 | static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
213 | { | ||
214 | Dwarf_Attribute attr; | ||
215 | int tag; | ||
216 | |||
217 | do { | ||
218 | if (dwarf_attr(vr_die, DW_AT_type, &attr) == NULL || | ||
219 | dwarf_formref_die(&attr, die_mem) == NULL) | ||
220 | return NULL; | ||
221 | |||
222 | tag = dwarf_tag(die_mem); | ||
223 | vr_die = die_mem; | ||
224 | } while (tag == DW_TAG_const_type || | ||
225 | tag == DW_TAG_restrict_type || | ||
226 | tag == DW_TAG_volatile_type || | ||
227 | tag == DW_TAG_shared_type || | ||
228 | tag == DW_TAG_typedef); | ||
229 | |||
230 | return die_mem; | ||
231 | } | ||
232 | |||
233 | /* Return values for die_find callbacks */ | ||
234 | enum { | ||
235 | DIE_FIND_CB_FOUND = 0, /* End of Search */ | ||
236 | DIE_FIND_CB_CHILD = 1, /* Search only children */ | ||
237 | DIE_FIND_CB_SIBLING = 2, /* Search only siblings */ | ||
238 | DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */ | ||
239 | }; | ||
240 | |||
241 | /* Search a child die */ | ||
242 | static Dwarf_Die *die_find_child(Dwarf_Die *rt_die, | ||
243 | int (*callback)(Dwarf_Die *, void *), | ||
244 | void *data, Dwarf_Die *die_mem) | ||
245 | { | ||
246 | Dwarf_Die child_die; | ||
247 | int ret; | ||
248 | |||
249 | ret = dwarf_child(rt_die, die_mem); | ||
250 | if (ret != 0) | ||
251 | return NULL; | ||
252 | |||
253 | do { | ||
254 | ret = callback(die_mem, data); | ||
255 | if (ret == DIE_FIND_CB_FOUND) | ||
256 | return die_mem; | ||
257 | |||
258 | if ((ret & DIE_FIND_CB_CHILD) && | ||
259 | die_find_child(die_mem, callback, data, &child_die)) { | ||
260 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); | ||
261 | return die_mem; | ||
262 | } | ||
263 | } while ((ret & DIE_FIND_CB_SIBLING) && | ||
264 | dwarf_siblingof(die_mem, die_mem) == 0); | ||
265 | |||
266 | return NULL; | ||
267 | } | ||
268 | |||
190 | struct __addr_die_search_param { | 269 | struct __addr_die_search_param { |
191 | Dwarf_Addr addr; | 270 | Dwarf_Addr addr; |
192 | Dwarf_Die *die_mem; | 271 | Dwarf_Die *die_mem; |
@@ -205,8 +284,8 @@ static int __die_search_func_cb(Dwarf_Die *fn_die, void *data) | |||
205 | } | 284 | } |
206 | 285 | ||
207 | /* Search a real subprogram including this line, */ | 286 | /* Search a real subprogram including this line, */ |
208 | static Dwarf_Die *die_get_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr, | 287 | static Dwarf_Die *die_find_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr, |
209 | Dwarf_Die *die_mem) | 288 | Dwarf_Die *die_mem) |
210 | { | 289 | { |
211 | struct __addr_die_search_param ad; | 290 | struct __addr_die_search_param ad; |
212 | ad.addr = addr; | 291 | ad.addr = addr; |
@@ -218,77 +297,64 @@ static Dwarf_Die *die_get_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr, | |||
218 | return die_mem; | 297 | return die_mem; |
219 | } | 298 | } |
220 | 299 | ||
221 | /* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */ | 300 | /* die_find callback for inline function search */ |
222 | static Dwarf_Die *die_get_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, | 301 | static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data) |
223 | Dwarf_Die *die_mem) | ||
224 | { | 302 | { |
225 | Dwarf_Die child_die; | 303 | Dwarf_Addr *addr = data; |
226 | int ret; | ||
227 | |||
228 | ret = dwarf_child(sp_die, die_mem); | ||
229 | if (ret != 0) | ||
230 | return NULL; | ||
231 | 304 | ||
232 | do { | 305 | if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine && |
233 | if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine && | 306 | dwarf_haspc(die_mem, *addr)) |
234 | dwarf_haspc(die_mem, addr)) | 307 | return DIE_FIND_CB_FOUND; |
235 | return die_mem; | ||
236 | 308 | ||
237 | if (die_get_inlinefunc(die_mem, addr, &child_die)) { | 309 | return DIE_FIND_CB_CONTINUE; |
238 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); | ||
239 | return die_mem; | ||
240 | } | ||
241 | } while (dwarf_siblingof(die_mem, die_mem) == 0); | ||
242 | |||
243 | return NULL; | ||
244 | } | 310 | } |
245 | 311 | ||
246 | /* Compare diename and tname */ | 312 | /* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */ |
247 | static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) | 313 | static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, |
314 | Dwarf_Die *die_mem) | ||
248 | { | 315 | { |
249 | const char *name; | 316 | return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem); |
250 | name = dwarf_diename(dw_die); | ||
251 | DIE_IF(name == NULL); | ||
252 | return strcmp(tname, name); | ||
253 | } | 317 | } |
254 | 318 | ||
255 | /* Get entry pc(or low pc, 1st entry of ranges) of the die */ | 319 | static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) |
256 | static Dwarf_Addr die_get_entrypc(Dwarf_Die *dw_die) | ||
257 | { | 320 | { |
258 | Dwarf_Addr epc; | 321 | const char *name = data; |
259 | int ret; | 322 | int tag; |
260 | 323 | ||
261 | ret = dwarf_entrypc(dw_die, &epc); | 324 | tag = dwarf_tag(die_mem); |
262 | DIE_IF(ret == -1); | 325 | if ((tag == DW_TAG_formal_parameter || |
263 | return epc; | 326 | tag == DW_TAG_variable) && |
327 | (die_compare_name(die_mem, name) == 0)) | ||
328 | return DIE_FIND_CB_FOUND; | ||
329 | |||
330 | return DIE_FIND_CB_CONTINUE; | ||
264 | } | 331 | } |
265 | 332 | ||
266 | /* Get a variable die */ | 333 | /* Find a variable called 'name' */ |
267 | static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name, | 334 | static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name, |
268 | Dwarf_Die *die_mem) | 335 | Dwarf_Die *die_mem) |
269 | { | 336 | { |
270 | Dwarf_Die child_die; | 337 | return die_find_child(sp_die, __die_find_variable_cb, (void *)name, |
271 | int tag; | 338 | die_mem); |
272 | int ret; | 339 | } |
273 | 340 | ||
274 | ret = dwarf_child(sp_die, die_mem); | 341 | static int __die_find_member_cb(Dwarf_Die *die_mem, void *data) |
275 | if (ret != 0) | 342 | { |
276 | return NULL; | 343 | const char *name = data; |
277 | 344 | ||
278 | do { | 345 | if ((dwarf_tag(die_mem) == DW_TAG_member) && |
279 | tag = dwarf_tag(die_mem); | 346 | (die_compare_name(die_mem, name) == 0)) |
280 | if ((tag == DW_TAG_formal_parameter || | 347 | return DIE_FIND_CB_FOUND; |
281 | tag == DW_TAG_variable) && | ||
282 | (die_compare_name(die_mem, name) == 0)) | ||
283 | return die_mem; | ||
284 | 348 | ||
285 | if (die_find_variable(die_mem, name, &child_die)) { | 349 | return DIE_FIND_CB_SIBLING; |
286 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); | 350 | } |
287 | return die_mem; | ||
288 | } | ||
289 | } while (dwarf_siblingof(die_mem, die_mem) == 0); | ||
290 | 351 | ||
291 | return NULL; | 352 | /* Find a member called 'name' */ |
353 | static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, | ||
354 | Dwarf_Die *die_mem) | ||
355 | { | ||
356 | return die_find_child(st_die, __die_find_member_cb, (void *)name, | ||
357 | die_mem); | ||
292 | } | 358 | } |
293 | 359 | ||
294 | /* | 360 | /* |
@@ -296,19 +362,20 @@ static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name, | |||
296 | */ | 362 | */ |
297 | 363 | ||
298 | /* Show a location */ | 364 | /* Show a location */ |
299 | static void show_location(Dwarf_Op *op, struct probe_finder *pf) | 365 | static void convert_location(Dwarf_Op *op, struct probe_finder *pf) |
300 | { | 366 | { |
301 | unsigned int regn; | 367 | unsigned int regn; |
302 | Dwarf_Word offs = 0; | 368 | Dwarf_Word offs = 0; |
303 | int deref = 0, ret; | 369 | bool ref = false; |
304 | const char *regs; | 370 | const char *regs; |
371 | struct kprobe_trace_arg *tvar = pf->tvar; | ||
305 | 372 | ||
306 | /* TODO: support CFA */ | 373 | /* TODO: support CFA */ |
307 | /* If this is based on frame buffer, set the offset */ | 374 | /* If this is based on frame buffer, set the offset */ |
308 | if (op->atom == DW_OP_fbreg) { | 375 | if (op->atom == DW_OP_fbreg) { |
309 | if (pf->fb_ops == NULL) | 376 | if (pf->fb_ops == NULL) |
310 | die("The attribute of frame base is not supported.\n"); | 377 | die("The attribute of frame base is not supported.\n"); |
311 | deref = 1; | 378 | ref = true; |
312 | offs = op->number; | 379 | offs = op->number; |
313 | op = &pf->fb_ops[0]; | 380 | op = &pf->fb_ops[0]; |
314 | } | 381 | } |
@@ -316,13 +383,13 @@ static void show_location(Dwarf_Op *op, struct probe_finder *pf) | |||
316 | if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { | 383 | if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { |
317 | regn = op->atom - DW_OP_breg0; | 384 | regn = op->atom - DW_OP_breg0; |
318 | offs += op->number; | 385 | offs += op->number; |
319 | deref = 1; | 386 | ref = true; |
320 | } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) { | 387 | } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) { |
321 | regn = op->atom - DW_OP_reg0; | 388 | regn = op->atom - DW_OP_reg0; |
322 | } else if (op->atom == DW_OP_bregx) { | 389 | } else if (op->atom == DW_OP_bregx) { |
323 | regn = op->number; | 390 | regn = op->number; |
324 | offs += op->number2; | 391 | offs += op->number2; |
325 | deref = 1; | 392 | ref = true; |
326 | } else if (op->atom == DW_OP_regx) { | 393 | } else if (op->atom == DW_OP_regx) { |
327 | regn = op->number; | 394 | regn = op->number; |
328 | } else | 395 | } else |
@@ -332,17 +399,75 @@ static void show_location(Dwarf_Op *op, struct probe_finder *pf) | |||
332 | if (!regs) | 399 | if (!regs) |
333 | die("%u exceeds max register number.", regn); | 400 | die("%u exceeds max register number.", regn); |
334 | 401 | ||
335 | if (deref) | 402 | tvar->value = xstrdup(regs); |
336 | ret = snprintf(pf->buf, pf->len, " %s=%+jd(%s)", | 403 | if (ref) { |
337 | pf->var, (intmax_t)offs, regs); | 404 | tvar->ref = xzalloc(sizeof(struct kprobe_trace_arg_ref)); |
338 | else | 405 | tvar->ref->offset = (long)offs; |
339 | ret = snprintf(pf->buf, pf->len, " %s=%s", pf->var, regs); | 406 | } |
340 | DIE_IF(ret < 0); | 407 | } |
341 | DIE_IF(ret >= pf->len); | 408 | |
409 | static void convert_variable_fields(Dwarf_Die *vr_die, const char *varname, | ||
410 | struct perf_probe_arg_field *field, | ||
411 | struct kprobe_trace_arg_ref **ref_ptr) | ||
412 | { | ||
413 | struct kprobe_trace_arg_ref *ref = *ref_ptr; | ||
414 | Dwarf_Attribute attr; | ||
415 | Dwarf_Die member; | ||
416 | Dwarf_Die type; | ||
417 | Dwarf_Word offs; | ||
418 | |||
419 | pr_debug("converting %s in %s\n", field->name, varname); | ||
420 | if (die_get_real_type(vr_die, &type) == NULL) | ||
421 | die("Failed to get a type information of %s.", varname); | ||
422 | |||
423 | /* Check the pointer and dereference */ | ||
424 | if (dwarf_tag(&type) == DW_TAG_pointer_type) { | ||
425 | if (!field->ref) | ||
426 | die("Semantic error: %s must be referred by '->'", | ||
427 | field->name); | ||
428 | /* Get the type pointed by this pointer */ | ||
429 | if (die_get_real_type(&type, &type) == NULL) | ||
430 | die("Failed to get a type information of %s.", varname); | ||
431 | |||
432 | /* Verify it is a data structure */ | ||
433 | if (dwarf_tag(&type) != DW_TAG_structure_type) | ||
434 | die("%s is not a data structure.", varname); | ||
435 | |||
436 | ref = xzalloc(sizeof(struct kprobe_trace_arg_ref)); | ||
437 | if (*ref_ptr) | ||
438 | (*ref_ptr)->next = ref; | ||
439 | else | ||
440 | *ref_ptr = ref; | ||
441 | } else { | ||
442 | /* Verify it is a data structure */ | ||
443 | if (dwarf_tag(&type) != DW_TAG_structure_type) | ||
444 | die("%s is not a data structure.", varname); | ||
445 | |||
446 | if (field->ref) | ||
447 | die("Semantic error: %s must be referred by '.'", | ||
448 | field->name); | ||
449 | if (!ref) | ||
450 | die("Structure on a register is not supported yet."); | ||
451 | } | ||
452 | |||
453 | if (die_find_member(&type, field->name, &member) == NULL) | ||
454 | die("%s(tyep:%s) has no member %s.", varname, | ||
455 | dwarf_diename(&type), field->name); | ||
456 | |||
457 | /* Get the offset of the field */ | ||
458 | if (dwarf_attr(&member, DW_AT_data_member_location, &attr) == NULL || | ||
459 | dwarf_formudata(&attr, &offs) != 0) | ||
460 | die("Failed to get the offset of %s.", field->name); | ||
461 | ref->offset += (long)offs; | ||
462 | |||
463 | /* Converting next field */ | ||
464 | if (field->next) | ||
465 | convert_variable_fields(&member, field->name, field->next, | ||
466 | &ref); | ||
342 | } | 467 | } |
343 | 468 | ||
344 | /* Show a variables in kprobe event format */ | 469 | /* Show a variables in kprobe event format */ |
345 | static void show_variable(Dwarf_Die *vr_die, struct probe_finder *pf) | 470 | static void convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) |
346 | { | 471 | { |
347 | Dwarf_Attribute attr; | 472 | Dwarf_Attribute attr; |
348 | Dwarf_Op *expr; | 473 | Dwarf_Op *expr; |
@@ -356,83 +481,77 @@ static void show_variable(Dwarf_Die *vr_die, struct probe_finder *pf) | |||
356 | if (ret <= 0 || nexpr == 0) | 481 | if (ret <= 0 || nexpr == 0) |
357 | goto error; | 482 | goto error; |
358 | 483 | ||
359 | show_location(expr, pf); | 484 | convert_location(expr, pf); |
485 | |||
486 | if (pf->pvar->field) | ||
487 | convert_variable_fields(vr_die, pf->pvar->name, | ||
488 | pf->pvar->field, &pf->tvar->ref); | ||
360 | /* *expr will be cached in libdw. Don't free it. */ | 489 | /* *expr will be cached in libdw. Don't free it. */ |
361 | return ; | 490 | return ; |
362 | error: | 491 | error: |
363 | /* TODO: Support const_value */ | 492 | /* TODO: Support const_value */ |
364 | die("Failed to find the location of %s at this address.\n" | 493 | die("Failed to find the location of %s at this address.\n" |
365 | " Perhaps, it has been optimized out.", pf->var); | 494 | " Perhaps, it has been optimized out.", pf->pvar->name); |
366 | } | 495 | } |
367 | 496 | ||
368 | /* Find a variable in a subprogram die */ | 497 | /* Find a variable in a subprogram die */ |
369 | static void find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) | 498 | static void find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) |
370 | { | 499 | { |
371 | int ret; | ||
372 | Dwarf_Die vr_die; | 500 | Dwarf_Die vr_die; |
501 | char buf[128]; | ||
373 | 502 | ||
374 | /* TODO: Support struct members and arrays */ | 503 | /* TODO: Support struct members and arrays */ |
375 | if (!is_c_varname(pf->var)) { | 504 | if (!is_c_varname(pf->pvar->name)) { |
376 | /* Output raw parameters */ | 505 | /* Copy raw parameters */ |
377 | ret = snprintf(pf->buf, pf->len, " %s", pf->var); | 506 | pf->tvar->value = xstrdup(pf->pvar->name); |
378 | DIE_IF(ret < 0); | 507 | } else { |
379 | DIE_IF(ret >= pf->len); | 508 | synthesize_perf_probe_arg(pf->pvar, buf, 128); |
380 | return ; | 509 | pf->tvar->name = xstrdup(buf); |
510 | pr_debug("Searching '%s' variable in context.\n", | ||
511 | pf->pvar->name); | ||
512 | /* Search child die for local variables and parameters. */ | ||
513 | if (!die_find_variable(sp_die, pf->pvar->name, &vr_die)) | ||
514 | die("Failed to find '%s' in this function.", | ||
515 | pf->pvar->name); | ||
516 | convert_variable(&vr_die, pf); | ||
381 | } | 517 | } |
382 | |||
383 | pr_debug("Searching '%s' variable in context.\n", pf->var); | ||
384 | /* Search child die for local variables and parameters. */ | ||
385 | if (!die_find_variable(sp_die, pf->var, &vr_die)) | ||
386 | die("Failed to find '%s' in this function.", pf->var); | ||
387 | |||
388 | show_variable(&vr_die, pf); | ||
389 | } | 518 | } |
390 | 519 | ||
391 | /* Show a probe point to output buffer */ | 520 | /* Show a probe point to output buffer */ |
392 | static void show_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | 521 | static void convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) |
393 | { | 522 | { |
394 | struct probe_point *pp = pf->pp; | 523 | struct kprobe_trace_event *tev; |
395 | Dwarf_Addr eaddr; | 524 | Dwarf_Addr eaddr; |
396 | Dwarf_Die die_mem; | 525 | Dwarf_Die die_mem; |
397 | const char *name; | 526 | const char *name; |
398 | char tmp[MAX_PROBE_BUFFER]; | 527 | int ret, i; |
399 | int ret, i, len; | ||
400 | Dwarf_Attribute fb_attr; | 528 | Dwarf_Attribute fb_attr; |
401 | size_t nops; | 529 | size_t nops; |
402 | 530 | ||
531 | if (pf->ntevs == MAX_PROBES) | ||
532 | die("Too many( > %d) probe point found.\n", MAX_PROBES); | ||
533 | tev = &pf->tevs[pf->ntevs++]; | ||
534 | |||
403 | /* If no real subprogram, find a real one */ | 535 | /* If no real subprogram, find a real one */ |
404 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { | 536 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { |
405 | sp_die = die_get_real_subprogram(&pf->cu_die, | 537 | sp_die = die_find_real_subprogram(&pf->cu_die, |
406 | pf->addr, &die_mem); | 538 | pf->addr, &die_mem); |
407 | if (!sp_die) | 539 | if (!sp_die) |
408 | die("Probe point is not found in subprograms."); | 540 | die("Probe point is not found in subprograms."); |
409 | } | 541 | } |
410 | 542 | ||
411 | /* Output name of probe point */ | 543 | /* Copy the name of probe point */ |
412 | name = dwarf_diename(sp_die); | 544 | name = dwarf_diename(sp_die); |
413 | if (name) { | 545 | if (name) { |
414 | dwarf_entrypc(sp_die, &eaddr); | 546 | dwarf_entrypc(sp_die, &eaddr); |
415 | ret = snprintf(tmp, MAX_PROBE_BUFFER, "%s+%lu", name, | 547 | tev->point.symbol = xstrdup(name); |
416 | (unsigned long)(pf->addr - eaddr)); | 548 | tev->point.offset = (unsigned long)(pf->addr - eaddr); |
417 | /* Copy the function name if possible */ | 549 | } else |
418 | if (!pp->function) { | ||
419 | pp->function = strdup(name); | ||
420 | pp->offset = (size_t)(pf->addr - eaddr); | ||
421 | } | ||
422 | } else { | ||
423 | /* This function has no name. */ | 550 | /* This function has no name. */ |
424 | ret = snprintf(tmp, MAX_PROBE_BUFFER, "0x%jx", | 551 | tev->point.offset = (unsigned long)pf->addr; |
425 | (uintmax_t)pf->addr); | 552 | |
426 | if (!pp->function) { | 553 | pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, |
427 | /* TODO: Use _stext */ | 554 | tev->point.offset); |
428 | pp->function = strdup(""); | ||
429 | pp->offset = (size_t)pf->addr; | ||
430 | } | ||
431 | } | ||
432 | DIE_IF(ret < 0); | ||
433 | DIE_IF(ret >= MAX_PROBE_BUFFER); | ||
434 | len = ret; | ||
435 | pr_debug("Probe point found: %s\n", tmp); | ||
436 | 555 | ||
437 | /* Get the frame base attribute/ops */ | 556 | /* Get the frame base attribute/ops */ |
438 | dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); | 557 | dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); |
@@ -442,22 +561,16 @@ static void show_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
442 | 561 | ||
443 | /* Find each argument */ | 562 | /* Find each argument */ |
444 | /* TODO: use dwarf_cfi_addrframe */ | 563 | /* TODO: use dwarf_cfi_addrframe */ |
445 | for (i = 0; i < pp->nr_args; i++) { | 564 | tev->nargs = pf->pev->nargs; |
446 | pf->var = pp->args[i]; | 565 | tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); |
447 | pf->buf = &tmp[len]; | 566 | for (i = 0; i < pf->pev->nargs; i++) { |
448 | pf->len = MAX_PROBE_BUFFER - len; | 567 | pf->pvar = &pf->pev->args[i]; |
568 | pf->tvar = &tev->args[i]; | ||
449 | find_variable(sp_die, pf); | 569 | find_variable(sp_die, pf); |
450 | len += strlen(pf->buf); | ||
451 | } | 570 | } |
452 | 571 | ||
453 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ | 572 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ |
454 | pf->fb_ops = NULL; | 573 | pf->fb_ops = NULL; |
455 | |||
456 | if (pp->found == MAX_PROBES) | ||
457 | die("Too many( > %d) probe point found.\n", MAX_PROBES); | ||
458 | |||
459 | pp->probes[pp->found] = strdup(tmp); | ||
460 | pp->found++; | ||
461 | } | 574 | } |
462 | 575 | ||
463 | /* Find probe point from its line number */ | 576 | /* Find probe point from its line number */ |
@@ -489,7 +602,7 @@ static void find_probe_point_by_line(struct probe_finder *pf) | |||
489 | (int)i, lineno, (uintmax_t)addr); | 602 | (int)i, lineno, (uintmax_t)addr); |
490 | pf->addr = addr; | 603 | pf->addr = addr; |
491 | 604 | ||
492 | show_probe_point(NULL, pf); | 605 | convert_probe_point(NULL, pf); |
493 | /* Continuing, because target line might be inlined. */ | 606 | /* Continuing, because target line might be inlined. */ |
494 | } | 607 | } |
495 | } | 608 | } |
@@ -506,8 +619,7 @@ static int find_lazy_match_lines(struct list_head *head, | |||
506 | if (fd < 0) | 619 | if (fd < 0) |
507 | die("failed to open %s", fname); | 620 | die("failed to open %s", fname); |
508 | DIE_IF(fstat(fd, &st) < 0); | 621 | DIE_IF(fstat(fd, &st) < 0); |
509 | fbuf = malloc(st.st_size + 2); | 622 | fbuf = xmalloc(st.st_size + 2); |
510 | DIE_IF(fbuf == NULL); | ||
511 | DIE_IF(read(fd, fbuf, st.st_size) < 0); | 623 | DIE_IF(read(fd, fbuf, st.st_size) < 0); |
512 | close(fd); | 624 | close(fd); |
513 | fbuf[st.st_size] = '\n'; /* Dummy line */ | 625 | fbuf[st.st_size] = '\n'; /* Dummy line */ |
@@ -541,7 +653,7 @@ static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
541 | if (list_empty(&pf->lcache)) { | 653 | if (list_empty(&pf->lcache)) { |
542 | /* Matching lazy line pattern */ | 654 | /* Matching lazy line pattern */ |
543 | ret = find_lazy_match_lines(&pf->lcache, pf->fname, | 655 | ret = find_lazy_match_lines(&pf->lcache, pf->fname, |
544 | pf->pp->lazy_line); | 656 | pf->pev->point.lazy_line); |
545 | if (ret <= 0) | 657 | if (ret <= 0) |
546 | die("No matched lines found in %s.", pf->fname); | 658 | die("No matched lines found in %s.", pf->fname); |
547 | } | 659 | } |
@@ -566,7 +678,7 @@ static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
566 | if (!dwarf_haspc(sp_die, addr)) | 678 | if (!dwarf_haspc(sp_die, addr)) |
567 | continue; | 679 | continue; |
568 | /* Address filtering 2: No child include addr? */ | 680 | /* Address filtering 2: No child include addr? */ |
569 | if (die_get_inlinefunc(sp_die, addr, &die_mem)) | 681 | if (die_find_inlinefunc(sp_die, addr, &die_mem)) |
570 | continue; | 682 | continue; |
571 | } | 683 | } |
572 | 684 | ||
@@ -574,7 +686,7 @@ static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
574 | (int)i, lineno, (unsigned long long)addr); | 686 | (int)i, lineno, (unsigned long long)addr); |
575 | pf->addr = addr; | 687 | pf->addr = addr; |
576 | 688 | ||
577 | show_probe_point(sp_die, pf); | 689 | convert_probe_point(sp_die, pf); |
578 | /* Continuing, because target line might be inlined. */ | 690 | /* Continuing, because target line might be inlined. */ |
579 | } | 691 | } |
580 | /* TODO: deallocate lines, but how? */ | 692 | /* TODO: deallocate lines, but how? */ |
@@ -583,7 +695,7 @@ static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
583 | static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) | 695 | static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) |
584 | { | 696 | { |
585 | struct probe_finder *pf = (struct probe_finder *)data; | 697 | struct probe_finder *pf = (struct probe_finder *)data; |
586 | struct probe_point *pp = pf->pp; | 698 | struct perf_probe_point *pp = &pf->pev->point; |
587 | 699 | ||
588 | if (pp->lazy_line) | 700 | if (pp->lazy_line) |
589 | find_probe_point_lazy(in_die, pf); | 701 | find_probe_point_lazy(in_die, pf); |
@@ -594,7 +706,7 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) | |||
594 | pr_debug("found inline addr: 0x%jx\n", | 706 | pr_debug("found inline addr: 0x%jx\n", |
595 | (uintmax_t)pf->addr); | 707 | (uintmax_t)pf->addr); |
596 | 708 | ||
597 | show_probe_point(in_die, pf); | 709 | convert_probe_point(in_die, pf); |
598 | } | 710 | } |
599 | 711 | ||
600 | return DWARF_CB_OK; | 712 | return DWARF_CB_OK; |
@@ -604,7 +716,7 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) | |||
604 | static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) | 716 | static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) |
605 | { | 717 | { |
606 | struct probe_finder *pf = (struct probe_finder *)data; | 718 | struct probe_finder *pf = (struct probe_finder *)data; |
607 | struct probe_point *pp = pf->pp; | 719 | struct perf_probe_point *pp = &pf->pev->point; |
608 | 720 | ||
609 | /* Check tag and diename */ | 721 | /* Check tag and diename */ |
610 | if (dwarf_tag(sp_die) != DW_TAG_subprogram || | 722 | if (dwarf_tag(sp_die) != DW_TAG_subprogram || |
@@ -624,7 +736,7 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) | |||
624 | pf->addr = die_get_entrypc(sp_die); | 736 | pf->addr = die_get_entrypc(sp_die); |
625 | pf->addr += pp->offset; | 737 | pf->addr += pp->offset; |
626 | /* TODO: Check the address in this function */ | 738 | /* TODO: Check the address in this function */ |
627 | show_probe_point(sp_die, pf); | 739 | convert_probe_point(sp_die, pf); |
628 | } | 740 | } |
629 | } else | 741 | } else |
630 | /* Inlined function: search instances */ | 742 | /* Inlined function: search instances */ |
@@ -638,20 +750,25 @@ static void find_probe_point_by_func(struct probe_finder *pf) | |||
638 | dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, pf, 0); | 750 | dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, pf, 0); |
639 | } | 751 | } |
640 | 752 | ||
641 | /* Find a probe point */ | 753 | /* Find kprobe_trace_events specified by perf_probe_event from debuginfo */ |
642 | int find_probe_point(int fd, struct probe_point *pp) | 754 | int find_kprobe_trace_events(int fd, struct perf_probe_event *pev, |
755 | struct kprobe_trace_event **tevs) | ||
643 | { | 756 | { |
644 | struct probe_finder pf = {.pp = pp}; | 757 | struct probe_finder pf = {.pev = pev}; |
758 | struct perf_probe_point *pp = &pev->point; | ||
645 | Dwarf_Off off, noff; | 759 | Dwarf_Off off, noff; |
646 | size_t cuhl; | 760 | size_t cuhl; |
647 | Dwarf_Die *diep; | 761 | Dwarf_Die *diep; |
648 | Dwarf *dbg; | 762 | Dwarf *dbg; |
649 | 763 | ||
764 | pf.tevs = xzalloc(sizeof(struct kprobe_trace_event) * MAX_PROBES); | ||
765 | *tevs = pf.tevs; | ||
766 | pf.ntevs = 0; | ||
767 | |||
650 | dbg = dwarf_begin(fd, DWARF_C_READ); | 768 | dbg = dwarf_begin(fd, DWARF_C_READ); |
651 | if (!dbg) | 769 | if (!dbg) |
652 | return -ENOENT; | 770 | return -ENOENT; |
653 | 771 | ||
654 | pp->found = 0; | ||
655 | off = 0; | 772 | off = 0; |
656 | line_list__init(&pf.lcache); | 773 | line_list__init(&pf.lcache); |
657 | /* Loop on CUs (Compilation Unit) */ | 774 | /* Loop on CUs (Compilation Unit) */ |
@@ -682,9 +799,81 @@ int find_probe_point(int fd, struct probe_point *pp) | |||
682 | line_list__free(&pf.lcache); | 799 | line_list__free(&pf.lcache); |
683 | dwarf_end(dbg); | 800 | dwarf_end(dbg); |
684 | 801 | ||
685 | return pp->found; | 802 | return pf.ntevs; |
803 | } | ||
804 | |||
805 | /* Reverse search */ | ||
806 | int find_perf_probe_point(int fd, unsigned long addr, | ||
807 | struct perf_probe_point *ppt) | ||
808 | { | ||
809 | Dwarf_Die cudie, spdie, indie; | ||
810 | Dwarf *dbg; | ||
811 | Dwarf_Line *line; | ||
812 | Dwarf_Addr laddr, eaddr; | ||
813 | const char *tmp; | ||
814 | int lineno, ret = 0; | ||
815 | |||
816 | dbg = dwarf_begin(fd, DWARF_C_READ); | ||
817 | if (!dbg) | ||
818 | return -ENOENT; | ||
819 | |||
820 | /* Find cu die */ | ||
821 | if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie)) { | ||
822 | ret = -EINVAL; | ||
823 | goto end; | ||
824 | } | ||
825 | |||
826 | /* Find a corresponding line */ | ||
827 | line = dwarf_getsrc_die(&cudie, (Dwarf_Addr)addr); | ||
828 | if (line) { | ||
829 | dwarf_lineaddr(line, &laddr); | ||
830 | if ((Dwarf_Addr)addr == laddr) { | ||
831 | dwarf_lineno(line, &lineno); | ||
832 | ppt->line = lineno; | ||
833 | |||
834 | tmp = dwarf_linesrc(line, NULL, NULL); | ||
835 | DIE_IF(!tmp); | ||
836 | ppt->file = xstrdup(tmp); | ||
837 | ret = 1; | ||
838 | } | ||
839 | } | ||
840 | |||
841 | /* Find a corresponding function */ | ||
842 | if (die_find_real_subprogram(&cudie, (Dwarf_Addr)addr, &spdie)) { | ||
843 | tmp = dwarf_diename(&spdie); | ||
844 | if (!tmp) | ||
845 | goto end; | ||
846 | |||
847 | dwarf_entrypc(&spdie, &eaddr); | ||
848 | if (!lineno) { | ||
849 | /* We don't have a line number, let's use offset */ | ||
850 | ppt->function = xstrdup(tmp); | ||
851 | ppt->offset = addr - (unsigned long)eaddr; | ||
852 | ret = 1; | ||
853 | goto end; | ||
854 | } | ||
855 | if (die_find_inlinefunc(&spdie, (Dwarf_Addr)addr, &indie)) { | ||
856 | /* addr in an inline function */ | ||
857 | tmp = dwarf_diename(&indie); | ||
858 | if (!tmp) | ||
859 | goto end; | ||
860 | dwarf_decl_line(&indie, &lineno); | ||
861 | } else { | ||
862 | if (eaddr == addr) /* No offset: function entry */ | ||
863 | lineno = ppt->line; | ||
864 | else | ||
865 | dwarf_decl_line(&spdie, &lineno); | ||
866 | } | ||
867 | ppt->function = xstrdup(tmp); | ||
868 | ppt->line -= lineno; /* Make a relative line number */ | ||
869 | } | ||
870 | |||
871 | end: | ||
872 | dwarf_end(dbg); | ||
873 | return ret; | ||
686 | } | 874 | } |
687 | 875 | ||
876 | |||
688 | /* Find line range from its line number */ | 877 | /* Find line range from its line number */ |
689 | static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) | 878 | static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) |
690 | { | 879 | { |
@@ -716,7 +905,7 @@ static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) | |||
716 | continue; | 905 | continue; |
717 | 906 | ||
718 | /* Address filtering 2: No child include addr? */ | 907 | /* Address filtering 2: No child include addr? */ |
719 | if (die_get_inlinefunc(sp_die, addr, &die_mem)) | 908 | if (die_find_inlinefunc(sp_die, addr, &die_mem)) |
720 | continue; | 909 | continue; |
721 | } | 910 | } |
722 | 911 | ||
@@ -727,7 +916,7 @@ static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) | |||
727 | 916 | ||
728 | /* Copy real path */ | 917 | /* Copy real path */ |
729 | if (!lf->lr->path) | 918 | if (!lf->lr->path) |
730 | lf->lr->path = strdup(src); | 919 | lf->lr->path = xstrdup(src); |
731 | line_list__add_line(&lf->lr->line_list, (unsigned int)lineno); | 920 | line_list__add_line(&lf->lr->line_list, (unsigned int)lineno); |
732 | } | 921 | } |
733 | /* Update status */ | 922 | /* Update status */ |
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 21f7354397b..3564f22954f 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include "util.h" | 5 | #include "util.h" |
6 | #include "probe-event.h" | ||
6 | 7 | ||
7 | #define MAX_PATH_LEN 256 | 8 | #define MAX_PATH_LEN 256 |
8 | #define MAX_PROBE_BUFFER 1024 | 9 | #define MAX_PROBE_BUFFER 1024 |
@@ -14,67 +15,36 @@ static inline int is_c_varname(const char *name) | |||
14 | return isalpha(name[0]) || name[0] == '_'; | 15 | return isalpha(name[0]) || name[0] == '_'; |
15 | } | 16 | } |
16 | 17 | ||
17 | struct probe_point { | 18 | #ifdef DWARF_SUPPORT |
18 | char *event; /* Event name */ | 19 | /* Find kprobe_trace_events specified by perf_probe_event from debuginfo */ |
19 | char *group; /* Event group */ | 20 | extern int find_kprobe_trace_events(int fd, struct perf_probe_event *pev, |
21 | struct kprobe_trace_event **tevs); | ||
20 | 22 | ||
21 | /* Inputs */ | 23 | /* Find a perf_probe_point from debuginfo */ |
22 | char *file; /* File name */ | 24 | extern int find_perf_probe_point(int fd, unsigned long addr, |
23 | int line; /* Line number */ | 25 | struct perf_probe_point *ppt); |
24 | char *lazy_line; /* Lazy line pattern */ | ||
25 | 26 | ||
26 | char *function; /* Function name */ | ||
27 | int offset; /* Offset bytes */ | ||
28 | |||
29 | int nr_args; /* Number of arguments */ | ||
30 | char **args; /* Arguments */ | ||
31 | |||
32 | int retprobe; /* Return probe */ | ||
33 | |||
34 | /* Output */ | ||
35 | int found; /* Number of found probe points */ | ||
36 | char *probes[MAX_PROBES]; /* Output buffers (will be allocated)*/ | ||
37 | }; | ||
38 | |||
39 | /* Line number container */ | ||
40 | struct line_node { | ||
41 | struct list_head list; | ||
42 | unsigned int line; | ||
43 | }; | ||
44 | |||
45 | /* Line range */ | ||
46 | struct line_range { | ||
47 | char *file; /* File name */ | ||
48 | char *function; /* Function name */ | ||
49 | unsigned int start; /* Start line number */ | ||
50 | unsigned int end; /* End line number */ | ||
51 | int offset; /* Start line offset */ | ||
52 | char *path; /* Real path name */ | ||
53 | struct list_head line_list; /* Visible lines */ | ||
54 | }; | ||
55 | |||
56 | #ifndef NO_DWARF_SUPPORT | ||
57 | extern int find_probe_point(int fd, struct probe_point *pp); | ||
58 | extern int find_line_range(int fd, struct line_range *lr); | 27 | extern int find_line_range(int fd, struct line_range *lr); |
59 | 28 | ||
60 | #include <dwarf.h> | 29 | #include <dwarf.h> |
61 | #include <libdw.h> | 30 | #include <libdw.h> |
62 | 31 | ||
63 | struct probe_finder { | 32 | struct probe_finder { |
64 | struct probe_point *pp; /* Target probe point */ | 33 | struct perf_probe_event *pev; /* Target probe event */ |
34 | int ntevs; /* number of trace events */ | ||
35 | struct kprobe_trace_event *tevs; /* Result trace events */ | ||
65 | 36 | ||
66 | /* For function searching */ | 37 | /* For function searching */ |
67 | Dwarf_Addr addr; /* Address */ | 38 | Dwarf_Addr addr; /* Address */ |
68 | const char *fname; /* File name */ | 39 | const char *fname; /* Real file name */ |
69 | int lno; /* Line number */ | 40 | int lno; /* Line number */ |
70 | Dwarf_Die cu_die; /* Current CU */ | 41 | Dwarf_Die cu_die; /* Current CU */ |
42 | struct list_head lcache; /* Line cache for lazy match */ | ||
71 | 43 | ||
72 | /* For variable searching */ | 44 | /* For variable searching */ |
73 | Dwarf_Op *fb_ops; /* Frame base attribute */ | 45 | Dwarf_Op *fb_ops; /* Frame base attribute */ |
74 | const char *var; /* Current variable name */ | 46 | struct perf_probe_arg *pvar; /* Current target variable */ |
75 | char *buf; /* Current output buffer */ | 47 | struct kprobe_trace_arg *tvar; /* Current result variable */ |
76 | int len; /* Length of output buffer */ | ||
77 | struct list_head lcache; /* Line cache for lazy match */ | ||
78 | }; | 48 | }; |
79 | 49 | ||
80 | struct line_finder { | 50 | struct line_finder { |
@@ -87,6 +57,6 @@ struct line_finder { | |||
87 | int found; | 57 | int found; |
88 | }; | 58 | }; |
89 | 59 | ||
90 | #endif /* NO_DWARF_SUPPORT */ | 60 | #endif /* DWARF_SUPPORT */ |
91 | 61 | ||
92 | #endif /*_PROBE_FINDER_H */ | 62 | #endif /*_PROBE_FINDER_H */ |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index eed1cb88900..ddf288fca3e 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -52,11 +52,6 @@ out_close: | |||
52 | return -1; | 52 | return -1; |
53 | } | 53 | } |
54 | 54 | ||
55 | static inline int perf_session__create_kernel_maps(struct perf_session *self) | ||
56 | { | ||
57 | return map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps); | ||
58 | } | ||
59 | |||
60 | struct perf_session *perf_session__new(const char *filename, int mode, bool force) | 55 | struct perf_session *perf_session__new(const char *filename, int mode, bool force) |
61 | { | 56 | { |
62 | size_t len = filename ? strlen(filename) + 1 : 0; | 57 | size_t len = filename ? strlen(filename) + 1 : 0; |
@@ -117,22 +112,17 @@ static bool symbol__match_parent_regex(struct symbol *sym) | |||
117 | return 0; | 112 | return 0; |
118 | } | 113 | } |
119 | 114 | ||
120 | struct symbol **perf_session__resolve_callchain(struct perf_session *self, | 115 | struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, |
121 | struct thread *thread, | 116 | struct thread *thread, |
122 | struct ip_callchain *chain, | 117 | struct ip_callchain *chain, |
123 | struct symbol **parent) | 118 | struct symbol **parent) |
124 | { | 119 | { |
125 | u8 cpumode = PERF_RECORD_MISC_USER; | 120 | u8 cpumode = PERF_RECORD_MISC_USER; |
126 | struct symbol **syms = NULL; | ||
127 | unsigned int i; | 121 | unsigned int i; |
122 | struct map_symbol *syms = calloc(chain->nr, sizeof(*syms)); | ||
128 | 123 | ||
129 | if (symbol_conf.use_callchain) { | 124 | if (!syms) |
130 | syms = calloc(chain->nr, sizeof(*syms)); | 125 | return NULL; |
131 | if (!syms) { | ||
132 | fprintf(stderr, "Can't allocate memory for symbols\n"); | ||
133 | exit(-1); | ||
134 | } | ||
135 | } | ||
136 | 126 | ||
137 | for (i = 0; i < chain->nr; i++) { | 127 | for (i = 0; i < chain->nr; i++) { |
138 | u64 ip = chain->ips[i]; | 128 | u64 ip = chain->ips[i]; |
@@ -160,7 +150,8 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self, | |||
160 | *parent = al.sym; | 150 | *parent = al.sym; |
161 | if (!symbol_conf.use_callchain) | 151 | if (!symbol_conf.use_callchain) |
162 | break; | 152 | break; |
163 | syms[i] = al.sym; | 153 | syms[i].map = al.map; |
154 | syms[i].sym = al.sym; | ||
164 | } | 155 | } |
165 | } | 156 | } |
166 | 157 | ||
@@ -396,6 +387,10 @@ int __perf_session__process_events(struct perf_session *self, | |||
396 | event_t *event; | 387 | event_t *event; |
397 | uint32_t size; | 388 | uint32_t size; |
398 | char *buf; | 389 | char *buf; |
390 | struct ui_progress *progress = ui_progress__new("Processing events...", | ||
391 | self->size); | ||
392 | if (progress == NULL) | ||
393 | return -1; | ||
399 | 394 | ||
400 | perf_event_ops__fill_defaults(ops); | 395 | perf_event_ops__fill_defaults(ops); |
401 | 396 | ||
@@ -424,6 +419,7 @@ remap: | |||
424 | 419 | ||
425 | more: | 420 | more: |
426 | event = (event_t *)(buf + head); | 421 | event = (event_t *)(buf + head); |
422 | ui_progress__update(progress, offset); | ||
427 | 423 | ||
428 | if (self->header.needs_swap) | 424 | if (self->header.needs_swap) |
429 | perf_event_header__bswap(&event->header); | 425 | perf_event_header__bswap(&event->header); |
@@ -474,6 +470,7 @@ more: | |||
474 | done: | 470 | done: |
475 | err = 0; | 471 | err = 0; |
476 | out_err: | 472 | out_err: |
473 | ui_progress__delete(progress); | ||
477 | return err; | 474 | return err; |
478 | } | 475 | } |
479 | 476 | ||
@@ -543,32 +540,3 @@ int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self, | |||
543 | 540 | ||
544 | return 0; | 541 | return 0; |
545 | } | 542 | } |
546 | |||
547 | static u64 map__reloc_map_ip(struct map *map, u64 ip) | ||
548 | { | ||
549 | return ip + (s64)map->pgoff; | ||
550 | } | ||
551 | |||
552 | static u64 map__reloc_unmap_ip(struct map *map, u64 ip) | ||
553 | { | ||
554 | return ip - (s64)map->pgoff; | ||
555 | } | ||
556 | |||
557 | void map__reloc_vmlinux(struct map *self) | ||
558 | { | ||
559 | struct kmap *kmap = map__kmap(self); | ||
560 | s64 reloc; | ||
561 | |||
562 | if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->unrelocated_addr) | ||
563 | return; | ||
564 | |||
565 | reloc = (kmap->ref_reloc_sym->unrelocated_addr - | ||
566 | kmap->ref_reloc_sym->addr); | ||
567 | |||
568 | if (!reloc) | ||
569 | return; | ||
570 | |||
571 | self->map_ip = map__reloc_map_ip; | ||
572 | self->unmap_ip = map__reloc_unmap_ip; | ||
573 | self->pgoff = reloc; | ||
574 | } | ||
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 5c33417eebb..27f4c2dc715 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -57,10 +57,10 @@ int __perf_session__process_events(struct perf_session *self, | |||
57 | int perf_session__process_events(struct perf_session *self, | 57 | int perf_session__process_events(struct perf_session *self, |
58 | struct perf_event_ops *event_ops); | 58 | struct perf_event_ops *event_ops); |
59 | 59 | ||
60 | struct symbol **perf_session__resolve_callchain(struct perf_session *self, | 60 | struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, |
61 | struct thread *thread, | 61 | struct thread *thread, |
62 | struct ip_callchain *chain, | 62 | struct ip_callchain *chain, |
63 | struct symbol **parent); | 63 | struct symbol **parent); |
64 | 64 | ||
65 | bool perf_session__has_traces(struct perf_session *self, const char *msg); | 65 | bool perf_session__has_traces(struct perf_session *self, const char *msg); |
66 | 66 | ||
@@ -80,10 +80,30 @@ static inline int __perf_session__create_kernel_maps(struct perf_session *self, | |||
80 | self->vmlinux_maps, kernel); | 80 | self->vmlinux_maps, kernel); |
81 | } | 81 | } |
82 | 82 | ||
83 | static inline int perf_session__create_kernel_maps(struct perf_session *self) | ||
84 | { | ||
85 | return map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps); | ||
86 | } | ||
87 | |||
83 | static inline struct map * | 88 | static inline struct map * |
84 | perf_session__new_module_map(struct perf_session *self, | 89 | perf_session__new_module_map(struct perf_session *self, |
85 | u64 start, const char *filename) | 90 | u64 start, const char *filename) |
86 | { | 91 | { |
87 | return map_groups__new_module(&self->kmaps, start, filename); | 92 | return map_groups__new_module(&self->kmaps, start, filename); |
88 | } | 93 | } |
94 | |||
95 | #ifdef NO_NEWT_SUPPORT | ||
96 | static inline int perf_session__browse_hists(struct rb_root *hists __used, | ||
97 | u64 nr_hists __used, | ||
98 | u64 session_total __used, | ||
99 | const char *helpline __used, | ||
100 | const char *input_name __used) | ||
101 | { | ||
102 | return 0; | ||
103 | } | ||
104 | #else | ||
105 | int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists, | ||
106 | u64 session_total, const char *helpline, | ||
107 | const char *input_name); | ||
108 | #endif | ||
89 | #endif /* __PERF_SESSION_H */ | 109 | #endif /* __PERF_SESSION_H */ |
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index cb0f327de9e..9d24d4b2c8f 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -18,10 +18,21 @@ char * field_sep; | |||
18 | 18 | ||
19 | LIST_HEAD(hist_entry__sort_list); | 19 | LIST_HEAD(hist_entry__sort_list); |
20 | 20 | ||
21 | static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf, | ||
22 | size_t size, unsigned int width); | ||
23 | static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf, | ||
24 | size_t size, unsigned int width); | ||
25 | static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf, | ||
26 | size_t size, unsigned int width); | ||
27 | static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf, | ||
28 | size_t size, unsigned int width); | ||
29 | static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf, | ||
30 | size_t size, unsigned int width); | ||
31 | |||
21 | struct sort_entry sort_thread = { | 32 | struct sort_entry sort_thread = { |
22 | .header = "Command: Pid", | 33 | .header = "Command: Pid", |
23 | .cmp = sort__thread_cmp, | 34 | .cmp = sort__thread_cmp, |
24 | .print = sort__thread_print, | 35 | .snprintf = hist_entry__thread_snprintf, |
25 | .width = &threads__col_width, | 36 | .width = &threads__col_width, |
26 | }; | 37 | }; |
27 | 38 | ||
@@ -29,27 +40,27 @@ struct sort_entry sort_comm = { | |||
29 | .header = "Command", | 40 | .header = "Command", |
30 | .cmp = sort__comm_cmp, | 41 | .cmp = sort__comm_cmp, |
31 | .collapse = sort__comm_collapse, | 42 | .collapse = sort__comm_collapse, |
32 | .print = sort__comm_print, | 43 | .snprintf = hist_entry__comm_snprintf, |
33 | .width = &comms__col_width, | 44 | .width = &comms__col_width, |
34 | }; | 45 | }; |
35 | 46 | ||
36 | struct sort_entry sort_dso = { | 47 | struct sort_entry sort_dso = { |
37 | .header = "Shared Object", | 48 | .header = "Shared Object", |
38 | .cmp = sort__dso_cmp, | 49 | .cmp = sort__dso_cmp, |
39 | .print = sort__dso_print, | 50 | .snprintf = hist_entry__dso_snprintf, |
40 | .width = &dsos__col_width, | 51 | .width = &dsos__col_width, |
41 | }; | 52 | }; |
42 | 53 | ||
43 | struct sort_entry sort_sym = { | 54 | struct sort_entry sort_sym = { |
44 | .header = "Symbol", | 55 | .header = "Symbol", |
45 | .cmp = sort__sym_cmp, | 56 | .cmp = sort__sym_cmp, |
46 | .print = sort__sym_print, | 57 | .snprintf = hist_entry__sym_snprintf, |
47 | }; | 58 | }; |
48 | 59 | ||
49 | struct sort_entry sort_parent = { | 60 | struct sort_entry sort_parent = { |
50 | .header = "Parent symbol", | 61 | .header = "Parent symbol", |
51 | .cmp = sort__parent_cmp, | 62 | .cmp = sort__parent_cmp, |
52 | .print = sort__parent_print, | 63 | .snprintf = hist_entry__parent_snprintf, |
53 | .width = &parent_symbol__col_width, | 64 | .width = &parent_symbol__col_width, |
54 | }; | 65 | }; |
55 | 66 | ||
@@ -85,45 +96,38 @@ sort__thread_cmp(struct hist_entry *left, struct hist_entry *right) | |||
85 | return right->thread->pid - left->thread->pid; | 96 | return right->thread->pid - left->thread->pid; |
86 | } | 97 | } |
87 | 98 | ||
88 | int repsep_fprintf(FILE *fp, const char *fmt, ...) | 99 | static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) |
89 | { | 100 | { |
90 | int n; | 101 | int n; |
91 | va_list ap; | 102 | va_list ap; |
92 | 103 | ||
93 | va_start(ap, fmt); | 104 | va_start(ap, fmt); |
94 | if (!field_sep) | 105 | n = vsnprintf(bf, size, fmt, ap); |
95 | n = vfprintf(fp, fmt, ap); | 106 | if (field_sep && n > 0) { |
96 | else { | 107 | char *sep = bf; |
97 | char *bf = NULL; | 108 | |
98 | n = vasprintf(&bf, fmt, ap); | 109 | while (1) { |
99 | if (n > 0) { | 110 | sep = strchr(sep, *field_sep); |
100 | char *sep = bf; | 111 | if (sep == NULL) |
101 | 112 | break; | |
102 | while (1) { | 113 | *sep = '.'; |
103 | sep = strchr(sep, *field_sep); | ||
104 | if (sep == NULL) | ||
105 | break; | ||
106 | *sep = '.'; | ||
107 | } | ||
108 | } | 114 | } |
109 | fputs(bf, fp); | ||
110 | free(bf); | ||
111 | } | 115 | } |
112 | va_end(ap); | 116 | va_end(ap); |
113 | return n; | 117 | return n; |
114 | } | 118 | } |
115 | 119 | ||
116 | size_t | 120 | static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf, |
117 | sort__thread_print(FILE *fp, struct hist_entry *self, unsigned int width) | 121 | size_t size, unsigned int width) |
118 | { | 122 | { |
119 | return repsep_fprintf(fp, "%*s:%5d", width - 6, | 123 | return repsep_snprintf(bf, size, "%*s:%5d", width, |
120 | self->thread->comm ?: "", self->thread->pid); | 124 | self->thread->comm ?: "", self->thread->pid); |
121 | } | 125 | } |
122 | 126 | ||
123 | size_t | 127 | static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf, |
124 | sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width) | 128 | size_t size, unsigned int width) |
125 | { | 129 | { |
126 | return repsep_fprintf(fp, "%*s", width, self->thread->comm); | 130 | return repsep_snprintf(bf, size, "%*s", width, self->thread->comm); |
127 | } | 131 | } |
128 | 132 | ||
129 | /* --sort dso */ | 133 | /* --sort dso */ |
@@ -131,8 +135,8 @@ sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width) | |||
131 | int64_t | 135 | int64_t |
132 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) | 136 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) |
133 | { | 137 | { |
134 | struct dso *dso_l = left->map ? left->map->dso : NULL; | 138 | struct dso *dso_l = left->ms.map ? left->ms.map->dso : NULL; |
135 | struct dso *dso_r = right->map ? right->map->dso : NULL; | 139 | struct dso *dso_r = right->ms.map ? right->ms.map->dso : NULL; |
136 | const char *dso_name_l, *dso_name_r; | 140 | const char *dso_name_l, *dso_name_r; |
137 | 141 | ||
138 | if (!dso_l || !dso_r) | 142 | if (!dso_l || !dso_r) |
@@ -149,16 +153,16 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) | |||
149 | return strcmp(dso_name_l, dso_name_r); | 153 | return strcmp(dso_name_l, dso_name_r); |
150 | } | 154 | } |
151 | 155 | ||
152 | size_t | 156 | static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf, |
153 | sort__dso_print(FILE *fp, struct hist_entry *self, unsigned int width) | 157 | size_t size, unsigned int width) |
154 | { | 158 | { |
155 | if (self->map && self->map->dso) { | 159 | if (self->ms.map && self->ms.map->dso) { |
156 | const char *dso_name = !verbose ? self->map->dso->short_name : | 160 | const char *dso_name = !verbose ? self->ms.map->dso->short_name : |
157 | self->map->dso->long_name; | 161 | self->ms.map->dso->long_name; |
158 | return repsep_fprintf(fp, "%-*s", width, dso_name); | 162 | return repsep_snprintf(bf, size, "%-*s", width, dso_name); |
159 | } | 163 | } |
160 | 164 | ||
161 | return repsep_fprintf(fp, "%*llx", width, (u64)self->ip); | 165 | return repsep_snprintf(bf, size, "%*Lx", width, self->ip); |
162 | } | 166 | } |
163 | 167 | ||
164 | /* --sort symbol */ | 168 | /* --sort symbol */ |
@@ -168,31 +172,31 @@ sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) | |||
168 | { | 172 | { |
169 | u64 ip_l, ip_r; | 173 | u64 ip_l, ip_r; |
170 | 174 | ||
171 | if (left->sym == right->sym) | 175 | if (left->ms.sym == right->ms.sym) |
172 | return 0; | 176 | return 0; |
173 | 177 | ||
174 | ip_l = left->sym ? left->sym->start : left->ip; | 178 | ip_l = left->ms.sym ? left->ms.sym->start : left->ip; |
175 | ip_r = right->sym ? right->sym->start : right->ip; | 179 | ip_r = right->ms.sym ? right->ms.sym->start : right->ip; |
176 | 180 | ||
177 | return (int64_t)(ip_r - ip_l); | 181 | return (int64_t)(ip_r - ip_l); |
178 | } | 182 | } |
179 | 183 | ||
180 | 184 | static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf, | |
181 | size_t | 185 | size_t size, unsigned int width __used) |
182 | sort__sym_print(FILE *fp, struct hist_entry *self, unsigned int width __used) | ||
183 | { | 186 | { |
184 | size_t ret = 0; | 187 | size_t ret = 0; |
185 | 188 | ||
186 | if (verbose) { | 189 | if (verbose) { |
187 | char o = self->map ? dso__symtab_origin(self->map->dso) : '!'; | 190 | char o = self->ms.map ? dso__symtab_origin(self->ms.map->dso) : '!'; |
188 | ret += repsep_fprintf(fp, "%#018llx %c ", (u64)self->ip, o); | 191 | ret += repsep_snprintf(bf, size, "%#018llx %c ", self->ip, o); |
189 | } | 192 | } |
190 | 193 | ||
191 | ret += repsep_fprintf(fp, "[%c] ", self->level); | 194 | ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", self->level); |
192 | if (self->sym) | 195 | if (self->ms.sym) |
193 | ret += repsep_fprintf(fp, "%s", self->sym->name); | 196 | ret += repsep_snprintf(bf + ret, size - ret, "%s", |
197 | self->ms.sym->name); | ||
194 | else | 198 | else |
195 | ret += repsep_fprintf(fp, "%#016llx", (u64)self->ip); | 199 | ret += repsep_snprintf(bf + ret, size - ret, "%#016llx", self->ip); |
196 | 200 | ||
197 | return ret; | 201 | return ret; |
198 | } | 202 | } |
@@ -231,10 +235,10 @@ sort__parent_cmp(struct hist_entry *left, struct hist_entry *right) | |||
231 | return strcmp(sym_l->name, sym_r->name); | 235 | return strcmp(sym_l->name, sym_r->name); |
232 | } | 236 | } |
233 | 237 | ||
234 | size_t | 238 | static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf, |
235 | sort__parent_print(FILE *fp, struct hist_entry *self, unsigned int width) | 239 | size_t size, unsigned int width) |
236 | { | 240 | { |
237 | return repsep_fprintf(fp, "%-*s", width, | 241 | return repsep_snprintf(bf, size, "%-*s", width, |
238 | self->parent ? self->parent->name : "[other]"); | 242 | self->parent ? self->parent->name : "[other]"); |
239 | } | 243 | } |
240 | 244 | ||
@@ -260,9 +264,8 @@ int sort_dimension__add(const char *tok) | |||
260 | char err[BUFSIZ]; | 264 | char err[BUFSIZ]; |
261 | 265 | ||
262 | regerror(ret, &parent_regex, err, sizeof(err)); | 266 | regerror(ret, &parent_regex, err, sizeof(err)); |
263 | fprintf(stderr, "Invalid regex: %s\n%s", | 267 | pr_err("Invalid regex: %s\n%s", parent_pattern, err); |
264 | parent_pattern, err); | 268 | return -EINVAL; |
265 | exit(-1); | ||
266 | } | 269 | } |
267 | sort__has_parent = 1; | 270 | sort__has_parent = 1; |
268 | } | 271 | } |
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 753f9ea99fb..6d7b4be7060 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h | |||
@@ -44,18 +44,23 @@ extern enum sort_type sort__first_dimension; | |||
44 | struct hist_entry { | 44 | struct hist_entry { |
45 | struct rb_node rb_node; | 45 | struct rb_node rb_node; |
46 | u64 count; | 46 | u64 count; |
47 | /* | ||
48 | * XXX WARNING! | ||
49 | * thread _has_ to come after ms, see | ||
50 | * hist_browser__selected_thread in util/newt.c | ||
51 | */ | ||
52 | struct map_symbol ms; | ||
47 | struct thread *thread; | 53 | struct thread *thread; |
48 | struct map *map; | ||
49 | struct symbol *sym; | ||
50 | u64 ip; | 54 | u64 ip; |
51 | char level; | 55 | char level; |
52 | struct symbol *parent; | 56 | u8 filtered; |
53 | struct callchain_node callchain; | 57 | struct symbol *parent; |
54 | union { | 58 | union { |
55 | unsigned long position; | 59 | unsigned long position; |
56 | struct hist_entry *pair; | 60 | struct hist_entry *pair; |
57 | struct rb_root sorted_chain; | 61 | struct rb_root sorted_chain; |
58 | }; | 62 | }; |
63 | struct callchain_node callchain[0]; | ||
59 | }; | 64 | }; |
60 | 65 | ||
61 | enum sort_type { | 66 | enum sort_type { |
@@ -77,7 +82,8 @@ struct sort_entry { | |||
77 | 82 | ||
78 | int64_t (*cmp)(struct hist_entry *, struct hist_entry *); | 83 | int64_t (*cmp)(struct hist_entry *, struct hist_entry *); |
79 | int64_t (*collapse)(struct hist_entry *, struct hist_entry *); | 84 | int64_t (*collapse)(struct hist_entry *, struct hist_entry *); |
80 | size_t (*print)(FILE *fp, struct hist_entry *, unsigned int width); | 85 | int (*snprintf)(struct hist_entry *self, char *bf, size_t size, |
86 | unsigned int width); | ||
81 | unsigned int *width; | 87 | unsigned int *width; |
82 | bool elide; | 88 | bool elide; |
83 | }; | 89 | }; |
@@ -87,7 +93,6 @@ extern struct list_head hist_entry__sort_list; | |||
87 | 93 | ||
88 | void setup_sorting(const char * const usagestr[], const struct option *opts); | 94 | void setup_sorting(const char * const usagestr[], const struct option *opts); |
89 | 95 | ||
90 | extern int repsep_fprintf(FILE *fp, const char *fmt, ...); | ||
91 | extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int); | 96 | extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int); |
92 | extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int); | 97 | extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int); |
93 | extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int); | 98 | extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int); |
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index a175949ed21..0409fc7c005 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
@@ -1,48 +1,5 @@ | |||
1 | #include "string.h" | ||
2 | #include "util.h" | 1 | #include "util.h" |
3 | 2 | #include "string.h" | |
4 | static int hex(char ch) | ||
5 | { | ||
6 | if ((ch >= '0') && (ch <= '9')) | ||
7 | return ch - '0'; | ||
8 | if ((ch >= 'a') && (ch <= 'f')) | ||
9 | return ch - 'a' + 10; | ||
10 | if ((ch >= 'A') && (ch <= 'F')) | ||
11 | return ch - 'A' + 10; | ||
12 | return -1; | ||
13 | } | ||
14 | |||
15 | /* | ||
16 | * While we find nice hex chars, build a long_val. | ||
17 | * Return number of chars processed. | ||
18 | */ | ||
19 | int hex2u64(const char *ptr, u64 *long_val) | ||
20 | { | ||
21 | const char *p = ptr; | ||
22 | *long_val = 0; | ||
23 | |||
24 | while (*p) { | ||
25 | const int hex_val = hex(*p); | ||
26 | |||
27 | if (hex_val < 0) | ||
28 | break; | ||
29 | |||
30 | *long_val = (*long_val << 4) | hex_val; | ||
31 | p++; | ||
32 | } | ||
33 | |||
34 | return p - ptr; | ||
35 | } | ||
36 | |||
37 | char *strxfrchar(char *s, char from, char to) | ||
38 | { | ||
39 | char *p = s; | ||
40 | |||
41 | while ((p = strchr(p, from)) != NULL) | ||
42 | *p++ = to; | ||
43 | |||
44 | return s; | ||
45 | } | ||
46 | 3 | ||
47 | #define K 1024LL | 4 | #define K 1024LL |
48 | /* | 5 | /* |
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h deleted file mode 100644 index 542e44de371..00000000000 --- a/tools/perf/util/string.h +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #ifndef __PERF_STRING_H_ | ||
2 | #define __PERF_STRING_H_ | ||
3 | |||
4 | #include <stdbool.h> | ||
5 | #include "types.h" | ||
6 | |||
7 | int hex2u64(const char *ptr, u64 *val); | ||
8 | char *strxfrchar(char *s, char from, char to); | ||
9 | s64 perf_atoll(const char *str); | ||
10 | char **argv_split(const char *str, int *argcp); | ||
11 | void argv_free(char **argv); | ||
12 | bool strglobmatch(const char *str, const char *pat); | ||
13 | bool strlazymatch(const char *str, const char *pat); | ||
14 | |||
15 | #define _STR(x) #x | ||
16 | #define STR(x) _STR(x) | ||
17 | |||
18 | #endif /* __PERF_STRING_H */ | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index c458c4a371d..f3d4151e46a 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -1,13 +1,19 @@ | |||
1 | #include "util.h" | 1 | #define _GNU_SOURCE |
2 | #include "../perf.h" | 2 | #include <ctype.h> |
3 | #include "sort.h" | 3 | #include <dirent.h> |
4 | #include "string.h" | 4 | #include <errno.h> |
5 | #include <libgen.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <stdio.h> | ||
8 | #include <string.h> | ||
9 | #include <sys/types.h> | ||
10 | #include <sys/stat.h> | ||
11 | #include <sys/param.h> | ||
12 | #include <fcntl.h> | ||
13 | #include <unistd.h> | ||
5 | #include "symbol.h" | 14 | #include "symbol.h" |
6 | #include "thread.h" | 15 | #include "strlist.h" |
7 | 16 | ||
8 | #include "debug.h" | ||
9 | |||
10 | #include <asm/bug.h> | ||
11 | #include <libelf.h> | 17 | #include <libelf.h> |
12 | #include <gelf.h> | 18 | #include <gelf.h> |
13 | #include <elf.h> | 19 | #include <elf.h> |
@@ -18,18 +24,6 @@ | |||
18 | #define NT_GNU_BUILD_ID 3 | 24 | #define NT_GNU_BUILD_ID 3 |
19 | #endif | 25 | #endif |
20 | 26 | ||
21 | enum dso_origin { | ||
22 | DSO__ORIG_KERNEL = 0, | ||
23 | DSO__ORIG_JAVA_JIT, | ||
24 | DSO__ORIG_BUILD_ID_CACHE, | ||
25 | DSO__ORIG_FEDORA, | ||
26 | DSO__ORIG_UBUNTU, | ||
27 | DSO__ORIG_BUILDID, | ||
28 | DSO__ORIG_DSO, | ||
29 | DSO__ORIG_KMODULE, | ||
30 | DSO__ORIG_NOT_FOUND, | ||
31 | }; | ||
32 | |||
33 | static void dsos__add(struct list_head *head, struct dso *dso); | 27 | static void dsos__add(struct list_head *head, struct dso *dso); |
34 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type); | 28 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type); |
35 | static int dso__load_kernel_sym(struct dso *self, struct map *map, | 29 | static int dso__load_kernel_sym(struct dso *self, struct map *map, |
@@ -126,8 +120,8 @@ static void map_groups__fixup_end(struct map_groups *self) | |||
126 | static struct symbol *symbol__new(u64 start, u64 len, const char *name) | 120 | static struct symbol *symbol__new(u64 start, u64 len, const char *name) |
127 | { | 121 | { |
128 | size_t namelen = strlen(name) + 1; | 122 | size_t namelen = strlen(name) + 1; |
129 | struct symbol *self = zalloc(symbol_conf.priv_size + | 123 | struct symbol *self = calloc(1, (symbol_conf.priv_size + |
130 | sizeof(*self) + namelen); | 124 | sizeof(*self) + namelen)); |
131 | if (self == NULL) | 125 | if (self == NULL) |
132 | return NULL; | 126 | return NULL; |
133 | 127 | ||
@@ -178,7 +172,7 @@ static void dso__set_basename(struct dso *self) | |||
178 | 172 | ||
179 | struct dso *dso__new(const char *name) | 173 | struct dso *dso__new(const char *name) |
180 | { | 174 | { |
181 | struct dso *self = zalloc(sizeof(*self) + strlen(name) + 1); | 175 | struct dso *self = calloc(1, sizeof(*self) + strlen(name) + 1); |
182 | 176 | ||
183 | if (self != NULL) { | 177 | if (self != NULL) { |
184 | int i; | 178 | int i; |
@@ -870,8 +864,8 @@ out_close: | |||
870 | if (err == 0) | 864 | if (err == 0) |
871 | return nr; | 865 | return nr; |
872 | out: | 866 | out: |
873 | pr_warning("%s: problems reading %s PLT info.\n", | 867 | pr_debug("%s: problems reading %s PLT info.\n", |
874 | __func__, self->long_name); | 868 | __func__, self->long_name); |
875 | return 0; | 869 | return 0; |
876 | } | 870 | } |
877 | 871 | ||
@@ -1025,7 +1019,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, | |||
1025 | } | 1019 | } |
1026 | curr_map->map_ip = identity__map_ip; | 1020 | curr_map->map_ip = identity__map_ip; |
1027 | curr_map->unmap_ip = identity__map_ip; | 1021 | curr_map->unmap_ip = identity__map_ip; |
1028 | curr_dso->origin = DSO__ORIG_KERNEL; | 1022 | curr_dso->origin = self->origin; |
1029 | map_groups__insert(kmap->kmaps, curr_map); | 1023 | map_groups__insert(kmap->kmaps, curr_map); |
1030 | dsos__add(&dsos__kernel, curr_dso); | 1024 | dsos__add(&dsos__kernel, curr_dso); |
1031 | dso__set_loaded(curr_dso, map->type); | 1025 | dso__set_loaded(curr_dso, map->type); |
@@ -1394,13 +1388,13 @@ static int dso__kernel_module_get_build_id(struct dso *self) | |||
1394 | return 0; | 1388 | return 0; |
1395 | } | 1389 | } |
1396 | 1390 | ||
1397 | static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirname) | 1391 | static int map_groups__set_modules_path_dir(struct map_groups *self, char *dir_name) |
1398 | { | 1392 | { |
1399 | struct dirent *dent; | 1393 | struct dirent *dent; |
1400 | DIR *dir = opendir(dirname); | 1394 | DIR *dir = opendir(dir_name); |
1401 | 1395 | ||
1402 | if (!dir) { | 1396 | if (!dir) { |
1403 | pr_debug("%s: cannot open %s dir\n", __func__, dirname); | 1397 | pr_debug("%s: cannot open %s dir\n", __func__, dir_name); |
1404 | return -1; | 1398 | return -1; |
1405 | } | 1399 | } |
1406 | 1400 | ||
@@ -1413,7 +1407,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna | |||
1413 | continue; | 1407 | continue; |
1414 | 1408 | ||
1415 | snprintf(path, sizeof(path), "%s/%s", | 1409 | snprintf(path, sizeof(path), "%s/%s", |
1416 | dirname, dent->d_name); | 1410 | dir_name, dent->d_name); |
1417 | if (map_groups__set_modules_path_dir(self, path) < 0) | 1411 | if (map_groups__set_modules_path_dir(self, path) < 0) |
1418 | goto failure; | 1412 | goto failure; |
1419 | } else { | 1413 | } else { |
@@ -1433,7 +1427,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna | |||
1433 | continue; | 1427 | continue; |
1434 | 1428 | ||
1435 | snprintf(path, sizeof(path), "%s/%s", | 1429 | snprintf(path, sizeof(path), "%s/%s", |
1436 | dirname, dent->d_name); | 1430 | dir_name, dent->d_name); |
1437 | 1431 | ||
1438 | long_name = strdup(path); | 1432 | long_name = strdup(path); |
1439 | if (long_name == NULL) | 1433 | if (long_name == NULL) |
@@ -1470,8 +1464,8 @@ static int map_groups__set_modules_path(struct map_groups *self) | |||
1470 | */ | 1464 | */ |
1471 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) | 1465 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) |
1472 | { | 1466 | { |
1473 | struct map *self = zalloc(sizeof(*self) + | 1467 | struct map *self = calloc(1, (sizeof(*self) + |
1474 | (dso->kernel ? sizeof(struct kmap) : 0)); | 1468 | (dso->kernel ? sizeof(struct kmap) : 0))); |
1475 | if (self != NULL) { | 1469 | if (self != NULL) { |
1476 | /* | 1470 | /* |
1477 | * ->end will be filled after we load all the symbols | 1471 | * ->end will be filled after we load all the symbols |
@@ -1895,6 +1889,17 @@ out_fail: | |||
1895 | return -1; | 1889 | return -1; |
1896 | } | 1890 | } |
1897 | 1891 | ||
1892 | size_t vmlinux_path__fprintf(FILE *fp) | ||
1893 | { | ||
1894 | int i; | ||
1895 | size_t printed = 0; | ||
1896 | |||
1897 | for (i = 0; i < vmlinux_path__nr_entries; ++i) | ||
1898 | printed += fprintf(fp, "[%d] %s\n", i, vmlinux_path[i]); | ||
1899 | |||
1900 | return printed; | ||
1901 | } | ||
1902 | |||
1898 | static int setup_list(struct strlist **list, const char *list_str, | 1903 | static int setup_list(struct strlist **list, const char *list_str, |
1899 | const char *list_name) | 1904 | const char *list_name) |
1900 | { | 1905 | { |
@@ -1964,3 +1969,46 @@ int map_groups__create_kernel_maps(struct map_groups *self, | |||
1964 | map_groups__fixup_end(self); | 1969 | map_groups__fixup_end(self); |
1965 | return 0; | 1970 | return 0; |
1966 | } | 1971 | } |
1972 | |||
1973 | static int hex(char ch) | ||
1974 | { | ||
1975 | if ((ch >= '0') && (ch <= '9')) | ||
1976 | return ch - '0'; | ||
1977 | if ((ch >= 'a') && (ch <= 'f')) | ||
1978 | return ch - 'a' + 10; | ||
1979 | if ((ch >= 'A') && (ch <= 'F')) | ||
1980 | return ch - 'A' + 10; | ||
1981 | return -1; | ||
1982 | } | ||
1983 | |||
1984 | /* | ||
1985 | * While we find nice hex chars, build a long_val. | ||
1986 | * Return number of chars processed. | ||
1987 | */ | ||
1988 | int hex2u64(const char *ptr, u64 *long_val) | ||
1989 | { | ||
1990 | const char *p = ptr; | ||
1991 | *long_val = 0; | ||
1992 | |||
1993 | while (*p) { | ||
1994 | const int hex_val = hex(*p); | ||
1995 | |||
1996 | if (hex_val < 0) | ||
1997 | break; | ||
1998 | |||
1999 | *long_val = (*long_val << 4) | hex_val; | ||
2000 | p++; | ||
2001 | } | ||
2002 | |||
2003 | return p - ptr; | ||
2004 | } | ||
2005 | |||
2006 | char *strxfrchar(char *s, char from, char to) | ||
2007 | { | ||
2008 | char *p = s; | ||
2009 | |||
2010 | while ((p = strchr(p, from)) != NULL) | ||
2011 | *p++ = to; | ||
2012 | |||
2013 | return s; | ||
2014 | } | ||
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index f30a3742891..757fae3f5ee 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -3,10 +3,11 @@ | |||
3 | 3 | ||
4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include "types.h" | 6 | #include <stdint.h> |
7 | #include "map.h" | ||
7 | #include <linux/list.h> | 8 | #include <linux/list.h> |
8 | #include <linux/rbtree.h> | 9 | #include <linux/rbtree.h> |
9 | #include "event.h" | 10 | #include <stdio.h> |
10 | 11 | ||
11 | #define DEBUG_CACHE_DIR ".debug" | 12 | #define DEBUG_CACHE_DIR ".debug" |
12 | 13 | ||
@@ -29,6 +30,9 @@ static inline char *bfd_demangle(void __used *v, const char __used *c, | |||
29 | #endif | 30 | #endif |
30 | #endif | 31 | #endif |
31 | 32 | ||
33 | int hex2u64(const char *ptr, u64 *val); | ||
34 | char *strxfrchar(char *s, char from, char to); | ||
35 | |||
32 | /* | 36 | /* |
33 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; | 37 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; |
34 | * for newer versions we can use mmap to reduce memory usage: | 38 | * for newer versions we can use mmap to reduce memory usage: |
@@ -44,6 +48,8 @@ static inline char *bfd_demangle(void __used *v, const char __used *c, | |||
44 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ | 48 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ |
45 | #endif | 49 | #endif |
46 | 50 | ||
51 | #define BUILD_ID_SIZE 20 | ||
52 | |||
47 | struct symbol { | 53 | struct symbol { |
48 | struct rb_node rb_node; | 54 | struct rb_node rb_node; |
49 | u64 start; | 55 | u64 start; |
@@ -88,6 +94,11 @@ struct ref_reloc_sym { | |||
88 | u64 unrelocated_addr; | 94 | u64 unrelocated_addr; |
89 | }; | 95 | }; |
90 | 96 | ||
97 | struct map_symbol { | ||
98 | struct map *map; | ||
99 | struct symbol *sym; | ||
100 | }; | ||
101 | |||
91 | struct addr_location { | 102 | struct addr_location { |
92 | struct thread *thread; | 103 | struct thread *thread; |
93 | struct map *map; | 104 | struct map *map; |
@@ -106,6 +117,7 @@ struct dso { | |||
106 | u8 has_build_id:1; | 117 | u8 has_build_id:1; |
107 | u8 kernel:1; | 118 | u8 kernel:1; |
108 | u8 hit:1; | 119 | u8 hit:1; |
120 | u8 annotate_warned:1; | ||
109 | unsigned char origin; | 121 | unsigned char origin; |
110 | u8 sorted_by_name; | 122 | u8 sorted_by_name; |
111 | u8 loaded; | 123 | u8 loaded; |
@@ -150,6 +162,19 @@ size_t dsos__fprintf_buildid(FILE *fp, bool with_hits); | |||
150 | 162 | ||
151 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp); | 163 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp); |
152 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp); | 164 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp); |
165 | |||
166 | enum dso_origin { | ||
167 | DSO__ORIG_KERNEL = 0, | ||
168 | DSO__ORIG_JAVA_JIT, | ||
169 | DSO__ORIG_BUILD_ID_CACHE, | ||
170 | DSO__ORIG_FEDORA, | ||
171 | DSO__ORIG_UBUNTU, | ||
172 | DSO__ORIG_BUILDID, | ||
173 | DSO__ORIG_DSO, | ||
174 | DSO__ORIG_KMODULE, | ||
175 | DSO__ORIG_NOT_FOUND, | ||
176 | }; | ||
177 | |||
153 | char dso__symtab_origin(const struct dso *self); | 178 | char dso__symtab_origin(const struct dso *self); |
154 | void dso__set_long_name(struct dso *self, char *name); | 179 | void dso__set_long_name(struct dso *self, char *name); |
155 | void dso__set_build_id(struct dso *self, void *build_id); | 180 | void dso__set_build_id(struct dso *self, void *build_id); |
@@ -169,4 +194,6 @@ int kallsyms__parse(const char *filename, void *arg, | |||
169 | int symbol__init(void); | 194 | int symbol__init(void); |
170 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); | 195 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); |
171 | 196 | ||
197 | size_t vmlinux_path__fprintf(FILE *fp); | ||
198 | |||
172 | #endif /* __PERF_SYMBOL */ | 199 | #endif /* __PERF_SYMBOL */ |
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index fa968312ee7..1f7ecd47f49 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
@@ -7,13 +7,35 @@ | |||
7 | #include "util.h" | 7 | #include "util.h" |
8 | #include "debug.h" | 8 | #include "debug.h" |
9 | 9 | ||
10 | void map_groups__init(struct map_groups *self) | 10 | int find_all_tid(int pid, pid_t ** all_tid) |
11 | { | 11 | { |
12 | char name[256]; | ||
13 | int items; | ||
14 | struct dirent **namelist = NULL; | ||
15 | int ret = 0; | ||
12 | int i; | 16 | int i; |
13 | for (i = 0; i < MAP__NR_TYPES; ++i) { | 17 | |
14 | self->maps[i] = RB_ROOT; | 18 | sprintf(name, "/proc/%d/task", pid); |
15 | INIT_LIST_HEAD(&self->removed_maps[i]); | 19 | items = scandir(name, &namelist, NULL, NULL); |
20 | if (items <= 0) | ||
21 | return -ENOENT; | ||
22 | *all_tid = malloc(sizeof(pid_t) * items); | ||
23 | if (!*all_tid) { | ||
24 | ret = -ENOMEM; | ||
25 | goto failure; | ||
16 | } | 26 | } |
27 | |||
28 | for (i = 0; i < items; i++) | ||
29 | (*all_tid)[i] = atoi(namelist[i]->d_name); | ||
30 | |||
31 | ret = items; | ||
32 | |||
33 | failure: | ||
34 | for (i=0; i<items; i++) | ||
35 | free(namelist[i]); | ||
36 | free(namelist); | ||
37 | |||
38 | return ret; | ||
17 | } | 39 | } |
18 | 40 | ||
19 | static struct thread *thread__new(pid_t pid) | 41 | static struct thread *thread__new(pid_t pid) |
@@ -31,28 +53,6 @@ static struct thread *thread__new(pid_t pid) | |||
31 | return self; | 53 | return self; |
32 | } | 54 | } |
33 | 55 | ||
34 | static void map_groups__flush(struct map_groups *self) | ||
35 | { | ||
36 | int type; | ||
37 | |||
38 | for (type = 0; type < MAP__NR_TYPES; type++) { | ||
39 | struct rb_root *root = &self->maps[type]; | ||
40 | struct rb_node *next = rb_first(root); | ||
41 | |||
42 | while (next) { | ||
43 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
44 | next = rb_next(&pos->rb_node); | ||
45 | rb_erase(&pos->rb_node, root); | ||
46 | /* | ||
47 | * We may have references to this map, for | ||
48 | * instance in some hist_entry instances, so | ||
49 | * just move them to a separate list. | ||
50 | */ | ||
51 | list_add_tail(&pos->node, &self->removed_maps[pos->type]); | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | int thread__set_comm(struct thread *self, const char *comm) | 56 | int thread__set_comm(struct thread *self, const char *comm) |
57 | { | 57 | { |
58 | int err; | 58 | int err; |
@@ -79,69 +79,10 @@ int thread__comm_len(struct thread *self) | |||
79 | return self->comm_len; | 79 | return self->comm_len; |
80 | } | 80 | } |
81 | 81 | ||
82 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
83 | enum map_type type, FILE *fp) | ||
84 | { | ||
85 | size_t printed = fprintf(fp, "%s:\n", map_type__name[type]); | ||
86 | struct rb_node *nd; | ||
87 | |||
88 | for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) { | ||
89 | struct map *pos = rb_entry(nd, struct map, rb_node); | ||
90 | printed += fprintf(fp, "Map:"); | ||
91 | printed += map__fprintf(pos, fp); | ||
92 | if (verbose > 2) { | ||
93 | printed += dso__fprintf(pos->dso, type, fp); | ||
94 | printed += fprintf(fp, "--\n"); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | return printed; | ||
99 | } | ||
100 | |||
101 | size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp) | ||
102 | { | ||
103 | size_t printed = 0, i; | ||
104 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
105 | printed += __map_groups__fprintf_maps(self, i, fp); | ||
106 | return printed; | ||
107 | } | ||
108 | |||
109 | static size_t __map_groups__fprintf_removed_maps(struct map_groups *self, | ||
110 | enum map_type type, FILE *fp) | ||
111 | { | ||
112 | struct map *pos; | ||
113 | size_t printed = 0; | ||
114 | |||
115 | list_for_each_entry(pos, &self->removed_maps[type], node) { | ||
116 | printed += fprintf(fp, "Map:"); | ||
117 | printed += map__fprintf(pos, fp); | ||
118 | if (verbose > 1) { | ||
119 | printed += dso__fprintf(pos->dso, type, fp); | ||
120 | printed += fprintf(fp, "--\n"); | ||
121 | } | ||
122 | } | ||
123 | return printed; | ||
124 | } | ||
125 | |||
126 | static size_t map_groups__fprintf_removed_maps(struct map_groups *self, FILE *fp) | ||
127 | { | ||
128 | size_t printed = 0, i; | ||
129 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
130 | printed += __map_groups__fprintf_removed_maps(self, i, fp); | ||
131 | return printed; | ||
132 | } | ||
133 | |||
134 | static size_t map_groups__fprintf(struct map_groups *self, FILE *fp) | ||
135 | { | ||
136 | size_t printed = map_groups__fprintf_maps(self, fp); | ||
137 | printed += fprintf(fp, "Removed maps:\n"); | ||
138 | return printed + map_groups__fprintf_removed_maps(self, fp); | ||
139 | } | ||
140 | |||
141 | static size_t thread__fprintf(struct thread *self, FILE *fp) | 82 | static size_t thread__fprintf(struct thread *self, FILE *fp) |
142 | { | 83 | { |
143 | return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) + | 84 | return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) + |
144 | map_groups__fprintf(&self->mg, fp); | 85 | map_groups__fprintf(&self->mg, verbose, fp); |
145 | } | 86 | } |
146 | 87 | ||
147 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) | 88 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) |
@@ -183,127 +124,12 @@ struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) | |||
183 | return th; | 124 | return th; |
184 | } | 125 | } |
185 | 126 | ||
186 | static int map_groups__fixup_overlappings(struct map_groups *self, | ||
187 | struct map *map) | ||
188 | { | ||
189 | struct rb_root *root = &self->maps[map->type]; | ||
190 | struct rb_node *next = rb_first(root); | ||
191 | |||
192 | while (next) { | ||
193 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
194 | next = rb_next(&pos->rb_node); | ||
195 | |||
196 | if (!map__overlap(pos, map)) | ||
197 | continue; | ||
198 | |||
199 | if (verbose >= 2) { | ||
200 | fputs("overlapping maps:\n", stderr); | ||
201 | map__fprintf(map, stderr); | ||
202 | map__fprintf(pos, stderr); | ||
203 | } | ||
204 | |||
205 | rb_erase(&pos->rb_node, root); | ||
206 | /* | ||
207 | * We may have references to this map, for instance in some | ||
208 | * hist_entry instances, so just move them to a separate | ||
209 | * list. | ||
210 | */ | ||
211 | list_add_tail(&pos->node, &self->removed_maps[map->type]); | ||
212 | /* | ||
213 | * Now check if we need to create new maps for areas not | ||
214 | * overlapped by the new map: | ||
215 | */ | ||
216 | if (map->start > pos->start) { | ||
217 | struct map *before = map__clone(pos); | ||
218 | |||
219 | if (before == NULL) | ||
220 | return -ENOMEM; | ||
221 | |||
222 | before->end = map->start - 1; | ||
223 | map_groups__insert(self, before); | ||
224 | if (verbose >= 2) | ||
225 | map__fprintf(before, stderr); | ||
226 | } | ||
227 | |||
228 | if (map->end < pos->end) { | ||
229 | struct map *after = map__clone(pos); | ||
230 | |||
231 | if (after == NULL) | ||
232 | return -ENOMEM; | ||
233 | |||
234 | after->start = map->end + 1; | ||
235 | map_groups__insert(self, after); | ||
236 | if (verbose >= 2) | ||
237 | map__fprintf(after, stderr); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | void maps__insert(struct rb_root *maps, struct map *map) | ||
245 | { | ||
246 | struct rb_node **p = &maps->rb_node; | ||
247 | struct rb_node *parent = NULL; | ||
248 | const u64 ip = map->start; | ||
249 | struct map *m; | ||
250 | |||
251 | while (*p != NULL) { | ||
252 | parent = *p; | ||
253 | m = rb_entry(parent, struct map, rb_node); | ||
254 | if (ip < m->start) | ||
255 | p = &(*p)->rb_left; | ||
256 | else | ||
257 | p = &(*p)->rb_right; | ||
258 | } | ||
259 | |||
260 | rb_link_node(&map->rb_node, parent, p); | ||
261 | rb_insert_color(&map->rb_node, maps); | ||
262 | } | ||
263 | |||
264 | struct map *maps__find(struct rb_root *maps, u64 ip) | ||
265 | { | ||
266 | struct rb_node **p = &maps->rb_node; | ||
267 | struct rb_node *parent = NULL; | ||
268 | struct map *m; | ||
269 | |||
270 | while (*p != NULL) { | ||
271 | parent = *p; | ||
272 | m = rb_entry(parent, struct map, rb_node); | ||
273 | if (ip < m->start) | ||
274 | p = &(*p)->rb_left; | ||
275 | else if (ip > m->end) | ||
276 | p = &(*p)->rb_right; | ||
277 | else | ||
278 | return m; | ||
279 | } | ||
280 | |||
281 | return NULL; | ||
282 | } | ||
283 | |||
284 | void thread__insert_map(struct thread *self, struct map *map) | 127 | void thread__insert_map(struct thread *self, struct map *map) |
285 | { | 128 | { |
286 | map_groups__fixup_overlappings(&self->mg, map); | 129 | map_groups__fixup_overlappings(&self->mg, map, verbose, stderr); |
287 | map_groups__insert(&self->mg, map); | 130 | map_groups__insert(&self->mg, map); |
288 | } | 131 | } |
289 | 132 | ||
290 | /* | ||
291 | * XXX This should not really _copy_ te maps, but refcount them. | ||
292 | */ | ||
293 | static int map_groups__clone(struct map_groups *self, | ||
294 | struct map_groups *parent, enum map_type type) | ||
295 | { | ||
296 | struct rb_node *nd; | ||
297 | for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) { | ||
298 | struct map *map = rb_entry(nd, struct map, rb_node); | ||
299 | struct map *new = map__clone(map); | ||
300 | if (new == NULL) | ||
301 | return -ENOMEM; | ||
302 | map_groups__insert(self, new); | ||
303 | } | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | int thread__fork(struct thread *self, struct thread *parent) | 133 | int thread__fork(struct thread *self, struct thread *parent) |
308 | { | 134 | { |
309 | int i; | 135 | int i; |
@@ -336,15 +162,3 @@ size_t perf_session__fprintf(struct perf_session *self, FILE *fp) | |||
336 | 162 | ||
337 | return ret; | 163 | return ret; |
338 | } | 164 | } |
339 | |||
340 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
341 | enum map_type type, u64 addr, | ||
342 | symbol_filter_t filter) | ||
343 | { | ||
344 | struct map *map = map_groups__find(self, type, addr); | ||
345 | |||
346 | if (map != NULL) | ||
347 | return map__find_symbol(map, map->map_ip(map, addr), filter); | ||
348 | |||
349 | return NULL; | ||
350 | } | ||
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index dcf70303e58..9c488fcadec 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h | |||
@@ -5,14 +5,6 @@ | |||
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include "symbol.h" | 6 | #include "symbol.h" |
7 | 7 | ||
8 | struct map_groups { | ||
9 | struct rb_root maps[MAP__NR_TYPES]; | ||
10 | struct list_head removed_maps[MAP__NR_TYPES]; | ||
11 | }; | ||
12 | |||
13 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
14 | enum map_type type, FILE *fp); | ||
15 | |||
16 | struct thread { | 8 | struct thread { |
17 | struct rb_node rb_node; | 9 | struct rb_node rb_node; |
18 | struct map_groups mg; | 10 | struct map_groups mg; |
@@ -23,29 +15,16 @@ struct thread { | |||
23 | int comm_len; | 15 | int comm_len; |
24 | }; | 16 | }; |
25 | 17 | ||
26 | void map_groups__init(struct map_groups *self); | 18 | struct perf_session; |
19 | |||
20 | int find_all_tid(int pid, pid_t ** all_tid); | ||
27 | int thread__set_comm(struct thread *self, const char *comm); | 21 | int thread__set_comm(struct thread *self, const char *comm); |
28 | int thread__comm_len(struct thread *self); | 22 | int thread__comm_len(struct thread *self); |
29 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid); | 23 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid); |
30 | void thread__insert_map(struct thread *self, struct map *map); | 24 | void thread__insert_map(struct thread *self, struct map *map); |
31 | int thread__fork(struct thread *self, struct thread *parent); | 25 | int thread__fork(struct thread *self, struct thread *parent); |
32 | size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp); | ||
33 | size_t perf_session__fprintf(struct perf_session *self, FILE *fp); | 26 | size_t perf_session__fprintf(struct perf_session *self, FILE *fp); |
34 | 27 | ||
35 | void maps__insert(struct rb_root *maps, struct map *map); | ||
36 | struct map *maps__find(struct rb_root *maps, u64 addr); | ||
37 | |||
38 | static inline void map_groups__insert(struct map_groups *self, struct map *map) | ||
39 | { | ||
40 | maps__insert(&self->maps[map->type], map); | ||
41 | } | ||
42 | |||
43 | static inline struct map *map_groups__find(struct map_groups *self, | ||
44 | enum map_type type, u64 addr) | ||
45 | { | ||
46 | return maps__find(&self->maps[type], addr); | ||
47 | } | ||
48 | |||
49 | static inline struct map *thread__find_map(struct thread *self, | 28 | static inline struct map *thread__find_map(struct thread *self, |
50 | enum map_type type, u64 addr) | 29 | enum map_type type, u64 addr) |
51 | { | 30 | { |
@@ -62,26 +41,4 @@ void thread__find_addr_location(struct thread *self, | |||
62 | enum map_type type, u64 addr, | 41 | enum map_type type, u64 addr, |
63 | struct addr_location *al, | 42 | struct addr_location *al, |
64 | symbol_filter_t filter); | 43 | symbol_filter_t filter); |
65 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
66 | enum map_type type, u64 addr, | ||
67 | symbol_filter_t filter); | ||
68 | |||
69 | static inline struct symbol *map_groups__find_function(struct map_groups *self, | ||
70 | u64 addr, | ||
71 | symbol_filter_t filter) | ||
72 | { | ||
73 | return map_groups__find_symbol(self, MAP__FUNCTION, addr, filter); | ||
74 | } | ||
75 | |||
76 | struct map *map_groups__find_by_name(struct map_groups *self, | ||
77 | enum map_type type, const char *name); | ||
78 | |||
79 | int __map_groups__create_kernel_maps(struct map_groups *self, | ||
80 | struct map *vmlinux_maps[MAP__NR_TYPES], | ||
81 | struct dso *kernel); | ||
82 | int map_groups__create_kernel_maps(struct map_groups *self, | ||
83 | struct map *vmlinux_maps[MAP__NR_TYPES]); | ||
84 | |||
85 | struct map *map_groups__new_module(struct map_groups *self, u64 start, | ||
86 | const char *filename); | ||
87 | #endif /* __PERF_THREAD_H */ | 44 | #endif /* __PERF_THREAD_H */ |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 0f5b2a6f108..fbf45d1b26f 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -42,12 +42,14 @@ | |||
42 | #define _ALL_SOURCE 1 | 42 | #define _ALL_SOURCE 1 |
43 | #define _GNU_SOURCE 1 | 43 | #define _GNU_SOURCE 1 |
44 | #define _BSD_SOURCE 1 | 44 | #define _BSD_SOURCE 1 |
45 | #define HAS_BOOL | ||
45 | 46 | ||
46 | #include <unistd.h> | 47 | #include <unistd.h> |
47 | #include <stdio.h> | 48 | #include <stdio.h> |
48 | #include <sys/stat.h> | 49 | #include <sys/stat.h> |
49 | #include <sys/statfs.h> | 50 | #include <sys/statfs.h> |
50 | #include <fcntl.h> | 51 | #include <fcntl.h> |
52 | #include <stdbool.h> | ||
51 | #include <stddef.h> | 53 | #include <stddef.h> |
52 | #include <stdlib.h> | 54 | #include <stdlib.h> |
53 | #include <stdarg.h> | 55 | #include <stdarg.h> |
@@ -78,6 +80,7 @@ | |||
78 | #include <pwd.h> | 80 | #include <pwd.h> |
79 | #include <inttypes.h> | 81 | #include <inttypes.h> |
80 | #include "../../../include/linux/magic.h" | 82 | #include "../../../include/linux/magic.h" |
83 | #include "types.h" | ||
81 | 84 | ||
82 | 85 | ||
83 | #ifndef NO_ICONV | 86 | #ifndef NO_ICONV |
@@ -295,6 +298,13 @@ extern void *xmemdupz(const void *data, size_t len); | |||
295 | extern char *xstrndup(const char *str, size_t len); | 298 | extern char *xstrndup(const char *str, size_t len); |
296 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); | 299 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); |
297 | 300 | ||
301 | static inline void *xzalloc(size_t size) | ||
302 | { | ||
303 | void *buf = xmalloc(size); | ||
304 | |||
305 | return memset(buf, 0, size); | ||
306 | } | ||
307 | |||
298 | static inline void *zalloc(size_t size) | 308 | static inline void *zalloc(size_t size) |
299 | { | 309 | { |
300 | return calloc(1, size); | 310 | return calloc(1, size); |
@@ -309,6 +319,7 @@ static inline int has_extension(const char *filename, const char *ext) | |||
309 | { | 319 | { |
310 | size_t len = strlen(filename); | 320 | size_t len = strlen(filename); |
311 | size_t extlen = strlen(ext); | 321 | size_t extlen = strlen(ext); |
322 | |||
312 | return len > extlen && !memcmp(filename + len - extlen, ext, extlen); | 323 | return len > extlen && !memcmp(filename + len - extlen, ext, extlen); |
313 | } | 324 | } |
314 | 325 | ||
@@ -322,6 +333,7 @@ static inline int has_extension(const char *filename, const char *ext) | |||
322 | #undef isalnum | 333 | #undef isalnum |
323 | #undef tolower | 334 | #undef tolower |
324 | #undef toupper | 335 | #undef toupper |
336 | |||
325 | extern unsigned char sane_ctype[256]; | 337 | extern unsigned char sane_ctype[256]; |
326 | #define GIT_SPACE 0x01 | 338 | #define GIT_SPACE 0x01 |
327 | #define GIT_DIGIT 0x02 | 339 | #define GIT_DIGIT 0x02 |
@@ -406,4 +418,13 @@ void git_qsort(void *base, size_t nmemb, size_t size, | |||
406 | int mkdir_p(char *path, mode_t mode); | 418 | int mkdir_p(char *path, mode_t mode); |
407 | int copyfile(const char *from, const char *to); | 419 | int copyfile(const char *from, const char *to); |
408 | 420 | ||
421 | s64 perf_atoll(const char *str); | ||
422 | char **argv_split(const char *str, int *argcp); | ||
423 | void argv_free(char **argv); | ||
424 | bool strglobmatch(const char *str, const char *pat); | ||
425 | bool strlazymatch(const char *str, const char *pat); | ||
426 | |||
427 | #define _STR(x) #x | ||
428 | #define STR(x) _STR(x) | ||
429 | |||
409 | #endif | 430 | #endif |