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;
29 * Special (free-form) trace entry:
31 struct special_entry {
38 * The trace entry - the most basic unit of tracing. This is what
39 * is printed in the end as a single line in the trace output, such as:
41 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
51 struct ftrace_entry fn;
52 struct ctx_switch_entry ctx;
53 struct special_entry special;
57 #define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
60 * The CPU trace array - it consists of thousands of trace entries
61 * plus some other descriptor data: (for example which task started
64 struct trace_array_cpu {
65 struct list_head trace_pages;
68 struct lock_class_key lock_key;
70 /* these fields get copied into max-trace: */
71 unsigned trace_head_idx;
72 unsigned trace_tail_idx;
73 void *trace_head; /* producer */
74 void *trace_tail; /* consumer */
75 unsigned long trace_idx;
76 unsigned long saved_latency;
77 unsigned long critical_start;
78 unsigned long critical_end;
79 unsigned long critical_sequence;
82 unsigned long rt_priority;
83 cycle_t preempt_timestamp;
86 char comm[TASK_COMM_LEN];
89 struct trace_iterator;
92 * The trace array - an array of per-CPU trace arrays. This is the
93 * highest level data structure that individual tracers deal with.
94 * They have on/off state as well:
97 unsigned long entries;
101 struct task_struct *waiter;
102 struct trace_array_cpu *data[NR_CPUS];
106 * A specific tracer, represented by methods that operate on a trace array:
110 void (*init)(struct trace_array *tr);
111 void (*reset)(struct trace_array *tr);
112 void (*open)(struct trace_iterator *iter);
113 void (*close)(struct trace_iterator *iter);
114 void (*start)(struct trace_iterator *iter);
115 void (*stop)(struct trace_iterator *iter);
116 void (*ctrl_update)(struct trace_array *tr);
117 #ifdef CONFIG_FTRACE_STARTUP_TEST
118 int (*selftest)(struct tracer *trace,
119 struct trace_array *tr);
126 unsigned char buffer[PAGE_SIZE];
131 * Trace iterator - used by printout routines who present trace
132 * results to users and which routines might sleep, etc:
134 struct trace_iterator {
135 struct trace_seq seq;
136 struct trace_array *tr;
137 struct tracer *trace;
139 struct trace_entry *ent;
142 struct trace_entry *prev_ent;
145 unsigned long iter_flags;
147 unsigned long next_idx[NR_CPUS];
148 struct list_head *next_page[NR_CPUS];
149 unsigned next_page_idx[NR_CPUS];
153 void notrace tracing_reset(struct trace_array_cpu *data);
154 int tracing_open_generic(struct inode *inode, struct file *filp);
155 struct dentry *tracing_init_dentry(void);
156 void ftrace(struct trace_array *tr,
157 struct trace_array_cpu *data,
159 unsigned long parent_ip,
160 unsigned long flags);
161 void tracing_sched_switch_trace(struct trace_array *tr,
162 struct trace_array_cpu *data,
163 struct task_struct *prev,
164 struct task_struct *next,
165 unsigned long flags);
166 void tracing_record_cmdline(struct task_struct *tsk);
167 void trace_special(struct trace_array *tr,
168 struct trace_array_cpu *data,
173 void tracing_start_function_trace(void);
174 void tracing_stop_function_trace(void);
175 int register_tracer(struct tracer *type);
176 void unregister_tracer(struct tracer *type);
178 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
180 extern unsigned long tracing_max_latency;
181 extern unsigned long tracing_thresh;
183 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
184 void update_max_tr_single(struct trace_array *tr,
185 struct task_struct *tsk, int cpu);
187 extern notrace cycle_t ftrace_now(int cpu);
189 #ifdef CONFIG_SCHED_TRACER
191 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
194 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
199 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
201 (*tracer_switch_func_t)(void *private,
202 struct task_struct *prev,
203 struct task_struct *next);
205 struct tracer_switch_ops {
206 tracer_switch_func_t func;
208 struct tracer_switch_ops *next;
211 extern int register_tracer_switch(struct tracer_switch_ops *ops);
212 extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
214 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
216 #ifdef CONFIG_DYNAMIC_FTRACE
217 extern unsigned long ftrace_update_tot_cnt;
220 #ifdef CONFIG_FTRACE_STARTUP_TEST
222 extern int trace_selftest_startup_function(struct tracer *trace,
223 struct trace_array *tr);
225 #ifdef CONFIG_IRQSOFF_TRACER
226 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
227 struct trace_array *tr);
229 #ifdef CONFIG_PREEMPT_TRACER
230 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
231 struct trace_array *tr);
233 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
234 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
235 struct trace_array *tr);
237 #ifdef CONFIG_SCHED_TRACER
238 extern int trace_selftest_startup_wakeup(struct tracer *trace,
239 struct trace_array *tr);
241 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
242 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
243 struct trace_array *tr);
245 #endif /* CONFIG_FTRACE_STARTUP_TEST */
247 extern void *head_page(struct trace_array_cpu *data);
249 #endif /* _LINUX_KERNEL_TRACE_H */