aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-11-06 16:30:20 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-06 16:30:20 -0500
commit22402cd0af685c1a5d067c87db3051db7fff7709 (patch)
tree4f06ef31f643be28f3d4c92821df36b8ff321d9b
parent7c623cac4939fb36916c029609dd22e3dec0a014 (diff)
parentd227c3ae4e94e5eb11dd780a811f59e1a7b74ccd (diff)
Merge tag 'trace-v4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracking updates from Steven Rostedt: "Most of the changes are clean ups and small fixes. Some of them have stable tags to them. I searched through my INBOX just as the merge window opened and found lots of patches to pull. I ran them through all my tests and they were in linux-next for a few days. Features added this release: ---------------------------- - Module globbing. You can now filter function tracing to several modules. # echo '*:mod:*snd*' > set_ftrace_filter (Dmitry Safonov) - Tracer specific options are now visible even when the tracer is not active. It was rather annoying that you can only see and modify tracer options after enabling the tracer. Now they are in the options/ directory even when the tracer is not active. Although they are still only visible when the tracer is active in the trace_options file. - Trace options are now per instance (although some of the tracer specific options are global) - New tracefs file: set_event_pid. If any pid is added to this file, then all events in the instance will filter out events that are not part of this pid. sched_switch and sched_wakeup events handle next and the wakee pids" * tag 'trace-v4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (68 commits) tracefs: Fix refcount imbalance in start_creating() tracing: Put back comma for empty fields in boot string parsing tracing: Apply tracer specific options from kernel command line. tracing: Add some documentation about set_event_pid ring_buffer: Remove unneeded smp_wmb() before wakeup of reader benchmark tracing: Allow dumping traces without tracking trace started cpus ring_buffer: Fix more races when terminating the producer in the benchmark ring_buffer: Do no not complete benchmark reader too early tracing: Remove redundant TP_ARGS redefining tracing: Rename max_stack_lock to stack_trace_max_lock tracing: Allow arch-specific stack tracer recordmcount: arm64: Replace the ignored mcount call into nop recordmcount: Fix endianness handling bug for nop_mcount tracepoints: Fix documentation of RCU lockdep checks tracing: ftrace_event_is_function() can return boolean tracing: is_legal_op() can return boolean ring-buffer: rb_event_is_commit() can return boolean ring-buffer: rb_per_cpu_empty() can return boolean ring_buffer: ring_buffer_empty{cpu}() can return boolean ring-buffer: rb_is_reader_page() can return boolean ...
-rw-r--r--Documentation/trace/events.txt18
-rw-r--r--Documentation/trace/ftrace.txt23
-rw-r--r--arch/x86/kernel/ftrace.c4
-rw-r--r--fs/tracefs/inode.c6
-rw-r--r--include/linux/ftrace.h11
-rw-r--r--include/linux/ring_buffer.h4
-rw-r--r--include/linux/trace_events.h20
-rw-r--r--include/linux/tracepoint.h39
-rw-r--r--include/trace/define_trace.h2
-rw-r--r--include/trace/events/gpio.h4
-rw-r--r--include/trace/perf.h258
-rw-r--r--include/trace/trace_events.h258
-rw-r--r--kernel/trace/Kconfig7
-rw-r--r--kernel/trace/blktrace.c11
-rw-r--r--kernel/trace/ftrace.c197
-rw-r--r--kernel/trace/ring_buffer.c20
-rw-r--r--kernel/trace/ring_buffer_benchmark.c79
-rw-r--r--kernel/trace/trace.c454
-rw-r--r--kernel/trace/trace.h168
-rw-r--r--kernel/trace/trace_benchmark.c2
-rw-r--r--kernel/trace/trace_branch.c15
-rw-r--r--kernel/trace/trace_events.c506
-rw-r--r--kernel/trace/trace_events_filter.c8
-rw-r--r--kernel/trace/trace_export.c2
-rw-r--r--kernel/trace/trace_functions_graph.c63
-rw-r--r--kernel/trace/trace_irqsoff.c106
-rw-r--r--kernel/trace/trace_kdb.c8
-rw-r--r--kernel/trace/trace_mmiotrace.c4
-rw-r--r--kernel/trace/trace_output.c97
-rw-r--r--kernel/trace/trace_output.h4
-rw-r--r--kernel/trace/trace_printk.c14
-rw-r--r--kernel/trace/trace_probe.h8
-rw-r--r--kernel/trace/trace_sched_wakeup.c120
-rw-r--r--kernel/trace/trace_stack.c92
-rw-r--r--kernel/trace/trace_syscalls.c3
-rw-r--r--kernel/tracepoint.c61
-rw-r--r--samples/trace_events/trace-events-sample.h6
-rw-r--r--scripts/recordmcount.c26
-rw-r--r--scripts/recordmcount.h2
39 files changed, 1787 insertions, 943 deletions
diff --git a/Documentation/trace/events.txt b/Documentation/trace/events.txt
index 75d25a1d6e42..c010be8c85d7 100644
--- a/Documentation/trace/events.txt
+++ b/Documentation/trace/events.txt
@@ -288,6 +288,24 @@ prev_pid == 0
288# cat sched_wakeup/filter 288# cat sched_wakeup/filter
289common_pid == 0 289common_pid == 0
290 290
2915.4 PID filtering
292-----------------
293
294The set_event_pid file in the same directory as the top events directory
295exists, will filter all events from tracing any task that does not have the
296PID listed in the set_event_pid file.
297
298# cd /sys/kernel/debug/tracing
299# echo $$ > set_event_pid
300# echo 1 > events/enabled
301
302Will only trace events for the current task.
303
304To add more PIDs without losing the PIDs already included, use '>>'.
305
306# echo 123 244 1 >> set_event_pid
307
308
2916. Event triggers 3096. Event triggers
292================= 310=================
293 311
diff --git a/Documentation/trace/ftrace.txt b/Documentation/trace/ftrace.txt
index ef621d34ba5b..f52f297cb406 100644
--- a/Documentation/trace/ftrace.txt
+++ b/Documentation/trace/ftrace.txt
@@ -204,6 +204,12 @@ of ftrace. Here is a list of some of the key files:
204 204
205 Have the function tracer only trace a single thread. 205 Have the function tracer only trace a single thread.
206 206
207 set_event_pid:
208
209 Have the events only trace a task with a PID listed in this file.
210 Note, sched_switch and sched_wake_up will also trace events
211 listed in this file.
212
207 set_graph_function: 213 set_graph_function:
208 214
209 Set a "trigger" function where tracing should start 215 Set a "trigger" function where tracing should start
@@ -2437,6 +2443,23 @@ The following commands are supported:
2437 2443
2438 echo '!writeback*:mod:ext3' >> set_ftrace_filter 2444 echo '!writeback*:mod:ext3' >> set_ftrace_filter
2439 2445
2446 Mod command supports module globbing. Disable tracing for all
2447 functions except a specific module:
2448
2449 echo '!*:mod:!ext3' >> set_ftrace_filter
2450
2451 Disable tracing for all modules, but still trace kernel:
2452
2453 echo '!*:mod:*' >> set_ftrace_filter
2454
2455 Enable filter only for kernel:
2456
2457 echo '*write*:mod:!*' >> set_ftrace_filter
2458
2459 Enable filter for module globbing:
2460
2461 echo '*write*:mod:*snd*' >> set_ftrace_filter
2462
2440- traceon/traceoff 2463- traceon/traceoff
2441 These commands turn tracing on and off when the specified 2464 These commands turn tracing on and off when the specified
2442 functions are hit. The parameter determines how many times the 2465 functions are hit. The parameter determines how many times the
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 8b7b0a51e742..311bcf338f07 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -556,6 +556,7 @@ void ftrace_replace_code(int enable)
556 run_sync(); 556 run_sync();
557 557
558 report = "updating code"; 558 report = "updating code";
559 count = 0;
559 560
560 for_ftrace_rec_iter(iter) { 561 for_ftrace_rec_iter(iter) {
561 rec = ftrace_rec_iter_record(iter); 562 rec = ftrace_rec_iter_record(iter);
@@ -563,11 +564,13 @@ void ftrace_replace_code(int enable)
563 ret = add_update(rec, enable); 564 ret = add_update(rec, enable);
564 if (ret) 565 if (ret)
565 goto remove_breakpoints; 566 goto remove_breakpoints;
567 count++;
566 } 568 }
567 569
568 run_sync(); 570 run_sync();
569 571
570 report = "removing breakpoints"; 572 report = "removing breakpoints";
573 count = 0;
571 574
572 for_ftrace_rec_iter(iter) { 575 for_ftrace_rec_iter(iter) {
573 rec = ftrace_rec_iter_record(iter); 576 rec = ftrace_rec_iter_record(iter);
@@ -575,6 +578,7 @@ void ftrace_replace_code(int enable)
575 ret = finish_update(rec, enable); 578 ret = finish_update(rec, enable);
576 if (ret) 579 if (ret)
577 goto remove_breakpoints; 580 goto remove_breakpoints;
581 count++;
578 } 582 }
579 583
580 run_sync(); 584 run_sync();
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index cbc8d5d2755a..c66f2423e1f5 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -340,8 +340,12 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)
340 dput(dentry); 340 dput(dentry);
341 dentry = ERR_PTR(-EEXIST); 341 dentry = ERR_PTR(-EEXIST);
342 } 342 }
343 if (IS_ERR(dentry)) 343
344 if (IS_ERR(dentry)) {
344 mutex_unlock(&parent->d_inode->i_mutex); 345 mutex_unlock(&parent->d_inode->i_mutex);
346 simple_release_fs(&tracefs_mount, &tracefs_mount_count);
347 }
348
345 return dentry; 349 return dentry;
346} 350}
347 351
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 6cd8c0ee4b6f..eae6548efbf0 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -263,7 +263,18 @@ static inline void ftrace_kill(void) { }
263#endif /* CONFIG_FUNCTION_TRACER */ 263#endif /* CONFIG_FUNCTION_TRACER */
264 264
265#ifdef CONFIG_STACK_TRACER 265#ifdef CONFIG_STACK_TRACER
266
267#define STACK_TRACE_ENTRIES 500
268
269struct stack_trace;
270
271extern unsigned stack_trace_index[];
272extern struct stack_trace stack_trace_max;
273extern unsigned long stack_trace_max_size;
274extern arch_spinlock_t stack_trace_max_lock;
275
266extern int stack_tracer_enabled; 276extern int stack_tracer_enabled;
277void stack_trace_print(void);
267int 278int
268stack_trace_sysctl(struct ctl_table *table, int write, 279stack_trace_sysctl(struct ctl_table *table, int write,
269 void __user *buffer, size_t *lenp, 280 void __user *buffer, size_t *lenp,
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index e2c13cd863bd..4acc552e9279 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -154,8 +154,8 @@ ring_buffer_swap_cpu(struct ring_buffer *buffer_a,
154} 154}
155#endif 155#endif
156 156
157int ring_buffer_empty(struct ring_buffer *buffer); 157bool ring_buffer_empty(struct ring_buffer *buffer);
158int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu); 158bool ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu);
159 159
160void ring_buffer_record_disable(struct ring_buffer *buffer); 160void ring_buffer_record_disable(struct ring_buffer *buffer);
161void ring_buffer_record_enable(struct ring_buffer *buffer); 161void ring_buffer_record_enable(struct ring_buffer *buffer);
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index ed27917cabc9..429fdfc3baf5 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -168,13 +168,12 @@ struct ring_buffer_event *
168trace_current_buffer_lock_reserve(struct ring_buffer **current_buffer, 168trace_current_buffer_lock_reserve(struct ring_buffer **current_buffer,
169 int type, unsigned long len, 169 int type, unsigned long len,
170 unsigned long flags, int pc); 170 unsigned long flags, int pc);
171void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, 171void trace_buffer_unlock_commit(struct trace_array *tr,
172 struct ring_buffer_event *event, 172 struct ring_buffer *buffer,
173 unsigned long flags, int pc);
174void trace_buffer_unlock_commit(struct ring_buffer *buffer,
175 struct ring_buffer_event *event, 173 struct ring_buffer_event *event,
176 unsigned long flags, int pc); 174 unsigned long flags, int pc);
177void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer, 175void trace_buffer_unlock_commit_regs(struct trace_array *tr,
176 struct ring_buffer *buffer,
178 struct ring_buffer_event *event, 177 struct ring_buffer_event *event,
179 unsigned long flags, int pc, 178 unsigned long flags, int pc,
180 struct pt_regs *regs); 179 struct pt_regs *regs);
@@ -329,6 +328,7 @@ enum {
329 EVENT_FILE_FL_SOFT_DISABLED_BIT, 328 EVENT_FILE_FL_SOFT_DISABLED_BIT,
330 EVENT_FILE_FL_TRIGGER_MODE_BIT, 329 EVENT_FILE_FL_TRIGGER_MODE_BIT,
331 EVENT_FILE_FL_TRIGGER_COND_BIT, 330 EVENT_FILE_FL_TRIGGER_COND_BIT,
331 EVENT_FILE_FL_PID_FILTER_BIT,
332}; 332};
333 333
334/* 334/*
@@ -342,6 +342,7 @@ enum {
342 * tracepoint may be enabled) 342 * tracepoint may be enabled)
343 * TRIGGER_MODE - When set, invoke the triggers associated with the event 343 * TRIGGER_MODE - When set, invoke the triggers associated with the event
344 * TRIGGER_COND - When set, one or more triggers has an associated filter 344 * TRIGGER_COND - When set, one or more triggers has an associated filter
345 * PID_FILTER - When set, the event is filtered based on pid
345 */ 346 */
346enum { 347enum {
347 EVENT_FILE_FL_ENABLED = (1 << EVENT_FILE_FL_ENABLED_BIT), 348 EVENT_FILE_FL_ENABLED = (1 << EVENT_FILE_FL_ENABLED_BIT),
@@ -352,6 +353,7 @@ enum {
352 EVENT_FILE_FL_SOFT_DISABLED = (1 << EVENT_FILE_FL_SOFT_DISABLED_BIT), 353 EVENT_FILE_FL_SOFT_DISABLED = (1 << EVENT_FILE_FL_SOFT_DISABLED_BIT),
353 EVENT_FILE_FL_TRIGGER_MODE = (1 << EVENT_FILE_FL_TRIGGER_MODE_BIT), 354 EVENT_FILE_FL_TRIGGER_MODE = (1 << EVENT_FILE_FL_TRIGGER_MODE_BIT),
354 EVENT_FILE_FL_TRIGGER_COND = (1 << EVENT_FILE_FL_TRIGGER_COND_BIT), 355 EVENT_FILE_FL_TRIGGER_COND = (1 << EVENT_FILE_FL_TRIGGER_COND_BIT),
356 EVENT_FILE_FL_PID_FILTER = (1 << EVENT_FILE_FL_PID_FILTER_BIT),
355}; 357};
356 358
357struct trace_event_file { 359struct trace_event_file {
@@ -430,6 +432,8 @@ extern enum event_trigger_type event_triggers_call(struct trace_event_file *file
430extern void event_triggers_post_call(struct trace_event_file *file, 432extern void event_triggers_post_call(struct trace_event_file *file,
431 enum event_trigger_type tt); 433 enum event_trigger_type tt);
432 434
435bool trace_event_ignore_this_pid(struct trace_event_file *trace_file);
436
433/** 437/**
434 * trace_trigger_soft_disabled - do triggers and test if soft disabled 438 * trace_trigger_soft_disabled - do triggers and test if soft disabled
435 * @file: The file pointer of the event to test 439 * @file: The file pointer of the event to test
@@ -449,6 +453,8 @@ trace_trigger_soft_disabled(struct trace_event_file *file)
449 event_triggers_call(file, NULL); 453 event_triggers_call(file, NULL);
450 if (eflags & EVENT_FILE_FL_SOFT_DISABLED) 454 if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
451 return true; 455 return true;
456 if (eflags & EVENT_FILE_FL_PID_FILTER)
457 return trace_event_ignore_this_pid(file);
452 } 458 }
453 return false; 459 return false;
454} 460}
@@ -508,7 +514,7 @@ event_trigger_unlock_commit(struct trace_event_file *file,
508 enum event_trigger_type tt = ETT_NONE; 514 enum event_trigger_type tt = ETT_NONE;
509 515
510 if (!__event_trigger_test_discard(file, buffer, event, entry, &tt)) 516 if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
511 trace_buffer_unlock_commit(buffer, event, irq_flags, pc); 517 trace_buffer_unlock_commit(file->tr, buffer, event, irq_flags, pc);
512 518
513 if (tt) 519 if (tt)
514 event_triggers_post_call(file, tt); 520 event_triggers_post_call(file, tt);
@@ -540,7 +546,7 @@ event_trigger_unlock_commit_regs(struct trace_event_file *file,
540 enum event_trigger_type tt = ETT_NONE; 546 enum event_trigger_type tt = ETT_NONE;
541 547
542 if (!__event_trigger_test_discard(file, buffer, event, entry, &tt)) 548 if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
543 trace_buffer_unlock_commit_regs(buffer, event, 549 trace_buffer_unlock_commit_regs(file->tr, buffer, event,
544 irq_flags, pc, regs); 550 irq_flags, pc, regs);
545 551
546 if (tt) 552 if (tt)
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index a5f7f3ecafa3..696a339c592c 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -26,6 +26,7 @@ struct notifier_block;
26struct tracepoint_func { 26struct tracepoint_func {
27 void *func; 27 void *func;
28 void *data; 28 void *data;
29 int prio;
29}; 30};
30 31
31struct tracepoint { 32struct tracepoint {
@@ -42,9 +43,14 @@ struct trace_enum_map {
42 unsigned long enum_value; 43 unsigned long enum_value;
43}; 44};
44 45
46#define TRACEPOINT_DEFAULT_PRIO 10
47
45extern int 48extern int
46tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data); 49tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
47extern int 50extern int
51tracepoint_probe_register_prio(struct tracepoint *tp, void *probe, void *data,
52 int prio);
53extern int
48tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data); 54tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data);
49extern void 55extern void
50for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), 56for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
@@ -111,7 +117,18 @@ extern void syscall_unregfunc(void);
111#define TP_ARGS(args...) args 117#define TP_ARGS(args...) args
112#define TP_CONDITION(args...) args 118#define TP_CONDITION(args...) args
113 119
114#ifdef CONFIG_TRACEPOINTS 120/*
121 * Individual subsystem my have a separate configuration to
122 * enable their tracepoints. By default, this file will create
123 * the tracepoints if CONFIG_TRACEPOINT is defined. If a subsystem
124 * wants to be able to disable its tracepoints from being created
125 * it can define NOTRACE before including the tracepoint headers.
126 */
127#if defined(CONFIG_TRACEPOINTS) && !defined(NOTRACE)
128#define TRACEPOINTS_ENABLED
129#endif
130
131#ifdef TRACEPOINTS_ENABLED
115 132
116/* 133/*
117 * it_func[0] is never NULL because there is at least one element in the array 134 * it_func[0] is never NULL because there is at least one element in the array
@@ -167,10 +184,11 @@ extern void syscall_unregfunc(void);
167 * structure. Force alignment to the same alignment as the section start. 184 * structure. Force alignment to the same alignment as the section start.
168 * 185 *
169 * When lockdep is enabled, we make sure to always do the RCU portions of 186 * When lockdep is enabled, we make sure to always do the RCU portions of
170 * the tracepoint code, regardless of whether tracing is on or we match the 187 * the tracepoint code, regardless of whether tracing is on. However,
171 * condition. This lets us find RCU issues triggered with tracepoints even 188 * don't check if the condition is false, due to interaction with idle
172 * when this tracepoint is off. This code has no purpose other than poking 189 * instrumentation. This lets us find RCU issues triggered with tracepoints
173 * RCU a bit. 190 * even when this tracepoint is off. This code has no purpose other than
191 * poking RCU a bit.
174 */ 192 */
175#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \ 193#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
176 extern struct tracepoint __tracepoint_##name; \ 194 extern struct tracepoint __tracepoint_##name; \
@@ -196,6 +214,13 @@ extern void syscall_unregfunc(void);
196 (void *)probe, data); \ 214 (void *)probe, data); \
197 } \ 215 } \
198 static inline int \ 216 static inline int \
217 register_trace_prio_##name(void (*probe)(data_proto), void *data,\
218 int prio) \
219 { \
220 return tracepoint_probe_register_prio(&__tracepoint_##name, \
221 (void *)probe, data, prio); \
222 } \
223 static inline int \
199 unregister_trace_##name(void (*probe)(data_proto), void *data) \ 224 unregister_trace_##name(void (*probe)(data_proto), void *data) \
200 { \ 225 { \
201 return tracepoint_probe_unregister(&__tracepoint_##name,\ 226 return tracepoint_probe_unregister(&__tracepoint_##name,\
@@ -234,7 +259,7 @@ extern void syscall_unregfunc(void);
234#define EXPORT_TRACEPOINT_SYMBOL(name) \ 259#define EXPORT_TRACEPOINT_SYMBOL(name) \
235 EXPORT_SYMBOL(__tracepoint_##name) 260 EXPORT_SYMBOL(__tracepoint_##name)
236 261
237#else /* !CONFIG_TRACEPOINTS */ 262#else /* !TRACEPOINTS_ENABLED */
238#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \ 263#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
239 static inline void trace_##name(proto) \ 264 static inline void trace_##name(proto) \
240 { } \ 265 { } \
@@ -266,7 +291,7 @@ extern void syscall_unregfunc(void);
266#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) 291#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
267#define EXPORT_TRACEPOINT_SYMBOL(name) 292#define EXPORT_TRACEPOINT_SYMBOL(name)
268 293
269#endif /* CONFIG_TRACEPOINTS */ 294#endif /* TRACEPOINTS_ENABLED */
270 295
271#ifdef CONFIG_TRACING 296#ifdef CONFIG_TRACING
272/** 297/**
diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h
index 09b3880105a9..2d8639ea64d5 100644
--- a/include/trace/define_trace.h
+++ b/include/trace/define_trace.h
@@ -86,7 +86,7 @@
86#undef DECLARE_TRACE 86#undef DECLARE_TRACE
87#define DECLARE_TRACE(name, proto, args) 87#define DECLARE_TRACE(name, proto, args)
88 88
89#ifdef CONFIG_EVENT_TRACING 89#ifdef TRACEPOINTS_ENABLED
90#include <trace/trace_events.h> 90#include <trace/trace_events.h>
91#include <trace/perf.h> 91#include <trace/perf.h>
92#endif 92#endif
diff --git a/include/trace/events/gpio.h b/include/trace/events/gpio.h
index 927a8ad9e51b..2da73b92d47e 100644
--- a/include/trace/events/gpio.h
+++ b/include/trace/events/gpio.h
@@ -1,6 +1,10 @@
1#undef TRACE_SYSTEM 1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM gpio 2#define TRACE_SYSTEM gpio
3 3
4#ifndef CONFIG_TRACING_EVENTS_GPIO
5#define NOTRACE
6#endif
7
4#if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ) 8#if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_GPIO_H 9#define _TRACE_GPIO_H
6 10
diff --git a/include/trace/perf.h b/include/trace/perf.h
index 1b5443cebedc..26486fcd74ce 100644
--- a/include/trace/perf.h
+++ b/include/trace/perf.h
@@ -1,261 +1,3 @@
1/*
2 * Stage 4 of the trace events.
3 *
4 * Override the macros in <trace/trace_events.h> to include the following:
5 *
6 * For those macros defined with TRACE_EVENT:
7 *
8 * static struct trace_event_call event_<call>;
9 *
10 * static void trace_event_raw_event_<call>(void *__data, proto)
11 * {
12 * struct trace_event_file *trace_file = __data;
13 * struct trace_event_call *event_call = trace_file->event_call;
14 * struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
15 * unsigned long eflags = trace_file->flags;
16 * enum event_trigger_type __tt = ETT_NONE;
17 * struct ring_buffer_event *event;
18 * struct trace_event_raw_<call> *entry; <-- defined in stage 1
19 * struct ring_buffer *buffer;
20 * unsigned long irq_flags;
21 * int __data_size;
22 * int pc;
23 *
24 * if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
25 * if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
26 * event_triggers_call(trace_file, NULL);
27 * if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
28 * return;
29 * }
30 *
31 * local_save_flags(irq_flags);
32 * pc = preempt_count();
33 *
34 * __data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
35 *
36 * event = trace_event_buffer_lock_reserve(&buffer, trace_file,
37 * event_<call>->event.type,
38 * sizeof(*entry) + __data_size,
39 * irq_flags, pc);
40 * if (!event)
41 * return;
42 * entry = ring_buffer_event_data(event);
43 *
44 * { <assign>; } <-- Here we assign the entries by the __field and
45 * __array macros.
46 *
47 * if (eflags & EVENT_FILE_FL_TRIGGER_COND)
48 * __tt = event_triggers_call(trace_file, entry);
49 *
50 * if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
51 * &trace_file->flags))
52 * ring_buffer_discard_commit(buffer, event);
53 * else if (!filter_check_discard(trace_file, entry, buffer, event))
54 * trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
55 *
56 * if (__tt)
57 * event_triggers_post_call(trace_file, __tt);
58 * }
59 *
60 * static struct trace_event ftrace_event_type_<call> = {
61 * .trace = trace_raw_output_<call>, <-- stage 2
62 * };
63 *
64 * static char print_fmt_<call>[] = <TP_printk>;
65 *
66 * static struct trace_event_class __used event_class_<template> = {
67 * .system = "<system>",
68 * .define_fields = trace_event_define_fields_<call>,
69 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
70 * .raw_init = trace_event_raw_init,
71 * .probe = trace_event_raw_event_##call,
72 * .reg = trace_event_reg,
73 * };
74 *
75 * static struct trace_event_call event_<call> = {
76 * .class = event_class_<template>,
77 * {
78 * .tp = &__tracepoint_<call>,
79 * },
80 * .event = &ftrace_event_type_<call>,
81 * .print_fmt = print_fmt_<call>,
82 * .flags = TRACE_EVENT_FL_TRACEPOINT,
83 * };
84 * // its only safe to use pointers when doing linker tricks to
85 * // create an array.
86 * static struct trace_event_call __used
87 * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
88 *
89 */
90
91#ifdef CONFIG_PERF_EVENTS
92
93#define _TRACE_PERF_PROTO(call, proto) \
94 static notrace void \
95 perf_trace_##call(void *__data, proto);
96
97#define _TRACE_PERF_INIT(call) \
98 .perf_probe = perf_trace_##call,
99
100#else
101#define _TRACE_PERF_PROTO(call, proto)
102#define _TRACE_PERF_INIT(call)
103#endif /* CONFIG_PERF_EVENTS */
104
105#undef __entry
106#define __entry entry
107
108#undef __field
109#define __field(type, item)
110
111#undef __field_struct
112#define __field_struct(type, item)
113
114#undef __array
115#define __array(type, item, len)
116
117#undef __dynamic_array
118#define __dynamic_array(type, item, len) \
119 __entry->__data_loc_##item = __data_offsets.item;
120
121#undef __string
122#define __string(item, src) __dynamic_array(char, item, -1)
123
124#undef __assign_str
125#define __assign_str(dst, src) \
126 strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
127
128#undef __bitmask
129#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
130
131#undef __get_bitmask
132#define __get_bitmask(field) (char *)__get_dynamic_array(field)
133
134#undef __assign_bitmask
135#define __assign_bitmask(dst, src, nr_bits) \
136 memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
137
138#undef TP_fast_assign
139#define TP_fast_assign(args...) args
140
141#undef __perf_addr
142#define __perf_addr(a) (a)
143
144#undef __perf_count
145#define __perf_count(c) (c)
146
147#undef __perf_task
148#define __perf_task(t) (t)
149
150#undef DECLARE_EVENT_CLASS
151#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
152 \
153static notrace void \
154trace_event_raw_event_##call(void *__data, proto) \
155{ \
156 struct trace_event_file *trace_file = __data; \
157 struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
158 struct trace_event_buffer fbuffer; \
159 struct trace_event_raw_##call *entry; \
160 int __data_size; \
161 \
162 if (trace_trigger_soft_disabled(trace_file)) \
163 return; \
164 \
165 __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
166 \
167 entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
168 sizeof(*entry) + __data_size); \
169 \
170 if (!entry) \
171 return; \
172 \
173 tstruct \
174 \
175 { assign; } \
176 \
177 trace_event_buffer_commit(&fbuffer); \
178}
179/*
180 * The ftrace_test_probe is compiled out, it is only here as a build time check
181 * to make sure that if the tracepoint handling changes, the ftrace probe will
182 * fail to compile unless it too is updated.
183 */
184
185#undef DEFINE_EVENT
186#define DEFINE_EVENT(template, call, proto, args) \
187static inline void ftrace_test_probe_##call(void) \
188{ \
189 check_trace_callback_type_##call(trace_event_raw_event_##template); \
190}
191
192#undef DEFINE_EVENT_PRINT
193#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
194
195#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
196
197#undef __entry
198#define __entry REC
199
200#undef __print_flags
201#undef __print_symbolic
202#undef __print_hex
203#undef __get_dynamic_array
204#undef __get_dynamic_array_len
205#undef __get_str
206#undef __get_bitmask
207#undef __print_array
208
209#undef TP_printk
210#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
211
212#undef DECLARE_EVENT_CLASS
213#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
214_TRACE_PERF_PROTO(call, PARAMS(proto)); \
215static char print_fmt_##call[] = print; \
216static struct trace_event_class __used __refdata event_class_##call = { \
217 .system = TRACE_SYSTEM_STRING, \
218 .define_fields = trace_event_define_fields_##call, \
219 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
220 .raw_init = trace_event_raw_init, \
221 .probe = trace_event_raw_event_##call, \
222 .reg = trace_event_reg, \
223 _TRACE_PERF_INIT(call) \
224};
225
226#undef DEFINE_EVENT
227#define DEFINE_EVENT(template, call, proto, args) \
228 \
229static struct trace_event_call __used event_##call = { \
230 .class = &event_class_##template, \
231 { \
232 .tp = &__tracepoint_##call, \
233 }, \
234 .event.funcs = &trace_event_type_funcs_##template, \
235 .print_fmt = print_fmt_##template, \
236 .flags = TRACE_EVENT_FL_TRACEPOINT, \
237}; \
238static struct trace_event_call __used \
239__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
240
241#undef DEFINE_EVENT_PRINT
242#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
243 \
244static char print_fmt_##call[] = print; \
245 \
246static struct trace_event_call __used event_##call = { \
247 .class = &event_class_##template, \
248 { \
249 .tp = &__tracepoint_##call, \
250 }, \
251 .event.funcs = &trace_event_type_funcs_##call, \
252 .print_fmt = print_fmt_##call, \
253 .flags = TRACE_EVENT_FL_TRACEPOINT, \
254}; \
255static struct trace_event_call __used \
256__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
257
258#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
259 1
260#undef TRACE_SYSTEM_VAR 2#undef TRACE_SYSTEM_VAR
261 3
diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h
index 43be3b0e44d3..de996cf61053 100644
--- a/include/trace/trace_events.h
+++ b/include/trace/trace_events.h
@@ -506,3 +506,261 @@ static inline notrace int trace_event_get_offsets_##call( \
506 506
507#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 507#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
508 508
509/*
510 * Stage 4 of the trace events.
511 *
512 * Override the macros in <trace/trace_events.h> to include the following:
513 *
514 * For those macros defined with TRACE_EVENT:
515 *
516 * static struct trace_event_call event_<call>;
517 *
518 * static void trace_event_raw_event_<call>(void *__data, proto)
519 * {
520 * struct trace_event_file *trace_file = __data;
521 * struct trace_event_call *event_call = trace_file->event_call;
522 * struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
523 * unsigned long eflags = trace_file->flags;
524 * enum event_trigger_type __tt = ETT_NONE;
525 * struct ring_buffer_event *event;
526 * struct trace_event_raw_<call> *entry; <-- defined in stage 1
527 * struct ring_buffer *buffer;
528 * unsigned long irq_flags;
529 * int __data_size;
530 * int pc;
531 *
532 * if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
533 * if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
534 * event_triggers_call(trace_file, NULL);
535 * if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
536 * return;
537 * }
538 *
539 * local_save_flags(irq_flags);
540 * pc = preempt_count();
541 *
542 * __data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
543 *
544 * event = trace_event_buffer_lock_reserve(&buffer, trace_file,
545 * event_<call>->event.type,
546 * sizeof(*entry) + __data_size,
547 * irq_flags, pc);
548 * if (!event)
549 * return;
550 * entry = ring_buffer_event_data(event);
551 *
552 * { <assign>; } <-- Here we assign the entries by the __field and
553 * __array macros.
554 *
555 * if (eflags & EVENT_FILE_FL_TRIGGER_COND)
556 * __tt = event_triggers_call(trace_file, entry);
557 *
558 * if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
559 * &trace_file->flags))
560 * ring_buffer_discard_commit(buffer, event);
561 * else if (!filter_check_discard(trace_file, entry, buffer, event))
562 * trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
563 *
564 * if (__tt)
565 * event_triggers_post_call(trace_file, __tt);
566 * }
567 *
568 * static struct trace_event ftrace_event_type_<call> = {
569 * .trace = trace_raw_output_<call>, <-- stage 2
570 * };
571 *
572 * static char print_fmt_<call>[] = <TP_printk>;
573 *
574 * static struct trace_event_class __used event_class_<template> = {
575 * .system = "<system>",
576 * .define_fields = trace_event_define_fields_<call>,
577 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
578 * .raw_init = trace_event_raw_init,
579 * .probe = trace_event_raw_event_##call,
580 * .reg = trace_event_reg,
581 * };
582 *
583 * static struct trace_event_call event_<call> = {
584 * .class = event_class_<template>,
585 * {
586 * .tp = &__tracepoint_<call>,
587 * },
588 * .event = &ftrace_event_type_<call>,
589 * .print_fmt = print_fmt_<call>,
590 * .flags = TRACE_EVENT_FL_TRACEPOINT,
591 * };
592 * // its only safe to use pointers when doing linker tricks to
593 * // create an array.
594 * static struct trace_event_call __used
595 * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
596 *
597 */
598
599#ifdef CONFIG_PERF_EVENTS
600
601#define _TRACE_PERF_PROTO(call, proto) \
602 static notrace void \
603 perf_trace_##call(void *__data, proto);
604
605#define _TRACE_PERF_INIT(call) \
606 .perf_probe = perf_trace_##call,
607
608#else
609#define _TRACE_PERF_PROTO(call, proto)
610#define _TRACE_PERF_INIT(call)
611#endif /* CONFIG_PERF_EVENTS */
612
613#undef __entry
614#define __entry entry
615
616#undef __field
617#define __field(type, item)
618
619#undef __field_struct
620#define __field_struct(type, item)
621
622#undef __array
623#define __array(type, item, len)
624
625#undef __dynamic_array
626#define __dynamic_array(type, item, len) \
627 __entry->__data_loc_##item = __data_offsets.item;
628
629#undef __string
630#define __string(item, src) __dynamic_array(char, item, -1)
631
632#undef __assign_str
633#define __assign_str(dst, src) \
634 strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
635
636#undef __bitmask
637#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
638
639#undef __get_bitmask
640#define __get_bitmask(field) (char *)__get_dynamic_array(field)
641
642#undef __assign_bitmask
643#define __assign_bitmask(dst, src, nr_bits) \
644 memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
645
646#undef TP_fast_assign
647#define TP_fast_assign(args...) args
648
649#undef __perf_addr
650#define __perf_addr(a) (a)
651
652#undef __perf_count
653#define __perf_count(c) (c)
654
655#undef __perf_task
656#define __perf_task(t) (t)
657
658#undef DECLARE_EVENT_CLASS
659#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
660 \
661static notrace void \
662trace_event_raw_event_##call(void *__data, proto) \
663{ \
664 struct trace_event_file *trace_file = __data; \
665 struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
666 struct trace_event_buffer fbuffer; \
667 struct trace_event_raw_##call *entry; \
668 int __data_size; \
669 \
670 if (trace_trigger_soft_disabled(trace_file)) \
671 return; \
672 \
673 __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
674 \
675 entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
676 sizeof(*entry) + __data_size); \
677 \
678 if (!entry) \
679 return; \
680 \
681 tstruct \
682 \
683 { assign; } \
684 \
685 trace_event_buffer_commit(&fbuffer); \
686}
687/*
688 * The ftrace_test_probe is compiled out, it is only here as a build time check
689 * to make sure that if the tracepoint handling changes, the ftrace probe will
690 * fail to compile unless it too is updated.
691 */
692
693#undef DEFINE_EVENT
694#define DEFINE_EVENT(template, call, proto, args) \
695static inline void ftrace_test_probe_##call(void) \
696{ \
697 check_trace_callback_type_##call(trace_event_raw_event_##template); \
698}
699
700#undef DEFINE_EVENT_PRINT
701#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
702
703#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
704
705#undef __entry
706#define __entry REC
707
708#undef __print_flags
709#undef __print_symbolic
710#undef __print_hex
711#undef __get_dynamic_array
712#undef __get_dynamic_array_len
713#undef __get_str
714#undef __get_bitmask
715#undef __print_array
716
717#undef TP_printk
718#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
719
720#undef DECLARE_EVENT_CLASS
721#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
722_TRACE_PERF_PROTO(call, PARAMS(proto)); \
723static char print_fmt_##call[] = print; \
724static struct trace_event_class __used __refdata event_class_##call = { \
725 .system = TRACE_SYSTEM_STRING, \
726 .define_fields = trace_event_define_fields_##call, \
727 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
728 .raw_init = trace_event_raw_init, \
729 .probe = trace_event_raw_event_##call, \
730 .reg = trace_event_reg, \
731 _TRACE_PERF_INIT(call) \
732};
733
734#undef DEFINE_EVENT
735#define DEFINE_EVENT(template, call, proto, args) \
736 \
737static struct trace_event_call __used event_##call = { \
738 .class = &event_class_##template, \
739 { \
740 .tp = &__tracepoint_##call, \
741 }, \
742 .event.funcs = &trace_event_type_funcs_##template, \
743 .print_fmt = print_fmt_##template, \
744 .flags = TRACE_EVENT_FL_TRACEPOINT, \
745}; \
746static struct trace_event_call __used \
747__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
748
749#undef DEFINE_EVENT_PRINT
750#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
751 \
752static char print_fmt_##call[] = print; \
753 \
754static struct trace_event_call __used event_##call = { \
755 .class = &event_class_##template, \
756 { \
757 .tp = &__tracepoint_##call, \
758 }, \
759 .event.funcs = &trace_event_type_funcs_##call, \
760 .print_fmt = print_fmt_##call, \
761 .flags = TRACE_EVENT_FL_TRACEPOINT, \
762}; \
763static struct trace_event_call __used \
764__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
765
766#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index 1153c43428f3..8d6363f42169 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -635,6 +635,13 @@ config TRACE_ENUM_MAP_FILE
635 635
636 If unsure, say N 636 If unsure, say N
637 637
638config TRACING_EVENTS_GPIO
639 bool "Trace gpio events"
640 depends on GPIOLIB
641 default y
642 help
643 Enable tracing events for gpio subsystem
644
638endif # FTRACE 645endif # FTRACE
639 646
640endif # TRACING_SUPPORT 647endif # TRACING_SUPPORT
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index e3a26188b95e..a990824c8604 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -103,7 +103,7 @@ record_it:
103 memcpy((void *) t + sizeof(*t), data, len); 103 memcpy((void *) t + sizeof(*t), data, len);
104 104
105 if (blk_tracer) 105 if (blk_tracer)
106 trace_buffer_unlock_commit(buffer, event, 0, pc); 106 trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
107 } 107 }
108} 108}
109 109
@@ -278,7 +278,7 @@ record_it:
278 memcpy((void *) t + sizeof(*t), pdu_data, pdu_len); 278 memcpy((void *) t + sizeof(*t), pdu_data, pdu_len);
279 279
280 if (blk_tracer) { 280 if (blk_tracer) {
281 trace_buffer_unlock_commit(buffer, event, 0, pc); 281 trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
282 return; 282 return;
283 } 283 }
284 } 284 }
@@ -1340,6 +1340,7 @@ static const struct {
1340static enum print_line_t print_one_line(struct trace_iterator *iter, 1340static enum print_line_t print_one_line(struct trace_iterator *iter,
1341 bool classic) 1341 bool classic)
1342{ 1342{
1343 struct trace_array *tr = iter->tr;
1343 struct trace_seq *s = &iter->seq; 1344 struct trace_seq *s = &iter->seq;
1344 const struct blk_io_trace *t; 1345 const struct blk_io_trace *t;
1345 u16 what; 1346 u16 what;
@@ -1348,7 +1349,7 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
1348 1349
1349 t = te_blk_io_trace(iter->ent); 1350 t = te_blk_io_trace(iter->ent);
1350 what = t->action & ((1 << BLK_TC_SHIFT) - 1); 1351 what = t->action & ((1 << BLK_TC_SHIFT) - 1);
1351 long_act = !!(trace_flags & TRACE_ITER_VERBOSE); 1352 long_act = !!(tr->trace_flags & TRACE_ITER_VERBOSE);
1352 log_action = classic ? &blk_log_action_classic : &blk_log_action; 1353 log_action = classic ? &blk_log_action_classic : &blk_log_action;
1353 1354
1354 if (t->action == BLK_TN_MESSAGE) { 1355 if (t->action == BLK_TN_MESSAGE) {
@@ -1410,9 +1411,9 @@ blk_tracer_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
1410 /* don't output context-info for blk_classic output */ 1411 /* don't output context-info for blk_classic output */
1411 if (bit == TRACE_BLK_OPT_CLASSIC) { 1412 if (bit == TRACE_BLK_OPT_CLASSIC) {
1412 if (set) 1413 if (set)
1413 trace_flags &= ~TRACE_ITER_CONTEXT_INFO; 1414 tr->trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
1414 else 1415 else
1415 trace_flags |= TRACE_ITER_CONTEXT_INFO; 1416 tr->trace_flags |= TRACE_ITER_CONTEXT_INFO;
1416 } 1417 }
1417 return 0; 1418 return 0;
1418} 1419}
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 00611e95a8ee..3f743b147247 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -243,6 +243,11 @@ static void ftrace_sync_ipi(void *data)
243 243
244#ifdef CONFIG_FUNCTION_GRAPH_TRACER 244#ifdef CONFIG_FUNCTION_GRAPH_TRACER
245static void update_function_graph_func(void); 245static void update_function_graph_func(void);
246
247/* Both enabled by default (can be cleared by function_graph tracer flags */
248static bool fgraph_sleep_time = true;
249static bool fgraph_graph_time = true;
250
246#else 251#else
247static inline void update_function_graph_func(void) { } 252static inline void update_function_graph_func(void) { }
248#endif 253#endif
@@ -917,7 +922,7 @@ static void profile_graph_return(struct ftrace_graph_ret *trace)
917 922
918 calltime = trace->rettime - trace->calltime; 923 calltime = trace->rettime - trace->calltime;
919 924
920 if (!(trace_flags & TRACE_ITER_GRAPH_TIME)) { 925 if (!fgraph_graph_time) {
921 int index; 926 int index;
922 927
923 index = trace->depth; 928 index = trace->depth;
@@ -3420,27 +3425,35 @@ ftrace_notrace_open(struct inode *inode, struct file *file)
3420 inode, file); 3425 inode, file);
3421} 3426}
3422 3427
3423static int ftrace_match(char *str, char *regex, int len, int type) 3428/* Type for quick search ftrace basic regexes (globs) from filter_parse_regex */
3429struct ftrace_glob {
3430 char *search;
3431 unsigned len;
3432 int type;
3433};
3434
3435static int ftrace_match(char *str, struct ftrace_glob *g)
3424{ 3436{
3425 int matched = 0; 3437 int matched = 0;
3426 int slen; 3438 int slen;
3427 3439
3428 switch (type) { 3440 switch (g->type) {
3429 case MATCH_FULL: 3441 case MATCH_FULL:
3430 if (strcmp(str, regex) == 0) 3442 if (strcmp(str, g->search) == 0)
3431 matched = 1; 3443 matched = 1;
3432 break; 3444 break;
3433 case MATCH_FRONT_ONLY: 3445 case MATCH_FRONT_ONLY:
3434 if (strncmp(str, regex, len) == 0) 3446 if (strncmp(str, g->search, g->len) == 0)
3435 matched = 1; 3447 matched = 1;
3436 break; 3448 break;
3437 case MATCH_MIDDLE_ONLY: 3449 case MATCH_MIDDLE_ONLY:
3438 if (strstr(str, regex)) 3450 if (strstr(str, g->search))
3439 matched = 1; 3451 matched = 1;
3440 break; 3452 break;
3441 case MATCH_END_ONLY: 3453 case MATCH_END_ONLY:
3442 slen = strlen(str); 3454 slen = strlen(str);
3443 if (slen >= len && memcmp(str + slen - len, regex, len) == 0) 3455 if (slen >= g->len &&
3456 memcmp(str + slen - g->len, g->search, g->len) == 0)
3444 matched = 1; 3457 matched = 1;
3445 break; 3458 break;
3446 } 3459 }
@@ -3449,13 +3462,13 @@ static int ftrace_match(char *str, char *regex, int len, int type)
3449} 3462}
3450 3463
3451static int 3464static int
3452enter_record(struct ftrace_hash *hash, struct dyn_ftrace *rec, int not) 3465enter_record(struct ftrace_hash *hash, struct dyn_ftrace *rec, int clear_filter)
3453{ 3466{
3454 struct ftrace_func_entry *entry; 3467 struct ftrace_func_entry *entry;
3455 int ret = 0; 3468 int ret = 0;
3456 3469
3457 entry = ftrace_lookup_ip(hash, rec->ip); 3470 entry = ftrace_lookup_ip(hash, rec->ip);
3458 if (not) { 3471 if (clear_filter) {
3459 /* Do nothing if it doesn't exist */ 3472 /* Do nothing if it doesn't exist */
3460 if (!entry) 3473 if (!entry)
3461 return 0; 3474 return 0;
@@ -3472,42 +3485,68 @@ enter_record(struct ftrace_hash *hash, struct dyn_ftrace *rec, int not)
3472} 3485}
3473 3486
3474static int 3487static int
3475ftrace_match_record(struct dyn_ftrace *rec, char *mod, 3488ftrace_match_record(struct dyn_ftrace *rec, struct ftrace_glob *func_g,
3476 char *regex, int len, int type) 3489 struct ftrace_glob *mod_g, int exclude_mod)
3477{ 3490{
3478 char str[KSYM_SYMBOL_LEN]; 3491 char str[KSYM_SYMBOL_LEN];
3479 char *modname; 3492 char *modname;
3480 3493
3481 kallsyms_lookup(rec->ip, NULL, NULL, &modname, str); 3494 kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
3482 3495
3483 if (mod) { 3496 if (mod_g) {
3484 /* module lookup requires matching the module */ 3497 int mod_matches = (modname) ? ftrace_match(modname, mod_g) : 0;
3485 if (!modname || strcmp(modname, mod)) 3498
3499 /* blank module name to match all modules */
3500 if (!mod_g->len) {
3501 /* blank module globbing: modname xor exclude_mod */
3502 if ((!exclude_mod) != (!modname))
3503 goto func_match;
3504 return 0;
3505 }
3506
3507 /* not matching the module */
3508 if (!modname || !mod_matches) {
3509 if (exclude_mod)
3510 goto func_match;
3511 else
3512 return 0;
3513 }
3514
3515 if (mod_matches && exclude_mod)
3486 return 0; 3516 return 0;
3487 3517
3518func_match:
3488 /* blank search means to match all funcs in the mod */ 3519 /* blank search means to match all funcs in the mod */
3489 if (!len) 3520 if (!func_g->len)
3490 return 1; 3521 return 1;
3491 } 3522 }
3492 3523
3493 return ftrace_match(str, regex, len, type); 3524 return ftrace_match(str, func_g);
3494} 3525}
3495 3526
3496static int 3527static int
3497match_records(struct ftrace_hash *hash, char *buff, 3528match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
3498 int len, char *mod, int not)
3499{ 3529{
3500 unsigned search_len = 0;
3501 struct ftrace_page *pg; 3530 struct ftrace_page *pg;
3502 struct dyn_ftrace *rec; 3531 struct dyn_ftrace *rec;
3503 int type = MATCH_FULL; 3532 struct ftrace_glob func_g = { .type = MATCH_FULL };
3504 char *search = buff; 3533 struct ftrace_glob mod_g = { .type = MATCH_FULL };
3534 struct ftrace_glob *mod_match = (mod) ? &mod_g : NULL;
3535 int exclude_mod = 0;
3505 int found = 0; 3536 int found = 0;
3506 int ret; 3537 int ret;
3538 int clear_filter;
3539
3540 if (func) {
3541 func_g.type = filter_parse_regex(func, len, &func_g.search,
3542 &clear_filter);
3543 func_g.len = strlen(func_g.search);
3544 }
3507 3545
3508 if (len) { 3546 if (mod) {
3509 type = filter_parse_regex(buff, len, &search, &not); 3547 mod_g.type = filter_parse_regex(mod, strlen(mod),
3510 search_len = strlen(search); 3548 &mod_g.search, &exclude_mod);
3549 mod_g.len = strlen(mod_g.search);
3511 } 3550 }
3512 3551
3513 mutex_lock(&ftrace_lock); 3552 mutex_lock(&ftrace_lock);
@@ -3516,8 +3555,8 @@ match_records(struct ftrace_hash *hash, char *buff,
3516 goto out_unlock; 3555 goto out_unlock;
3517 3556
3518 do_for_each_ftrace_rec(pg, rec) { 3557 do_for_each_ftrace_rec(pg, rec) {
3519 if (ftrace_match_record(rec, mod, search, search_len, type)) { 3558 if (ftrace_match_record(rec, &func_g, mod_match, exclude_mod)) {
3520 ret = enter_record(hash, rec, not); 3559 ret = enter_record(hash, rec, clear_filter);
3521 if (ret < 0) { 3560 if (ret < 0) {
3522 found = ret; 3561 found = ret;
3523 goto out_unlock; 3562 goto out_unlock;
@@ -3534,26 +3573,9 @@ match_records(struct ftrace_hash *hash, char *buff,
3534static int 3573static int
3535ftrace_match_records(struct ftrace_hash *hash, char *buff, int len) 3574ftrace_match_records(struct ftrace_hash *hash, char *buff, int len)
3536{ 3575{
3537 return match_records(hash, buff, len, NULL, 0); 3576 return match_records(hash, buff, len, NULL);
3538} 3577}
3539 3578
3540static int
3541ftrace_match_module_records(struct ftrace_hash *hash, char *buff, char *mod)
3542{
3543 int not = 0;
3544
3545 /* blank or '*' mean the same */
3546 if (strcmp(buff, "*") == 0)
3547 buff[0] = 0;
3548
3549 /* handle the case of 'dont filter this module' */
3550 if (strcmp(buff, "!") == 0 || strcmp(buff, "!*") == 0) {
3551 buff[0] = 0;
3552 not = 1;
3553 }
3554
3555 return match_records(hash, buff, strlen(buff), mod, not);
3556}
3557 3579
3558/* 3580/*
3559 * We register the module command as a template to show others how 3581 * We register the module command as a template to show others how
@@ -3562,10 +3584,9 @@ ftrace_match_module_records(struct ftrace_hash *hash, char *buff, char *mod)
3562 3584
3563static int 3585static int
3564ftrace_mod_callback(struct ftrace_hash *hash, 3586ftrace_mod_callback(struct ftrace_hash *hash,
3565 char *func, char *cmd, char *param, int enable) 3587 char *func, char *cmd, char *module, int enable)
3566{ 3588{
3567 char *mod; 3589 int ret;
3568 int ret = -EINVAL;
3569 3590
3570 /* 3591 /*
3571 * cmd == 'mod' because we only registered this func 3592 * cmd == 'mod' because we only registered this func
@@ -3574,21 +3595,11 @@ ftrace_mod_callback(struct ftrace_hash *hash,
3574 * you can tell which command was used by the cmd 3595 * you can tell which command was used by the cmd
3575 * parameter. 3596 * parameter.
3576 */ 3597 */
3577 3598 ret = match_records(hash, func, strlen(func), module);
3578 /* we must have a module name */
3579 if (!param)
3580 return ret;
3581
3582 mod = strsep(&param, ":");
3583 if (!strlen(mod))
3584 return ret;
3585
3586 ret = ftrace_match_module_records(hash, func, mod);
3587 if (!ret) 3599 if (!ret)
3588 ret = -EINVAL; 3600 return -EINVAL;
3589 if (ret < 0) 3601 if (ret < 0)
3590 return ret; 3602 return ret;
3591
3592 return 0; 3603 return 0;
3593} 3604}
3594 3605
@@ -3699,19 +3710,20 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
3699{ 3710{
3700 struct ftrace_ops_hash old_hash_ops; 3711 struct ftrace_ops_hash old_hash_ops;
3701 struct ftrace_func_probe *entry; 3712 struct ftrace_func_probe *entry;
3713 struct ftrace_glob func_g;
3702 struct ftrace_hash **orig_hash = &trace_probe_ops.func_hash->filter_hash; 3714 struct ftrace_hash **orig_hash = &trace_probe_ops.func_hash->filter_hash;
3703 struct ftrace_hash *old_hash = *orig_hash; 3715 struct ftrace_hash *old_hash = *orig_hash;
3704 struct ftrace_hash *hash; 3716 struct ftrace_hash *hash;
3705 struct ftrace_page *pg; 3717 struct ftrace_page *pg;
3706 struct dyn_ftrace *rec; 3718 struct dyn_ftrace *rec;
3707 int type, len, not; 3719 int not;
3708 unsigned long key; 3720 unsigned long key;
3709 int count = 0; 3721 int count = 0;
3710 char *search;
3711 int ret; 3722 int ret;
3712 3723
3713 type = filter_parse_regex(glob, strlen(glob), &search, &not); 3724 func_g.type = filter_parse_regex(glob, strlen(glob),
3714 len = strlen(search); 3725 &func_g.search, &not);
3726 func_g.len = strlen(func_g.search);
3715 3727
3716 /* we do not support '!' for function probes */ 3728 /* we do not support '!' for function probes */
3717 if (WARN_ON(not)) 3729 if (WARN_ON(not))
@@ -3738,7 +3750,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
3738 3750
3739 do_for_each_ftrace_rec(pg, rec) { 3751 do_for_each_ftrace_rec(pg, rec) {
3740 3752
3741 if (!ftrace_match_record(rec, NULL, search, len, type)) 3753 if (!ftrace_match_record(rec, &func_g, NULL, 0))
3742 continue; 3754 continue;
3743 3755
3744 entry = kmalloc(sizeof(*entry), GFP_KERNEL); 3756 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
@@ -3811,24 +3823,24 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
3811 struct ftrace_func_entry *rec_entry; 3823 struct ftrace_func_entry *rec_entry;
3812 struct ftrace_func_probe *entry; 3824 struct ftrace_func_probe *entry;
3813 struct ftrace_func_probe *p; 3825 struct ftrace_func_probe *p;
3826 struct ftrace_glob func_g;
3814 struct ftrace_hash **orig_hash = &trace_probe_ops.func_hash->filter_hash; 3827 struct ftrace_hash **orig_hash = &trace_probe_ops.func_hash->filter_hash;
3815 struct ftrace_hash *old_hash = *orig_hash; 3828 struct ftrace_hash *old_hash = *orig_hash;
3816 struct list_head free_list; 3829 struct list_head free_list;
3817 struct ftrace_hash *hash; 3830 struct ftrace_hash *hash;
3818 struct hlist_node *tmp; 3831 struct hlist_node *tmp;
3819 char str[KSYM_SYMBOL_LEN]; 3832 char str[KSYM_SYMBOL_LEN];
3820 int type = MATCH_FULL; 3833 int i, ret;
3821 int i, len = 0;
3822 char *search;
3823 int ret;
3824 3834
3825 if (glob && (strcmp(glob, "*") == 0 || !strlen(glob))) 3835 if (glob && (strcmp(glob, "*") == 0 || !strlen(glob)))
3826 glob = NULL; 3836 func_g.search = NULL;
3827 else if (glob) { 3837 else if (glob) {
3828 int not; 3838 int not;
3829 3839
3830 type = filter_parse_regex(glob, strlen(glob), &search, &not); 3840 func_g.type = filter_parse_regex(glob, strlen(glob),
3831 len = strlen(search); 3841 &func_g.search, &not);
3842 func_g.len = strlen(func_g.search);
3843 func_g.search = glob;
3832 3844
3833 /* we do not support '!' for function probes */ 3845 /* we do not support '!' for function probes */
3834 if (WARN_ON(not)) 3846 if (WARN_ON(not))
@@ -3857,10 +3869,10 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
3857 continue; 3869 continue;
3858 3870
3859 /* do this last, since it is the most expensive */ 3871 /* do this last, since it is the most expensive */
3860 if (glob) { 3872 if (func_g.search) {
3861 kallsyms_lookup(entry->ip, NULL, NULL, 3873 kallsyms_lookup(entry->ip, NULL, NULL,
3862 NULL, str); 3874 NULL, str);
3863 if (!ftrace_match(str, glob, len, type)) 3875 if (!ftrace_match(str, &func_g))
3864 continue; 3876 continue;
3865 } 3877 }
3866 3878
@@ -3889,7 +3901,7 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
3889 ftrace_free_entry(entry); 3901 ftrace_free_entry(entry);
3890 } 3902 }
3891 mutex_unlock(&ftrace_lock); 3903 mutex_unlock(&ftrace_lock);
3892 3904
3893 out_unlock: 3905 out_unlock:
3894 mutex_unlock(&trace_probe_ops.func_hash->regex_lock); 3906 mutex_unlock(&trace_probe_ops.func_hash->regex_lock);
3895 free_ftrace_hash(hash); 3907 free_ftrace_hash(hash);
@@ -4605,21 +4617,21 @@ ftrace_graph_release(struct inode *inode, struct file *file)
4605static int 4617static int
4606ftrace_set_func(unsigned long *array, int *idx, int size, char *buffer) 4618ftrace_set_func(unsigned long *array, int *idx, int size, char *buffer)
4607{ 4619{
4620 struct ftrace_glob func_g;
4608 struct dyn_ftrace *rec; 4621 struct dyn_ftrace *rec;
4609 struct ftrace_page *pg; 4622 struct ftrace_page *pg;
4610 int search_len;
4611 int fail = 1; 4623 int fail = 1;
4612 int type, not; 4624 int not;
4613 char *search;
4614 bool exists; 4625 bool exists;
4615 int i; 4626 int i;
4616 4627
4617 /* decode regex */ 4628 /* decode regex */
4618 type = filter_parse_regex(buffer, strlen(buffer), &search, &not); 4629 func_g.type = filter_parse_regex(buffer, strlen(buffer),
4630 &func_g.search, &not);
4619 if (!not && *idx >= size) 4631 if (!not && *idx >= size)
4620 return -EBUSY; 4632 return -EBUSY;
4621 4633
4622 search_len = strlen(search); 4634 func_g.len = strlen(func_g.search);
4623 4635
4624 mutex_lock(&ftrace_lock); 4636 mutex_lock(&ftrace_lock);
4625 4637
@@ -4630,7 +4642,7 @@ ftrace_set_func(unsigned long *array, int *idx, int size, char *buffer)
4630 4642
4631 do_for_each_ftrace_rec(pg, rec) { 4643 do_for_each_ftrace_rec(pg, rec) {
4632 4644
4633 if (ftrace_match_record(rec, NULL, search, search_len, type)) { 4645 if (ftrace_match_record(rec, &func_g, NULL, 0)) {
4634 /* if it is in the array */ 4646 /* if it is in the array */
4635 exists = false; 4647 exists = false;
4636 for (i = 0; i < *idx; i++) { 4648 for (i = 0; i < *idx; i++) {
@@ -4783,17 +4795,6 @@ static int ftrace_cmp_ips(const void *a, const void *b)
4783 return 0; 4795 return 0;
4784} 4796}
4785 4797
4786static void ftrace_swap_ips(void *a, void *b, int size)
4787{
4788 unsigned long *ipa = a;
4789 unsigned long *ipb = b;
4790 unsigned long t;
4791
4792 t = *ipa;
4793 *ipa = *ipb;
4794 *ipb = t;
4795}
4796
4797static int ftrace_process_locs(struct module *mod, 4798static int ftrace_process_locs(struct module *mod,
4798 unsigned long *start, 4799 unsigned long *start,
4799 unsigned long *end) 4800 unsigned long *end)
@@ -4813,7 +4814,7 @@ static int ftrace_process_locs(struct module *mod,
4813 return 0; 4814 return 0;
4814 4815
4815 sort(start, count, sizeof(*start), 4816 sort(start, count, sizeof(*start),
4816 ftrace_cmp_ips, ftrace_swap_ips); 4817 ftrace_cmp_ips, NULL);
4817 4818
4818 start_pg = ftrace_allocate_pages(count); 4819 start_pg = ftrace_allocate_pages(count);
4819 if (!start_pg) 4820 if (!start_pg)
@@ -5639,6 +5640,16 @@ static struct ftrace_ops graph_ops = {
5639 ASSIGN_OPS_HASH(graph_ops, &global_ops.local_hash) 5640 ASSIGN_OPS_HASH(graph_ops, &global_ops.local_hash)
5640}; 5641};
5641 5642
5643void ftrace_graph_sleep_time_control(bool enable)
5644{
5645 fgraph_sleep_time = enable;
5646}
5647
5648void ftrace_graph_graph_time_control(bool enable)
5649{
5650 fgraph_graph_time = enable;
5651}
5652
5642int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace) 5653int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
5643{ 5654{
5644 return 0; 5655 return 0;
@@ -5707,7 +5718,7 @@ ftrace_graph_probe_sched_switch(void *ignore, bool preempt,
5707 * Does the user want to count the time a function was asleep. 5718 * Does the user want to count the time a function was asleep.
5708 * If so, do not update the time stamps. 5719 * If so, do not update the time stamps.
5709 */ 5720 */
5710 if (trace_flags & TRACE_ITER_SLEEP_TIME) 5721 if (fgraph_sleep_time)
5711 return; 5722 return;
5712 5723
5713 timestamp = trace_clock_local(); 5724 timestamp = trace_clock_local();
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index fc347f8b1bca..75f1d05ea82d 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -829,7 +829,7 @@ rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
829 * writer is ever on it, the previous pointer never points 829 * writer is ever on it, the previous pointer never points
830 * back to the reader page. 830 * back to the reader page.
831 */ 831 */
832static int rb_is_reader_page(struct buffer_page *page) 832static bool rb_is_reader_page(struct buffer_page *page)
833{ 833{
834 struct list_head *list = page->list.prev; 834 struct list_head *list = page->list.prev;
835 835
@@ -2270,7 +2270,7 @@ rb_add_time_stamp(struct ring_buffer_event *event, u64 delta)
2270 return skip_time_extend(event); 2270 return skip_time_extend(event);
2271} 2271}
2272 2272
2273static inline int rb_event_is_commit(struct ring_buffer_per_cpu *cpu_buffer, 2273static inline bool rb_event_is_commit(struct ring_buffer_per_cpu *cpu_buffer,
2274 struct ring_buffer_event *event); 2274 struct ring_buffer_event *event);
2275 2275
2276/** 2276/**
@@ -2498,7 +2498,7 @@ static inline void rb_event_discard(struct ring_buffer_event *event)
2498 event->time_delta = 1; 2498 event->time_delta = 1;
2499} 2499}
2500 2500
2501static inline int 2501static inline bool
2502rb_event_is_commit(struct ring_buffer_per_cpu *cpu_buffer, 2502rb_event_is_commit(struct ring_buffer_per_cpu *cpu_buffer,
2503 struct ring_buffer_event *event) 2503 struct ring_buffer_event *event)
2504{ 2504{
@@ -3039,7 +3039,7 @@ int ring_buffer_write(struct ring_buffer *buffer,
3039} 3039}
3040EXPORT_SYMBOL_GPL(ring_buffer_write); 3040EXPORT_SYMBOL_GPL(ring_buffer_write);
3041 3041
3042static int rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer) 3042static bool rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer)
3043{ 3043{
3044 struct buffer_page *reader = cpu_buffer->reader_page; 3044 struct buffer_page *reader = cpu_buffer->reader_page;
3045 struct buffer_page *head = rb_set_head_page(cpu_buffer); 3045 struct buffer_page *head = rb_set_head_page(cpu_buffer);
@@ -3047,7 +3047,7 @@ static int rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer)
3047 3047
3048 /* In case of error, head will be NULL */ 3048 /* In case of error, head will be NULL */
3049 if (unlikely(!head)) 3049 if (unlikely(!head))
3050 return 1; 3050 return true;
3051 3051
3052 return reader->read == rb_page_commit(reader) && 3052 return reader->read == rb_page_commit(reader) &&
3053 (commit == reader || 3053 (commit == reader ||
@@ -4267,7 +4267,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_reset);
4267 * rind_buffer_empty - is the ring buffer empty? 4267 * rind_buffer_empty - is the ring buffer empty?
4268 * @buffer: The ring buffer to test 4268 * @buffer: The ring buffer to test
4269 */ 4269 */
4270int ring_buffer_empty(struct ring_buffer *buffer) 4270bool ring_buffer_empty(struct ring_buffer *buffer)
4271{ 4271{
4272 struct ring_buffer_per_cpu *cpu_buffer; 4272 struct ring_buffer_per_cpu *cpu_buffer;
4273 unsigned long flags; 4273 unsigned long flags;
@@ -4285,10 +4285,10 @@ int ring_buffer_empty(struct ring_buffer *buffer)
4285 local_irq_restore(flags); 4285 local_irq_restore(flags);
4286 4286
4287 if (!ret) 4287 if (!ret)
4288 return 0; 4288 return false;
4289 } 4289 }
4290 4290
4291 return 1; 4291 return true;
4292} 4292}
4293EXPORT_SYMBOL_GPL(ring_buffer_empty); 4293EXPORT_SYMBOL_GPL(ring_buffer_empty);
4294 4294
@@ -4297,7 +4297,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_empty);
4297 * @buffer: The ring buffer 4297 * @buffer: The ring buffer
4298 * @cpu: The CPU buffer to test 4298 * @cpu: The CPU buffer to test
4299 */ 4299 */
4300int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu) 4300bool ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu)
4301{ 4301{
4302 struct ring_buffer_per_cpu *cpu_buffer; 4302 struct ring_buffer_per_cpu *cpu_buffer;
4303 unsigned long flags; 4303 unsigned long flags;
@@ -4305,7 +4305,7 @@ int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu)
4305 int ret; 4305 int ret;
4306 4306
4307 if (!cpumask_test_cpu(cpu, buffer->cpumask)) 4307 if (!cpumask_test_cpu(cpu, buffer->cpumask))
4308 return 1; 4308 return true;
4309 4309
4310 cpu_buffer = buffer->buffers[cpu]; 4310 cpu_buffer = buffer->buffers[cpu];
4311 local_irq_save(flags); 4311 local_irq_save(flags);
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index a1503a027ee2..6df9a83e20d7 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -24,8 +24,8 @@ struct rb_page {
24static int wakeup_interval = 100; 24static int wakeup_interval = 100;
25 25
26static int reader_finish; 26static int reader_finish;
27static struct completion read_start; 27static DECLARE_COMPLETION(read_start);
28static struct completion read_done; 28static DECLARE_COMPLETION(read_done);
29 29
30static struct ring_buffer *buffer; 30static struct ring_buffer *buffer;
31static struct task_struct *producer; 31static struct task_struct *producer;
@@ -60,12 +60,12 @@ MODULE_PARM_DESC(consumer_fifo, "fifo prio for consumer");
60 60
61static int read_events; 61static int read_events;
62 62
63static int kill_test; 63static int test_error;
64 64
65#define KILL_TEST() \ 65#define TEST_ERROR() \
66 do { \ 66 do { \
67 if (!kill_test) { \ 67 if (!test_error) { \
68 kill_test = 1; \ 68 test_error = 1; \
69 WARN_ON(1); \ 69 WARN_ON(1); \
70 } \ 70 } \
71 } while (0) 71 } while (0)
@@ -75,6 +75,11 @@ enum event_status {
75 EVENT_DROPPED, 75 EVENT_DROPPED,
76}; 76};
77 77
78static bool break_test(void)
79{
80 return test_error || kthread_should_stop();
81}
82
78static enum event_status read_event(int cpu) 83static enum event_status read_event(int cpu)
79{ 84{
80 struct ring_buffer_event *event; 85 struct ring_buffer_event *event;
@@ -87,7 +92,7 @@ static enum event_status read_event(int cpu)
87 92
88 entry = ring_buffer_event_data(event); 93 entry = ring_buffer_event_data(event);
89 if (*entry != cpu) { 94 if (*entry != cpu) {
90 KILL_TEST(); 95 TEST_ERROR();
91 return EVENT_DROPPED; 96 return EVENT_DROPPED;
92 } 97 }
93 98
@@ -115,10 +120,10 @@ static enum event_status read_page(int cpu)
115 rpage = bpage; 120 rpage = bpage;
116 /* The commit may have missed event flags set, clear them */ 121 /* The commit may have missed event flags set, clear them */
117 commit = local_read(&rpage->commit) & 0xfffff; 122 commit = local_read(&rpage->commit) & 0xfffff;
118 for (i = 0; i < commit && !kill_test; i += inc) { 123 for (i = 0; i < commit && !test_error ; i += inc) {
119 124
120 if (i >= (PAGE_SIZE - offsetof(struct rb_page, data))) { 125 if (i >= (PAGE_SIZE - offsetof(struct rb_page, data))) {
121 KILL_TEST(); 126 TEST_ERROR();
122 break; 127 break;
123 } 128 }
124 129
@@ -128,7 +133,7 @@ static enum event_status read_page(int cpu)
128 case RINGBUF_TYPE_PADDING: 133 case RINGBUF_TYPE_PADDING:
129 /* failed writes may be discarded events */ 134 /* failed writes may be discarded events */
130 if (!event->time_delta) 135 if (!event->time_delta)
131 KILL_TEST(); 136 TEST_ERROR();
132 inc = event->array[0] + 4; 137 inc = event->array[0] + 4;
133 break; 138 break;
134 case RINGBUF_TYPE_TIME_EXTEND: 139 case RINGBUF_TYPE_TIME_EXTEND:
@@ -137,12 +142,12 @@ static enum event_status read_page(int cpu)
137 case 0: 142 case 0:
138 entry = ring_buffer_event_data(event); 143 entry = ring_buffer_event_data(event);
139 if (*entry != cpu) { 144 if (*entry != cpu) {
140 KILL_TEST(); 145 TEST_ERROR();
141 break; 146 break;
142 } 147 }
143 read++; 148 read++;
144 if (!event->array[0]) { 149 if (!event->array[0]) {
145 KILL_TEST(); 150 TEST_ERROR();
146 break; 151 break;
147 } 152 }
148 inc = event->array[0] + 4; 153 inc = event->array[0] + 4;
@@ -150,17 +155,17 @@ static enum event_status read_page(int cpu)
150 default: 155 default:
151 entry = ring_buffer_event_data(event); 156 entry = ring_buffer_event_data(event);
152 if (*entry != cpu) { 157 if (*entry != cpu) {
153 KILL_TEST(); 158 TEST_ERROR();
154 break; 159 break;
155 } 160 }
156 read++; 161 read++;
157 inc = ((event->type_len + 1) * 4); 162 inc = ((event->type_len + 1) * 4);
158 } 163 }
159 if (kill_test) 164 if (test_error)
160 break; 165 break;
161 166
162 if (inc <= 0) { 167 if (inc <= 0) {
163 KILL_TEST(); 168 TEST_ERROR();
164 break; 169 break;
165 } 170 }
166 } 171 }
@@ -178,10 +183,14 @@ static void ring_buffer_consumer(void)
178 read_events ^= 1; 183 read_events ^= 1;
179 184
180 read = 0; 185 read = 0;
181 while (!reader_finish && !kill_test) { 186 /*
182 int found; 187 * Continue running until the producer specifically asks to stop
188 * and is ready for the completion.
189 */
190 while (!READ_ONCE(reader_finish)) {
191 int found = 1;
183 192
184 do { 193 while (found && !test_error) {
185 int cpu; 194 int cpu;
186 195
187 found = 0; 196 found = 0;
@@ -193,19 +202,25 @@ static void ring_buffer_consumer(void)
193 else 202 else
194 stat = read_page(cpu); 203 stat = read_page(cpu);
195 204
196 if (kill_test) 205 if (test_error)
197 break; 206 break;
207
198 if (stat == EVENT_FOUND) 208 if (stat == EVENT_FOUND)
199 found = 1; 209 found = 1;
210
200 } 211 }
201 } while (found && !kill_test); 212 }
202 213
214 /* Wait till the producer wakes us up when there is more data
215 * available or when the producer wants us to finish reading.
216 */
203 set_current_state(TASK_INTERRUPTIBLE); 217 set_current_state(TASK_INTERRUPTIBLE);
204 if (reader_finish) 218 if (reader_finish)
205 break; 219 break;
206 220
207 schedule(); 221 schedule();
208 } 222 }
223 __set_current_state(TASK_RUNNING);
209 reader_finish = 0; 224 reader_finish = 0;
210 complete(&read_done); 225 complete(&read_done);
211} 226}
@@ -263,10 +278,7 @@ static void ring_buffer_producer(void)
263 if (cnt % wakeup_interval) 278 if (cnt % wakeup_interval)
264 cond_resched(); 279 cond_resched();
265#endif 280#endif
266 if (kthread_should_stop()) 281 } while (ktime_before(end_time, timeout) && !break_test());
267 kill_test = 1;
268
269 } while (ktime_before(end_time, timeout) && !kill_test);
270 trace_printk("End ring buffer hammer\n"); 282 trace_printk("End ring buffer hammer\n");
271 283
272 if (consumer) { 284 if (consumer) {
@@ -276,8 +288,6 @@ static void ring_buffer_producer(void)
276 /* the completions must be visible before the finish var */ 288 /* the completions must be visible before the finish var */
277 smp_wmb(); 289 smp_wmb();
278 reader_finish = 1; 290 reader_finish = 1;
279 /* finish var visible before waking up the consumer */
280 smp_wmb();
281 wake_up_process(consumer); 291 wake_up_process(consumer);
282 wait_for_completion(&read_done); 292 wait_for_completion(&read_done);
283 } 293 }
@@ -287,7 +297,7 @@ static void ring_buffer_producer(void)
287 entries = ring_buffer_entries(buffer); 297 entries = ring_buffer_entries(buffer);
288 overruns = ring_buffer_overruns(buffer); 298 overruns = ring_buffer_overruns(buffer);
289 299
290 if (kill_test && !kthread_should_stop()) 300 if (test_error)
291 trace_printk("ERROR!\n"); 301 trace_printk("ERROR!\n");
292 302
293 if (!disable_reader) { 303 if (!disable_reader) {
@@ -368,15 +378,14 @@ static void wait_to_die(void)
368 378
369static int ring_buffer_consumer_thread(void *arg) 379static int ring_buffer_consumer_thread(void *arg)
370{ 380{
371 while (!kthread_should_stop() && !kill_test) { 381 while (!break_test()) {
372 complete(&read_start); 382 complete(&read_start);
373 383
374 ring_buffer_consumer(); 384 ring_buffer_consumer();
375 385
376 set_current_state(TASK_INTERRUPTIBLE); 386 set_current_state(TASK_INTERRUPTIBLE);
377 if (kthread_should_stop() || kill_test) 387 if (break_test())
378 break; 388 break;
379
380 schedule(); 389 schedule();
381 } 390 }
382 __set_current_state(TASK_RUNNING); 391 __set_current_state(TASK_RUNNING);
@@ -389,27 +398,27 @@ static int ring_buffer_consumer_thread(void *arg)
389 398
390static int ring_buffer_producer_thread(void *arg) 399static int ring_buffer_producer_thread(void *arg)
391{ 400{
392 init_completion(&read_start); 401 while (!break_test()) {
393
394 while (!kthread_should_stop() && !kill_test) {
395 ring_buffer_reset(buffer); 402 ring_buffer_reset(buffer);
396 403
397 if (consumer) { 404 if (consumer) {
398 smp_wmb();
399 wake_up_process(consumer); 405 wake_up_process(consumer);
400 wait_for_completion(&read_start); 406 wait_for_completion(&read_start);
401 } 407 }
402 408
403 ring_buffer_producer(); 409 ring_buffer_producer();
404 if (kill_test) 410 if (break_test())
405 goto out_kill; 411 goto out_kill;
406 412
407 trace_printk("Sleeping for 10 secs\n"); 413 trace_printk("Sleeping for 10 secs\n");
408 set_current_state(TASK_INTERRUPTIBLE); 414 set_current_state(TASK_INTERRUPTIBLE);
415 if (break_test())
416 goto out_kill;
409 schedule_timeout(HZ * SLEEP_TIME); 417 schedule_timeout(HZ * SLEEP_TIME);
410 } 418 }
411 419
412out_kill: 420out_kill:
421 __set_current_state(TASK_RUNNING);
413 if (!kthread_should_stop()) 422 if (!kthread_should_stop())
414 wait_to_die(); 423 wait_to_die();
415 424
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 6e79408674aa..2198a630ef58 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -214,12 +214,10 @@ __setup("alloc_snapshot", boot_alloc_snapshot);
214 214
215 215
216static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; 216static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
217static char *trace_boot_options __initdata;
218 217
219static int __init set_trace_boot_options(char *str) 218static int __init set_trace_boot_options(char *str)
220{ 219{
221 strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); 220 strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
222 trace_boot_options = trace_boot_options_buf;
223 return 0; 221 return 0;
224} 222}
225__setup("trace_options=", set_trace_boot_options); 223__setup("trace_options=", set_trace_boot_options);
@@ -250,6 +248,19 @@ unsigned long long ns2usecs(cycle_t nsec)
250 return nsec; 248 return nsec;
251} 249}
252 250
251/* trace_flags holds trace_options default values */
252#define TRACE_DEFAULT_FLAGS \
253 (FUNCTION_DEFAULT_FLAGS | \
254 TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | \
255 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | \
256 TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | \
257 TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS)
258
259/* trace_options that are only supported by global_trace */
260#define TOP_LEVEL_TRACE_FLAGS (TRACE_ITER_PRINTK | \
261 TRACE_ITER_PRINTK_MSGONLY | TRACE_ITER_RECORD_CMD)
262
263
253/* 264/*
254 * The global_trace is the descriptor that holds the tracing 265 * The global_trace is the descriptor that holds the tracing
255 * buffers for the live tracing. For each CPU, it contains 266 * buffers for the live tracing. For each CPU, it contains
@@ -262,7 +273,9 @@ unsigned long long ns2usecs(cycle_t nsec)
262 * pages for the buffer for that CPU. Each CPU has the same number 273 * pages for the buffer for that CPU. Each CPU has the same number
263 * of pages allocated for its buffer. 274 * of pages allocated for its buffer.
264 */ 275 */
265static struct trace_array global_trace; 276static struct trace_array global_trace = {
277 .trace_flags = TRACE_DEFAULT_FLAGS,
278};
266 279
267LIST_HEAD(ftrace_trace_arrays); 280LIST_HEAD(ftrace_trace_arrays);
268 281
@@ -468,11 +481,29 @@ static inline void trace_access_lock_init(void)
468 481
469#endif 482#endif
470 483
471/* trace_flags holds trace_options default values */ 484#ifdef CONFIG_STACKTRACE
472unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | 485static void __ftrace_trace_stack(struct ring_buffer *buffer,
473 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | 486 unsigned long flags,
474 TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | 487 int skip, int pc, struct pt_regs *regs);
475 TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION; 488static inline void ftrace_trace_stack(struct trace_array *tr,
489 struct ring_buffer *buffer,
490 unsigned long flags,
491 int skip, int pc, struct pt_regs *regs);
492
493#else
494static inline void __ftrace_trace_stack(struct ring_buffer *buffer,
495 unsigned long flags,
496 int skip, int pc, struct pt_regs *regs)
497{
498}
499static inline void ftrace_trace_stack(struct trace_array *tr,
500 struct ring_buffer *buffer,
501 unsigned long flags,
502 int skip, int pc, struct pt_regs *regs)
503{
504}
505
506#endif
476 507
477static void tracer_tracing_on(struct trace_array *tr) 508static void tracer_tracing_on(struct trace_array *tr)
478{ 509{
@@ -518,7 +549,7 @@ int __trace_puts(unsigned long ip, const char *str, int size)
518 int alloc; 549 int alloc;
519 int pc; 550 int pc;
520 551
521 if (!(trace_flags & TRACE_ITER_PRINTK)) 552 if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
522 return 0; 553 return 0;
523 554
524 pc = preempt_count(); 555 pc = preempt_count();
@@ -548,7 +579,7 @@ int __trace_puts(unsigned long ip, const char *str, int size)
548 entry->buf[size] = '\0'; 579 entry->buf[size] = '\0';
549 580
550 __buffer_unlock_commit(buffer, event); 581 __buffer_unlock_commit(buffer, event);
551 ftrace_trace_stack(buffer, irq_flags, 4, pc); 582 ftrace_trace_stack(&global_trace, buffer, irq_flags, 4, pc, NULL);
552 583
553 return size; 584 return size;
554} 585}
@@ -568,7 +599,7 @@ int __trace_bputs(unsigned long ip, const char *str)
568 int size = sizeof(struct bputs_entry); 599 int size = sizeof(struct bputs_entry);
569 int pc; 600 int pc;
570 601
571 if (!(trace_flags & TRACE_ITER_PRINTK)) 602 if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
572 return 0; 603 return 0;
573 604
574 pc = preempt_count(); 605 pc = preempt_count();
@@ -588,7 +619,7 @@ int __trace_bputs(unsigned long ip, const char *str)
588 entry->str = str; 619 entry->str = str;
589 620
590 __buffer_unlock_commit(buffer, event); 621 __buffer_unlock_commit(buffer, event);
591 ftrace_trace_stack(buffer, irq_flags, 4, pc); 622 ftrace_trace_stack(&global_trace, buffer, irq_flags, 4, pc, NULL);
592 623
593 return 1; 624 return 1;
594} 625}
@@ -834,34 +865,18 @@ unsigned long nsecs_to_usecs(unsigned long nsecs)
834 return nsecs / 1000; 865 return nsecs / 1000;
835} 866}
836 867
868/*
869 * TRACE_FLAGS is defined as a tuple matching bit masks with strings.
870 * It uses C(a, b) where 'a' is the enum name and 'b' is the string that
871 * matches it. By defining "C(a, b) b", TRACE_FLAGS becomes a list
872 * of strings in the order that the enums were defined.
873 */
874#undef C
875#define C(a, b) b
876
837/* These must match the bit postions in trace_iterator_flags */ 877/* These must match the bit postions in trace_iterator_flags */
838static const char *trace_options[] = { 878static const char *trace_options[] = {
839 "print-parent", 879 TRACE_FLAGS
840 "sym-offset",
841 "sym-addr",
842 "verbose",
843 "raw",
844 "hex",
845 "bin",
846 "block",
847 "stacktrace",
848 "trace_printk",
849 "ftrace_preempt",
850 "branch",
851 "annotate",
852 "userstacktrace",
853 "sym-userobj",
854 "printk-msg-only",
855 "context-info",
856 "latency-format",
857 "sleep-time",
858 "graph-time",
859 "record-cmd",
860 "overwrite",
861 "disable_on_free",
862 "irq-info",
863 "markers",
864 "function-trace",
865 NULL 880 NULL
866}; 881};
867 882
@@ -1204,13 +1219,17 @@ static inline int run_tracer_selftest(struct tracer *type)
1204} 1219}
1205#endif /* CONFIG_FTRACE_STARTUP_TEST */ 1220#endif /* CONFIG_FTRACE_STARTUP_TEST */
1206 1221
1222static void add_tracer_options(struct trace_array *tr, struct tracer *t);
1223
1224static void __init apply_trace_boot_options(void);
1225
1207/** 1226/**
1208 * register_tracer - register a tracer with the ftrace system. 1227 * register_tracer - register a tracer with the ftrace system.
1209 * @type - the plugin for the tracer 1228 * @type - the plugin for the tracer
1210 * 1229 *
1211 * Register a new plugin tracer. 1230 * Register a new plugin tracer.
1212 */ 1231 */
1213int register_tracer(struct tracer *type) 1232int __init register_tracer(struct tracer *type)
1214{ 1233{
1215 struct tracer *t; 1234 struct tracer *t;
1216 int ret = 0; 1235 int ret = 0;
@@ -1253,6 +1272,7 @@ int register_tracer(struct tracer *type)
1253 1272
1254 type->next = trace_types; 1273 type->next = trace_types;
1255 trace_types = type; 1274 trace_types = type;
1275 add_tracer_options(&global_trace, type);
1256 1276
1257 out: 1277 out:
1258 tracing_selftest_running = false; 1278 tracing_selftest_running = false;
@@ -1268,6 +1288,9 @@ int register_tracer(struct tracer *type)
1268 /* Do we want this tracer to start on bootup? */ 1288 /* Do we want this tracer to start on bootup? */
1269 tracing_set_tracer(&global_trace, type->name); 1289 tracing_set_tracer(&global_trace, type->name);
1270 default_bootup_tracer = NULL; 1290 default_bootup_tracer = NULL;
1291
1292 apply_trace_boot_options();
1293
1271 /* disable other selftests, since this will break it. */ 1294 /* disable other selftests, since this will break it. */
1272 tracing_selftest_disabled = true; 1295 tracing_selftest_disabled = true;
1273#ifdef CONFIG_FTRACE_STARTUP_TEST 1296#ifdef CONFIG_FTRACE_STARTUP_TEST
@@ -1671,23 +1694,16 @@ __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *eve
1671 ring_buffer_unlock_commit(buffer, event); 1694 ring_buffer_unlock_commit(buffer, event);
1672} 1695}
1673 1696
1674static inline void 1697void trace_buffer_unlock_commit(struct trace_array *tr,
1675__trace_buffer_unlock_commit(struct ring_buffer *buffer, 1698 struct ring_buffer *buffer,
1676 struct ring_buffer_event *event, 1699 struct ring_buffer_event *event,
1677 unsigned long flags, int pc) 1700 unsigned long flags, int pc)
1678{ 1701{
1679 __buffer_unlock_commit(buffer, event); 1702 __buffer_unlock_commit(buffer, event);
1680 1703
1681 ftrace_trace_stack(buffer, flags, 6, pc); 1704 ftrace_trace_stack(tr, buffer, flags, 6, pc, NULL);
1682 ftrace_trace_userstack(buffer, flags, pc); 1705 ftrace_trace_userstack(buffer, flags, pc);
1683} 1706}
1684
1685void trace_buffer_unlock_commit(struct ring_buffer *buffer,
1686 struct ring_buffer_event *event,
1687 unsigned long flags, int pc)
1688{
1689 __trace_buffer_unlock_commit(buffer, event, flags, pc);
1690}
1691EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); 1707EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit);
1692 1708
1693static struct ring_buffer *temp_buffer; 1709static struct ring_buffer *temp_buffer;
@@ -1729,22 +1745,15 @@ trace_current_buffer_lock_reserve(struct ring_buffer **current_rb,
1729} 1745}
1730EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); 1746EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve);
1731 1747
1732void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, 1748void trace_buffer_unlock_commit_regs(struct trace_array *tr,
1733 struct ring_buffer_event *event, 1749 struct ring_buffer *buffer,
1734 unsigned long flags, int pc)
1735{
1736 __trace_buffer_unlock_commit(buffer, event, flags, pc);
1737}
1738EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit);
1739
1740void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer,
1741 struct ring_buffer_event *event, 1750 struct ring_buffer_event *event,
1742 unsigned long flags, int pc, 1751 unsigned long flags, int pc,
1743 struct pt_regs *regs) 1752 struct pt_regs *regs)
1744{ 1753{
1745 __buffer_unlock_commit(buffer, event); 1754 __buffer_unlock_commit(buffer, event);
1746 1755
1747 ftrace_trace_stack_regs(buffer, flags, 0, pc, regs); 1756 ftrace_trace_stack(tr, buffer, flags, 6, pc, regs);
1748 ftrace_trace_userstack(buffer, flags, pc); 1757 ftrace_trace_userstack(buffer, flags, pc);
1749} 1758}
1750EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); 1759EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs);
@@ -1873,24 +1882,17 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
1873 1882
1874} 1883}
1875 1884
1876void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, 1885static inline void ftrace_trace_stack(struct trace_array *tr,
1877 int skip, int pc, struct pt_regs *regs) 1886 struct ring_buffer *buffer,
1887 unsigned long flags,
1888 int skip, int pc, struct pt_regs *regs)
1878{ 1889{
1879 if (!(trace_flags & TRACE_ITER_STACKTRACE)) 1890 if (!(tr->trace_flags & TRACE_ITER_STACKTRACE))
1880 return; 1891 return;
1881 1892
1882 __ftrace_trace_stack(buffer, flags, skip, pc, regs); 1893 __ftrace_trace_stack(buffer, flags, skip, pc, regs);
1883} 1894}
1884 1895
1885void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
1886 int skip, int pc)
1887{
1888 if (!(trace_flags & TRACE_ITER_STACKTRACE))
1889 return;
1890
1891 __ftrace_trace_stack(buffer, flags, skip, pc, NULL);
1892}
1893
1894void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, 1896void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
1895 int pc) 1897 int pc)
1896{ 1898{
@@ -1929,7 +1931,7 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
1929 struct userstack_entry *entry; 1931 struct userstack_entry *entry;
1930 struct stack_trace trace; 1932 struct stack_trace trace;
1931 1933
1932 if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) 1934 if (!(global_trace.trace_flags & TRACE_ITER_USERSTACKTRACE))
1933 return; 1935 return;
1934 1936
1935 /* 1937 /*
@@ -2173,7 +2175,7 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
2173 memcpy(entry->buf, tbuffer, sizeof(u32) * len); 2175 memcpy(entry->buf, tbuffer, sizeof(u32) * len);
2174 if (!call_filter_check_discard(call, entry, buffer, event)) { 2176 if (!call_filter_check_discard(call, entry, buffer, event)) {
2175 __buffer_unlock_commit(buffer, event); 2177 __buffer_unlock_commit(buffer, event);
2176 ftrace_trace_stack(buffer, flags, 6, pc); 2178 ftrace_trace_stack(tr, buffer, flags, 6, pc, NULL);
2177 } 2179 }
2178 2180
2179out: 2181out:
@@ -2225,7 +2227,7 @@ __trace_array_vprintk(struct ring_buffer *buffer,
2225 memcpy(&entry->buf, tbuffer, len + 1); 2227 memcpy(&entry->buf, tbuffer, len + 1);
2226 if (!call_filter_check_discard(call, entry, buffer, event)) { 2228 if (!call_filter_check_discard(call, entry, buffer, event)) {
2227 __buffer_unlock_commit(buffer, event); 2229 __buffer_unlock_commit(buffer, event);
2228 ftrace_trace_stack(buffer, flags, 6, pc); 2230 ftrace_trace_stack(&global_trace, buffer, flags, 6, pc, NULL);
2229 } 2231 }
2230 out: 2232 out:
2231 preempt_enable_notrace(); 2233 preempt_enable_notrace();
@@ -2246,7 +2248,7 @@ int trace_array_printk(struct trace_array *tr,
2246 int ret; 2248 int ret;
2247 va_list ap; 2249 va_list ap;
2248 2250
2249 if (!(trace_flags & TRACE_ITER_PRINTK)) 2251 if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
2250 return 0; 2252 return 0;
2251 2253
2252 va_start(ap, fmt); 2254 va_start(ap, fmt);
@@ -2261,7 +2263,7 @@ int trace_array_printk_buf(struct ring_buffer *buffer,
2261 int ret; 2263 int ret;
2262 va_list ap; 2264 va_list ap;
2263 2265
2264 if (!(trace_flags & TRACE_ITER_PRINTK)) 2266 if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
2265 return 0; 2267 return 0;
2266 2268
2267 va_start(ap, fmt); 2269 va_start(ap, fmt);
@@ -2602,7 +2604,7 @@ static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file
2602void 2604void
2603print_trace_header(struct seq_file *m, struct trace_iterator *iter) 2605print_trace_header(struct seq_file *m, struct trace_iterator *iter)
2604{ 2606{
2605 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); 2607 unsigned long sym_flags = (global_trace.trace_flags & TRACE_ITER_SYM_MASK);
2606 struct trace_buffer *buf = iter->trace_buffer; 2608 struct trace_buffer *buf = iter->trace_buffer;
2607 struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); 2609 struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu);
2608 struct tracer *type = iter->trace; 2610 struct tracer *type = iter->trace;
@@ -2664,20 +2666,22 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter)
2664static void test_cpu_buff_start(struct trace_iterator *iter) 2666static void test_cpu_buff_start(struct trace_iterator *iter)
2665{ 2667{
2666 struct trace_seq *s = &iter->seq; 2668 struct trace_seq *s = &iter->seq;
2669 struct trace_array *tr = iter->tr;
2667 2670
2668 if (!(trace_flags & TRACE_ITER_ANNOTATE)) 2671 if (!(tr->trace_flags & TRACE_ITER_ANNOTATE))
2669 return; 2672 return;
2670 2673
2671 if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) 2674 if (!(iter->iter_flags & TRACE_FILE_ANNOTATE))
2672 return; 2675 return;
2673 2676
2674 if (cpumask_test_cpu(iter->cpu, iter->started)) 2677 if (iter->started && cpumask_test_cpu(iter->cpu, iter->started))
2675 return; 2678 return;
2676 2679
2677 if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) 2680 if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries)
2678 return; 2681 return;
2679 2682
2680 cpumask_set_cpu(iter->cpu, iter->started); 2683 if (iter->started)
2684 cpumask_set_cpu(iter->cpu, iter->started);
2681 2685
2682 /* Don't print started cpu buffer for the first entry of the trace */ 2686 /* Don't print started cpu buffer for the first entry of the trace */
2683 if (iter->idx > 1) 2687 if (iter->idx > 1)
@@ -2687,8 +2691,9 @@ static void test_cpu_buff_start(struct trace_iterator *iter)
2687 2691
2688static enum print_line_t print_trace_fmt(struct trace_iterator *iter) 2692static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
2689{ 2693{
2694 struct trace_array *tr = iter->tr;
2690 struct trace_seq *s = &iter->seq; 2695 struct trace_seq *s = &iter->seq;
2691 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); 2696 unsigned long sym_flags = (tr->trace_flags & TRACE_ITER_SYM_MASK);
2692 struct trace_entry *entry; 2697 struct trace_entry *entry;
2693 struct trace_event *event; 2698 struct trace_event *event;
2694 2699
@@ -2698,7 +2703,7 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
2698 2703
2699 event = ftrace_find_event(entry->type); 2704 event = ftrace_find_event(entry->type);
2700 2705
2701 if (trace_flags & TRACE_ITER_CONTEXT_INFO) { 2706 if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO) {
2702 if (iter->iter_flags & TRACE_FILE_LAT_FMT) 2707 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2703 trace_print_lat_context(iter); 2708 trace_print_lat_context(iter);
2704 else 2709 else
@@ -2718,13 +2723,14 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
2718 2723
2719static enum print_line_t print_raw_fmt(struct trace_iterator *iter) 2724static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
2720{ 2725{
2726 struct trace_array *tr = iter->tr;
2721 struct trace_seq *s = &iter->seq; 2727 struct trace_seq *s = &iter->seq;
2722 struct trace_entry *entry; 2728 struct trace_entry *entry;
2723 struct trace_event *event; 2729 struct trace_event *event;
2724 2730
2725 entry = iter->ent; 2731 entry = iter->ent;
2726 2732
2727 if (trace_flags & TRACE_ITER_CONTEXT_INFO) 2733 if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO)
2728 trace_seq_printf(s, "%d %d %llu ", 2734 trace_seq_printf(s, "%d %d %llu ",
2729 entry->pid, iter->cpu, iter->ts); 2735 entry->pid, iter->cpu, iter->ts);
2730 2736
@@ -2742,6 +2748,7 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
2742 2748
2743static enum print_line_t print_hex_fmt(struct trace_iterator *iter) 2749static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2744{ 2750{
2751 struct trace_array *tr = iter->tr;
2745 struct trace_seq *s = &iter->seq; 2752 struct trace_seq *s = &iter->seq;
2746 unsigned char newline = '\n'; 2753 unsigned char newline = '\n';
2747 struct trace_entry *entry; 2754 struct trace_entry *entry;
@@ -2749,7 +2756,7 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2749 2756
2750 entry = iter->ent; 2757 entry = iter->ent;
2751 2758
2752 if (trace_flags & TRACE_ITER_CONTEXT_INFO) { 2759 if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO) {
2753 SEQ_PUT_HEX_FIELD(s, entry->pid); 2760 SEQ_PUT_HEX_FIELD(s, entry->pid);
2754 SEQ_PUT_HEX_FIELD(s, iter->cpu); 2761 SEQ_PUT_HEX_FIELD(s, iter->cpu);
2755 SEQ_PUT_HEX_FIELD(s, iter->ts); 2762 SEQ_PUT_HEX_FIELD(s, iter->ts);
@@ -2771,13 +2778,14 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2771 2778
2772static enum print_line_t print_bin_fmt(struct trace_iterator *iter) 2779static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
2773{ 2780{
2781 struct trace_array *tr = iter->tr;
2774 struct trace_seq *s = &iter->seq; 2782 struct trace_seq *s = &iter->seq;
2775 struct trace_entry *entry; 2783 struct trace_entry *entry;
2776 struct trace_event *event; 2784 struct trace_event *event;
2777 2785
2778 entry = iter->ent; 2786 entry = iter->ent;
2779 2787
2780 if (trace_flags & TRACE_ITER_CONTEXT_INFO) { 2788 if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO) {
2781 SEQ_PUT_FIELD(s, entry->pid); 2789 SEQ_PUT_FIELD(s, entry->pid);
2782 SEQ_PUT_FIELD(s, iter->cpu); 2790 SEQ_PUT_FIELD(s, iter->cpu);
2783 SEQ_PUT_FIELD(s, iter->ts); 2791 SEQ_PUT_FIELD(s, iter->ts);
@@ -2826,6 +2834,8 @@ int trace_empty(struct trace_iterator *iter)
2826/* Called with trace_event_read_lock() held. */ 2834/* Called with trace_event_read_lock() held. */
2827enum print_line_t print_trace_line(struct trace_iterator *iter) 2835enum print_line_t print_trace_line(struct trace_iterator *iter)
2828{ 2836{
2837 struct trace_array *tr = iter->tr;
2838 unsigned long trace_flags = tr->trace_flags;
2829 enum print_line_t ret; 2839 enum print_line_t ret;
2830 2840
2831 if (iter->lost_events) { 2841 if (iter->lost_events) {
@@ -2871,6 +2881,7 @@ enum print_line_t print_trace_line(struct trace_iterator *iter)
2871void trace_latency_header(struct seq_file *m) 2881void trace_latency_header(struct seq_file *m)
2872{ 2882{
2873 struct trace_iterator *iter = m->private; 2883 struct trace_iterator *iter = m->private;
2884 struct trace_array *tr = iter->tr;
2874 2885
2875 /* print nothing if the buffers are empty */ 2886 /* print nothing if the buffers are empty */
2876 if (trace_empty(iter)) 2887 if (trace_empty(iter))
@@ -2879,13 +2890,15 @@ void trace_latency_header(struct seq_file *m)
2879 if (iter->iter_flags & TRACE_FILE_LAT_FMT) 2890 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2880 print_trace_header(m, iter); 2891 print_trace_header(m, iter);
2881 2892
2882 if (!(trace_flags & TRACE_ITER_VERBOSE)) 2893 if (!(tr->trace_flags & TRACE_ITER_VERBOSE))
2883 print_lat_help_header(m); 2894 print_lat_help_header(m);
2884} 2895}
2885 2896
2886void trace_default_header(struct seq_file *m) 2897void trace_default_header(struct seq_file *m)
2887{ 2898{
2888 struct trace_iterator *iter = m->private; 2899 struct trace_iterator *iter = m->private;
2900 struct trace_array *tr = iter->tr;
2901 unsigned long trace_flags = tr->trace_flags;
2889 2902
2890 if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) 2903 if (!(trace_flags & TRACE_ITER_CONTEXT_INFO))
2891 return; 2904 return;
@@ -3230,7 +3243,7 @@ static int tracing_open(struct inode *inode, struct file *file)
3230 iter = __tracing_open(inode, file, false); 3243 iter = __tracing_open(inode, file, false);
3231 if (IS_ERR(iter)) 3244 if (IS_ERR(iter))
3232 ret = PTR_ERR(iter); 3245 ret = PTR_ERR(iter);
3233 else if (trace_flags & TRACE_ITER_LATENCY_FMT) 3246 else if (tr->trace_flags & TRACE_ITER_LATENCY_FMT)
3234 iter->iter_flags |= TRACE_FILE_LAT_FMT; 3247 iter->iter_flags |= TRACE_FILE_LAT_FMT;
3235 } 3248 }
3236 3249
@@ -3477,7 +3490,7 @@ static int tracing_trace_options_show(struct seq_file *m, void *v)
3477 trace_opts = tr->current_trace->flags->opts; 3490 trace_opts = tr->current_trace->flags->opts;
3478 3491
3479 for (i = 0; trace_options[i]; i++) { 3492 for (i = 0; trace_options[i]; i++) {
3480 if (trace_flags & (1 << i)) 3493 if (tr->trace_flags & (1 << i))
3481 seq_printf(m, "%s\n", trace_options[i]); 3494 seq_printf(m, "%s\n", trace_options[i]);
3482 else 3495 else
3483 seq_printf(m, "no%s\n", trace_options[i]); 3496 seq_printf(m, "no%s\n", trace_options[i]);
@@ -3542,7 +3555,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
3542int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) 3555int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
3543{ 3556{
3544 /* do nothing if flag is already set */ 3557 /* do nothing if flag is already set */
3545 if (!!(trace_flags & mask) == !!enabled) 3558 if (!!(tr->trace_flags & mask) == !!enabled)
3546 return 0; 3559 return 0;
3547 3560
3548 /* Give the tracer a chance to approve the change */ 3561 /* Give the tracer a chance to approve the change */
@@ -3551,9 +3564,9 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
3551 return -EINVAL; 3564 return -EINVAL;
3552 3565
3553 if (enabled) 3566 if (enabled)
3554 trace_flags |= mask; 3567 tr->trace_flags |= mask;
3555 else 3568 else
3556 trace_flags &= ~mask; 3569 tr->trace_flags &= ~mask;
3557 3570
3558 if (mask == TRACE_ITER_RECORD_CMD) 3571 if (mask == TRACE_ITER_RECORD_CMD)
3559 trace_event_enable_cmd_record(enabled); 3572 trace_event_enable_cmd_record(enabled);
@@ -3565,8 +3578,10 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
3565#endif 3578#endif
3566 } 3579 }
3567 3580
3568 if (mask == TRACE_ITER_PRINTK) 3581 if (mask == TRACE_ITER_PRINTK) {
3569 trace_printk_start_stop_comm(enabled); 3582 trace_printk_start_stop_comm(enabled);
3583 trace_printk_control(enabled);
3584 }
3570 3585
3571 return 0; 3586 return 0;
3572} 3587}
@@ -3577,6 +3592,7 @@ static int trace_set_options(struct trace_array *tr, char *option)
3577 int neg = 0; 3592 int neg = 0;
3578 int ret = -ENODEV; 3593 int ret = -ENODEV;
3579 int i; 3594 int i;
3595 size_t orig_len = strlen(option);
3580 3596
3581 cmp = strstrip(option); 3597 cmp = strstrip(option);
3582 3598
@@ -3600,9 +3616,36 @@ static int trace_set_options(struct trace_array *tr, char *option)
3600 3616
3601 mutex_unlock(&trace_types_lock); 3617 mutex_unlock(&trace_types_lock);
3602 3618
3619 /*
3620 * If the first trailing whitespace is replaced with '\0' by strstrip,
3621 * turn it back into a space.
3622 */
3623 if (orig_len > strlen(option))
3624 option[strlen(option)] = ' ';
3625
3603 return ret; 3626 return ret;
3604} 3627}
3605 3628
3629static void __init apply_trace_boot_options(void)
3630{
3631 char *buf = trace_boot_options_buf;
3632 char *option;
3633
3634 while (true) {
3635 option = strsep(&buf, ",");
3636
3637 if (!option)
3638 break;
3639
3640 if (*option)
3641 trace_set_options(&global_trace, option);
3642
3643 /* Put back the comma to allow this to be called again */
3644 if (buf)
3645 *(buf - 1) = ',';
3646 }
3647}
3648
3606static ssize_t 3649static ssize_t
3607tracing_trace_options_write(struct file *filp, const char __user *ubuf, 3650tracing_trace_options_write(struct file *filp, const char __user *ubuf,
3608 size_t cnt, loff_t *ppos) 3651 size_t cnt, loff_t *ppos)
@@ -4297,11 +4340,8 @@ int tracing_update_buffers(void)
4297 4340
4298struct trace_option_dentry; 4341struct trace_option_dentry;
4299 4342
4300static struct trace_option_dentry *
4301create_trace_option_files(struct trace_array *tr, struct tracer *tracer);
4302
4303static void 4343static void
4304destroy_trace_option_files(struct trace_option_dentry *topts); 4344create_trace_option_files(struct trace_array *tr, struct tracer *tracer);
4305 4345
4306/* 4346/*
4307 * Used to clear out the tracer before deletion of an instance. 4347 * Used to clear out the tracer before deletion of an instance.
@@ -4320,20 +4360,13 @@ static void tracing_set_nop(struct trace_array *tr)
4320 tr->current_trace = &nop_trace; 4360 tr->current_trace = &nop_trace;
4321} 4361}
4322 4362
4323static void update_tracer_options(struct trace_array *tr, struct tracer *t) 4363static void add_tracer_options(struct trace_array *tr, struct tracer *t)
4324{ 4364{
4325 static struct trace_option_dentry *topts;
4326
4327 /* Only enable if the directory has been created already. */ 4365 /* Only enable if the directory has been created already. */
4328 if (!tr->dir) 4366 if (!tr->dir)
4329 return; 4367 return;
4330 4368
4331 /* Currently, only the top instance has options */ 4369 create_trace_option_files(tr, t);
4332 if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL))
4333 return;
4334
4335 destroy_trace_option_files(topts);
4336 topts = create_trace_option_files(tr, t);
4337} 4370}
4338 4371
4339static int tracing_set_tracer(struct trace_array *tr, const char *buf) 4372static int tracing_set_tracer(struct trace_array *tr, const char *buf)
@@ -4402,7 +4435,6 @@ static int tracing_set_tracer(struct trace_array *tr, const char *buf)
4402 free_snapshot(tr); 4435 free_snapshot(tr);
4403 } 4436 }
4404#endif 4437#endif
4405 update_tracer_options(tr, t);
4406 4438
4407#ifdef CONFIG_TRACER_MAX_TRACE 4439#ifdef CONFIG_TRACER_MAX_TRACE
4408 if (t->use_max_tr && !had_max_tr) { 4440 if (t->use_max_tr && !had_max_tr) {
@@ -4569,7 +4601,7 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
4569 /* trace pipe does not show start of buffer */ 4601 /* trace pipe does not show start of buffer */
4570 cpumask_setall(iter->started); 4602 cpumask_setall(iter->started);
4571 4603
4572 if (trace_flags & TRACE_ITER_LATENCY_FMT) 4604 if (tr->trace_flags & TRACE_ITER_LATENCY_FMT)
4573 iter->iter_flags |= TRACE_FILE_LAT_FMT; 4605 iter->iter_flags |= TRACE_FILE_LAT_FMT;
4574 4606
4575 /* Output in nanoseconds only if we are using a clock in nanoseconds. */ 4607 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
@@ -4626,11 +4658,13 @@ static int tracing_release_pipe(struct inode *inode, struct file *file)
4626static unsigned int 4658static unsigned int
4627trace_poll(struct trace_iterator *iter, struct file *filp, poll_table *poll_table) 4659trace_poll(struct trace_iterator *iter, struct file *filp, poll_table *poll_table)
4628{ 4660{
4661 struct trace_array *tr = iter->tr;
4662
4629 /* Iterators are static, they should be filled or empty */ 4663 /* Iterators are static, they should be filled or empty */
4630 if (trace_buffer_iter(iter, iter->cpu_file)) 4664 if (trace_buffer_iter(iter, iter->cpu_file))
4631 return POLLIN | POLLRDNORM; 4665 return POLLIN | POLLRDNORM;
4632 4666
4633 if (trace_flags & TRACE_ITER_BLOCK) 4667 if (tr->trace_flags & TRACE_ITER_BLOCK)
4634 /* 4668 /*
4635 * Always select as readable when in blocking mode 4669 * Always select as readable when in blocking mode
4636 */ 4670 */
@@ -5047,7 +5081,7 @@ tracing_free_buffer_release(struct inode *inode, struct file *filp)
5047 struct trace_array *tr = inode->i_private; 5081 struct trace_array *tr = inode->i_private;
5048 5082
5049 /* disable tracing ? */ 5083 /* disable tracing ? */
5050 if (trace_flags & TRACE_ITER_STOP_ON_FREE) 5084 if (tr->trace_flags & TRACE_ITER_STOP_ON_FREE)
5051 tracer_tracing_off(tr); 5085 tracer_tracing_off(tr);
5052 /* resize the ring buffer to 0 */ 5086 /* resize the ring buffer to 0 */
5053 tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); 5087 tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS);
@@ -5080,7 +5114,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
5080 if (tracing_disabled) 5114 if (tracing_disabled)
5081 return -EINVAL; 5115 return -EINVAL;
5082 5116
5083 if (!(trace_flags & TRACE_ITER_MARKERS)) 5117 if (!(tr->trace_flags & TRACE_ITER_MARKERS))
5084 return -EINVAL; 5118 return -EINVAL;
5085 5119
5086 if (cnt > TRACE_BUF_SIZE) 5120 if (cnt > TRACE_BUF_SIZE)
@@ -6132,13 +6166,6 @@ tracing_init_tracefs_percpu(struct trace_array *tr, long cpu)
6132#include "trace_selftest.c" 6166#include "trace_selftest.c"
6133#endif 6167#endif
6134 6168
6135struct trace_option_dentry {
6136 struct tracer_opt *opt;
6137 struct tracer_flags *flags;
6138 struct trace_array *tr;
6139 struct dentry *entry;
6140};
6141
6142static ssize_t 6169static ssize_t
6143trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, 6170trace_options_read(struct file *filp, char __user *ubuf, size_t cnt,
6144 loff_t *ppos) 6171 loff_t *ppos)
@@ -6191,14 +6218,51 @@ static const struct file_operations trace_options_fops = {
6191 .llseek = generic_file_llseek, 6218 .llseek = generic_file_llseek,
6192}; 6219};
6193 6220
6221/*
6222 * In order to pass in both the trace_array descriptor as well as the index
6223 * to the flag that the trace option file represents, the trace_array
6224 * has a character array of trace_flags_index[], which holds the index
6225 * of the bit for the flag it represents. index[0] == 0, index[1] == 1, etc.
6226 * The address of this character array is passed to the flag option file
6227 * read/write callbacks.
6228 *
6229 * In order to extract both the index and the trace_array descriptor,
6230 * get_tr_index() uses the following algorithm.
6231 *
6232 * idx = *ptr;
6233 *
6234 * As the pointer itself contains the address of the index (remember
6235 * index[1] == 1).
6236 *
6237 * Then to get the trace_array descriptor, by subtracting that index
6238 * from the ptr, we get to the start of the index itself.
6239 *
6240 * ptr - idx == &index[0]
6241 *
6242 * Then a simple container_of() from that pointer gets us to the
6243 * trace_array descriptor.
6244 */
6245static void get_tr_index(void *data, struct trace_array **ptr,
6246 unsigned int *pindex)
6247{
6248 *pindex = *(unsigned char *)data;
6249
6250 *ptr = container_of(data - *pindex, struct trace_array,
6251 trace_flags_index);
6252}
6253
6194static ssize_t 6254static ssize_t
6195trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, 6255trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt,
6196 loff_t *ppos) 6256 loff_t *ppos)
6197{ 6257{
6198 long index = (long)filp->private_data; 6258 void *tr_index = filp->private_data;
6259 struct trace_array *tr;
6260 unsigned int index;
6199 char *buf; 6261 char *buf;
6200 6262
6201 if (trace_flags & (1 << index)) 6263 get_tr_index(tr_index, &tr, &index);
6264
6265 if (tr->trace_flags & (1 << index))
6202 buf = "1\n"; 6266 buf = "1\n";
6203 else 6267 else
6204 buf = "0\n"; 6268 buf = "0\n";
@@ -6210,11 +6274,14 @@ static ssize_t
6210trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, 6274trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
6211 loff_t *ppos) 6275 loff_t *ppos)
6212{ 6276{
6213 struct trace_array *tr = &global_trace; 6277 void *tr_index = filp->private_data;
6214 long index = (long)filp->private_data; 6278 struct trace_array *tr;
6279 unsigned int index;
6215 unsigned long val; 6280 unsigned long val;
6216 int ret; 6281 int ret;
6217 6282
6283 get_tr_index(tr_index, &tr, &index);
6284
6218 ret = kstrtoul_from_user(ubuf, cnt, 10, &val); 6285 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
6219 if (ret) 6286 if (ret)
6220 return ret; 6287 return ret;
@@ -6298,21 +6365,39 @@ create_trace_option_file(struct trace_array *tr,
6298 6365
6299} 6366}
6300 6367
6301static struct trace_option_dentry * 6368static void
6302create_trace_option_files(struct trace_array *tr, struct tracer *tracer) 6369create_trace_option_files(struct trace_array *tr, struct tracer *tracer)
6303{ 6370{
6304 struct trace_option_dentry *topts; 6371 struct trace_option_dentry *topts;
6372 struct trace_options *tr_topts;
6305 struct tracer_flags *flags; 6373 struct tracer_flags *flags;
6306 struct tracer_opt *opts; 6374 struct tracer_opt *opts;
6307 int cnt; 6375 int cnt;
6376 int i;
6308 6377
6309 if (!tracer) 6378 if (!tracer)
6310 return NULL; 6379 return;
6311 6380
6312 flags = tracer->flags; 6381 flags = tracer->flags;
6313 6382
6314 if (!flags || !flags->opts) 6383 if (!flags || !flags->opts)
6315 return NULL; 6384 return;
6385
6386 /*
6387 * If this is an instance, only create flags for tracers
6388 * the instance may have.
6389 */
6390 if (!trace_ok_for_array(tracer, tr))
6391 return;
6392
6393 for (i = 0; i < tr->nr_topts; i++) {
6394 /*
6395 * Check if these flags have already been added.
6396 * Some tracers share flags.
6397 */
6398 if (tr->topts[i].tracer->flags == tracer->flags)
6399 return;
6400 }
6316 6401
6317 opts = flags->opts; 6402 opts = flags->opts;
6318 6403
@@ -6321,27 +6406,27 @@ create_trace_option_files(struct trace_array *tr, struct tracer *tracer)
6321 6406
6322 topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); 6407 topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL);
6323 if (!topts) 6408 if (!topts)
6324 return NULL; 6409 return;
6325
6326 for (cnt = 0; opts[cnt].name; cnt++)
6327 create_trace_option_file(tr, &topts[cnt], flags,
6328 &opts[cnt]);
6329
6330 return topts;
6331}
6332
6333static void
6334destroy_trace_option_files(struct trace_option_dentry *topts)
6335{
6336 int cnt;
6337 6410
6338 if (!topts) 6411 tr_topts = krealloc(tr->topts, sizeof(*tr->topts) * (tr->nr_topts + 1),
6412 GFP_KERNEL);
6413 if (!tr_topts) {
6414 kfree(topts);
6339 return; 6415 return;
6416 }
6340 6417
6341 for (cnt = 0; topts[cnt].opt; cnt++) 6418 tr->topts = tr_topts;
6342 tracefs_remove(topts[cnt].entry); 6419 tr->topts[tr->nr_topts].tracer = tracer;
6420 tr->topts[tr->nr_topts].topts = topts;
6421 tr->nr_topts++;
6343 6422
6344 kfree(topts); 6423 for (cnt = 0; opts[cnt].name; cnt++) {
6424 create_trace_option_file(tr, &topts[cnt], flags,
6425 &opts[cnt]);
6426 WARN_ONCE(topts[cnt].entry == NULL,
6427 "Failed to create trace option: %s",
6428 opts[cnt].name);
6429 }
6345} 6430}
6346 6431
6347static struct dentry * 6432static struct dentry *
@@ -6354,21 +6439,26 @@ create_trace_option_core_file(struct trace_array *tr,
6354 if (!t_options) 6439 if (!t_options)
6355 return NULL; 6440 return NULL;
6356 6441
6357 return trace_create_file(option, 0644, t_options, (void *)index, 6442 return trace_create_file(option, 0644, t_options,
6358 &trace_options_core_fops); 6443 (void *)&tr->trace_flags_index[index],
6444 &trace_options_core_fops);
6359} 6445}
6360 6446
6361static __init void create_trace_options_dir(struct trace_array *tr) 6447static void create_trace_options_dir(struct trace_array *tr)
6362{ 6448{
6363 struct dentry *t_options; 6449 struct dentry *t_options;
6450 bool top_level = tr == &global_trace;
6364 int i; 6451 int i;
6365 6452
6366 t_options = trace_options_init_dentry(tr); 6453 t_options = trace_options_init_dentry(tr);
6367 if (!t_options) 6454 if (!t_options)
6368 return; 6455 return;
6369 6456
6370 for (i = 0; trace_options[i]; i++) 6457 for (i = 0; trace_options[i]; i++) {
6371 create_trace_option_core_file(tr, trace_options[i], i); 6458 if (top_level ||
6459 !((1 << i) & TOP_LEVEL_TRACE_FLAGS))
6460 create_trace_option_core_file(tr, trace_options[i], i);
6461 }
6372} 6462}
6373 6463
6374static ssize_t 6464static ssize_t
@@ -6435,7 +6525,7 @@ allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size
6435{ 6525{
6436 enum ring_buffer_flags rb_flags; 6526 enum ring_buffer_flags rb_flags;
6437 6527
6438 rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; 6528 rb_flags = tr->trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0;
6439 6529
6440 buf->tr = tr; 6530 buf->tr = tr;
6441 6531
@@ -6505,6 +6595,30 @@ static void free_trace_buffers(struct trace_array *tr)
6505#endif 6595#endif
6506} 6596}
6507 6597
6598static void init_trace_flags_index(struct trace_array *tr)
6599{
6600 int i;
6601
6602 /* Used by the trace options files */
6603 for (i = 0; i < TRACE_FLAGS_MAX_SIZE; i++)
6604 tr->trace_flags_index[i] = i;
6605}
6606
6607static void __update_tracer_options(struct trace_array *tr)
6608{
6609 struct tracer *t;
6610
6611 for (t = trace_types; t; t = t->next)
6612 add_tracer_options(tr, t);
6613}
6614
6615static void update_tracer_options(struct trace_array *tr)
6616{
6617 mutex_lock(&trace_types_lock);
6618 __update_tracer_options(tr);
6619 mutex_unlock(&trace_types_lock);
6620}
6621
6508static int instance_mkdir(const char *name) 6622static int instance_mkdir(const char *name)
6509{ 6623{
6510 struct trace_array *tr; 6624 struct trace_array *tr;
@@ -6530,6 +6644,8 @@ static int instance_mkdir(const char *name)
6530 if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL)) 6644 if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL))
6531 goto out_free_tr; 6645 goto out_free_tr;
6532 6646
6647 tr->trace_flags = global_trace.trace_flags;
6648
6533 cpumask_copy(tr->tracing_cpumask, cpu_all_mask); 6649 cpumask_copy(tr->tracing_cpumask, cpu_all_mask);
6534 6650
6535 raw_spin_lock_init(&tr->start_lock); 6651 raw_spin_lock_init(&tr->start_lock);
@@ -6555,6 +6671,8 @@ static int instance_mkdir(const char *name)
6555 } 6671 }
6556 6672
6557 init_tracer_tracefs(tr, tr->dir); 6673 init_tracer_tracefs(tr, tr->dir);
6674 init_trace_flags_index(tr);
6675 __update_tracer_options(tr);
6558 6676
6559 list_add(&tr->list, &ftrace_trace_arrays); 6677 list_add(&tr->list, &ftrace_trace_arrays);
6560 6678
@@ -6580,6 +6698,7 @@ static int instance_rmdir(const char *name)
6580 struct trace_array *tr; 6698 struct trace_array *tr;
6581 int found = 0; 6699 int found = 0;
6582 int ret; 6700 int ret;
6701 int i;
6583 6702
6584 mutex_lock(&trace_types_lock); 6703 mutex_lock(&trace_types_lock);
6585 6704
@@ -6602,9 +6721,14 @@ static int instance_rmdir(const char *name)
6602 tracing_set_nop(tr); 6721 tracing_set_nop(tr);
6603 event_trace_del_tracer(tr); 6722 event_trace_del_tracer(tr);
6604 ftrace_destroy_function_files(tr); 6723 ftrace_destroy_function_files(tr);
6605 debugfs_remove_recursive(tr->dir); 6724 tracefs_remove_recursive(tr->dir);
6606 free_trace_buffers(tr); 6725 free_trace_buffers(tr);
6607 6726
6727 for (i = 0; i < tr->nr_topts; i++) {
6728 kfree(tr->topts[i].topts);
6729 }
6730 kfree(tr->topts);
6731
6608 kfree(tr->name); 6732 kfree(tr->name);
6609 kfree(tr); 6733 kfree(tr);
6610 6734
@@ -6666,6 +6790,8 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
6666 trace_create_file("tracing_on", 0644, d_tracer, 6790 trace_create_file("tracing_on", 0644, d_tracer,
6667 tr, &rb_simple_fops); 6791 tr, &rb_simple_fops);
6668 6792
6793 create_trace_options_dir(tr);
6794
6669#ifdef CONFIG_TRACER_MAX_TRACE 6795#ifdef CONFIG_TRACER_MAX_TRACE
6670 trace_create_file("tracing_max_latency", 0644, d_tracer, 6796 trace_create_file("tracing_max_latency", 0644, d_tracer,
6671 &tr->max_latency, &tracing_max_lat_fops); 6797 &tr->max_latency, &tracing_max_lat_fops);
@@ -6861,11 +6987,7 @@ static __init int tracer_init_tracefs(void)
6861 6987
6862 create_trace_instances(d_tracer); 6988 create_trace_instances(d_tracer);
6863 6989
6864 create_trace_options_dir(&global_trace); 6990 update_tracer_options(&global_trace);
6865
6866 /* If the tracer was started via cmdline, create options for it here */
6867 if (global_trace.current_trace != &nop_trace)
6868 update_tracer_options(&global_trace, global_trace.current_trace);
6869 6991
6870 return 0; 6992 return 0;
6871} 6993}
@@ -6964,6 +7086,7 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
6964 /* use static because iter can be a bit big for the stack */ 7086 /* use static because iter can be a bit big for the stack */
6965 static struct trace_iterator iter; 7087 static struct trace_iterator iter;
6966 static atomic_t dump_running; 7088 static atomic_t dump_running;
7089 struct trace_array *tr = &global_trace;
6967 unsigned int old_userobj; 7090 unsigned int old_userobj;
6968 unsigned long flags; 7091 unsigned long flags;
6969 int cnt = 0, cpu; 7092 int cnt = 0, cpu;
@@ -6993,10 +7116,10 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
6993 atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); 7116 atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled);
6994 } 7117 }
6995 7118
6996 old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; 7119 old_userobj = tr->trace_flags & TRACE_ITER_SYM_USEROBJ;
6997 7120
6998 /* don't look at user memory in panic mode */ 7121 /* don't look at user memory in panic mode */
6999 trace_flags &= ~TRACE_ITER_SYM_USEROBJ; 7122 tr->trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
7000 7123
7001 switch (oops_dump_mode) { 7124 switch (oops_dump_mode) {
7002 case DUMP_ALL: 7125 case DUMP_ALL:
@@ -7059,7 +7182,7 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
7059 printk(KERN_TRACE "---------------------------------\n"); 7182 printk(KERN_TRACE "---------------------------------\n");
7060 7183
7061 out_enable: 7184 out_enable:
7062 trace_flags |= old_userobj; 7185 tr->trace_flags |= old_userobj;
7063 7186
7064 for_each_tracing_cpu(cpu) { 7187 for_each_tracing_cpu(cpu) {
7065 atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); 7188 atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled);
@@ -7074,6 +7197,12 @@ __init static int tracer_alloc_buffers(void)
7074 int ring_buf_size; 7197 int ring_buf_size;
7075 int ret = -ENOMEM; 7198 int ret = -ENOMEM;
7076 7199
7200 /*
7201 * Make sure we don't accidently add more trace options
7202 * than we have bits for.
7203 */
7204 BUILD_BUG_ON(TRACE_ITER_LAST_BIT > TRACE_FLAGS_MAX_SIZE);
7205
7077 if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) 7206 if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL))
7078 goto out; 7207 goto out;
7079 7208
@@ -7132,6 +7261,8 @@ __init static int tracer_alloc_buffers(void)
7132 7261
7133 ftrace_init_global_array_ops(&global_trace); 7262 ftrace_init_global_array_ops(&global_trace);
7134 7263
7264 init_trace_flags_index(&global_trace);
7265
7135 register_tracer(&nop_trace); 7266 register_tracer(&nop_trace);
7136 7267
7137 /* All seems OK, enable tracing */ 7268 /* All seems OK, enable tracing */
@@ -7148,12 +7279,7 @@ __init static int tracer_alloc_buffers(void)
7148 INIT_LIST_HEAD(&global_trace.events); 7279 INIT_LIST_HEAD(&global_trace.events);
7149 list_add(&global_trace.list, &ftrace_trace_arrays); 7280 list_add(&global_trace.list, &ftrace_trace_arrays);
7150 7281
7151 while (trace_boot_options) { 7282 apply_trace_boot_options();
7152 char *option;
7153
7154 option = strsep(&trace_boot_options, ",");
7155 trace_set_options(&global_trace, option);
7156 }
7157 7283
7158 register_snapshot_cmd(); 7284 register_snapshot_cmd();
7159 7285
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 74bde81601a9..dd7620802e72 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -71,9 +71,6 @@ enum trace_type {
71 tstruct \ 71 tstruct \
72 } 72 }
73 73
74#undef TP_ARGS
75#define TP_ARGS(args...) args
76
77#undef FTRACE_ENTRY_DUP 74#undef FTRACE_ENTRY_DUP
78#define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk, filter) 75#define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk, filter)
79 76
@@ -156,9 +153,12 @@ struct trace_array_cpu {
156 pid_t pid; 153 pid_t pid;
157 kuid_t uid; 154 kuid_t uid;
158 char comm[TASK_COMM_LEN]; 155 char comm[TASK_COMM_LEN];
156
157 bool ignore_pid;
159}; 158};
160 159
161struct tracer; 160struct tracer;
161struct trace_option_dentry;
162 162
163struct trace_buffer { 163struct trace_buffer {
164 struct trace_array *tr; 164 struct trace_array *tr;
@@ -168,6 +168,19 @@ struct trace_buffer {
168 int cpu; 168 int cpu;
169}; 169};
170 170
171#define TRACE_FLAGS_MAX_SIZE 32
172
173struct trace_options {
174 struct tracer *tracer;
175 struct trace_option_dentry *topts;
176};
177
178struct trace_pid_list {
179 unsigned int nr_pids;
180 int order;
181 pid_t *pids;
182};
183
171/* 184/*
172 * The trace array - an array of per-CPU trace arrays. This is the 185 * The trace array - an array of per-CPU trace arrays. This is the
173 * highest level data structure that individual tracers deal with. 186 * highest level data structure that individual tracers deal with.
@@ -193,6 +206,7 @@ struct trace_array {
193 bool allocated_snapshot; 206 bool allocated_snapshot;
194 unsigned long max_latency; 207 unsigned long max_latency;
195#endif 208#endif
209 struct trace_pid_list __rcu *filtered_pids;
196 /* 210 /*
197 * max_lock is used to protect the swapping of buffers 211 * max_lock is used to protect the swapping of buffers
198 * when taking a max snapshot. The buffers themselves are 212 * when taking a max snapshot. The buffers themselves are
@@ -216,13 +230,17 @@ struct trace_array {
216#endif 230#endif
217 int stop_count; 231 int stop_count;
218 int clock_id; 232 int clock_id;
233 int nr_topts;
219 struct tracer *current_trace; 234 struct tracer *current_trace;
235 unsigned int trace_flags;
236 unsigned char trace_flags_index[TRACE_FLAGS_MAX_SIZE];
220 unsigned int flags; 237 unsigned int flags;
221 raw_spinlock_t start_lock; 238 raw_spinlock_t start_lock;
222 struct dentry *dir; 239 struct dentry *dir;
223 struct dentry *options; 240 struct dentry *options;
224 struct dentry *percpu_dir; 241 struct dentry *percpu_dir;
225 struct dentry *event_dir; 242 struct dentry *event_dir;
243 struct trace_options *topts;
226 struct list_head systems; 244 struct list_head systems;
227 struct list_head events; 245 struct list_head events;
228 cpumask_var_t tracing_cpumask; /* only trace on set CPUs */ 246 cpumask_var_t tracing_cpumask; /* only trace on set CPUs */
@@ -333,6 +351,13 @@ struct tracer_flags {
333#define TRACER_OPT(s, b) .name = #s, .bit = b 351#define TRACER_OPT(s, b) .name = #s, .bit = b
334 352
335 353
354struct trace_option_dentry {
355 struct tracer_opt *opt;
356 struct tracer_flags *flags;
357 struct trace_array *tr;
358 struct dentry *entry;
359};
360
336/** 361/**
337 * struct tracer - a specific tracer and its callbacks to interact with tracefs 362 * struct tracer - a specific tracer and its callbacks to interact with tracefs
338 * @name: the name chosen to select it on the available_tracers file 363 * @name: the name chosen to select it on the available_tracers file
@@ -611,29 +636,12 @@ void update_max_tr_single(struct trace_array *tr,
611#endif /* CONFIG_TRACER_MAX_TRACE */ 636#endif /* CONFIG_TRACER_MAX_TRACE */
612 637
613#ifdef CONFIG_STACKTRACE 638#ifdef CONFIG_STACKTRACE
614void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
615 int skip, int pc);
616
617void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags,
618 int skip, int pc, struct pt_regs *regs);
619
620void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, 639void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
621 int pc); 640 int pc);
622 641
623void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, 642void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
624 int pc); 643 int pc);
625#else 644#else
626static inline void ftrace_trace_stack(struct ring_buffer *buffer,
627 unsigned long flags, int skip, int pc)
628{
629}
630
631static inline void ftrace_trace_stack_regs(struct ring_buffer *buffer,
632 unsigned long flags, int skip,
633 int pc, struct pt_regs *regs)
634{
635}
636
637static inline void ftrace_trace_userstack(struct ring_buffer *buffer, 645static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
638 unsigned long flags, int pc) 646 unsigned long flags, int pc)
639{ 647{
@@ -707,8 +715,6 @@ int trace_array_printk_buf(struct ring_buffer *buffer,
707void trace_printk_seq(struct trace_seq *s); 715void trace_printk_seq(struct trace_seq *s);
708enum print_line_t print_trace_line(struct trace_iterator *iter); 716enum print_line_t print_trace_line(struct trace_iterator *iter);
709 717
710extern unsigned long trace_flags;
711
712extern char trace_find_mark(unsigned long long duration); 718extern char trace_find_mark(unsigned long long duration);
713 719
714/* Standard output formatting function used for function return traces */ 720/* Standard output formatting function used for function return traces */
@@ -723,9 +729,14 @@ extern char trace_find_mark(unsigned long long duration);
723#define TRACE_GRAPH_PRINT_ABS_TIME 0x20 729#define TRACE_GRAPH_PRINT_ABS_TIME 0x20
724#define TRACE_GRAPH_PRINT_IRQS 0x40 730#define TRACE_GRAPH_PRINT_IRQS 0x40
725#define TRACE_GRAPH_PRINT_TAIL 0x80 731#define TRACE_GRAPH_PRINT_TAIL 0x80
732#define TRACE_GRAPH_SLEEP_TIME 0x100
733#define TRACE_GRAPH_GRAPH_TIME 0x200
726#define TRACE_GRAPH_PRINT_FILL_SHIFT 28 734#define TRACE_GRAPH_PRINT_FILL_SHIFT 28
727#define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT) 735#define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
728 736
737extern void ftrace_graph_sleep_time_control(bool enable);
738extern void ftrace_graph_graph_time_control(bool enable);
739
729extern enum print_line_t 740extern enum print_line_t
730print_graph_function_flags(struct trace_iterator *iter, u32 flags); 741print_graph_function_flags(struct trace_iterator *iter, u32 flags);
731extern void print_graph_headers_flags(struct seq_file *s, u32 flags); 742extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
@@ -859,7 +870,7 @@ void ftrace_destroy_filter_files(struct ftrace_ops *ops);
859#define ftrace_destroy_filter_files(ops) do { } while (0) 870#define ftrace_destroy_filter_files(ops) do { } while (0)
860#endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */ 871#endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
861 872
862int ftrace_event_is_function(struct trace_event_call *call); 873bool ftrace_event_is_function(struct trace_event_call *call);
863 874
864/* 875/*
865 * struct trace_parser - servers for reading the user input separated by spaces 876 * struct trace_parser - servers for reading the user input separated by spaces
@@ -897,42 +908,94 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
897 size_t cnt, loff_t *ppos); 908 size_t cnt, loff_t *ppos);
898 909
899/* 910/*
911 * Only create function graph options if function graph is configured.
912 */
913#ifdef CONFIG_FUNCTION_GRAPH_TRACER
914# define FGRAPH_FLAGS \
915 C(DISPLAY_GRAPH, "display-graph"),
916#else
917# define FGRAPH_FLAGS
918#endif
919
920#ifdef CONFIG_BRANCH_TRACER
921# define BRANCH_FLAGS \
922 C(BRANCH, "branch"),
923#else
924# define BRANCH_FLAGS
925#endif
926
927#ifdef CONFIG_FUNCTION_TRACER
928# define FUNCTION_FLAGS \
929 C(FUNCTION, "function-trace"),
930# define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
931#else
932# define FUNCTION_FLAGS
933# define FUNCTION_DEFAULT_FLAGS 0UL
934#endif
935
936#ifdef CONFIG_STACKTRACE
937# define STACK_FLAGS \
938 C(STACKTRACE, "stacktrace"),
939#else
940# define STACK_FLAGS
941#endif
942
943/*
900 * trace_iterator_flags is an enumeration that defines bit 944 * trace_iterator_flags is an enumeration that defines bit
901 * positions into trace_flags that controls the output. 945 * positions into trace_flags that controls the output.
902 * 946 *
903 * NOTE: These bits must match the trace_options array in 947 * NOTE: These bits must match the trace_options array in
904 * trace.c. 948 * trace.c (this macro guarantees it).
949 */
950#define TRACE_FLAGS \
951 C(PRINT_PARENT, "print-parent"), \
952 C(SYM_OFFSET, "sym-offset"), \
953 C(SYM_ADDR, "sym-addr"), \
954 C(VERBOSE, "verbose"), \
955 C(RAW, "raw"), \
956 C(HEX, "hex"), \
957 C(BIN, "bin"), \
958 C(BLOCK, "block"), \
959 C(PRINTK, "trace_printk"), \
960 C(ANNOTATE, "annotate"), \
961 C(USERSTACKTRACE, "userstacktrace"), \
962 C(SYM_USEROBJ, "sym-userobj"), \
963 C(PRINTK_MSGONLY, "printk-msg-only"), \
964 C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
965 C(LATENCY_FMT, "latency-format"), \
966 C(RECORD_CMD, "record-cmd"), \
967 C(OVERWRITE, "overwrite"), \
968 C(STOP_ON_FREE, "disable_on_free"), \
969 C(IRQ_INFO, "irq-info"), \
970 C(MARKERS, "markers"), \
971 FUNCTION_FLAGS \
972 FGRAPH_FLAGS \
973 STACK_FLAGS \
974 BRANCH_FLAGS
975
976/*
977 * By defining C, we can make TRACE_FLAGS a list of bit names
978 * that will define the bits for the flag masks.
905 */ 979 */
906enum trace_iterator_flags { 980#undef C
907 TRACE_ITER_PRINT_PARENT = 0x01, 981#define C(a, b) TRACE_ITER_##a##_BIT
908 TRACE_ITER_SYM_OFFSET = 0x02, 982
909 TRACE_ITER_SYM_ADDR = 0x04, 983enum trace_iterator_bits {
910 TRACE_ITER_VERBOSE = 0x08, 984 TRACE_FLAGS
911 TRACE_ITER_RAW = 0x10, 985 /* Make sure we don't go more than we have bits for */
912 TRACE_ITER_HEX = 0x20, 986 TRACE_ITER_LAST_BIT
913 TRACE_ITER_BIN = 0x40,
914 TRACE_ITER_BLOCK = 0x80,
915 TRACE_ITER_STACKTRACE = 0x100,
916 TRACE_ITER_PRINTK = 0x200,
917 TRACE_ITER_PREEMPTONLY = 0x400,
918 TRACE_ITER_BRANCH = 0x800,
919 TRACE_ITER_ANNOTATE = 0x1000,
920 TRACE_ITER_USERSTACKTRACE = 0x2000,
921 TRACE_ITER_SYM_USEROBJ = 0x4000,
922 TRACE_ITER_PRINTK_MSGONLY = 0x8000,
923 TRACE_ITER_CONTEXT_INFO = 0x10000, /* Print pid/cpu/time */
924 TRACE_ITER_LATENCY_FMT = 0x20000,
925 TRACE_ITER_SLEEP_TIME = 0x40000,
926 TRACE_ITER_GRAPH_TIME = 0x80000,
927 TRACE_ITER_RECORD_CMD = 0x100000,
928 TRACE_ITER_OVERWRITE = 0x200000,
929 TRACE_ITER_STOP_ON_FREE = 0x400000,
930 TRACE_ITER_IRQ_INFO = 0x800000,
931 TRACE_ITER_MARKERS = 0x1000000,
932 TRACE_ITER_FUNCTION = 0x2000000,
933}; 987};
934 988
935/* 989/*
990 * By redefining C, we can make TRACE_FLAGS a list of masks that
991 * use the bits as defined above.
992 */
993#undef C
994#define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
995
996enum trace_iterator_flags { TRACE_FLAGS };
997
998/*
936 * TRACE_ITER_SYM_MASK masks the options in trace_flags that 999 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
937 * control the output of kernel symbols. 1000 * control the output of kernel symbols.
938 */ 1001 */
@@ -946,7 +1009,7 @@ extern int enable_branch_tracing(struct trace_array *tr);
946extern void disable_branch_tracing(void); 1009extern void disable_branch_tracing(void);
947static inline int trace_branch_enable(struct trace_array *tr) 1010static inline int trace_branch_enable(struct trace_array *tr)
948{ 1011{
949 if (trace_flags & TRACE_ITER_BRANCH) 1012 if (tr->trace_flags & TRACE_ITER_BRANCH)
950 return enable_branch_tracing(tr); 1013 return enable_branch_tracing(tr);
951 return 0; 1014 return 0;
952} 1015}
@@ -1269,6 +1332,7 @@ extern const char *__stop___trace_bprintk_fmt[];
1269extern const char *__start___tracepoint_str[]; 1332extern const char *__start___tracepoint_str[];
1270extern const char *__stop___tracepoint_str[]; 1333extern const char *__stop___tracepoint_str[];
1271 1334
1335void trace_printk_control(bool enabled);
1272void trace_printk_init_buffers(void); 1336void trace_printk_init_buffers(void);
1273void trace_printk_start_comm(void); 1337void trace_printk_start_comm(void);
1274int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set); 1338int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
diff --git a/kernel/trace/trace_benchmark.c b/kernel/trace/trace_benchmark.c
index 40a14cbcf8e0..0f109c4130d3 100644
--- a/kernel/trace/trace_benchmark.c
+++ b/kernel/trace/trace_benchmark.c
@@ -43,7 +43,7 @@ static void trace_do_benchmark(void)
43 unsigned int std = 0; 43 unsigned int std = 0;
44 44
45 /* Only run if the tracepoint is actually active */ 45 /* Only run if the tracepoint is actually active */
46 if (!trace_benchmark_event_enabled()) 46 if (!trace_benchmark_event_enabled() || !tracing_is_on())
47 return; 47 return;
48 48
49 local_irq_disable(); 49 local_irq_disable();
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
index e2e12ad3186f..3a2a73716a5b 100644
--- a/kernel/trace/trace_branch.c
+++ b/kernel/trace/trace_branch.c
@@ -125,25 +125,14 @@ void disable_branch_tracing(void)
125 mutex_unlock(&branch_tracing_mutex); 125 mutex_unlock(&branch_tracing_mutex);
126} 126}
127 127
128static void start_branch_trace(struct trace_array *tr)
129{
130 enable_branch_tracing(tr);
131}
132
133static void stop_branch_trace(struct trace_array *tr)
134{
135 disable_branch_tracing();
136}
137
138static int branch_trace_init(struct trace_array *tr) 128static int branch_trace_init(struct trace_array *tr)
139{ 129{
140 start_branch_trace(tr); 130 return enable_branch_tracing(tr);
141 return 0;
142} 131}
143 132
144static void branch_trace_reset(struct trace_array *tr) 133static void branch_trace_reset(struct trace_array *tr)
145{ 134{
146 stop_branch_trace(tr); 135 disable_branch_tracing();
147} 136}
148 137
149static enum print_line_t trace_branch_print(struct trace_iterator *iter, 138static enum print_line_t trace_branch_print(struct trace_iterator *iter,
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 7ca09cdc20c2..6bbc5f652355 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -15,11 +15,15 @@
15#include <linux/kthread.h> 15#include <linux/kthread.h>
16#include <linux/tracefs.h> 16#include <linux/tracefs.h>
17#include <linux/uaccess.h> 17#include <linux/uaccess.h>
18#include <linux/bsearch.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/ctype.h> 20#include <linux/ctype.h>
21#include <linux/sort.h>
20#include <linux/slab.h> 22#include <linux/slab.h>
21#include <linux/delay.h> 23#include <linux/delay.h>
22 24
25#include <trace/events/sched.h>
26
23#include <asm/setup.h> 27#include <asm/setup.h>
24 28
25#include "trace_output.h" 29#include "trace_output.h"
@@ -38,21 +42,19 @@ static LIST_HEAD(ftrace_common_fields);
38static struct kmem_cache *field_cachep; 42static struct kmem_cache *field_cachep;
39static struct kmem_cache *file_cachep; 43static struct kmem_cache *file_cachep;
40 44
41#define SYSTEM_FL_FREE_NAME (1 << 31)
42
43static inline int system_refcount(struct event_subsystem *system) 45static inline int system_refcount(struct event_subsystem *system)
44{ 46{
45 return system->ref_count & ~SYSTEM_FL_FREE_NAME; 47 return system->ref_count;
46} 48}
47 49
48static int system_refcount_inc(struct event_subsystem *system) 50static int system_refcount_inc(struct event_subsystem *system)
49{ 51{
50 return (system->ref_count++) & ~SYSTEM_FL_FREE_NAME; 52 return system->ref_count++;
51} 53}
52 54
53static int system_refcount_dec(struct event_subsystem *system) 55static int system_refcount_dec(struct event_subsystem *system)
54{ 56{
55 return (--system->ref_count) & ~SYSTEM_FL_FREE_NAME; 57 return --system->ref_count;
56} 58}
57 59
58/* Double loops, do not use break, only goto's work */ 60/* Double loops, do not use break, only goto's work */
@@ -212,12 +214,32 @@ int trace_event_raw_init(struct trace_event_call *call)
212} 214}
213EXPORT_SYMBOL_GPL(trace_event_raw_init); 215EXPORT_SYMBOL_GPL(trace_event_raw_init);
214 216
217bool trace_event_ignore_this_pid(struct trace_event_file *trace_file)
218{
219 struct trace_array *tr = trace_file->tr;
220 struct trace_array_cpu *data;
221 struct trace_pid_list *pid_list;
222
223 pid_list = rcu_dereference_sched(tr->filtered_pids);
224 if (!pid_list)
225 return false;
226
227 data = this_cpu_ptr(tr->trace_buffer.data);
228
229 return data->ignore_pid;
230}
231EXPORT_SYMBOL_GPL(trace_event_ignore_this_pid);
232
215void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer, 233void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
216 struct trace_event_file *trace_file, 234 struct trace_event_file *trace_file,
217 unsigned long len) 235 unsigned long len)
218{ 236{
219 struct trace_event_call *event_call = trace_file->event_call; 237 struct trace_event_call *event_call = trace_file->event_call;
220 238
239 if ((trace_file->flags & EVENT_FILE_FL_PID_FILTER) &&
240 trace_event_ignore_this_pid(trace_file))
241 return NULL;
242
221 local_save_flags(fbuffer->flags); 243 local_save_flags(fbuffer->flags);
222 fbuffer->pc = preempt_count(); 244 fbuffer->pc = preempt_count();
223 fbuffer->trace_file = trace_file; 245 fbuffer->trace_file = trace_file;
@@ -338,6 +360,7 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
338 int enable, int soft_disable) 360 int enable, int soft_disable)
339{ 361{
340 struct trace_event_call *call = file->event_call; 362 struct trace_event_call *call = file->event_call;
363 struct trace_array *tr = file->tr;
341 int ret = 0; 364 int ret = 0;
342 int disable; 365 int disable;
343 366
@@ -401,7 +424,7 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
401 if (soft_disable) 424 if (soft_disable)
402 set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags); 425 set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
403 426
404 if (trace_flags & TRACE_ITER_RECORD_CMD) { 427 if (tr->trace_flags & TRACE_ITER_RECORD_CMD) {
405 tracing_start_cmdline_record(); 428 tracing_start_cmdline_record();
406 set_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags); 429 set_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
407 } 430 }
@@ -446,6 +469,142 @@ static void ftrace_clear_events(struct trace_array *tr)
446 mutex_unlock(&event_mutex); 469 mutex_unlock(&event_mutex);
447} 470}
448 471
472static int cmp_pid(const void *key, const void *elt)
473{
474 const pid_t *search_pid = key;
475 const pid_t *pid = elt;
476
477 if (*search_pid == *pid)
478 return 0;
479 if (*search_pid < *pid)
480 return -1;
481 return 1;
482}
483
484static bool
485check_ignore_pid(struct trace_pid_list *filtered_pids, struct task_struct *task)
486{
487 pid_t search_pid;
488 pid_t *pid;
489
490 /*
491 * Return false, because if filtered_pids does not exist,
492 * all pids are good to trace.
493 */
494 if (!filtered_pids)
495 return false;
496
497 search_pid = task->pid;
498
499 pid = bsearch(&search_pid, filtered_pids->pids,
500 filtered_pids->nr_pids, sizeof(pid_t),
501 cmp_pid);
502 if (!pid)
503 return true;
504
505 return false;
506}
507
508static void
509event_filter_pid_sched_switch_probe_pre(void *data, bool preempt,
510 struct task_struct *prev, struct task_struct *next)
511{
512 struct trace_array *tr = data;
513 struct trace_pid_list *pid_list;
514
515 pid_list = rcu_dereference_sched(tr->filtered_pids);
516
517 this_cpu_write(tr->trace_buffer.data->ignore_pid,
518 check_ignore_pid(pid_list, prev) &&
519 check_ignore_pid(pid_list, next));
520}
521
522static void
523event_filter_pid_sched_switch_probe_post(void *data, bool preempt,
524 struct task_struct *prev, struct task_struct *next)
525{
526 struct trace_array *tr = data;
527 struct trace_pid_list *pid_list;
528
529 pid_list = rcu_dereference_sched(tr->filtered_pids);
530
531 this_cpu_write(tr->trace_buffer.data->ignore_pid,
532 check_ignore_pid(pid_list, next));
533}
534
535static void
536event_filter_pid_sched_wakeup_probe_pre(void *data, struct task_struct *task)
537{
538 struct trace_array *tr = data;
539 struct trace_pid_list *pid_list;
540
541 /* Nothing to do if we are already tracing */
542 if (!this_cpu_read(tr->trace_buffer.data->ignore_pid))
543 return;
544
545 pid_list = rcu_dereference_sched(tr->filtered_pids);
546
547 this_cpu_write(tr->trace_buffer.data->ignore_pid,
548 check_ignore_pid(pid_list, task));
549}
550
551static void
552event_filter_pid_sched_wakeup_probe_post(void *data, struct task_struct *task)
553{
554 struct trace_array *tr = data;
555 struct trace_pid_list *pid_list;
556
557 /* Nothing to do if we are not tracing */
558 if (this_cpu_read(tr->trace_buffer.data->ignore_pid))
559 return;
560
561 pid_list = rcu_dereference_sched(tr->filtered_pids);
562
563 /* Set tracing if current is enabled */
564 this_cpu_write(tr->trace_buffer.data->ignore_pid,
565 check_ignore_pid(pid_list, current));
566}
567
568static void __ftrace_clear_event_pids(struct trace_array *tr)
569{
570 struct trace_pid_list *pid_list;
571 struct trace_event_file *file;
572 int cpu;
573
574 pid_list = rcu_dereference_protected(tr->filtered_pids,
575 lockdep_is_held(&event_mutex));
576 if (!pid_list)
577 return;
578
579 unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_pre, tr);
580 unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_post, tr);
581
582 unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, tr);
583 unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, tr);
584
585 list_for_each_entry(file, &tr->events, list) {
586 clear_bit(EVENT_FILE_FL_PID_FILTER_BIT, &file->flags);
587 }
588
589 for_each_possible_cpu(cpu)
590 per_cpu_ptr(tr->trace_buffer.data, cpu)->ignore_pid = false;
591
592 rcu_assign_pointer(tr->filtered_pids, NULL);
593
594 /* Wait till all users are no longer using pid filtering */
595 synchronize_sched();
596
597 free_pages((unsigned long)pid_list->pids, pid_list->order);
598 kfree(pid_list);
599}
600
601static void ftrace_clear_event_pids(struct trace_array *tr)
602{
603 mutex_lock(&event_mutex);
604 __ftrace_clear_event_pids(tr);
605 mutex_unlock(&event_mutex);
606}
607
449static void __put_system(struct event_subsystem *system) 608static void __put_system(struct event_subsystem *system)
450{ 609{
451 struct event_filter *filter = system->filter; 610 struct event_filter *filter = system->filter;
@@ -460,8 +619,7 @@ static void __put_system(struct event_subsystem *system)
460 kfree(filter->filter_string); 619 kfree(filter->filter_string);
461 kfree(filter); 620 kfree(filter);
462 } 621 }
463 if (system->ref_count & SYSTEM_FL_FREE_NAME) 622 kfree_const(system->name);
464 kfree(system->name);
465 kfree(system); 623 kfree(system);
466} 624}
467 625
@@ -779,6 +937,58 @@ static void t_stop(struct seq_file *m, void *p)
779 mutex_unlock(&event_mutex); 937 mutex_unlock(&event_mutex);
780} 938}
781 939
940static void *p_start(struct seq_file *m, loff_t *pos)
941 __acquires(RCU)
942{
943 struct trace_pid_list *pid_list;
944 struct trace_array *tr = m->private;
945
946 /*
947 * Grab the mutex, to keep calls to p_next() having the same
948 * tr->filtered_pids as p_start() has.
949 * If we just passed the tr->filtered_pids around, then RCU would
950 * have been enough, but doing that makes things more complex.
951 */
952 mutex_lock(&event_mutex);
953 rcu_read_lock_sched();
954
955 pid_list = rcu_dereference_sched(tr->filtered_pids);
956
957 if (!pid_list || *pos >= pid_list->nr_pids)
958 return NULL;
959
960 return (void *)&pid_list->pids[*pos];
961}
962
963static void p_stop(struct seq_file *m, void *p)
964 __releases(RCU)
965{
966 rcu_read_unlock_sched();
967 mutex_unlock(&event_mutex);
968}
969
970static void *
971p_next(struct seq_file *m, void *v, loff_t *pos)
972{
973 struct trace_array *tr = m->private;
974 struct trace_pid_list *pid_list = rcu_dereference_sched(tr->filtered_pids);
975
976 (*pos)++;
977
978 if (*pos >= pid_list->nr_pids)
979 return NULL;
980
981 return (void *)&pid_list->pids[*pos];
982}
983
984static int p_show(struct seq_file *m, void *v)
985{
986 pid_t *pid = v;
987
988 seq_printf(m, "%d\n", *pid);
989 return 0;
990}
991
782static ssize_t 992static ssize_t
783event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, 993event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
784 loff_t *ppos) 994 loff_t *ppos)
@@ -1336,8 +1546,209 @@ show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
1336 return r; 1546 return r;
1337} 1547}
1338 1548
1549static int max_pids(struct trace_pid_list *pid_list)
1550{
1551 return (PAGE_SIZE << pid_list->order) / sizeof(pid_t);
1552}
1553
1554static void ignore_task_cpu(void *data)
1555{
1556 struct trace_array *tr = data;
1557 struct trace_pid_list *pid_list;
1558
1559 /*
1560 * This function is called by on_each_cpu() while the
1561 * event_mutex is held.
1562 */
1563 pid_list = rcu_dereference_protected(tr->filtered_pids,
1564 mutex_is_locked(&event_mutex));
1565
1566 this_cpu_write(tr->trace_buffer.data->ignore_pid,
1567 check_ignore_pid(pid_list, current));
1568}
1569
1570static ssize_t
1571ftrace_event_pid_write(struct file *filp, const char __user *ubuf,
1572 size_t cnt, loff_t *ppos)
1573{
1574 struct seq_file *m = filp->private_data;
1575 struct trace_array *tr = m->private;
1576 struct trace_pid_list *filtered_pids = NULL;
1577 struct trace_pid_list *pid_list = NULL;
1578 struct trace_event_file *file;
1579 struct trace_parser parser;
1580 unsigned long val;
1581 loff_t this_pos;
1582 ssize_t read = 0;
1583 ssize_t ret = 0;
1584 pid_t pid;
1585 int i;
1586
1587 if (!cnt)
1588 return 0;
1589
1590 ret = tracing_update_buffers();
1591 if (ret < 0)
1592 return ret;
1593
1594 if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
1595 return -ENOMEM;
1596
1597 mutex_lock(&event_mutex);
1598 /*
1599 * Load as many pids into the array before doing a
1600 * swap from the tr->filtered_pids to the new list.
1601 */
1602 while (cnt > 0) {
1603
1604 this_pos = 0;
1605
1606 ret = trace_get_user(&parser, ubuf, cnt, &this_pos);
1607 if (ret < 0 || !trace_parser_loaded(&parser))
1608 break;
1609
1610 read += ret;
1611 ubuf += ret;
1612 cnt -= ret;
1613
1614 parser.buffer[parser.idx] = 0;
1615
1616 ret = -EINVAL;
1617 if (kstrtoul(parser.buffer, 0, &val))
1618 break;
1619 if (val > INT_MAX)
1620 break;
1621
1622 pid = (pid_t)val;
1623
1624 ret = -ENOMEM;
1625 if (!pid_list) {
1626 pid_list = kmalloc(sizeof(*pid_list), GFP_KERNEL);
1627 if (!pid_list)
1628 break;
1629
1630 filtered_pids = rcu_dereference_protected(tr->filtered_pids,
1631 lockdep_is_held(&event_mutex));
1632 if (filtered_pids)
1633 pid_list->order = filtered_pids->order;
1634 else
1635 pid_list->order = 0;
1636
1637 pid_list->pids = (void *)__get_free_pages(GFP_KERNEL,
1638 pid_list->order);
1639 if (!pid_list->pids)
1640 break;
1641
1642 if (filtered_pids) {
1643 pid_list->nr_pids = filtered_pids->nr_pids;
1644 memcpy(pid_list->pids, filtered_pids->pids,
1645 pid_list->nr_pids * sizeof(pid_t));
1646 } else
1647 pid_list->nr_pids = 0;
1648 }
1649
1650 if (pid_list->nr_pids >= max_pids(pid_list)) {
1651 pid_t *pid_page;
1652
1653 pid_page = (void *)__get_free_pages(GFP_KERNEL,
1654 pid_list->order + 1);
1655 if (!pid_page)
1656 break;
1657 memcpy(pid_page, pid_list->pids,
1658 pid_list->nr_pids * sizeof(pid_t));
1659 free_pages((unsigned long)pid_list->pids, pid_list->order);
1660
1661 pid_list->order++;
1662 pid_list->pids = pid_page;
1663 }
1664
1665 pid_list->pids[pid_list->nr_pids++] = pid;
1666 trace_parser_clear(&parser);
1667 ret = 0;
1668 }
1669 trace_parser_put(&parser);
1670
1671 if (ret < 0) {
1672 if (pid_list)
1673 free_pages((unsigned long)pid_list->pids, pid_list->order);
1674 kfree(pid_list);
1675 mutex_unlock(&event_mutex);
1676 return ret;
1677 }
1678
1679 if (!pid_list) {
1680 mutex_unlock(&event_mutex);
1681 return ret;
1682 }
1683
1684 sort(pid_list->pids, pid_list->nr_pids, sizeof(pid_t), cmp_pid, NULL);
1685
1686 /* Remove duplicates */
1687 for (i = 1; i < pid_list->nr_pids; i++) {
1688 int start = i;
1689
1690 while (i < pid_list->nr_pids &&
1691 pid_list->pids[i - 1] == pid_list->pids[i])
1692 i++;
1693
1694 if (start != i) {
1695 if (i < pid_list->nr_pids) {
1696 memmove(&pid_list->pids[start], &pid_list->pids[i],
1697 (pid_list->nr_pids - i) * sizeof(pid_t));
1698 pid_list->nr_pids -= i - start;
1699 i = start;
1700 } else
1701 pid_list->nr_pids = start;
1702 }
1703 }
1704
1705 rcu_assign_pointer(tr->filtered_pids, pid_list);
1706
1707 list_for_each_entry(file, &tr->events, list) {
1708 set_bit(EVENT_FILE_FL_PID_FILTER_BIT, &file->flags);
1709 }
1710
1711 if (filtered_pids) {
1712 synchronize_sched();
1713
1714 free_pages((unsigned long)filtered_pids->pids, filtered_pids->order);
1715 kfree(filtered_pids);
1716 } else {
1717 /*
1718 * Register a probe that is called before all other probes
1719 * to set ignore_pid if next or prev do not match.
1720 * Register a probe this is called after all other probes
1721 * to only keep ignore_pid set if next pid matches.
1722 */
1723 register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_pre,
1724 tr, INT_MAX);
1725 register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_post,
1726 tr, 0);
1727
1728 register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre,
1729 tr, INT_MAX);
1730 register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_post,
1731 tr, 0);
1732 }
1733
1734 /*
1735 * Ignoring of pids is done at task switch. But we have to
1736 * check for those tasks that are currently running.
1737 * Always do this in case a pid was appended or removed.
1738 */
1739 on_each_cpu(ignore_task_cpu, tr, 1);
1740
1741 mutex_unlock(&event_mutex);
1742
1743 ret = read;
1744 *ppos += read;
1745
1746 return ret;
1747}
1748
1339static int ftrace_event_avail_open(struct inode *inode, struct file *file); 1749static int ftrace_event_avail_open(struct inode *inode, struct file *file);
1340static int ftrace_event_set_open(struct inode *inode, struct file *file); 1750static int ftrace_event_set_open(struct inode *inode, struct file *file);
1751static int ftrace_event_set_pid_open(struct inode *inode, struct file *file);
1341static int ftrace_event_release(struct inode *inode, struct file *file); 1752static int ftrace_event_release(struct inode *inode, struct file *file);
1342 1753
1343static const struct seq_operations show_event_seq_ops = { 1754static const struct seq_operations show_event_seq_ops = {
@@ -1354,6 +1765,13 @@ static const struct seq_operations show_set_event_seq_ops = {
1354 .stop = t_stop, 1765 .stop = t_stop,
1355}; 1766};
1356 1767
1768static const struct seq_operations show_set_pid_seq_ops = {
1769 .start = p_start,
1770 .next = p_next,
1771 .show = p_show,
1772 .stop = p_stop,
1773};
1774
1357static const struct file_operations ftrace_avail_fops = { 1775static const struct file_operations ftrace_avail_fops = {
1358 .open = ftrace_event_avail_open, 1776 .open = ftrace_event_avail_open,
1359 .read = seq_read, 1777 .read = seq_read,
@@ -1369,6 +1787,14 @@ static const struct file_operations ftrace_set_event_fops = {
1369 .release = ftrace_event_release, 1787 .release = ftrace_event_release,
1370}; 1788};
1371 1789
1790static const struct file_operations ftrace_set_event_pid_fops = {
1791 .open = ftrace_event_set_pid_open,
1792 .read = seq_read,
1793 .write = ftrace_event_pid_write,
1794 .llseek = seq_lseek,
1795 .release = ftrace_event_release,
1796};
1797
1372static const struct file_operations ftrace_enable_fops = { 1798static const struct file_operations ftrace_enable_fops = {
1373 .open = tracing_open_generic, 1799 .open = tracing_open_generic,
1374 .read = event_enable_read, 1800 .read = event_enable_read,
@@ -1479,6 +1905,26 @@ ftrace_event_set_open(struct inode *inode, struct file *file)
1479 return ret; 1905 return ret;
1480} 1906}
1481 1907
1908static int
1909ftrace_event_set_pid_open(struct inode *inode, struct file *file)
1910{
1911 const struct seq_operations *seq_ops = &show_set_pid_seq_ops;
1912 struct trace_array *tr = inode->i_private;
1913 int ret;
1914
1915 if (trace_array_get(tr) < 0)
1916 return -ENODEV;
1917
1918 if ((file->f_mode & FMODE_WRITE) &&
1919 (file->f_flags & O_TRUNC))
1920 ftrace_clear_event_pids(tr);
1921
1922 ret = ftrace_event_open(inode, file, seq_ops);
1923 if (ret < 0)
1924 trace_array_put(tr);
1925 return ret;
1926}
1927
1482static struct event_subsystem * 1928static struct event_subsystem *
1483create_new_subsystem(const char *name) 1929create_new_subsystem(const char *name)
1484{ 1930{
@@ -1492,13 +1938,9 @@ create_new_subsystem(const char *name)
1492 system->ref_count = 1; 1938 system->ref_count = 1;
1493 1939
1494 /* Only allocate if dynamic (kprobes and modules) */ 1940 /* Only allocate if dynamic (kprobes and modules) */
1495 if (!core_kernel_data((unsigned long)name)) { 1941 system->name = kstrdup_const(name, GFP_KERNEL);
1496 system->ref_count |= SYSTEM_FL_FREE_NAME; 1942 if (!system->name)
1497 system->name = kstrdup(name, GFP_KERNEL); 1943 goto out_free;
1498 if (!system->name)
1499 goto out_free;
1500 } else
1501 system->name = name;
1502 1944
1503 system->filter = NULL; 1945 system->filter = NULL;
1504 1946
@@ -1511,8 +1953,7 @@ create_new_subsystem(const char *name)
1511 return system; 1953 return system;
1512 1954
1513 out_free: 1955 out_free:
1514 if (system->ref_count & SYSTEM_FL_FREE_NAME) 1956 kfree_const(system->name);
1515 kfree(system->name);
1516 kfree(system); 1957 kfree(system);
1517 return NULL; 1958 return NULL;
1518} 1959}
@@ -2478,6 +2919,9 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
2478 return -ENOMEM; 2919 return -ENOMEM;
2479 } 2920 }
2480 2921
2922 entry = tracefs_create_file("set_event_pid", 0644, parent,
2923 tr, &ftrace_set_event_pid_fops);
2924
2481 /* ring buffer internal formats */ 2925 /* ring buffer internal formats */
2482 trace_create_file("header_page", 0444, d_events, 2926 trace_create_file("header_page", 0444, d_events,
2483 ring_buffer_print_page_header, 2927 ring_buffer_print_page_header,
@@ -2558,6 +3002,9 @@ int event_trace_del_tracer(struct trace_array *tr)
2558 /* Disable any event triggers and associated soft-disabled events */ 3002 /* Disable any event triggers and associated soft-disabled events */
2559 clear_event_triggers(tr); 3003 clear_event_triggers(tr);
2560 3004
3005 /* Clear the pid list */
3006 __ftrace_clear_event_pids(tr);
3007
2561 /* Disable any running events */ 3008 /* Disable any running events */
2562 __ftrace_set_clr_event_nolock(tr, NULL, NULL, NULL, 0); 3009 __ftrace_set_clr_event_nolock(tr, NULL, NULL, NULL, 0);
2563 3010
@@ -2595,16 +3042,16 @@ early_enable_events(struct trace_array *tr, bool disable_first)
2595 3042
2596 if (!token) 3043 if (!token)
2597 break; 3044 break;
2598 if (!*token)
2599 continue;
2600 3045
2601 /* Restarting syscalls requires that we stop them first */ 3046 if (*token) {
2602 if (disable_first) 3047 /* Restarting syscalls requires that we stop them first */
2603 ftrace_set_clr_event(tr, token, 0); 3048 if (disable_first)
3049 ftrace_set_clr_event(tr, token, 0);
2604 3050
2605 ret = ftrace_set_clr_event(tr, token, 1); 3051 ret = ftrace_set_clr_event(tr, token, 1);
2606 if (ret) 3052 if (ret)
2607 pr_warn("Failed to enable trace event: %s\n", token); 3053 pr_warn("Failed to enable trace event: %s\n", token);
3054 }
2608 3055
2609 /* Put back the comma to allow this to be called again */ 3056 /* Put back the comma to allow this to be called again */
2610 if (buf) 3057 if (buf)
@@ -2891,7 +3338,9 @@ static __init void event_trace_self_tests(void)
2891 3338
2892static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable); 3339static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
2893 3340
2894static void 3341static struct trace_array *event_tr;
3342
3343static void __init
2895function_test_events_call(unsigned long ip, unsigned long parent_ip, 3344function_test_events_call(unsigned long ip, unsigned long parent_ip,
2896 struct ftrace_ops *op, struct pt_regs *pt_regs) 3345 struct ftrace_ops *op, struct pt_regs *pt_regs)
2897{ 3346{
@@ -2922,7 +3371,7 @@ function_test_events_call(unsigned long ip, unsigned long parent_ip,
2922 entry->ip = ip; 3371 entry->ip = ip;
2923 entry->parent_ip = parent_ip; 3372 entry->parent_ip = parent_ip;
2924 3373
2925 trace_buffer_unlock_commit(buffer, event, flags, pc); 3374 trace_buffer_unlock_commit(event_tr, buffer, event, flags, pc);
2926 3375
2927 out: 3376 out:
2928 atomic_dec(&per_cpu(ftrace_test_event_disable, cpu)); 3377 atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
@@ -2938,6 +3387,9 @@ static struct ftrace_ops trace_ops __initdata =
2938static __init void event_trace_self_test_with_function(void) 3387static __init void event_trace_self_test_with_function(void)
2939{ 3388{
2940 int ret; 3389 int ret;
3390 event_tr = top_trace_array();
3391 if (WARN_ON(!event_tr))
3392 return;
2941 ret = register_ftrace_function(&trace_ops); 3393 ret = register_ftrace_function(&trace_ops);
2942 if (WARN_ON(ret < 0)) { 3394 if (WARN_ON(ret < 0)) {
2943 pr_info("Failed to enable function tracer for event tests\n"); 3395 pr_info("Failed to enable function tracer for event tests\n");
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index bd1bf184c5c9..f93a219b18da 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -973,15 +973,15 @@ static bool is_string_field(struct ftrace_event_field *field)
973 field->filter_type == FILTER_PTR_STRING; 973 field->filter_type == FILTER_PTR_STRING;
974} 974}
975 975
976static int is_legal_op(struct ftrace_event_field *field, int op) 976static bool is_legal_op(struct ftrace_event_field *field, int op)
977{ 977{
978 if (is_string_field(field) && 978 if (is_string_field(field) &&
979 (op != OP_EQ && op != OP_NE && op != OP_GLOB)) 979 (op != OP_EQ && op != OP_NE && op != OP_GLOB))
980 return 0; 980 return false;
981 if (!is_string_field(field) && op == OP_GLOB) 981 if (!is_string_field(field) && op == OP_GLOB)
982 return 0; 982 return false;
983 983
984 return 1; 984 return true;
985} 985}
986 986
987static filter_pred_fn_t select_comparison_fn(int op, int field_size, 987static filter_pred_fn_t select_comparison_fn(int op, int field_size,
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c
index adabf7da9113..39aa7aa66468 100644
--- a/kernel/trace/trace_export.c
+++ b/kernel/trace/trace_export.c
@@ -187,7 +187,7 @@ __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
187 FTRACE_ENTRY_REG(call, struct_name, etype, \ 187 FTRACE_ENTRY_REG(call, struct_name, etype, \
188 PARAMS(tstruct), PARAMS(print), filter, NULL) 188 PARAMS(tstruct), PARAMS(print), filter, NULL)
189 189
190int ftrace_event_is_function(struct trace_event_call *call) 190bool ftrace_event_is_function(struct trace_event_call *call)
191{ 191{
192 return call == &event_function; 192 return call == &event_function;
193} 193}
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index ca98445782ac..92382af7a213 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -83,13 +83,18 @@ static struct tracer_opt trace_opts[] = {
83 { TRACER_OPT(funcgraph-irqs, TRACE_GRAPH_PRINT_IRQS) }, 83 { TRACER_OPT(funcgraph-irqs, TRACE_GRAPH_PRINT_IRQS) },
84 /* Display function name after trailing } */ 84 /* Display function name after trailing } */
85 { TRACER_OPT(funcgraph-tail, TRACE_GRAPH_PRINT_TAIL) }, 85 { TRACER_OPT(funcgraph-tail, TRACE_GRAPH_PRINT_TAIL) },
86 /* Include sleep time (scheduled out) between entry and return */
87 { TRACER_OPT(sleep-time, TRACE_GRAPH_SLEEP_TIME) },
88 /* Include time within nested functions */
89 { TRACER_OPT(graph-time, TRACE_GRAPH_GRAPH_TIME) },
86 { } /* Empty entry */ 90 { } /* Empty entry */
87}; 91};
88 92
89static struct tracer_flags tracer_flags = { 93static struct tracer_flags tracer_flags = {
90 /* Don't display overruns, proc, or tail by default */ 94 /* Don't display overruns, proc, or tail by default */
91 .val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD | 95 .val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD |
92 TRACE_GRAPH_PRINT_DURATION | TRACE_GRAPH_PRINT_IRQS, 96 TRACE_GRAPH_PRINT_DURATION | TRACE_GRAPH_PRINT_IRQS |
97 TRACE_GRAPH_SLEEP_TIME | TRACE_GRAPH_GRAPH_TIME,
93 .opts = trace_opts 98 .opts = trace_opts
94}; 99};
95 100
@@ -107,8 +112,8 @@ enum {
107}; 112};
108 113
109static void 114static void
110print_graph_duration(unsigned long long duration, struct trace_seq *s, 115print_graph_duration(struct trace_array *tr, unsigned long long duration,
111 u32 flags); 116 struct trace_seq *s, u32 flags);
112 117
113/* Add a function return address to the trace stack on thread info.*/ 118/* Add a function return address to the trace stack on thread info.*/
114int 119int
@@ -653,6 +658,7 @@ static void
653print_graph_irq(struct trace_iterator *iter, unsigned long addr, 658print_graph_irq(struct trace_iterator *iter, unsigned long addr,
654 enum trace_type type, int cpu, pid_t pid, u32 flags) 659 enum trace_type type, int cpu, pid_t pid, u32 flags)
655{ 660{
661 struct trace_array *tr = iter->tr;
656 struct trace_seq *s = &iter->seq; 662 struct trace_seq *s = &iter->seq;
657 struct trace_entry *ent = iter->ent; 663 struct trace_entry *ent = iter->ent;
658 664
@@ -660,7 +666,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
660 addr >= (unsigned long)__irqentry_text_end) 666 addr >= (unsigned long)__irqentry_text_end)
661 return; 667 return;
662 668
663 if (trace_flags & TRACE_ITER_CONTEXT_INFO) { 669 if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO) {
664 /* Absolute time */ 670 /* Absolute time */
665 if (flags & TRACE_GRAPH_PRINT_ABS_TIME) 671 if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
666 print_graph_abs_time(iter->ts, s); 672 print_graph_abs_time(iter->ts, s);
@@ -676,19 +682,19 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
676 } 682 }
677 683
678 /* Latency format */ 684 /* Latency format */
679 if (trace_flags & TRACE_ITER_LATENCY_FMT) 685 if (tr->trace_flags & TRACE_ITER_LATENCY_FMT)
680 print_graph_lat_fmt(s, ent); 686 print_graph_lat_fmt(s, ent);
681 } 687 }
682 688
683 /* No overhead */ 689 /* No overhead */
684 print_graph_duration(0, s, flags | FLAGS_FILL_START); 690 print_graph_duration(tr, 0, s, flags | FLAGS_FILL_START);
685 691
686 if (type == TRACE_GRAPH_ENT) 692 if (type == TRACE_GRAPH_ENT)
687 trace_seq_puts(s, "==========>"); 693 trace_seq_puts(s, "==========>");
688 else 694 else
689 trace_seq_puts(s, "<=========="); 695 trace_seq_puts(s, "<==========");
690 696
691 print_graph_duration(0, s, flags | FLAGS_FILL_END); 697 print_graph_duration(tr, 0, s, flags | FLAGS_FILL_END);
692 trace_seq_putc(s, '\n'); 698 trace_seq_putc(s, '\n');
693} 699}
694 700
@@ -726,11 +732,11 @@ trace_print_graph_duration(unsigned long long duration, struct trace_seq *s)
726} 732}
727 733
728static void 734static void
729print_graph_duration(unsigned long long duration, struct trace_seq *s, 735print_graph_duration(struct trace_array *tr, unsigned long long duration,
730 u32 flags) 736 struct trace_seq *s, u32 flags)
731{ 737{
732 if (!(flags & TRACE_GRAPH_PRINT_DURATION) || 738 if (!(flags & TRACE_GRAPH_PRINT_DURATION) ||
733 !(trace_flags & TRACE_ITER_CONTEXT_INFO)) 739 !(tr->trace_flags & TRACE_ITER_CONTEXT_INFO))
734 return; 740 return;
735 741
736 /* No real adata, just filling the column with spaces */ 742 /* No real adata, just filling the column with spaces */
@@ -764,6 +770,7 @@ print_graph_entry_leaf(struct trace_iterator *iter,
764 struct trace_seq *s, u32 flags) 770 struct trace_seq *s, u32 flags)
765{ 771{
766 struct fgraph_data *data = iter->private; 772 struct fgraph_data *data = iter->private;
773 struct trace_array *tr = iter->tr;
767 struct ftrace_graph_ret *graph_ret; 774 struct ftrace_graph_ret *graph_ret;
768 struct ftrace_graph_ent *call; 775 struct ftrace_graph_ent *call;
769 unsigned long long duration; 776 unsigned long long duration;
@@ -792,7 +799,7 @@ print_graph_entry_leaf(struct trace_iterator *iter,
792 } 799 }
793 800
794 /* Overhead and duration */ 801 /* Overhead and duration */
795 print_graph_duration(duration, s, flags); 802 print_graph_duration(tr, duration, s, flags);
796 803
797 /* Function */ 804 /* Function */
798 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) 805 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++)
@@ -810,6 +817,7 @@ print_graph_entry_nested(struct trace_iterator *iter,
810{ 817{
811 struct ftrace_graph_ent *call = &entry->graph_ent; 818 struct ftrace_graph_ent *call = &entry->graph_ent;
812 struct fgraph_data *data = iter->private; 819 struct fgraph_data *data = iter->private;
820 struct trace_array *tr = iter->tr;
813 int i; 821 int i;
814 822
815 if (data) { 823 if (data) {
@@ -825,7 +833,7 @@ print_graph_entry_nested(struct trace_iterator *iter,
825 } 833 }
826 834
827 /* No time */ 835 /* No time */
828 print_graph_duration(0, s, flags | FLAGS_FILL_FULL); 836 print_graph_duration(tr, 0, s, flags | FLAGS_FILL_FULL);
829 837
830 /* Function */ 838 /* Function */
831 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) 839 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++)
@@ -849,6 +857,7 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
849{ 857{
850 struct fgraph_data *data = iter->private; 858 struct fgraph_data *data = iter->private;
851 struct trace_entry *ent = iter->ent; 859 struct trace_entry *ent = iter->ent;
860 struct trace_array *tr = iter->tr;
852 int cpu = iter->cpu; 861 int cpu = iter->cpu;
853 862
854 /* Pid */ 863 /* Pid */
@@ -858,7 +867,7 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
858 /* Interrupt */ 867 /* Interrupt */
859 print_graph_irq(iter, addr, type, cpu, ent->pid, flags); 868 print_graph_irq(iter, addr, type, cpu, ent->pid, flags);
860 869
861 if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) 870 if (!(tr->trace_flags & TRACE_ITER_CONTEXT_INFO))
862 return; 871 return;
863 872
864 /* Absolute time */ 873 /* Absolute time */
@@ -876,7 +885,7 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
876 } 885 }
877 886
878 /* Latency format */ 887 /* Latency format */
879 if (trace_flags & TRACE_ITER_LATENCY_FMT) 888 if (tr->trace_flags & TRACE_ITER_LATENCY_FMT)
880 print_graph_lat_fmt(s, ent); 889 print_graph_lat_fmt(s, ent);
881 890
882 return; 891 return;
@@ -1027,6 +1036,7 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
1027{ 1036{
1028 unsigned long long duration = trace->rettime - trace->calltime; 1037 unsigned long long duration = trace->rettime - trace->calltime;
1029 struct fgraph_data *data = iter->private; 1038 struct fgraph_data *data = iter->private;
1039 struct trace_array *tr = iter->tr;
1030 pid_t pid = ent->pid; 1040 pid_t pid = ent->pid;
1031 int cpu = iter->cpu; 1041 int cpu = iter->cpu;
1032 int func_match = 1; 1042 int func_match = 1;
@@ -1058,7 +1068,7 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
1058 print_graph_prologue(iter, s, 0, 0, flags); 1068 print_graph_prologue(iter, s, 0, 0, flags);
1059 1069
1060 /* Overhead and duration */ 1070 /* Overhead and duration */
1061 print_graph_duration(duration, s, flags); 1071 print_graph_duration(tr, duration, s, flags);
1062 1072
1063 /* Closing brace */ 1073 /* Closing brace */
1064 for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++) 1074 for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++)
@@ -1091,7 +1101,8 @@ static enum print_line_t
1091print_graph_comment(struct trace_seq *s, struct trace_entry *ent, 1101print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
1092 struct trace_iterator *iter, u32 flags) 1102 struct trace_iterator *iter, u32 flags)
1093{ 1103{
1094 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); 1104 struct trace_array *tr = iter->tr;
1105 unsigned long sym_flags = (tr->trace_flags & TRACE_ITER_SYM_MASK);
1095 struct fgraph_data *data = iter->private; 1106 struct fgraph_data *data = iter->private;
1096 struct trace_event *event; 1107 struct trace_event *event;
1097 int depth = 0; 1108 int depth = 0;
@@ -1104,7 +1115,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
1104 print_graph_prologue(iter, s, 0, 0, flags); 1115 print_graph_prologue(iter, s, 0, 0, flags);
1105 1116
1106 /* No time */ 1117 /* No time */
1107 print_graph_duration(0, s, flags | FLAGS_FILL_FULL); 1118 print_graph_duration(tr, 0, s, flags | FLAGS_FILL_FULL);
1108 1119
1109 /* Indentation */ 1120 /* Indentation */
1110 if (depth > 0) 1121 if (depth > 0)
@@ -1245,9 +1256,10 @@ static void print_lat_header(struct seq_file *s, u32 flags)
1245 seq_printf(s, "#%.*s||| / \n", size, spaces); 1256 seq_printf(s, "#%.*s||| / \n", size, spaces);
1246} 1257}
1247 1258
1248static void __print_graph_headers_flags(struct seq_file *s, u32 flags) 1259static void __print_graph_headers_flags(struct trace_array *tr,
1260 struct seq_file *s, u32 flags)
1249{ 1261{
1250 int lat = trace_flags & TRACE_ITER_LATENCY_FMT; 1262 int lat = tr->trace_flags & TRACE_ITER_LATENCY_FMT;
1251 1263
1252 if (lat) 1264 if (lat)
1253 print_lat_header(s, flags); 1265 print_lat_header(s, flags);
@@ -1289,11 +1301,12 @@ static void print_graph_headers(struct seq_file *s)
1289void print_graph_headers_flags(struct seq_file *s, u32 flags) 1301void print_graph_headers_flags(struct seq_file *s, u32 flags)
1290{ 1302{
1291 struct trace_iterator *iter = s->private; 1303 struct trace_iterator *iter = s->private;
1304 struct trace_array *tr = iter->tr;
1292 1305
1293 if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) 1306 if (!(tr->trace_flags & TRACE_ITER_CONTEXT_INFO))
1294 return; 1307 return;
1295 1308
1296 if (trace_flags & TRACE_ITER_LATENCY_FMT) { 1309 if (tr->trace_flags & TRACE_ITER_LATENCY_FMT) {
1297 /* print nothing if the buffers are empty */ 1310 /* print nothing if the buffers are empty */
1298 if (trace_empty(iter)) 1311 if (trace_empty(iter))
1299 return; 1312 return;
@@ -1301,7 +1314,7 @@ void print_graph_headers_flags(struct seq_file *s, u32 flags)
1301 print_trace_header(s, iter); 1314 print_trace_header(s, iter);
1302 } 1315 }
1303 1316
1304 __print_graph_headers_flags(s, flags); 1317 __print_graph_headers_flags(tr, s, flags);
1305} 1318}
1306 1319
1307void graph_trace_open(struct trace_iterator *iter) 1320void graph_trace_open(struct trace_iterator *iter)
@@ -1362,6 +1375,12 @@ func_graph_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
1362 if (bit == TRACE_GRAPH_PRINT_IRQS) 1375 if (bit == TRACE_GRAPH_PRINT_IRQS)
1363 ftrace_graph_skip_irqs = !set; 1376 ftrace_graph_skip_irqs = !set;
1364 1377
1378 if (bit == TRACE_GRAPH_SLEEP_TIME)
1379 ftrace_graph_sleep_time_control(set);
1380
1381 if (bit == TRACE_GRAPH_GRAPH_TIME)
1382 ftrace_graph_graph_time_control(set);
1383
1365 return 0; 1384 return 0;
1366} 1385}
1367 1386
diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c
index 8523ea345f2b..e4e56589ec1d 100644
--- a/kernel/trace/trace_irqsoff.c
+++ b/kernel/trace/trace_irqsoff.c
@@ -31,7 +31,6 @@ enum {
31static int trace_type __read_mostly; 31static int trace_type __read_mostly;
32 32
33static int save_flags; 33static int save_flags;
34static bool function_enabled;
35 34
36static void stop_irqsoff_tracer(struct trace_array *tr, int graph); 35static void stop_irqsoff_tracer(struct trace_array *tr, int graph);
37static int start_irqsoff_tracer(struct trace_array *tr, int graph); 36static int start_irqsoff_tracer(struct trace_array *tr, int graph);
@@ -57,22 +56,16 @@ irq_trace(void)
57# define irq_trace() (0) 56# define irq_trace() (0)
58#endif 57#endif
59 58
60#define TRACE_DISPLAY_GRAPH 1
61
62static struct tracer_opt trace_opts[] = {
63#ifdef CONFIG_FUNCTION_GRAPH_TRACER 59#ifdef CONFIG_FUNCTION_GRAPH_TRACER
64 /* display latency trace as call graph */ 60static int irqsoff_display_graph(struct trace_array *tr, int set);
65 { TRACER_OPT(display-graph, TRACE_DISPLAY_GRAPH) }, 61# define is_graph(tr) ((tr)->trace_flags & TRACE_ITER_DISPLAY_GRAPH)
62#else
63static inline int irqsoff_display_graph(struct trace_array *tr, int set)
64{
65 return -EINVAL;
66}
67# define is_graph(tr) false
66#endif 68#endif
67 { } /* Empty entry */
68};
69
70static struct tracer_flags tracer_flags = {
71 .val = 0,
72 .opts = trace_opts,
73};
74
75#define is_graph() (tracer_flags.val & TRACE_DISPLAY_GRAPH)
76 69
77/* 70/*
78 * Sequence count - we record it when starting a measurement and 71 * Sequence count - we record it when starting a measurement and
@@ -152,15 +145,11 @@ irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip,
152#endif /* CONFIG_FUNCTION_TRACER */ 145#endif /* CONFIG_FUNCTION_TRACER */
153 146
154#ifdef CONFIG_FUNCTION_GRAPH_TRACER 147#ifdef CONFIG_FUNCTION_GRAPH_TRACER
155static int 148static int irqsoff_display_graph(struct trace_array *tr, int set)
156irqsoff_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
157{ 149{
158 int cpu; 150 int cpu;
159 151
160 if (!(bit & TRACE_DISPLAY_GRAPH)) 152 if (!(is_graph(tr) ^ set))
161 return -EINVAL;
162
163 if (!(is_graph() ^ set))
164 return 0; 153 return 0;
165 154
166 stop_irqsoff_tracer(irqsoff_trace, !set); 155 stop_irqsoff_tracer(irqsoff_trace, !set);
@@ -209,7 +198,7 @@ static void irqsoff_graph_return(struct ftrace_graph_ret *trace)
209 198
210static void irqsoff_trace_open(struct trace_iterator *iter) 199static void irqsoff_trace_open(struct trace_iterator *iter)
211{ 200{
212 if (is_graph()) 201 if (is_graph(iter->tr))
213 graph_trace_open(iter); 202 graph_trace_open(iter);
214 203
215} 204}
@@ -231,7 +220,7 @@ static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
231 * In graph mode call the graph tracer output function, 220 * In graph mode call the graph tracer output function,
232 * otherwise go with the TRACE_FN event handler 221 * otherwise go with the TRACE_FN event handler
233 */ 222 */
234 if (is_graph()) 223 if (is_graph(iter->tr))
235 return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS); 224 return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
236 225
237 return TRACE_TYPE_UNHANDLED; 226 return TRACE_TYPE_UNHANDLED;
@@ -239,7 +228,9 @@ static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
239 228
240static void irqsoff_print_header(struct seq_file *s) 229static void irqsoff_print_header(struct seq_file *s)
241{ 230{
242 if (is_graph()) 231 struct trace_array *tr = irqsoff_trace;
232
233 if (is_graph(tr))
243 print_graph_headers_flags(s, GRAPH_TRACER_FLAGS); 234 print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
244 else 235 else
245 trace_default_header(s); 236 trace_default_header(s);
@@ -250,7 +241,7 @@ __trace_function(struct trace_array *tr,
250 unsigned long ip, unsigned long parent_ip, 241 unsigned long ip, unsigned long parent_ip,
251 unsigned long flags, int pc) 242 unsigned long flags, int pc)
252{ 243{
253 if (is_graph()) 244 if (is_graph(tr))
254 trace_graph_function(tr, ip, parent_ip, flags, pc); 245 trace_graph_function(tr, ip, parent_ip, flags, pc);
255 else 246 else
256 trace_function(tr, ip, parent_ip, flags, pc); 247 trace_function(tr, ip, parent_ip, flags, pc);
@@ -259,27 +250,23 @@ __trace_function(struct trace_array *tr,
259#else 250#else
260#define __trace_function trace_function 251#define __trace_function trace_function
261 252
262static int 253#ifdef CONFIG_FUNCTION_TRACER
263irqsoff_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
264{
265 return -EINVAL;
266}
267
268static int irqsoff_graph_entry(struct ftrace_graph_ent *trace) 254static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
269{ 255{
270 return -1; 256 return -1;
271} 257}
258#endif
272 259
273static enum print_line_t irqsoff_print_line(struct trace_iterator *iter) 260static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
274{ 261{
275 return TRACE_TYPE_UNHANDLED; 262 return TRACE_TYPE_UNHANDLED;
276} 263}
277 264
278static void irqsoff_graph_return(struct ftrace_graph_ret *trace) { }
279static void irqsoff_trace_open(struct trace_iterator *iter) { } 265static void irqsoff_trace_open(struct trace_iterator *iter) { }
280static void irqsoff_trace_close(struct trace_iterator *iter) { } 266static void irqsoff_trace_close(struct trace_iterator *iter) { }
281 267
282#ifdef CONFIG_FUNCTION_TRACER 268#ifdef CONFIG_FUNCTION_TRACER
269static void irqsoff_graph_return(struct ftrace_graph_ret *trace) { }
283static void irqsoff_print_header(struct seq_file *s) 270static void irqsoff_print_header(struct seq_file *s)
284{ 271{
285 trace_default_header(s); 272 trace_default_header(s);
@@ -295,16 +282,16 @@ static void irqsoff_print_header(struct seq_file *s)
295/* 282/*
296 * Should this new latency be reported/recorded? 283 * Should this new latency be reported/recorded?
297 */ 284 */
298static int report_latency(struct trace_array *tr, cycle_t delta) 285static bool report_latency(struct trace_array *tr, cycle_t delta)
299{ 286{
300 if (tracing_thresh) { 287 if (tracing_thresh) {
301 if (delta < tracing_thresh) 288 if (delta < tracing_thresh)
302 return 0; 289 return false;
303 } else { 290 } else {
304 if (delta <= tr->max_latency) 291 if (delta <= tr->max_latency)
305 return 0; 292 return false;
306 } 293 }
307 return 1; 294 return true;
308} 295}
309 296
310static void 297static void
@@ -523,12 +510,15 @@ void trace_preempt_off(unsigned long a0, unsigned long a1)
523} 510}
524#endif /* CONFIG_PREEMPT_TRACER */ 511#endif /* CONFIG_PREEMPT_TRACER */
525 512
513#ifdef CONFIG_FUNCTION_TRACER
514static bool function_enabled;
515
526static int register_irqsoff_function(struct trace_array *tr, int graph, int set) 516static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
527{ 517{
528 int ret; 518 int ret;
529 519
530 /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */ 520 /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */
531 if (function_enabled || (!set && !(trace_flags & TRACE_ITER_FUNCTION))) 521 if (function_enabled || (!set && !(tr->trace_flags & TRACE_ITER_FUNCTION)))
532 return 0; 522 return 0;
533 523
534 if (graph) 524 if (graph)
@@ -556,20 +546,40 @@ static void unregister_irqsoff_function(struct trace_array *tr, int graph)
556 function_enabled = false; 546 function_enabled = false;
557} 547}
558 548
559static void irqsoff_function_set(struct trace_array *tr, int set) 549static int irqsoff_function_set(struct trace_array *tr, u32 mask, int set)
560{ 550{
551 if (!(mask & TRACE_ITER_FUNCTION))
552 return 0;
553
561 if (set) 554 if (set)
562 register_irqsoff_function(tr, is_graph(), 1); 555 register_irqsoff_function(tr, is_graph(tr), 1);
563 else 556 else
564 unregister_irqsoff_function(tr, is_graph()); 557 unregister_irqsoff_function(tr, is_graph(tr));
558 return 1;
559}
560#else
561static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
562{
563 return 0;
564}
565static void unregister_irqsoff_function(struct trace_array *tr, int graph) { }
566static inline int irqsoff_function_set(struct trace_array *tr, u32 mask, int set)
567{
568 return 0;
565} 569}
570#endif /* CONFIG_FUNCTION_TRACER */
566 571
567static int irqsoff_flag_changed(struct trace_array *tr, u32 mask, int set) 572static int irqsoff_flag_changed(struct trace_array *tr, u32 mask, int set)
568{ 573{
569 struct tracer *tracer = tr->current_trace; 574 struct tracer *tracer = tr->current_trace;
570 575
571 if (mask & TRACE_ITER_FUNCTION) 576 if (irqsoff_function_set(tr, mask, set))
572 irqsoff_function_set(tr, set); 577 return 0;
578
579#ifdef CONFIG_FUNCTION_GRAPH_TRACER
580 if (mask & TRACE_ITER_DISPLAY_GRAPH)
581 return irqsoff_display_graph(tr, set);
582#endif
573 583
574 return trace_keep_overwrite(tracer, mask, set); 584 return trace_keep_overwrite(tracer, mask, set);
575} 585}
@@ -602,7 +612,7 @@ static int __irqsoff_tracer_init(struct trace_array *tr)
602 if (irqsoff_busy) 612 if (irqsoff_busy)
603 return -EBUSY; 613 return -EBUSY;
604 614
605 save_flags = trace_flags; 615 save_flags = tr->trace_flags;
606 616
607 /* non overwrite screws up the latency tracers */ 617 /* non overwrite screws up the latency tracers */
608 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1); 618 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
@@ -618,7 +628,7 @@ static int __irqsoff_tracer_init(struct trace_array *tr)
618 628
619 /* Only toplevel instance supports graph tracing */ 629 /* Only toplevel instance supports graph tracing */
620 if (start_irqsoff_tracer(tr, (tr->flags & TRACE_ARRAY_FL_GLOBAL && 630 if (start_irqsoff_tracer(tr, (tr->flags & TRACE_ARRAY_FL_GLOBAL &&
621 is_graph()))) 631 is_graph(tr))))
622 printk(KERN_ERR "failed to start irqsoff tracer\n"); 632 printk(KERN_ERR "failed to start irqsoff tracer\n");
623 633
624 irqsoff_busy = true; 634 irqsoff_busy = true;
@@ -630,7 +640,7 @@ static void irqsoff_tracer_reset(struct trace_array *tr)
630 int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT; 640 int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT;
631 int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE; 641 int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE;
632 642
633 stop_irqsoff_tracer(tr, is_graph()); 643 stop_irqsoff_tracer(tr, is_graph(tr));
634 644
635 set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag); 645 set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag);
636 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag); 646 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag);
@@ -666,8 +676,6 @@ static struct tracer irqsoff_tracer __read_mostly =
666 .print_max = true, 676 .print_max = true,
667 .print_header = irqsoff_print_header, 677 .print_header = irqsoff_print_header,
668 .print_line = irqsoff_print_line, 678 .print_line = irqsoff_print_line,
669 .flags = &tracer_flags,
670 .set_flag = irqsoff_set_flag,
671 .flag_changed = irqsoff_flag_changed, 679 .flag_changed = irqsoff_flag_changed,
672#ifdef CONFIG_FTRACE_SELFTEST 680#ifdef CONFIG_FTRACE_SELFTEST
673 .selftest = trace_selftest_startup_irqsoff, 681 .selftest = trace_selftest_startup_irqsoff,
@@ -700,8 +708,6 @@ static struct tracer preemptoff_tracer __read_mostly =
700 .print_max = true, 708 .print_max = true,
701 .print_header = irqsoff_print_header, 709 .print_header = irqsoff_print_header,
702 .print_line = irqsoff_print_line, 710 .print_line = irqsoff_print_line,
703 .flags = &tracer_flags,
704 .set_flag = irqsoff_set_flag,
705 .flag_changed = irqsoff_flag_changed, 711 .flag_changed = irqsoff_flag_changed,
706#ifdef CONFIG_FTRACE_SELFTEST 712#ifdef CONFIG_FTRACE_SELFTEST
707 .selftest = trace_selftest_startup_preemptoff, 713 .selftest = trace_selftest_startup_preemptoff,
@@ -736,8 +742,6 @@ static struct tracer preemptirqsoff_tracer __read_mostly =
736 .print_max = true, 742 .print_max = true,
737 .print_header = irqsoff_print_header, 743 .print_header = irqsoff_print_header,
738 .print_line = irqsoff_print_line, 744 .print_line = irqsoff_print_line,
739 .flags = &tracer_flags,
740 .set_flag = irqsoff_set_flag,
741 .flag_changed = irqsoff_flag_changed, 745 .flag_changed = irqsoff_flag_changed,
742#ifdef CONFIG_FTRACE_SELFTEST 746#ifdef CONFIG_FTRACE_SELFTEST
743 .selftest = trace_selftest_startup_preemptirqsoff, 747 .selftest = trace_selftest_startup_preemptirqsoff,
diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c
index 3ccf5c2c1320..57149bce6aad 100644
--- a/kernel/trace/trace_kdb.c
+++ b/kernel/trace/trace_kdb.c
@@ -21,20 +21,22 @@ static void ftrace_dump_buf(int skip_lines, long cpu_file)
21 /* use static because iter can be a bit big for the stack */ 21 /* use static because iter can be a bit big for the stack */
22 static struct trace_iterator iter; 22 static struct trace_iterator iter;
23 static struct ring_buffer_iter *buffer_iter[CONFIG_NR_CPUS]; 23 static struct ring_buffer_iter *buffer_iter[CONFIG_NR_CPUS];
24 struct trace_array *tr;
24 unsigned int old_userobj; 25 unsigned int old_userobj;
25 int cnt = 0, cpu; 26 int cnt = 0, cpu;
26 27
27 trace_init_global_iter(&iter); 28 trace_init_global_iter(&iter);
28 iter.buffer_iter = buffer_iter; 29 iter.buffer_iter = buffer_iter;
30 tr = iter.tr;
29 31
30 for_each_tracing_cpu(cpu) { 32 for_each_tracing_cpu(cpu) {
31 atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); 33 atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled);
32 } 34 }
33 35
34 old_userobj = trace_flags; 36 old_userobj = tr->trace_flags;
35 37
36 /* don't look at user memory in panic mode */ 38 /* don't look at user memory in panic mode */
37 trace_flags &= ~TRACE_ITER_SYM_USEROBJ; 39 tr->trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
38 40
39 kdb_printf("Dumping ftrace buffer:\n"); 41 kdb_printf("Dumping ftrace buffer:\n");
40 42
@@ -82,7 +84,7 @@ static void ftrace_dump_buf(int skip_lines, long cpu_file)
82 kdb_printf("---------------------------------\n"); 84 kdb_printf("---------------------------------\n");
83 85
84out: 86out:
85 trace_flags = old_userobj; 87 tr->trace_flags = old_userobj;
86 88
87 for_each_tracing_cpu(cpu) { 89 for_each_tracing_cpu(cpu) {
88 atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); 90 atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled);
diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
index 638e110c5bfd..2be8c4f2403d 100644
--- a/kernel/trace/trace_mmiotrace.c
+++ b/kernel/trace/trace_mmiotrace.c
@@ -314,7 +314,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
314 entry->rw = *rw; 314 entry->rw = *rw;
315 315
316 if (!call_filter_check_discard(call, entry, buffer, event)) 316 if (!call_filter_check_discard(call, entry, buffer, event))
317 trace_buffer_unlock_commit(buffer, event, 0, pc); 317 trace_buffer_unlock_commit(tr, buffer, event, 0, pc);
318} 318}
319 319
320void mmio_trace_rw(struct mmiotrace_rw *rw) 320void mmio_trace_rw(struct mmiotrace_rw *rw)
@@ -344,7 +344,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
344 entry->map = *map; 344 entry->map = *map;
345 345
346 if (!call_filter_check_discard(call, entry, buffer, event)) 346 if (!call_filter_check_discard(call, entry, buffer, event))
347 trace_buffer_unlock_commit(buffer, event, 0, pc); 347 trace_buffer_unlock_commit(tr, buffer, event, 0, pc);
348} 348}
349 349
350void mmio_trace_mapping(struct mmiotrace_map *map) 350void mmio_trace_mapping(struct mmiotrace_map *map)
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 8e481a84aeea..282982195e09 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -322,8 +322,8 @@ seq_print_sym_offset(struct trace_seq *s, const char *fmt,
322# define IP_FMT "%016lx" 322# define IP_FMT "%016lx"
323#endif 323#endif
324 324
325int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, 325static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
326 unsigned long ip, unsigned long sym_flags) 326 unsigned long ip, unsigned long sym_flags)
327{ 327{
328 struct file *file = NULL; 328 struct file *file = NULL;
329 unsigned long vmstart = 0; 329 unsigned long vmstart = 0;
@@ -355,50 +355,6 @@ int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
355} 355}
356 356
357int 357int
358seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
359 unsigned long sym_flags)
360{
361 struct mm_struct *mm = NULL;
362 unsigned int i;
363
364 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
365 struct task_struct *task;
366 /*
367 * we do the lookup on the thread group leader,
368 * since individual threads might have already quit!
369 */
370 rcu_read_lock();
371 task = find_task_by_vpid(entry->tgid);
372 if (task)
373 mm = get_task_mm(task);
374 rcu_read_unlock();
375 }
376
377 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
378 unsigned long ip = entry->caller[i];
379
380 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
381 break;
382
383 trace_seq_puts(s, " => ");
384
385 if (!ip) {
386 trace_seq_puts(s, "??");
387 trace_seq_putc(s, '\n');
388 continue;
389 }
390
391 seq_print_user_ip(s, mm, ip, sym_flags);
392 trace_seq_putc(s, '\n');
393 }
394
395 if (mm)
396 mmput(mm);
397
398 return !trace_seq_has_overflowed(s);
399}
400
401int
402seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) 358seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
403{ 359{
404 if (!ip) { 360 if (!ip) {
@@ -520,7 +476,8 @@ char trace_find_mark(unsigned long long d)
520static int 476static int
521lat_print_timestamp(struct trace_iterator *iter, u64 next_ts) 477lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
522{ 478{
523 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE; 479 struct trace_array *tr = iter->tr;
480 unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE;
524 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS; 481 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
525 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start; 482 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
526 unsigned long long rel_ts = next_ts - iter->ts; 483 unsigned long long rel_ts = next_ts - iter->ts;
@@ -563,6 +520,7 @@ lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
563 520
564int trace_print_context(struct trace_iterator *iter) 521int trace_print_context(struct trace_iterator *iter)
565{ 522{
523 struct trace_array *tr = iter->tr;
566 struct trace_seq *s = &iter->seq; 524 struct trace_seq *s = &iter->seq;
567 struct trace_entry *entry = iter->ent; 525 struct trace_entry *entry = iter->ent;
568 unsigned long long t; 526 unsigned long long t;
@@ -574,7 +532,7 @@ int trace_print_context(struct trace_iterator *iter)
574 trace_seq_printf(s, "%16s-%-5d [%03d] ", 532 trace_seq_printf(s, "%16s-%-5d [%03d] ",
575 comm, entry->pid, iter->cpu); 533 comm, entry->pid, iter->cpu);
576 534
577 if (trace_flags & TRACE_ITER_IRQ_INFO) 535 if (tr->trace_flags & TRACE_ITER_IRQ_INFO)
578 trace_print_lat_fmt(s, entry); 536 trace_print_lat_fmt(s, entry);
579 537
580 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) { 538 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
@@ -590,14 +548,15 @@ int trace_print_context(struct trace_iterator *iter)
590 548
591int trace_print_lat_context(struct trace_iterator *iter) 549int trace_print_lat_context(struct trace_iterator *iter)
592{ 550{
593 u64 next_ts; 551 struct trace_array *tr = iter->tr;
594 /* trace_find_next_entry will reset ent_size */ 552 /* trace_find_next_entry will reset ent_size */
595 int ent_size = iter->ent_size; 553 int ent_size = iter->ent_size;
596 struct trace_seq *s = &iter->seq; 554 struct trace_seq *s = &iter->seq;
555 u64 next_ts;
597 struct trace_entry *entry = iter->ent, 556 struct trace_entry *entry = iter->ent,
598 *next_entry = trace_find_next_entry(iter, NULL, 557 *next_entry = trace_find_next_entry(iter, NULL,
599 &next_ts); 558 &next_ts);
600 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); 559 unsigned long verbose = (tr->trace_flags & TRACE_ITER_VERBOSE);
601 560
602 /* Restore the original ent_size */ 561 /* Restore the original ent_size */
603 iter->ent_size = ent_size; 562 iter->ent_size = ent_size;
@@ -1079,13 +1038,49 @@ static struct trace_event trace_stack_event = {
1079static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, 1038static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1080 int flags, struct trace_event *event) 1039 int flags, struct trace_event *event)
1081{ 1040{
1041 struct trace_array *tr = iter->tr;
1082 struct userstack_entry *field; 1042 struct userstack_entry *field;
1083 struct trace_seq *s = &iter->seq; 1043 struct trace_seq *s = &iter->seq;
1044 struct mm_struct *mm = NULL;
1045 unsigned int i;
1084 1046
1085 trace_assign_type(field, iter->ent); 1047 trace_assign_type(field, iter->ent);
1086 1048
1087 trace_seq_puts(s, "<user stack trace>\n"); 1049 trace_seq_puts(s, "<user stack trace>\n");
1088 seq_print_userip_objs(field, s, flags); 1050
1051 if (tr->trace_flags & TRACE_ITER_SYM_USEROBJ) {
1052 struct task_struct *task;
1053 /*
1054 * we do the lookup on the thread group leader,
1055 * since individual threads might have already quit!
1056 */
1057 rcu_read_lock();
1058 task = find_task_by_vpid(field->tgid);
1059 if (task)
1060 mm = get_task_mm(task);
1061 rcu_read_unlock();
1062 }
1063
1064 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1065 unsigned long ip = field->caller[i];
1066
1067 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
1068 break;
1069
1070 trace_seq_puts(s, " => ");
1071
1072 if (!ip) {
1073 trace_seq_puts(s, "??");
1074 trace_seq_putc(s, '\n');
1075 continue;
1076 }
1077
1078 seq_print_user_ip(s, mm, ip, flags);
1079 trace_seq_putc(s, '\n');
1080 }
1081
1082 if (mm)
1083 mmput(mm);
1089 1084
1090 return trace_handle_return(s); 1085 return trace_handle_return(s);
1091} 1086}
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
index 4cbfe85b99c8..fabc49bcd493 100644
--- a/kernel/trace/trace_output.h
+++ b/kernel/trace/trace_output.h
@@ -14,10 +14,6 @@ trace_print_printk_msg_only(struct trace_iterator *iter);
14extern int 14extern int
15seq_print_ip_sym(struct trace_seq *s, unsigned long ip, 15seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
16 unsigned long sym_flags); 16 unsigned long sym_flags);
17extern int seq_print_userip_objs(const struct userstack_entry *entry,
18 struct trace_seq *s, unsigned long sym_flags);
19extern int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
20 unsigned long ip, unsigned long sym_flags);
21 17
22extern int trace_print_context(struct trace_iterator *iter); 18extern int trace_print_context(struct trace_iterator *iter);
23extern int trace_print_lat_context(struct trace_iterator *iter); 19extern int trace_print_lat_context(struct trace_iterator *iter);
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
index 36c1455b7567..1c2b28536feb 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -178,6 +178,12 @@ static inline void format_mod_start(void) { }
178static inline void format_mod_stop(void) { } 178static inline void format_mod_stop(void) { }
179#endif /* CONFIG_MODULES */ 179#endif /* CONFIG_MODULES */
180 180
181static bool __read_mostly trace_printk_enabled = true;
182
183void trace_printk_control(bool enabled)
184{
185 trace_printk_enabled = enabled;
186}
181 187
182__initdata_or_module static 188__initdata_or_module static
183struct notifier_block module_trace_bprintk_format_nb = { 189struct notifier_block module_trace_bprintk_format_nb = {
@@ -192,7 +198,7 @@ int __trace_bprintk(unsigned long ip, const char *fmt, ...)
192 if (unlikely(!fmt)) 198 if (unlikely(!fmt))
193 return 0; 199 return 0;
194 200
195 if (!(trace_flags & TRACE_ITER_PRINTK)) 201 if (!trace_printk_enabled)
196 return 0; 202 return 0;
197 203
198 va_start(ap, fmt); 204 va_start(ap, fmt);
@@ -207,7 +213,7 @@ int __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap)
207 if (unlikely(!fmt)) 213 if (unlikely(!fmt))
208 return 0; 214 return 0;
209 215
210 if (!(trace_flags & TRACE_ITER_PRINTK)) 216 if (!trace_printk_enabled)
211 return 0; 217 return 0;
212 218
213 return trace_vbprintk(ip, fmt, ap); 219 return trace_vbprintk(ip, fmt, ap);
@@ -219,7 +225,7 @@ int __trace_printk(unsigned long ip, const char *fmt, ...)
219 int ret; 225 int ret;
220 va_list ap; 226 va_list ap;
221 227
222 if (!(trace_flags & TRACE_ITER_PRINTK)) 228 if (!trace_printk_enabled)
223 return 0; 229 return 0;
224 230
225 va_start(ap, fmt); 231 va_start(ap, fmt);
@@ -231,7 +237,7 @@ EXPORT_SYMBOL_GPL(__trace_printk);
231 237
232int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap) 238int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap)
233{ 239{
234 if (!(trace_flags & TRACE_ITER_PRINTK)) 240 if (!trace_printk_enabled)
235 return 0; 241 return 0;
236 242
237 return trace_vprintk(ip, fmt, ap); 243 return trace_vprintk(ip, fmt, ap);
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index b98dee914542..f6398db09114 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -302,15 +302,15 @@ static nokprobe_inline void call_fetch(struct fetch_param *fprm,
302} 302}
303 303
304/* Check the name is good for event/group/fields */ 304/* Check the name is good for event/group/fields */
305static inline int is_good_name(const char *name) 305static inline bool is_good_name(const char *name)
306{ 306{
307 if (!isalpha(*name) && *name != '_') 307 if (!isalpha(*name) && *name != '_')
308 return 0; 308 return false;
309 while (*++name != '\0') { 309 while (*++name != '\0') {
310 if (!isalpha(*name) && !isdigit(*name) && *name != '_') 310 if (!isalpha(*name) && !isdigit(*name) && *name != '_')
311 return 0; 311 return false;
312 } 312 }
313 return 1; 313 return true;
314} 314}
315 315
316static inline struct event_file_link * 316static inline struct event_file_link *
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c
index 4bcfbac289ff..9d4399b553a3 100644
--- a/kernel/trace/trace_sched_wakeup.c
+++ b/kernel/trace/trace_sched_wakeup.c
@@ -34,31 +34,28 @@ static arch_spinlock_t wakeup_lock =
34 34
35static void wakeup_reset(struct trace_array *tr); 35static void wakeup_reset(struct trace_array *tr);
36static void __wakeup_reset(struct trace_array *tr); 36static void __wakeup_reset(struct trace_array *tr);
37static int wakeup_graph_entry(struct ftrace_graph_ent *trace);
38static void wakeup_graph_return(struct ftrace_graph_ret *trace);
39 37
40static int save_flags; 38static int save_flags;
41static bool function_enabled;
42
43#define TRACE_DISPLAY_GRAPH 1
44 39
45static struct tracer_opt trace_opts[] = {
46#ifdef CONFIG_FUNCTION_GRAPH_TRACER 40#ifdef CONFIG_FUNCTION_GRAPH_TRACER
47 /* display latency trace as call graph */ 41static int wakeup_display_graph(struct trace_array *tr, int set);
48 { TRACER_OPT(display-graph, TRACE_DISPLAY_GRAPH) }, 42# define is_graph(tr) ((tr)->trace_flags & TRACE_ITER_DISPLAY_GRAPH)
43#else
44static inline int wakeup_display_graph(struct trace_array *tr, int set)
45{
46 return 0;
47}
48# define is_graph(tr) false
49#endif 49#endif
50 { } /* Empty entry */
51};
52
53static struct tracer_flags tracer_flags = {
54 .val = 0,
55 .opts = trace_opts,
56};
57 50
58#define is_graph() (tracer_flags.val & TRACE_DISPLAY_GRAPH)
59 51
60#ifdef CONFIG_FUNCTION_TRACER 52#ifdef CONFIG_FUNCTION_TRACER
61 53
54static int wakeup_graph_entry(struct ftrace_graph_ent *trace);
55static void wakeup_graph_return(struct ftrace_graph_ret *trace);
56
57static bool function_enabled;
58
62/* 59/*
63 * Prologue for the wakeup function tracers. 60 * Prologue for the wakeup function tracers.
64 * 61 *
@@ -128,14 +125,13 @@ wakeup_tracer_call(unsigned long ip, unsigned long parent_ip,
128 atomic_dec(&data->disabled); 125 atomic_dec(&data->disabled);
129 preempt_enable_notrace(); 126 preempt_enable_notrace();
130} 127}
131#endif /* CONFIG_FUNCTION_TRACER */
132 128
133static int register_wakeup_function(struct trace_array *tr, int graph, int set) 129static int register_wakeup_function(struct trace_array *tr, int graph, int set)
134{ 130{
135 int ret; 131 int ret;
136 132
137 /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */ 133 /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */
138 if (function_enabled || (!set && !(trace_flags & TRACE_ITER_FUNCTION))) 134 if (function_enabled || (!set && !(tr->trace_flags & TRACE_ITER_FUNCTION)))
139 return 0; 135 return 0;
140 136
141 if (graph) 137 if (graph)
@@ -163,20 +159,40 @@ static void unregister_wakeup_function(struct trace_array *tr, int graph)
163 function_enabled = false; 159 function_enabled = false;
164} 160}
165 161
166static void wakeup_function_set(struct trace_array *tr, int set) 162static int wakeup_function_set(struct trace_array *tr, u32 mask, int set)
167{ 163{
164 if (!(mask & TRACE_ITER_FUNCTION))
165 return 0;
166
168 if (set) 167 if (set)
169 register_wakeup_function(tr, is_graph(), 1); 168 register_wakeup_function(tr, is_graph(tr), 1);
170 else 169 else
171 unregister_wakeup_function(tr, is_graph()); 170 unregister_wakeup_function(tr, is_graph(tr));
171 return 1;
172}
173#else
174static int register_wakeup_function(struct trace_array *tr, int graph, int set)
175{
176 return 0;
177}
178static void unregister_wakeup_function(struct trace_array *tr, int graph) { }
179static int wakeup_function_set(struct trace_array *tr, u32 mask, int set)
180{
181 return 0;
172} 182}
183#endif /* CONFIG_FUNCTION_TRACER */
173 184
174static int wakeup_flag_changed(struct trace_array *tr, u32 mask, int set) 185static int wakeup_flag_changed(struct trace_array *tr, u32 mask, int set)
175{ 186{
176 struct tracer *tracer = tr->current_trace; 187 struct tracer *tracer = tr->current_trace;
177 188
178 if (mask & TRACE_ITER_FUNCTION) 189 if (wakeup_function_set(tr, mask, set))
179 wakeup_function_set(tr, set); 190 return 0;
191
192#ifdef CONFIG_FUNCTION_GRAPH_TRACER
193 if (mask & TRACE_ITER_DISPLAY_GRAPH)
194 return wakeup_display_graph(tr, set);
195#endif
180 196
181 return trace_keep_overwrite(tracer, mask, set); 197 return trace_keep_overwrite(tracer, mask, set);
182} 198}
@@ -203,14 +219,9 @@ static void stop_func_tracer(struct trace_array *tr, int graph)
203} 219}
204 220
205#ifdef CONFIG_FUNCTION_GRAPH_TRACER 221#ifdef CONFIG_FUNCTION_GRAPH_TRACER
206static int 222static int wakeup_display_graph(struct trace_array *tr, int set)
207wakeup_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
208{ 223{
209 224 if (!(is_graph(tr) ^ set))
210 if (!(bit & TRACE_DISPLAY_GRAPH))
211 return -EINVAL;
212
213 if (!(is_graph() ^ set))
214 return 0; 225 return 0;
215 226
216 stop_func_tracer(tr, !set); 227 stop_func_tracer(tr, !set);
@@ -259,7 +270,7 @@ static void wakeup_graph_return(struct ftrace_graph_ret *trace)
259 270
260static void wakeup_trace_open(struct trace_iterator *iter) 271static void wakeup_trace_open(struct trace_iterator *iter)
261{ 272{
262 if (is_graph()) 273 if (is_graph(iter->tr))
263 graph_trace_open(iter); 274 graph_trace_open(iter);
264} 275}
265 276
@@ -279,7 +290,7 @@ static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
279 * In graph mode call the graph tracer output function, 290 * In graph mode call the graph tracer output function,
280 * otherwise go with the TRACE_FN event handler 291 * otherwise go with the TRACE_FN event handler
281 */ 292 */
282 if (is_graph()) 293 if (is_graph(iter->tr))
283 return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS); 294 return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
284 295
285 return TRACE_TYPE_UNHANDLED; 296 return TRACE_TYPE_UNHANDLED;
@@ -287,7 +298,7 @@ static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
287 298
288static void wakeup_print_header(struct seq_file *s) 299static void wakeup_print_header(struct seq_file *s)
289{ 300{
290 if (is_graph()) 301 if (is_graph(wakeup_trace))
291 print_graph_headers_flags(s, GRAPH_TRACER_FLAGS); 302 print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
292 else 303 else
293 trace_default_header(s); 304 trace_default_header(s);
@@ -298,7 +309,7 @@ __trace_function(struct trace_array *tr,
298 unsigned long ip, unsigned long parent_ip, 309 unsigned long ip, unsigned long parent_ip,
299 unsigned long flags, int pc) 310 unsigned long flags, int pc)
300{ 311{
301 if (is_graph()) 312 if (is_graph(tr))
302 trace_graph_function(tr, ip, parent_ip, flags, pc); 313 trace_graph_function(tr, ip, parent_ip, flags, pc);
303 else 314 else
304 trace_function(tr, ip, parent_ip, flags, pc); 315 trace_function(tr, ip, parent_ip, flags, pc);
@@ -306,27 +317,20 @@ __trace_function(struct trace_array *tr,
306#else 317#else
307#define __trace_function trace_function 318#define __trace_function trace_function
308 319
309static int
310wakeup_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
311{
312 return -EINVAL;
313}
314
315static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
316{
317 return -1;
318}
319
320static enum print_line_t wakeup_print_line(struct trace_iterator *iter) 320static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
321{ 321{
322 return TRACE_TYPE_UNHANDLED; 322 return TRACE_TYPE_UNHANDLED;
323} 323}
324 324
325static void wakeup_graph_return(struct ftrace_graph_ret *trace) { }
326static void wakeup_trace_open(struct trace_iterator *iter) { } 325static void wakeup_trace_open(struct trace_iterator *iter) { }
327static void wakeup_trace_close(struct trace_iterator *iter) { } 326static void wakeup_trace_close(struct trace_iterator *iter) { }
328 327
329#ifdef CONFIG_FUNCTION_TRACER 328#ifdef CONFIG_FUNCTION_TRACER
329static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
330{
331 return -1;
332}
333static void wakeup_graph_return(struct ftrace_graph_ret *trace) { }
330static void wakeup_print_header(struct seq_file *s) 334static void wakeup_print_header(struct seq_file *s)
331{ 335{
332 trace_default_header(s); 336 trace_default_header(s);
@@ -342,16 +346,16 @@ static void wakeup_print_header(struct seq_file *s)
342/* 346/*
343 * Should this new latency be reported/recorded? 347 * Should this new latency be reported/recorded?
344 */ 348 */
345static int report_latency(struct trace_array *tr, cycle_t delta) 349static bool report_latency(struct trace_array *tr, cycle_t delta)
346{ 350{
347 if (tracing_thresh) { 351 if (tracing_thresh) {
348 if (delta < tracing_thresh) 352 if (delta < tracing_thresh)
349 return 0; 353 return false;
350 } else { 354 } else {
351 if (delta <= tr->max_latency) 355 if (delta <= tr->max_latency)
352 return 0; 356 return false;
353 } 357 }
354 return 1; 358 return true;
355} 359}
356 360
357static void 361static void
@@ -388,7 +392,7 @@ tracing_sched_switch_trace(struct trace_array *tr,
388 entry->next_cpu = task_cpu(next); 392 entry->next_cpu = task_cpu(next);
389 393
390 if (!call_filter_check_discard(call, entry, buffer, event)) 394 if (!call_filter_check_discard(call, entry, buffer, event))
391 trace_buffer_unlock_commit(buffer, event, flags, pc); 395 trace_buffer_unlock_commit(tr, buffer, event, flags, pc);
392} 396}
393 397
394static void 398static void
@@ -416,7 +420,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr,
416 entry->next_cpu = task_cpu(wakee); 420 entry->next_cpu = task_cpu(wakee);
417 421
418 if (!call_filter_check_discard(call, entry, buffer, event)) 422 if (!call_filter_check_discard(call, entry, buffer, event))
419 trace_buffer_unlock_commit(buffer, event, flags, pc); 423 trace_buffer_unlock_commit(tr, buffer, event, flags, pc);
420} 424}
421 425
422static void notrace 426static void notrace
@@ -635,7 +639,7 @@ static void start_wakeup_tracer(struct trace_array *tr)
635 */ 639 */
636 smp_wmb(); 640 smp_wmb();
637 641
638 if (start_func_tracer(tr, is_graph())) 642 if (start_func_tracer(tr, is_graph(tr)))
639 printk(KERN_ERR "failed to start wakeup tracer\n"); 643 printk(KERN_ERR "failed to start wakeup tracer\n");
640 644
641 return; 645 return;
@@ -648,7 +652,7 @@ fail_deprobe:
648static void stop_wakeup_tracer(struct trace_array *tr) 652static void stop_wakeup_tracer(struct trace_array *tr)
649{ 653{
650 tracer_enabled = 0; 654 tracer_enabled = 0;
651 stop_func_tracer(tr, is_graph()); 655 stop_func_tracer(tr, is_graph(tr));
652 unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL); 656 unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
653 unregister_trace_sched_wakeup_new(probe_wakeup, NULL); 657 unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
654 unregister_trace_sched_wakeup(probe_wakeup, NULL); 658 unregister_trace_sched_wakeup(probe_wakeup, NULL);
@@ -659,7 +663,7 @@ static bool wakeup_busy;
659 663
660static int __wakeup_tracer_init(struct trace_array *tr) 664static int __wakeup_tracer_init(struct trace_array *tr)
661{ 665{
662 save_flags = trace_flags; 666 save_flags = tr->trace_flags;
663 667
664 /* non overwrite screws up the latency tracers */ 668 /* non overwrite screws up the latency tracers */
665 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1); 669 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
@@ -740,8 +744,6 @@ static struct tracer wakeup_tracer __read_mostly =
740 .print_max = true, 744 .print_max = true,
741 .print_header = wakeup_print_header, 745 .print_header = wakeup_print_header,
742 .print_line = wakeup_print_line, 746 .print_line = wakeup_print_line,
743 .flags = &tracer_flags,
744 .set_flag = wakeup_set_flag,
745 .flag_changed = wakeup_flag_changed, 747 .flag_changed = wakeup_flag_changed,
746#ifdef CONFIG_FTRACE_SELFTEST 748#ifdef CONFIG_FTRACE_SELFTEST
747 .selftest = trace_selftest_startup_wakeup, 749 .selftest = trace_selftest_startup_wakeup,
@@ -762,8 +764,6 @@ static struct tracer wakeup_rt_tracer __read_mostly =
762 .print_max = true, 764 .print_max = true,
763 .print_header = wakeup_print_header, 765 .print_header = wakeup_print_header,
764 .print_line = wakeup_print_line, 766 .print_line = wakeup_print_line,
765 .flags = &tracer_flags,
766 .set_flag = wakeup_set_flag,
767 .flag_changed = wakeup_flag_changed, 767 .flag_changed = wakeup_flag_changed,
768#ifdef CONFIG_FTRACE_SELFTEST 768#ifdef CONFIG_FTRACE_SELFTEST
769 .selftest = trace_selftest_startup_wakeup, 769 .selftest = trace_selftest_startup_wakeup,
@@ -784,8 +784,6 @@ static struct tracer wakeup_dl_tracer __read_mostly =
784 .print_max = true, 784 .print_max = true,
785 .print_header = wakeup_print_header, 785 .print_header = wakeup_print_header,
786 .print_line = wakeup_print_line, 786 .print_line = wakeup_print_line,
787 .flags = &tracer_flags,
788 .set_flag = wakeup_set_flag,
789 .flag_changed = wakeup_flag_changed, 787 .flag_changed = wakeup_flag_changed,
790#ifdef CONFIG_FTRACE_SELFTEST 788#ifdef CONFIG_FTRACE_SELFTEST
791 .selftest = trace_selftest_startup_wakeup, 789 .selftest = trace_selftest_startup_wakeup,
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index 8abf1ba18085..dda9e6742950 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -16,24 +16,22 @@
16 16
17#include "trace.h" 17#include "trace.h"
18 18
19#define STACK_TRACE_ENTRIES 500
20
21static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES+1] = 19static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES+1] =
22 { [0 ... (STACK_TRACE_ENTRIES)] = ULONG_MAX }; 20 { [0 ... (STACK_TRACE_ENTRIES)] = ULONG_MAX };
23static unsigned stack_dump_index[STACK_TRACE_ENTRIES]; 21unsigned stack_trace_index[STACK_TRACE_ENTRIES];
24 22
25/* 23/*
26 * Reserve one entry for the passed in ip. This will allow 24 * Reserve one entry for the passed in ip. This will allow
27 * us to remove most or all of the stack size overhead 25 * us to remove most or all of the stack size overhead
28 * added by the stack tracer itself. 26 * added by the stack tracer itself.
29 */ 27 */
30static struct stack_trace max_stack_trace = { 28struct stack_trace stack_trace_max = {
31 .max_entries = STACK_TRACE_ENTRIES - 1, 29 .max_entries = STACK_TRACE_ENTRIES - 1,
32 .entries = &stack_dump_trace[0], 30 .entries = &stack_dump_trace[0],
33}; 31};
34 32
35static unsigned long max_stack_size; 33unsigned long stack_trace_max_size;
36static arch_spinlock_t max_stack_lock = 34arch_spinlock_t stack_trace_max_lock =
37 (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; 35 (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
38 36
39static DEFINE_PER_CPU(int, trace_active); 37static DEFINE_PER_CPU(int, trace_active);
@@ -42,30 +40,38 @@ static DEFINE_MUTEX(stack_sysctl_mutex);
42int stack_tracer_enabled; 40int stack_tracer_enabled;
43static int last_stack_tracer_enabled; 41static int last_stack_tracer_enabled;
44 42
45static inline void print_max_stack(void) 43void stack_trace_print(void)
46{ 44{
47 long i; 45 long i;
48 int size; 46 int size;
49 47
50 pr_emerg(" Depth Size Location (%d entries)\n" 48 pr_emerg(" Depth Size Location (%d entries)\n"
51 " ----- ---- --------\n", 49 " ----- ---- --------\n",
52 max_stack_trace.nr_entries); 50 stack_trace_max.nr_entries);
53 51
54 for (i = 0; i < max_stack_trace.nr_entries; i++) { 52 for (i = 0; i < stack_trace_max.nr_entries; i++) {
55 if (stack_dump_trace[i] == ULONG_MAX) 53 if (stack_dump_trace[i] == ULONG_MAX)
56 break; 54 break;
57 if (i+1 == max_stack_trace.nr_entries || 55 if (i+1 == stack_trace_max.nr_entries ||
58 stack_dump_trace[i+1] == ULONG_MAX) 56 stack_dump_trace[i+1] == ULONG_MAX)
59 size = stack_dump_index[i]; 57 size = stack_trace_index[i];
60 else 58 else
61 size = stack_dump_index[i] - stack_dump_index[i+1]; 59 size = stack_trace_index[i] - stack_trace_index[i+1];
62 60
63 pr_emerg("%3ld) %8d %5d %pS\n", i, stack_dump_index[i], 61 pr_emerg("%3ld) %8d %5d %pS\n", i, stack_trace_index[i],
64 size, (void *)stack_dump_trace[i]); 62 size, (void *)stack_dump_trace[i]);
65 } 63 }
66} 64}
67 65
68static inline void 66/*
67 * When arch-specific code overides this function, the following
68 * data should be filled up, assuming stack_trace_max_lock is held to
69 * prevent concurrent updates.
70 * stack_trace_index[]
71 * stack_trace_max
72 * stack_trace_max_size
73 */
74void __weak
69check_stack(unsigned long ip, unsigned long *stack) 75check_stack(unsigned long ip, unsigned long *stack)
70{ 76{
71 unsigned long this_size, flags; unsigned long *p, *top, *start; 77 unsigned long this_size, flags; unsigned long *p, *top, *start;
@@ -78,7 +84,7 @@ check_stack(unsigned long ip, unsigned long *stack)
78 /* Remove the frame of the tracer */ 84 /* Remove the frame of the tracer */
79 this_size -= frame_size; 85 this_size -= frame_size;
80 86
81 if (this_size <= max_stack_size) 87 if (this_size <= stack_trace_max_size)
82 return; 88 return;
83 89
84 /* we do not handle interrupt stacks yet */ 90 /* we do not handle interrupt stacks yet */
@@ -90,7 +96,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90 return; 96 return;
91 97
92 local_irq_save(flags); 98 local_irq_save(flags);
93 arch_spin_lock(&max_stack_lock); 99 arch_spin_lock(&stack_trace_max_lock);
94 100
95 /* 101 /*
96 * RCU may not be watching, make it see us. 102 * RCU may not be watching, make it see us.
@@ -103,18 +109,18 @@ check_stack(unsigned long ip, unsigned long *stack)
103 this_size -= tracer_frame; 109 this_size -= tracer_frame;
104 110
105 /* a race could have already updated it */ 111 /* a race could have already updated it */
106 if (this_size <= max_stack_size) 112 if (this_size <= stack_trace_max_size)
107 goto out; 113 goto out;
108 114
109 max_stack_size = this_size; 115 stack_trace_max_size = this_size;
110 116
111 max_stack_trace.nr_entries = 0; 117 stack_trace_max.nr_entries = 0;
112 max_stack_trace.skip = 3; 118 stack_trace_max.skip = 3;
113 119
114 save_stack_trace(&max_stack_trace); 120 save_stack_trace(&stack_trace_max);
115 121
116 /* Skip over the overhead of the stack tracer itself */ 122 /* Skip over the overhead of the stack tracer itself */
117 for (i = 0; i < max_stack_trace.nr_entries; i++) { 123 for (i = 0; i < stack_trace_max.nr_entries; i++) {
118 if (stack_dump_trace[i] == ip) 124 if (stack_dump_trace[i] == ip)
119 break; 125 break;
120 } 126 }
@@ -134,18 +140,18 @@ check_stack(unsigned long ip, unsigned long *stack)
134 * loop will only happen once. This code only takes place 140 * loop will only happen once. This code only takes place
135 * on a new max, so it is far from a fast path. 141 * on a new max, so it is far from a fast path.
136 */ 142 */
137 while (i < max_stack_trace.nr_entries) { 143 while (i < stack_trace_max.nr_entries) {
138 int found = 0; 144 int found = 0;
139 145
140 stack_dump_index[x] = this_size; 146 stack_trace_index[x] = this_size;
141 p = start; 147 p = start;
142 148
143 for (; p < top && i < max_stack_trace.nr_entries; p++) { 149 for (; p < top && i < stack_trace_max.nr_entries; p++) {
144 if (stack_dump_trace[i] == ULONG_MAX) 150 if (stack_dump_trace[i] == ULONG_MAX)
145 break; 151 break;
146 if (*p == stack_dump_trace[i]) { 152 if (*p == stack_dump_trace[i]) {
147 stack_dump_trace[x] = stack_dump_trace[i++]; 153 stack_dump_trace[x] = stack_dump_trace[i++];
148 this_size = stack_dump_index[x++] = 154 this_size = stack_trace_index[x++] =
149 (top - p) * sizeof(unsigned long); 155 (top - p) * sizeof(unsigned long);
150 found = 1; 156 found = 1;
151 /* Start the search from here */ 157 /* Start the search from here */
@@ -160,7 +166,7 @@ check_stack(unsigned long ip, unsigned long *stack)
160 if (unlikely(!tracer_frame)) { 166 if (unlikely(!tracer_frame)) {
161 tracer_frame = (p - stack) * 167 tracer_frame = (p - stack) *
162 sizeof(unsigned long); 168 sizeof(unsigned long);
163 max_stack_size -= tracer_frame; 169 stack_trace_max_size -= tracer_frame;
164 } 170 }
165 } 171 }
166 } 172 }
@@ -169,18 +175,18 @@ check_stack(unsigned long ip, unsigned long *stack)
169 i++; 175 i++;
170 } 176 }
171 177
172 max_stack_trace.nr_entries = x; 178 stack_trace_max.nr_entries = x;
173 for (; x < i; x++) 179 for (; x < i; x++)
174 stack_dump_trace[x] = ULONG_MAX; 180 stack_dump_trace[x] = ULONG_MAX;
175 181
176 if (task_stack_end_corrupted(current)) { 182 if (task_stack_end_corrupted(current)) {
177 print_max_stack(); 183 stack_trace_print();
178 BUG(); 184 BUG();
179 } 185 }
180 186
181 out: 187 out:
182 rcu_irq_exit(); 188 rcu_irq_exit();
183 arch_spin_unlock(&max_stack_lock); 189 arch_spin_unlock(&stack_trace_max_lock);
184 local_irq_restore(flags); 190 local_irq_restore(flags);
185} 191}
186 192
@@ -251,9 +257,9 @@ stack_max_size_write(struct file *filp, const char __user *ubuf,
251 cpu = smp_processor_id(); 257 cpu = smp_processor_id();
252 per_cpu(trace_active, cpu)++; 258 per_cpu(trace_active, cpu)++;
253 259
254 arch_spin_lock(&max_stack_lock); 260 arch_spin_lock(&stack_trace_max_lock);
255 *ptr = val; 261 *ptr = val;
256 arch_spin_unlock(&max_stack_lock); 262 arch_spin_unlock(&stack_trace_max_lock);
257 263
258 per_cpu(trace_active, cpu)--; 264 per_cpu(trace_active, cpu)--;
259 local_irq_restore(flags); 265 local_irq_restore(flags);
@@ -273,7 +279,7 @@ __next(struct seq_file *m, loff_t *pos)
273{ 279{
274 long n = *pos - 1; 280 long n = *pos - 1;
275 281
276 if (n > max_stack_trace.nr_entries || stack_dump_trace[n] == ULONG_MAX) 282 if (n > stack_trace_max.nr_entries || stack_dump_trace[n] == ULONG_MAX)
277 return NULL; 283 return NULL;
278 284
279 m->private = (void *)n; 285 m->private = (void *)n;
@@ -296,7 +302,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)
296 cpu = smp_processor_id(); 302 cpu = smp_processor_id();
297 per_cpu(trace_active, cpu)++; 303 per_cpu(trace_active, cpu)++;
298 304
299 arch_spin_lock(&max_stack_lock); 305 arch_spin_lock(&stack_trace_max_lock);
300 306
301 if (*pos == 0) 307 if (*pos == 0)
302 return SEQ_START_TOKEN; 308 return SEQ_START_TOKEN;
@@ -308,7 +314,7 @@ static void t_stop(struct seq_file *m, void *p)
308{ 314{
309 int cpu; 315 int cpu;
310 316
311 arch_spin_unlock(&max_stack_lock); 317 arch_spin_unlock(&stack_trace_max_lock);
312 318
313 cpu = smp_processor_id(); 319 cpu = smp_processor_id();
314 per_cpu(trace_active, cpu)--; 320 per_cpu(trace_active, cpu)--;
@@ -343,9 +349,9 @@ static int t_show(struct seq_file *m, void *v)
343 seq_printf(m, " Depth Size Location" 349 seq_printf(m, " Depth Size Location"
344 " (%d entries)\n" 350 " (%d entries)\n"
345 " ----- ---- --------\n", 351 " ----- ---- --------\n",
346 max_stack_trace.nr_entries); 352 stack_trace_max.nr_entries);
347 353
348 if (!stack_tracer_enabled && !max_stack_size) 354 if (!stack_tracer_enabled && !stack_trace_max_size)
349 print_disabled(m); 355 print_disabled(m);
350 356
351 return 0; 357 return 0;
@@ -353,17 +359,17 @@ static int t_show(struct seq_file *m, void *v)
353 359
354 i = *(long *)v; 360 i = *(long *)v;
355 361
356 if (i >= max_stack_trace.nr_entries || 362 if (i >= stack_trace_max.nr_entries ||
357 stack_dump_trace[i] == ULONG_MAX) 363 stack_dump_trace[i] == ULONG_MAX)
358 return 0; 364 return 0;
359 365
360 if (i+1 == max_stack_trace.nr_entries || 366 if (i+1 == stack_trace_max.nr_entries ||
361 stack_dump_trace[i+1] == ULONG_MAX) 367 stack_dump_trace[i+1] == ULONG_MAX)
362 size = stack_dump_index[i]; 368 size = stack_trace_index[i];
363 else 369 else
364 size = stack_dump_index[i] - stack_dump_index[i+1]; 370 size = stack_trace_index[i] - stack_trace_index[i+1];
365 371
366 seq_printf(m, "%3ld) %8d %5d ", i, stack_dump_index[i], size); 372 seq_printf(m, "%3ld) %8d %5d ", i, stack_trace_index[i], size);
367 373
368 trace_lookup_stack(m, i); 374 trace_lookup_stack(m, i);
369 375
@@ -453,7 +459,7 @@ static __init int stack_trace_init(void)
453 return 0; 459 return 0;
454 460
455 trace_create_file("stack_max_size", 0644, d_tracer, 461 trace_create_file("stack_max_size", 0644, d_tracer,
456 &max_stack_size, &stack_max_size_fops); 462 &stack_trace_max_size, &stack_max_size_fops);
457 463
458 trace_create_file("stack_trace", 0444, d_tracer, 464 trace_create_file("stack_trace", 0444, d_tracer,
459 NULL, &stack_trace_fops); 465 NULL, &stack_trace_fops);
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index 7d567a4b9fa7..0655afbea83f 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -110,6 +110,7 @@ static enum print_line_t
110print_syscall_enter(struct trace_iterator *iter, int flags, 110print_syscall_enter(struct trace_iterator *iter, int flags,
111 struct trace_event *event) 111 struct trace_event *event)
112{ 112{
113 struct trace_array *tr = iter->tr;
113 struct trace_seq *s = &iter->seq; 114 struct trace_seq *s = &iter->seq;
114 struct trace_entry *ent = iter->ent; 115 struct trace_entry *ent = iter->ent;
115 struct syscall_trace_enter *trace; 116 struct syscall_trace_enter *trace;
@@ -136,7 +137,7 @@ print_syscall_enter(struct trace_iterator *iter, int flags,
136 goto end; 137 goto end;
137 138
138 /* parameter types */ 139 /* parameter types */
139 if (trace_flags & TRACE_ITER_VERBOSE) 140 if (tr->trace_flags & TRACE_ITER_VERBOSE)
140 trace_seq_printf(s, "%s ", entry->types[i]); 141 trace_seq_printf(s, "%s ", entry->types[i]);
141 142
142 /* parameter values */ 143 /* parameter values */
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 3490407dc7b7..ecd536de603a 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -91,11 +91,13 @@ static void debug_print_probes(struct tracepoint_func *funcs)
91 printk(KERN_DEBUG "Probe %d : %p\n", i, funcs[i].func); 91 printk(KERN_DEBUG "Probe %d : %p\n", i, funcs[i].func);
92} 92}
93 93
94static struct tracepoint_func *func_add(struct tracepoint_func **funcs, 94static struct tracepoint_func *
95 struct tracepoint_func *tp_func) 95func_add(struct tracepoint_func **funcs, struct tracepoint_func *tp_func,
96 int prio)
96{ 97{
97 int nr_probes = 0;
98 struct tracepoint_func *old, *new; 98 struct tracepoint_func *old, *new;
99 int nr_probes = 0;
100 int pos = -1;
99 101
100 if (WARN_ON(!tp_func->func)) 102 if (WARN_ON(!tp_func->func))
101 return ERR_PTR(-EINVAL); 103 return ERR_PTR(-EINVAL);
@@ -104,18 +106,33 @@ static struct tracepoint_func *func_add(struct tracepoint_func **funcs,
104 old = *funcs; 106 old = *funcs;
105 if (old) { 107 if (old) {
106 /* (N -> N+1), (N != 0, 1) probes */ 108 /* (N -> N+1), (N != 0, 1) probes */
107 for (nr_probes = 0; old[nr_probes].func; nr_probes++) 109 for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
110 /* Insert before probes of lower priority */
111 if (pos < 0 && old[nr_probes].prio < prio)
112 pos = nr_probes;
108 if (old[nr_probes].func == tp_func->func && 113 if (old[nr_probes].func == tp_func->func &&
109 old[nr_probes].data == tp_func->data) 114 old[nr_probes].data == tp_func->data)
110 return ERR_PTR(-EEXIST); 115 return ERR_PTR(-EEXIST);
116 }
111 } 117 }
112 /* + 2 : one for new probe, one for NULL func */ 118 /* + 2 : one for new probe, one for NULL func */
113 new = allocate_probes(nr_probes + 2); 119 new = allocate_probes(nr_probes + 2);
114 if (new == NULL) 120 if (new == NULL)
115 return ERR_PTR(-ENOMEM); 121 return ERR_PTR(-ENOMEM);
116 if (old) 122 if (old) {
117 memcpy(new, old, nr_probes * sizeof(struct tracepoint_func)); 123 if (pos < 0) {
118 new[nr_probes] = *tp_func; 124 pos = nr_probes;
125 memcpy(new, old, nr_probes * sizeof(struct tracepoint_func));
126 } else {
127 /* Copy higher priority probes ahead of the new probe */
128 memcpy(new, old, pos * sizeof(struct tracepoint_func));
129 /* Copy the rest after it. */
130 memcpy(new + pos + 1, old + pos,
131 (nr_probes - pos) * sizeof(struct tracepoint_func));
132 }
133 } else
134 pos = 0;
135 new[pos] = *tp_func;
119 new[nr_probes + 1].func = NULL; 136 new[nr_probes + 1].func = NULL;
120 *funcs = new; 137 *funcs = new;
121 debug_print_probes(*funcs); 138 debug_print_probes(*funcs);
@@ -174,7 +191,7 @@ static void *func_remove(struct tracepoint_func **funcs,
174 * Add the probe function to a tracepoint. 191 * Add the probe function to a tracepoint.
175 */ 192 */
176static int tracepoint_add_func(struct tracepoint *tp, 193static int tracepoint_add_func(struct tracepoint *tp,
177 struct tracepoint_func *func) 194 struct tracepoint_func *func, int prio)
178{ 195{
179 struct tracepoint_func *old, *tp_funcs; 196 struct tracepoint_func *old, *tp_funcs;
180 197
@@ -183,7 +200,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
183 200
184 tp_funcs = rcu_dereference_protected(tp->funcs, 201 tp_funcs = rcu_dereference_protected(tp->funcs,
185 lockdep_is_held(&tracepoints_mutex)); 202 lockdep_is_held(&tracepoints_mutex));
186 old = func_add(&tp_funcs, func); 203 old = func_add(&tp_funcs, func, prio);
187 if (IS_ERR(old)) { 204 if (IS_ERR(old)) {
188 WARN_ON_ONCE(1); 205 WARN_ON_ONCE(1);
189 return PTR_ERR(old); 206 return PTR_ERR(old);
@@ -240,6 +257,7 @@ static int tracepoint_remove_func(struct tracepoint *tp,
240 * @tp: tracepoint 257 * @tp: tracepoint
241 * @probe: probe handler 258 * @probe: probe handler
242 * @data: tracepoint data 259 * @data: tracepoint data
260 * @prio: priority of this function over other registered functions
243 * 261 *
244 * Returns 0 if ok, error value on error. 262 * Returns 0 if ok, error value on error.
245 * Note: if @tp is within a module, the caller is responsible for 263 * Note: if @tp is within a module, the caller is responsible for
@@ -247,7 +265,8 @@ static int tracepoint_remove_func(struct tracepoint *tp,
247 * performed either with a tracepoint module going notifier, or from 265 * performed either with a tracepoint module going notifier, or from
248 * within module exit functions. 266 * within module exit functions.
249 */ 267 */
250int tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data) 268int tracepoint_probe_register_prio(struct tracepoint *tp, void *probe,
269 void *data, int prio)
251{ 270{
252 struct tracepoint_func tp_func; 271 struct tracepoint_func tp_func;
253 int ret; 272 int ret;
@@ -255,10 +274,30 @@ int tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data)
255 mutex_lock(&tracepoints_mutex); 274 mutex_lock(&tracepoints_mutex);
256 tp_func.func = probe; 275 tp_func.func = probe;
257 tp_func.data = data; 276 tp_func.data = data;
258 ret = tracepoint_add_func(tp, &tp_func); 277 tp_func.prio = prio;
278 ret = tracepoint_add_func(tp, &tp_func, prio);
259 mutex_unlock(&tracepoints_mutex); 279 mutex_unlock(&tracepoints_mutex);
260 return ret; 280 return ret;
261} 281}
282EXPORT_SYMBOL_GPL(tracepoint_probe_register_prio);
283
284/**
285 * tracepoint_probe_register - Connect a probe to a tracepoint
286 * @tp: tracepoint
287 * @probe: probe handler
288 * @data: tracepoint data
289 * @prio: priority of this function over other registered functions
290 *
291 * Returns 0 if ok, error value on error.
292 * Note: if @tp is within a module, the caller is responsible for
293 * unregistering the probe before the module is gone. This can be
294 * performed either with a tracepoint module going notifier, or from
295 * within module exit functions.
296 */
297int tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data)
298{
299 return tracepoint_probe_register_prio(tp, probe, data, TRACEPOINT_DEFAULT_PRIO);
300}
262EXPORT_SYMBOL_GPL(tracepoint_probe_register); 301EXPORT_SYMBOL_GPL(tracepoint_probe_register);
263 302
264/** 303/**
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
index 125d6402f64f..d6b75bb495b3 100644
--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -4,14 +4,14 @@
4 * 4 *
5 * The define_trace.h below will also look for a file name of 5 * The define_trace.h below will also look for a file name of
6 * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here. 6 * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
7 * In this case, it would look for sample.h 7 * In this case, it would look for sample-trace.h
8 * 8 *
9 * If the header name will be different than the system name 9 * If the header name will be different than the system name
10 * (as in this case), then you can override the header name that 10 * (as in this case), then you can override the header name that
11 * define_trace.h will look up by defining TRACE_INCLUDE_FILE 11 * define_trace.h will look up by defining TRACE_INCLUDE_FILE
12 * 12 *
13 * This file is called trace-events-sample.h but we want the system 13 * This file is called trace-events-sample.h but we want the system
14 * to be called "sample". Therefore we must define the name of this 14 * to be called "sample-trace". Therefore we must define the name of this
15 * file: 15 * file:
16 * 16 *
17 * #define TRACE_INCLUDE_FILE trace-events-sample 17 * #define TRACE_INCLUDE_FILE trace-events-sample
@@ -106,7 +106,7 @@
106 * 106 *
107 * memcpy(__entry->foo, bar, 10); 107 * memcpy(__entry->foo, bar, 10);
108 * 108 *
109 * __dynamic_array: This is similar to array, but can vary is size from 109 * __dynamic_array: This is similar to array, but can vary its size from
110 * instance to instance of the tracepoint being called. 110 * instance to instance of the tracepoint being called.
111 * Like __array, this too has three elements (type, name, size); 111 * Like __array, this too has three elements (type, name, size);
112 * type is the type of the element, name is the name of the array. 112 * type is the type of the element, name is the name of the array.
diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index 3d1984e59a30..698768bdc581 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -42,6 +42,7 @@
42 42
43#ifndef EM_AARCH64 43#ifndef EM_AARCH64
44#define EM_AARCH64 183 44#define EM_AARCH64 183
45#define R_AARCH64_NONE 0
45#define R_AARCH64_ABS64 257 46#define R_AARCH64_ABS64 257
46#endif 47#endif
47 48
@@ -160,6 +161,22 @@ static int make_nop_x86(void *map, size_t const offset)
160 return 0; 161 return 0;
161} 162}
162 163
164static unsigned char ideal_nop4_arm64[4] = {0x1f, 0x20, 0x03, 0xd5};
165static int make_nop_arm64(void *map, size_t const offset)
166{
167 uint32_t *ptr;
168
169 ptr = map + offset;
170 /* bl <_mcount> is 0x94000000 before relocation */
171 if (*ptr != 0x94000000)
172 return -1;
173
174 /* Convert to nop */
175 ulseek(fd_map, offset, SEEK_SET);
176 uwrite(fd_map, ideal_nop, 4);
177 return 0;
178}
179
163/* 180/*
164 * Get the whole file as a programming convenience in order to avoid 181 * Get the whole file as a programming convenience in order to avoid
165 * malloc+lseek+read+free of many pieces. If successful, then mmap 182 * malloc+lseek+read+free of many pieces. If successful, then mmap
@@ -345,6 +362,7 @@ do_file(char const *const fname)
345 break; 362 break;
346 case EM_386: 363 case EM_386:
347 reltype = R_386_32; 364 reltype = R_386_32;
365 rel_type_nop = R_386_NONE;
348 make_nop = make_nop_x86; 366 make_nop = make_nop_x86;
349 ideal_nop = ideal_nop5_x86_32; 367 ideal_nop = ideal_nop5_x86_32;
350 mcount_adjust_32 = -1; 368 mcount_adjust_32 = -1;
@@ -353,7 +371,12 @@ do_file(char const *const fname)
353 altmcount = "__gnu_mcount_nc"; 371 altmcount = "__gnu_mcount_nc";
354 break; 372 break;
355 case EM_AARCH64: 373 case EM_AARCH64:
356 reltype = R_AARCH64_ABS64; gpfx = '_'; break; 374 reltype = R_AARCH64_ABS64;
375 make_nop = make_nop_arm64;
376 rel_type_nop = R_AARCH64_NONE;
377 ideal_nop = ideal_nop4_arm64;
378 gpfx = '_';
379 break;
357 case EM_IA_64: reltype = R_IA64_IMM64; gpfx = '_'; break; 380 case EM_IA_64: reltype = R_IA64_IMM64; gpfx = '_'; break;
358 case EM_METAG: reltype = R_METAG_ADDR32; 381 case EM_METAG: reltype = R_METAG_ADDR32;
359 altmcount = "_mcount_wrapper"; 382 altmcount = "_mcount_wrapper";
@@ -371,6 +394,7 @@ do_file(char const *const fname)
371 make_nop = make_nop_x86; 394 make_nop = make_nop_x86;
372 ideal_nop = ideal_nop5_x86_64; 395 ideal_nop = ideal_nop5_x86_64;
373 reltype = R_X86_64_64; 396 reltype = R_X86_64_64;
397 rel_type_nop = R_X86_64_NONE;
374 mcount_adjust_64 = -1; 398 mcount_adjust_64 = -1;
375 break; 399 break;
376 } /* end switch */ 400 } /* end switch */
diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h
index 49b582a225b0..b9897e2be404 100644
--- a/scripts/recordmcount.h
+++ b/scripts/recordmcount.h
@@ -377,7 +377,7 @@ static void nop_mcount(Elf_Shdr const *const relhdr,
377 377
378 if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) { 378 if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) {
379 if (make_nop) 379 if (make_nop)
380 ret = make_nop((void *)ehdr, shdr->sh_offset + relp->r_offset); 380 ret = make_nop((void *)ehdr, _w(shdr->sh_offset) + _w(relp->r_offset));
381 if (warn_on_notrace_sect && !once) { 381 if (warn_on_notrace_sect && !once) {
382 printf("Section %s has mcount callers being ignored\n", 382 printf("Section %s has mcount callers being ignored\n",
383 txtname); 383 txtname);