blob: 5df8ff2b84a76921c5f2c50431ec1488eb5e2ded [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;
41 unsigned long idx;
42 union {
43 struct ftrace_entry fn;
44 struct ctx_switch_entry ctx;
45 };
46};
47
48#define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
49
50/*
51 * The CPU trace array - it consists of thousands of trace entries
52 * plus some other descriptor data: (for example which task started
53 * the trace, etc.)
54 */
55struct trace_array_cpu {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +020056 void *trace_current;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +020057 struct list_head trace_pages;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020058 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +020059 cycle_t time_offset;
60
Ingo Molnarc7aafc52008-05-12 21:20:45 +020061 /* these fields get copied into max-trace: */
62 unsigned trace_current_idx;
63 unsigned long trace_idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020064 unsigned long saved_latency;
65 unsigned long critical_start;
66 unsigned long critical_end;
67 unsigned long critical_sequence;
68 unsigned long nice;
69 unsigned long policy;
70 unsigned long rt_priority;
71 cycle_t preempt_timestamp;
72 pid_t pid;
73 uid_t uid;
74 char comm[TASK_COMM_LEN];
75};
76
77struct trace_iterator;
78
79/*
80 * The trace array - an array of per-CPU trace arrays. This is the
81 * highest level data structure that individual tracers deal with.
82 * They have on/off state as well:
83 */
84struct trace_array {
85 unsigned long entries;
86 long ctrl;
87 int cpu;
88 cycle_t time_start;
89 struct trace_array_cpu *data[NR_CPUS];
90};
91
92/*
93 * A specific tracer, represented by methods that operate on a trace array:
94 */
95struct tracer {
96 const char *name;
97 void (*init)(struct trace_array *tr);
98 void (*reset)(struct trace_array *tr);
99 void (*open)(struct trace_iterator *iter);
100 void (*close)(struct trace_iterator *iter);
101 void (*start)(struct trace_iterator *iter);
102 void (*stop)(struct trace_iterator *iter);
103 void (*ctrl_update)(struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200104#ifdef CONFIG_FTRACE_STARTUP_TEST
105 int (*selftest)(struct tracer *trace,
106 struct trace_array *tr);
107#endif
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200108 struct tracer *next;
109 int print_max;
110};
111
112/*
113 * Trace iterator - used by printout routines who present trace
114 * results to users and which routines might sleep, etc:
115 */
116struct trace_iterator {
117 struct trace_array *tr;
118 struct tracer *trace;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200119
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200120 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200121 int cpu;
122
123 struct trace_entry *prev_ent;
124 int prev_cpu;
125
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200126 unsigned long iter_flags;
127 loff_t pos;
128 unsigned long next_idx[NR_CPUS];
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200129 struct list_head *next_page[NR_CPUS];
130 unsigned next_page_idx[NR_CPUS];
131 long idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200132};
133
134void notrace tracing_reset(struct trace_array_cpu *data);
135int tracing_open_generic(struct inode *inode, struct file *filp);
136struct dentry *tracing_init_dentry(void);
137void ftrace(struct trace_array *tr,
138 struct trace_array_cpu *data,
139 unsigned long ip,
140 unsigned long parent_ip,
141 unsigned long flags);
142void tracing_sched_switch_trace(struct trace_array *tr,
143 struct trace_array_cpu *data,
144 struct task_struct *prev,
145 struct task_struct *next,
146 unsigned long flags);
147void tracing_record_cmdline(struct task_struct *tsk);
148
149void tracing_start_function_trace(void);
150void tracing_stop_function_trace(void);
151int register_tracer(struct tracer *type);
152void unregister_tracer(struct tracer *type);
153
154extern unsigned long nsecs_to_usecs(unsigned long nsecs);
155
156extern unsigned long tracing_max_latency;
157extern unsigned long tracing_thresh;
158
159void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
160void update_max_tr_single(struct trace_array *tr,
161 struct task_struct *tsk, int cpu);
162
163static inline notrace cycle_t now(int cpu)
164{
165 return cpu_clock(cpu);
166}
167
168#ifdef CONFIG_SCHED_TRACER
169extern void notrace
170wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
171#else
172static inline void
173wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
174{
175}
176#endif
177
178#ifdef CONFIG_CONTEXT_SWITCH_TRACER
179typedef void
180(*tracer_switch_func_t)(void *private,
181 struct task_struct *prev,
182 struct task_struct *next);
183
184struct tracer_switch_ops {
185 tracer_switch_func_t func;
186 void *private;
187 struct tracer_switch_ops *next;
188};
189
190extern int register_tracer_switch(struct tracer_switch_ops *ops);
191extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
192
193#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
194
195#ifdef CONFIG_DYNAMIC_FTRACE
196extern unsigned long ftrace_update_tot_cnt;
197#endif
198
Steven Rostedt60a11772008-05-12 21:20:44 +0200199#ifdef CONFIG_FTRACE_STARTUP_TEST
200#ifdef CONFIG_FTRACE
201extern int trace_selftest_startup_function(struct tracer *trace,
202 struct trace_array *tr);
203#endif
204#ifdef CONFIG_IRQSOFF_TRACER
205extern int trace_selftest_startup_irqsoff(struct tracer *trace,
206 struct trace_array *tr);
207#endif
208#ifdef CONFIG_PREEMPT_TRACER
209extern int trace_selftest_startup_preemptoff(struct tracer *trace,
210 struct trace_array *tr);
211#endif
212#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
213extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
214 struct trace_array *tr);
215#endif
216#ifdef CONFIG_SCHED_TRACER
217extern int trace_selftest_startup_wakeup(struct tracer *trace,
218 struct trace_array *tr);
219#endif
220#ifdef CONFIG_CONTEXT_SWITCH_TRACER
221extern int trace_selftest_startup_sched_switch(struct tracer *trace,
222 struct trace_array *tr);
223#endif
224#endif /* CONFIG_FTRACE_STARTUP_TEST */
225
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200226extern void *head_page(struct trace_array_cpu *data);
227
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200228#endif /* _LINUX_KERNEL_TRACE_H */