blob: 27fa2d06f499648c03441ba5a34cbc1fb94bf124 [file] [log] [blame]
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001#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>
8
9/*
10 * Function trace entry - function address and parent function addres:
11 */
12struct ftrace_entry {
13 unsigned long ip;
14 unsigned long parent_ip;
15};
16
17/*
18 * Context switch trace entry - which task (and prio) we switched from/to:
19 */
20struct 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};
27
28/*
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:
31 *
32 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
33 */
34struct trace_entry {
35 char type;
36 char cpu;
37 char flags;
38 char preempt_count;
39 int pid;
40 cycle_t t;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020041 union {
42 struct ftrace_entry fn;
43 struct ctx_switch_entry ctx;
44 };
45};
46
47#define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
48
49/*
50 * The CPU trace array - it consists of thousands of trace entries
51 * plus some other descriptor data: (for example which task started
52 * the trace, etc.)
53 */
54struct trace_array_cpu {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +020055 struct list_head trace_pages;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020056 atomic_t disabled;
Steven Rostedtb3806b42008-05-12 21:20:46 +020057 spinlock_t lock;
Ingo Molnard4c5a2f2008-05-12 21:20:46 +020058 struct lock_class_key lock_key;
Ingo Molnar4e3c3332008-05-12 21:20:45 +020059
Ingo Molnarc7aafc52008-05-12 21:20:45 +020060 /* these fields get copied into max-trace: */
Steven Rostedt93a588f2008-05-12 21:20:45 +020061 unsigned trace_head_idx;
62 unsigned trace_tail_idx;
63 void *trace_head; /* producer */
64 void *trace_tail; /* consumer */
Ingo Molnarc7aafc52008-05-12 21:20:45 +020065 unsigned long trace_idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020066 unsigned long saved_latency;
67 unsigned long critical_start;
68 unsigned long critical_end;
69 unsigned long critical_sequence;
70 unsigned long nice;
71 unsigned long policy;
72 unsigned long rt_priority;
73 cycle_t preempt_timestamp;
74 pid_t pid;
75 uid_t uid;
76 char comm[TASK_COMM_LEN];
77};
78
79struct trace_iterator;
80
81/*
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:
85 */
86struct trace_array {
87 unsigned long entries;
88 long ctrl;
89 int cpu;
90 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +020091 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020092 struct trace_array_cpu *data[NR_CPUS];
93};
94
95/*
96 * A specific tracer, represented by methods that operate on a trace array:
97 */
98struct tracer {
99 const char *name;
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);
Steven Rostedt60a11772008-05-12 21:20:44 +0200107#ifdef CONFIG_FTRACE_STARTUP_TEST
108 int (*selftest)(struct tracer *trace,
109 struct trace_array *tr);
110#endif
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200111 struct tracer *next;
112 int print_max;
113};
114
Steven Rostedt214023c2008-05-12 21:20:46 +0200115struct trace_seq {
116 unsigned char buffer[PAGE_SIZE];
117 unsigned int len;
118};
119
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200120/*
121 * Trace iterator - used by printout routines who present trace
122 * results to users and which routines might sleep, etc:
123 */
124struct trace_iterator {
Steven Rostedt214023c2008-05-12 21:20:46 +0200125 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200126 struct trace_array *tr;
127 struct tracer *trace;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200128
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200129 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200130 int cpu;
131
132 struct trace_entry *prev_ent;
133 int prev_cpu;
134
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200135 unsigned long iter_flags;
136 loff_t pos;
137 unsigned long next_idx[NR_CPUS];
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200138 struct list_head *next_page[NR_CPUS];
139 unsigned next_page_idx[NR_CPUS];
140 long idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200141};
142
143void notrace tracing_reset(struct trace_array_cpu *data);
144int tracing_open_generic(struct inode *inode, struct file *filp);
145struct dentry *tracing_init_dentry(void);
146void ftrace(struct trace_array *tr,
147 struct trace_array_cpu *data,
148 unsigned long ip,
149 unsigned long parent_ip,
150 unsigned long flags);
151void 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);
156void tracing_record_cmdline(struct task_struct *tsk);
157
158void tracing_start_function_trace(void);
159void tracing_stop_function_trace(void);
160int register_tracer(struct tracer *type);
161void unregister_tracer(struct tracer *type);
162
163extern unsigned long nsecs_to_usecs(unsigned long nsecs);
164
165extern unsigned long tracing_max_latency;
166extern unsigned long tracing_thresh;
167
168void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
169void update_max_tr_single(struct trace_array *tr,
170 struct task_struct *tsk, int cpu);
171
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200172extern notrace cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200173
174#ifdef CONFIG_SCHED_TRACER
175extern void notrace
176wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
177#else
178static inline void
179wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
180{
181}
182#endif
183
184#ifdef CONFIG_CONTEXT_SWITCH_TRACER
185typedef void
186(*tracer_switch_func_t)(void *private,
187 struct task_struct *prev,
188 struct task_struct *next);
189
190struct tracer_switch_ops {
191 tracer_switch_func_t func;
192 void *private;
193 struct tracer_switch_ops *next;
194};
195
196extern int register_tracer_switch(struct tracer_switch_ops *ops);
197extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
198
199#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
200
201#ifdef CONFIG_DYNAMIC_FTRACE
202extern unsigned long ftrace_update_tot_cnt;
203#endif
204
Steven Rostedt60a11772008-05-12 21:20:44 +0200205#ifdef CONFIG_FTRACE_STARTUP_TEST
206#ifdef CONFIG_FTRACE
207extern int trace_selftest_startup_function(struct tracer *trace,
208 struct trace_array *tr);
209#endif
210#ifdef CONFIG_IRQSOFF_TRACER
211extern int trace_selftest_startup_irqsoff(struct tracer *trace,
212 struct trace_array *tr);
213#endif
214#ifdef CONFIG_PREEMPT_TRACER
215extern int trace_selftest_startup_preemptoff(struct tracer *trace,
216 struct trace_array *tr);
217#endif
218#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
219extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
220 struct trace_array *tr);
221#endif
222#ifdef CONFIG_SCHED_TRACER
223extern int trace_selftest_startup_wakeup(struct tracer *trace,
224 struct trace_array *tr);
225#endif
226#ifdef CONFIG_CONTEXT_SWITCH_TRACER
227extern int trace_selftest_startup_sched_switch(struct tracer *trace,
228 struct trace_array *tr);
229#endif
230#endif /* CONFIG_FTRACE_STARTUP_TEST */
231
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200232extern void *head_page(struct trace_array_cpu *data);
233
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200234#endif /* _LINUX_KERNEL_TRACE_H */