Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 1 | /* |
| 2 | * trace_output.c |
| 3 | * |
| 4 | * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/mutex.h> |
| 10 | #include <linux/ftrace.h> |
| 11 | |
| 12 | #include "trace_output.h" |
| 13 | |
| 14 | /* must be a power of 2 */ |
| 15 | #define EVENT_HASHSIZE 128 |
| 16 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 17 | DECLARE_RWSEM(trace_event_sem); |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 18 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 19 | static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly; |
| 20 | |
| 21 | static int next_event_type = __TRACE_LAST_TYPE + 1; |
| 22 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 23 | enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter) |
| 24 | { |
| 25 | struct trace_seq *s = &iter->seq; |
| 26 | struct trace_entry *entry = iter->ent; |
| 27 | struct bputs_entry *field; |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 28 | |
| 29 | trace_assign_type(field, entry); |
| 30 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 31 | trace_seq_puts(s, field->str); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 32 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 33 | return trace_handle_return(s); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 36 | enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter) |
| 37 | { |
| 38 | struct trace_seq *s = &iter->seq; |
| 39 | struct trace_entry *entry = iter->ent; |
| 40 | struct bprint_entry *field; |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 41 | |
| 42 | trace_assign_type(field, entry); |
| 43 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 44 | trace_seq_bprintf(s, field->fmt, field->buf); |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 45 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 46 | return trace_handle_return(s); |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter) |
| 50 | { |
| 51 | struct trace_seq *s = &iter->seq; |
| 52 | struct trace_entry *entry = iter->ent; |
| 53 | struct print_entry *field; |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 54 | |
| 55 | trace_assign_type(field, entry); |
| 56 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 57 | trace_seq_puts(s, field->buf); |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 58 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 59 | return trace_handle_return(s); |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 60 | } |
| 61 | |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 62 | const char * |
| 63 | ftrace_print_flags_seq(struct trace_seq *p, const char *delim, |
| 64 | unsigned long flags, |
| 65 | const struct trace_print_flags *flag_array) |
| 66 | { |
| 67 | unsigned long mask; |
| 68 | const char *str; |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 69 | const char *ret = trace_seq_buffer_ptr(p); |
Andrey Vagin | e404b32 | 2012-02-19 14:16:07 +0300 | [diff] [blame] | 70 | int i, first = 1; |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 71 | |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 72 | for (i = 0; flag_array[i].name && flags; i++) { |
| 73 | |
| 74 | mask = flag_array[i].mask; |
| 75 | if ((flags & mask) != mask) |
| 76 | continue; |
| 77 | |
| 78 | str = flag_array[i].name; |
| 79 | flags &= ~mask; |
Andrey Vagin | e404b32 | 2012-02-19 14:16:07 +0300 | [diff] [blame] | 80 | if (!first && delim) |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 81 | trace_seq_puts(p, delim); |
Andrey Vagin | e404b32 | 2012-02-19 14:16:07 +0300 | [diff] [blame] | 82 | else |
| 83 | first = 0; |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 84 | trace_seq_puts(p, str); |
| 85 | } |
| 86 | |
| 87 | /* check for left over flags */ |
| 88 | if (flags) { |
Steven Rostedt | 5b34926 | 2012-02-20 20:37:32 -0500 | [diff] [blame] | 89 | if (!first && delim) |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 90 | trace_seq_puts(p, delim); |
| 91 | trace_seq_printf(p, "0x%lx", flags); |
| 92 | } |
| 93 | |
| 94 | trace_seq_putc(p, 0); |
| 95 | |
Steven Whitehouse | 56d8bd3 | 2009-06-03 14:52:03 +0100 | [diff] [blame] | 96 | return ret; |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 97 | } |
Steven Whitehouse | ec081dd | 2009-06-01 15:53:35 +0100 | [diff] [blame] | 98 | EXPORT_SYMBOL(ftrace_print_flags_seq); |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 99 | |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 100 | const char * |
| 101 | ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val, |
| 102 | const struct trace_print_flags *symbol_array) |
| 103 | { |
| 104 | int i; |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 105 | const char *ret = trace_seq_buffer_ptr(p); |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 106 | |
| 107 | for (i = 0; symbol_array[i].name; i++) { |
| 108 | |
| 109 | if (val != symbol_array[i].mask) |
| 110 | continue; |
| 111 | |
| 112 | trace_seq_puts(p, symbol_array[i].name); |
| 113 | break; |
| 114 | } |
| 115 | |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 116 | if (ret == (const char *)(trace_seq_buffer_ptr(p))) |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 117 | trace_seq_printf(p, "0x%lx", val); |
| 118 | |
| 119 | trace_seq_putc(p, 0); |
| 120 | |
Steven Whitehouse | 56d8bd3 | 2009-06-03 14:52:03 +0100 | [diff] [blame] | 121 | return ret; |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 122 | } |
Steven Whitehouse | ec081dd | 2009-06-01 15:53:35 +0100 | [diff] [blame] | 123 | EXPORT_SYMBOL(ftrace_print_symbols_seq); |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 124 | |
liubo | 2fc1b6f | 2011-04-19 09:35:28 +0800 | [diff] [blame] | 125 | #if BITS_PER_LONG == 32 |
| 126 | const char * |
| 127 | ftrace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val, |
| 128 | const struct trace_print_flags_u64 *symbol_array) |
| 129 | { |
| 130 | int i; |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 131 | const char *ret = trace_seq_buffer_ptr(p); |
liubo | 2fc1b6f | 2011-04-19 09:35:28 +0800 | [diff] [blame] | 132 | |
| 133 | for (i = 0; symbol_array[i].name; i++) { |
| 134 | |
| 135 | if (val != symbol_array[i].mask) |
| 136 | continue; |
| 137 | |
| 138 | trace_seq_puts(p, symbol_array[i].name); |
| 139 | break; |
| 140 | } |
| 141 | |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 142 | if (ret == (const char *)(trace_seq_buffer_ptr(p))) |
liubo | 2fc1b6f | 2011-04-19 09:35:28 +0800 | [diff] [blame] | 143 | trace_seq_printf(p, "0x%llx", val); |
| 144 | |
| 145 | trace_seq_putc(p, 0); |
| 146 | |
| 147 | return ret; |
| 148 | } |
| 149 | EXPORT_SYMBOL(ftrace_print_symbols_seq_u64); |
| 150 | #endif |
| 151 | |
Kei Tokunaga | 5a2e399 | 2010-04-01 20:40:58 +0900 | [diff] [blame] | 152 | const char * |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 153 | ftrace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr, |
| 154 | unsigned int bitmask_size) |
| 155 | { |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 156 | const char *ret = trace_seq_buffer_ptr(p); |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 157 | |
| 158 | trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8); |
| 159 | trace_seq_putc(p, 0); |
| 160 | |
| 161 | return ret; |
| 162 | } |
| 163 | EXPORT_SYMBOL_GPL(ftrace_print_bitmask_seq); |
| 164 | |
| 165 | const char * |
Kei Tokunaga | 5a2e399 | 2010-04-01 20:40:58 +0900 | [diff] [blame] | 166 | ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len) |
| 167 | { |
| 168 | int i; |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 169 | const char *ret = trace_seq_buffer_ptr(p); |
Kei Tokunaga | 5a2e399 | 2010-04-01 20:40:58 +0900 | [diff] [blame] | 170 | |
| 171 | for (i = 0; i < buf_len; i++) |
| 172 | trace_seq_printf(p, "%s%2.2x", i == 0 ? "" : " ", buf[i]); |
| 173 | |
| 174 | trace_seq_putc(p, 0); |
| 175 | |
| 176 | return ret; |
| 177 | } |
| 178 | EXPORT_SYMBOL(ftrace_print_hex_seq); |
| 179 | |
Li Zefan | f71130d | 2013-02-21 10:32:38 +0800 | [diff] [blame] | 180 | int ftrace_raw_output_prep(struct trace_iterator *iter, |
| 181 | struct trace_event *trace_event) |
| 182 | { |
| 183 | struct ftrace_event_call *event; |
| 184 | struct trace_seq *s = &iter->seq; |
| 185 | struct trace_seq *p = &iter->tmp_seq; |
| 186 | struct trace_entry *entry; |
Li Zefan | f71130d | 2013-02-21 10:32:38 +0800 | [diff] [blame] | 187 | |
| 188 | event = container_of(trace_event, struct ftrace_event_call, event); |
| 189 | entry = iter->ent; |
| 190 | |
| 191 | if (entry->type != event->event.type) { |
| 192 | WARN_ON_ONCE(1); |
| 193 | return TRACE_TYPE_UNHANDLED; |
| 194 | } |
| 195 | |
| 196 | trace_seq_init(p); |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 197 | trace_seq_printf(s, "%s: ", ftrace_event_name(event)); |
| 198 | |
| 199 | if (trace_seq_has_overflowed(s)) |
Li Zefan | f71130d | 2013-02-21 10:32:38 +0800 | [diff] [blame] | 200 | return TRACE_TYPE_PARTIAL_LINE; |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | EXPORT_SYMBOL(ftrace_raw_output_prep); |
| 205 | |
Steven Rostedt | 1d6bae9 | 2012-08-09 19:16:14 -0400 | [diff] [blame] | 206 | static int ftrace_output_raw(struct trace_iterator *iter, char *name, |
| 207 | char *fmt, va_list ap) |
| 208 | { |
| 209 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | 1d6bae9 | 2012-08-09 19:16:14 -0400 | [diff] [blame] | 210 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 211 | trace_seq_printf(s, "%s: ", name); |
| 212 | trace_seq_vprintf(s, fmt, ap); |
Steven Rostedt | 1d6bae9 | 2012-08-09 19:16:14 -0400 | [diff] [blame] | 213 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 214 | return trace_handle_return(s); |
Steven Rostedt | 1d6bae9 | 2012-08-09 19:16:14 -0400 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...) |
| 218 | { |
| 219 | va_list ap; |
| 220 | int ret; |
| 221 | |
| 222 | va_start(ap, fmt); |
| 223 | ret = ftrace_output_raw(iter, name, fmt, ap); |
| 224 | va_end(ap); |
| 225 | |
| 226 | return ret; |
| 227 | } |
| 228 | EXPORT_SYMBOL_GPL(ftrace_output_call); |
| 229 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 230 | #ifdef CONFIG_KRETPROBES |
| 231 | static inline const char *kretprobed(const char *name) |
| 232 | { |
| 233 | static const char tramp_name[] = "kretprobe_trampoline"; |
| 234 | int size = sizeof(tramp_name); |
| 235 | |
| 236 | if (strncmp(tramp_name, name, size) == 0) |
| 237 | return "[unknown/kretprobe'd]"; |
| 238 | return name; |
| 239 | } |
| 240 | #else |
| 241 | static inline const char *kretprobed(const char *name) |
| 242 | { |
| 243 | return name; |
| 244 | } |
| 245 | #endif /* CONFIG_KRETPROBES */ |
| 246 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 247 | static void |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 248 | seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address) |
| 249 | { |
| 250 | #ifdef CONFIG_KALLSYMS |
| 251 | char str[KSYM_SYMBOL_LEN]; |
| 252 | const char *name; |
| 253 | |
| 254 | kallsyms_lookup(address, NULL, NULL, NULL, str); |
| 255 | |
| 256 | name = kretprobed(str); |
| 257 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 258 | trace_seq_printf(s, fmt, name); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 259 | #endif |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 260 | } |
| 261 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 262 | static void |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 263 | seq_print_sym_offset(struct trace_seq *s, const char *fmt, |
| 264 | unsigned long address) |
| 265 | { |
| 266 | #ifdef CONFIG_KALLSYMS |
| 267 | char str[KSYM_SYMBOL_LEN]; |
| 268 | const char *name; |
| 269 | |
| 270 | sprint_symbol(str, address); |
| 271 | name = kretprobed(str); |
| 272 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 273 | trace_seq_printf(s, fmt, name); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 274 | #endif |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | #ifndef CONFIG_64BIT |
| 278 | # define IP_FMT "%08lx" |
| 279 | #else |
| 280 | # define IP_FMT "%016lx" |
| 281 | #endif |
| 282 | |
| 283 | int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, |
| 284 | unsigned long ip, unsigned long sym_flags) |
| 285 | { |
| 286 | struct file *file = NULL; |
| 287 | unsigned long vmstart = 0; |
| 288 | int ret = 1; |
| 289 | |
Johannes Berg | d184b31 | 2009-11-25 16:10:14 +0100 | [diff] [blame] | 290 | if (s->full) |
| 291 | return 0; |
| 292 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 293 | if (mm) { |
| 294 | const struct vm_area_struct *vma; |
| 295 | |
| 296 | down_read(&mm->mmap_sem); |
| 297 | vma = find_vma(mm, ip); |
| 298 | if (vma) { |
| 299 | file = vma->vm_file; |
| 300 | vmstart = vma->vm_start; |
| 301 | } |
| 302 | if (file) { |
| 303 | ret = trace_seq_path(s, &file->f_path); |
| 304 | if (ret) |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 305 | trace_seq_printf(s, "[+0x%lx]", |
| 306 | ip - vmstart); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 307 | } |
| 308 | up_read(&mm->mmap_sem); |
| 309 | } |
| 310 | if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file)) |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 311 | trace_seq_printf(s, " <" IP_FMT ">", ip); |
| 312 | return !trace_seq_has_overflowed(s); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | int |
| 316 | seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s, |
| 317 | unsigned long sym_flags) |
| 318 | { |
| 319 | struct mm_struct *mm = NULL; |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 320 | unsigned int i; |
| 321 | |
| 322 | if (trace_flags & TRACE_ITER_SYM_USEROBJ) { |
| 323 | struct task_struct *task; |
| 324 | /* |
| 325 | * we do the lookup on the thread group leader, |
| 326 | * since individual threads might have already quit! |
| 327 | */ |
| 328 | rcu_read_lock(); |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 329 | task = find_task_by_vpid(entry->tgid); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 330 | if (task) |
| 331 | mm = get_task_mm(task); |
| 332 | rcu_read_unlock(); |
| 333 | } |
| 334 | |
| 335 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { |
| 336 | unsigned long ip = entry->caller[i]; |
| 337 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 338 | if (ip == ULONG_MAX || trace_seq_has_overflowed(s)) |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 339 | break; |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 340 | |
| 341 | trace_seq_puts(s, " => "); |
| 342 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 343 | if (!ip) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 344 | trace_seq_puts(s, "??"); |
| 345 | trace_seq_putc(s, '\n'); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 346 | continue; |
| 347 | } |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 348 | |
| 349 | seq_print_user_ip(s, mm, ip, sym_flags); |
| 350 | trace_seq_putc(s, '\n'); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | if (mm) |
| 354 | mmput(mm); |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 355 | |
| 356 | return !trace_seq_has_overflowed(s); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | int |
| 360 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) |
| 361 | { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 362 | if (!ip) { |
| 363 | trace_seq_putc(s, '0'); |
| 364 | goto out; |
| 365 | } |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 366 | |
| 367 | if (sym_flags & TRACE_ITER_SYM_OFFSET) |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 368 | seq_print_sym_offset(s, "%s", ip); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 369 | else |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 370 | seq_print_sym_short(s, "%s", ip); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 371 | |
| 372 | if (sym_flags & TRACE_ITER_SYM_ADDR) |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 373 | trace_seq_printf(s, " <" IP_FMT ">", ip); |
| 374 | |
| 375 | out: |
| 376 | return !trace_seq_has_overflowed(s); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 377 | } |
| 378 | |
Steven Rostedt | f81c972 | 2009-09-11 14:24:13 -0400 | [diff] [blame] | 379 | /** |
| 380 | * trace_print_lat_fmt - print the irq, preempt and lockdep fields |
| 381 | * @s: trace seq struct to write to |
| 382 | * @entry: The trace entry field from the ring buffer |
| 383 | * |
| 384 | * Prints the generic fields of irqs off, in hard or softirq, preempt |
Steven Rostedt | e6e1e25 | 2011-03-09 10:41:56 -0500 | [diff] [blame] | 385 | * count. |
Steven Rostedt | f81c972 | 2009-09-11 14:24:13 -0400 | [diff] [blame] | 386 | */ |
| 387 | int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry) |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 388 | { |
David Sharp | 10da37a | 2010-12-03 16:13:26 -0800 | [diff] [blame] | 389 | char hardsoft_irq; |
| 390 | char need_resched; |
| 391 | char irqs_off; |
| 392 | int hardirq; |
| 393 | int softirq; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 394 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 395 | hardirq = entry->flags & TRACE_FLAG_HARDIRQ; |
| 396 | softirq = entry->flags & TRACE_FLAG_SOFTIRQ; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 397 | |
David Sharp | 10da37a | 2010-12-03 16:13:26 -0800 | [diff] [blame] | 398 | irqs_off = |
| 399 | (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : |
| 400 | (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : |
| 401 | '.'; |
Peter Zijlstra | e5137b5 | 2013-10-04 17:28:26 +0200 | [diff] [blame] | 402 | |
| 403 | switch (entry->flags & (TRACE_FLAG_NEED_RESCHED | |
| 404 | TRACE_FLAG_PREEMPT_RESCHED)) { |
| 405 | case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED: |
| 406 | need_resched = 'N'; |
| 407 | break; |
| 408 | case TRACE_FLAG_NEED_RESCHED: |
| 409 | need_resched = 'n'; |
| 410 | break; |
| 411 | case TRACE_FLAG_PREEMPT_RESCHED: |
| 412 | need_resched = 'p'; |
| 413 | break; |
| 414 | default: |
| 415 | need_resched = '.'; |
| 416 | break; |
| 417 | } |
| 418 | |
David Sharp | 10da37a | 2010-12-03 16:13:26 -0800 | [diff] [blame] | 419 | hardsoft_irq = |
| 420 | (hardirq && softirq) ? 'H' : |
| 421 | hardirq ? 'h' : |
| 422 | softirq ? 's' : |
| 423 | '.'; |
| 424 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 425 | trace_seq_printf(s, "%c%c%c", |
| 426 | irqs_off, need_resched, hardsoft_irq); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 427 | |
Steven Rostedt | 829b876 | 2009-09-27 07:02:07 -0400 | [diff] [blame] | 428 | if (entry->preempt_count) |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 429 | trace_seq_printf(s, "%x", entry->preempt_count); |
Steven Rostedt | 637e7e8 | 2009-09-11 13:55:35 -0400 | [diff] [blame] | 430 | else |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 431 | trace_seq_putc(s, '.'); |
Steven Rostedt | 829b876 | 2009-09-27 07:02:07 -0400 | [diff] [blame] | 432 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 433 | return !trace_seq_has_overflowed(s); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 434 | } |
| 435 | |
Steven Rostedt | f81c972 | 2009-09-11 14:24:13 -0400 | [diff] [blame] | 436 | static int |
| 437 | lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) |
| 438 | { |
| 439 | char comm[TASK_COMM_LEN]; |
| 440 | |
| 441 | trace_find_cmdline(entry->pid, comm); |
| 442 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 443 | trace_seq_printf(s, "%8.8s-%-5d %3d", |
| 444 | comm, entry->pid, cpu); |
Steven Rostedt | f81c972 | 2009-09-11 14:24:13 -0400 | [diff] [blame] | 445 | |
| 446 | return trace_print_lat_fmt(s, entry); |
| 447 | } |
| 448 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 449 | static unsigned long preempt_mark_thresh_us = 100; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 450 | |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 451 | static int |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 452 | lat_print_timestamp(struct trace_iterator *iter, u64 next_ts) |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 453 | { |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 454 | unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE; |
| 455 | unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 456 | unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 457 | unsigned long long rel_ts = next_ts - iter->ts; |
| 458 | struct trace_seq *s = &iter->seq; |
| 459 | |
| 460 | if (in_ns) { |
| 461 | abs_ts = ns2usecs(abs_ts); |
| 462 | rel_ts = ns2usecs(rel_ts); |
| 463 | } |
| 464 | |
| 465 | if (verbose && in_ns) { |
| 466 | unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC); |
| 467 | unsigned long abs_msec = (unsigned long)abs_ts; |
| 468 | unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC); |
| 469 | unsigned long rel_msec = (unsigned long)rel_ts; |
| 470 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 471 | trace_seq_printf( |
| 472 | s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ", |
| 473 | ns2usecs(iter->ts), |
| 474 | abs_msec, abs_usec, |
| 475 | rel_msec, rel_usec); |
| 476 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 477 | } else if (verbose && !in_ns) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 478 | trace_seq_printf( |
| 479 | s, "[%016llx] %lld (+%lld): ", |
| 480 | iter->ts, abs_ts, rel_ts); |
| 481 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 482 | } else if (!verbose && in_ns) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 483 | trace_seq_printf( |
| 484 | s, " %4lldus%c: ", |
| 485 | abs_ts, |
| 486 | rel_ts > preempt_mark_thresh_us ? '!' : |
| 487 | rel_ts > 1 ? '+' : ' '); |
| 488 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 489 | } else { /* !verbose && !in_ns */ |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 490 | trace_seq_printf(s, " %4lld: ", abs_ts); |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 491 | } |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 492 | |
| 493 | return !trace_seq_has_overflowed(s); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | int trace_print_context(struct trace_iterator *iter) |
| 497 | { |
| 498 | struct trace_seq *s = &iter->seq; |
| 499 | struct trace_entry *entry = iter->ent; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 500 | unsigned long long t; |
| 501 | unsigned long secs, usec_rem; |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 502 | char comm[TASK_COMM_LEN]; |
| 503 | |
| 504 | trace_find_cmdline(entry->pid, comm); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 505 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 506 | trace_seq_printf(s, "%16s-%-5d [%03d] ", |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 507 | comm, entry->pid, iter->cpu); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 508 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 509 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
| 510 | trace_print_lat_fmt(s, entry); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 511 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 512 | if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) { |
| 513 | t = ns2usecs(iter->ts); |
| 514 | usec_rem = do_div(t, USEC_PER_SEC); |
| 515 | secs = (unsigned long)t; |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 516 | trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem); |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 517 | } else |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 518 | trace_seq_printf(s, " %12llu: ", iter->ts); |
| 519 | |
| 520 | return !trace_seq_has_overflowed(s); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | int trace_print_lat_context(struct trace_iterator *iter) |
| 524 | { |
| 525 | u64 next_ts; |
Steven Rostedt | db4c75c | 2012-04-19 10:31:47 -0400 | [diff] [blame] | 526 | /* trace_find_next_entry will reset ent_size */ |
| 527 | int ent_size = iter->ent_size; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 528 | struct trace_seq *s = &iter->seq; |
| 529 | struct trace_entry *entry = iter->ent, |
| 530 | *next_entry = trace_find_next_entry(iter, NULL, |
| 531 | &next_ts); |
| 532 | unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 533 | |
Steven Rostedt | db4c75c | 2012-04-19 10:31:47 -0400 | [diff] [blame] | 534 | /* Restore the original ent_size */ |
| 535 | iter->ent_size = ent_size; |
| 536 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 537 | if (!next_entry) |
| 538 | next_ts = iter->ts; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 539 | |
| 540 | if (verbose) { |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 541 | char comm[TASK_COMM_LEN]; |
| 542 | |
| 543 | trace_find_cmdline(entry->pid, comm); |
| 544 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 545 | trace_seq_printf( |
| 546 | s, "%16s %5d %3d %d %08x %08lx ", |
| 547 | comm, entry->pid, iter->cpu, entry->flags, |
| 548 | entry->preempt_count, iter->idx); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 549 | } else { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 550 | lat_print_generic(s, entry, iter->cpu); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 551 | } |
| 552 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 553 | lat_print_timestamp(iter, next_ts); |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 554 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 555 | return !trace_seq_has_overflowed(s); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 556 | } |
| 557 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 558 | static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; |
| 559 | |
| 560 | static int task_state_char(unsigned long state) |
| 561 | { |
| 562 | int bit = state ? __ffs(state) + 1 : 0; |
| 563 | |
| 564 | return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; |
| 565 | } |
| 566 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 567 | /** |
| 568 | * ftrace_find_event - find a registered event |
| 569 | * @type: the type of event to look for |
| 570 | * |
| 571 | * Returns an event of type @type otherwise NULL |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 572 | * Called with trace_event_read_lock() held. |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 573 | */ |
| 574 | struct trace_event *ftrace_find_event(int type) |
| 575 | { |
| 576 | struct trace_event *event; |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 577 | unsigned key; |
| 578 | |
| 579 | key = type & (EVENT_HASHSIZE - 1); |
| 580 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 581 | hlist_for_each_entry(event, &event_hash[key], node) { |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 582 | if (event->type == type) |
| 583 | return event; |
| 584 | } |
| 585 | |
| 586 | return NULL; |
| 587 | } |
| 588 | |
Steven Rostedt | 060fa5c8 | 2009-04-24 12:20:52 -0400 | [diff] [blame] | 589 | static LIST_HEAD(ftrace_event_list); |
| 590 | |
| 591 | static int trace_search_list(struct list_head **list) |
| 592 | { |
| 593 | struct trace_event *e; |
| 594 | int last = __TRACE_LAST_TYPE; |
| 595 | |
| 596 | if (list_empty(&ftrace_event_list)) { |
| 597 | *list = &ftrace_event_list; |
| 598 | return last + 1; |
| 599 | } |
| 600 | |
| 601 | /* |
| 602 | * We used up all possible max events, |
| 603 | * lets see if somebody freed one. |
| 604 | */ |
| 605 | list_for_each_entry(e, &ftrace_event_list, list) { |
| 606 | if (e->type != last + 1) |
| 607 | break; |
| 608 | last++; |
| 609 | } |
| 610 | |
| 611 | /* Did we used up all 65 thousand events??? */ |
| 612 | if ((last + 1) > FTRACE_MAX_EVENT) |
| 613 | return 0; |
| 614 | |
| 615 | *list = &e->list; |
| 616 | return last + 1; |
| 617 | } |
| 618 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 619 | void trace_event_read_lock(void) |
| 620 | { |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 621 | down_read(&trace_event_sem); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | void trace_event_read_unlock(void) |
| 625 | { |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 626 | up_read(&trace_event_sem); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 627 | } |
| 628 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 629 | /** |
| 630 | * register_ftrace_event - register output for an event type |
| 631 | * @event: the event type to register |
| 632 | * |
| 633 | * Event types are stored in a hash and this hash is used to |
| 634 | * find a way to print an event. If the @event->type is set |
| 635 | * then it will use that type, otherwise it will assign a |
| 636 | * type to use. |
| 637 | * |
| 638 | * If you assign your own type, please make sure it is added |
| 639 | * to the trace_type enum in trace.h, to avoid collisions |
| 640 | * with the dynamic types. |
| 641 | * |
| 642 | * Returns the event type number or zero on error. |
| 643 | */ |
| 644 | int register_ftrace_event(struct trace_event *event) |
| 645 | { |
| 646 | unsigned key; |
| 647 | int ret = 0; |
| 648 | |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 649 | down_write(&trace_event_sem); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 650 | |
Steven Rostedt | 060fa5c8 | 2009-04-24 12:20:52 -0400 | [diff] [blame] | 651 | if (WARN_ON(!event)) |
Peter Zijlstra | 28bea27 | 2009-03-19 20:26:14 +0100 | [diff] [blame] | 652 | goto out; |
Peter Zijlstra | 28bea27 | 2009-03-19 20:26:14 +0100 | [diff] [blame] | 653 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 654 | if (WARN_ON(!event->funcs)) |
| 655 | goto out; |
| 656 | |
Steven Rostedt | 060fa5c8 | 2009-04-24 12:20:52 -0400 | [diff] [blame] | 657 | INIT_LIST_HEAD(&event->list); |
| 658 | |
| 659 | if (!event->type) { |
Jaswinder Singh Rajput | 48dd0fe | 2009-05-06 15:45:45 +0530 | [diff] [blame] | 660 | struct list_head *list = NULL; |
Steven Rostedt | 060fa5c8 | 2009-04-24 12:20:52 -0400 | [diff] [blame] | 661 | |
| 662 | if (next_event_type > FTRACE_MAX_EVENT) { |
| 663 | |
| 664 | event->type = trace_search_list(&list); |
| 665 | if (!event->type) |
| 666 | goto out; |
| 667 | |
| 668 | } else { |
| 669 | |
| 670 | event->type = next_event_type++; |
| 671 | list = &ftrace_event_list; |
| 672 | } |
| 673 | |
| 674 | if (WARN_ON(ftrace_find_event(event->type))) |
| 675 | goto out; |
| 676 | |
| 677 | list_add_tail(&event->list, list); |
| 678 | |
| 679 | } else if (event->type > __TRACE_LAST_TYPE) { |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 680 | printk(KERN_WARNING "Need to add type to trace.h\n"); |
| 681 | WARN_ON(1); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 682 | goto out; |
Steven Rostedt | 060fa5c8 | 2009-04-24 12:20:52 -0400 | [diff] [blame] | 683 | } else { |
| 684 | /* Is this event already used */ |
| 685 | if (ftrace_find_event(event->type)) |
| 686 | goto out; |
| 687 | } |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 688 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 689 | if (event->funcs->trace == NULL) |
| 690 | event->funcs->trace = trace_nop_print; |
| 691 | if (event->funcs->raw == NULL) |
| 692 | event->funcs->raw = trace_nop_print; |
| 693 | if (event->funcs->hex == NULL) |
| 694 | event->funcs->hex = trace_nop_print; |
| 695 | if (event->funcs->binary == NULL) |
| 696 | event->funcs->binary = trace_nop_print; |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 697 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 698 | key = event->type & (EVENT_HASHSIZE - 1); |
| 699 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 700 | hlist_add_head(&event->node, &event_hash[key]); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 701 | |
| 702 | ret = event->type; |
| 703 | out: |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 704 | up_write(&trace_event_sem); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 705 | |
| 706 | return ret; |
| 707 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 708 | EXPORT_SYMBOL_GPL(register_ftrace_event); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 709 | |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 710 | /* |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 711 | * Used by module code with the trace_event_sem held for write. |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 712 | */ |
| 713 | int __unregister_ftrace_event(struct trace_event *event) |
| 714 | { |
| 715 | hlist_del(&event->node); |
| 716 | list_del(&event->list); |
| 717 | return 0; |
| 718 | } |
| 719 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 720 | /** |
| 721 | * unregister_ftrace_event - remove a no longer used event |
| 722 | * @event: the event to remove |
| 723 | */ |
| 724 | int unregister_ftrace_event(struct trace_event *event) |
| 725 | { |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 726 | down_write(&trace_event_sem); |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 727 | __unregister_ftrace_event(event); |
zhangwei(Jovi) | 52f6ad6 | 2013-03-11 15:14:03 +0800 | [diff] [blame] | 728 | up_write(&trace_event_sem); |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 729 | |
| 730 | return 0; |
| 731 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 732 | EXPORT_SYMBOL_GPL(unregister_ftrace_event); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 733 | |
| 734 | /* |
| 735 | * Standard events |
| 736 | */ |
| 737 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 738 | enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags, |
| 739 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 740 | { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 741 | trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type); |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 742 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 743 | return trace_handle_return(&iter->seq); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* TRACE_FN */ |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 747 | static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags, |
| 748 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 749 | { |
| 750 | struct ftrace_entry *field; |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 751 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 752 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 753 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 754 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 755 | seq_print_ip_sym(s, field->ip, flags); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 756 | |
| 757 | if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 758 | trace_seq_puts(s, " <-"); |
| 759 | seq_print_ip_sym(s, field->parent_ip, flags); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 760 | } |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 761 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 762 | trace_seq_putc(s, '\n'); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 763 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 764 | return trace_handle_return(s); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 765 | } |
| 766 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 767 | static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags, |
| 768 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 769 | { |
| 770 | struct ftrace_entry *field; |
| 771 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 772 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 773 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 774 | trace_seq_printf(&iter->seq, "%lx %lx\n", |
| 775 | field->ip, |
| 776 | field->parent_ip); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 777 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 778 | return trace_handle_return(&iter->seq); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 779 | } |
| 780 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 781 | static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags, |
| 782 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 783 | { |
| 784 | struct ftrace_entry *field; |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 785 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 786 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 787 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 788 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 789 | SEQ_PUT_HEX_FIELD(s, field->ip); |
| 790 | SEQ_PUT_HEX_FIELD(s, field->parent_ip); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 791 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 792 | return trace_handle_return(s); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 793 | } |
| 794 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 795 | static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags, |
| 796 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 797 | { |
| 798 | struct ftrace_entry *field; |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 799 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 800 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 801 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 802 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 803 | SEQ_PUT_FIELD(s, field->ip); |
| 804 | SEQ_PUT_FIELD(s, field->parent_ip); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 805 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 806 | return trace_handle_return(s); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 807 | } |
| 808 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 809 | static struct trace_event_functions trace_fn_funcs = { |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 810 | .trace = trace_fn_trace, |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 811 | .raw = trace_fn_raw, |
| 812 | .hex = trace_fn_hex, |
| 813 | .binary = trace_fn_bin, |
| 814 | }; |
| 815 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 816 | static struct trace_event trace_fn_event = { |
| 817 | .type = TRACE_FN, |
| 818 | .funcs = &trace_fn_funcs, |
| 819 | }; |
| 820 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 821 | /* TRACE_CTX an TRACE_WAKE */ |
Arnaldo Carvalho de Melo | ae7462b | 2009-02-03 22:05:50 -0200 | [diff] [blame] | 822 | static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, |
| 823 | char *delim) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 824 | { |
| 825 | struct ctx_switch_entry *field; |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 826 | char comm[TASK_COMM_LEN]; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 827 | int S, T; |
| 828 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 829 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 830 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 831 | |
| 832 | T = task_state_char(field->next_state); |
| 833 | S = task_state_char(field->prev_state); |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 834 | trace_find_cmdline(field->next_pid, comm); |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 835 | trace_seq_printf(&iter->seq, |
| 836 | " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n", |
| 837 | field->prev_pid, |
| 838 | field->prev_prio, |
| 839 | S, delim, |
| 840 | field->next_cpu, |
| 841 | field->next_pid, |
| 842 | field->next_prio, |
| 843 | T, comm); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 844 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 845 | return trace_handle_return(&iter->seq); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 846 | } |
| 847 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 848 | static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags, |
| 849 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 850 | { |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 851 | return trace_ctxwake_print(iter, "==>"); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 852 | } |
| 853 | |
Arnaldo Carvalho de Melo | ae7462b | 2009-02-03 22:05:50 -0200 | [diff] [blame] | 854 | static enum print_line_t trace_wake_print(struct trace_iterator *iter, |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 855 | int flags, struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 856 | { |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 857 | return trace_ctxwake_print(iter, " +"); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 858 | } |
| 859 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 860 | static int trace_ctxwake_raw(struct trace_iterator *iter, char S) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 861 | { |
| 862 | struct ctx_switch_entry *field; |
| 863 | int T; |
| 864 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 865 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 866 | |
| 867 | if (!S) |
Hiroshi Shimamoto | b0f56f1 | 2009-10-01 13:33:28 +0900 | [diff] [blame] | 868 | S = task_state_char(field->prev_state); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 869 | T = task_state_char(field->next_state); |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 870 | trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n", |
| 871 | field->prev_pid, |
| 872 | field->prev_prio, |
| 873 | S, |
| 874 | field->next_cpu, |
| 875 | field->next_pid, |
| 876 | field->next_prio, |
| 877 | T); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 878 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 879 | return trace_handle_return(&iter->seq); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 880 | } |
| 881 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 882 | static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags, |
| 883 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 884 | { |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 885 | return trace_ctxwake_raw(iter, 0); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 886 | } |
| 887 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 888 | static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags, |
| 889 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 890 | { |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 891 | return trace_ctxwake_raw(iter, '+'); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 895 | static int trace_ctxwake_hex(struct trace_iterator *iter, char S) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 896 | { |
| 897 | struct ctx_switch_entry *field; |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 898 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 899 | int T; |
| 900 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 901 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 902 | |
| 903 | if (!S) |
Hiroshi Shimamoto | b0f56f1 | 2009-10-01 13:33:28 +0900 | [diff] [blame] | 904 | S = task_state_char(field->prev_state); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 905 | T = task_state_char(field->next_state); |
| 906 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 907 | SEQ_PUT_HEX_FIELD(s, field->prev_pid); |
| 908 | SEQ_PUT_HEX_FIELD(s, field->prev_prio); |
| 909 | SEQ_PUT_HEX_FIELD(s, S); |
| 910 | SEQ_PUT_HEX_FIELD(s, field->next_cpu); |
| 911 | SEQ_PUT_HEX_FIELD(s, field->next_pid); |
| 912 | SEQ_PUT_HEX_FIELD(s, field->next_prio); |
| 913 | SEQ_PUT_HEX_FIELD(s, T); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 914 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 915 | return trace_handle_return(s); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 916 | } |
| 917 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 918 | static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags, |
| 919 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 920 | { |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 921 | return trace_ctxwake_hex(iter, 0); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 922 | } |
| 923 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 924 | static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags, |
| 925 | struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 926 | { |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 927 | return trace_ctxwake_hex(iter, '+'); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 928 | } |
| 929 | |
Arnaldo Carvalho de Melo | ae7462b | 2009-02-03 22:05:50 -0200 | [diff] [blame] | 930 | static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 931 | int flags, struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 932 | { |
| 933 | struct ctx_switch_entry *field; |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 934 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 935 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 936 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 937 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 938 | SEQ_PUT_FIELD(s, field->prev_pid); |
| 939 | SEQ_PUT_FIELD(s, field->prev_prio); |
| 940 | SEQ_PUT_FIELD(s, field->prev_state); |
| 941 | SEQ_PUT_FIELD(s, field->next_cpu); |
| 942 | SEQ_PUT_FIELD(s, field->next_pid); |
| 943 | SEQ_PUT_FIELD(s, field->next_prio); |
| 944 | SEQ_PUT_FIELD(s, field->next_state); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 945 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 946 | return trace_handle_return(s); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 947 | } |
| 948 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 949 | static struct trace_event_functions trace_ctx_funcs = { |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 950 | .trace = trace_ctx_print, |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 951 | .raw = trace_ctx_raw, |
| 952 | .hex = trace_ctx_hex, |
| 953 | .binary = trace_ctxwake_bin, |
| 954 | }; |
| 955 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 956 | static struct trace_event trace_ctx_event = { |
| 957 | .type = TRACE_CTX, |
| 958 | .funcs = &trace_ctx_funcs, |
| 959 | }; |
| 960 | |
| 961 | static struct trace_event_functions trace_wake_funcs = { |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 962 | .trace = trace_wake_print, |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 963 | .raw = trace_wake_raw, |
| 964 | .hex = trace_wake_hex, |
| 965 | .binary = trace_ctxwake_bin, |
| 966 | }; |
| 967 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 968 | static struct trace_event trace_wake_event = { |
| 969 | .type = TRACE_WAKE, |
| 970 | .funcs = &trace_wake_funcs, |
| 971 | }; |
| 972 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 973 | /* TRACE_STACK */ |
| 974 | |
Arnaldo Carvalho de Melo | ae7462b | 2009-02-03 22:05:50 -0200 | [diff] [blame] | 975 | static enum print_line_t trace_stack_print(struct trace_iterator *iter, |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 976 | int flags, struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 977 | { |
| 978 | struct stack_entry *field; |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 979 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 980 | unsigned long *p; |
| 981 | unsigned long *end; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 982 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 983 | trace_assign_type(field, iter->ent); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 984 | end = (unsigned long *)((long)iter->ent + iter->ent_size); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 985 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 986 | trace_seq_puts(s, "<stack trace>\n"); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 987 | |
| 988 | for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) { |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 989 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 990 | if (trace_seq_has_overflowed(s)) |
| 991 | break; |
| 992 | |
| 993 | trace_seq_puts(s, " => "); |
| 994 | seq_print_ip_sym(s, *p, flags); |
| 995 | trace_seq_putc(s, '\n'); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 996 | } |
| 997 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 998 | return trace_handle_return(s); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 999 | } |
| 1000 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1001 | static struct trace_event_functions trace_stack_funcs = { |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1002 | .trace = trace_stack_print, |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1003 | }; |
| 1004 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1005 | static struct trace_event trace_stack_event = { |
| 1006 | .type = TRACE_STACK, |
| 1007 | .funcs = &trace_stack_funcs, |
| 1008 | }; |
| 1009 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1010 | /* TRACE_USER_STACK */ |
Arnaldo Carvalho de Melo | ae7462b | 2009-02-03 22:05:50 -0200 | [diff] [blame] | 1011 | static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1012 | int flags, struct trace_event *event) |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1013 | { |
| 1014 | struct userstack_entry *field; |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 1015 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1016 | |
Arnaldo Carvalho de Melo | 2c9b238 | 2009-02-02 20:30:12 -0200 | [diff] [blame] | 1017 | trace_assign_type(field, iter->ent); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1018 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1019 | trace_seq_puts(s, "<user stack trace>\n"); |
| 1020 | seq_print_userip_objs(field, s, flags); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1021 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1022 | return trace_handle_return(s); |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1023 | } |
| 1024 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1025 | static struct trace_event_functions trace_user_stack_funcs = { |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1026 | .trace = trace_user_stack_print, |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1027 | }; |
| 1028 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1029 | static struct trace_event trace_user_stack_event = { |
| 1030 | .type = TRACE_USER_STACK, |
| 1031 | .funcs = &trace_user_stack_funcs, |
| 1032 | }; |
| 1033 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 1034 | /* TRACE_BPUTS */ |
| 1035 | static enum print_line_t |
| 1036 | trace_bputs_print(struct trace_iterator *iter, int flags, |
| 1037 | struct trace_event *event) |
| 1038 | { |
| 1039 | struct trace_entry *entry = iter->ent; |
| 1040 | struct trace_seq *s = &iter->seq; |
| 1041 | struct bputs_entry *field; |
| 1042 | |
| 1043 | trace_assign_type(field, entry); |
| 1044 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1045 | seq_print_ip_sym(s, field->ip, flags); |
| 1046 | trace_seq_puts(s, ": "); |
| 1047 | trace_seq_puts(s, field->str); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 1048 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1049 | return trace_handle_return(s); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | static enum print_line_t |
| 1054 | trace_bputs_raw(struct trace_iterator *iter, int flags, |
| 1055 | struct trace_event *event) |
| 1056 | { |
| 1057 | struct bputs_entry *field; |
| 1058 | struct trace_seq *s = &iter->seq; |
| 1059 | |
| 1060 | trace_assign_type(field, iter->ent); |
| 1061 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1062 | trace_seq_printf(s, ": %lx : ", field->ip); |
| 1063 | trace_seq_puts(s, field->str); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 1064 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1065 | return trace_handle_return(s); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | static struct trace_event_functions trace_bputs_funcs = { |
| 1069 | .trace = trace_bputs_print, |
| 1070 | .raw = trace_bputs_raw, |
| 1071 | }; |
| 1072 | |
| 1073 | static struct trace_event trace_bputs_event = { |
| 1074 | .type = TRACE_BPUTS, |
| 1075 | .funcs = &trace_bputs_funcs, |
| 1076 | }; |
| 1077 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1078 | /* TRACE_BPRINT */ |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1079 | static enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1080 | trace_bprint_print(struct trace_iterator *iter, int flags, |
| 1081 | struct trace_event *event) |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1082 | { |
| 1083 | struct trace_entry *entry = iter->ent; |
| 1084 | struct trace_seq *s = &iter->seq; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1085 | struct bprint_entry *field; |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1086 | |
| 1087 | trace_assign_type(field, entry); |
| 1088 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1089 | seq_print_ip_sym(s, field->ip, flags); |
| 1090 | trace_seq_puts(s, ": "); |
| 1091 | trace_seq_bprintf(s, field->fmt, field->buf); |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1092 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1093 | return trace_handle_return(s); |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1096 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1097 | static enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1098 | trace_bprint_raw(struct trace_iterator *iter, int flags, |
| 1099 | struct trace_event *event) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1100 | { |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1101 | struct bprint_entry *field; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1102 | struct trace_seq *s = &iter->seq; |
| 1103 | |
| 1104 | trace_assign_type(field, iter->ent); |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1105 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1106 | trace_seq_printf(s, ": %lx : ", field->ip); |
| 1107 | trace_seq_bprintf(s, field->fmt, field->buf); |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1108 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1109 | return trace_handle_return(s); |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1110 | } |
| 1111 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1112 | static struct trace_event_functions trace_bprint_funcs = { |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1113 | .trace = trace_bprint_print, |
| 1114 | .raw = trace_bprint_raw, |
| 1115 | }; |
| 1116 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1117 | static struct trace_event trace_bprint_event = { |
| 1118 | .type = TRACE_BPRINT, |
| 1119 | .funcs = &trace_bprint_funcs, |
| 1120 | }; |
| 1121 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1122 | /* TRACE_PRINT */ |
| 1123 | static enum print_line_t trace_print_print(struct trace_iterator *iter, |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1124 | int flags, struct trace_event *event) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1125 | { |
| 1126 | struct print_entry *field; |
| 1127 | struct trace_seq *s = &iter->seq; |
| 1128 | |
| 1129 | trace_assign_type(field, iter->ent); |
| 1130 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1131 | seq_print_ip_sym(s, field->ip, flags); |
| 1132 | trace_seq_printf(s, ": %s", field->buf); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1133 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1134 | return trace_handle_return(s); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1135 | } |
| 1136 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1137 | static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags, |
| 1138 | struct trace_event *event) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1139 | { |
| 1140 | struct print_entry *field; |
| 1141 | |
| 1142 | trace_assign_type(field, iter->ent); |
| 1143 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1144 | trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1145 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame^] | 1146 | return trace_handle_return(&iter->seq); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1147 | } |
| 1148 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1149 | static struct trace_event_functions trace_print_funcs = { |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1150 | .trace = trace_print_print, |
| 1151 | .raw = trace_print_raw, |
Lai Jiangshan | 1427cdf | 2009-03-06 17:21:47 +0100 | [diff] [blame] | 1152 | }; |
| 1153 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1154 | static struct trace_event trace_print_event = { |
| 1155 | .type = TRACE_PRINT, |
| 1156 | .funcs = &trace_print_funcs, |
| 1157 | }; |
| 1158 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1159 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1160 | static struct trace_event *events[] __initdata = { |
| 1161 | &trace_fn_event, |
| 1162 | &trace_ctx_event, |
| 1163 | &trace_wake_event, |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1164 | &trace_stack_event, |
| 1165 | &trace_user_stack_event, |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 1166 | &trace_bputs_event, |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1167 | &trace_bprint_event, |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1168 | &trace_print_event, |
| 1169 | NULL |
| 1170 | }; |
| 1171 | |
| 1172 | __init static int init_events(void) |
| 1173 | { |
| 1174 | struct trace_event *event; |
| 1175 | int i, ret; |
| 1176 | |
| 1177 | for (i = 0; events[i]; i++) { |
| 1178 | event = events[i]; |
| 1179 | |
| 1180 | ret = register_ftrace_event(event); |
| 1181 | if (!ret) { |
| 1182 | printk(KERN_WARNING "event %d failed to register\n", |
| 1183 | event->type); |
| 1184 | WARN_ON_ONCE(1); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | return 0; |
| 1189 | } |
Steven Rostedt | 7374e82 | 2012-05-31 21:40:05 -0400 | [diff] [blame] | 1190 | early_initcall(init_events); |