]> git.karo-electronics.de Git - mv-sheeva.git/blob - kernel/trace/trace.h
ftrace: user run time file reading
[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         spinlock_t              lock;
59         cycle_t                 time_offset;
60
61         /* these fields get copied into max-trace: */
62         unsigned                trace_head_idx;
63         unsigned                trace_tail_idx;
64         void                    *trace_head; /* producer */
65         void                    *trace_tail; /* consumer */
66         unsigned long           trace_idx;
67         unsigned long           saved_latency;
68         unsigned long           critical_start;
69         unsigned long           critical_end;
70         unsigned long           critical_sequence;
71         unsigned long           nice;
72         unsigned long           policy;
73         unsigned long           rt_priority;
74         cycle_t                 preempt_timestamp;
75         pid_t                   pid;
76         uid_t                   uid;
77         char                    comm[TASK_COMM_LEN];
78 };
79
80 struct trace_iterator;
81
82 /*
83  * The trace array - an array of per-CPU trace arrays. This is the
84  * highest level data structure that individual tracers deal with.
85  * They have on/off state as well:
86  */
87 struct trace_array {
88         unsigned long           entries;
89         long                    ctrl;
90         int                     cpu;
91         cycle_t                 time_start;
92         struct task_struct      *waiter;
93         struct trace_array_cpu  *data[NR_CPUS];
94 };
95
96 /*
97  * A specific tracer, represented by methods that operate on a trace array:
98  */
99 struct tracer {
100         const char              *name;
101         void                    (*init)(struct trace_array *tr);
102         void                    (*reset)(struct trace_array *tr);
103         void                    (*open)(struct trace_iterator *iter);
104         void                    (*close)(struct trace_iterator *iter);
105         void                    (*start)(struct trace_iterator *iter);
106         void                    (*stop)(struct trace_iterator *iter);
107         void                    (*ctrl_update)(struct trace_array *tr);
108 #ifdef CONFIG_FTRACE_STARTUP_TEST
109         int                     (*selftest)(struct tracer *trace,
110                                             struct trace_array *tr);
111 #endif
112         struct tracer           *next;
113         int                     print_max;
114 };
115
116 struct trace_seq {
117         unsigned char           buffer[PAGE_SIZE];
118         unsigned int            len;
119 };
120
121 /*
122  * Trace iterator - used by printout routines who present trace
123  * results to users and which routines might sleep, etc:
124  */
125 struct trace_iterator {
126         struct trace_seq        seq;
127         struct trace_array      *tr;
128         struct tracer           *trace;
129
130         struct trace_entry      *ent;
131         int                     cpu;
132
133         struct trace_entry      *prev_ent;
134         int                     prev_cpu;
135
136         unsigned long           iter_flags;
137         loff_t                  pos;
138         unsigned long           next_idx[NR_CPUS];
139         struct list_head        *next_page[NR_CPUS];
140         unsigned                next_page_idx[NR_CPUS];
141         long                    idx;
142 };
143
144 void notrace tracing_reset(struct trace_array_cpu *data);
145 int tracing_open_generic(struct inode *inode, struct file *filp);
146 struct dentry *tracing_init_dentry(void);
147 void ftrace(struct trace_array *tr,
148                             struct trace_array_cpu *data,
149                             unsigned long ip,
150                             unsigned long parent_ip,
151                             unsigned long flags);
152 void tracing_sched_switch_trace(struct trace_array *tr,
153                                 struct trace_array_cpu *data,
154                                 struct task_struct *prev,
155                                 struct task_struct *next,
156                                 unsigned long flags);
157 void tracing_record_cmdline(struct task_struct *tsk);
158
159 void tracing_start_function_trace(void);
160 void tracing_stop_function_trace(void);
161 int register_tracer(struct tracer *type);
162 void unregister_tracer(struct tracer *type);
163
164 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
165
166 extern unsigned long tracing_max_latency;
167 extern unsigned long tracing_thresh;
168
169 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
170 void update_max_tr_single(struct trace_array *tr,
171                           struct task_struct *tsk, int cpu);
172
173 static inline notrace cycle_t now(int cpu)
174 {
175         return cpu_clock(cpu);
176 }
177
178 #ifdef CONFIG_SCHED_TRACER
179 extern void notrace
180 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
181 #else
182 static inline void
183 wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
184 {
185 }
186 #endif
187
188 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
189 typedef void
190 (*tracer_switch_func_t)(void *private,
191                         struct task_struct *prev,
192                         struct task_struct *next);
193
194 struct tracer_switch_ops {
195         tracer_switch_func_t            func;
196         void                            *private;
197         struct tracer_switch_ops        *next;
198 };
199
200 extern int register_tracer_switch(struct tracer_switch_ops *ops);
201 extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
202
203 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
204
205 #ifdef CONFIG_DYNAMIC_FTRACE
206 extern unsigned long ftrace_update_tot_cnt;
207 #endif
208
209 #ifdef CONFIG_FTRACE_STARTUP_TEST
210 #ifdef CONFIG_FTRACE
211 extern int trace_selftest_startup_function(struct tracer *trace,
212                                            struct trace_array *tr);
213 #endif
214 #ifdef CONFIG_IRQSOFF_TRACER
215 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
216                                           struct trace_array *tr);
217 #endif
218 #ifdef CONFIG_PREEMPT_TRACER
219 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
220                                              struct trace_array *tr);
221 #endif
222 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
223 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
224                                                  struct trace_array *tr);
225 #endif
226 #ifdef CONFIG_SCHED_TRACER
227 extern int trace_selftest_startup_wakeup(struct tracer *trace,
228                                          struct trace_array *tr);
229 #endif
230 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
231 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
232                                                struct trace_array *tr);
233 #endif
234 #endif /* CONFIG_FTRACE_STARTUP_TEST */
235
236 extern void *head_page(struct trace_array_cpu *data);
237
238 #endif /* _LINUX_KERNEL_TRACE_H */