trace: make the trace_event callbacks return enum print_line_t
[linux-2.6] / kernel / trace / trace_output.c
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
17 static DEFINE_MUTEX(trace_event_mutex);
18 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
19
20 static int next_event_type = __TRACE_LAST_TYPE + 1;
21
22 /**
23  * trace_seq_printf - sequence printing of trace information
24  * @s: trace sequence descriptor
25  * @fmt: printf format string
26  *
27  * The tracer may use either sequence operations or its own
28  * copy to user routines. To simplify formating of a trace
29  * trace_seq_printf is used to store strings into a special
30  * buffer (@s). Then the output may be either used by
31  * the sequencer or pulled into another buffer.
32  */
33 int
34 trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
35 {
36         int len = (PAGE_SIZE - 1) - s->len;
37         va_list ap;
38         int ret;
39
40         if (!len)
41                 return 0;
42
43         va_start(ap, fmt);
44         ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
45         va_end(ap);
46
47         /* If we can't write it all, don't bother writing anything */
48         if (ret >= len)
49                 return 0;
50
51         s->len += ret;
52
53         return len;
54 }
55
56 /**
57  * trace_seq_puts - trace sequence printing of simple string
58  * @s: trace sequence descriptor
59  * @str: simple string to record
60  *
61  * The tracer may use either the sequence operations or its own
62  * copy to user routines. This function records a simple string
63  * into a special buffer (@s) for later retrieval by a sequencer
64  * or other mechanism.
65  */
66 int trace_seq_puts(struct trace_seq *s, const char *str)
67 {
68         int len = strlen(str);
69
70         if (len > ((PAGE_SIZE - 1) - s->len))
71                 return 0;
72
73         memcpy(s->buffer + s->len, str, len);
74         s->len += len;
75
76         return len;
77 }
78
79 int trace_seq_putc(struct trace_seq *s, unsigned char c)
80 {
81         if (s->len >= (PAGE_SIZE - 1))
82                 return 0;
83
84         s->buffer[s->len++] = c;
85
86         return 1;
87 }
88
89 int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
90 {
91         if (len > ((PAGE_SIZE - 1) - s->len))
92                 return 0;
93
94         memcpy(s->buffer + s->len, mem, len);
95         s->len += len;
96
97         return len;
98 }
99
100 int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
101 {
102         unsigned char hex[HEX_CHARS];
103         unsigned char *data = mem;
104         int i, j;
105
106 #ifdef __BIG_ENDIAN
107         for (i = 0, j = 0; i < len; i++) {
108 #else
109         for (i = len-1, j = 0; i >= 0; i--) {
110 #endif
111                 hex[j++] = hex_asc_hi(data[i]);
112                 hex[j++] = hex_asc_lo(data[i]);
113         }
114         hex[j++] = ' ';
115
116         return trace_seq_putmem(s, hex, j);
117 }
118
119 int trace_seq_path(struct trace_seq *s, struct path *path)
120 {
121         unsigned char *p;
122
123         if (s->len >= (PAGE_SIZE - 1))
124                 return 0;
125         p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
126         if (!IS_ERR(p)) {
127                 p = mangle_path(s->buffer + s->len, p, "\n");
128                 if (p) {
129                         s->len = p - s->buffer;
130                         return 1;
131                 }
132         } else {
133                 s->buffer[s->len++] = '?';
134                 return 1;
135         }
136
137         return 0;
138 }
139
140 #ifdef CONFIG_KRETPROBES
141 static inline const char *kretprobed(const char *name)
142 {
143         static const char tramp_name[] = "kretprobe_trampoline";
144         int size = sizeof(tramp_name);
145
146         if (strncmp(tramp_name, name, size) == 0)
147                 return "[unknown/kretprobe'd]";
148         return name;
149 }
150 #else
151 static inline const char *kretprobed(const char *name)
152 {
153         return name;
154 }
155 #endif /* CONFIG_KRETPROBES */
156
157 static int
158 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
159 {
160 #ifdef CONFIG_KALLSYMS
161         char str[KSYM_SYMBOL_LEN];
162         const char *name;
163
164         kallsyms_lookup(address, NULL, NULL, NULL, str);
165
166         name = kretprobed(str);
167
168         return trace_seq_printf(s, fmt, name);
169 #endif
170         return 1;
171 }
172
173 static int
174 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
175                      unsigned long address)
176 {
177 #ifdef CONFIG_KALLSYMS
178         char str[KSYM_SYMBOL_LEN];
179         const char *name;
180
181         sprint_symbol(str, address);
182         name = kretprobed(str);
183
184         return trace_seq_printf(s, fmt, name);
185 #endif
186         return 1;
187 }
188
189 #ifndef CONFIG_64BIT
190 # define IP_FMT "%08lx"
191 #else
192 # define IP_FMT "%016lx"
193 #endif
194
195 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
196                       unsigned long ip, unsigned long sym_flags)
197 {
198         struct file *file = NULL;
199         unsigned long vmstart = 0;
200         int ret = 1;
201
202         if (mm) {
203                 const struct vm_area_struct *vma;
204
205                 down_read(&mm->mmap_sem);
206                 vma = find_vma(mm, ip);
207                 if (vma) {
208                         file = vma->vm_file;
209                         vmstart = vma->vm_start;
210                 }
211                 if (file) {
212                         ret = trace_seq_path(s, &file->f_path);
213                         if (ret)
214                                 ret = trace_seq_printf(s, "[+0x%lx]",
215                                                        ip - vmstart);
216                 }
217                 up_read(&mm->mmap_sem);
218         }
219         if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
220                 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
221         return ret;
222 }
223
224 int
225 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
226                       unsigned long sym_flags)
227 {
228         struct mm_struct *mm = NULL;
229         int ret = 1;
230         unsigned int i;
231
232         if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
233                 struct task_struct *task;
234                 /*
235                  * we do the lookup on the thread group leader,
236                  * since individual threads might have already quit!
237                  */
238                 rcu_read_lock();
239                 task = find_task_by_vpid(entry->ent.tgid);
240                 if (task)
241                         mm = get_task_mm(task);
242                 rcu_read_unlock();
243         }
244
245         for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
246                 unsigned long ip = entry->caller[i];
247
248                 if (ip == ULONG_MAX || !ret)
249                         break;
250                 if (i && ret)
251                         ret = trace_seq_puts(s, " <- ");
252                 if (!ip) {
253                         if (ret)
254                                 ret = trace_seq_puts(s, "??");
255                         continue;
256                 }
257                 if (!ret)
258                         break;
259                 if (ret)
260                         ret = seq_print_user_ip(s, mm, ip, sym_flags);
261         }
262
263         if (mm)
264                 mmput(mm);
265         return ret;
266 }
267
268 int
269 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
270 {
271         int ret;
272
273         if (!ip)
274                 return trace_seq_printf(s, "0");
275
276         if (sym_flags & TRACE_ITER_SYM_OFFSET)
277                 ret = seq_print_sym_offset(s, "%s", ip);
278         else
279                 ret = seq_print_sym_short(s, "%s", ip);
280
281         if (!ret)
282                 return 0;
283
284         if (sym_flags & TRACE_ITER_SYM_ADDR)
285                 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
286         return ret;
287 }
288
289 static int
290 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
291 {
292         int hardirq, softirq;
293         char *comm;
294
295         comm = trace_find_cmdline(entry->pid);
296         hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
297         softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
298
299         if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
300                               comm, entry->pid, cpu,
301                               (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
302                                 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
303                                   'X' : '.',
304                               (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
305                                 'N' : '.',
306                               (hardirq && softirq) ? 'H' :
307                                 hardirq ? 'h' : softirq ? 's' : '.'))
308                 return 0;
309
310         if (entry->preempt_count)
311                 return trace_seq_printf(s, "%x", entry->preempt_count);
312         return trace_seq_puts(s, ".");
313 }
314
315 static unsigned long preempt_mark_thresh = 100;
316
317 static int
318 lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
319                     unsigned long rel_usecs)
320 {
321         return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
322                                 rel_usecs > preempt_mark_thresh ? '!' :
323                                   rel_usecs > 1 ? '+' : ' ');
324 }
325
326 int trace_print_context(struct trace_iterator *iter)
327 {
328         struct trace_seq *s = &iter->seq;
329         struct trace_entry *entry = iter->ent;
330         char *comm = trace_find_cmdline(entry->pid);
331         unsigned long long t = ns2usecs(iter->ts);
332         unsigned long usec_rem = do_div(t, USEC_PER_SEC);
333         unsigned long secs = (unsigned long)t;
334
335         return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
336                                 comm, entry->pid, entry->cpu, secs, usec_rem);
337 }
338
339 int trace_print_lat_context(struct trace_iterator *iter)
340 {
341         u64 next_ts;
342         int ret;
343         struct trace_seq *s = &iter->seq;
344         struct trace_entry *entry = iter->ent,
345                            *next_entry = trace_find_next_entry(iter, NULL,
346                                                                &next_ts);
347         unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
348         unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
349         unsigned long rel_usecs;
350
351         if (!next_entry)
352                 next_ts = iter->ts;
353         rel_usecs = ns2usecs(next_ts - iter->ts);
354
355         if (verbose) {
356                 char *comm = trace_find_cmdline(entry->pid);
357                 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
358                                        " %ld.%03ldms (+%ld.%03ldms): ", comm,
359                                        entry->pid, entry->cpu, entry->flags,
360                                        entry->preempt_count, iter->idx,
361                                        ns2usecs(iter->ts),
362                                        abs_usecs / USEC_PER_MSEC,
363                                        abs_usecs % USEC_PER_MSEC,
364                                        rel_usecs / USEC_PER_MSEC,
365                                        rel_usecs % USEC_PER_MSEC);
366         } else {
367                 ret = lat_print_generic(s, entry, entry->cpu);
368                 if (ret)
369                         ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
370         }
371
372         return ret;
373 }
374
375 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
376
377 static int task_state_char(unsigned long state)
378 {
379         int bit = state ? __ffs(state) + 1 : 0;
380
381         return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
382 }
383
384 /**
385  * ftrace_find_event - find a registered event
386  * @type: the type of event to look for
387  *
388  * Returns an event of type @type otherwise NULL
389  */
390 struct trace_event *ftrace_find_event(int type)
391 {
392         struct trace_event *event;
393         struct hlist_node *n;
394         unsigned key;
395
396         key = type & (EVENT_HASHSIZE - 1);
397
398         hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
399                 if (event->type == type)
400                         return event;
401         }
402
403         return NULL;
404 }
405
406 /**
407  * register_ftrace_event - register output for an event type
408  * @event: the event type to register
409  *
410  * Event types are stored in a hash and this hash is used to
411  * find a way to print an event. If the @event->type is set
412  * then it will use that type, otherwise it will assign a
413  * type to use.
414  *
415  * If you assign your own type, please make sure it is added
416  * to the trace_type enum in trace.h, to avoid collisions
417  * with the dynamic types.
418  *
419  * Returns the event type number or zero on error.
420  */
421 int register_ftrace_event(struct trace_event *event)
422 {
423         unsigned key;
424         int ret = 0;
425
426         mutex_lock(&trace_event_mutex);
427
428         if (!event->type)
429                 event->type = next_event_type++;
430         else if (event->type > __TRACE_LAST_TYPE) {
431                 printk(KERN_WARNING "Need to add type to trace.h\n");
432                 WARN_ON(1);
433         }
434
435         if (ftrace_find_event(event->type))
436                 goto out;
437
438         key = event->type & (EVENT_HASHSIZE - 1);
439
440         hlist_add_head_rcu(&event->node, &event_hash[key]);
441
442         ret = event->type;
443  out:
444         mutex_unlock(&trace_event_mutex);
445
446         return ret;
447 }
448
449 /**
450  * unregister_ftrace_event - remove a no longer used event
451  * @event: the event to remove
452  */
453 int unregister_ftrace_event(struct trace_event *event)
454 {
455         mutex_lock(&trace_event_mutex);
456         hlist_del(&event->node);
457         mutex_unlock(&trace_event_mutex);
458
459         return 0;
460 }
461
462 /*
463  * Standard events
464  */
465
466 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
467 {
468         return TRACE_TYPE_HANDLED;
469 }
470
471 /* TRACE_FN */
472 static enum print_line_t trace_fn_latency(struct trace_iterator *iter,
473                                           int flags)
474 {
475         struct ftrace_entry *field;
476         struct trace_seq *s = &iter->seq;
477
478         trace_assign_type(field, iter->ent);
479
480         if (!seq_print_ip_sym(s, field->ip, flags))
481                 goto partial;
482         if (!trace_seq_puts(s, " ("))
483                 goto partial;
484         if (!seq_print_ip_sym(s, field->parent_ip, flags))
485                 goto partial;
486         if (!trace_seq_puts(s, ")\n"))
487                 goto partial;
488
489         return TRACE_TYPE_HANDLED;
490
491  partial:
492         return TRACE_TYPE_PARTIAL_LINE;
493 }
494
495 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
496 {
497         struct ftrace_entry *field;
498         struct trace_seq *s = &iter->seq;
499
500         trace_assign_type(field, iter->ent);
501
502         if (!seq_print_ip_sym(s, field->ip, flags))
503                 goto partial;
504
505         if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
506                 if (!trace_seq_printf(s, " <-"))
507                         goto partial;
508                 if (!seq_print_ip_sym(s,
509                                       field->parent_ip,
510                                       flags))
511                         goto partial;
512         }
513         if (!trace_seq_printf(s, "\n"))
514                 goto partial;
515
516         return TRACE_TYPE_HANDLED;
517
518  partial:
519         return TRACE_TYPE_PARTIAL_LINE;
520 }
521
522 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
523 {
524         struct ftrace_entry *field;
525
526         trace_assign_type(field, iter->ent);
527
528         if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
529                               field->ip,
530                               field->parent_ip))
531                 return TRACE_TYPE_PARTIAL_LINE;
532
533         return TRACE_TYPE_HANDLED;
534 }
535
536 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
537 {
538         struct ftrace_entry *field;
539         struct trace_seq *s = &iter->seq;
540
541         trace_assign_type(field, iter->ent);
542
543         SEQ_PUT_HEX_FIELD_RET(s, field->ip);
544         SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
545
546         return TRACE_TYPE_HANDLED;
547 }
548
549 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
550 {
551         struct ftrace_entry *field;
552         struct trace_seq *s = &iter->seq;
553
554         trace_assign_type(field, iter->ent);
555
556         SEQ_PUT_FIELD_RET(s, field->ip);
557         SEQ_PUT_FIELD_RET(s, field->parent_ip);
558
559         return TRACE_TYPE_HANDLED;
560 }
561
562 static struct trace_event trace_fn_event = {
563         .type           = TRACE_FN,
564         .trace          = trace_fn_trace,
565         .latency_trace  = trace_fn_latency,
566         .raw            = trace_fn_raw,
567         .hex            = trace_fn_hex,
568         .binary         = trace_fn_bin,
569 };
570
571 /* TRACE_CTX an TRACE_WAKE */
572 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
573                                              char *delim)
574 {
575         struct ctx_switch_entry *field;
576         char *comm;
577         int S, T;
578
579         trace_assign_type(field, iter->ent);
580
581         T = task_state_char(field->next_state);
582         S = task_state_char(field->prev_state);
583         comm = trace_find_cmdline(field->next_pid);
584         if (!trace_seq_printf(&iter->seq,
585                               " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
586                               field->prev_pid,
587                               field->prev_prio,
588                               S, delim,
589                               field->next_cpu,
590                               field->next_pid,
591                               field->next_prio,
592                               T, comm))
593                 return TRACE_TYPE_PARTIAL_LINE;
594
595         return TRACE_TYPE_HANDLED;
596 }
597
598 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
599 {
600         return trace_ctxwake_print(iter, "==>");
601 }
602
603 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
604                                           int flags)
605 {
606         return trace_ctxwake_print(iter, "  +");
607 }
608
609 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
610 {
611         struct ctx_switch_entry *field;
612         int T;
613
614         trace_assign_type(field, iter->ent);
615
616         if (!S)
617                 task_state_char(field->prev_state);
618         T = task_state_char(field->next_state);
619         if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
620                               field->prev_pid,
621                               field->prev_prio,
622                               S,
623                               field->next_cpu,
624                               field->next_pid,
625                               field->next_prio,
626                               T))
627                 return TRACE_TYPE_PARTIAL_LINE;
628
629         return TRACE_TYPE_HANDLED;
630 }
631
632 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
633 {
634         return trace_ctxwake_raw(iter, 0);
635 }
636
637 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
638 {
639         return trace_ctxwake_raw(iter, '+');
640 }
641
642
643 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
644 {
645         struct ctx_switch_entry *field;
646         struct trace_seq *s = &iter->seq;
647         int T;
648
649         trace_assign_type(field, iter->ent);
650
651         if (!S)
652                 task_state_char(field->prev_state);
653         T = task_state_char(field->next_state);
654
655         SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
656         SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
657         SEQ_PUT_HEX_FIELD_RET(s, S);
658         SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
659         SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
660         SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
661         SEQ_PUT_HEX_FIELD_RET(s, T);
662
663         return TRACE_TYPE_HANDLED;
664 }
665
666 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
667 {
668         return trace_ctxwake_hex(iter, 0);
669 }
670
671 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
672 {
673         return trace_ctxwake_hex(iter, '+');
674 }
675
676 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
677                                            int flags)
678 {
679         struct ctx_switch_entry *field;
680         struct trace_seq *s = &iter->seq;
681
682         trace_assign_type(field, iter->ent);
683
684         SEQ_PUT_FIELD_RET(s, field->prev_pid);
685         SEQ_PUT_FIELD_RET(s, field->prev_prio);
686         SEQ_PUT_FIELD_RET(s, field->prev_state);
687         SEQ_PUT_FIELD_RET(s, field->next_pid);
688         SEQ_PUT_FIELD_RET(s, field->next_prio);
689         SEQ_PUT_FIELD_RET(s, field->next_state);
690
691         return TRACE_TYPE_HANDLED;
692 }
693
694 static struct trace_event trace_ctx_event = {
695         .type           = TRACE_CTX,
696         .trace          = trace_ctx_print,
697         .latency_trace  = trace_ctx_print,
698         .raw            = trace_ctx_raw,
699         .hex            = trace_ctx_hex,
700         .binary         = trace_ctxwake_bin,
701 };
702
703 static struct trace_event trace_wake_event = {
704         .type           = TRACE_WAKE,
705         .trace          = trace_wake_print,
706         .latency_trace  = trace_wake_print,
707         .raw            = trace_wake_raw,
708         .hex            = trace_wake_hex,
709         .binary         = trace_ctxwake_bin,
710 };
711
712 /* TRACE_SPECIAL */
713 static enum print_line_t trace_special_print(struct trace_iterator *iter,
714                                              int flags)
715 {
716         struct special_entry *field;
717
718         trace_assign_type(field, iter->ent);
719
720         if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
721                               field->arg1,
722                               field->arg2,
723                               field->arg3))
724                 return TRACE_TYPE_PARTIAL_LINE;
725
726         return TRACE_TYPE_HANDLED;
727 }
728
729 static enum print_line_t trace_special_hex(struct trace_iterator *iter,
730                                            int flags)
731 {
732         struct special_entry *field;
733         struct trace_seq *s = &iter->seq;
734
735         trace_assign_type(field, iter->ent);
736
737         SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
738         SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
739         SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
740
741         return TRACE_TYPE_HANDLED;
742 }
743
744 static enum print_line_t trace_special_bin(struct trace_iterator *iter,
745                                            int flags)
746 {
747         struct special_entry *field;
748         struct trace_seq *s = &iter->seq;
749
750         trace_assign_type(field, iter->ent);
751
752         SEQ_PUT_FIELD_RET(s, field->arg1);
753         SEQ_PUT_FIELD_RET(s, field->arg2);
754         SEQ_PUT_FIELD_RET(s, field->arg3);
755
756         return TRACE_TYPE_HANDLED;
757 }
758
759 static struct trace_event trace_special_event = {
760         .type           = TRACE_SPECIAL,
761         .trace          = trace_special_print,
762         .latency_trace  = trace_special_print,
763         .raw            = trace_special_print,
764         .hex            = trace_special_hex,
765         .binary         = trace_special_bin,
766 };
767
768 /* TRACE_STACK */
769
770 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
771                                            int flags)
772 {
773         struct stack_entry *field;
774         struct trace_seq *s = &iter->seq;
775         int i;
776
777         trace_assign_type(field, iter->ent);
778
779         for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
780                 if (i) {
781                         if (!trace_seq_puts(s, " <= "))
782                                 goto partial;
783
784                         if (!seq_print_ip_sym(s, field->caller[i], flags))
785                                 goto partial;
786                 }
787                 if (!trace_seq_puts(s, "\n"))
788                         goto partial;
789         }
790
791         return TRACE_TYPE_HANDLED;
792
793  partial:
794         return TRACE_TYPE_PARTIAL_LINE;
795 }
796
797 static struct trace_event trace_stack_event = {
798         .type           = TRACE_STACK,
799         .trace          = trace_stack_print,
800         .latency_trace  = trace_stack_print,
801         .raw            = trace_special_print,
802         .hex            = trace_special_hex,
803         .binary         = trace_special_bin,
804 };
805
806 /* TRACE_USER_STACK */
807 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
808                                                 int flags)
809 {
810         struct userstack_entry *field;
811         struct trace_seq *s = &iter->seq;
812
813         trace_assign_type(field, iter->ent);
814
815         if (!seq_print_userip_objs(field, s, flags))
816                 goto partial;
817
818         if (!trace_seq_putc(s, '\n'))
819                 goto partial;
820
821         return TRACE_TYPE_HANDLED;
822
823  partial:
824         return TRACE_TYPE_PARTIAL_LINE;
825 }
826
827 static struct trace_event trace_user_stack_event = {
828         .type           = TRACE_USER_STACK,
829         .trace          = trace_user_stack_print,
830         .latency_trace  = trace_user_stack_print,
831         .raw            = trace_special_print,
832         .hex            = trace_special_hex,
833         .binary         = trace_special_bin,
834 };
835
836 /* TRACE_PRINT */
837 static enum print_line_t trace_print_print(struct trace_iterator *iter,
838                                            int flags)
839 {
840         struct print_entry *field;
841         struct trace_seq *s = &iter->seq;
842
843         trace_assign_type(field, iter->ent);
844
845         if (!seq_print_ip_sym(s, field->ip, flags))
846                 goto partial;
847
848         if (!trace_seq_printf(s, ": %s", field->buf))
849                 goto partial;
850
851         return TRACE_TYPE_HANDLED;
852
853  partial:
854         return TRACE_TYPE_PARTIAL_LINE;
855 }
856
857 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
858 {
859         struct print_entry *field;
860
861         trace_assign_type(field, iter->ent);
862
863         if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
864                 goto partial;
865
866         return TRACE_TYPE_HANDLED;
867
868  partial:
869         return TRACE_TYPE_PARTIAL_LINE;
870 }
871
872 static struct trace_event trace_print_event = {
873         .type           = TRACE_PRINT,
874         .trace          = trace_print_print,
875         .latency_trace  = trace_print_print,
876         .raw            = trace_print_raw,
877         .hex            = trace_nop_print,
878         .binary         = trace_nop_print,
879 };
880
881 static struct trace_event *events[] __initdata = {
882         &trace_fn_event,
883         &trace_ctx_event,
884         &trace_wake_event,
885         &trace_special_event,
886         &trace_stack_event,
887         &trace_user_stack_event,
888         &trace_print_event,
889         NULL
890 };
891
892 __init static int init_events(void)
893 {
894         struct trace_event *event;
895         int i, ret;
896
897         for (i = 0; events[i]; i++) {
898                 event = events[i];
899
900                 ret = register_ftrace_event(event);
901                 if (!ret) {
902                         printk(KERN_WARNING "event %d failed to register\n",
903                                event->type);
904                         WARN_ON_ONCE(1);
905                 }
906         }
907
908         return 0;
909 }
910 device_initcall(init_events);