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
42 struct ftrace_entry fn;
43 struct ctx_switch_entry ctx;
47 #define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
50 * The CPU trace array - it consists of thousands of trace entries
51 * plus some other descriptor data: (for example which task started
54 struct trace_array_cpu {
55 struct list_head trace_pages;
58 struct lock_class_key lock_key;
60 /* these fields get copied into max-trace: */
61 unsigned trace_head_idx;
62 unsigned trace_tail_idx;
63 void *trace_head; /* producer */
64 void *trace_tail; /* consumer */
65 unsigned long trace_idx;
66 unsigned long saved_latency;
67 unsigned long critical_start;
68 unsigned long critical_end;
69 unsigned long critical_sequence;
72 unsigned long rt_priority;
73 cycle_t preempt_timestamp;
76 char comm[TASK_COMM_LEN];
79 struct trace_iterator;
82 * The trace array - an array of per-CPU trace arrays. This is the
83 * highest level data structure that individual tracers deal with.
84 * They have on/off state as well:
87 unsigned long entries;
91 struct task_struct *waiter;
92 struct trace_array_cpu *data[NR_CPUS];
96 * A specific tracer, represented by methods that operate on a trace array:
100 void (*init)(struct trace_array *tr);
101 void (*reset)(struct trace_array *tr);
102 void (*open)(struct trace_iterator *iter);
103 void (*close)(struct trace_iterator *iter);
104 void (*start)(struct trace_iterator *iter);
105 void (*stop)(struct trace_iterator *iter);
106 void (*ctrl_update)(struct trace_array *tr);
107 #ifdef CONFIG_FTRACE_STARTUP_TEST
108 int (*selftest)(struct tracer *trace,
109 struct trace_array *tr);
116 unsigned char buffer[PAGE_SIZE];
121 * Trace iterator - used by printout routines who present trace
122 * results to users and which routines might sleep, etc:
124 struct trace_iterator {
125 struct trace_seq seq;
126 struct trace_array *tr;
127 struct tracer *trace;
129 struct trace_entry *ent;
132 struct trace_entry *prev_ent;
135 unsigned long iter_flags;
137 unsigned long next_idx[NR_CPUS];
138 struct list_head *next_page[NR_CPUS];
139 unsigned next_page_idx[NR_CPUS];
143 void notrace tracing_reset(struct trace_array_cpu *data);
144 int tracing_open_generic(struct inode *inode, struct file *filp);
145 struct dentry *tracing_init_dentry(void);
146 void ftrace(struct trace_array *tr,
147 struct trace_array_cpu *data,
149 unsigned long parent_ip,
150 unsigned long flags);
151 void tracing_sched_switch_trace(struct trace_array *tr,
152 struct trace_array_cpu *data,
153 struct task_struct *prev,
154 struct task_struct *next,
155 unsigned long flags);
156 void tracing_record_cmdline(struct task_struct *tsk);
158 void tracing_start_function_trace(void);
159 void tracing_stop_function_trace(void);
160 int register_tracer(struct tracer *type);
161 void unregister_tracer(struct tracer *type);
163 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
165 extern unsigned long tracing_max_latency;
166 extern unsigned long tracing_thresh;
168 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
169 void update_max_tr_single(struct trace_array *tr,
170 struct task_struct *tsk, int cpu);
172 extern notrace cycle_t ftrace_now(int cpu);
174 #ifdef CONFIG_SCHED_TRACER
176 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
179 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
184 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
186 (*tracer_switch_func_t)(void *private,
187 struct task_struct *prev,
188 struct task_struct *next);
190 struct tracer_switch_ops {
191 tracer_switch_func_t func;
193 struct tracer_switch_ops *next;
196 extern int register_tracer_switch(struct tracer_switch_ops *ops);
197 extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
199 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
201 #ifdef CONFIG_DYNAMIC_FTRACE
202 extern unsigned long ftrace_update_tot_cnt;
205 #ifdef CONFIG_FTRACE_STARTUP_TEST
207 extern int trace_selftest_startup_function(struct tracer *trace,
208 struct trace_array *tr);
210 #ifdef CONFIG_IRQSOFF_TRACER
211 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
212 struct trace_array *tr);
214 #ifdef CONFIG_PREEMPT_TRACER
215 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
216 struct trace_array *tr);
218 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
219 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
220 struct trace_array *tr);
222 #ifdef CONFIG_SCHED_TRACER
223 extern int trace_selftest_startup_wakeup(struct tracer *trace,
224 struct trace_array *tr);
226 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
227 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
228 struct trace_array *tr);
230 #endif /* CONFIG_FTRACE_STARTUP_TEST */
232 extern void *head_page(struct trace_array_cpu *data);
234 #endif /* _LINUX_KERNEL_TRACE_H */