]> git.karo-electronics.de Git - mv-sheeva.git/blob - kernel/trace/trace.h
ftrace: change buffers to producer consumer
[mv-sheeva.git] / kernel / trace / trace.h
1 #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  */
12 struct 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  */
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;
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  */
34 struct 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  */
55 struct trace_array_cpu {
56         struct list_head        trace_pages;
57         atomic_t                disabled;
58         cycle_t                 time_offset;
59
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;
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
79 struct 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  */
86 struct trace_array {
87         unsigned long           entries;
88         long                    ctrl;
89         int                     cpu;
90         cycle_t                 time_start;
91         struct trace_array_cpu  *data[NR_CPUS];
92 };
93
94 /*
95  * A specific tracer, represented by methods that operate on a trace array:
96  */
97 struct tracer {
98         const char              *name;
99         void                    (*init)(struct trace_array *tr);
100         void                    (*reset)(struct trace_array *tr);
101         void                    (*open)(struct trace_iterator *iter);
102         void                    (*close)(struct trace_iterator *iter);
103         void                    (*start)(struct trace_iterator *iter);
104         void                    (*stop)(struct trace_iterator *iter);
105         void                    (*ctrl_update)(struct trace_array *tr);
106 #ifdef CONFIG_FTRACE_STARTUP_TEST
107         int                     (*selftest)(struct tracer *trace,
108                                             struct trace_array *tr);
109 #endif
110         struct tracer           *next;
111         int                     print_max;
112 };
113
114 /*
115  * Trace iterator - used by printout routines who present trace
116  * results to users and which routines might sleep, etc:
117  */
118 struct trace_iterator {
119         struct trace_array      *tr;
120         struct tracer           *trace;
121
122         struct trace_entry      *ent;
123         int                     cpu;
124
125         struct trace_entry      *prev_ent;
126         int                     prev_cpu;
127
128         unsigned long           iter_flags;
129         loff_t                  pos;
130         unsigned long           next_idx[NR_CPUS];
131         struct list_head        *next_page[NR_CPUS];
132         unsigned                next_page_idx[NR_CPUS];
133         long                    idx;
134 };
135
136 void notrace tracing_reset(struct trace_array_cpu *data);
137 int tracing_open_generic(struct inode *inode, struct file *filp);
138 struct dentry *tracing_init_dentry(void);
139 void ftrace(struct trace_array *tr,
140                             struct trace_array_cpu *data,
141                             unsigned long ip,
142                             unsigned long parent_ip,
143                             unsigned long flags);
144 void tracing_sched_switch_trace(struct trace_array *tr,
145                                 struct trace_array_cpu *data,
146                                 struct task_struct *prev,
147                                 struct task_struct *next,
148                                 unsigned long flags);
149 void tracing_record_cmdline(struct task_struct *tsk);
150
151 void tracing_start_function_trace(void);
152 void tracing_stop_function_trace(void);
153 int register_tracer(struct tracer *type);
154 void unregister_tracer(struct tracer *type);
155
156 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
157
158 extern unsigned long tracing_max_latency;
159 extern unsigned long tracing_thresh;
160
161 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
162 void update_max_tr_single(struct trace_array *tr,
163                           struct task_struct *tsk, int cpu);
164
165 static inline notrace cycle_t now(int cpu)
166 {
167         return cpu_clock(cpu);
168 }
169
170 #ifdef CONFIG_SCHED_TRACER
171 extern void notrace
172 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
173 #else
174 static inline void
175 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
176 {
177 }
178 #endif
179
180 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
181 typedef void
182 (*tracer_switch_func_t)(void *private,
183                         struct task_struct *prev,
184                         struct task_struct *next);
185
186 struct tracer_switch_ops {
187         tracer_switch_func_t            func;
188         void                            *private;
189         struct tracer_switch_ops        *next;
190 };
191
192 extern int register_tracer_switch(struct tracer_switch_ops *ops);
193 extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
194
195 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
196
197 #ifdef CONFIG_DYNAMIC_FTRACE
198 extern unsigned long ftrace_update_tot_cnt;
199 #endif
200
201 #ifdef CONFIG_FTRACE_STARTUP_TEST
202 #ifdef CONFIG_FTRACE
203 extern int trace_selftest_startup_function(struct tracer *trace,
204                                            struct trace_array *tr);
205 #endif
206 #ifdef CONFIG_IRQSOFF_TRACER
207 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
208                                           struct trace_array *tr);
209 #endif
210 #ifdef CONFIG_PREEMPT_TRACER
211 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
212                                              struct trace_array *tr);
213 #endif
214 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
215 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
216                                                  struct trace_array *tr);
217 #endif
218 #ifdef CONFIG_SCHED_TRACER
219 extern int trace_selftest_startup_wakeup(struct tracer *trace,
220                                          struct trace_array *tr);
221 #endif
222 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
223 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
224                                                struct trace_array *tr);
225 #endif
226 #endif /* CONFIG_FTRACE_STARTUP_TEST */
227
228 extern void *head_page(struct trace_array_cpu *data);
229
230 #endif /* _LINUX_KERNEL_TRACE_H */