this_cpu: Use this_cpu_xx in nmi handling
[deliverable/linux.git] / kernel / trace / trace.h
CommitLineData
bc0c38d1
SR
1#ifndef _LINUX_KERNEL_TRACE_H
2#define _LINUX_KERNEL_TRACE_H
3
4#include <linux/fs.h>
5#include <asm/atomic.h>
6#include <linux/sched.h>
7#include <linux/clocksource.h>
3928a8a2 8#include <linux/ring_buffer.h>
bd8ac686 9#include <linux/mmiotrace.h>
4e5292ea 10#include <linux/tracepoint.h>
d13744cd 11#include <linux/ftrace.h>
3f5ec136 12#include <trace/boot.h>
02af61bb 13#include <linux/kmemtrace.h>
bc0c38d1 14
9504504c 15#include <linux/trace_seq.h>
97f20251 16#include <linux/ftrace_event.h>
9504504c 17
72829bc3
TG
18enum trace_type {
19 __TRACE_FIRST_TYPE = 0,
20
21 TRACE_FN,
22 TRACE_CTX,
23 TRACE_WAKE,
24 TRACE_STACK,
dd0e545f 25 TRACE_PRINT,
48ead020 26 TRACE_BPRINT,
72829bc3 27 TRACE_SPECIAL,
bd8ac686
PP
28 TRACE_MMIO_RW,
29 TRACE_MMIO_MAP,
9f029e83 30 TRACE_BRANCH,
74239072
FW
31 TRACE_BOOT_CALL,
32 TRACE_BOOT_RET,
287b6e68
FW
33 TRACE_GRAPH_RET,
34 TRACE_GRAPH_ENT,
02b67518 35 TRACE_USER_STACK,
a93751ca 36 TRACE_HW_BRANCHES,
36994e58
FW
37 TRACE_KMEM_ALLOC,
38 TRACE_KMEM_FREE,
c71a8961 39 TRACE_BLK,
72829bc3 40
f0868d1e 41 __TRACE_LAST_TYPE,
72829bc3
TG
42};
43
0a1c49db
SR
44enum kmemtrace_type_id {
45 KMEMTRACE_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */
46 KMEMTRACE_TYPE_CACHE, /* kmem_cache_*(). */
47 KMEMTRACE_TYPE_PAGES, /* __get_free_pages() and friends. */
287b6e68
FW
48};
49
d13744cd 50extern struct tracer boot_tracer;
bc0c38d1 51
0a1c49db
SR
52#undef __field
53#define __field(type, item) type item;
48ead020 54
d7315094
SR
55#undef __field_struct
56#define __field_struct(type, item) __field(type, item)
57
58#undef __field_desc
59#define __field_desc(type, container, item)
60
0a1c49db
SR
61#undef __array
62#define __array(type, item, size) type item[size];
777e208d 63
d7315094
SR
64#undef __array_desc
65#define __array_desc(type, container, item, size)
66
0a1c49db
SR
67#undef __dynamic_array
68#define __dynamic_array(type, item) type item[];
777e208d 69
0a1c49db
SR
70#undef F_STRUCT
71#define F_STRUCT(args...) args
74239072 72
0a1c49db
SR
73#undef FTRACE_ENTRY
74#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
75 struct struct_name { \
76 struct trace_entry ent; \
77 tstruct \
78 }
777e208d 79
0a1c49db
SR
80#undef TP_ARGS
81#define TP_ARGS(args...) args
52f232cb 82
0a1c49db
SR
83#undef FTRACE_ENTRY_DUP
84#define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk)
1e9b51c2 85
0a1c49db 86#include "trace_entries.h"
36994e58 87
0a1c49db
SR
88/*
89 * syscalls are special, and need special handling, this is why
90 * they are not included in trace_entries.h
91 */
bed1ffca
FW
92struct syscall_trace_enter {
93 struct trace_entry ent;
94 int nr;
95 unsigned long args[];
96};
97
98struct syscall_trace_exit {
99 struct trace_entry ent;
100 int nr;
101 unsigned long ret;
102};
103
fc5e27ae
PP
104/*
105 * trace_flag_type is an enumeration that holds different
106 * states when a trace occurs. These are:
9244489a 107 * IRQS_OFF - interrupts were disabled
9de36825 108 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
bd9cfca9 109 * NEED_RESCHED - reschedule is requested
9244489a
SR
110 * HARDIRQ - inside an interrupt handler
111 * SOFTIRQ - inside a softirq handler
fc5e27ae
PP
112 */
113enum trace_flag_type {
114 TRACE_FLAG_IRQS_OFF = 0x01,
9244489a
SR
115 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
116 TRACE_FLAG_NEED_RESCHED = 0x04,
117 TRACE_FLAG_HARDIRQ = 0x08,
118 TRACE_FLAG_SOFTIRQ = 0x10,
fc5e27ae
PP
119};
120
5bf9a1ee 121#define TRACE_BUF_SIZE 1024
bc0c38d1
SR
122
123/*
124 * The CPU trace array - it consists of thousands of trace entries
125 * plus some other descriptor data: (for example which task started
126 * the trace, etc.)
127 */
128struct trace_array_cpu {
bc0c38d1 129 atomic_t disabled;
2cadf913 130 void *buffer_page; /* ring buffer spare */
4e3c3333 131
bc0c38d1
SR
132 unsigned long saved_latency;
133 unsigned long critical_start;
134 unsigned long critical_end;
135 unsigned long critical_sequence;
136 unsigned long nice;
137 unsigned long policy;
138 unsigned long rt_priority;
2f26ebd5 139 unsigned long skipped_entries;
bc0c38d1
SR
140 cycle_t preempt_timestamp;
141 pid_t pid;
142 uid_t uid;
143 char comm[TASK_COMM_LEN];
144};
145
bc0c38d1
SR
146/*
147 * The trace array - an array of per-CPU trace arrays. This is the
148 * highest level data structure that individual tracers deal with.
149 * They have on/off state as well:
150 */
151struct trace_array {
3928a8a2 152 struct ring_buffer *buffer;
bc0c38d1 153 unsigned long entries;
bc0c38d1
SR
154 int cpu;
155 cycle_t time_start;
b3806b43 156 struct task_struct *waiter;
bc0c38d1
SR
157 struct trace_array_cpu *data[NR_CPUS];
158};
159
7104f300
SR
160#define FTRACE_CMP_TYPE(var, type) \
161 __builtin_types_compatible_p(typeof(var), type *)
162
163#undef IF_ASSIGN
164#define IF_ASSIGN(var, entry, etype, id) \
165 if (FTRACE_CMP_TYPE(var, etype)) { \
166 var = (typeof(var))(entry); \
167 WARN_ON(id && (entry)->type != id); \
168 break; \
169 }
170
171/* Will cause compile errors if type is not found. */
172extern void __ftrace_bad_type(void);
173
174/*
175 * The trace_assign_type is a verifier that the entry type is
176 * the same as the type being assigned. To add new types simply
177 * add a line with the following format:
178 *
179 * IF_ASSIGN(var, ent, type, id);
180 *
181 * Where "type" is the trace type that includes the trace_entry
182 * as the "ent" item. And "id" is the trace identifier that is
183 * used in the trace_type enum.
184 *
185 * If the type can have more than one id, then use zero.
186 */
187#define trace_assign_type(var, ent) \
188 do { \
189 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
190 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
7104f300 191 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
02b67518 192 IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
7104f300 193 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
48ead020 194 IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
7104f300
SR
195 IF_ASSIGN(var, ent, struct special_entry, 0); \
196 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
197 TRACE_MMIO_RW); \
198 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
199 TRACE_MMIO_MAP); \
74239072
FW
200 IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
201 IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
9f029e83 202 IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
287b6e68
FW
203 IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
204 TRACE_GRAPH_ENT); \
205 IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
206 TRACE_GRAPH_RET); \
a93751ca 207 IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
36994e58
FW
208 IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \
209 TRACE_KMEM_ALLOC); \
210 IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \
211 TRACE_KMEM_FREE); \
7104f300
SR
212 __ftrace_bad_type(); \
213 } while (0)
2c4f035f 214
adf9f195
FW
215/*
216 * An option specific to a tracer. This is a boolean value.
217 * The bit is the bit index that sets its value on the
218 * flags value in struct tracer_flags.
219 */
220struct tracer_opt {
9de36825
IM
221 const char *name; /* Will appear on the trace_options file */
222 u32 bit; /* Mask assigned in val field in tracer_flags */
adf9f195
FW
223};
224
225/*
226 * The set of specific options for a tracer. Your tracer
227 * have to set the initial value of the flags val.
228 */
229struct tracer_flags {
230 u32 val;
9de36825 231 struct tracer_opt *opts;
adf9f195
FW
232};
233
234/* Makes more easy to define a tracer opt */
235#define TRACER_OPT(s, b) .name = #s, .bit = b
236
034939b6 237
6eaaa5d5
FW
238/**
239 * struct tracer - a specific tracer and its callbacks to interact with debugfs
240 * @name: the name chosen to select it on the available_tracers file
241 * @init: called when one switches to this tracer (echo name > current_tracer)
242 * @reset: called when one switches to another tracer
243 * @start: called when tracing is unpaused (echo 1 > tracing_enabled)
244 * @stop: called when tracing is paused (echo 0 > tracing_enabled)
245 * @open: called when the trace file is opened
246 * @pipe_open: called when the trace_pipe file is opened
247 * @wait_pipe: override how the user waits for traces on trace_pipe
248 * @close: called when the trace file is released
249 * @read: override the default read callback on trace_pipe
250 * @splice_read: override the default splice_read callback on trace_pipe
251 * @selftest: selftest to run on boot (see trace_selftest.c)
252 * @print_headers: override the first lines that describe your columns
253 * @print_line: callback that prints a trace
254 * @set_flag: signals one of your private flags changed (trace_options file)
255 * @flags: your private flags
bc0c38d1
SR
256 */
257struct tracer {
258 const char *name;
1c80025a 259 int (*init)(struct trace_array *tr);
bc0c38d1 260 void (*reset)(struct trace_array *tr);
9036990d
SR
261 void (*start)(struct trace_array *tr);
262 void (*stop)(struct trace_array *tr);
bc0c38d1 263 void (*open)(struct trace_iterator *iter);
107bad8b 264 void (*pipe_open)(struct trace_iterator *iter);
6eaaa5d5 265 void (*wait_pipe)(struct trace_iterator *iter);
bc0c38d1 266 void (*close)(struct trace_iterator *iter);
107bad8b
SR
267 ssize_t (*read)(struct trace_iterator *iter,
268 struct file *filp, char __user *ubuf,
269 size_t cnt, loff_t *ppos);
3c56819b
EGM
270 ssize_t (*splice_read)(struct trace_iterator *iter,
271 struct file *filp,
272 loff_t *ppos,
273 struct pipe_inode_info *pipe,
274 size_t len,
275 unsigned int flags);
60a11774
SR
276#ifdef CONFIG_FTRACE_STARTUP_TEST
277 int (*selftest)(struct tracer *trace,
278 struct trace_array *tr);
279#endif
8bba1bf5 280 void (*print_header)(struct seq_file *m);
2c4f035f 281 enum print_line_t (*print_line)(struct trace_iterator *iter);
adf9f195
FW
282 /* If you handled the flag setting, return 0 */
283 int (*set_flag)(u32 old_flags, u32 bit, int set);
bc0c38d1
SR
284 struct tracer *next;
285 int print_max;
9de36825 286 struct tracer_flags *flags;
bc0c38d1
SR
287};
288
f9520750 289
b04cc6b1
FW
290#define TRACE_PIPE_ALL_CPU -1
291
b6f11df2 292int tracer_init(struct tracer *t, struct trace_array *tr);
9036990d 293int tracing_is_enabled(void);
45dcd8b8 294void trace_wake_up(void);
3928a8a2 295void tracing_reset(struct trace_array *tr, int cpu);
213cc060 296void tracing_reset_online_cpus(struct trace_array *tr);
9456f0fa
SR
297void tracing_reset_current(int cpu);
298void tracing_reset_current_online_cpus(void);
bc0c38d1 299int tracing_open_generic(struct inode *inode, struct file *filp);
5452af66
FW
300struct dentry *trace_create_file(const char *name,
301 mode_t mode,
302 struct dentry *parent,
303 void *data,
304 const struct file_operations *fops);
305
bc0c38d1 306struct dentry *tracing_init_dentry(void);
d618b3e6
IM
307void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
308
51a763dd
ACM
309struct ring_buffer_event;
310
e77405ad
SR
311struct ring_buffer_event *
312trace_buffer_lock_reserve(struct ring_buffer *buffer,
313 int type,
314 unsigned long len,
315 unsigned long flags,
316 int pc);
317void trace_buffer_unlock_commit(struct ring_buffer *buffer,
51a763dd
ACM
318 struct ring_buffer_event *event,
319 unsigned long flags, int pc);
320
45dcd8b8
PP
321struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
322 struct trace_array_cpu *data);
c4a8e8be
FW
323
324struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
325 int *ent_cpu, u64 *ent_ts);
326
6eaaa5d5
FW
327void default_wait_pipe(struct trace_iterator *iter);
328void poll_wait_pipe(struct trace_iterator *iter);
329
bc0c38d1
SR
330void ftrace(struct trace_array *tr,
331 struct trace_array_cpu *data,
332 unsigned long ip,
333 unsigned long parent_ip,
38697053 334 unsigned long flags, int pc);
bc0c38d1 335void tracing_sched_switch_trace(struct trace_array *tr,
bc0c38d1
SR
336 struct task_struct *prev,
337 struct task_struct *next,
38697053 338 unsigned long flags, int pc);
57422797
IM
339
340void tracing_sched_wakeup_trace(struct trace_array *tr,
57422797
IM
341 struct task_struct *wakee,
342 struct task_struct *cur,
38697053 343 unsigned long flags, int pc);
f0a920d5
IM
344void trace_special(struct trace_array *tr,
345 struct trace_array_cpu *data,
346 unsigned long arg1,
347 unsigned long arg2,
38697053 348 unsigned long arg3, int pc);
6fb44b71 349void trace_function(struct trace_array *tr,
6fb44b71
SR
350 unsigned long ip,
351 unsigned long parent_ip,
38697053 352 unsigned long flags, int pc);
bc0c38d1 353
287b6e68 354void trace_graph_return(struct ftrace_graph_ret *trace);
e49dc19c 355int trace_graph_entry(struct ftrace_graph_ent *trace);
1a0799a8 356void set_graph_array(struct trace_array *tr);
1e9b51c2 357
41bc8144
SR
358void tracing_start_cmdline_record(void);
359void tracing_stop_cmdline_record(void);
e168e051
SR
360void tracing_sched_switch_assign_trace(struct trace_array *tr);
361void tracing_stop_sched_switch_record(void);
362void tracing_start_sched_switch_record(void);
bc0c38d1
SR
363int register_tracer(struct tracer *type);
364void unregister_tracer(struct tracer *type);
b5130b1e 365int is_tracing_stopped(void);
bc0c38d1
SR
366
367extern unsigned long nsecs_to_usecs(unsigned long nsecs);
368
5d4a9dba 369#ifdef CONFIG_TRACER_MAX_TRACE
bc0c38d1
SR
370extern unsigned long tracing_max_latency;
371extern unsigned long tracing_thresh;
372
373void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
374void update_max_tr_single(struct trace_array *tr,
375 struct task_struct *tsk, int cpu);
5d4a9dba 376#endif /* CONFIG_TRACER_MAX_TRACE */
bc0c38d1 377
c0a0d0d3 378#ifdef CONFIG_STACKTRACE
e77405ad 379void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
c0a0d0d3
FW
380 int skip, int pc);
381
e77405ad 382void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
c0a0d0d3
FW
383 int pc);
384
385void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
386 int pc);
387#else
388static inline void ftrace_trace_stack(struct trace_array *tr,
389 unsigned long flags, int skip, int pc)
390{
391}
392
393static inline void ftrace_trace_userstack(struct trace_array *tr,
394 unsigned long flags, int pc)
395{
396}
397
398static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
399 int skip, int pc)
400{
401}
402#endif /* CONFIG_STACKTRACE */
53614991 403
e309b41d 404extern cycle_t ftrace_now(int cpu);
bc0c38d1 405
4ca53085 406extern void trace_find_cmdline(int pid, char comm[]);
f7d48cbd 407
bc0c38d1
SR
408#ifdef CONFIG_DYNAMIC_FTRACE
409extern unsigned long ftrace_update_tot_cnt;
d05cdb25
SR
410#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
411extern int DYN_FTRACE_TEST_NAME(void);
bc0c38d1
SR
412#endif
413
020e5f85
LZ
414extern int ring_buffer_expanded;
415extern bool tracing_selftest_disabled;
5e5bf483 416DECLARE_PER_CPU(local_t, ftrace_cpu_disabled);
020e5f85 417
60a11774 418#ifdef CONFIG_FTRACE_STARTUP_TEST
60a11774
SR
419extern int trace_selftest_startup_function(struct tracer *trace,
420 struct trace_array *tr);
7447dce9
FW
421extern int trace_selftest_startup_function_graph(struct tracer *trace,
422 struct trace_array *tr);
60a11774
SR
423extern int trace_selftest_startup_irqsoff(struct tracer *trace,
424 struct trace_array *tr);
60a11774
SR
425extern int trace_selftest_startup_preemptoff(struct tracer *trace,
426 struct trace_array *tr);
60a11774
SR
427extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
428 struct trace_array *tr);
60a11774
SR
429extern int trace_selftest_startup_wakeup(struct tracer *trace,
430 struct trace_array *tr);
fb1b6d8b
SN
431extern int trace_selftest_startup_nop(struct tracer *trace,
432 struct trace_array *tr);
60a11774
SR
433extern int trace_selftest_startup_sched_switch(struct tracer *trace,
434 struct trace_array *tr);
a6dd24f8
IM
435extern int trace_selftest_startup_sysprof(struct tracer *trace,
436 struct trace_array *tr);
80e5ea45
SR
437extern int trace_selftest_startup_branch(struct tracer *trace,
438 struct trace_array *tr);
321bb5e1
MM
439extern int trace_selftest_startup_hw_branches(struct tracer *trace,
440 struct trace_array *tr);
60a11774
SR
441#endif /* CONFIG_FTRACE_STARTUP_TEST */
442
c7aafc54 443extern void *head_page(struct trace_array_cpu *data);
cf8e3474 444extern unsigned long long ns2usecs(cycle_t nsec);
1fd8f2a3 445extern int
40ce74f1 446trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
48ead020 447extern int
40ce74f1 448trace_vprintk(unsigned long ip, const char *fmt, va_list args);
659372d3
SR
449extern int
450trace_array_vprintk(struct trace_array *tr,
451 unsigned long ip, const char *fmt, va_list args);
452int trace_array_printk(struct trace_array *tr,
453 unsigned long ip, const char *fmt, ...);
c7aafc54 454
4e655519
IM
455extern unsigned long trace_flags;
456
5079f326
Z
457extern int trace_clock_id;
458
15e6cb36 459/* Standard output formatting function used for function return traces */
fb52607a
FW
460#ifdef CONFIG_FUNCTION_GRAPH_TRACER
461extern enum print_line_t print_graph_function(struct trace_iterator *iter);
0706f1c4
SR
462extern enum print_line_t
463trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
ea4e2bc4
SR
464
465#ifdef CONFIG_DYNAMIC_FTRACE
466/* TODO: make this variable */
467#define FTRACE_GRAPH_MAX_FUNCS 32
468extern int ftrace_graph_count;
469extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
470
471static inline int ftrace_graph_addr(unsigned long addr)
472{
473 int i;
474
475 if (!ftrace_graph_count || test_tsk_trace_graph(current))
476 return 1;
477
478 for (i = 0; i < ftrace_graph_count; i++) {
479 if (addr == ftrace_graph_funcs[i])
480 return 1;
481 }
482
483 return 0;
484}
15e6cb36 485#else
ea4e2bc4
SR
486static inline int ftrace_trace_addr(unsigned long addr)
487{
6b253930
IM
488 return 1;
489}
490static inline int ftrace_graph_addr(unsigned long addr)
491{
492 return 1;
ea4e2bc4
SR
493}
494#endif /* CONFIG_DYNAMIC_FTRACE */
ea4e2bc4 495#else /* CONFIG_FUNCTION_GRAPH_TRACER */
15e6cb36 496static inline enum print_line_t
fb52607a 497print_graph_function(struct trace_iterator *iter)
15e6cb36
FW
498{
499 return TRACE_TYPE_UNHANDLED;
500}
ea4e2bc4 501#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
15e6cb36 502
978f3a45 503extern struct pid *ftrace_pid_trace;
804a6851 504
1155de47 505#ifdef CONFIG_FUNCTION_TRACER
804a6851
SR
506static inline int ftrace_trace_task(struct task_struct *task)
507{
77d683f3 508 if (!ftrace_pid_trace)
804a6851
SR
509 return 1;
510
511 return test_tsk_trace_trace(task);
512}
1155de47
PM
513#else
514static inline int ftrace_trace_task(struct task_struct *task)
515{
516 return 1;
517}
518#endif
804a6851 519
b63f39ea 520/*
521 * struct trace_parser - servers for reading the user input separated by spaces
522 * @cont: set if the input is not complete - no final space char was found
523 * @buffer: holds the parsed user input
524 * @idx: user input lenght
525 * @size: buffer size
526 */
527struct trace_parser {
528 bool cont;
529 char *buffer;
530 unsigned idx;
531 unsigned size;
532};
533
534static inline bool trace_parser_loaded(struct trace_parser *parser)
535{
536 return (parser->idx != 0);
537}
538
539static inline bool trace_parser_cont(struct trace_parser *parser)
540{
541 return parser->cont;
542}
543
544static inline void trace_parser_clear(struct trace_parser *parser)
545{
546 parser->cont = false;
547 parser->idx = 0;
548}
549
550extern int trace_parser_get_init(struct trace_parser *parser, int size);
551extern void trace_parser_put(struct trace_parser *parser);
552extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
553 size_t cnt, loff_t *ppos);
554
4fcdae83
SR
555/*
556 * trace_iterator_flags is an enumeration that defines bit
557 * positions into trace_flags that controls the output.
558 *
559 * NOTE: These bits must match the trace_options array in
560 * trace.c.
561 */
4e655519
IM
562enum trace_iterator_flags {
563 TRACE_ITER_PRINT_PARENT = 0x01,
564 TRACE_ITER_SYM_OFFSET = 0x02,
565 TRACE_ITER_SYM_ADDR = 0x04,
566 TRACE_ITER_VERBOSE = 0x08,
567 TRACE_ITER_RAW = 0x10,
568 TRACE_ITER_HEX = 0x20,
569 TRACE_ITER_BIN = 0x40,
570 TRACE_ITER_BLOCK = 0x80,
571 TRACE_ITER_STACKTRACE = 0x100,
4ac3ba41 572 TRACE_ITER_SCHED_TREE = 0x200,
f09ce573 573 TRACE_ITER_PRINTK = 0x400,
b2a866f9 574 TRACE_ITER_PREEMPTONLY = 0x800,
9f029e83 575 TRACE_ITER_BRANCH = 0x1000,
12ef7d44 576 TRACE_ITER_ANNOTATE = 0x2000,
b54d3de9 577 TRACE_ITER_USERSTACKTRACE = 0x4000,
66896a85 578 TRACE_ITER_SYM_USEROBJ = 0x8000,
c4a8e8be 579 TRACE_ITER_PRINTK_MSGONLY = 0x10000,
c032ef64
SR
580 TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */
581 TRACE_ITER_LATENCY_FMT = 0x40000,
5079f326
Z
582 TRACE_ITER_SLEEP_TIME = 0x80000,
583 TRACE_ITER_GRAPH_TIME = 0x100000,
4e655519
IM
584};
585
15e6cb36
FW
586/*
587 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
588 * control the output of kernel symbols.
589 */
590#define TRACE_ITER_SYM_MASK \
591 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
592
43a15386
FW
593extern struct tracer nop_trace;
594
8f0a056f
SR
595/**
596 * ftrace_preempt_disable - disable preemption scheduler safe
597 *
598 * When tracing can happen inside the scheduler, there exists
599 * cases that the tracing might happen before the need_resched
600 * flag is checked. If this happens and the tracer calls
601 * preempt_enable (after a disable), a schedule might take place
602 * causing an infinite recursion.
603 *
57794a9d 604 * To prevent this, we read the need_resched flag before
8f0a056f
SR
605 * disabling preemption. When we want to enable preemption we
606 * check the flag, if it is set, then we call preempt_enable_no_resched.
607 * Otherwise, we call preempt_enable.
608 *
57794a9d 609 * The rational for doing the above is that if need_resched is set
8f0a056f
SR
610 * and we have yet to reschedule, we are either in an atomic location
611 * (where we do not need to check for scheduling) or we are inside
612 * the scheduler and do not want to resched.
613 */
614static inline int ftrace_preempt_disable(void)
615{
616 int resched;
617
618 resched = need_resched();
619 preempt_disable_notrace();
620
621 return resched;
622}
623
624/**
625 * ftrace_preempt_enable - enable preemption scheduler safe
626 * @resched: the return value from ftrace_preempt_disable
627 *
628 * This is a scheduler safe way to enable preemption and not miss
629 * any preemption checks. The disabled saved the state of preemption.
57794a9d 630 * If resched is set, then we are either inside an atomic or
8f0a056f
SR
631 * are inside the scheduler (we would have already scheduled
632 * otherwise). In this case, we do not want to call normal
633 * preempt_enable, but preempt_enable_no_resched instead.
634 */
635static inline void ftrace_preempt_enable(int resched)
636{
637 if (resched)
638 preempt_enable_no_resched_notrace();
639 else
640 preempt_enable_notrace();
641}
642
2ed84eeb 643#ifdef CONFIG_BRANCH_TRACER
9f029e83
SR
644extern int enable_branch_tracing(struct trace_array *tr);
645extern void disable_branch_tracing(void);
646static inline int trace_branch_enable(struct trace_array *tr)
52f232cb 647{
9f029e83
SR
648 if (trace_flags & TRACE_ITER_BRANCH)
649 return enable_branch_tracing(tr);
52f232cb
SR
650 return 0;
651}
9f029e83 652static inline void trace_branch_disable(void)
52f232cb
SR
653{
654 /* due to races, always disable */
9f029e83 655 disable_branch_tracing();
52f232cb
SR
656}
657#else
9f029e83 658static inline int trace_branch_enable(struct trace_array *tr)
52f232cb
SR
659{
660 return 0;
661}
9f029e83 662static inline void trace_branch_disable(void)
52f232cb
SR
663{
664}
2ed84eeb 665#endif /* CONFIG_BRANCH_TRACER */
52f232cb 666
1852fcce
SR
667/* set ring buffers to default size if not already done so */
668int tracing_update_buffers(void);
669
fd994989
SR
670/* trace event type bit fields, not numeric */
671enum {
672 TRACE_EVENT_TYPE_PRINTF = 1,
673 TRACE_EVENT_TYPE_RAW = 2,
674};
675
cf027f64
TZ
676struct ftrace_event_field {
677 struct list_head link;
678 char *name;
679 char *type;
aa38e9fc 680 int filter_type;
cf027f64
TZ
681 int offset;
682 int size;
a118e4d1 683 int is_signed;
cf027f64
TZ
684};
685
30e673b2
TZ
686struct event_filter {
687 int n_preds;
688 struct filter_pred **preds;
8b372562 689 char *filter_string;
1f9963cb 690 bool no_reset;
30e673b2
TZ
691};
692
cfb180f3
TZ
693struct event_subsystem {
694 struct list_head list;
695 const char *name;
696 struct dentry *entry;
1f9963cb 697 struct event_filter *filter;
dc82ec98 698 int nr_events;
cfb180f3
TZ
699};
700
7ce7e424
TZ
701struct filter_pred;
702
8b372562
TZ
703typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event,
704 int val1, int val2);
7ce7e424
TZ
705
706struct filter_pred {
707 filter_pred_fn_t fn;
708 u64 val;
0a19e53c 709 char str_val[MAX_FILTER_STR_VAL];
7ce7e424
TZ
710 int str_len;
711 char *field_name;
712 int offset;
713 int not;
8b372562
TZ
714 int op;
715 int pop_n;
7ce7e424
TZ
716};
717
8b372562 718extern void print_event_filter(struct ftrace_event_call *call,
4bda2d51 719 struct trace_seq *s);
8b372562
TZ
720extern int apply_event_filter(struct ftrace_event_call *call,
721 char *filter_string);
722extern int apply_subsystem_event_filter(struct event_subsystem *system,
723 char *filter_string);
724extern void print_subsystem_event_filter(struct event_subsystem *system,
ac1adc55 725 struct trace_seq *s);
aa38e9fc 726extern int filter_assign_type(const char *type);
7ce7e424 727
eb02ce01 728static inline int
e1112b4d 729filter_check_discard(struct ftrace_event_call *call, void *rec,
eb02ce01 730 struct ring_buffer *buffer,
e1112b4d
TZ
731 struct ring_buffer_event *event)
732{
30e673b2 733 if (unlikely(call->filter_active) && !filter_match_preds(call, rec)) {
eb02ce01
TZ
734 ring_buffer_discard_commit(buffer, event);
735 return 1;
736 }
737
738 return 0;
e1112b4d
TZ
739}
740
20c8928a 741extern struct mutex event_mutex;
a59fd602 742extern struct list_head ftrace_events;
ac199db0 743
e9fb2b6d
SR
744extern const char *__start___trace_bprintk_fmt[];
745extern const char *__stop___trace_bprintk_fmt[];
746
4e5292ea
SR
747#undef FTRACE_ENTRY
748#define FTRACE_ENTRY(call, struct_name, id, tstruct, print) \
e1112b4d 749 extern struct ftrace_event_call event_##call;
4e5292ea
SR
750#undef FTRACE_ENTRY_DUP
751#define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print) \
752 FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
753#include "trace_entries.h"
e1112b4d 754
bc0c38d1 755#endif /* _LINUX_KERNEL_TRACE_H */
This page took 0.152455 seconds and 5 git commands to generate.