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