diff options
35 files changed, 1560 insertions, 355 deletions
diff --git a/Documentation/tracepoints.txt b/Documentation/tracepoints.txt index 4ff43c6de299..c0e1ceed75a4 100644 --- a/Documentation/tracepoints.txt +++ b/Documentation/tracepoints.txt | |||
@@ -103,13 +103,14 @@ used to export the defined tracepoints. | |||
103 | 103 | ||
104 | * Probe / tracepoint example | 104 | * Probe / tracepoint example |
105 | 105 | ||
106 | See the example provided in samples/tracepoints/src | 106 | See the example provided in samples/tracepoints |
107 | 107 | ||
108 | Compile them with your kernel. | 108 | Compile them with your kernel. They are built during 'make' (not |
109 | 'make modules') when CONFIG_SAMPLE_TRACEPOINTS=m. | ||
109 | 110 | ||
110 | Run, as root : | 111 | Run, as root : |
111 | modprobe tracepoint-example (insmod order is not important) | 112 | modprobe tracepoint-sample (insmod order is not important) |
112 | modprobe tracepoint-probe-example | 113 | modprobe tracepoint-probe-sample |
113 | cat /proc/tracepoint-example (returns an expected error) | 114 | cat /proc/tracepoint-sample (returns an expected error) |
114 | rmmod tracepoint-example tracepoint-probe-example | 115 | rmmod tracepoint-sample tracepoint-probe-sample |
115 | dmesg | 116 | dmesg |
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 1d0d7f42efe3..61df77532120 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c | |||
@@ -79,11 +79,11 @@ static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr) | |||
79 | * | 79 | * |
80 | * 1) Put the instruction pointer into the IP buffer | 80 | * 1) Put the instruction pointer into the IP buffer |
81 | * and the new code into the "code" buffer. | 81 | * and the new code into the "code" buffer. |
82 | * 2) Set a flag that says we are modifying code | 82 | * 2) Wait for any running NMIs to finish and set a flag that says |
83 | * 3) Wait for any running NMIs to finish. | 83 | * we are modifying code, it is done in an atomic operation. |
84 | * 4) Write the code | 84 | * 3) Write the code |
85 | * 5) clear the flag. | 85 | * 4) clear the flag. |
86 | * 6) Wait for any running NMIs to finish. | 86 | * 5) Wait for any running NMIs to finish. |
87 | * | 87 | * |
88 | * If an NMI is executed, the first thing it does is to call | 88 | * If an NMI is executed, the first thing it does is to call |
89 | * "ftrace_nmi_enter". This will check if the flag is set to write | 89 | * "ftrace_nmi_enter". This will check if the flag is set to write |
@@ -95,9 +95,9 @@ static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr) | |||
95 | * are the same as what exists. | 95 | * are the same as what exists. |
96 | */ | 96 | */ |
97 | 97 | ||
98 | #define MOD_CODE_WRITE_FLAG (1 << 31) /* set when NMI should do the write */ | ||
98 | static atomic_t nmi_running = ATOMIC_INIT(0); | 99 | static atomic_t nmi_running = ATOMIC_INIT(0); |
99 | static int mod_code_status; /* holds return value of text write */ | 100 | static int mod_code_status; /* holds return value of text write */ |
100 | static int mod_code_write; /* set when NMI should do the write */ | ||
101 | static void *mod_code_ip; /* holds the IP to write to */ | 101 | static void *mod_code_ip; /* holds the IP to write to */ |
102 | static void *mod_code_newcode; /* holds the text to write to the IP */ | 102 | static void *mod_code_newcode; /* holds the text to write to the IP */ |
103 | 103 | ||
@@ -114,6 +114,20 @@ int ftrace_arch_read_dyn_info(char *buf, int size) | |||
114 | return r; | 114 | return r; |
115 | } | 115 | } |
116 | 116 | ||
117 | static void clear_mod_flag(void) | ||
118 | { | ||
119 | int old = atomic_read(&nmi_running); | ||
120 | |||
121 | for (;;) { | ||
122 | int new = old & ~MOD_CODE_WRITE_FLAG; | ||
123 | |||
124 | if (old == new) | ||
125 | break; | ||
126 | |||
127 | old = atomic_cmpxchg(&nmi_running, old, new); | ||
128 | } | ||
129 | } | ||
130 | |||
117 | static void ftrace_mod_code(void) | 131 | static void ftrace_mod_code(void) |
118 | { | 132 | { |
119 | /* | 133 | /* |
@@ -127,27 +141,39 @@ static void ftrace_mod_code(void) | |||
127 | 141 | ||
128 | /* if we fail, then kill any new writers */ | 142 | /* if we fail, then kill any new writers */ |
129 | if (mod_code_status) | 143 | if (mod_code_status) |
130 | mod_code_write = 0; | 144 | clear_mod_flag(); |
131 | } | 145 | } |
132 | 146 | ||
133 | void ftrace_nmi_enter(void) | 147 | void ftrace_nmi_enter(void) |
134 | { | 148 | { |
135 | atomic_inc(&nmi_running); | 149 | if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) { |
136 | /* Must have nmi_running seen before reading write flag */ | 150 | smp_rmb(); |
137 | smp_mb(); | ||
138 | if (mod_code_write) { | ||
139 | ftrace_mod_code(); | 151 | ftrace_mod_code(); |
140 | atomic_inc(&nmi_update_count); | 152 | atomic_inc(&nmi_update_count); |
141 | } | 153 | } |
154 | /* Must have previous changes seen before executions */ | ||
155 | smp_mb(); | ||
142 | } | 156 | } |
143 | 157 | ||
144 | void ftrace_nmi_exit(void) | 158 | void ftrace_nmi_exit(void) |
145 | { | 159 | { |
146 | /* Finish all executions before clearing nmi_running */ | 160 | /* Finish all executions before clearing nmi_running */ |
147 | smp_wmb(); | 161 | smp_mb(); |
148 | atomic_dec(&nmi_running); | 162 | atomic_dec(&nmi_running); |
149 | } | 163 | } |
150 | 164 | ||
165 | static void wait_for_nmi_and_set_mod_flag(void) | ||
166 | { | ||
167 | if (!atomic_cmpxchg(&nmi_running, 0, MOD_CODE_WRITE_FLAG)) | ||
168 | return; | ||
169 | |||
170 | do { | ||
171 | cpu_relax(); | ||
172 | } while (atomic_cmpxchg(&nmi_running, 0, MOD_CODE_WRITE_FLAG)); | ||
173 | |||
174 | nmi_wait_count++; | ||
175 | } | ||
176 | |||
151 | static void wait_for_nmi(void) | 177 | static void wait_for_nmi(void) |
152 | { | 178 | { |
153 | if (!atomic_read(&nmi_running)) | 179 | if (!atomic_read(&nmi_running)) |
@@ -167,14 +193,9 @@ do_ftrace_mod_code(unsigned long ip, void *new_code) | |||
167 | mod_code_newcode = new_code; | 193 | mod_code_newcode = new_code; |
168 | 194 | ||
169 | /* The buffers need to be visible before we let NMIs write them */ | 195 | /* The buffers need to be visible before we let NMIs write them */ |
170 | smp_wmb(); | ||
171 | |||
172 | mod_code_write = 1; | ||
173 | |||
174 | /* Make sure write bit is visible before we wait on NMIs */ | ||
175 | smp_mb(); | 196 | smp_mb(); |
176 | 197 | ||
177 | wait_for_nmi(); | 198 | wait_for_nmi_and_set_mod_flag(); |
178 | 199 | ||
179 | /* Make sure all running NMIs have finished before we write the code */ | 200 | /* Make sure all running NMIs have finished before we write the code */ |
180 | smp_mb(); | 201 | smp_mb(); |
@@ -182,13 +203,9 @@ do_ftrace_mod_code(unsigned long ip, void *new_code) | |||
182 | ftrace_mod_code(); | 203 | ftrace_mod_code(); |
183 | 204 | ||
184 | /* Make sure the write happens before clearing the bit */ | 205 | /* Make sure the write happens before clearing the bit */ |
185 | smp_wmb(); | ||
186 | |||
187 | mod_code_write = 0; | ||
188 | |||
189 | /* make sure NMIs see the cleared bit */ | ||
190 | smp_mb(); | 206 | smp_mb(); |
191 | 207 | ||
208 | clear_mod_flag(); | ||
192 | wait_for_nmi(); | 209 | wait_for_nmi(); |
193 | 210 | ||
194 | return mod_code_status; | 211 | return mod_code_status; |
@@ -393,7 +410,6 @@ int ftrace_disable_ftrace_graph_caller(void) | |||
393 | void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr) | 410 | void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr) |
394 | { | 411 | { |
395 | unsigned long old; | 412 | unsigned long old; |
396 | unsigned long long calltime; | ||
397 | int faulted; | 413 | int faulted; |
398 | struct ftrace_graph_ent trace; | 414 | struct ftrace_graph_ent trace; |
399 | unsigned long return_hooker = (unsigned long) | 415 | unsigned long return_hooker = (unsigned long) |
@@ -436,10 +452,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr) | |||
436 | return; | 452 | return; |
437 | } | 453 | } |
438 | 454 | ||
439 | calltime = trace_clock_local(); | 455 | if (ftrace_push_return_trace(old, self_addr, &trace.depth) == -EBUSY) { |
440 | |||
441 | if (ftrace_push_return_trace(old, calltime, | ||
442 | self_addr, &trace.depth) == -EBUSY) { | ||
443 | *parent = old; | 456 | *parent = old; |
444 | return; | 457 | return; |
445 | } | 458 | } |
diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c index 4558dd3918cf..759095d53a06 100644 --- a/arch/x86/kernel/kprobes.c +++ b/arch/x86/kernel/kprobes.c | |||
@@ -638,13 +638,13 @@ static void __used __kprobes kretprobe_trampoline_holder(void) | |||
638 | #else | 638 | #else |
639 | " pushf\n" | 639 | " pushf\n" |
640 | /* | 640 | /* |
641 | * Skip cs, ip, orig_ax. | 641 | * Skip cs, ip, orig_ax and gs. |
642 | * trampoline_handler() will plug in these values | 642 | * trampoline_handler() will plug in these values |
643 | */ | 643 | */ |
644 | " subl $12, %esp\n" | 644 | " subl $16, %esp\n" |
645 | " pushl %fs\n" | 645 | " pushl %fs\n" |
646 | " pushl %ds\n" | ||
647 | " pushl %es\n" | 646 | " pushl %es\n" |
647 | " pushl %ds\n" | ||
648 | " pushl %eax\n" | 648 | " pushl %eax\n" |
649 | " pushl %ebp\n" | 649 | " pushl %ebp\n" |
650 | " pushl %edi\n" | 650 | " pushl %edi\n" |
@@ -655,10 +655,10 @@ static void __used __kprobes kretprobe_trampoline_holder(void) | |||
655 | " movl %esp, %eax\n" | 655 | " movl %esp, %eax\n" |
656 | " call trampoline_handler\n" | 656 | " call trampoline_handler\n" |
657 | /* Move flags to cs */ | 657 | /* Move flags to cs */ |
658 | " movl 52(%esp), %edx\n" | 658 | " movl 56(%esp), %edx\n" |
659 | " movl %edx, 48(%esp)\n" | 659 | " movl %edx, 52(%esp)\n" |
660 | /* Replace saved flags with true return address. */ | 660 | /* Replace saved flags with true return address. */ |
661 | " movl %eax, 52(%esp)\n" | 661 | " movl %eax, 56(%esp)\n" |
662 | " popl %ebx\n" | 662 | " popl %ebx\n" |
663 | " popl %ecx\n" | 663 | " popl %ecx\n" |
664 | " popl %edx\n" | 664 | " popl %edx\n" |
@@ -666,8 +666,8 @@ static void __used __kprobes kretprobe_trampoline_holder(void) | |||
666 | " popl %edi\n" | 666 | " popl %edi\n" |
667 | " popl %ebp\n" | 667 | " popl %ebp\n" |
668 | " popl %eax\n" | 668 | " popl %eax\n" |
669 | /* Skip ip, orig_ax, es, ds, fs */ | 669 | /* Skip ds, es, fs, gs, orig_ax and ip */ |
670 | " addl $20, %esp\n" | 670 | " addl $24, %esp\n" |
671 | " popf\n" | 671 | " popf\n" |
672 | #endif | 672 | #endif |
673 | " ret\n"); | 673 | " ret\n"); |
@@ -691,6 +691,7 @@ static __used __kprobes void *trampoline_handler(struct pt_regs *regs) | |||
691 | regs->cs = __KERNEL_CS; | 691 | regs->cs = __KERNEL_CS; |
692 | #else | 692 | #else |
693 | regs->cs = __KERNEL_CS | get_kernel_rpl(); | 693 | regs->cs = __KERNEL_CS | get_kernel_rpl(); |
694 | regs->gs = 0; | ||
694 | #endif | 695 | #endif |
695 | regs->ip = trampoline_address; | 696 | regs->ip = trampoline_address; |
696 | regs->orig_ax = ~0UL; | 697 | regs->orig_ax = ~0UL; |
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 81ae9ea3c6e1..0662ba6de85a 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c | |||
@@ -30,6 +30,7 @@ | |||
30 | 30 | ||
31 | static struct vfsmount *debugfs_mount; | 31 | static struct vfsmount *debugfs_mount; |
32 | static int debugfs_mount_count; | 32 | static int debugfs_mount_count; |
33 | static bool debugfs_registered; | ||
33 | 34 | ||
34 | static struct inode *debugfs_get_inode(struct super_block *sb, int mode, dev_t dev) | 35 | static struct inode *debugfs_get_inode(struct super_block *sb, int mode, dev_t dev) |
35 | { | 36 | { |
@@ -496,6 +497,16 @@ exit: | |||
496 | } | 497 | } |
497 | EXPORT_SYMBOL_GPL(debugfs_rename); | 498 | EXPORT_SYMBOL_GPL(debugfs_rename); |
498 | 499 | ||
500 | /** | ||
501 | * debugfs_initialized - Tells whether debugfs has been registered | ||
502 | */ | ||
503 | bool debugfs_initialized(void) | ||
504 | { | ||
505 | return debugfs_registered; | ||
506 | } | ||
507 | EXPORT_SYMBOL_GPL(debugfs_initialized); | ||
508 | |||
509 | |||
499 | static struct kobject *debug_kobj; | 510 | static struct kobject *debug_kobj; |
500 | 511 | ||
501 | static int __init debugfs_init(void) | 512 | static int __init debugfs_init(void) |
@@ -509,11 +520,16 @@ static int __init debugfs_init(void) | |||
509 | retval = register_filesystem(&debug_fs_type); | 520 | retval = register_filesystem(&debug_fs_type); |
510 | if (retval) | 521 | if (retval) |
511 | kobject_put(debug_kobj); | 522 | kobject_put(debug_kobj); |
523 | else | ||
524 | debugfs_registered = true; | ||
525 | |||
512 | return retval; | 526 | return retval; |
513 | } | 527 | } |
514 | 528 | ||
515 | static void __exit debugfs_exit(void) | 529 | static void __exit debugfs_exit(void) |
516 | { | 530 | { |
531 | debugfs_registered = false; | ||
532 | |||
517 | simple_release_fs(&debugfs_mount, &debugfs_mount_count); | 533 | simple_release_fs(&debugfs_mount, &debugfs_mount_count); |
518 | unregister_filesystem(&debug_fs_type); | 534 | unregister_filesystem(&debug_fs_type); |
519 | kobject_put(debug_kobj); | 535 | kobject_put(debug_kobj); |
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index af0e01d4c663..eb5c2ba2f81a 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h | |||
@@ -71,6 +71,9 @@ struct dentry *debugfs_create_bool(const char *name, mode_t mode, | |||
71 | struct dentry *debugfs_create_blob(const char *name, mode_t mode, | 71 | struct dentry *debugfs_create_blob(const char *name, mode_t mode, |
72 | struct dentry *parent, | 72 | struct dentry *parent, |
73 | struct debugfs_blob_wrapper *blob); | 73 | struct debugfs_blob_wrapper *blob); |
74 | |||
75 | bool debugfs_initialized(void); | ||
76 | |||
74 | #else | 77 | #else |
75 | 78 | ||
76 | #include <linux/err.h> | 79 | #include <linux/err.h> |
@@ -183,6 +186,11 @@ static inline struct dentry *debugfs_create_blob(const char *name, mode_t mode, | |||
183 | return ERR_PTR(-ENODEV); | 186 | return ERR_PTR(-ENODEV); |
184 | } | 187 | } |
185 | 188 | ||
189 | static inline bool debugfs_initialized(void) | ||
190 | { | ||
191 | return false; | ||
192 | } | ||
193 | |||
186 | #endif | 194 | #endif |
187 | 195 | ||
188 | #endif | 196 | #endif |
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index db3fed630db3..015a3d22cf74 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h | |||
@@ -145,9 +145,15 @@ enum { | |||
145 | }; | 145 | }; |
146 | 146 | ||
147 | struct dyn_ftrace { | 147 | struct dyn_ftrace { |
148 | unsigned long ip; /* address of mcount call-site */ | 148 | union { |
149 | unsigned long flags; | 149 | unsigned long ip; /* address of mcount call-site */ |
150 | struct dyn_arch_ftrace arch; | 150 | struct dyn_ftrace *freelist; |
151 | }; | ||
152 | union { | ||
153 | unsigned long flags; | ||
154 | struct dyn_ftrace *newlist; | ||
155 | }; | ||
156 | struct dyn_arch_ftrace arch; | ||
151 | }; | 157 | }; |
152 | 158 | ||
153 | int ftrace_force_update(void); | 159 | int ftrace_force_update(void); |
@@ -369,8 +375,7 @@ struct ftrace_ret_stack { | |||
369 | extern void return_to_handler(void); | 375 | extern void return_to_handler(void); |
370 | 376 | ||
371 | extern int | 377 | extern int |
372 | ftrace_push_return_trace(unsigned long ret, unsigned long long time, | 378 | ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth); |
373 | unsigned long func, int *depth); | ||
374 | extern void | 379 | extern void |
375 | ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret); | 380 | ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret); |
376 | 381 | ||
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index 9e6052bd1a1c..e1b7b2173885 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h | |||
@@ -18,10 +18,13 @@ struct ring_buffer_event { | |||
18 | /** | 18 | /** |
19 | * enum ring_buffer_type - internal ring buffer types | 19 | * enum ring_buffer_type - internal ring buffer types |
20 | * | 20 | * |
21 | * @RINGBUF_TYPE_PADDING: Left over page padding | 21 | * @RINGBUF_TYPE_PADDING: Left over page padding or discarded event |
22 | * array is ignored | 22 | * If time_delta is 0: |
23 | * size is variable depending on how much | 23 | * array is ignored |
24 | * size is variable depending on how much | ||
24 | * padding is needed | 25 | * padding is needed |
26 | * If time_delta is non zero: | ||
27 | * everything else same as RINGBUF_TYPE_DATA | ||
25 | * | 28 | * |
26 | * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta | 29 | * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta |
27 | * array[0] = time delta (28 .. 59) | 30 | * array[0] = time delta (28 .. 59) |
@@ -65,6 +68,8 @@ ring_buffer_event_time_delta(struct ring_buffer_event *event) | |||
65 | return event->time_delta; | 68 | return event->time_delta; |
66 | } | 69 | } |
67 | 70 | ||
71 | void ring_buffer_event_discard(struct ring_buffer_event *event); | ||
72 | |||
68 | /* | 73 | /* |
69 | * size is in bytes for each per CPU buffer. | 74 | * size is in bytes for each per CPU buffer. |
70 | */ | 75 | */ |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 89cd308cc7a5..471e36d30123 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1409,6 +1409,8 @@ struct task_struct { | |||
1409 | int curr_ret_stack; | 1409 | int curr_ret_stack; |
1410 | /* Stack of return addresses for return function tracing */ | 1410 | /* Stack of return addresses for return function tracing */ |
1411 | struct ftrace_ret_stack *ret_stack; | 1411 | struct ftrace_ret_stack *ret_stack; |
1412 | /* time stamp for last schedule */ | ||
1413 | unsigned long long ftrace_timestamp; | ||
1412 | /* | 1414 | /* |
1413 | * Number of functions that haven't been traced | 1415 | * Number of functions that haven't been traced |
1414 | * because of depth overrun. | 1416 | * because of depth overrun. |
diff --git a/init/main.c b/init/main.c index 20d784ab5ef8..b0097d2b63ae 100644 --- a/init/main.c +++ b/init/main.c | |||
@@ -772,6 +772,7 @@ static void __init do_basic_setup(void) | |||
772 | { | 772 | { |
773 | rcu_init_sched(); /* needed by module_init stage. */ | 773 | rcu_init_sched(); /* needed by module_init stage. */ |
774 | init_workqueues(); | 774 | init_workqueues(); |
775 | cpuset_init_smp(); | ||
775 | usermodehelper_init(); | 776 | usermodehelper_init(); |
776 | driver_init(); | 777 | driver_init(); |
777 | init_irq_proc(); | 778 | init_irq_proc(); |
@@ -865,8 +866,6 @@ static int __init kernel_init(void * unused) | |||
865 | smp_init(); | 866 | smp_init(); |
866 | sched_init_smp(); | 867 | sched_init_smp(); |
867 | 868 | ||
868 | cpuset_init_smp(); | ||
869 | |||
870 | do_basic_setup(); | 869 | do_basic_setup(); |
871 | 870 | ||
872 | /* | 871 | /* |
diff --git a/kernel/extable.c b/kernel/extable.c index 0df6253730be..b54a6017b6b5 100644 --- a/kernel/extable.c +++ b/kernel/extable.c | |||
@@ -15,11 +15,22 @@ | |||
15 | along with this program; if not, write to the Free Software | 15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | */ | 17 | */ |
18 | #include <linux/ftrace.h> | ||
19 | #include <linux/memory.h> | ||
18 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/mutex.h> | ||
19 | #include <linux/init.h> | 22 | #include <linux/init.h> |
20 | #include <linux/ftrace.h> | 23 | |
21 | #include <asm/uaccess.h> | ||
22 | #include <asm/sections.h> | 24 | #include <asm/sections.h> |
25 | #include <asm/uaccess.h> | ||
26 | |||
27 | /* | ||
28 | * mutex protecting text section modification (dynamic code patching). | ||
29 | * some users need to sleep (allocating memory...) while they hold this lock. | ||
30 | * | ||
31 | * NOT exported to modules - patching kernel text is a really delicate matter. | ||
32 | */ | ||
33 | DEFINE_MUTEX(text_mutex); | ||
23 | 34 | ||
24 | extern struct exception_table_entry __start___ex_table[]; | 35 | extern struct exception_table_entry __start___ex_table[]; |
25 | extern struct exception_table_entry __stop___ex_table[]; | 36 | extern struct exception_table_entry __stop___ex_table[]; |
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index b0a46f889659..8a4d72931042 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig | |||
@@ -63,7 +63,11 @@ config TRACING | |||
63 | # | 63 | # |
64 | config TRACING_SUPPORT | 64 | config TRACING_SUPPORT |
65 | bool | 65 | bool |
66 | depends on TRACE_IRQFLAGS_SUPPORT | 66 | # PPC32 has no irqflags tracing support, but it can use most of the |
67 | # tracers anyway, they were tested to build and work. Note that new | ||
68 | # exceptions to this list aren't welcomed, better implement the | ||
69 | # irqflags tracing for your architecture. | ||
70 | depends on TRACE_IRQFLAGS_SUPPORT || PPC32 | ||
67 | depends on STACKTRACE_SUPPORT | 71 | depends on STACKTRACE_SUPPORT |
68 | default y | 72 | default y |
69 | 73 | ||
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index c3feea01c3e0..2630f5121ec1 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile | |||
@@ -44,5 +44,7 @@ obj-$(CONFIG_EVENT_TRACER) += trace_events.o | |||
44 | obj-$(CONFIG_EVENT_TRACER) += events.o | 44 | obj-$(CONFIG_EVENT_TRACER) += events.o |
45 | obj-$(CONFIG_EVENT_TRACER) += trace_export.o | 45 | obj-$(CONFIG_EVENT_TRACER) += trace_export.o |
46 | obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o | 46 | obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o |
47 | obj-$(CONFIG_EVENT_PROFILE) += trace_event_profile.o | ||
48 | obj-$(CONFIG_EVENT_TRACER) += trace_events_filter.o | ||
47 | 49 | ||
48 | libftrace-y := ftrace.o | 50 | libftrace-y := ftrace.o |
diff --git a/kernel/trace/events.c b/kernel/trace/events.c index 9fc918da404f..246f2aa6dc46 100644 --- a/kernel/trace/events.c +++ b/kernel/trace/events.c | |||
@@ -12,4 +12,3 @@ | |||
12 | #include "trace_events_stage_2.h" | 12 | #include "trace_events_stage_2.h" |
13 | #include "trace_events_stage_3.h" | 13 | #include "trace_events_stage_3.h" |
14 | 14 | ||
15 | #include <trace/trace_event_types.h> | ||
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 7847806eefef..1752a63f37c0 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -29,6 +29,8 @@ | |||
29 | #include <linux/list.h> | 29 | #include <linux/list.h> |
30 | #include <linux/hash.h> | 30 | #include <linux/hash.h> |
31 | 31 | ||
32 | #include <trace/sched.h> | ||
33 | |||
32 | #include <asm/ftrace.h> | 34 | #include <asm/ftrace.h> |
33 | 35 | ||
34 | #include "trace.h" | 36 | #include "trace.h" |
@@ -339,7 +341,7 @@ static inline int record_frozen(struct dyn_ftrace *rec) | |||
339 | 341 | ||
340 | static void ftrace_free_rec(struct dyn_ftrace *rec) | 342 | static void ftrace_free_rec(struct dyn_ftrace *rec) |
341 | { | 343 | { |
342 | rec->ip = (unsigned long)ftrace_free_records; | 344 | rec->freelist = ftrace_free_records; |
343 | ftrace_free_records = rec; | 345 | ftrace_free_records = rec; |
344 | rec->flags |= FTRACE_FL_FREE; | 346 | rec->flags |= FTRACE_FL_FREE; |
345 | } | 347 | } |
@@ -356,9 +358,14 @@ void ftrace_release(void *start, unsigned long size) | |||
356 | 358 | ||
357 | mutex_lock(&ftrace_lock); | 359 | mutex_lock(&ftrace_lock); |
358 | do_for_each_ftrace_rec(pg, rec) { | 360 | do_for_each_ftrace_rec(pg, rec) { |
359 | if ((rec->ip >= s) && (rec->ip < e) && | 361 | if ((rec->ip >= s) && (rec->ip < e)) { |
360 | !(rec->flags & FTRACE_FL_FREE)) | 362 | /* |
363 | * rec->ip is changed in ftrace_free_rec() | ||
364 | * It should not between s and e if record was freed. | ||
365 | */ | ||
366 | FTRACE_WARN_ON(rec->flags & FTRACE_FL_FREE); | ||
361 | ftrace_free_rec(rec); | 367 | ftrace_free_rec(rec); |
368 | } | ||
362 | } while_for_each_ftrace_rec(); | 369 | } while_for_each_ftrace_rec(); |
363 | mutex_unlock(&ftrace_lock); | 370 | mutex_unlock(&ftrace_lock); |
364 | } | 371 | } |
@@ -377,7 +384,7 @@ static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip) | |||
377 | return NULL; | 384 | return NULL; |
378 | } | 385 | } |
379 | 386 | ||
380 | ftrace_free_records = (void *)rec->ip; | 387 | ftrace_free_records = rec->freelist; |
381 | memset(rec, 0, sizeof(*rec)); | 388 | memset(rec, 0, sizeof(*rec)); |
382 | return rec; | 389 | return rec; |
383 | } | 390 | } |
@@ -409,7 +416,7 @@ ftrace_record_ip(unsigned long ip) | |||
409 | return NULL; | 416 | return NULL; |
410 | 417 | ||
411 | rec->ip = ip; | 418 | rec->ip = ip; |
412 | rec->flags = (unsigned long)ftrace_new_addrs; | 419 | rec->newlist = ftrace_new_addrs; |
413 | ftrace_new_addrs = rec; | 420 | ftrace_new_addrs = rec; |
414 | 421 | ||
415 | return rec; | 422 | return rec; |
@@ -729,7 +736,7 @@ static int ftrace_update_code(struct module *mod) | |||
729 | return -1; | 736 | return -1; |
730 | 737 | ||
731 | p = ftrace_new_addrs; | 738 | p = ftrace_new_addrs; |
732 | ftrace_new_addrs = (struct dyn_ftrace *)p->flags; | 739 | ftrace_new_addrs = p->newlist; |
733 | p->flags = 0L; | 740 | p->flags = 0L; |
734 | 741 | ||
735 | /* convert record (i.e, patch mcount-call with NOP) */ | 742 | /* convert record (i.e, patch mcount-call with NOP) */ |
@@ -2262,7 +2269,7 @@ ftrace_pid_read(struct file *file, char __user *ubuf, | |||
2262 | if (ftrace_pid_trace == ftrace_swapper_pid) | 2269 | if (ftrace_pid_trace == ftrace_swapper_pid) |
2263 | r = sprintf(buf, "swapper tasks\n"); | 2270 | r = sprintf(buf, "swapper tasks\n"); |
2264 | else if (ftrace_pid_trace) | 2271 | else if (ftrace_pid_trace) |
2265 | r = sprintf(buf, "%u\n", pid_nr(ftrace_pid_trace)); | 2272 | r = sprintf(buf, "%u\n", pid_vnr(ftrace_pid_trace)); |
2266 | else | 2273 | else |
2267 | r = sprintf(buf, "no pid\n"); | 2274 | r = sprintf(buf, "no pid\n"); |
2268 | 2275 | ||
@@ -2590,6 +2597,38 @@ free: | |||
2590 | return ret; | 2597 | return ret; |
2591 | } | 2598 | } |
2592 | 2599 | ||
2600 | static void | ||
2601 | ftrace_graph_probe_sched_switch(struct rq *__rq, struct task_struct *prev, | ||
2602 | struct task_struct *next) | ||
2603 | { | ||
2604 | unsigned long long timestamp; | ||
2605 | int index; | ||
2606 | |||
2607 | /* | ||
2608 | * Does the user want to count the time a function was asleep. | ||
2609 | * If so, do not update the time stamps. | ||
2610 | */ | ||
2611 | if (trace_flags & TRACE_ITER_SLEEP_TIME) | ||
2612 | return; | ||
2613 | |||
2614 | timestamp = trace_clock_local(); | ||
2615 | |||
2616 | prev->ftrace_timestamp = timestamp; | ||
2617 | |||
2618 | /* only process tasks that we timestamped */ | ||
2619 | if (!next->ftrace_timestamp) | ||
2620 | return; | ||
2621 | |||
2622 | /* | ||
2623 | * Update all the counters in next to make up for the | ||
2624 | * time next was sleeping. | ||
2625 | */ | ||
2626 | timestamp -= next->ftrace_timestamp; | ||
2627 | |||
2628 | for (index = next->curr_ret_stack; index >= 0; index--) | ||
2629 | next->ret_stack[index].calltime += timestamp; | ||
2630 | } | ||
2631 | |||
2593 | /* Allocate a return stack for each task */ | 2632 | /* Allocate a return stack for each task */ |
2594 | static int start_graph_tracing(void) | 2633 | static int start_graph_tracing(void) |
2595 | { | 2634 | { |
@@ -2611,6 +2650,13 @@ static int start_graph_tracing(void) | |||
2611 | ret = alloc_retstack_tasklist(ret_stack_list); | 2650 | ret = alloc_retstack_tasklist(ret_stack_list); |
2612 | } while (ret == -EAGAIN); | 2651 | } while (ret == -EAGAIN); |
2613 | 2652 | ||
2653 | if (!ret) { | ||
2654 | ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch); | ||
2655 | if (ret) | ||
2656 | pr_info("ftrace_graph: Couldn't activate tracepoint" | ||
2657 | " probe to kernel_sched_switch\n"); | ||
2658 | } | ||
2659 | |||
2614 | kfree(ret_stack_list); | 2660 | kfree(ret_stack_list); |
2615 | return ret; | 2661 | return ret; |
2616 | } | 2662 | } |
@@ -2643,6 +2689,12 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc, | |||
2643 | 2689 | ||
2644 | mutex_lock(&ftrace_lock); | 2690 | mutex_lock(&ftrace_lock); |
2645 | 2691 | ||
2692 | /* we currently allow only one tracer registered at a time */ | ||
2693 | if (atomic_read(&ftrace_graph_active)) { | ||
2694 | ret = -EBUSY; | ||
2695 | goto out; | ||
2696 | } | ||
2697 | |||
2646 | ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call; | 2698 | ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call; |
2647 | register_pm_notifier(&ftrace_suspend_notifier); | 2699 | register_pm_notifier(&ftrace_suspend_notifier); |
2648 | 2700 | ||
@@ -2668,6 +2720,7 @@ void unregister_ftrace_graph(void) | |||
2668 | mutex_lock(&ftrace_lock); | 2720 | mutex_lock(&ftrace_lock); |
2669 | 2721 | ||
2670 | atomic_dec(&ftrace_graph_active); | 2722 | atomic_dec(&ftrace_graph_active); |
2723 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch); | ||
2671 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; | 2724 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; |
2672 | ftrace_graph_entry = ftrace_graph_entry_stub; | 2725 | ftrace_graph_entry = ftrace_graph_entry_stub; |
2673 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); | 2726 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
@@ -2688,6 +2741,7 @@ void ftrace_graph_init_task(struct task_struct *t) | |||
2688 | t->curr_ret_stack = -1; | 2741 | t->curr_ret_stack = -1; |
2689 | atomic_set(&t->tracing_graph_pause, 0); | 2742 | atomic_set(&t->tracing_graph_pause, 0); |
2690 | atomic_set(&t->trace_overrun, 0); | 2743 | atomic_set(&t->trace_overrun, 0); |
2744 | t->ftrace_timestamp = 0; | ||
2691 | } else | 2745 | } else |
2692 | t->ret_stack = NULL; | 2746 | t->ret_stack = NULL; |
2693 | } | 2747 | } |
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 384ca5d9d729..edce2ff38944 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
@@ -189,16 +189,65 @@ enum { | |||
189 | RB_LEN_TIME_STAMP = 16, | 189 | RB_LEN_TIME_STAMP = 16, |
190 | }; | 190 | }; |
191 | 191 | ||
192 | /* inline for ring buffer fast paths */ | 192 | static inline int rb_null_event(struct ring_buffer_event *event) |
193 | { | ||
194 | return event->type == RINGBUF_TYPE_PADDING && event->time_delta == 0; | ||
195 | } | ||
196 | |||
197 | static inline int rb_discarded_event(struct ring_buffer_event *event) | ||
198 | { | ||
199 | return event->type == RINGBUF_TYPE_PADDING && event->time_delta; | ||
200 | } | ||
201 | |||
202 | static void rb_event_set_padding(struct ring_buffer_event *event) | ||
203 | { | ||
204 | event->type = RINGBUF_TYPE_PADDING; | ||
205 | event->time_delta = 0; | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * ring_buffer_event_discard - discard an event in the ring buffer | ||
210 | * @buffer: the ring buffer | ||
211 | * @event: the event to discard | ||
212 | * | ||
213 | * Sometimes a event that is in the ring buffer needs to be ignored. | ||
214 | * This function lets the user discard an event in the ring buffer | ||
215 | * and then that event will not be read later. | ||
216 | * | ||
217 | * Note, it is up to the user to be careful with this, and protect | ||
218 | * against races. If the user discards an event that has been consumed | ||
219 | * it is possible that it could corrupt the ring buffer. | ||
220 | */ | ||
221 | void ring_buffer_event_discard(struct ring_buffer_event *event) | ||
222 | { | ||
223 | event->type = RINGBUF_TYPE_PADDING; | ||
224 | /* time delta must be non zero */ | ||
225 | if (!event->time_delta) | ||
226 | event->time_delta = 1; | ||
227 | } | ||
228 | |||
193 | static unsigned | 229 | static unsigned |
194 | rb_event_length(struct ring_buffer_event *event) | 230 | rb_event_data_length(struct ring_buffer_event *event) |
195 | { | 231 | { |
196 | unsigned length; | 232 | unsigned length; |
197 | 233 | ||
234 | if (event->len) | ||
235 | length = event->len * RB_ALIGNMENT; | ||
236 | else | ||
237 | length = event->array[0]; | ||
238 | return length + RB_EVNT_HDR_SIZE; | ||
239 | } | ||
240 | |||
241 | /* inline for ring buffer fast paths */ | ||
242 | static unsigned | ||
243 | rb_event_length(struct ring_buffer_event *event) | ||
244 | { | ||
198 | switch (event->type) { | 245 | switch (event->type) { |
199 | case RINGBUF_TYPE_PADDING: | 246 | case RINGBUF_TYPE_PADDING: |
200 | /* undefined */ | 247 | if (rb_null_event(event)) |
201 | return -1; | 248 | /* undefined */ |
249 | return -1; | ||
250 | return rb_event_data_length(event); | ||
202 | 251 | ||
203 | case RINGBUF_TYPE_TIME_EXTEND: | 252 | case RINGBUF_TYPE_TIME_EXTEND: |
204 | return RB_LEN_TIME_EXTEND; | 253 | return RB_LEN_TIME_EXTEND; |
@@ -207,11 +256,7 @@ rb_event_length(struct ring_buffer_event *event) | |||
207 | return RB_LEN_TIME_STAMP; | 256 | return RB_LEN_TIME_STAMP; |
208 | 257 | ||
209 | case RINGBUF_TYPE_DATA: | 258 | case RINGBUF_TYPE_DATA: |
210 | if (event->len) | 259 | return rb_event_data_length(event); |
211 | length = event->len * RB_ALIGNMENT; | ||
212 | else | ||
213 | length = event->array[0]; | ||
214 | return length + RB_EVNT_HDR_SIZE; | ||
215 | default: | 260 | default: |
216 | BUG(); | 261 | BUG(); |
217 | } | 262 | } |
@@ -535,8 +580,8 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer) | |||
535 | extern int ring_buffer_page_too_big(void); | 580 | extern int ring_buffer_page_too_big(void); |
536 | 581 | ||
537 | #ifdef CONFIG_HOTPLUG_CPU | 582 | #ifdef CONFIG_HOTPLUG_CPU |
538 | static int __cpuinit rb_cpu_notify(struct notifier_block *self, | 583 | static int rb_cpu_notify(struct notifier_block *self, |
539 | unsigned long action, void *hcpu); | 584 | unsigned long action, void *hcpu); |
540 | #endif | 585 | #endif |
541 | 586 | ||
542 | /** | 587 | /** |
@@ -845,11 +890,6 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size) | |||
845 | } | 890 | } |
846 | EXPORT_SYMBOL_GPL(ring_buffer_resize); | 891 | EXPORT_SYMBOL_GPL(ring_buffer_resize); |
847 | 892 | ||
848 | static inline int rb_null_event(struct ring_buffer_event *event) | ||
849 | { | ||
850 | return event->type == RINGBUF_TYPE_PADDING; | ||
851 | } | ||
852 | |||
853 | static inline void * | 893 | static inline void * |
854 | __rb_data_page_index(struct buffer_data_page *bpage, unsigned index) | 894 | __rb_data_page_index(struct buffer_data_page *bpage, unsigned index) |
855 | { | 895 | { |
@@ -1219,7 +1259,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, | |||
1219 | if (tail < BUF_PAGE_SIZE) { | 1259 | if (tail < BUF_PAGE_SIZE) { |
1220 | /* Mark the rest of the page with padding */ | 1260 | /* Mark the rest of the page with padding */ |
1221 | event = __rb_page_index(tail_page, tail); | 1261 | event = __rb_page_index(tail_page, tail); |
1222 | event->type = RINGBUF_TYPE_PADDING; | 1262 | rb_event_set_padding(event); |
1223 | } | 1263 | } |
1224 | 1264 | ||
1225 | if (tail <= BUF_PAGE_SIZE) | 1265 | if (tail <= BUF_PAGE_SIZE) |
@@ -1969,7 +2009,7 @@ static void rb_advance_reader(struct ring_buffer_per_cpu *cpu_buffer) | |||
1969 | 2009 | ||
1970 | event = rb_reader_event(cpu_buffer); | 2010 | event = rb_reader_event(cpu_buffer); |
1971 | 2011 | ||
1972 | if (event->type == RINGBUF_TYPE_DATA) | 2012 | if (event->type == RINGBUF_TYPE_DATA || rb_discarded_event(event)) |
1973 | cpu_buffer->entries--; | 2013 | cpu_buffer->entries--; |
1974 | 2014 | ||
1975 | rb_update_read_stamp(cpu_buffer, event); | 2015 | rb_update_read_stamp(cpu_buffer, event); |
@@ -2052,9 +2092,18 @@ rb_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
2052 | 2092 | ||
2053 | switch (event->type) { | 2093 | switch (event->type) { |
2054 | case RINGBUF_TYPE_PADDING: | 2094 | case RINGBUF_TYPE_PADDING: |
2055 | RB_WARN_ON(cpu_buffer, 1); | 2095 | if (rb_null_event(event)) |
2096 | RB_WARN_ON(cpu_buffer, 1); | ||
2097 | /* | ||
2098 | * Because the writer could be discarding every | ||
2099 | * event it creates (which would probably be bad) | ||
2100 | * if we were to go back to "again" then we may never | ||
2101 | * catch up, and will trigger the warn on, or lock | ||
2102 | * the box. Return the padding, and we will release | ||
2103 | * the current locks, and try again. | ||
2104 | */ | ||
2056 | rb_advance_reader(cpu_buffer); | 2105 | rb_advance_reader(cpu_buffer); |
2057 | return NULL; | 2106 | return event; |
2058 | 2107 | ||
2059 | case RINGBUF_TYPE_TIME_EXTEND: | 2108 | case RINGBUF_TYPE_TIME_EXTEND: |
2060 | /* Internal data, OK to advance */ | 2109 | /* Internal data, OK to advance */ |
@@ -2115,8 +2164,12 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts) | |||
2115 | 2164 | ||
2116 | switch (event->type) { | 2165 | switch (event->type) { |
2117 | case RINGBUF_TYPE_PADDING: | 2166 | case RINGBUF_TYPE_PADDING: |
2118 | rb_inc_iter(iter); | 2167 | if (rb_null_event(event)) { |
2119 | goto again; | 2168 | rb_inc_iter(iter); |
2169 | goto again; | ||
2170 | } | ||
2171 | rb_advance_iter(iter); | ||
2172 | return event; | ||
2120 | 2173 | ||
2121 | case RINGBUF_TYPE_TIME_EXTEND: | 2174 | case RINGBUF_TYPE_TIME_EXTEND: |
2122 | /* Internal data, OK to advance */ | 2175 | /* Internal data, OK to advance */ |
@@ -2163,10 +2216,16 @@ ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
2163 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) | 2216 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
2164 | return NULL; | 2217 | return NULL; |
2165 | 2218 | ||
2219 | again: | ||
2166 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); | 2220 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); |
2167 | event = rb_buffer_peek(buffer, cpu, ts); | 2221 | event = rb_buffer_peek(buffer, cpu, ts); |
2168 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 2222 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
2169 | 2223 | ||
2224 | if (event && event->type == RINGBUF_TYPE_PADDING) { | ||
2225 | cpu_relax(); | ||
2226 | goto again; | ||
2227 | } | ||
2228 | |||
2170 | return event; | 2229 | return event; |
2171 | } | 2230 | } |
2172 | 2231 | ||
@@ -2185,10 +2244,16 @@ ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts) | |||
2185 | struct ring_buffer_event *event; | 2244 | struct ring_buffer_event *event; |
2186 | unsigned long flags; | 2245 | unsigned long flags; |
2187 | 2246 | ||
2247 | again: | ||
2188 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); | 2248 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); |
2189 | event = rb_iter_peek(iter, ts); | 2249 | event = rb_iter_peek(iter, ts); |
2190 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 2250 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
2191 | 2251 | ||
2252 | if (event && event->type == RINGBUF_TYPE_PADDING) { | ||
2253 | cpu_relax(); | ||
2254 | goto again; | ||
2255 | } | ||
2256 | |||
2192 | return event; | 2257 | return event; |
2193 | } | 2258 | } |
2194 | 2259 | ||
@@ -2207,6 +2272,7 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
2207 | struct ring_buffer_event *event = NULL; | 2272 | struct ring_buffer_event *event = NULL; |
2208 | unsigned long flags; | 2273 | unsigned long flags; |
2209 | 2274 | ||
2275 | again: | ||
2210 | /* might be called in atomic */ | 2276 | /* might be called in atomic */ |
2211 | preempt_disable(); | 2277 | preempt_disable(); |
2212 | 2278 | ||
@@ -2228,6 +2294,11 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
2228 | out: | 2294 | out: |
2229 | preempt_enable(); | 2295 | preempt_enable(); |
2230 | 2296 | ||
2297 | if (event && event->type == RINGBUF_TYPE_PADDING) { | ||
2298 | cpu_relax(); | ||
2299 | goto again; | ||
2300 | } | ||
2301 | |||
2231 | return event; | 2302 | return event; |
2232 | } | 2303 | } |
2233 | EXPORT_SYMBOL_GPL(ring_buffer_consume); | 2304 | EXPORT_SYMBOL_GPL(ring_buffer_consume); |
@@ -2306,6 +2377,7 @@ ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts) | |||
2306 | struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer; | 2377 | struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer; |
2307 | unsigned long flags; | 2378 | unsigned long flags; |
2308 | 2379 | ||
2380 | again: | ||
2309 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); | 2381 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); |
2310 | event = rb_iter_peek(iter, ts); | 2382 | event = rb_iter_peek(iter, ts); |
2311 | if (!event) | 2383 | if (!event) |
@@ -2315,6 +2387,11 @@ ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts) | |||
2315 | out: | 2387 | out: |
2316 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 2388 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
2317 | 2389 | ||
2390 | if (event && event->type == RINGBUF_TYPE_PADDING) { | ||
2391 | cpu_relax(); | ||
2392 | goto again; | ||
2393 | } | ||
2394 | |||
2318 | return event; | 2395 | return event; |
2319 | } | 2396 | } |
2320 | EXPORT_SYMBOL_GPL(ring_buffer_read); | 2397 | EXPORT_SYMBOL_GPL(ring_buffer_read); |
@@ -2784,8 +2861,8 @@ static __init int rb_init_debugfs(void) | |||
2784 | fs_initcall(rb_init_debugfs); | 2861 | fs_initcall(rb_init_debugfs); |
2785 | 2862 | ||
2786 | #ifdef CONFIG_HOTPLUG_CPU | 2863 | #ifdef CONFIG_HOTPLUG_CPU |
2787 | static int __cpuinit rb_cpu_notify(struct notifier_block *self, | 2864 | static int rb_cpu_notify(struct notifier_block *self, |
2788 | unsigned long action, void *hcpu) | 2865 | unsigned long action, void *hcpu) |
2789 | { | 2866 | { |
2790 | struct ring_buffer *buffer = | 2867 | struct ring_buffer *buffer = |
2791 | container_of(self, struct ring_buffer, cpu_notify); | 2868 | container_of(self, struct ring_buffer, cpu_notify); |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index c95b7292be70..a0174a40c563 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -255,7 +255,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait); | |||
255 | 255 | ||
256 | /* trace_flags holds trace_options default values */ | 256 | /* trace_flags holds trace_options default values */ |
257 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | | 257 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
258 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO; | 258 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME; |
259 | 259 | ||
260 | /** | 260 | /** |
261 | * trace_wake_up - wake up tasks waiting for trace input | 261 | * trace_wake_up - wake up tasks waiting for trace input |
@@ -316,6 +316,7 @@ static const char *trace_options[] = { | |||
316 | "context-info", | 316 | "context-info", |
317 | "latency-format", | 317 | "latency-format", |
318 | "global-clock", | 318 | "global-clock", |
319 | "sleep-time", | ||
319 | NULL | 320 | NULL |
320 | }; | 321 | }; |
321 | 322 | ||
@@ -382,7 +383,7 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) | |||
382 | return cnt; | 383 | return cnt; |
383 | } | 384 | } |
384 | 385 | ||
385 | ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) | 386 | static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) |
386 | { | 387 | { |
387 | int len; | 388 | int len; |
388 | void *ret; | 389 | void *ret; |
@@ -860,15 +861,25 @@ static void ftrace_trace_stack(struct trace_array *tr, | |||
860 | static void ftrace_trace_userstack(struct trace_array *tr, | 861 | static void ftrace_trace_userstack(struct trace_array *tr, |
861 | unsigned long flags, int pc); | 862 | unsigned long flags, int pc); |
862 | 863 | ||
863 | void trace_buffer_unlock_commit(struct trace_array *tr, | 864 | static inline void __trace_buffer_unlock_commit(struct trace_array *tr, |
864 | struct ring_buffer_event *event, | 865 | struct ring_buffer_event *event, |
865 | unsigned long flags, int pc) | 866 | unsigned long flags, int pc, |
867 | int wake) | ||
866 | { | 868 | { |
867 | ring_buffer_unlock_commit(tr->buffer, event); | 869 | ring_buffer_unlock_commit(tr->buffer, event); |
868 | 870 | ||
869 | ftrace_trace_stack(tr, flags, 6, pc); | 871 | ftrace_trace_stack(tr, flags, 6, pc); |
870 | ftrace_trace_userstack(tr, flags, pc); | 872 | ftrace_trace_userstack(tr, flags, pc); |
871 | trace_wake_up(); | 873 | |
874 | if (wake) | ||
875 | trace_wake_up(); | ||
876 | } | ||
877 | |||
878 | void trace_buffer_unlock_commit(struct trace_array *tr, | ||
879 | struct ring_buffer_event *event, | ||
880 | unsigned long flags, int pc) | ||
881 | { | ||
882 | __trace_buffer_unlock_commit(tr, event, flags, pc, 1); | ||
872 | } | 883 | } |
873 | 884 | ||
874 | struct ring_buffer_event * | 885 | struct ring_buffer_event * |
@@ -882,7 +893,13 @@ trace_current_buffer_lock_reserve(unsigned char type, unsigned long len, | |||
882 | void trace_current_buffer_unlock_commit(struct ring_buffer_event *event, | 893 | void trace_current_buffer_unlock_commit(struct ring_buffer_event *event, |
883 | unsigned long flags, int pc) | 894 | unsigned long flags, int pc) |
884 | { | 895 | { |
885 | return trace_buffer_unlock_commit(&global_trace, event, flags, pc); | 896 | return __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 1); |
897 | } | ||
898 | |||
899 | void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event, | ||
900 | unsigned long flags, int pc) | ||
901 | { | ||
902 | return __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 0); | ||
886 | } | 903 | } |
887 | 904 | ||
888 | void | 905 | void |
@@ -908,7 +925,7 @@ trace_function(struct trace_array *tr, | |||
908 | } | 925 | } |
909 | 926 | ||
910 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 927 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
911 | static void __trace_graph_entry(struct trace_array *tr, | 928 | static int __trace_graph_entry(struct trace_array *tr, |
912 | struct ftrace_graph_ent *trace, | 929 | struct ftrace_graph_ent *trace, |
913 | unsigned long flags, | 930 | unsigned long flags, |
914 | int pc) | 931 | int pc) |
@@ -917,15 +934,17 @@ static void __trace_graph_entry(struct trace_array *tr, | |||
917 | struct ftrace_graph_ent_entry *entry; | 934 | struct ftrace_graph_ent_entry *entry; |
918 | 935 | ||
919 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | 936 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) |
920 | return; | 937 | return 0; |
921 | 938 | ||
922 | event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_ENT, | 939 | event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_ENT, |
923 | sizeof(*entry), flags, pc); | 940 | sizeof(*entry), flags, pc); |
924 | if (!event) | 941 | if (!event) |
925 | return; | 942 | return 0; |
926 | entry = ring_buffer_event_data(event); | 943 | entry = ring_buffer_event_data(event); |
927 | entry->graph_ent = *trace; | 944 | entry->graph_ent = *trace; |
928 | ring_buffer_unlock_commit(global_trace.buffer, event); | 945 | ring_buffer_unlock_commit(global_trace.buffer, event); |
946 | |||
947 | return 1; | ||
929 | } | 948 | } |
930 | 949 | ||
931 | static void __trace_graph_return(struct trace_array *tr, | 950 | static void __trace_graph_return(struct trace_array *tr, |
@@ -1146,6 +1165,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace) | |||
1146 | struct trace_array_cpu *data; | 1165 | struct trace_array_cpu *data; |
1147 | unsigned long flags; | 1166 | unsigned long flags; |
1148 | long disabled; | 1167 | long disabled; |
1168 | int ret; | ||
1149 | int cpu; | 1169 | int cpu; |
1150 | int pc; | 1170 | int pc; |
1151 | 1171 | ||
@@ -1161,15 +1181,18 @@ int trace_graph_entry(struct ftrace_graph_ent *trace) | |||
1161 | disabled = atomic_inc_return(&data->disabled); | 1181 | disabled = atomic_inc_return(&data->disabled); |
1162 | if (likely(disabled == 1)) { | 1182 | if (likely(disabled == 1)) { |
1163 | pc = preempt_count(); | 1183 | pc = preempt_count(); |
1164 | __trace_graph_entry(tr, trace, flags, pc); | 1184 | ret = __trace_graph_entry(tr, trace, flags, pc); |
1185 | } else { | ||
1186 | ret = 0; | ||
1165 | } | 1187 | } |
1166 | /* Only do the atomic if it is not already set */ | 1188 | /* Only do the atomic if it is not already set */ |
1167 | if (!test_tsk_trace_graph(current)) | 1189 | if (!test_tsk_trace_graph(current)) |
1168 | set_tsk_trace_graph(current); | 1190 | set_tsk_trace_graph(current); |
1191 | |||
1169 | atomic_dec(&data->disabled); | 1192 | atomic_dec(&data->disabled); |
1170 | local_irq_restore(flags); | 1193 | local_irq_restore(flags); |
1171 | 1194 | ||
1172 | return 1; | 1195 | return ret; |
1173 | } | 1196 | } |
1174 | 1197 | ||
1175 | void trace_graph_return(struct ftrace_graph_ret *trace) | 1198 | void trace_graph_return(struct ftrace_graph_ret *trace) |
@@ -1201,7 +1224,7 @@ void trace_graph_return(struct ftrace_graph_ret *trace) | |||
1201 | * trace_vbprintk - write binary msg to tracing buffer | 1224 | * trace_vbprintk - write binary msg to tracing buffer |
1202 | * | 1225 | * |
1203 | */ | 1226 | */ |
1204 | int trace_vbprintk(unsigned long ip, int depth, const char *fmt, va_list args) | 1227 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
1205 | { | 1228 | { |
1206 | static raw_spinlock_t trace_buf_lock = | 1229 | static raw_spinlock_t trace_buf_lock = |
1207 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | 1230 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; |
@@ -1243,7 +1266,6 @@ int trace_vbprintk(unsigned long ip, int depth, const char *fmt, va_list args) | |||
1243 | goto out_unlock; | 1266 | goto out_unlock; |
1244 | entry = ring_buffer_event_data(event); | 1267 | entry = ring_buffer_event_data(event); |
1245 | entry->ip = ip; | 1268 | entry->ip = ip; |
1246 | entry->depth = depth; | ||
1247 | entry->fmt = fmt; | 1269 | entry->fmt = fmt; |
1248 | 1270 | ||
1249 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); | 1271 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); |
@@ -1261,7 +1283,7 @@ out: | |||
1261 | } | 1283 | } |
1262 | EXPORT_SYMBOL_GPL(trace_vbprintk); | 1284 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
1263 | 1285 | ||
1264 | int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args) | 1286 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
1265 | { | 1287 | { |
1266 | static raw_spinlock_t trace_buf_lock = __RAW_SPIN_LOCK_UNLOCKED; | 1288 | static raw_spinlock_t trace_buf_lock = __RAW_SPIN_LOCK_UNLOCKED; |
1267 | static char trace_buf[TRACE_BUF_SIZE]; | 1289 | static char trace_buf[TRACE_BUF_SIZE]; |
@@ -1298,7 +1320,6 @@ int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args) | |||
1298 | goto out_unlock; | 1320 | goto out_unlock; |
1299 | entry = ring_buffer_event_data(event); | 1321 | entry = ring_buffer_event_data(event); |
1300 | entry->ip = ip; | 1322 | entry->ip = ip; |
1301 | entry->depth = depth; | ||
1302 | 1323 | ||
1303 | memcpy(&entry->buf, trace_buf, len); | 1324 | memcpy(&entry->buf, trace_buf, len); |
1304 | entry->buf[len] = 0; | 1325 | entry->buf[len] = 0; |
@@ -1701,38 +1722,6 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter) | |||
1701 | return TRACE_TYPE_HANDLED; | 1722 | return TRACE_TYPE_HANDLED; |
1702 | } | 1723 | } |
1703 | 1724 | ||
1704 | static enum print_line_t print_bprintk_msg_only(struct trace_iterator *iter) | ||
1705 | { | ||
1706 | struct trace_seq *s = &iter->seq; | ||
1707 | struct trace_entry *entry = iter->ent; | ||
1708 | struct bprint_entry *field; | ||
1709 | int ret; | ||
1710 | |||
1711 | trace_assign_type(field, entry); | ||
1712 | |||
1713 | ret = trace_seq_bprintf(s, field->fmt, field->buf); | ||
1714 | if (!ret) | ||
1715 | return TRACE_TYPE_PARTIAL_LINE; | ||
1716 | |||
1717 | return TRACE_TYPE_HANDLED; | ||
1718 | } | ||
1719 | |||
1720 | static enum print_line_t print_printk_msg_only(struct trace_iterator *iter) | ||
1721 | { | ||
1722 | struct trace_seq *s = &iter->seq; | ||
1723 | struct trace_entry *entry = iter->ent; | ||
1724 | struct print_entry *field; | ||
1725 | int ret; | ||
1726 | |||
1727 | trace_assign_type(field, entry); | ||
1728 | |||
1729 | ret = trace_seq_printf(s, "%s", field->buf); | ||
1730 | if (!ret) | ||
1731 | return TRACE_TYPE_PARTIAL_LINE; | ||
1732 | |||
1733 | return TRACE_TYPE_HANDLED; | ||
1734 | } | ||
1735 | |||
1736 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) | 1725 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
1737 | { | 1726 | { |
1738 | struct trace_seq *s = &iter->seq; | 1727 | struct trace_seq *s = &iter->seq; |
@@ -1794,12 +1783,12 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter) | |||
1794 | if (iter->ent->type == TRACE_BPRINT && | 1783 | if (iter->ent->type == TRACE_BPRINT && |
1795 | trace_flags & TRACE_ITER_PRINTK && | 1784 | trace_flags & TRACE_ITER_PRINTK && |
1796 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) | 1785 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
1797 | return print_bprintk_msg_only(iter); | 1786 | return trace_print_bprintk_msg_only(iter); |
1798 | 1787 | ||
1799 | if (iter->ent->type == TRACE_PRINT && | 1788 | if (iter->ent->type == TRACE_PRINT && |
1800 | trace_flags & TRACE_ITER_PRINTK && | 1789 | trace_flags & TRACE_ITER_PRINTK && |
1801 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) | 1790 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
1802 | return print_printk_msg_only(iter); | 1791 | return trace_print_printk_msg_only(iter); |
1803 | 1792 | ||
1804 | if (trace_flags & TRACE_ITER_BIN) | 1793 | if (trace_flags & TRACE_ITER_BIN) |
1805 | return print_bin_fmt(iter); | 1794 | return print_bin_fmt(iter); |
@@ -1948,9 +1937,14 @@ int tracing_open_generic(struct inode *inode, struct file *filp) | |||
1948 | static int tracing_release(struct inode *inode, struct file *file) | 1937 | static int tracing_release(struct inode *inode, struct file *file) |
1949 | { | 1938 | { |
1950 | struct seq_file *m = (struct seq_file *)file->private_data; | 1939 | struct seq_file *m = (struct seq_file *)file->private_data; |
1951 | struct trace_iterator *iter = m->private; | 1940 | struct trace_iterator *iter; |
1952 | int cpu; | 1941 | int cpu; |
1953 | 1942 | ||
1943 | if (!(file->f_mode & FMODE_READ)) | ||
1944 | return 0; | ||
1945 | |||
1946 | iter = m->private; | ||
1947 | |||
1954 | mutex_lock(&trace_types_lock); | 1948 | mutex_lock(&trace_types_lock); |
1955 | for_each_tracing_cpu(cpu) { | 1949 | for_each_tracing_cpu(cpu) { |
1956 | if (iter->buffer_iter[cpu]) | 1950 | if (iter->buffer_iter[cpu]) |
@@ -1976,12 +1970,24 @@ static int tracing_open(struct inode *inode, struct file *file) | |||
1976 | struct trace_iterator *iter; | 1970 | struct trace_iterator *iter; |
1977 | int ret = 0; | 1971 | int ret = 0; |
1978 | 1972 | ||
1979 | iter = __tracing_open(inode, file); | 1973 | /* If this file was open for write, then erase contents */ |
1980 | if (IS_ERR(iter)) | 1974 | if ((file->f_mode & FMODE_WRITE) && |
1981 | ret = PTR_ERR(iter); | 1975 | !(file->f_flags & O_APPEND)) { |
1982 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) | 1976 | long cpu = (long) inode->i_private; |
1983 | iter->iter_flags |= TRACE_FILE_LAT_FMT; | ||
1984 | 1977 | ||
1978 | if (cpu == TRACE_PIPE_ALL_CPU) | ||
1979 | tracing_reset_online_cpus(&global_trace); | ||
1980 | else | ||
1981 | tracing_reset(&global_trace, cpu); | ||
1982 | } | ||
1983 | |||
1984 | if (file->f_mode & FMODE_READ) { | ||
1985 | iter = __tracing_open(inode, file); | ||
1986 | if (IS_ERR(iter)) | ||
1987 | ret = PTR_ERR(iter); | ||
1988 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) | ||
1989 | iter->iter_flags |= TRACE_FILE_LAT_FMT; | ||
1990 | } | ||
1985 | return ret; | 1991 | return ret; |
1986 | } | 1992 | } |
1987 | 1993 | ||
@@ -2056,9 +2062,17 @@ static int show_traces_open(struct inode *inode, struct file *file) | |||
2056 | return ret; | 2062 | return ret; |
2057 | } | 2063 | } |
2058 | 2064 | ||
2065 | static ssize_t | ||
2066 | tracing_write_stub(struct file *filp, const char __user *ubuf, | ||
2067 | size_t count, loff_t *ppos) | ||
2068 | { | ||
2069 | return count; | ||
2070 | } | ||
2071 | |||
2059 | static const struct file_operations tracing_fops = { | 2072 | static const struct file_operations tracing_fops = { |
2060 | .open = tracing_open, | 2073 | .open = tracing_open, |
2061 | .read = seq_read, | 2074 | .read = seq_read, |
2075 | .write = tracing_write_stub, | ||
2062 | .llseek = seq_lseek, | 2076 | .llseek = seq_lseek, |
2063 | .release = tracing_release, | 2077 | .release = tracing_release, |
2064 | }; | 2078 | }; |
@@ -3154,7 +3168,7 @@ static int mark_printk(const char *fmt, ...) | |||
3154 | int ret; | 3168 | int ret; |
3155 | va_list args; | 3169 | va_list args; |
3156 | va_start(args, fmt); | 3170 | va_start(args, fmt); |
3157 | ret = trace_vprintk(0, -1, fmt, args); | 3171 | ret = trace_vprintk(0, fmt, args); |
3158 | va_end(args); | 3172 | va_end(args); |
3159 | return ret; | 3173 | return ret; |
3160 | } | 3174 | } |
@@ -3522,6 +3536,9 @@ struct dentry *tracing_init_dentry(void) | |||
3522 | if (d_tracer) | 3536 | if (d_tracer) |
3523 | return d_tracer; | 3537 | return d_tracer; |
3524 | 3538 | ||
3539 | if (!debugfs_initialized()) | ||
3540 | return NULL; | ||
3541 | |||
3525 | d_tracer = debugfs_create_dir("tracing", NULL); | 3542 | d_tracer = debugfs_create_dir("tracing", NULL); |
3526 | 3543 | ||
3527 | if (!d_tracer && !once) { | 3544 | if (!d_tracer && !once) { |
@@ -3583,7 +3600,7 @@ static void tracing_init_debugfs_percpu(long cpu) | |||
3583 | pr_warning("Could not create debugfs 'trace_pipe' entry\n"); | 3600 | pr_warning("Could not create debugfs 'trace_pipe' entry\n"); |
3584 | 3601 | ||
3585 | /* per cpu trace */ | 3602 | /* per cpu trace */ |
3586 | entry = debugfs_create_file("trace", 0444, d_cpu, | 3603 | entry = debugfs_create_file("trace", 0644, d_cpu, |
3587 | (void *) cpu, &tracing_fops); | 3604 | (void *) cpu, &tracing_fops); |
3588 | if (!entry) | 3605 | if (!entry) |
3589 | pr_warning("Could not create debugfs 'trace' entry\n"); | 3606 | pr_warning("Could not create debugfs 'trace' entry\n"); |
@@ -3897,7 +3914,7 @@ static __init int tracer_init_debugfs(void) | |||
3897 | if (!entry) | 3914 | if (!entry) |
3898 | pr_warning("Could not create debugfs 'tracing_cpumask' entry\n"); | 3915 | pr_warning("Could not create debugfs 'tracing_cpumask' entry\n"); |
3899 | 3916 | ||
3900 | entry = debugfs_create_file("trace", 0444, d_tracer, | 3917 | entry = debugfs_create_file("trace", 0644, d_tracer, |
3901 | (void *) TRACE_PIPE_ALL_CPU, &tracing_fops); | 3918 | (void *) TRACE_PIPE_ALL_CPU, &tracing_fops); |
3902 | if (!entry) | 3919 | if (!entry) |
3903 | pr_warning("Could not create debugfs 'trace' entry\n"); | 3920 | pr_warning("Could not create debugfs 'trace' entry\n"); |
@@ -4027,11 +4044,12 @@ trace_printk_seq(struct trace_seq *s) | |||
4027 | trace_seq_init(s); | 4044 | trace_seq_init(s); |
4028 | } | 4045 | } |
4029 | 4046 | ||
4030 | void ftrace_dump(void) | 4047 | static void __ftrace_dump(bool disable_tracing) |
4031 | { | 4048 | { |
4032 | static DEFINE_SPINLOCK(ftrace_dump_lock); | 4049 | static DEFINE_SPINLOCK(ftrace_dump_lock); |
4033 | /* use static because iter can be a bit big for the stack */ | 4050 | /* use static because iter can be a bit big for the stack */ |
4034 | static struct trace_iterator iter; | 4051 | static struct trace_iterator iter; |
4052 | unsigned int old_userobj; | ||
4035 | static int dump_ran; | 4053 | static int dump_ran; |
4036 | unsigned long flags; | 4054 | unsigned long flags; |
4037 | int cnt = 0, cpu; | 4055 | int cnt = 0, cpu; |
@@ -4043,14 +4061,17 @@ void ftrace_dump(void) | |||
4043 | 4061 | ||
4044 | dump_ran = 1; | 4062 | dump_ran = 1; |
4045 | 4063 | ||
4046 | /* No turning back! */ | ||
4047 | tracing_off(); | 4064 | tracing_off(); |
4048 | ftrace_kill(); | 4065 | |
4066 | if (disable_tracing) | ||
4067 | ftrace_kill(); | ||
4049 | 4068 | ||
4050 | for_each_tracing_cpu(cpu) { | 4069 | for_each_tracing_cpu(cpu) { |
4051 | atomic_inc(&global_trace.data[cpu]->disabled); | 4070 | atomic_inc(&global_trace.data[cpu]->disabled); |
4052 | } | 4071 | } |
4053 | 4072 | ||
4073 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; | ||
4074 | |||
4054 | /* don't look at user memory in panic mode */ | 4075 | /* don't look at user memory in panic mode */ |
4055 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; | 4076 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
4056 | 4077 | ||
@@ -4095,10 +4116,26 @@ void ftrace_dump(void) | |||
4095 | else | 4116 | else |
4096 | printk(KERN_TRACE "---------------------------------\n"); | 4117 | printk(KERN_TRACE "---------------------------------\n"); |
4097 | 4118 | ||
4119 | /* Re-enable tracing if requested */ | ||
4120 | if (!disable_tracing) { | ||
4121 | trace_flags |= old_userobj; | ||
4122 | |||
4123 | for_each_tracing_cpu(cpu) { | ||
4124 | atomic_dec(&global_trace.data[cpu]->disabled); | ||
4125 | } | ||
4126 | tracing_on(); | ||
4127 | } | ||
4128 | |||
4098 | out: | 4129 | out: |
4099 | spin_unlock_irqrestore(&ftrace_dump_lock, flags); | 4130 | spin_unlock_irqrestore(&ftrace_dump_lock, flags); |
4100 | } | 4131 | } |
4101 | 4132 | ||
4133 | /* By default: disable tracing after the dump */ | ||
4134 | void ftrace_dump(void) | ||
4135 | { | ||
4136 | __ftrace_dump(true); | ||
4137 | } | ||
4138 | |||
4102 | __init static int tracer_alloc_buffers(void) | 4139 | __init static int tracer_alloc_buffers(void) |
4103 | { | 4140 | { |
4104 | struct trace_array_cpu *data; | 4141 | struct trace_array_cpu *data; |
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 38276d1638e3..cb0ce3fc36d3 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
@@ -123,7 +123,6 @@ struct userstack_entry { | |||
123 | struct bprint_entry { | 123 | struct bprint_entry { |
124 | struct trace_entry ent; | 124 | struct trace_entry ent; |
125 | unsigned long ip; | 125 | unsigned long ip; |
126 | int depth; | ||
127 | const char *fmt; | 126 | const char *fmt; |
128 | u32 buf[]; | 127 | u32 buf[]; |
129 | }; | 128 | }; |
@@ -131,7 +130,6 @@ struct bprint_entry { | |||
131 | struct print_entry { | 130 | struct print_entry { |
132 | struct trace_entry ent; | 131 | struct trace_entry ent; |
133 | unsigned long ip; | 132 | unsigned long ip; |
134 | int depth; | ||
135 | char buf[]; | 133 | char buf[]; |
136 | }; | 134 | }; |
137 | 135 | ||
@@ -485,6 +483,8 @@ trace_current_buffer_lock_reserve(unsigned char type, unsigned long len, | |||
485 | unsigned long flags, int pc); | 483 | unsigned long flags, int pc); |
486 | void trace_current_buffer_unlock_commit(struct ring_buffer_event *event, | 484 | void trace_current_buffer_unlock_commit(struct ring_buffer_event *event, |
487 | unsigned long flags, int pc); | 485 | unsigned long flags, int pc); |
486 | void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event, | ||
487 | unsigned long flags, int pc); | ||
488 | 488 | ||
489 | struct trace_entry *tracing_get_trace_entry(struct trace_array *tr, | 489 | struct trace_entry *tracing_get_trace_entry(struct trace_array *tr, |
490 | struct trace_array_cpu *data); | 490 | struct trace_array_cpu *data); |
@@ -598,9 +598,9 @@ extern int trace_selftest_startup_branch(struct tracer *trace, | |||
598 | extern void *head_page(struct trace_array_cpu *data); | 598 | extern void *head_page(struct trace_array_cpu *data); |
599 | extern long ns2usecs(cycle_t nsec); | 599 | extern long ns2usecs(cycle_t nsec); |
600 | extern int | 600 | extern int |
601 | trace_vbprintk(unsigned long ip, int depth, const char *fmt, va_list args); | 601 | trace_vbprintk(unsigned long ip, const char *fmt, va_list args); |
602 | extern int | 602 | extern int |
603 | trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args); | 603 | trace_vprintk(unsigned long ip, const char *fmt, va_list args); |
604 | 604 | ||
605 | extern unsigned long trace_flags; | 605 | extern unsigned long trace_flags; |
606 | 606 | ||
@@ -685,6 +685,7 @@ enum trace_iterator_flags { | |||
685 | TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */ | 685 | TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */ |
686 | TRACE_ITER_LATENCY_FMT = 0x40000, | 686 | TRACE_ITER_LATENCY_FMT = 0x40000, |
687 | TRACE_ITER_GLOBAL_CLK = 0x80000, | 687 | TRACE_ITER_GLOBAL_CLK = 0x80000, |
688 | TRACE_ITER_SLEEP_TIME = 0x100000, | ||
688 | }; | 689 | }; |
689 | 690 | ||
690 | /* | 691 | /* |
@@ -777,22 +778,89 @@ enum { | |||
777 | TRACE_EVENT_TYPE_RAW = 2, | 778 | TRACE_EVENT_TYPE_RAW = 2, |
778 | }; | 779 | }; |
779 | 780 | ||
781 | struct ftrace_event_field { | ||
782 | struct list_head link; | ||
783 | char *name; | ||
784 | char *type; | ||
785 | int offset; | ||
786 | int size; | ||
787 | }; | ||
788 | |||
780 | struct ftrace_event_call { | 789 | struct ftrace_event_call { |
781 | char *name; | 790 | char *name; |
782 | char *system; | 791 | char *system; |
783 | struct dentry *dir; | 792 | struct dentry *dir; |
784 | int enabled; | 793 | int enabled; |
785 | int (*regfunc)(void); | 794 | int (*regfunc)(void); |
786 | void (*unregfunc)(void); | 795 | void (*unregfunc)(void); |
787 | int id; | 796 | int id; |
788 | int (*raw_init)(void); | 797 | int (*raw_init)(void); |
789 | int (*show_format)(struct trace_seq *s); | 798 | int (*show_format)(struct trace_seq *s); |
799 | int (*define_fields)(void); | ||
800 | struct list_head fields; | ||
801 | struct filter_pred **preds; | ||
802 | |||
803 | #ifdef CONFIG_EVENT_PROFILE | ||
804 | atomic_t profile_count; | ||
805 | int (*profile_enable)(struct ftrace_event_call *); | ||
806 | void (*profile_disable)(struct ftrace_event_call *); | ||
807 | #endif | ||
790 | }; | 808 | }; |
791 | 809 | ||
810 | struct event_subsystem { | ||
811 | struct list_head list; | ||
812 | const char *name; | ||
813 | struct dentry *entry; | ||
814 | struct filter_pred **preds; | ||
815 | }; | ||
816 | |||
817 | #define events_for_each(event) \ | ||
818 | for (event = __start_ftrace_events; \ | ||
819 | (unsigned long)event < (unsigned long)__stop_ftrace_events; \ | ||
820 | event++) | ||
821 | |||
822 | #define MAX_FILTER_PRED 8 | ||
823 | |||
824 | struct filter_pred; | ||
825 | |||
826 | typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event); | ||
827 | |||
828 | struct filter_pred { | ||
829 | filter_pred_fn_t fn; | ||
830 | u64 val; | ||
831 | char *str_val; | ||
832 | int str_len; | ||
833 | char *field_name; | ||
834 | int offset; | ||
835 | int not; | ||
836 | int or; | ||
837 | int compound; | ||
838 | int clear; | ||
839 | }; | ||
840 | |||
841 | int trace_define_field(struct ftrace_event_call *call, char *type, | ||
842 | char *name, int offset, int size); | ||
843 | extern void filter_free_pred(struct filter_pred *pred); | ||
844 | extern void filter_print_preds(struct filter_pred **preds, | ||
845 | struct trace_seq *s); | ||
846 | extern int filter_parse(char **pbuf, struct filter_pred *pred); | ||
847 | extern int filter_add_pred(struct ftrace_event_call *call, | ||
848 | struct filter_pred *pred); | ||
849 | extern void filter_free_preds(struct ftrace_event_call *call); | ||
850 | extern int filter_match_preds(struct ftrace_event_call *call, void *rec); | ||
851 | extern void filter_free_subsystem_preds(struct event_subsystem *system); | ||
852 | extern int filter_add_subsystem_pred(struct event_subsystem *system, | ||
853 | struct filter_pred *pred); | ||
854 | |||
792 | void event_trace_printk(unsigned long ip, const char *fmt, ...); | 855 | void event_trace_printk(unsigned long ip, const char *fmt, ...); |
793 | extern struct ftrace_event_call __start_ftrace_events[]; | 856 | extern struct ftrace_event_call __start_ftrace_events[]; |
794 | extern struct ftrace_event_call __stop_ftrace_events[]; | 857 | extern struct ftrace_event_call __stop_ftrace_events[]; |
795 | 858 | ||
859 | #define for_each_event(event) \ | ||
860 | for (event = __start_ftrace_events; \ | ||
861 | (unsigned long)event < (unsigned long)__stop_ftrace_events; \ | ||
862 | event++) | ||
863 | |||
796 | extern const char *__start___trace_bprintk_fmt[]; | 864 | extern const char *__start___trace_bprintk_fmt[]; |
797 | extern const char *__stop___trace_bprintk_fmt[]; | 865 | extern const char *__stop___trace_bprintk_fmt[]; |
798 | 866 | ||
diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c index 05b176abfd30..b588fd81f7f9 100644 --- a/kernel/trace/trace_clock.c +++ b/kernel/trace/trace_clock.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/percpu.h> | 18 | #include <linux/percpu.h> |
19 | #include <linux/sched.h> | 19 | #include <linux/sched.h> |
20 | #include <linux/ktime.h> | 20 | #include <linux/ktime.h> |
21 | #include <linux/trace_clock.h> | ||
21 | 22 | ||
22 | /* | 23 | /* |
23 | * trace_clock_local(): the simplest and least coherent tracing clock. | 24 | * trace_clock_local(): the simplest and least coherent tracing clock. |
diff --git a/kernel/trace/trace_event_profile.c b/kernel/trace/trace_event_profile.c new file mode 100644 index 000000000000..22cba9970776 --- /dev/null +++ b/kernel/trace/trace_event_profile.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * trace event based perf counter profiling | ||
3 | * | ||
4 | * Copyright (C) 2009 Red Hat Inc, Peter Zijlstra <pzijlstr@redhat.com> | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | #include "trace.h" | ||
9 | |||
10 | int ftrace_profile_enable(int event_id) | ||
11 | { | ||
12 | struct ftrace_event_call *event; | ||
13 | |||
14 | for_each_event(event) { | ||
15 | if (event->id == event_id) | ||
16 | return event->profile_enable(event); | ||
17 | } | ||
18 | |||
19 | return -EINVAL; | ||
20 | } | ||
21 | |||
22 | void ftrace_profile_disable(int event_id) | ||
23 | { | ||
24 | struct ftrace_event_call *event; | ||
25 | |||
26 | for_each_event(event) { | ||
27 | if (event->id == event_id) | ||
28 | return event->profile_disable(event); | ||
29 | } | ||
30 | } | ||
31 | |||
diff --git a/kernel/trace/trace_event_types.h b/kernel/trace/trace_event_types.h index 019915063fe6..fd78bee71dd7 100644 --- a/kernel/trace/trace_event_types.h +++ b/kernel/trace/trace_event_types.h | |||
@@ -105,7 +105,6 @@ TRACE_EVENT_FORMAT(user_stack, TRACE_USER_STACK, userstack_entry, ignore, | |||
105 | TRACE_EVENT_FORMAT(bprint, TRACE_BPRINT, bprint_entry, ignore, | 105 | TRACE_EVENT_FORMAT(bprint, TRACE_BPRINT, bprint_entry, ignore, |
106 | TRACE_STRUCT( | 106 | TRACE_STRUCT( |
107 | TRACE_FIELD(unsigned long, ip, ip) | 107 | TRACE_FIELD(unsigned long, ip, ip) |
108 | TRACE_FIELD(unsigned int, depth, depth) | ||
109 | TRACE_FIELD(char *, fmt, fmt) | 108 | TRACE_FIELD(char *, fmt, fmt) |
110 | TRACE_FIELD_ZERO_CHAR(buf) | 109 | TRACE_FIELD_ZERO_CHAR(buf) |
111 | ), | 110 | ), |
@@ -115,7 +114,6 @@ TRACE_EVENT_FORMAT(bprint, TRACE_BPRINT, bprint_entry, ignore, | |||
115 | TRACE_EVENT_FORMAT(print, TRACE_PRINT, print_entry, ignore, | 114 | TRACE_EVENT_FORMAT(print, TRACE_PRINT, print_entry, ignore, |
116 | TRACE_STRUCT( | 115 | TRACE_STRUCT( |
117 | TRACE_FIELD(unsigned long, ip, ip) | 116 | TRACE_FIELD(unsigned long, ip, ip) |
118 | TRACE_FIELD(unsigned int, depth, depth) | ||
119 | TRACE_FIELD_ZERO_CHAR(buf) | 117 | TRACE_FIELD_ZERO_CHAR(buf) |
120 | ), | 118 | ), |
121 | TP_RAW_FMT("%08lx (%d) fmt:%p %s") | 119 | TP_RAW_FMT("%08lx (%d) fmt:%p %s") |
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index c88227b3b9db..64ec4d278ffb 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
@@ -19,10 +19,38 @@ | |||
19 | 19 | ||
20 | static DEFINE_MUTEX(event_mutex); | 20 | static DEFINE_MUTEX(event_mutex); |
21 | 21 | ||
22 | #define events_for_each(event) \ | 22 | int trace_define_field(struct ftrace_event_call *call, char *type, |
23 | for (event = __start_ftrace_events; \ | 23 | char *name, int offset, int size) |
24 | (unsigned long)event < (unsigned long)__stop_ftrace_events; \ | 24 | { |
25 | event++) | 25 | struct ftrace_event_field *field; |
26 | |||
27 | field = kzalloc(sizeof(*field), GFP_KERNEL); | ||
28 | if (!field) | ||
29 | goto err; | ||
30 | |||
31 | field->name = kstrdup(name, GFP_KERNEL); | ||
32 | if (!field->name) | ||
33 | goto err; | ||
34 | |||
35 | field->type = kstrdup(type, GFP_KERNEL); | ||
36 | if (!field->type) | ||
37 | goto err; | ||
38 | |||
39 | field->offset = offset; | ||
40 | field->size = size; | ||
41 | list_add(&field->link, &call->fields); | ||
42 | |||
43 | return 0; | ||
44 | |||
45 | err: | ||
46 | if (field) { | ||
47 | kfree(field->name); | ||
48 | kfree(field->type); | ||
49 | } | ||
50 | kfree(field); | ||
51 | |||
52 | return -ENOMEM; | ||
53 | } | ||
26 | 54 | ||
27 | static void ftrace_clear_events(void) | 55 | static void ftrace_clear_events(void) |
28 | { | 56 | { |
@@ -90,7 +118,7 @@ static int ftrace_set_clr_event(char *buf, int set) | |||
90 | } | 118 | } |
91 | 119 | ||
92 | mutex_lock(&event_mutex); | 120 | mutex_lock(&event_mutex); |
93 | events_for_each(call) { | 121 | for_each_event(call) { |
94 | 122 | ||
95 | if (!call->name || !call->regfunc) | 123 | if (!call->name || !call->regfunc) |
96 | continue; | 124 | continue; |
@@ -348,7 +376,8 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
348 | 376 | ||
349 | #undef FIELD | 377 | #undef FIELD |
350 | #define FIELD(type, name) \ | 378 | #define FIELD(type, name) \ |
351 | #type, #name, offsetof(typeof(field), name), sizeof(field.name) | 379 | #type, "common_" #name, offsetof(typeof(field), name), \ |
380 | sizeof(field.name) | ||
352 | 381 | ||
353 | static int trace_write_header(struct trace_seq *s) | 382 | static int trace_write_header(struct trace_seq *s) |
354 | { | 383 | { |
@@ -412,6 +441,162 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
412 | return r; | 441 | return r; |
413 | } | 442 | } |
414 | 443 | ||
444 | static ssize_t | ||
445 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | ||
446 | { | ||
447 | struct ftrace_event_call *call = filp->private_data; | ||
448 | struct trace_seq *s; | ||
449 | int r; | ||
450 | |||
451 | if (*ppos) | ||
452 | return 0; | ||
453 | |||
454 | s = kmalloc(sizeof(*s), GFP_KERNEL); | ||
455 | if (!s) | ||
456 | return -ENOMEM; | ||
457 | |||
458 | trace_seq_init(s); | ||
459 | trace_seq_printf(s, "%d\n", call->id); | ||
460 | |||
461 | r = simple_read_from_buffer(ubuf, cnt, ppos, | ||
462 | s->buffer, s->len); | ||
463 | kfree(s); | ||
464 | return r; | ||
465 | } | ||
466 | |||
467 | static ssize_t | ||
468 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | ||
469 | loff_t *ppos) | ||
470 | { | ||
471 | struct ftrace_event_call *call = filp->private_data; | ||
472 | struct trace_seq *s; | ||
473 | int r; | ||
474 | |||
475 | if (*ppos) | ||
476 | return 0; | ||
477 | |||
478 | s = kmalloc(sizeof(*s), GFP_KERNEL); | ||
479 | if (!s) | ||
480 | return -ENOMEM; | ||
481 | |||
482 | trace_seq_init(s); | ||
483 | |||
484 | filter_print_preds(call->preds, s); | ||
485 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | ||
486 | |||
487 | kfree(s); | ||
488 | |||
489 | return r; | ||
490 | } | ||
491 | |||
492 | static ssize_t | ||
493 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | ||
494 | loff_t *ppos) | ||
495 | { | ||
496 | struct ftrace_event_call *call = filp->private_data; | ||
497 | char buf[64], *pbuf = buf; | ||
498 | struct filter_pred *pred; | ||
499 | int err; | ||
500 | |||
501 | if (cnt >= sizeof(buf)) | ||
502 | return -EINVAL; | ||
503 | |||
504 | if (copy_from_user(&buf, ubuf, cnt)) | ||
505 | return -EFAULT; | ||
506 | |||
507 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); | ||
508 | if (!pred) | ||
509 | return -ENOMEM; | ||
510 | |||
511 | err = filter_parse(&pbuf, pred); | ||
512 | if (err < 0) { | ||
513 | filter_free_pred(pred); | ||
514 | return err; | ||
515 | } | ||
516 | |||
517 | if (pred->clear) { | ||
518 | filter_free_preds(call); | ||
519 | filter_free_pred(pred); | ||
520 | return cnt; | ||
521 | } | ||
522 | |||
523 | if (filter_add_pred(call, pred)) { | ||
524 | filter_free_pred(pred); | ||
525 | return -EINVAL; | ||
526 | } | ||
527 | |||
528 | *ppos += cnt; | ||
529 | |||
530 | return cnt; | ||
531 | } | ||
532 | |||
533 | static ssize_t | ||
534 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | ||
535 | loff_t *ppos) | ||
536 | { | ||
537 | struct event_subsystem *system = filp->private_data; | ||
538 | struct trace_seq *s; | ||
539 | int r; | ||
540 | |||
541 | if (*ppos) | ||
542 | return 0; | ||
543 | |||
544 | s = kmalloc(sizeof(*s), GFP_KERNEL); | ||
545 | if (!s) | ||
546 | return -ENOMEM; | ||
547 | |||
548 | trace_seq_init(s); | ||
549 | |||
550 | filter_print_preds(system->preds, s); | ||
551 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | ||
552 | |||
553 | kfree(s); | ||
554 | |||
555 | return r; | ||
556 | } | ||
557 | |||
558 | static ssize_t | ||
559 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | ||
560 | loff_t *ppos) | ||
561 | { | ||
562 | struct event_subsystem *system = filp->private_data; | ||
563 | char buf[64], *pbuf = buf; | ||
564 | struct filter_pred *pred; | ||
565 | int err; | ||
566 | |||
567 | if (cnt >= sizeof(buf)) | ||
568 | return -EINVAL; | ||
569 | |||
570 | if (copy_from_user(&buf, ubuf, cnt)) | ||
571 | return -EFAULT; | ||
572 | |||
573 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); | ||
574 | if (!pred) | ||
575 | return -ENOMEM; | ||
576 | |||
577 | err = filter_parse(&pbuf, pred); | ||
578 | if (err < 0) { | ||
579 | filter_free_pred(pred); | ||
580 | return err; | ||
581 | } | ||
582 | |||
583 | if (pred->clear) { | ||
584 | filter_free_subsystem_preds(system); | ||
585 | filter_free_pred(pred); | ||
586 | return cnt; | ||
587 | } | ||
588 | |||
589 | if (filter_add_subsystem_pred(system, pred)) { | ||
590 | filter_free_subsystem_preds(system); | ||
591 | filter_free_pred(pred); | ||
592 | return -EINVAL; | ||
593 | } | ||
594 | |||
595 | *ppos += cnt; | ||
596 | |||
597 | return cnt; | ||
598 | } | ||
599 | |||
415 | static const struct seq_operations show_event_seq_ops = { | 600 | static const struct seq_operations show_event_seq_ops = { |
416 | .start = t_start, | 601 | .start = t_start, |
417 | .next = t_next, | 602 | .next = t_next, |
@@ -452,6 +637,23 @@ static const struct file_operations ftrace_event_format_fops = { | |||
452 | .read = event_format_read, | 637 | .read = event_format_read, |
453 | }; | 638 | }; |
454 | 639 | ||
640 | static const struct file_operations ftrace_event_id_fops = { | ||
641 | .open = tracing_open_generic, | ||
642 | .read = event_id_read, | ||
643 | }; | ||
644 | |||
645 | static const struct file_operations ftrace_event_filter_fops = { | ||
646 | .open = tracing_open_generic, | ||
647 | .read = event_filter_read, | ||
648 | .write = event_filter_write, | ||
649 | }; | ||
650 | |||
651 | static const struct file_operations ftrace_subsystem_filter_fops = { | ||
652 | .open = tracing_open_generic, | ||
653 | .read = subsystem_filter_read, | ||
654 | .write = subsystem_filter_write, | ||
655 | }; | ||
656 | |||
455 | static struct dentry *event_trace_events_dir(void) | 657 | static struct dentry *event_trace_events_dir(void) |
456 | { | 658 | { |
457 | static struct dentry *d_tracer; | 659 | static struct dentry *d_tracer; |
@@ -472,12 +674,6 @@ static struct dentry *event_trace_events_dir(void) | |||
472 | return d_events; | 674 | return d_events; |
473 | } | 675 | } |
474 | 676 | ||
475 | struct event_subsystem { | ||
476 | struct list_head list; | ||
477 | const char *name; | ||
478 | struct dentry *entry; | ||
479 | }; | ||
480 | |||
481 | static LIST_HEAD(event_subsystems); | 677 | static LIST_HEAD(event_subsystems); |
482 | 678 | ||
483 | static struct dentry * | 679 | static struct dentry * |
@@ -510,6 +706,8 @@ event_subsystem_dir(const char *name, struct dentry *d_events) | |||
510 | system->name = name; | 706 | system->name = name; |
511 | list_add(&system->list, &event_subsystems); | 707 | list_add(&system->list, &event_subsystems); |
512 | 708 | ||
709 | system->preds = NULL; | ||
710 | |||
513 | return system->entry; | 711 | return system->entry; |
514 | } | 712 | } |
515 | 713 | ||
@@ -550,6 +748,28 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events) | |||
550 | "'%s/enable' entry\n", call->name); | 748 | "'%s/enable' entry\n", call->name); |
551 | } | 749 | } |
552 | 750 | ||
751 | if (call->id) { | ||
752 | entry = debugfs_create_file("id", 0444, call->dir, call, | ||
753 | &ftrace_event_id_fops); | ||
754 | if (!entry) | ||
755 | pr_warning("Could not create debugfs '%s/id' entry\n", | ||
756 | call->name); | ||
757 | } | ||
758 | |||
759 | if (call->define_fields) { | ||
760 | ret = call->define_fields(); | ||
761 | if (ret < 0) { | ||
762 | pr_warning("Could not initialize trace point" | ||
763 | " events/%s\n", call->name); | ||
764 | return ret; | ||
765 | } | ||
766 | entry = debugfs_create_file("filter", 0644, call->dir, call, | ||
767 | &ftrace_event_filter_fops); | ||
768 | if (!entry) | ||
769 | pr_warning("Could not create debugfs " | ||
770 | "'%s/filter' entry\n", call->name); | ||
771 | } | ||
772 | |||
553 | /* A trace may not want to export its format */ | 773 | /* A trace may not want to export its format */ |
554 | if (!call->show_format) | 774 | if (!call->show_format) |
555 | return 0; | 775 | return 0; |
@@ -592,7 +812,7 @@ static __init int event_trace_init(void) | |||
592 | if (!d_events) | 812 | if (!d_events) |
593 | return 0; | 813 | return 0; |
594 | 814 | ||
595 | events_for_each(call) { | 815 | for_each_event(call) { |
596 | /* The linker may leave blanks */ | 816 | /* The linker may leave blanks */ |
597 | if (!call->name) | 817 | if (!call->name) |
598 | continue; | 818 | continue; |
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c new file mode 100644 index 000000000000..026be412f356 --- /dev/null +++ b/kernel/trace/trace_events_filter.c | |||
@@ -0,0 +1,427 @@ | |||
1 | /* | ||
2 | * trace_events_filter - generic event filtering | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
17 | * | ||
18 | * Copyright (C) 2009 Tom Zanussi <tzanussi@gmail.com> | ||
19 | */ | ||
20 | |||
21 | #include <linux/debugfs.h> | ||
22 | #include <linux/uaccess.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/ctype.h> | ||
25 | |||
26 | #include "trace.h" | ||
27 | #include "trace_output.h" | ||
28 | |||
29 | static int filter_pred_64(struct filter_pred *pred, void *event) | ||
30 | { | ||
31 | u64 *addr = (u64 *)(event + pred->offset); | ||
32 | u64 val = (u64)pred->val; | ||
33 | int match; | ||
34 | |||
35 | match = (val == *addr) ^ pred->not; | ||
36 | |||
37 | return match; | ||
38 | } | ||
39 | |||
40 | static int filter_pred_32(struct filter_pred *pred, void *event) | ||
41 | { | ||
42 | u32 *addr = (u32 *)(event + pred->offset); | ||
43 | u32 val = (u32)pred->val; | ||
44 | int match; | ||
45 | |||
46 | match = (val == *addr) ^ pred->not; | ||
47 | |||
48 | return match; | ||
49 | } | ||
50 | |||
51 | static int filter_pred_16(struct filter_pred *pred, void *event) | ||
52 | { | ||
53 | u16 *addr = (u16 *)(event + pred->offset); | ||
54 | u16 val = (u16)pred->val; | ||
55 | int match; | ||
56 | |||
57 | match = (val == *addr) ^ pred->not; | ||
58 | |||
59 | return match; | ||
60 | } | ||
61 | |||
62 | static int filter_pred_8(struct filter_pred *pred, void *event) | ||
63 | { | ||
64 | u8 *addr = (u8 *)(event + pred->offset); | ||
65 | u8 val = (u8)pred->val; | ||
66 | int match; | ||
67 | |||
68 | match = (val == *addr) ^ pred->not; | ||
69 | |||
70 | return match; | ||
71 | } | ||
72 | |||
73 | static int filter_pred_string(struct filter_pred *pred, void *event) | ||
74 | { | ||
75 | char *addr = (char *)(event + pred->offset); | ||
76 | int cmp, match; | ||
77 | |||
78 | cmp = strncmp(addr, pred->str_val, pred->str_len); | ||
79 | |||
80 | match = (!cmp) ^ pred->not; | ||
81 | |||
82 | return match; | ||
83 | } | ||
84 | |||
85 | /* return 1 if event matches, 0 otherwise (discard) */ | ||
86 | int filter_match_preds(struct ftrace_event_call *call, void *rec) | ||
87 | { | ||
88 | int i, matched, and_failed = 0; | ||
89 | struct filter_pred *pred; | ||
90 | |||
91 | for (i = 0; i < MAX_FILTER_PRED; i++) { | ||
92 | if (call->preds[i]) { | ||
93 | pred = call->preds[i]; | ||
94 | if (and_failed && !pred->or) | ||
95 | continue; | ||
96 | matched = pred->fn(pred, rec); | ||
97 | if (!matched && !pred->or) { | ||
98 | and_failed = 1; | ||
99 | continue; | ||
100 | } else if (matched && pred->or) | ||
101 | return 1; | ||
102 | } else | ||
103 | break; | ||
104 | } | ||
105 | |||
106 | if (and_failed) | ||
107 | return 0; | ||
108 | |||
109 | return 1; | ||
110 | } | ||
111 | |||
112 | void filter_print_preds(struct filter_pred **preds, struct trace_seq *s) | ||
113 | { | ||
114 | char *field_name; | ||
115 | struct filter_pred *pred; | ||
116 | int i; | ||
117 | |||
118 | if (!preds) { | ||
119 | trace_seq_printf(s, "none\n"); | ||
120 | return; | ||
121 | } | ||
122 | |||
123 | for (i = 0; i < MAX_FILTER_PRED; i++) { | ||
124 | if (preds[i]) { | ||
125 | pred = preds[i]; | ||
126 | field_name = pred->field_name; | ||
127 | if (i) | ||
128 | trace_seq_printf(s, pred->or ? "|| " : "&& "); | ||
129 | trace_seq_printf(s, "%s ", field_name); | ||
130 | trace_seq_printf(s, pred->not ? "!= " : "== "); | ||
131 | if (pred->str_val) | ||
132 | trace_seq_printf(s, "%s\n", pred->str_val); | ||
133 | else | ||
134 | trace_seq_printf(s, "%llu\n", pred->val); | ||
135 | } else | ||
136 | break; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | static struct ftrace_event_field * | ||
141 | find_event_field(struct ftrace_event_call *call, char *name) | ||
142 | { | ||
143 | struct ftrace_event_field *field; | ||
144 | |||
145 | list_for_each_entry(field, &call->fields, link) { | ||
146 | if (!strcmp(field->name, name)) | ||
147 | return field; | ||
148 | } | ||
149 | |||
150 | return NULL; | ||
151 | } | ||
152 | |||
153 | void filter_free_pred(struct filter_pred *pred) | ||
154 | { | ||
155 | if (!pred) | ||
156 | return; | ||
157 | |||
158 | kfree(pred->field_name); | ||
159 | kfree(pred->str_val); | ||
160 | kfree(pred); | ||
161 | } | ||
162 | |||
163 | void filter_free_preds(struct ftrace_event_call *call) | ||
164 | { | ||
165 | int i; | ||
166 | |||
167 | if (call->preds) { | ||
168 | for (i = 0; i < MAX_FILTER_PRED; i++) | ||
169 | filter_free_pred(call->preds[i]); | ||
170 | kfree(call->preds); | ||
171 | call->preds = NULL; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | void filter_free_subsystem_preds(struct event_subsystem *system) | ||
176 | { | ||
177 | struct ftrace_event_call *call = __start_ftrace_events; | ||
178 | int i; | ||
179 | |||
180 | if (system->preds) { | ||
181 | for (i = 0; i < MAX_FILTER_PRED; i++) | ||
182 | filter_free_pred(system->preds[i]); | ||
183 | kfree(system->preds); | ||
184 | system->preds = NULL; | ||
185 | } | ||
186 | |||
187 | events_for_each(call) { | ||
188 | if (!call->name || !call->regfunc) | ||
189 | continue; | ||
190 | |||
191 | if (!strcmp(call->system, system->name)) | ||
192 | filter_free_preds(call); | ||
193 | } | ||
194 | } | ||
195 | |||
196 | static int __filter_add_pred(struct ftrace_event_call *call, | ||
197 | struct filter_pred *pred) | ||
198 | { | ||
199 | int i; | ||
200 | |||
201 | if (call->preds && !pred->compound) | ||
202 | filter_free_preds(call); | ||
203 | |||
204 | if (!call->preds) { | ||
205 | call->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred), | ||
206 | GFP_KERNEL); | ||
207 | if (!call->preds) | ||
208 | return -ENOMEM; | ||
209 | } | ||
210 | |||
211 | for (i = 0; i < MAX_FILTER_PRED; i++) { | ||
212 | if (!call->preds[i]) { | ||
213 | call->preds[i] = pred; | ||
214 | return 0; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | return -ENOMEM; | ||
219 | } | ||
220 | |||
221 | static int is_string_field(const char *type) | ||
222 | { | ||
223 | if (strchr(type, '[') && strstr(type, "char")) | ||
224 | return 1; | ||
225 | |||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | int filter_add_pred(struct ftrace_event_call *call, struct filter_pred *pred) | ||
230 | { | ||
231 | struct ftrace_event_field *field; | ||
232 | |||
233 | field = find_event_field(call, pred->field_name); | ||
234 | if (!field) | ||
235 | return -EINVAL; | ||
236 | |||
237 | pred->offset = field->offset; | ||
238 | |||
239 | if (is_string_field(field->type)) { | ||
240 | if (!pred->str_val) | ||
241 | return -EINVAL; | ||
242 | pred->fn = filter_pred_string; | ||
243 | pred->str_len = field->size; | ||
244 | return __filter_add_pred(call, pred); | ||
245 | } else { | ||
246 | if (pred->str_val) | ||
247 | return -EINVAL; | ||
248 | } | ||
249 | |||
250 | switch (field->size) { | ||
251 | case 8: | ||
252 | pred->fn = filter_pred_64; | ||
253 | break; | ||
254 | case 4: | ||
255 | pred->fn = filter_pred_32; | ||
256 | break; | ||
257 | case 2: | ||
258 | pred->fn = filter_pred_16; | ||
259 | break; | ||
260 | case 1: | ||
261 | pred->fn = filter_pred_8; | ||
262 | break; | ||
263 | default: | ||
264 | return -EINVAL; | ||
265 | } | ||
266 | |||
267 | return __filter_add_pred(call, pred); | ||
268 | } | ||
269 | |||
270 | static struct filter_pred *copy_pred(struct filter_pred *pred) | ||
271 | { | ||
272 | struct filter_pred *new_pred = kmalloc(sizeof(*pred), GFP_KERNEL); | ||
273 | if (!new_pred) | ||
274 | return NULL; | ||
275 | |||
276 | memcpy(new_pred, pred, sizeof(*pred)); | ||
277 | |||
278 | if (pred->field_name) { | ||
279 | new_pred->field_name = kstrdup(pred->field_name, GFP_KERNEL); | ||
280 | if (!new_pred->field_name) { | ||
281 | kfree(new_pred); | ||
282 | return NULL; | ||
283 | } | ||
284 | } | ||
285 | |||
286 | if (pred->str_val) { | ||
287 | new_pred->str_val = kstrdup(pred->str_val, GFP_KERNEL); | ||
288 | if (!new_pred->str_val) { | ||
289 | filter_free_pred(new_pred); | ||
290 | return NULL; | ||
291 | } | ||
292 | } | ||
293 | |||
294 | return new_pred; | ||
295 | } | ||
296 | |||
297 | int filter_add_subsystem_pred(struct event_subsystem *system, | ||
298 | struct filter_pred *pred) | ||
299 | { | ||
300 | struct ftrace_event_call *call = __start_ftrace_events; | ||
301 | struct filter_pred *event_pred; | ||
302 | int i; | ||
303 | |||
304 | if (system->preds && !pred->compound) | ||
305 | filter_free_subsystem_preds(system); | ||
306 | |||
307 | if (!system->preds) { | ||
308 | system->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred), | ||
309 | GFP_KERNEL); | ||
310 | if (!system->preds) | ||
311 | return -ENOMEM; | ||
312 | } | ||
313 | |||
314 | for (i = 0; i < MAX_FILTER_PRED; i++) { | ||
315 | if (!system->preds[i]) { | ||
316 | system->preds[i] = pred; | ||
317 | break; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | if (i == MAX_FILTER_PRED) | ||
322 | return -EINVAL; | ||
323 | |||
324 | events_for_each(call) { | ||
325 | int err; | ||
326 | |||
327 | if (!call->name || !call->regfunc) | ||
328 | continue; | ||
329 | |||
330 | if (strcmp(call->system, system->name)) | ||
331 | continue; | ||
332 | |||
333 | if (!find_event_field(call, pred->field_name)) | ||
334 | continue; | ||
335 | |||
336 | event_pred = copy_pred(pred); | ||
337 | if (!event_pred) | ||
338 | goto oom; | ||
339 | |||
340 | err = filter_add_pred(call, event_pred); | ||
341 | if (err) | ||
342 | filter_free_pred(event_pred); | ||
343 | if (err == -ENOMEM) | ||
344 | goto oom; | ||
345 | } | ||
346 | |||
347 | return 0; | ||
348 | |||
349 | oom: | ||
350 | system->preds[i] = NULL; | ||
351 | return -ENOMEM; | ||
352 | } | ||
353 | |||
354 | int filter_parse(char **pbuf, struct filter_pred *pred) | ||
355 | { | ||
356 | char *tmp, *tok, *val_str = NULL; | ||
357 | int tok_n = 0; | ||
358 | |||
359 | /* field ==/!= number, or/and field ==/!= number, number */ | ||
360 | while ((tok = strsep(pbuf, " \n"))) { | ||
361 | if (tok_n == 0) { | ||
362 | if (!strcmp(tok, "0")) { | ||
363 | pred->clear = 1; | ||
364 | return 0; | ||
365 | } else if (!strcmp(tok, "&&")) { | ||
366 | pred->or = 0; | ||
367 | pred->compound = 1; | ||
368 | } else if (!strcmp(tok, "||")) { | ||
369 | pred->or = 1; | ||
370 | pred->compound = 1; | ||
371 | } else | ||
372 | pred->field_name = tok; | ||
373 | tok_n = 1; | ||
374 | continue; | ||
375 | } | ||
376 | if (tok_n == 1) { | ||
377 | if (!pred->field_name) | ||
378 | pred->field_name = tok; | ||
379 | else if (!strcmp(tok, "!=")) | ||
380 | pred->not = 1; | ||
381 | else if (!strcmp(tok, "==")) | ||
382 | pred->not = 0; | ||
383 | else { | ||
384 | pred->field_name = NULL; | ||
385 | return -EINVAL; | ||
386 | } | ||
387 | tok_n = 2; | ||
388 | continue; | ||
389 | } | ||
390 | if (tok_n == 2) { | ||
391 | if (pred->compound) { | ||
392 | if (!strcmp(tok, "!=")) | ||
393 | pred->not = 1; | ||
394 | else if (!strcmp(tok, "==")) | ||
395 | pred->not = 0; | ||
396 | else { | ||
397 | pred->field_name = NULL; | ||
398 | return -EINVAL; | ||
399 | } | ||
400 | } else { | ||
401 | val_str = tok; | ||
402 | break; /* done */ | ||
403 | } | ||
404 | tok_n = 3; | ||
405 | continue; | ||
406 | } | ||
407 | if (tok_n == 3) { | ||
408 | val_str = tok; | ||
409 | break; /* done */ | ||
410 | } | ||
411 | } | ||
412 | |||
413 | pred->field_name = kstrdup(pred->field_name, GFP_KERNEL); | ||
414 | if (!pred->field_name) | ||
415 | return -ENOMEM; | ||
416 | |||
417 | pred->val = simple_strtoull(val_str, &tmp, 10); | ||
418 | if (tmp == val_str) { | ||
419 | pred->str_val = kstrdup(val_str, GFP_KERNEL); | ||
420 | if (!pred->str_val) | ||
421 | return -ENOMEM; | ||
422 | } | ||
423 | |||
424 | return 0; | ||
425 | } | ||
426 | |||
427 | |||
diff --git a/kernel/trace/trace_events_stage_2.h b/kernel/trace/trace_events_stage_2.h index 5117c43f5c67..30743f7d4110 100644 --- a/kernel/trace/trace_events_stage_2.h +++ b/kernel/trace/trace_events_stage_2.h | |||
@@ -129,3 +129,48 @@ ftrace_format_##call(struct trace_seq *s) \ | |||
129 | } | 129 | } |
130 | 130 | ||
131 | #include <trace/trace_event_types.h> | 131 | #include <trace/trace_event_types.h> |
132 | |||
133 | #undef __field | ||
134 | #define __field(type, item) \ | ||
135 | ret = trace_define_field(event_call, #type, #item, \ | ||
136 | offsetof(typeof(field), item), \ | ||
137 | sizeof(field.item)); \ | ||
138 | if (ret) \ | ||
139 | return ret; | ||
140 | |||
141 | #undef __array | ||
142 | #define __array(type, item, len) \ | ||
143 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ | ||
144 | offsetof(typeof(field), item), \ | ||
145 | sizeof(field.item)); \ | ||
146 | if (ret) \ | ||
147 | return ret; | ||
148 | |||
149 | #define __common_field(type, item) \ | ||
150 | ret = trace_define_field(event_call, #type, "common_" #item, \ | ||
151 | offsetof(typeof(field.ent), item), \ | ||
152 | sizeof(field.ent.item)); \ | ||
153 | if (ret) \ | ||
154 | return ret; | ||
155 | |||
156 | #undef TRACE_EVENT | ||
157 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ | ||
158 | int \ | ||
159 | ftrace_define_fields_##call(void) \ | ||
160 | { \ | ||
161 | struct ftrace_raw_##call field; \ | ||
162 | struct ftrace_event_call *event_call = &event_##call; \ | ||
163 | int ret; \ | ||
164 | \ | ||
165 | __common_field(unsigned char, type); \ | ||
166 | __common_field(unsigned char, flags); \ | ||
167 | __common_field(unsigned char, preempt_count); \ | ||
168 | __common_field(int, pid); \ | ||
169 | __common_field(int, tgid); \ | ||
170 | \ | ||
171 | tstruct; \ | ||
172 | \ | ||
173 | return ret; \ | ||
174 | } | ||
175 | |||
176 | #include <trace/trace_event_types.h> | ||
diff --git a/kernel/trace/trace_events_stage_3.h b/kernel/trace/trace_events_stage_3.h index ae2e323df0c7..9d2fa78cecca 100644 --- a/kernel/trace/trace_events_stage_3.h +++ b/kernel/trace/trace_events_stage_3.h | |||
@@ -109,6 +109,40 @@ | |||
109 | #undef TP_FMT | 109 | #undef TP_FMT |
110 | #define TP_FMT(fmt, args...) fmt "\n", ##args | 110 | #define TP_FMT(fmt, args...) fmt "\n", ##args |
111 | 111 | ||
112 | #ifdef CONFIG_EVENT_PROFILE | ||
113 | #define _TRACE_PROFILE(call, proto, args) \ | ||
114 | static void ftrace_profile_##call(proto) \ | ||
115 | { \ | ||
116 | extern void perf_tpcounter_event(int); \ | ||
117 | perf_tpcounter_event(event_##call.id); \ | ||
118 | } \ | ||
119 | \ | ||
120 | static int ftrace_profile_enable_##call(struct ftrace_event_call *call) \ | ||
121 | { \ | ||
122 | int ret = 0; \ | ||
123 | \ | ||
124 | if (!atomic_inc_return(&call->profile_count)) \ | ||
125 | ret = register_trace_##call(ftrace_profile_##call); \ | ||
126 | \ | ||
127 | return ret; \ | ||
128 | } \ | ||
129 | \ | ||
130 | static void ftrace_profile_disable_##call(struct ftrace_event_call *call) \ | ||
131 | { \ | ||
132 | if (atomic_add_negative(-1, &call->profile_count)) \ | ||
133 | unregister_trace_##call(ftrace_profile_##call); \ | ||
134 | } | ||
135 | |||
136 | #define _TRACE_PROFILE_INIT(call) \ | ||
137 | .profile_count = ATOMIC_INIT(-1), \ | ||
138 | .profile_enable = ftrace_profile_enable_##call, \ | ||
139 | .profile_disable = ftrace_profile_disable_##call, | ||
140 | |||
141 | #else | ||
142 | #define _TRACE_PROFILE(call, proto, args) | ||
143 | #define _TRACE_PROFILE_INIT(call) | ||
144 | #endif | ||
145 | |||
112 | #define _TRACE_FORMAT(call, proto, args, fmt) \ | 146 | #define _TRACE_FORMAT(call, proto, args, fmt) \ |
113 | static void ftrace_event_##call(proto) \ | 147 | static void ftrace_event_##call(proto) \ |
114 | { \ | 148 | { \ |
@@ -130,18 +164,33 @@ static void ftrace_unreg_event_##call(void) \ | |||
130 | { \ | 164 | { \ |
131 | unregister_trace_##call(ftrace_event_##call); \ | 165 | unregister_trace_##call(ftrace_event_##call); \ |
132 | } \ | 166 | } \ |
133 | 167 | \ | |
168 | static struct ftrace_event_call event_##call; \ | ||
169 | \ | ||
170 | static int ftrace_init_event_##call(void) \ | ||
171 | { \ | ||
172 | int id; \ | ||
173 | \ | ||
174 | id = register_ftrace_event(NULL); \ | ||
175 | if (!id) \ | ||
176 | return -ENODEV; \ | ||
177 | event_##call.id = id; \ | ||
178 | return 0; \ | ||
179 | } | ||
134 | 180 | ||
135 | #undef TRACE_FORMAT | 181 | #undef TRACE_FORMAT |
136 | #define TRACE_FORMAT(call, proto, args, fmt) \ | 182 | #define TRACE_FORMAT(call, proto, args, fmt) \ |
137 | _TRACE_FORMAT(call, PARAMS(proto), PARAMS(args), PARAMS(fmt)) \ | 183 | _TRACE_FORMAT(call, PARAMS(proto), PARAMS(args), PARAMS(fmt)) \ |
184 | _TRACE_PROFILE(call, PARAMS(proto), PARAMS(args)) \ | ||
138 | static struct ftrace_event_call __used \ | 185 | static struct ftrace_event_call __used \ |
139 | __attribute__((__aligned__(4))) \ | 186 | __attribute__((__aligned__(4))) \ |
140 | __attribute__((section("_ftrace_events"))) event_##call = { \ | 187 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
141 | .name = #call, \ | 188 | .name = #call, \ |
142 | .system = __stringify(TRACE_SYSTEM), \ | 189 | .system = __stringify(TRACE_SYSTEM), \ |
190 | .raw_init = ftrace_init_event_##call, \ | ||
143 | .regfunc = ftrace_reg_event_##call, \ | 191 | .regfunc = ftrace_reg_event_##call, \ |
144 | .unregfunc = ftrace_unreg_event_##call, \ | 192 | .unregfunc = ftrace_unreg_event_##call, \ |
193 | _TRACE_PROFILE_INIT(call) \ | ||
145 | } | 194 | } |
146 | 195 | ||
147 | #undef __entry | 196 | #undef __entry |
@@ -149,11 +198,13 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
149 | 198 | ||
150 | #undef TRACE_EVENT | 199 | #undef TRACE_EVENT |
151 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | 200 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ |
201 | _TRACE_PROFILE(call, PARAMS(proto), PARAMS(args)) \ | ||
152 | \ | 202 | \ |
153 | static struct ftrace_event_call event_##call; \ | 203 | static struct ftrace_event_call event_##call; \ |
154 | \ | 204 | \ |
155 | static void ftrace_raw_event_##call(proto) \ | 205 | static void ftrace_raw_event_##call(proto) \ |
156 | { \ | 206 | { \ |
207 | struct ftrace_event_call *call = &event_##call; \ | ||
157 | struct ring_buffer_event *event; \ | 208 | struct ring_buffer_event *event; \ |
158 | struct ftrace_raw_##call *entry; \ | 209 | struct ftrace_raw_##call *entry; \ |
159 | unsigned long irq_flags; \ | 210 | unsigned long irq_flags; \ |
@@ -171,7 +222,11 @@ static void ftrace_raw_event_##call(proto) \ | |||
171 | \ | 222 | \ |
172 | assign; \ | 223 | assign; \ |
173 | \ | 224 | \ |
174 | trace_current_buffer_unlock_commit(event, irq_flags, pc); \ | 225 | if (call->preds && !filter_match_preds(call, entry)) \ |
226 | ring_buffer_event_discard(event); \ | ||
227 | \ | ||
228 | trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \ | ||
229 | \ | ||
175 | } \ | 230 | } \ |
176 | \ | 231 | \ |
177 | static int ftrace_raw_reg_event_##call(void) \ | 232 | static int ftrace_raw_reg_event_##call(void) \ |
@@ -202,6 +257,7 @@ static int ftrace_raw_init_event_##call(void) \ | |||
202 | if (!id) \ | 257 | if (!id) \ |
203 | return -ENODEV; \ | 258 | return -ENODEV; \ |
204 | event_##call.id = id; \ | 259 | event_##call.id = id; \ |
260 | INIT_LIST_HEAD(&event_##call.fields); \ | ||
205 | return 0; \ | 261 | return 0; \ |
206 | } \ | 262 | } \ |
207 | \ | 263 | \ |
@@ -214,4 +270,12 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
214 | .regfunc = ftrace_raw_reg_event_##call, \ | 270 | .regfunc = ftrace_raw_reg_event_##call, \ |
215 | .unregfunc = ftrace_raw_unreg_event_##call, \ | 271 | .unregfunc = ftrace_raw_unreg_event_##call, \ |
216 | .show_format = ftrace_format_##call, \ | 272 | .show_format = ftrace_format_##call, \ |
273 | .define_fields = ftrace_define_fields_##call, \ | ||
274 | _TRACE_PROFILE_INIT(call) \ | ||
217 | } | 275 | } |
276 | |||
277 | #include <trace/trace_event_types.h> | ||
278 | |||
279 | #undef _TRACE_PROFILE | ||
280 | #undef _TRACE_PROFILE_INIT | ||
281 | |||
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index 6004ccac2dd7..d28687e7b3a7 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c | |||
@@ -14,6 +14,11 @@ | |||
14 | #include "trace.h" | 14 | #include "trace.h" |
15 | #include "trace_output.h" | 15 | #include "trace_output.h" |
16 | 16 | ||
17 | struct fgraph_data { | ||
18 | pid_t last_pid; | ||
19 | int depth; | ||
20 | }; | ||
21 | |||
17 | #define TRACE_GRAPH_INDENT 2 | 22 | #define TRACE_GRAPH_INDENT 2 |
18 | 23 | ||
19 | /* Flag options */ | 24 | /* Flag options */ |
@@ -52,9 +57,9 @@ static struct tracer_flags tracer_flags = { | |||
52 | 57 | ||
53 | /* Add a function return address to the trace stack on thread info.*/ | 58 | /* Add a function return address to the trace stack on thread info.*/ |
54 | int | 59 | int |
55 | ftrace_push_return_trace(unsigned long ret, unsigned long long time, | 60 | ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth) |
56 | unsigned long func, int *depth) | ||
57 | { | 61 | { |
62 | unsigned long long calltime; | ||
58 | int index; | 63 | int index; |
59 | 64 | ||
60 | if (!current->ret_stack) | 65 | if (!current->ret_stack) |
@@ -66,11 +71,13 @@ ftrace_push_return_trace(unsigned long ret, unsigned long long time, | |||
66 | return -EBUSY; | 71 | return -EBUSY; |
67 | } | 72 | } |
68 | 73 | ||
74 | calltime = trace_clock_local(); | ||
75 | |||
69 | index = ++current->curr_ret_stack; | 76 | index = ++current->curr_ret_stack; |
70 | barrier(); | 77 | barrier(); |
71 | current->ret_stack[index].ret = ret; | 78 | current->ret_stack[index].ret = ret; |
72 | current->ret_stack[index].func = func; | 79 | current->ret_stack[index].func = func; |
73 | current->ret_stack[index].calltime = time; | 80 | current->ret_stack[index].calltime = calltime; |
74 | *depth = index; | 81 | *depth = index; |
75 | 82 | ||
76 | return 0; | 83 | return 0; |
@@ -231,16 +238,16 @@ print_graph_proc(struct trace_seq *s, pid_t pid) | |||
231 | 238 | ||
232 | /* If the pid changed since the last trace, output this event */ | 239 | /* If the pid changed since the last trace, output this event */ |
233 | static enum print_line_t | 240 | static enum print_line_t |
234 | verif_pid(struct trace_seq *s, pid_t pid, int cpu, pid_t *last_pids_cpu) | 241 | verif_pid(struct trace_seq *s, pid_t pid, int cpu, struct fgraph_data *data) |
235 | { | 242 | { |
236 | pid_t prev_pid; | 243 | pid_t prev_pid; |
237 | pid_t *last_pid; | 244 | pid_t *last_pid; |
238 | int ret; | 245 | int ret; |
239 | 246 | ||
240 | if (!last_pids_cpu) | 247 | if (!data) |
241 | return TRACE_TYPE_HANDLED; | 248 | return TRACE_TYPE_HANDLED; |
242 | 249 | ||
243 | last_pid = per_cpu_ptr(last_pids_cpu, cpu); | 250 | last_pid = &(per_cpu_ptr(data, cpu)->last_pid); |
244 | 251 | ||
245 | if (*last_pid == pid) | 252 | if (*last_pid == pid) |
246 | return TRACE_TYPE_HANDLED; | 253 | return TRACE_TYPE_HANDLED; |
@@ -471,6 +478,7 @@ print_graph_entry_leaf(struct trace_iterator *iter, | |||
471 | struct ftrace_graph_ent_entry *entry, | 478 | struct ftrace_graph_ent_entry *entry, |
472 | struct ftrace_graph_ret_entry *ret_entry, struct trace_seq *s) | 479 | struct ftrace_graph_ret_entry *ret_entry, struct trace_seq *s) |
473 | { | 480 | { |
481 | struct fgraph_data *data = iter->private; | ||
474 | struct ftrace_graph_ret *graph_ret; | 482 | struct ftrace_graph_ret *graph_ret; |
475 | struct ftrace_graph_ent *call; | 483 | struct ftrace_graph_ent *call; |
476 | unsigned long long duration; | 484 | unsigned long long duration; |
@@ -481,6 +489,18 @@ print_graph_entry_leaf(struct trace_iterator *iter, | |||
481 | call = &entry->graph_ent; | 489 | call = &entry->graph_ent; |
482 | duration = graph_ret->rettime - graph_ret->calltime; | 490 | duration = graph_ret->rettime - graph_ret->calltime; |
483 | 491 | ||
492 | if (data) { | ||
493 | int cpu = iter->cpu; | ||
494 | int *depth = &(per_cpu_ptr(data, cpu)->depth); | ||
495 | |||
496 | /* | ||
497 | * Comments display at + 1 to depth. Since | ||
498 | * this is a leaf function, keep the comments | ||
499 | * equal to this depth. | ||
500 | */ | ||
501 | *depth = call->depth - 1; | ||
502 | } | ||
503 | |||
484 | /* Overhead */ | 504 | /* Overhead */ |
485 | ret = print_graph_overhead(duration, s); | 505 | ret = print_graph_overhead(duration, s); |
486 | if (!ret) | 506 | if (!ret) |
@@ -512,12 +532,21 @@ print_graph_entry_leaf(struct trace_iterator *iter, | |||
512 | } | 532 | } |
513 | 533 | ||
514 | static enum print_line_t | 534 | static enum print_line_t |
515 | print_graph_entry_nested(struct ftrace_graph_ent_entry *entry, | 535 | print_graph_entry_nested(struct trace_iterator *iter, |
516 | struct trace_seq *s, pid_t pid, int cpu) | 536 | struct ftrace_graph_ent_entry *entry, |
537 | struct trace_seq *s, int cpu) | ||
517 | { | 538 | { |
518 | int i; | ||
519 | int ret; | ||
520 | struct ftrace_graph_ent *call = &entry->graph_ent; | 539 | struct ftrace_graph_ent *call = &entry->graph_ent; |
540 | struct fgraph_data *data = iter->private; | ||
541 | int ret; | ||
542 | int i; | ||
543 | |||
544 | if (data) { | ||
545 | int cpu = iter->cpu; | ||
546 | int *depth = &(per_cpu_ptr(data, cpu)->depth); | ||
547 | |||
548 | *depth = call->depth; | ||
549 | } | ||
521 | 550 | ||
522 | /* No overhead */ | 551 | /* No overhead */ |
523 | ret = print_graph_overhead(-1, s); | 552 | ret = print_graph_overhead(-1, s); |
@@ -554,24 +583,24 @@ print_graph_entry_nested(struct ftrace_graph_ent_entry *entry, | |||
554 | } | 583 | } |
555 | 584 | ||
556 | static enum print_line_t | 585 | static enum print_line_t |
557 | print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, | 586 | print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s, |
558 | struct trace_iterator *iter) | 587 | int type, unsigned long addr) |
559 | { | 588 | { |
560 | int ret; | 589 | struct fgraph_data *data = iter->private; |
561 | int cpu = iter->cpu; | ||
562 | pid_t *last_entry = iter->private; | ||
563 | struct trace_entry *ent = iter->ent; | 590 | struct trace_entry *ent = iter->ent; |
564 | struct ftrace_graph_ent *call = &field->graph_ent; | 591 | int cpu = iter->cpu; |
565 | struct ftrace_graph_ret_entry *leaf_ret; | 592 | int ret; |
566 | 593 | ||
567 | /* Pid */ | 594 | /* Pid */ |
568 | if (verif_pid(s, ent->pid, cpu, last_entry) == TRACE_TYPE_PARTIAL_LINE) | 595 | if (verif_pid(s, ent->pid, cpu, data) == TRACE_TYPE_PARTIAL_LINE) |
569 | return TRACE_TYPE_PARTIAL_LINE; | 596 | return TRACE_TYPE_PARTIAL_LINE; |
570 | 597 | ||
571 | /* Interrupt */ | 598 | if (type) { |
572 | ret = print_graph_irq(iter, call->func, TRACE_GRAPH_ENT, cpu, ent->pid); | 599 | /* Interrupt */ |
573 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 600 | ret = print_graph_irq(iter, addr, type, cpu, ent->pid); |
574 | return TRACE_TYPE_PARTIAL_LINE; | 601 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
602 | return TRACE_TYPE_PARTIAL_LINE; | ||
603 | } | ||
575 | 604 | ||
576 | /* Absolute time */ | 605 | /* Absolute time */ |
577 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) { | 606 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) { |
@@ -598,11 +627,25 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, | |||
598 | return TRACE_TYPE_PARTIAL_LINE; | 627 | return TRACE_TYPE_PARTIAL_LINE; |
599 | } | 628 | } |
600 | 629 | ||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | static enum print_line_t | ||
634 | print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, | ||
635 | struct trace_iterator *iter) | ||
636 | { | ||
637 | int cpu = iter->cpu; | ||
638 | struct ftrace_graph_ent *call = &field->graph_ent; | ||
639 | struct ftrace_graph_ret_entry *leaf_ret; | ||
640 | |||
641 | if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func)) | ||
642 | return TRACE_TYPE_PARTIAL_LINE; | ||
643 | |||
601 | leaf_ret = get_return_for_leaf(iter, field); | 644 | leaf_ret = get_return_for_leaf(iter, field); |
602 | if (leaf_ret) | 645 | if (leaf_ret) |
603 | return print_graph_entry_leaf(iter, field, leaf_ret, s); | 646 | return print_graph_entry_leaf(iter, field, leaf_ret, s); |
604 | else | 647 | else |
605 | return print_graph_entry_nested(field, s, iter->ent->pid, cpu); | 648 | return print_graph_entry_nested(iter, field, s, cpu); |
606 | 649 | ||
607 | } | 650 | } |
608 | 651 | ||
@@ -610,40 +653,27 @@ static enum print_line_t | |||
610 | print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, | 653 | print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, |
611 | struct trace_entry *ent, struct trace_iterator *iter) | 654 | struct trace_entry *ent, struct trace_iterator *iter) |
612 | { | 655 | { |
613 | int i; | ||
614 | int ret; | ||
615 | int cpu = iter->cpu; | ||
616 | pid_t *last_pid = iter->private, pid = ent->pid; | ||
617 | unsigned long long duration = trace->rettime - trace->calltime; | 656 | unsigned long long duration = trace->rettime - trace->calltime; |
657 | struct fgraph_data *data = iter->private; | ||
658 | pid_t pid = ent->pid; | ||
659 | int cpu = iter->cpu; | ||
660 | int ret; | ||
661 | int i; | ||
618 | 662 | ||
619 | /* Pid */ | 663 | if (data) { |
620 | if (verif_pid(s, pid, cpu, last_pid) == TRACE_TYPE_PARTIAL_LINE) | 664 | int cpu = iter->cpu; |
621 | return TRACE_TYPE_PARTIAL_LINE; | 665 | int *depth = &(per_cpu_ptr(data, cpu)->depth); |
622 | 666 | ||
623 | /* Absolute time */ | 667 | /* |
624 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) { | 668 | * Comments display at + 1 to depth. This is the |
625 | ret = print_graph_abs_time(iter->ts, s); | 669 | * return from a function, we now want the comments |
626 | if (!ret) | 670 | * to display at the same level of the bracket. |
627 | return TRACE_TYPE_PARTIAL_LINE; | 671 | */ |
672 | *depth = trace->depth - 1; | ||
628 | } | 673 | } |
629 | 674 | ||
630 | /* Cpu */ | 675 | if (print_graph_prologue(iter, s, 0, 0)) |
631 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) { | 676 | return TRACE_TYPE_PARTIAL_LINE; |
632 | ret = print_graph_cpu(s, cpu); | ||
633 | if (ret == TRACE_TYPE_PARTIAL_LINE) | ||
634 | return TRACE_TYPE_PARTIAL_LINE; | ||
635 | } | ||
636 | |||
637 | /* Proc */ | ||
638 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) { | ||
639 | ret = print_graph_proc(s, ent->pid); | ||
640 | if (ret == TRACE_TYPE_PARTIAL_LINE) | ||
641 | return TRACE_TYPE_PARTIAL_LINE; | ||
642 | |||
643 | ret = trace_seq_printf(s, " | "); | ||
644 | if (!ret) | ||
645 | return TRACE_TYPE_PARTIAL_LINE; | ||
646 | } | ||
647 | 677 | ||
648 | /* Overhead */ | 678 | /* Overhead */ |
649 | ret = print_graph_overhead(duration, s); | 679 | ret = print_graph_overhead(duration, s); |
@@ -684,42 +714,21 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, | |||
684 | } | 714 | } |
685 | 715 | ||
686 | static enum print_line_t | 716 | static enum print_line_t |
687 | print_graph_comment(struct bprint_entry *trace, struct trace_seq *s, | 717 | print_graph_comment(struct trace_seq *s, struct trace_entry *ent, |
688 | struct trace_entry *ent, struct trace_iterator *iter) | 718 | struct trace_iterator *iter) |
689 | { | 719 | { |
690 | int i; | 720 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
721 | struct fgraph_data *data = iter->private; | ||
722 | struct trace_event *event; | ||
723 | int depth = 0; | ||
691 | int ret; | 724 | int ret; |
692 | int cpu = iter->cpu; | 725 | int i; |
693 | pid_t *last_pid = iter->private; | ||
694 | |||
695 | /* Pid */ | ||
696 | if (verif_pid(s, ent->pid, cpu, last_pid) == TRACE_TYPE_PARTIAL_LINE) | ||
697 | return TRACE_TYPE_PARTIAL_LINE; | ||
698 | |||
699 | /* Absolute time */ | ||
700 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) { | ||
701 | ret = print_graph_abs_time(iter->ts, s); | ||
702 | if (!ret) | ||
703 | return TRACE_TYPE_PARTIAL_LINE; | ||
704 | } | ||
705 | |||
706 | /* Cpu */ | ||
707 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) { | ||
708 | ret = print_graph_cpu(s, cpu); | ||
709 | if (ret == TRACE_TYPE_PARTIAL_LINE) | ||
710 | return TRACE_TYPE_PARTIAL_LINE; | ||
711 | } | ||
712 | 726 | ||
713 | /* Proc */ | 727 | if (data) |
714 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) { | 728 | depth = per_cpu_ptr(data, iter->cpu)->depth; |
715 | ret = print_graph_proc(s, ent->pid); | ||
716 | if (ret == TRACE_TYPE_PARTIAL_LINE) | ||
717 | return TRACE_TYPE_PARTIAL_LINE; | ||
718 | 729 | ||
719 | ret = trace_seq_printf(s, " | "); | 730 | if (print_graph_prologue(iter, s, 0, 0)) |
720 | if (!ret) | 731 | return TRACE_TYPE_PARTIAL_LINE; |
721 | return TRACE_TYPE_PARTIAL_LINE; | ||
722 | } | ||
723 | 732 | ||
724 | /* No overhead */ | 733 | /* No overhead */ |
725 | ret = print_graph_overhead(-1, s); | 734 | ret = print_graph_overhead(-1, s); |
@@ -734,8 +743,8 @@ print_graph_comment(struct bprint_entry *trace, struct trace_seq *s, | |||
734 | } | 743 | } |
735 | 744 | ||
736 | /* Indentation */ | 745 | /* Indentation */ |
737 | if (trace->depth > 0) | 746 | if (depth > 0) |
738 | for (i = 0; i < (trace->depth + 1) * TRACE_GRAPH_INDENT; i++) { | 747 | for (i = 0; i < (depth + 1) * TRACE_GRAPH_INDENT; i++) { |
739 | ret = trace_seq_printf(s, " "); | 748 | ret = trace_seq_printf(s, " "); |
740 | if (!ret) | 749 | if (!ret) |
741 | return TRACE_TYPE_PARTIAL_LINE; | 750 | return TRACE_TYPE_PARTIAL_LINE; |
@@ -746,9 +755,26 @@ print_graph_comment(struct bprint_entry *trace, struct trace_seq *s, | |||
746 | if (!ret) | 755 | if (!ret) |
747 | return TRACE_TYPE_PARTIAL_LINE; | 756 | return TRACE_TYPE_PARTIAL_LINE; |
748 | 757 | ||
749 | ret = trace_seq_bprintf(s, trace->fmt, trace->buf); | 758 | switch (iter->ent->type) { |
750 | if (!ret) | 759 | case TRACE_BPRINT: |
751 | return TRACE_TYPE_PARTIAL_LINE; | 760 | ret = trace_print_bprintk_msg_only(iter); |
761 | if (ret != TRACE_TYPE_HANDLED) | ||
762 | return ret; | ||
763 | break; | ||
764 | case TRACE_PRINT: | ||
765 | ret = trace_print_printk_msg_only(iter); | ||
766 | if (ret != TRACE_TYPE_HANDLED) | ||
767 | return ret; | ||
768 | break; | ||
769 | default: | ||
770 | event = ftrace_find_event(ent->type); | ||
771 | if (!event) | ||
772 | return TRACE_TYPE_UNHANDLED; | ||
773 | |||
774 | ret = event->trace(iter, sym_flags); | ||
775 | if (ret != TRACE_TYPE_HANDLED) | ||
776 | return ret; | ||
777 | } | ||
752 | 778 | ||
753 | /* Strip ending newline */ | 779 | /* Strip ending newline */ |
754 | if (s->buffer[s->len - 1] == '\n') { | 780 | if (s->buffer[s->len - 1] == '\n') { |
@@ -767,8 +793,8 @@ print_graph_comment(struct bprint_entry *trace, struct trace_seq *s, | |||
767 | enum print_line_t | 793 | enum print_line_t |
768 | print_graph_function(struct trace_iterator *iter) | 794 | print_graph_function(struct trace_iterator *iter) |
769 | { | 795 | { |
770 | struct trace_seq *s = &iter->seq; | ||
771 | struct trace_entry *entry = iter->ent; | 796 | struct trace_entry *entry = iter->ent; |
797 | struct trace_seq *s = &iter->seq; | ||
772 | 798 | ||
773 | switch (entry->type) { | 799 | switch (entry->type) { |
774 | case TRACE_GRAPH_ENT: { | 800 | case TRACE_GRAPH_ENT: { |
@@ -781,14 +807,11 @@ print_graph_function(struct trace_iterator *iter) | |||
781 | trace_assign_type(field, entry); | 807 | trace_assign_type(field, entry); |
782 | return print_graph_return(&field->ret, s, entry, iter); | 808 | return print_graph_return(&field->ret, s, entry, iter); |
783 | } | 809 | } |
784 | case TRACE_BPRINT: { | ||
785 | struct bprint_entry *field; | ||
786 | trace_assign_type(field, entry); | ||
787 | return print_graph_comment(field, s, entry, iter); | ||
788 | } | ||
789 | default: | 810 | default: |
790 | return TRACE_TYPE_UNHANDLED; | 811 | return print_graph_comment(s, entry, iter); |
791 | } | 812 | } |
813 | |||
814 | return TRACE_TYPE_HANDLED; | ||
792 | } | 815 | } |
793 | 816 | ||
794 | static void print_graph_headers(struct seq_file *s) | 817 | static void print_graph_headers(struct seq_file *s) |
@@ -820,19 +843,21 @@ static void print_graph_headers(struct seq_file *s) | |||
820 | 843 | ||
821 | static void graph_trace_open(struct trace_iterator *iter) | 844 | static void graph_trace_open(struct trace_iterator *iter) |
822 | { | 845 | { |
823 | /* pid on the last trace processed */ | 846 | /* pid and depth on the last trace processed */ |
824 | pid_t *last_pid = alloc_percpu(pid_t); | 847 | struct fgraph_data *data = alloc_percpu(struct fgraph_data); |
825 | int cpu; | 848 | int cpu; |
826 | 849 | ||
827 | if (!last_pid) | 850 | if (!data) |
828 | pr_warning("function graph tracer: not enough memory\n"); | 851 | pr_warning("function graph tracer: not enough memory\n"); |
829 | else | 852 | else |
830 | for_each_possible_cpu(cpu) { | 853 | for_each_possible_cpu(cpu) { |
831 | pid_t *pid = per_cpu_ptr(last_pid, cpu); | 854 | pid_t *pid = &(per_cpu_ptr(data, cpu)->last_pid); |
855 | int *depth = &(per_cpu_ptr(data, cpu)->depth); | ||
832 | *pid = -1; | 856 | *pid = -1; |
857 | *depth = 0; | ||
833 | } | 858 | } |
834 | 859 | ||
835 | iter->private = last_pid; | 860 | iter->private = data; |
836 | } | 861 | } |
837 | 862 | ||
838 | static void graph_trace_close(struct trace_iterator *iter) | 863 | static void graph_trace_close(struct trace_iterator *iter) |
diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c index f095916e477f..8e37fcddd8b4 100644 --- a/kernel/trace/trace_mmiotrace.c +++ b/kernel/trace/trace_mmiotrace.c | |||
@@ -359,5 +359,5 @@ void mmio_trace_mapping(struct mmiotrace_map *map) | |||
359 | 359 | ||
360 | int mmio_trace_printk(const char *fmt, va_list args) | 360 | int mmio_trace_printk(const char *fmt, va_list args) |
361 | { | 361 | { |
362 | return trace_vprintk(0, -1, fmt, args); | 362 | return trace_vprintk(0, fmt, args); |
363 | } | 363 | } |
diff --git a/kernel/trace/trace_nop.c b/kernel/trace/trace_nop.c index 9aa84bde23cd..394f94417e2f 100644 --- a/kernel/trace/trace_nop.c +++ b/kernel/trace/trace_nop.c | |||
@@ -91,6 +91,7 @@ struct tracer nop_trace __read_mostly = | |||
91 | .name = "nop", | 91 | .name = "nop", |
92 | .init = nop_trace_init, | 92 | .init = nop_trace_init, |
93 | .reset = nop_trace_reset, | 93 | .reset = nop_trace_reset, |
94 | .wait_pipe = poll_wait_pipe, | ||
94 | #ifdef CONFIG_FTRACE_SELFTEST | 95 | #ifdef CONFIG_FTRACE_SELFTEST |
95 | .selftest = trace_selftest_startup_nop, | 96 | .selftest = trace_selftest_startup_nop, |
96 | #endif | 97 | #endif |
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 6a4c9dea191e..d72b9a63b247 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c | |||
@@ -19,6 +19,38 @@ static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly; | |||
19 | 19 | ||
20 | static int next_event_type = __TRACE_LAST_TYPE + 1; | 20 | static int next_event_type = __TRACE_LAST_TYPE + 1; |
21 | 21 | ||
22 | enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter) | ||
23 | { | ||
24 | struct trace_seq *s = &iter->seq; | ||
25 | struct trace_entry *entry = iter->ent; | ||
26 | struct bprint_entry *field; | ||
27 | int ret; | ||
28 | |||
29 | trace_assign_type(field, entry); | ||
30 | |||
31 | ret = trace_seq_bprintf(s, field->fmt, field->buf); | ||
32 | if (!ret) | ||
33 | return TRACE_TYPE_PARTIAL_LINE; | ||
34 | |||
35 | return TRACE_TYPE_HANDLED; | ||
36 | } | ||
37 | |||
38 | enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter) | ||
39 | { | ||
40 | struct trace_seq *s = &iter->seq; | ||
41 | struct trace_entry *entry = iter->ent; | ||
42 | struct print_entry *field; | ||
43 | int ret; | ||
44 | |||
45 | trace_assign_type(field, entry); | ||
46 | |||
47 | ret = trace_seq_printf(s, "%s", field->buf); | ||
48 | if (!ret) | ||
49 | return TRACE_TYPE_PARTIAL_LINE; | ||
50 | |||
51 | return TRACE_TYPE_HANDLED; | ||
52 | } | ||
53 | |||
22 | /** | 54 | /** |
23 | * trace_seq_printf - sequence printing of trace information | 55 | * trace_seq_printf - sequence printing of trace information |
24 | * @s: trace sequence descriptor | 56 | * @s: trace sequence descriptor |
@@ -105,7 +137,7 @@ int trace_seq_putc(struct trace_seq *s, unsigned char c) | |||
105 | return 1; | 137 | return 1; |
106 | } | 138 | } |
107 | 139 | ||
108 | int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len) | 140 | int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len) |
109 | { | 141 | { |
110 | if (len > ((PAGE_SIZE - 1) - s->len)) | 142 | if (len > ((PAGE_SIZE - 1) - s->len)) |
111 | return 0; | 143 | return 0; |
@@ -116,10 +148,10 @@ int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len) | |||
116 | return len; | 148 | return len; |
117 | } | 149 | } |
118 | 150 | ||
119 | int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len) | 151 | int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len) |
120 | { | 152 | { |
121 | unsigned char hex[HEX_CHARS]; | 153 | unsigned char hex[HEX_CHARS]; |
122 | unsigned char *data = mem; | 154 | const unsigned char *data = mem; |
123 | int i, j; | 155 | int i, j; |
124 | 156 | ||
125 | #ifdef __BIG_ENDIAN | 157 | #ifdef __BIG_ENDIAN |
@@ -135,6 +167,19 @@ int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len) | |||
135 | return trace_seq_putmem(s, hex, j); | 167 | return trace_seq_putmem(s, hex, j); |
136 | } | 168 | } |
137 | 169 | ||
170 | void *trace_seq_reserve(struct trace_seq *s, size_t len) | ||
171 | { | ||
172 | void *ret; | ||
173 | |||
174 | if (len > ((PAGE_SIZE - 1) - s->len)) | ||
175 | return NULL; | ||
176 | |||
177 | ret = s->buffer + s->len; | ||
178 | s->len += len; | ||
179 | |||
180 | return ret; | ||
181 | } | ||
182 | |||
138 | int trace_seq_path(struct trace_seq *s, struct path *path) | 183 | int trace_seq_path(struct trace_seq *s, struct path *path) |
139 | { | 184 | { |
140 | unsigned char *p; | 185 | unsigned char *p; |
@@ -449,6 +494,11 @@ int register_ftrace_event(struct trace_event *event) | |||
449 | 494 | ||
450 | mutex_lock(&trace_event_mutex); | 495 | mutex_lock(&trace_event_mutex); |
451 | 496 | ||
497 | if (!event) { | ||
498 | ret = next_event_type++; | ||
499 | goto out; | ||
500 | } | ||
501 | |||
452 | if (!event->type) | 502 | if (!event->type) |
453 | event->type = next_event_type++; | 503 | event->type = next_event_type++; |
454 | else if (event->type > __TRACE_LAST_TYPE) { | 504 | else if (event->type > __TRACE_LAST_TYPE) { |
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h index 3b90e6ade1aa..e0bde39c2dd9 100644 --- a/kernel/trace/trace_output.h +++ b/kernel/trace/trace_output.h | |||
@@ -15,6 +15,11 @@ struct trace_event { | |||
15 | trace_print_func binary; | 15 | trace_print_func binary; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | extern enum print_line_t | ||
19 | trace_print_bprintk_msg_only(struct trace_iterator *iter); | ||
20 | extern enum print_line_t | ||
21 | trace_print_printk_msg_only(struct trace_iterator *iter); | ||
22 | |||
18 | extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...) | 23 | extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...) |
19 | __attribute__ ((format (printf, 2, 3))); | 24 | __attribute__ ((format (printf, 2, 3))); |
20 | extern int | 25 | extern int |
@@ -24,24 +29,27 @@ seq_print_ip_sym(struct trace_seq *s, unsigned long ip, | |||
24 | unsigned long sym_flags); | 29 | unsigned long sym_flags); |
25 | extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, | 30 | extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, |
26 | size_t cnt); | 31 | size_t cnt); |
27 | int trace_seq_puts(struct trace_seq *s, const char *str); | 32 | extern int trace_seq_puts(struct trace_seq *s, const char *str); |
28 | int trace_seq_putc(struct trace_seq *s, unsigned char c); | 33 | extern int trace_seq_putc(struct trace_seq *s, unsigned char c); |
29 | int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len); | 34 | extern int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len); |
30 | int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len); | 35 | extern int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, |
31 | int trace_seq_path(struct trace_seq *s, struct path *path); | 36 | size_t len); |
32 | int seq_print_userip_objs(const struct userstack_entry *entry, | 37 | extern void *trace_seq_reserve(struct trace_seq *s, size_t len); |
33 | struct trace_seq *s, unsigned long sym_flags); | 38 | extern int trace_seq_path(struct trace_seq *s, struct path *path); |
34 | int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, | 39 | extern int seq_print_userip_objs(const struct userstack_entry *entry, |
35 | unsigned long ip, unsigned long sym_flags); | 40 | struct trace_seq *s, unsigned long sym_flags); |
36 | 41 | extern int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, | |
37 | int trace_print_context(struct trace_iterator *iter); | 42 | unsigned long ip, unsigned long sym_flags); |
38 | int trace_print_lat_context(struct trace_iterator *iter); | 43 | |
39 | 44 | extern int trace_print_context(struct trace_iterator *iter); | |
40 | struct trace_event *ftrace_find_event(int type); | 45 | extern int trace_print_lat_context(struct trace_iterator *iter); |
41 | int register_ftrace_event(struct trace_event *event); | 46 | |
42 | int unregister_ftrace_event(struct trace_event *event); | 47 | extern struct trace_event *ftrace_find_event(int type); |
43 | 48 | extern int register_ftrace_event(struct trace_event *event); | |
44 | enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags); | 49 | extern int unregister_ftrace_event(struct trace_event *event); |
50 | |||
51 | extern enum print_line_t trace_nop_print(struct trace_iterator *iter, | ||
52 | int flags); | ||
45 | 53 | ||
46 | #define MAX_MEMHEX_BYTES 8 | 54 | #define MAX_MEMHEX_BYTES 8 |
47 | #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) | 55 | #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) |
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c index 486785214e3e..eb81556107fe 100644 --- a/kernel/trace/trace_printk.c +++ b/kernel/trace/trace_printk.c | |||
@@ -112,7 +112,7 @@ int __trace_bprintk(unsigned long ip, const char *fmt, ...) | |||
112 | return 0; | 112 | return 0; |
113 | 113 | ||
114 | va_start(ap, fmt); | 114 | va_start(ap, fmt); |
115 | ret = trace_vbprintk(ip, task_curr_ret_stack(current), fmt, ap); | 115 | ret = trace_vbprintk(ip, fmt, ap); |
116 | va_end(ap); | 116 | va_end(ap); |
117 | return ret; | 117 | return ret; |
118 | } | 118 | } |
@@ -126,7 +126,7 @@ int __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap) | |||
126 | if (!(trace_flags & TRACE_ITER_PRINTK)) | 126 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
127 | return 0; | 127 | return 0; |
128 | 128 | ||
129 | return trace_vbprintk(ip, task_curr_ret_stack(current), fmt, ap); | 129 | return trace_vbprintk(ip, fmt, ap); |
130 | } | 130 | } |
131 | EXPORT_SYMBOL_GPL(__ftrace_vbprintk); | 131 | EXPORT_SYMBOL_GPL(__ftrace_vbprintk); |
132 | 132 | ||
@@ -139,7 +139,7 @@ int __trace_printk(unsigned long ip, const char *fmt, ...) | |||
139 | return 0; | 139 | return 0; |
140 | 140 | ||
141 | va_start(ap, fmt); | 141 | va_start(ap, fmt); |
142 | ret = trace_vprintk(ip, task_curr_ret_stack(current), fmt, ap); | 142 | ret = trace_vprintk(ip, fmt, ap); |
143 | va_end(ap); | 143 | va_end(ap); |
144 | return ret; | 144 | return ret; |
145 | } | 145 | } |
@@ -150,7 +150,7 @@ int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap) | |||
150 | if (!(trace_flags & TRACE_ITER_PRINTK)) | 150 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
151 | return 0; | 151 | return 0; |
152 | 152 | ||
153 | return trace_vprintk(ip, task_curr_ret_stack(current), fmt, ap); | 153 | return trace_vprintk(ip, fmt, ap); |
154 | } | 154 | } |
155 | EXPORT_SYMBOL_GPL(__ftrace_vprintk); | 155 | EXPORT_SYMBOL_GPL(__ftrace_vprintk); |
156 | 156 | ||
diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index 38856ba78a92..08f4eb2763d1 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c | |||
@@ -248,6 +248,28 @@ trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr) | |||
248 | 248 | ||
249 | 249 | ||
250 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 250 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
251 | |||
252 | /* Maximum number of functions to trace before diagnosing a hang */ | ||
253 | #define GRAPH_MAX_FUNC_TEST 100000000 | ||
254 | |||
255 | static void __ftrace_dump(bool disable_tracing); | ||
256 | static unsigned int graph_hang_thresh; | ||
257 | |||
258 | /* Wrap the real function entry probe to avoid possible hanging */ | ||
259 | static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace) | ||
260 | { | ||
261 | /* This is harmlessly racy, we want to approximately detect a hang */ | ||
262 | if (unlikely(++graph_hang_thresh > GRAPH_MAX_FUNC_TEST)) { | ||
263 | ftrace_graph_stop(); | ||
264 | printk(KERN_WARNING "BUG: Function graph tracer hang!\n"); | ||
265 | if (ftrace_dump_on_oops) | ||
266 | __ftrace_dump(false); | ||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | return trace_graph_entry(trace); | ||
271 | } | ||
272 | |||
251 | /* | 273 | /* |
252 | * Pretty much the same than for the function tracer from which the selftest | 274 | * Pretty much the same than for the function tracer from which the selftest |
253 | * has been borrowed. | 275 | * has been borrowed. |
@@ -259,15 +281,29 @@ trace_selftest_startup_function_graph(struct tracer *trace, | |||
259 | int ret; | 281 | int ret; |
260 | unsigned long count; | 282 | unsigned long count; |
261 | 283 | ||
262 | ret = tracer_init(trace, tr); | 284 | /* |
285 | * Simulate the init() callback but we attach a watchdog callback | ||
286 | * to detect and recover from possible hangs | ||
287 | */ | ||
288 | tracing_reset_online_cpus(tr); | ||
289 | ret = register_ftrace_graph(&trace_graph_return, | ||
290 | &trace_graph_entry_watchdog); | ||
263 | if (ret) { | 291 | if (ret) { |
264 | warn_failed_init_tracer(trace, ret); | 292 | warn_failed_init_tracer(trace, ret); |
265 | goto out; | 293 | goto out; |
266 | } | 294 | } |
295 | tracing_start_cmdline_record(); | ||
267 | 296 | ||
268 | /* Sleep for a 1/10 of a second */ | 297 | /* Sleep for a 1/10 of a second */ |
269 | msleep(100); | 298 | msleep(100); |
270 | 299 | ||
300 | /* Have we just recovered from a hang? */ | ||
301 | if (graph_hang_thresh > GRAPH_MAX_FUNC_TEST) { | ||
302 | tracing_selftest_disabled = true; | ||
303 | ret = -1; | ||
304 | goto out; | ||
305 | } | ||
306 | |||
271 | tracing_stop(); | 307 | tracing_stop(); |
272 | 308 | ||
273 | /* check the trace buffer */ | 309 | /* check the trace buffer */ |
diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c index 39310e3434ee..acdebd771a93 100644 --- a/kernel/trace/trace_stat.c +++ b/kernel/trace/trace_stat.c | |||
@@ -75,7 +75,7 @@ static int stat_seq_init(struct tracer_stat_session *session) | |||
75 | { | 75 | { |
76 | struct trace_stat_list *iter_entry, *new_entry; | 76 | struct trace_stat_list *iter_entry, *new_entry; |
77 | struct tracer_stat *ts = session->ts; | 77 | struct tracer_stat *ts = session->ts; |
78 | void *prev_stat; | 78 | void *stat; |
79 | int ret = 0; | 79 | int ret = 0; |
80 | int i; | 80 | int i; |
81 | 81 | ||
@@ -85,6 +85,10 @@ static int stat_seq_init(struct tracer_stat_session *session) | |||
85 | if (!ts->stat_cmp) | 85 | if (!ts->stat_cmp) |
86 | ts->stat_cmp = dummy_cmp; | 86 | ts->stat_cmp = dummy_cmp; |
87 | 87 | ||
88 | stat = ts->stat_start(); | ||
89 | if (!stat) | ||
90 | goto exit; | ||
91 | |||
88 | /* | 92 | /* |
89 | * The first entry. Actually this is the second, but the first | 93 | * The first entry. Actually this is the second, but the first |
90 | * one (the stat_list head) is pointless. | 94 | * one (the stat_list head) is pointless. |
@@ -99,14 +103,19 @@ static int stat_seq_init(struct tracer_stat_session *session) | |||
99 | 103 | ||
100 | list_add(&new_entry->list, &session->stat_list); | 104 | list_add(&new_entry->list, &session->stat_list); |
101 | 105 | ||
102 | new_entry->stat = ts->stat_start(); | 106 | new_entry->stat = stat; |
103 | prev_stat = new_entry->stat; | ||
104 | 107 | ||
105 | /* | 108 | /* |
106 | * Iterate over the tracer stat entries and store them in a sorted | 109 | * Iterate over the tracer stat entries and store them in a sorted |
107 | * list. | 110 | * list. |
108 | */ | 111 | */ |
109 | for (i = 1; ; i++) { | 112 | for (i = 1; ; i++) { |
113 | stat = ts->stat_next(stat, i); | ||
114 | |||
115 | /* End of insertion */ | ||
116 | if (!stat) | ||
117 | break; | ||
118 | |||
110 | new_entry = kmalloc(sizeof(struct trace_stat_list), GFP_KERNEL); | 119 | new_entry = kmalloc(sizeof(struct trace_stat_list), GFP_KERNEL); |
111 | if (!new_entry) { | 120 | if (!new_entry) { |
112 | ret = -ENOMEM; | 121 | ret = -ENOMEM; |
@@ -114,31 +123,23 @@ static int stat_seq_init(struct tracer_stat_session *session) | |||
114 | } | 123 | } |
115 | 124 | ||
116 | INIT_LIST_HEAD(&new_entry->list); | 125 | INIT_LIST_HEAD(&new_entry->list); |
117 | new_entry->stat = ts->stat_next(prev_stat, i); | 126 | new_entry->stat = stat; |
118 | 127 | ||
119 | /* End of insertion */ | 128 | list_for_each_entry_reverse(iter_entry, &session->stat_list, |
120 | if (!new_entry->stat) | 129 | list) { |
121 | break; | ||
122 | |||
123 | list_for_each_entry(iter_entry, &session->stat_list, list) { | ||
124 | 130 | ||
125 | /* Insertion with a descendent sorting */ | 131 | /* Insertion with a descendent sorting */ |
126 | if (ts->stat_cmp(new_entry->stat, | 132 | if (ts->stat_cmp(iter_entry->stat, |
127 | iter_entry->stat) > 0) { | 133 | new_entry->stat) >= 0) { |
128 | |||
129 | list_add_tail(&new_entry->list, | ||
130 | &iter_entry->list); | ||
131 | break; | ||
132 | 134 | ||
133 | /* The current smaller value */ | ||
134 | } else if (list_is_last(&iter_entry->list, | ||
135 | &session->stat_list)) { | ||
136 | list_add(&new_entry->list, &iter_entry->list); | 135 | list_add(&new_entry->list, &iter_entry->list); |
137 | break; | 136 | break; |
138 | } | 137 | } |
139 | } | 138 | } |
140 | 139 | ||
141 | prev_stat = new_entry->stat; | 140 | /* The current larger value */ |
141 | if (list_empty(&new_entry->list)) | ||
142 | list_add(&new_entry->list, &session->stat_list); | ||
142 | } | 143 | } |
143 | exit: | 144 | exit: |
144 | mutex_unlock(&session->stat_mutex); | 145 | mutex_unlock(&session->stat_mutex); |
@@ -160,7 +161,7 @@ static void *stat_seq_start(struct seq_file *s, loff_t *pos) | |||
160 | 161 | ||
161 | /* If we are in the beginning of the file, print the headers */ | 162 | /* If we are in the beginning of the file, print the headers */ |
162 | if (!*pos && session->ts->stat_headers) | 163 | if (!*pos && session->ts->stat_headers) |
163 | session->ts->stat_headers(s); | 164 | return SEQ_START_TOKEN; |
164 | 165 | ||
165 | return seq_list_start(&session->stat_list, *pos); | 166 | return seq_list_start(&session->stat_list, *pos); |
166 | } | 167 | } |
@@ -169,6 +170,9 @@ static void *stat_seq_next(struct seq_file *s, void *p, loff_t *pos) | |||
169 | { | 170 | { |
170 | struct tracer_stat_session *session = s->private; | 171 | struct tracer_stat_session *session = s->private; |
171 | 172 | ||
173 | if (p == SEQ_START_TOKEN) | ||
174 | return seq_list_start(&session->stat_list, *pos); | ||
175 | |||
172 | return seq_list_next(p, &session->stat_list, pos); | 176 | return seq_list_next(p, &session->stat_list, pos); |
173 | } | 177 | } |
174 | 178 | ||
@@ -183,6 +187,9 @@ static int stat_seq_show(struct seq_file *s, void *v) | |||
183 | struct tracer_stat_session *session = s->private; | 187 | struct tracer_stat_session *session = s->private; |
184 | struct trace_stat_list *l = list_entry(v, struct trace_stat_list, list); | 188 | struct trace_stat_list *l = list_entry(v, struct trace_stat_list, list); |
185 | 189 | ||
190 | if (v == SEQ_START_TOKEN) | ||
191 | return session->ts->stat_headers(s); | ||
192 | |||
186 | return session->ts->stat_show(s, l->stat); | 193 | return session->ts->stat_show(s, l->stat); |
187 | } | 194 | } |
188 | 195 | ||
diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c index 9ab035b58cf1..797201e4a137 100644 --- a/kernel/trace/trace_workqueue.c +++ b/kernel/trace/trace_workqueue.c | |||
@@ -196,6 +196,11 @@ static int workqueue_stat_show(struct seq_file *s, void *p) | |||
196 | struct pid *pid; | 196 | struct pid *pid; |
197 | struct task_struct *tsk; | 197 | struct task_struct *tsk; |
198 | 198 | ||
199 | spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags); | ||
200 | if (&cws->list == workqueue_cpu_stat(cpu)->list.next) | ||
201 | seq_printf(s, "\n"); | ||
202 | spin_unlock_irqrestore(&workqueue_cpu_stat(cpu)->lock, flags); | ||
203 | |||
199 | pid = find_get_pid(cws->pid); | 204 | pid = find_get_pid(cws->pid); |
200 | if (pid) { | 205 | if (pid) { |
201 | tsk = get_pid_task(pid, PIDTYPE_PID); | 206 | tsk = get_pid_task(pid, PIDTYPE_PID); |
@@ -208,18 +213,13 @@ static int workqueue_stat_show(struct seq_file *s, void *p) | |||
208 | put_pid(pid); | 213 | put_pid(pid); |
209 | } | 214 | } |
210 | 215 | ||
211 | spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags); | ||
212 | if (&cws->list == workqueue_cpu_stat(cpu)->list.next) | ||
213 | seq_printf(s, "\n"); | ||
214 | spin_unlock_irqrestore(&workqueue_cpu_stat(cpu)->lock, flags); | ||
215 | |||
216 | return 0; | 216 | return 0; |
217 | } | 217 | } |
218 | 218 | ||
219 | static int workqueue_stat_headers(struct seq_file *s) | 219 | static int workqueue_stat_headers(struct seq_file *s) |
220 | { | 220 | { |
221 | seq_printf(s, "# CPU INSERTED EXECUTED NAME\n"); | 221 | seq_printf(s, "# CPU INSERTED EXECUTED NAME\n"); |
222 | seq_printf(s, "# | | | |\n\n"); | 222 | seq_printf(s, "# | | | |\n"); |
223 | return 0; | 223 | return 0; |
224 | } | 224 | } |
225 | 225 | ||
diff --git a/mm/memory.c b/mm/memory.c index 05fab3bc5b4b..baa999e87cd2 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
@@ -48,8 +48,6 @@ | |||
48 | #include <linux/rmap.h> | 48 | #include <linux/rmap.h> |
49 | #include <linux/module.h> | 49 | #include <linux/module.h> |
50 | #include <linux/delayacct.h> | 50 | #include <linux/delayacct.h> |
51 | #include <linux/kprobes.h> | ||
52 | #include <linux/mutex.h> | ||
53 | #include <linux/init.h> | 51 | #include <linux/init.h> |
54 | #include <linux/writeback.h> | 52 | #include <linux/writeback.h> |
55 | #include <linux/memcontrol.h> | 53 | #include <linux/memcontrol.h> |
@@ -101,14 +99,6 @@ int randomize_va_space __read_mostly = | |||
101 | 2; | 99 | 2; |
102 | #endif | 100 | #endif |
103 | 101 | ||
104 | /* | ||
105 | * mutex protecting text section modification (dynamic code patching). | ||
106 | * some users need to sleep (allocating memory...) while they hold this lock. | ||
107 | * | ||
108 | * NOT exported to modules - patching kernel text is a really delicate matter. | ||
109 | */ | ||
110 | DEFINE_MUTEX(text_mutex); | ||
111 | |||
112 | static int __init disable_randmaps(char *s) | 102 | static int __init disable_randmaps(char *s) |
113 | { | 103 | { |
114 | randomize_va_space = 0; | 104 | randomize_va_space = 0; |
diff --git a/samples/tracepoints/tracepoint-sample.c b/samples/tracepoints/tracepoint-sample.c index 68d5dc0310e4..9cf80a11e8b6 100644 --- a/samples/tracepoints/tracepoint-sample.c +++ b/samples/tracepoints/tracepoint-sample.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* tracepoint-sample.c | 1 | /* tracepoint-sample.c |
2 | * | 2 | * |
3 | * Executes a tracepoint when /proc/tracepoint-example is opened. | 3 | * Executes a tracepoint when /proc/tracepoint-sample is opened. |
4 | * | 4 | * |
5 | * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | 5 | * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> |
6 | * | 6 | * |
@@ -16,7 +16,7 @@ | |||
16 | DEFINE_TRACE(subsys_event); | 16 | DEFINE_TRACE(subsys_event); |
17 | DEFINE_TRACE(subsys_eventb); | 17 | DEFINE_TRACE(subsys_eventb); |
18 | 18 | ||
19 | struct proc_dir_entry *pentry_example; | 19 | struct proc_dir_entry *pentry_sample; |
20 | 20 | ||
21 | static int my_open(struct inode *inode, struct file *file) | 21 | static int my_open(struct inode *inode, struct file *file) |
22 | { | 22 | { |
@@ -32,25 +32,25 @@ static struct file_operations mark_ops = { | |||
32 | .open = my_open, | 32 | .open = my_open, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | static int __init example_init(void) | 35 | static int __init sample_init(void) |
36 | { | 36 | { |
37 | printk(KERN_ALERT "example init\n"); | 37 | printk(KERN_ALERT "sample init\n"); |
38 | pentry_example = proc_create("tracepoint-example", 0444, NULL, | 38 | pentry_sample = proc_create("tracepoint-sample", 0444, NULL, |
39 | &mark_ops); | 39 | &mark_ops); |
40 | if (!pentry_example) | 40 | if (!pentry_sample) |
41 | return -EPERM; | 41 | return -EPERM; |
42 | return 0; | 42 | return 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | static void __exit example_exit(void) | 45 | static void __exit sample_exit(void) |
46 | { | 46 | { |
47 | printk(KERN_ALERT "example exit\n"); | 47 | printk(KERN_ALERT "sample exit\n"); |
48 | remove_proc_entry("tracepoint-example", NULL); | 48 | remove_proc_entry("tracepoint-sample", NULL); |
49 | } | 49 | } |
50 | 50 | ||
51 | module_init(example_init) | 51 | module_init(sample_init) |
52 | module_exit(example_exit) | 52 | module_exit(sample_exit) |
53 | 53 | ||
54 | MODULE_LICENSE("GPL"); | 54 | MODULE_LICENSE("GPL"); |
55 | MODULE_AUTHOR("Mathieu Desnoyers"); | 55 | MODULE_AUTHOR("Mathieu Desnoyers"); |
56 | MODULE_DESCRIPTION("Tracepoint example"); | 56 | MODULE_DESCRIPTION("Tracepoint sample"); |