1 #ifndef _LINUX_KERNEL_TRACE_H
2 #define _LINUX_KERNEL_TRACE_H
5 #include <asm/atomic.h>
6 #include <linux/sched.h>
7 #include <linux/clocksource.h>
10 * Function trace entry - function address and parent function addres:
14 unsigned long parent_ip
;
18 * Context switch trace entry - which task (and prio) we switched from/to:
20 struct ctx_switch_entry
{
21 unsigned int prev_pid
;
22 unsigned char prev_prio
;
23 unsigned char prev_state
;
24 unsigned int next_pid
;
25 unsigned char next_prio
;
26 unsigned char next_state
;
30 * Special (free-form) trace entry:
32 struct special_entry
{
42 #define FTRACE_STACK_ENTRIES 5
45 unsigned long caller
[FTRACE_STACK_ENTRIES
];
49 * The trace entry - the most basic unit of tracing. This is what
50 * is printed in the end as a single line in the trace output, such as:
52 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
62 struct ftrace_entry fn
;
63 struct ctx_switch_entry ctx
;
64 struct special_entry special
;
65 struct stack_entry stack
;
69 #define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
72 * The CPU trace array - it consists of thousands of trace entries
73 * plus some other descriptor data: (for example which task started
76 struct trace_array_cpu
{
77 struct list_head trace_pages
;
80 struct lock_class_key lock_key
;
82 /* these fields get copied into max-trace: */
83 unsigned trace_head_idx
;
84 unsigned trace_tail_idx
;
85 void *trace_head
; /* producer */
86 void *trace_tail
; /* consumer */
87 unsigned long trace_idx
;
88 unsigned long saved_latency
;
89 unsigned long critical_start
;
90 unsigned long critical_end
;
91 unsigned long critical_sequence
;
94 unsigned long rt_priority
;
95 cycle_t preempt_timestamp
;
98 char comm
[TASK_COMM_LEN
];
101 struct trace_iterator
;
104 * The trace array - an array of per-CPU trace arrays. This is the
105 * highest level data structure that individual tracers deal with.
106 * They have on/off state as well:
109 unsigned long entries
;
113 struct task_struct
*waiter
;
114 struct trace_array_cpu
*data
[NR_CPUS
];
118 * A specific tracer, represented by methods that operate on a trace array:
122 void (*init
)(struct trace_array
*tr
);
123 void (*reset
)(struct trace_array
*tr
);
124 void (*open
)(struct trace_iterator
*iter
);
125 void (*close
)(struct trace_iterator
*iter
);
126 void (*start
)(struct trace_iterator
*iter
);
127 void (*stop
)(struct trace_iterator
*iter
);
128 void (*ctrl_update
)(struct trace_array
*tr
);
129 #ifdef CONFIG_FTRACE_STARTUP_TEST
130 int (*selftest
)(struct tracer
*trace
,
131 struct trace_array
*tr
);
138 unsigned char buffer
[PAGE_SIZE
];
143 * Trace iterator - used by printout routines who present trace
144 * results to users and which routines might sleep, etc:
146 struct trace_iterator
{
147 struct trace_seq seq
;
148 struct trace_array
*tr
;
149 struct tracer
*trace
;
151 struct trace_entry
*ent
;
154 struct trace_entry
*prev_ent
;
157 unsigned long iter_flags
;
159 unsigned long next_idx
[NR_CPUS
];
160 struct list_head
*next_page
[NR_CPUS
];
161 unsigned next_page_idx
[NR_CPUS
];
165 void tracing_reset(struct trace_array_cpu
*data
);
166 int tracing_open_generic(struct inode
*inode
, struct file
*filp
);
167 struct dentry
*tracing_init_dentry(void);
168 void ftrace(struct trace_array
*tr
,
169 struct trace_array_cpu
*data
,
171 unsigned long parent_ip
,
172 unsigned long flags
);
173 void tracing_sched_switch_trace(struct trace_array
*tr
,
174 struct trace_array_cpu
*data
,
175 struct task_struct
*prev
,
176 struct task_struct
*next
,
177 unsigned long flags
);
178 void tracing_record_cmdline(struct task_struct
*tsk
);
180 void tracing_sched_wakeup_trace(struct trace_array
*tr
,
181 struct trace_array_cpu
*data
,
182 struct task_struct
*wakee
,
183 struct task_struct
*cur
,
184 unsigned long flags
);
185 void trace_special(struct trace_array
*tr
,
186 struct trace_array_cpu
*data
,
190 void trace_function(struct trace_array
*tr
,
191 struct trace_array_cpu
*data
,
193 unsigned long parent_ip
,
194 unsigned long flags
);
196 void tracing_start_function_trace(void);
197 void tracing_stop_function_trace(void);
198 int register_tracer(struct tracer
*type
);
199 void unregister_tracer(struct tracer
*type
);
201 extern unsigned long nsecs_to_usecs(unsigned long nsecs
);
203 extern unsigned long tracing_max_latency
;
204 extern unsigned long tracing_thresh
;
206 void update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
);
207 void update_max_tr_single(struct trace_array
*tr
,
208 struct task_struct
*tsk
, int cpu
);
210 extern cycle_t
ftrace_now(int cpu
);
212 #ifdef CONFIG_SCHED_TRACER
214 wakeup_sched_switch(struct task_struct
*prev
, struct task_struct
*next
);
216 wakeup_sched_wakeup(struct task_struct
*wakee
, struct task_struct
*curr
);
219 wakeup_sched_switch(struct task_struct
*prev
, struct task_struct
*next
)
223 wakeup_sched_wakeup(struct task_struct
*wakee
, struct task_struct
*curr
)
228 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
230 (*tracer_switch_func_t
)(void *private,
231 struct task_struct
*prev
,
232 struct task_struct
*next
);
234 struct tracer_switch_ops
{
235 tracer_switch_func_t func
;
237 struct tracer_switch_ops
*next
;
240 extern int register_tracer_switch(struct tracer_switch_ops
*ops
);
241 extern int unregister_tracer_switch(struct tracer_switch_ops
*ops
);
243 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
245 #ifdef CONFIG_DYNAMIC_FTRACE
246 extern unsigned long ftrace_update_tot_cnt
;
247 #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
248 extern int DYN_FTRACE_TEST_NAME(void);
251 #ifdef CONFIG_FTRACE_STARTUP_TEST
253 extern int trace_selftest_startup_function(struct tracer
*trace
,
254 struct trace_array
*tr
);
256 #ifdef CONFIG_IRQSOFF_TRACER
257 extern int trace_selftest_startup_irqsoff(struct tracer
*trace
,
258 struct trace_array
*tr
);
260 #ifdef CONFIG_PREEMPT_TRACER
261 extern int trace_selftest_startup_preemptoff(struct tracer
*trace
,
262 struct trace_array
*tr
);
264 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
265 extern int trace_selftest_startup_preemptirqsoff(struct tracer
*trace
,
266 struct trace_array
*tr
);
268 #ifdef CONFIG_SCHED_TRACER
269 extern int trace_selftest_startup_wakeup(struct tracer
*trace
,
270 struct trace_array
*tr
);
272 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
273 extern int trace_selftest_startup_sched_switch(struct tracer
*trace
,
274 struct trace_array
*tr
);
276 #endif /* CONFIG_FTRACE_STARTUP_TEST */
278 extern void *head_page(struct trace_array_cpu
*data
);
280 extern unsigned long trace_flags
;
282 enum trace_iterator_flags
{
283 TRACE_ITER_PRINT_PARENT
= 0x01,
284 TRACE_ITER_SYM_OFFSET
= 0x02,
285 TRACE_ITER_SYM_ADDR
= 0x04,
286 TRACE_ITER_VERBOSE
= 0x08,
287 TRACE_ITER_RAW
= 0x10,
288 TRACE_ITER_HEX
= 0x20,
289 TRACE_ITER_BIN
= 0x40,
290 TRACE_ITER_BLOCK
= 0x80,
291 TRACE_ITER_STACKTRACE
= 0x100,
292 TRACE_ITER_SCHED_TREE
= 0x200,
295 #endif /* _LINUX_KERNEL_TRACE_H */