]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - kernel/trace/trace.h
tracing/fastboot: move boot tracer structs and funcs into their own header.
[mirror_ubuntu-zesty-kernel.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>
d13744cd 10#include <linux/ftrace.h>
3f5ec136 11#include <trace/boot.h>
bc0c38d1 12
72829bc3
TG
13enum trace_type {
14 __TRACE_FIRST_TYPE = 0,
15
16 TRACE_FN,
17 TRACE_CTX,
18 TRACE_WAKE,
dd0e545f 19 TRACE_CONT,
72829bc3 20 TRACE_STACK,
dd0e545f 21 TRACE_PRINT,
72829bc3 22 TRACE_SPECIAL,
bd8ac686
PP
23 TRACE_MMIO_RW,
24 TRACE_MMIO_MAP,
d13744cd 25 TRACE_BOOT,
15e6cb36 26 TRACE_FN_RET,
72829bc3
TG
27
28 __TRACE_LAST_TYPE
29};
30
777e208d
SR
31/*
32 * The trace entry - the most basic unit of tracing. This is what
33 * is printed in the end as a single line in the trace output, such as:
34 *
35 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
36 */
37struct trace_entry {
38 unsigned char type;
39 unsigned char cpu;
40 unsigned char flags;
41 unsigned char preempt_count;
42 int pid;
43};
44
bc0c38d1
SR
45/*
46 * Function trace entry - function address and parent function addres:
47 */
48struct ftrace_entry {
777e208d 49 struct trace_entry ent;
bc0c38d1
SR
50 unsigned long ip;
51 unsigned long parent_ip;
52};
15e6cb36
FW
53
54/* Function return entry */
55struct ftrace_ret_entry {
56 struct trace_entry ent;
57 unsigned long ip;
58 unsigned long parent_ip;
59 unsigned long long calltime;
60 unsigned long long rettime;
61};
d13744cd 62extern struct tracer boot_tracer;
bc0c38d1
SR
63
64/*
65 * Context switch trace entry - which task (and prio) we switched from/to:
66 */
67struct ctx_switch_entry {
777e208d 68 struct trace_entry ent;
bc0c38d1
SR
69 unsigned int prev_pid;
70 unsigned char prev_prio;
71 unsigned char prev_state;
72 unsigned int next_pid;
73 unsigned char next_prio;
bac524d3 74 unsigned char next_state;
80b5e940 75 unsigned int next_cpu;
bc0c38d1
SR
76};
77
f0a920d5
IM
78/*
79 * Special (free-form) trace entry:
80 */
81struct special_entry {
777e208d 82 struct trace_entry ent;
f0a920d5
IM
83 unsigned long arg1;
84 unsigned long arg2;
85 unsigned long arg3;
86};
87
86387f7e
IM
88/*
89 * Stack-trace entry:
90 */
91
74f4e369 92#define FTRACE_STACK_ENTRIES 8
86387f7e
IM
93
94struct stack_entry {
777e208d 95 struct trace_entry ent;
86387f7e
IM
96 unsigned long caller[FTRACE_STACK_ENTRIES];
97};
98
dd0e545f
SR
99/*
100 * ftrace_printk entry:
101 */
102struct print_entry {
777e208d 103 struct trace_entry ent;
dd0e545f
SR
104 unsigned long ip;
105 char buf[];
106};
107
777e208d
SR
108#define TRACE_OLD_SIZE 88
109
110struct trace_field_cont {
111 unsigned char type;
112 /* Temporary till we get rid of this completely */
113 char buf[TRACE_OLD_SIZE - 1];
114};
115
116struct trace_mmiotrace_rw {
117 struct trace_entry ent;
118 struct mmiotrace_rw rw;
119};
120
121struct trace_mmiotrace_map {
122 struct trace_entry ent;
123 struct mmiotrace_map map;
124};
125
126struct trace_boot {
127 struct trace_entry ent;
128 struct boot_trace initcall;
129};
130
fc5e27ae
PP
131/*
132 * trace_flag_type is an enumeration that holds different
133 * states when a trace occurs. These are:
9244489a
SR
134 * IRQS_OFF - interrupts were disabled
135 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
136 * NEED_RESCED - reschedule is requested
137 * HARDIRQ - inside an interrupt handler
138 * SOFTIRQ - inside a softirq handler
139 * CONT - multiple entries hold the trace item
fc5e27ae
PP
140 */
141enum trace_flag_type {
142 TRACE_FLAG_IRQS_OFF = 0x01,
9244489a
SR
143 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
144 TRACE_FLAG_NEED_RESCHED = 0x04,
145 TRACE_FLAG_HARDIRQ = 0x08,
146 TRACE_FLAG_SOFTIRQ = 0x10,
147 TRACE_FLAG_CONT = 0x20,
fc5e27ae
PP
148};
149
5bf9a1ee 150#define TRACE_BUF_SIZE 1024
bc0c38d1
SR
151
152/*
153 * The CPU trace array - it consists of thousands of trace entries
154 * plus some other descriptor data: (for example which task started
155 * the trace, etc.)
156 */
157struct trace_array_cpu {
bc0c38d1 158 atomic_t disabled;
4e3c3333 159
c7aafc54 160 /* these fields get copied into max-trace: */
c7aafc54 161 unsigned long trace_idx;
53d0aa77 162 unsigned long overrun;
bc0c38d1
SR
163 unsigned long saved_latency;
164 unsigned long critical_start;
165 unsigned long critical_end;
166 unsigned long critical_sequence;
167 unsigned long nice;
168 unsigned long policy;
169 unsigned long rt_priority;
170 cycle_t preempt_timestamp;
171 pid_t pid;
172 uid_t uid;
173 char comm[TASK_COMM_LEN];
174};
175
176struct trace_iterator;
177
178/*
179 * The trace array - an array of per-CPU trace arrays. This is the
180 * highest level data structure that individual tracers deal with.
181 * They have on/off state as well:
182 */
183struct trace_array {
3928a8a2 184 struct ring_buffer *buffer;
bc0c38d1 185 unsigned long entries;
bc0c38d1
SR
186 int cpu;
187 cycle_t time_start;
b3806b43 188 struct task_struct *waiter;
bc0c38d1
SR
189 struct trace_array_cpu *data[NR_CPUS];
190};
191
7104f300
SR
192#define FTRACE_CMP_TYPE(var, type) \
193 __builtin_types_compatible_p(typeof(var), type *)
194
195#undef IF_ASSIGN
196#define IF_ASSIGN(var, entry, etype, id) \
197 if (FTRACE_CMP_TYPE(var, etype)) { \
198 var = (typeof(var))(entry); \
199 WARN_ON(id && (entry)->type != id); \
200 break; \
201 }
202
203/* Will cause compile errors if type is not found. */
204extern void __ftrace_bad_type(void);
205
206/*
207 * The trace_assign_type is a verifier that the entry type is
208 * the same as the type being assigned. To add new types simply
209 * add a line with the following format:
210 *
211 * IF_ASSIGN(var, ent, type, id);
212 *
213 * Where "type" is the trace type that includes the trace_entry
214 * as the "ent" item. And "id" is the trace identifier that is
215 * used in the trace_type enum.
216 *
217 * If the type can have more than one id, then use zero.
218 */
219#define trace_assign_type(var, ent) \
220 do { \
221 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
222 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
223 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
224 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
225 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
226 IF_ASSIGN(var, ent, struct special_entry, 0); \
227 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
228 TRACE_MMIO_RW); \
229 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
230 TRACE_MMIO_MAP); \
231 IF_ASSIGN(var, ent, struct trace_boot, TRACE_BOOT); \
15e6cb36 232 IF_ASSIGN(var, ent, struct ftrace_ret_entry, TRACE_FN_RET); \
7104f300
SR
233 __ftrace_bad_type(); \
234 } while (0)
2c4f035f
FW
235
236/* Return values for print_line callback */
237enum print_line_t {
238 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
239 TRACE_TYPE_HANDLED = 1,
240 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
241};
242
bc0c38d1
SR
243/*
244 * A specific tracer, represented by methods that operate on a trace array:
245 */
246struct tracer {
247 const char *name;
248 void (*init)(struct trace_array *tr);
249 void (*reset)(struct trace_array *tr);
9036990d
SR
250 void (*start)(struct trace_array *tr);
251 void (*stop)(struct trace_array *tr);
bc0c38d1 252 void (*open)(struct trace_iterator *iter);
107bad8b 253 void (*pipe_open)(struct trace_iterator *iter);
bc0c38d1 254 void (*close)(struct trace_iterator *iter);
107bad8b
SR
255 ssize_t (*read)(struct trace_iterator *iter,
256 struct file *filp, char __user *ubuf,
257 size_t cnt, loff_t *ppos);
60a11774
SR
258#ifdef CONFIG_FTRACE_STARTUP_TEST
259 int (*selftest)(struct tracer *trace,
260 struct trace_array *tr);
261#endif
2c4f035f 262 enum print_line_t (*print_line)(struct trace_iterator *iter);
bc0c38d1
SR
263 struct tracer *next;
264 int print_max;
265};
266
214023c3
SR
267struct trace_seq {
268 unsigned char buffer[PAGE_SIZE];
269 unsigned int len;
6c6c2796 270 unsigned int readpos;
214023c3
SR
271};
272
bc0c38d1
SR
273/*
274 * Trace iterator - used by printout routines who present trace
275 * results to users and which routines might sleep, etc:
276 */
277struct trace_iterator {
278 struct trace_array *tr;
279 struct tracer *trace;
107bad8b 280 void *private;
3928a8a2 281 struct ring_buffer_iter *buffer_iter[NR_CPUS];
4e3c3333 282
53d0aa77
SR
283 /* The below is zeroed out in pipe_read */
284 struct trace_seq seq;
bc0c38d1 285 struct trace_entry *ent;
4e3c3333 286 int cpu;
3928a8a2 287 u64 ts;
4e3c3333 288
bc0c38d1
SR
289 unsigned long iter_flags;
290 loff_t pos;
4c11d7ae 291 long idx;
a309720c
SR
292
293 cpumask_t started;
bc0c38d1
SR
294};
295
9036990d 296int tracing_is_enabled(void);
45dcd8b8 297void trace_wake_up(void);
3928a8a2 298void tracing_reset(struct trace_array *tr, int cpu);
bc0c38d1
SR
299int tracing_open_generic(struct inode *inode, struct file *filp);
300struct dentry *tracing_init_dentry(void);
d618b3e6
IM
301void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
302
45dcd8b8
PP
303struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
304 struct trace_array_cpu *data);
305void tracing_generic_entry_update(struct trace_entry *entry,
38697053
SR
306 unsigned long flags,
307 int pc);
45dcd8b8 308
bc0c38d1
SR
309void ftrace(struct trace_array *tr,
310 struct trace_array_cpu *data,
311 unsigned long ip,
312 unsigned long parent_ip,
38697053 313 unsigned long flags, int pc);
bc0c38d1
SR
314void tracing_sched_switch_trace(struct trace_array *tr,
315 struct trace_array_cpu *data,
316 struct task_struct *prev,
317 struct task_struct *next,
38697053 318 unsigned long flags, int pc);
bc0c38d1 319void tracing_record_cmdline(struct task_struct *tsk);
57422797
IM
320
321void tracing_sched_wakeup_trace(struct trace_array *tr,
322 struct trace_array_cpu *data,
323 struct task_struct *wakee,
324 struct task_struct *cur,
38697053 325 unsigned long flags, int pc);
f0a920d5
IM
326void trace_special(struct trace_array *tr,
327 struct trace_array_cpu *data,
328 unsigned long arg1,
329 unsigned long arg2,
38697053 330 unsigned long arg3, int pc);
6fb44b71
SR
331void trace_function(struct trace_array *tr,
332 struct trace_array_cpu *data,
333 unsigned long ip,
334 unsigned long parent_ip,
38697053 335 unsigned long flags, int pc);
15e6cb36
FW
336void
337trace_function_return(struct ftrace_retfunc *trace);
bc0c38d1 338
41bc8144
SR
339void tracing_start_cmdline_record(void);
340void tracing_stop_cmdline_record(void);
e168e051
SR
341void tracing_sched_switch_assign_trace(struct trace_array *tr);
342void tracing_stop_sched_switch_record(void);
343void tracing_start_sched_switch_record(void);
bc0c38d1
SR
344int register_tracer(struct tracer *type);
345void unregister_tracer(struct tracer *type);
346
347extern unsigned long nsecs_to_usecs(unsigned long nsecs);
348
349extern unsigned long tracing_max_latency;
350extern unsigned long tracing_thresh;
351
352void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
353void update_max_tr_single(struct trace_array *tr,
354 struct task_struct *tsk, int cpu);
355
e309b41d 356extern cycle_t ftrace_now(int cpu);
bc0c38d1 357
606576ce 358#ifdef CONFIG_FUNCTION_TRACER
001b6767
SR
359void tracing_start_function_trace(void);
360void tracing_stop_function_trace(void);
361#else
362# define tracing_start_function_trace() do { } while (0)
363# define tracing_stop_function_trace() do { } while (0)
364#endif
365
bc0c38d1
SR
366#ifdef CONFIG_CONTEXT_SWITCH_TRACER
367typedef void
368(*tracer_switch_func_t)(void *private,
5b82a1b0 369 void *__rq,
bc0c38d1
SR
370 struct task_struct *prev,
371 struct task_struct *next);
372
373struct tracer_switch_ops {
374 tracer_switch_func_t func;
375 void *private;
376 struct tracer_switch_ops *next;
377};
378
bc0c38d1
SR
379#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
380
381#ifdef CONFIG_DYNAMIC_FTRACE
382extern unsigned long ftrace_update_tot_cnt;
d05cdb25
SR
383#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
384extern int DYN_FTRACE_TEST_NAME(void);
bc0c38d1
SR
385#endif
386
60a11774 387#ifdef CONFIG_FTRACE_STARTUP_TEST
60a11774
SR
388extern int trace_selftest_startup_function(struct tracer *trace,
389 struct trace_array *tr);
60a11774
SR
390extern int trace_selftest_startup_irqsoff(struct tracer *trace,
391 struct trace_array *tr);
60a11774
SR
392extern int trace_selftest_startup_preemptoff(struct tracer *trace,
393 struct trace_array *tr);
60a11774
SR
394extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
395 struct trace_array *tr);
60a11774
SR
396extern int trace_selftest_startup_wakeup(struct tracer *trace,
397 struct trace_array *tr);
fb1b6d8b
SN
398extern int trace_selftest_startup_nop(struct tracer *trace,
399 struct trace_array *tr);
60a11774
SR
400extern int trace_selftest_startup_sched_switch(struct tracer *trace,
401 struct trace_array *tr);
a6dd24f8
IM
402extern int trace_selftest_startup_sysprof(struct tracer *trace,
403 struct trace_array *tr);
60a11774
SR
404#endif /* CONFIG_FTRACE_STARTUP_TEST */
405
c7aafc54 406extern void *head_page(struct trace_array_cpu *data);
72829bc3 407extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
fc5e27ae
PP
408extern void trace_seq_print_cont(struct trace_seq *s,
409 struct trace_iterator *iter);
15e6cb36
FW
410
411extern int
412seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
413 unsigned long sym_flags);
6c6c2796
PP
414extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
415 size_t cnt);
72829bc3 416extern long ns2usecs(cycle_t nsec);
801fe400 417extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
c7aafc54 418
4e655519
IM
419extern unsigned long trace_flags;
420
15e6cb36
FW
421/* Standard output formatting function used for function return traces */
422#ifdef CONFIG_FUNCTION_RET_TRACER
423extern enum print_line_t print_return_function(struct trace_iterator *iter);
424#else
425static inline enum print_line_t
426print_return_function(struct trace_iterator *iter)
427{
428 return TRACE_TYPE_UNHANDLED;
429}
430#endif
431
4fcdae83
SR
432/*
433 * trace_iterator_flags is an enumeration that defines bit
434 * positions into trace_flags that controls the output.
435 *
436 * NOTE: These bits must match the trace_options array in
437 * trace.c.
438 */
4e655519
IM
439enum trace_iterator_flags {
440 TRACE_ITER_PRINT_PARENT = 0x01,
441 TRACE_ITER_SYM_OFFSET = 0x02,
442 TRACE_ITER_SYM_ADDR = 0x04,
443 TRACE_ITER_VERBOSE = 0x08,
444 TRACE_ITER_RAW = 0x10,
445 TRACE_ITER_HEX = 0x20,
446 TRACE_ITER_BIN = 0x40,
447 TRACE_ITER_BLOCK = 0x80,
448 TRACE_ITER_STACKTRACE = 0x100,
4ac3ba41 449 TRACE_ITER_SCHED_TREE = 0x200,
f09ce573 450 TRACE_ITER_PRINTK = 0x400,
b2a866f9 451 TRACE_ITER_PREEMPTONLY = 0x800,
4e655519
IM
452};
453
15e6cb36
FW
454/*
455 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
456 * control the output of kernel symbols.
457 */
458#define TRACE_ITER_SYM_MASK \
459 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
460
43a15386
FW
461extern struct tracer nop_trace;
462
8f0a056f
SR
463/**
464 * ftrace_preempt_disable - disable preemption scheduler safe
465 *
466 * When tracing can happen inside the scheduler, there exists
467 * cases that the tracing might happen before the need_resched
468 * flag is checked. If this happens and the tracer calls
469 * preempt_enable (after a disable), a schedule might take place
470 * causing an infinite recursion.
471 *
472 * To prevent this, we read the need_recshed flag before
473 * disabling preemption. When we want to enable preemption we
474 * check the flag, if it is set, then we call preempt_enable_no_resched.
475 * Otherwise, we call preempt_enable.
476 *
477 * The rational for doing the above is that if need resched is set
478 * and we have yet to reschedule, we are either in an atomic location
479 * (where we do not need to check for scheduling) or we are inside
480 * the scheduler and do not want to resched.
481 */
482static inline int ftrace_preempt_disable(void)
483{
484 int resched;
485
486 resched = need_resched();
487 preempt_disable_notrace();
488
489 return resched;
490}
491
492/**
493 * ftrace_preempt_enable - enable preemption scheduler safe
494 * @resched: the return value from ftrace_preempt_disable
495 *
496 * This is a scheduler safe way to enable preemption and not miss
497 * any preemption checks. The disabled saved the state of preemption.
498 * If resched is set, then we were either inside an atomic or
499 * are inside the scheduler (we would have already scheduled
500 * otherwise). In this case, we do not want to call normal
501 * preempt_enable, but preempt_enable_no_resched instead.
502 */
503static inline void ftrace_preempt_enable(int resched)
504{
505 if (resched)
506 preempt_enable_no_resched_notrace();
507 else
508 preempt_enable_notrace();
509}
510
bc0c38d1 511#endif /* _LINUX_KERNEL_TRACE_H */