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