Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 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 | /* |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 29 | * Special (free-form) trace entry: |
| 30 | */ |
| 31 | struct special_entry { |
| 32 | unsigned long arg1; |
| 33 | unsigned long arg2; |
| 34 | unsigned long arg3; |
| 35 | }; |
| 36 | |
| 37 | /* |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 38 | * Stack-trace entry: |
| 39 | */ |
| 40 | |
| 41 | #define FTRACE_STACK_ENTRIES 5 |
| 42 | |
| 43 | struct stack_entry { |
| 44 | unsigned long caller[FTRACE_STACK_ENTRIES]; |
| 45 | }; |
| 46 | |
| 47 | /* |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 48 | * The trace entry - the most basic unit of tracing. This is what |
| 49 | * is printed in the end as a single line in the trace output, such as: |
| 50 | * |
| 51 | * bash-15816 [01] 235.197585: idle_cpu <- irq_enter |
| 52 | */ |
| 53 | struct trace_entry { |
| 54 | char type; |
| 55 | char cpu; |
| 56 | char flags; |
| 57 | char preempt_count; |
| 58 | int pid; |
| 59 | cycle_t t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 60 | union { |
| 61 | struct ftrace_entry fn; |
| 62 | struct ctx_switch_entry ctx; |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 63 | struct special_entry special; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 64 | struct stack_entry stack; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 65 | }; |
| 66 | }; |
| 67 | |
| 68 | #define TRACE_ENTRY_SIZE sizeof(struct trace_entry) |
| 69 | |
| 70 | /* |
| 71 | * The CPU trace array - it consists of thousands of trace entries |
| 72 | * plus some other descriptor data: (for example which task started |
| 73 | * the trace, etc.) |
| 74 | */ |
| 75 | struct trace_array_cpu { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 76 | struct list_head trace_pages; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 77 | atomic_t disabled; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 78 | spinlock_t lock; |
Ingo Molnar | d4c5a2f | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 79 | struct lock_class_key lock_key; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 80 | |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 81 | /* these fields get copied into max-trace: */ |
Steven Rostedt | 93a588f | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 82 | unsigned trace_head_idx; |
| 83 | unsigned trace_tail_idx; |
| 84 | void *trace_head; /* producer */ |
| 85 | void *trace_tail; /* consumer */ |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 86 | unsigned long trace_idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 87 | unsigned long saved_latency; |
| 88 | unsigned long critical_start; |
| 89 | unsigned long critical_end; |
| 90 | unsigned long critical_sequence; |
| 91 | unsigned long nice; |
| 92 | unsigned long policy; |
| 93 | unsigned long rt_priority; |
| 94 | cycle_t preempt_timestamp; |
| 95 | pid_t pid; |
| 96 | uid_t uid; |
| 97 | char comm[TASK_COMM_LEN]; |
| 98 | }; |
| 99 | |
| 100 | struct trace_iterator; |
| 101 | |
| 102 | /* |
| 103 | * The trace array - an array of per-CPU trace arrays. This is the |
| 104 | * highest level data structure that individual tracers deal with. |
| 105 | * They have on/off state as well: |
| 106 | */ |
| 107 | struct trace_array { |
| 108 | unsigned long entries; |
| 109 | long ctrl; |
| 110 | int cpu; |
| 111 | cycle_t time_start; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 112 | struct task_struct *waiter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 113 | struct trace_array_cpu *data[NR_CPUS]; |
| 114 | }; |
| 115 | |
| 116 | /* |
| 117 | * A specific tracer, represented by methods that operate on a trace array: |
| 118 | */ |
| 119 | struct tracer { |
| 120 | const char *name; |
| 121 | void (*init)(struct trace_array *tr); |
| 122 | void (*reset)(struct trace_array *tr); |
| 123 | void (*open)(struct trace_iterator *iter); |
| 124 | void (*close)(struct trace_iterator *iter); |
| 125 | void (*start)(struct trace_iterator *iter); |
| 126 | void (*stop)(struct trace_iterator *iter); |
| 127 | void (*ctrl_update)(struct trace_array *tr); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 128 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 129 | int (*selftest)(struct tracer *trace, |
| 130 | struct trace_array *tr); |
| 131 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 132 | struct tracer *next; |
| 133 | int print_max; |
| 134 | }; |
| 135 | |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 136 | struct trace_seq { |
| 137 | unsigned char buffer[PAGE_SIZE]; |
| 138 | unsigned int len; |
| 139 | }; |
| 140 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 141 | /* |
| 142 | * Trace iterator - used by printout routines who present trace |
| 143 | * results to users and which routines might sleep, etc: |
| 144 | */ |
| 145 | struct trace_iterator { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 146 | struct trace_seq seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 147 | struct trace_array *tr; |
| 148 | struct tracer *trace; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 149 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 150 | struct trace_entry *ent; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 151 | int cpu; |
| 152 | |
| 153 | struct trace_entry *prev_ent; |
| 154 | int prev_cpu; |
| 155 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 156 | unsigned long iter_flags; |
| 157 | loff_t pos; |
| 158 | unsigned long next_idx[NR_CPUS]; |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 159 | struct list_head *next_page[NR_CPUS]; |
| 160 | unsigned next_page_idx[NR_CPUS]; |
| 161 | long idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 162 | }; |
| 163 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 164 | void tracing_reset(struct trace_array_cpu *data); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 165 | int tracing_open_generic(struct inode *inode, struct file *filp); |
| 166 | struct dentry *tracing_init_dentry(void); |
| 167 | void ftrace(struct trace_array *tr, |
| 168 | struct trace_array_cpu *data, |
| 169 | unsigned long ip, |
| 170 | unsigned long parent_ip, |
| 171 | unsigned long flags); |
| 172 | void tracing_sched_switch_trace(struct trace_array *tr, |
| 173 | struct trace_array_cpu *data, |
| 174 | struct task_struct *prev, |
| 175 | struct task_struct *next, |
| 176 | unsigned long flags); |
| 177 | void tracing_record_cmdline(struct task_struct *tsk); |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 178 | |
| 179 | void tracing_sched_wakeup_trace(struct trace_array *tr, |
| 180 | struct trace_array_cpu *data, |
| 181 | struct task_struct *wakee, |
| 182 | struct task_struct *cur, |
| 183 | unsigned long flags); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 184 | void trace_special(struct trace_array *tr, |
| 185 | struct trace_array_cpu *data, |
| 186 | unsigned long arg1, |
| 187 | unsigned long arg2, |
| 188 | unsigned long arg3); |
Steven Rostedt | 6fb44b7 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 189 | void trace_function(struct trace_array *tr, |
| 190 | struct trace_array_cpu *data, |
| 191 | unsigned long ip, |
| 192 | unsigned long parent_ip, |
| 193 | unsigned long flags); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 194 | |
| 195 | void tracing_start_function_trace(void); |
| 196 | void tracing_stop_function_trace(void); |
| 197 | int register_tracer(struct tracer *type); |
| 198 | void unregister_tracer(struct tracer *type); |
| 199 | |
| 200 | extern unsigned long nsecs_to_usecs(unsigned long nsecs); |
| 201 | |
| 202 | extern unsigned long tracing_max_latency; |
| 203 | extern unsigned long tracing_thresh; |
| 204 | |
| 205 | void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu); |
| 206 | void update_max_tr_single(struct trace_array *tr, |
| 207 | struct task_struct *tsk, int cpu); |
| 208 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 209 | extern cycle_t ftrace_now(int cpu); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 210 | |
| 211 | #ifdef CONFIG_SCHED_TRACER |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 212 | extern void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 213 | wakeup_sched_switch(struct task_struct *prev, struct task_struct *next); |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 214 | extern void |
| 215 | wakeup_sched_wakeup(struct task_struct *wakee, struct task_struct *curr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 216 | #else |
| 217 | static inline void |
| 218 | wakeup_sched_switch(struct task_struct *prev, struct task_struct *next) |
| 219 | { |
| 220 | } |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 221 | static inline void |
| 222 | wakeup_sched_wakeup(struct task_struct *wakee, struct task_struct *curr) |
| 223 | { |
| 224 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 225 | #endif |
| 226 | |
| 227 | #ifdef CONFIG_CONTEXT_SWITCH_TRACER |
| 228 | typedef void |
| 229 | (*tracer_switch_func_t)(void *private, |
| 230 | struct task_struct *prev, |
| 231 | struct task_struct *next); |
| 232 | |
| 233 | struct tracer_switch_ops { |
| 234 | tracer_switch_func_t func; |
| 235 | void *private; |
| 236 | struct tracer_switch_ops *next; |
| 237 | }; |
| 238 | |
| 239 | extern int register_tracer_switch(struct tracer_switch_ops *ops); |
| 240 | extern int unregister_tracer_switch(struct tracer_switch_ops *ops); |
| 241 | |
| 242 | #endif /* CONFIG_CONTEXT_SWITCH_TRACER */ |
| 243 | |
| 244 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 245 | extern unsigned long ftrace_update_tot_cnt; |
| 246 | #endif |
| 247 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 248 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 249 | #ifdef CONFIG_FTRACE |
| 250 | extern int trace_selftest_startup_function(struct tracer *trace, |
| 251 | struct trace_array *tr); |
| 252 | #endif |
| 253 | #ifdef CONFIG_IRQSOFF_TRACER |
| 254 | extern int trace_selftest_startup_irqsoff(struct tracer *trace, |
| 255 | struct trace_array *tr); |
| 256 | #endif |
| 257 | #ifdef CONFIG_PREEMPT_TRACER |
| 258 | extern int trace_selftest_startup_preemptoff(struct tracer *trace, |
| 259 | struct trace_array *tr); |
| 260 | #endif |
| 261 | #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER) |
| 262 | extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace, |
| 263 | struct trace_array *tr); |
| 264 | #endif |
| 265 | #ifdef CONFIG_SCHED_TRACER |
| 266 | extern int trace_selftest_startup_wakeup(struct tracer *trace, |
| 267 | struct trace_array *tr); |
| 268 | #endif |
| 269 | #ifdef CONFIG_CONTEXT_SWITCH_TRACER |
| 270 | extern int trace_selftest_startup_sched_switch(struct tracer *trace, |
| 271 | struct trace_array *tr); |
| 272 | #endif |
| 273 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
| 274 | |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 275 | extern void *head_page(struct trace_array_cpu *data); |
| 276 | |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 277 | extern unsigned long trace_flags; |
| 278 | |
| 279 | enum trace_iterator_flags { |
| 280 | TRACE_ITER_PRINT_PARENT = 0x01, |
| 281 | TRACE_ITER_SYM_OFFSET = 0x02, |
| 282 | TRACE_ITER_SYM_ADDR = 0x04, |
| 283 | TRACE_ITER_VERBOSE = 0x08, |
| 284 | TRACE_ITER_RAW = 0x10, |
| 285 | TRACE_ITER_HEX = 0x20, |
| 286 | TRACE_ITER_BIN = 0x40, |
| 287 | TRACE_ITER_BLOCK = 0x80, |
| 288 | TRACE_ITER_STACKTRACE = 0x100, |
Ingo Molnar | 4ac3ba4 | 2008-05-12 21:20:52 +0200 | [diff] [blame^] | 289 | TRACE_ITER_SCHED_TREE = 0x200, |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 290 | }; |
| 291 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 292 | #endif /* _LINUX_KERNEL_TRACE_H */ |