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 * The trace entry - the most basic unit of tracing. This is what
30 * is printed in the end as a single line in the trace output, such as:
32 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
43 struct ftrace_entry fn;
44 struct ctx_switch_entry ctx;
48 #define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
51 * The CPU trace array - it consists of thousands of trace entries
52 * plus some other descriptor data: (for example which task started
55 struct trace_array_cpu {
56 struct list_head trace_pages;
59 struct lock_class_key lock_key;
62 /* these fields get copied into max-trace: */
63 unsigned trace_head_idx;
64 unsigned trace_tail_idx;
65 void *trace_head; /* producer */
66 void *trace_tail; /* consumer */
67 unsigned long trace_idx;
68 unsigned long saved_latency;
69 unsigned long critical_start;
70 unsigned long critical_end;
71 unsigned long critical_sequence;
74 unsigned long rt_priority;
75 cycle_t preempt_timestamp;
78 char comm[TASK_COMM_LEN];
81 struct trace_iterator;
84 * The trace array - an array of per-CPU trace arrays. This is the
85 * highest level data structure that individual tracers deal with.
86 * They have on/off state as well:
89 unsigned long entries;
93 struct task_struct *waiter;
94 struct trace_array_cpu *data[NR_CPUS];
98 * A specific tracer, represented by methods that operate on a trace array:
102 void (*init)(struct trace_array *tr);
103 void (*reset)(struct trace_array *tr);
104 void (*open)(struct trace_iterator *iter);
105 void (*close)(struct trace_iterator *iter);
106 void (*start)(struct trace_iterator *iter);
107 void (*stop)(struct trace_iterator *iter);
108 void (*ctrl_update)(struct trace_array *tr);
109 #ifdef CONFIG_FTRACE_STARTUP_TEST
110 int (*selftest)(struct tracer *trace,
111 struct trace_array *tr);
118 unsigned char buffer[PAGE_SIZE];
123 * Trace iterator - used by printout routines who present trace
124 * results to users and which routines might sleep, etc:
126 struct trace_iterator {
127 struct trace_seq seq;
128 struct trace_array *tr;
129 struct tracer *trace;
131 struct trace_entry *ent;
134 struct trace_entry *prev_ent;
137 unsigned long iter_flags;
139 unsigned long next_idx[NR_CPUS];
140 struct list_head *next_page[NR_CPUS];
141 unsigned next_page_idx[NR_CPUS];
145 void notrace tracing_reset(struct trace_array_cpu *data);
146 int tracing_open_generic(struct inode *inode, struct file *filp);
147 struct dentry *tracing_init_dentry(void);
148 void ftrace(struct trace_array *tr,
149 struct trace_array_cpu *data,
151 unsigned long parent_ip,
152 unsigned long flags);
153 void tracing_sched_switch_trace(struct trace_array *tr,
154 struct trace_array_cpu *data,
155 struct task_struct *prev,
156 struct task_struct *next,
157 unsigned long flags);
158 void tracing_record_cmdline(struct task_struct *tsk);
160 void tracing_start_function_trace(void);
161 void tracing_stop_function_trace(void);
162 int register_tracer(struct tracer *type);
163 void unregister_tracer(struct tracer *type);
165 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
167 extern unsigned long tracing_max_latency;
168 extern unsigned long tracing_thresh;
170 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
171 void update_max_tr_single(struct trace_array *tr,
172 struct task_struct *tsk, int cpu);
174 extern notrace cycle_t ftrace_now(int cpu);
176 #ifdef CONFIG_SCHED_TRACER
178 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
181 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
186 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
188 (*tracer_switch_func_t)(void *private,
189 struct task_struct *prev,
190 struct task_struct *next);
192 struct tracer_switch_ops {
193 tracer_switch_func_t func;
195 struct tracer_switch_ops *next;
198 extern int register_tracer_switch(struct tracer_switch_ops *ops);
199 extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
201 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
203 #ifdef CONFIG_DYNAMIC_FTRACE
204 extern unsigned long ftrace_update_tot_cnt;
207 #ifdef CONFIG_FTRACE_STARTUP_TEST
209 extern int trace_selftest_startup_function(struct tracer *trace,
210 struct trace_array *tr);
212 #ifdef CONFIG_IRQSOFF_TRACER
213 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
214 struct trace_array *tr);
216 #ifdef CONFIG_PREEMPT_TRACER
217 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
218 struct trace_array *tr);
220 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
221 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
222 struct trace_array *tr);
224 #ifdef CONFIG_SCHED_TRACER
225 extern int trace_selftest_startup_wakeup(struct tracer *trace,
226 struct trace_array *tr);
228 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
229 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
230 struct trace_array *tr);
232 #endif /* CONFIG_FTRACE_STARTUP_TEST */
234 extern void *head_page(struct trace_array_cpu *data);
236 #endif /* _LINUX_KERNEL_TRACE_H */