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 DECLARE_RWSEM(trace_event_sem);
18
19 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
20
21 static int next_event_type = __TRACE_LAST_TYPE + 1;
22
trace_print_seq(struct seq_file * m,struct trace_seq * s)23 int trace_print_seq(struct seq_file *m, struct trace_seq *s)
24 {
25 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
26 int ret;
27
28 ret = seq_write(m, s->buffer, len);
29
30 /*
31 * Only reset this buffer if we successfully wrote to the
32 * seq_file buffer.
33 */
34 if (!ret)
35 trace_seq_init(s);
36
37 return ret;
38 }
39
trace_print_bputs_msg_only(struct trace_iterator * iter)40 enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
41 {
42 struct trace_seq *s = &iter->seq;
43 struct trace_entry *entry = iter->ent;
44 struct bputs_entry *field;
45 int ret;
46
47 trace_assign_type(field, entry);
48
49 ret = trace_seq_puts(s, field->str);
50 if (!ret)
51 return TRACE_TYPE_PARTIAL_LINE;
52
53 return TRACE_TYPE_HANDLED;
54 }
55
trace_print_bprintk_msg_only(struct trace_iterator * iter)56 enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
57 {
58 struct trace_seq *s = &iter->seq;
59 struct trace_entry *entry = iter->ent;
60 struct bprint_entry *field;
61 int ret;
62
63 trace_assign_type(field, entry);
64
65 ret = trace_seq_bprintf(s, field->fmt, field->buf);
66 if (!ret)
67 return TRACE_TYPE_PARTIAL_LINE;
68
69 return TRACE_TYPE_HANDLED;
70 }
71
trace_print_printk_msg_only(struct trace_iterator * iter)72 enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
73 {
74 struct trace_seq *s = &iter->seq;
75 struct trace_entry *entry = iter->ent;
76 struct print_entry *field;
77 int ret;
78
79 trace_assign_type(field, entry);
80
81 ret = trace_seq_printf(s, "%s", field->buf);
82 if (!ret)
83 return TRACE_TYPE_PARTIAL_LINE;
84
85 return TRACE_TYPE_HANDLED;
86 }
87
88 /**
89 * trace_seq_printf - sequence printing of trace information
90 * @s: trace sequence descriptor
91 * @fmt: printf format string
92 *
93 * It returns 0 if the trace oversizes the buffer's free
94 * space, 1 otherwise.
95 *
96 * The tracer may use either sequence operations or its own
97 * copy to user routines. To simplify formating of a trace
98 * trace_seq_printf is used to store strings into a special
99 * buffer (@s). Then the output may be either used by
100 * the sequencer or pulled into another buffer.
101 */
102 int
trace_seq_printf(struct trace_seq * s,const char * fmt,...)103 trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
104 {
105 int len = (PAGE_SIZE - 1) - s->len;
106 va_list ap;
107 int ret;
108
109 if (s->full || !len)
110 return 0;
111
112 va_start(ap, fmt);
113 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
114 va_end(ap);
115
116 /* If we can't write it all, don't bother writing anything */
117 if (ret >= len) {
118 s->full = 1;
119 return 0;
120 }
121
122 s->len += ret;
123
124 return 1;
125 }
126 EXPORT_SYMBOL_GPL(trace_seq_printf);
127
128 /**
129 * trace_seq_vprintf - sequence printing of trace information
130 * @s: trace sequence descriptor
131 * @fmt: printf format string
132 *
133 * The tracer may use either sequence operations or its own
134 * copy to user routines. To simplify formating of a trace
135 * trace_seq_printf is used to store strings into a special
136 * buffer (@s). Then the output may be either used by
137 * the sequencer or pulled into another buffer.
138 */
139 int
trace_seq_vprintf(struct trace_seq * s,const char * fmt,va_list args)140 trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
141 {
142 int len = (PAGE_SIZE - 1) - s->len;
143 int ret;
144
145 if (s->full || !len)
146 return 0;
147
148 ret = vsnprintf(s->buffer + s->len, len, fmt, args);
149
150 /* If we can't write it all, don't bother writing anything */
151 if (ret >= len) {
152 s->full = 1;
153 return 0;
154 }
155
156 s->len += ret;
157
158 return len;
159 }
160 EXPORT_SYMBOL_GPL(trace_seq_vprintf);
161
trace_seq_bprintf(struct trace_seq * s,const char * fmt,const u32 * binary)162 int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
163 {
164 int len = (PAGE_SIZE - 1) - s->len;
165 int ret;
166
167 if (s->full || !len)
168 return 0;
169
170 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
171
172 /* If we can't write it all, don't bother writing anything */
173 if (ret >= len) {
174 s->full = 1;
175 return 0;
176 }
177
178 s->len += ret;
179
180 return len;
181 }
182
183 /**
184 * trace_seq_puts - trace sequence printing of simple string
185 * @s: trace sequence descriptor
186 * @str: simple string to record
187 *
188 * The tracer may use either the sequence operations or its own
189 * copy to user routines. This function records a simple string
190 * into a special buffer (@s) for later retrieval by a sequencer
191 * or other mechanism.
192 */
trace_seq_puts(struct trace_seq * s,const char * str)193 int trace_seq_puts(struct trace_seq *s, const char *str)
194 {
195 int len = strlen(str);
196
197 if (s->full)
198 return 0;
199
200 if (len > ((PAGE_SIZE - 1) - s->len)) {
201 s->full = 1;
202 return 0;
203 }
204
205 memcpy(s->buffer + s->len, str, len);
206 s->len += len;
207
208 return len;
209 }
210
trace_seq_putc(struct trace_seq * s,unsigned char c)211 int trace_seq_putc(struct trace_seq *s, unsigned char c)
212 {
213 if (s->full)
214 return 0;
215
216 if (s->len >= (PAGE_SIZE - 1)) {
217 s->full = 1;
218 return 0;
219 }
220
221 s->buffer[s->len++] = c;
222
223 return 1;
224 }
225 EXPORT_SYMBOL(trace_seq_putc);
226
trace_seq_putmem(struct trace_seq * s,const void * mem,size_t len)227 int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
228 {
229 if (s->full)
230 return 0;
231
232 if (len > ((PAGE_SIZE - 1) - s->len)) {
233 s->full = 1;
234 return 0;
235 }
236
237 memcpy(s->buffer + s->len, mem, len);
238 s->len += len;
239
240 return len;
241 }
242
trace_seq_putmem_hex(struct trace_seq * s,const void * mem,size_t len)243 int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
244 {
245 unsigned char hex[HEX_CHARS];
246 const unsigned char *data = mem;
247 int i, j;
248
249 if (s->full)
250 return 0;
251
252 #ifdef __BIG_ENDIAN
253 for (i = 0, j = 0; i < len; i++) {
254 #else
255 for (i = len-1, j = 0; i >= 0; i--) {
256 #endif
257 hex[j++] = hex_asc_hi(data[i]);
258 hex[j++] = hex_asc_lo(data[i]);
259 }
260 hex[j++] = ' ';
261
262 return trace_seq_putmem(s, hex, j);
263 }
264
265 void *trace_seq_reserve(struct trace_seq *s, size_t len)
266 {
267 void *ret;
268
269 if (s->full)
270 return NULL;
271
272 if (len > ((PAGE_SIZE - 1) - s->len)) {
273 s->full = 1;
274 return NULL;
275 }
276
277 ret = s->buffer + s->len;
278 s->len += len;
279
280 return ret;
281 }
282
283 int trace_seq_path(struct trace_seq *s, const struct path *path)
284 {
285 unsigned char *p;
286
287 if (s->full)
288 return 0;
289
290 if (s->len >= (PAGE_SIZE - 1)) {
291 s->full = 1;
292 return 0;
293 }
294
295 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
296 if (!IS_ERR(p)) {
297 p = mangle_path(s->buffer + s->len, p, "\n");
298 if (p) {
299 s->len = p - s->buffer;
300 return 1;
301 }
302 } else {
303 s->buffer[s->len++] = '?';
304 return 1;
305 }
306
307 s->full = 1;
308 return 0;
309 }
310
311 const char *
312 ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
313 unsigned long flags,
314 const struct trace_print_flags *flag_array)
315 {
316 unsigned long mask;
317 const char *str;
318 const char *ret = p->buffer + p->len;
319 int i, first = 1;
320
321 for (i = 0; flag_array[i].name && flags; i++) {
322
323 mask = flag_array[i].mask;
324 if ((flags & mask) != mask)
325 continue;
326
327 str = flag_array[i].name;
328 flags &= ~mask;
329 if (!first && delim)
330 trace_seq_puts(p, delim);
331 else
332 first = 0;
333 trace_seq_puts(p, str);
334 }
335
336 /* check for left over flags */
337 if (flags) {
338 if (!first && delim)
339 trace_seq_puts(p, delim);
340 trace_seq_printf(p, "0x%lx", flags);
341 }
342
343 trace_seq_putc(p, 0);
344
345 return ret;
346 }
347 EXPORT_SYMBOL(ftrace_print_flags_seq);
348
349 const char *
350 ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
351 const struct trace_print_flags *symbol_array)
352 {
353 int i;
354 const char *ret = p->buffer + p->len;
355
356 for (i = 0; symbol_array[i].name; i++) {
357
358 if (val != symbol_array[i].mask)
359 continue;
360
361 trace_seq_puts(p, symbol_array[i].name);
362 break;
363 }
364
365 if (ret == (const char *)(p->buffer + p->len))
366 trace_seq_printf(p, "0x%lx", val);
367
368 trace_seq_putc(p, 0);
369
370 return ret;
371 }
372 EXPORT_SYMBOL(ftrace_print_symbols_seq);
373
374 #if BITS_PER_LONG == 32
375 const char *
376 ftrace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
377 const struct trace_print_flags_u64 *symbol_array)
378 {
379 int i;
380 const char *ret = p->buffer + p->len;
381
382 for (i = 0; symbol_array[i].name; i++) {
383
384 if (val != symbol_array[i].mask)
385 continue;
386
387 trace_seq_puts(p, symbol_array[i].name);
388 break;
389 }
390
391 if (ret == (const char *)(p->buffer + p->len))
392 trace_seq_printf(p, "0x%llx", val);
393
394 trace_seq_putc(p, 0);
395
396 return ret;
397 }
398 EXPORT_SYMBOL(ftrace_print_symbols_seq_u64);
399 #endif
400
401 const char *
402 ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len)
403 {
404 int i;
405 const char *ret = p->buffer + p->len;
406
407 for (i = 0; i < buf_len; i++)
408 trace_seq_printf(p, "%s%2.2x", i == 0 ? "" : " ", buf[i]);
409
410 trace_seq_putc(p, 0);
411
412 return ret;
413 }
414 EXPORT_SYMBOL(ftrace_print_hex_seq);
415
416 int ftrace_raw_output_prep(struct trace_iterator *iter,
417 struct trace_event *trace_event)
418 {
419 struct ftrace_event_call *event;
420 struct trace_seq *s = &iter->seq;
421 struct trace_seq *p = &iter->tmp_seq;
422 struct trace_entry *entry;
423 int ret;
424
425 event = container_of(trace_event, struct ftrace_event_call, event);
426 entry = iter->ent;
427
428 if (entry->type != event->event.type) {
429 WARN_ON_ONCE(1);
430 return TRACE_TYPE_UNHANDLED;
431 }
432
433 trace_seq_init(p);
434 ret = trace_seq_printf(s, "%s: ", event->name);
435 if (!ret)
436 return TRACE_TYPE_PARTIAL_LINE;
437
438 return 0;
439 }
440 EXPORT_SYMBOL(ftrace_raw_output_prep);
441
442 #ifdef CONFIG_KRETPROBES
443 static inline const char *kretprobed(const char *name)
444 {
445 static const char tramp_name[] = "kretprobe_trampoline";
446 int size = sizeof(tramp_name);
447
448 if (strncmp(tramp_name, name, size) == 0)
449 return "[unknown/kretprobe'd]";
450 return name;
451 }
452 #else
453 static inline const char *kretprobed(const char *name)
454 {
455 return name;
456 }
457 #endif /* CONFIG_KRETPROBES */
458
459 static int
460 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
461 {
462 #ifdef CONFIG_KALLSYMS
463 char str[KSYM_SYMBOL_LEN];
464 const char *name;
465
466 kallsyms_lookup(address, NULL, NULL, NULL, str);
467
468 name = kretprobed(str);
469
470 return trace_seq_printf(s, fmt, name);
471 #endif
472 return 1;
473 }
474
475 static int
476 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
477 unsigned long address)
478 {
479 #ifdef CONFIG_KALLSYMS
480 char str[KSYM_SYMBOL_LEN];
481 const char *name;
482
483 sprint_symbol(str, address);
484 name = kretprobed(str);
485
486 return trace_seq_printf(s, fmt, name);
487 #endif
488 return 1;
489 }
490
491 #ifndef CONFIG_64BIT
492 # define IP_FMT "%08lx"
493 #else
494 # define IP_FMT "%016lx"
495 #endif
496
497 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
498 unsigned long ip, unsigned long sym_flags)
499 {
500 struct file *file = NULL;
501 unsigned long vmstart = 0;
502 int ret = 1;
503
504 if (s->full)
505 return 0;
506
507 if (mm) {
508 const struct vm_area_struct *vma;
509
510 down_read(&mm->mmap_sem);
511 vma = find_vma(mm, ip);
512 if (vma) {
513 file = vma->vm_file;
514 vmstart = vma->vm_start;
515 }
516 if (file) {
517 ret = trace_seq_path(s, &file->f_path);
518 if (ret)
519 ret = trace_seq_printf(s, "[+0x%lx]",
520 ip - vmstart);
521 }
522 up_read(&mm->mmap_sem);
523 }
524 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
525 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
526 return ret;
527 }
528
529 int
530 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
531 unsigned long sym_flags)
532 {
533 struct mm_struct *mm = NULL;
534 int ret = 1;
535 unsigned int i;
536
537 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
538 struct task_struct *task;
539 /*
540 * we do the lookup on the thread group leader,
541 * since individual threads might have already quit!
542 */
543 rcu_read_lock();
544 task = find_task_by_vpid(entry->tgid);
545 if (task)
546 mm = get_task_mm(task);
547 rcu_read_unlock();
548 }
549
550 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
551 unsigned long ip = entry->caller[i];
552
553 if (ip == ULONG_MAX || !ret)
554 break;
555 if (ret)
556 ret = trace_seq_puts(s, " => ");
557 if (!ip) {
558 if (ret)
559 ret = trace_seq_puts(s, "??");
560 if (ret)
561 ret = trace_seq_puts(s, "\n");
562 continue;
563 }
564 if (!ret)
565 break;
566 if (ret)
567 ret = seq_print_user_ip(s, mm, ip, sym_flags);
568 ret = trace_seq_puts(s, "\n");
569 }
570
571 if (mm)
572 mmput(mm);
573 return ret;
574 }
575
576 int
577 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
578 {
579 int ret;
580
581 if (!ip)
582 return trace_seq_printf(s, "0");
583
584 if (sym_flags & TRACE_ITER_SYM_OFFSET)
585 ret = seq_print_sym_offset(s, "%s", ip);
586 else
587 ret = seq_print_sym_short(s, "%s", ip);
588
589 if (!ret)
590 return 0;
591
592 if (sym_flags & TRACE_ITER_SYM_ADDR)
593 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
594 return ret;
595 }
596
597 /**
598 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
599 * @s: trace seq struct to write to
600 * @entry: The trace entry field from the ring buffer
601 *
602 * Prints the generic fields of irqs off, in hard or softirq, preempt
603 * count.
604 */
605 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
606 {
607 char hardsoft_irq;
608 char need_resched;
609 char irqs_off;
610 int hardirq;
611 int softirq;
612 int ret;
613
614 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
615 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
616
617 irqs_off =
618 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
619 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
620 '.';
621 need_resched =
622 (entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.';
623 hardsoft_irq =
624 (hardirq && softirq) ? 'H' :
625 hardirq ? 'h' :
626 softirq ? 's' :
627 '.';
628
629 if (!trace_seq_printf(s, "%c%c%c",
630 irqs_off, need_resched, hardsoft_irq))
631 return 0;
632
633 if (entry->preempt_count)
634 ret = trace_seq_printf(s, "%x", entry->preempt_count);
635 else
636 ret = trace_seq_putc(s, '.');
637
638 return ret;
639 }
640
641 static int
642 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
643 {
644 char comm[TASK_COMM_LEN];
645
646 trace_find_cmdline(entry->pid, comm);
647
648 if (!trace_seq_printf(s, "%8.8s-%-5d %3d",
649 comm, entry->pid, cpu))
650 return 0;
651
652 return trace_print_lat_fmt(s, entry);
653 }
654
655 static unsigned long preempt_mark_thresh_us = 100;
656
657 static int
658 lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
659 {
660 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE;
661 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
662 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
663 unsigned long long rel_ts = next_ts - iter->ts;
664 struct trace_seq *s = &iter->seq;
665
666 if (in_ns) {
667 abs_ts = ns2usecs(abs_ts);
668 rel_ts = ns2usecs(rel_ts);
669 }
670
671 if (verbose && in_ns) {
672 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
673 unsigned long abs_msec = (unsigned long)abs_ts;
674 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
675 unsigned long rel_msec = (unsigned long)rel_ts;
676
677 return trace_seq_printf(
678 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
679 ns2usecs(iter->ts),
680 abs_msec, abs_usec,
681 rel_msec, rel_usec);
682 } else if (verbose && !in_ns) {
683 return trace_seq_printf(
684 s, "[%016llx] %lld (+%lld): ",
685 iter->ts, abs_ts, rel_ts);
686 } else if (!verbose && in_ns) {
687 return trace_seq_printf(
688 s, " %4lldus%c: ",
689 abs_ts,
690 rel_ts > preempt_mark_thresh_us ? '!' :
691 rel_ts > 1 ? '+' : ' ');
692 } else { /* !verbose && !in_ns */
693 return trace_seq_printf(s, " %4lld: ", abs_ts);
694 }
695 }
696
697 int trace_print_context(struct trace_iterator *iter)
698 {
699 struct trace_seq *s = &iter->seq;
700 struct trace_entry *entry = iter->ent;
701 unsigned long long t;
702 unsigned long secs, usec_rem;
703 char comm[TASK_COMM_LEN];
704 int ret;
705 int tgid;
706
707 trace_find_cmdline(entry->pid, comm);
708
709 ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
710 if (!ret)
711 return 0;
712
713 if (trace_flags & TRACE_ITER_TGID) {
714 tgid = trace_find_tgid(entry->pid);
715 if (tgid < 0)
716 ret = trace_seq_puts(s, "(-----) ");
717 else
718 ret = trace_seq_printf(s, "(%5d) ", tgid);
719 if (!ret)
720 return 0;
721 }
722
723 ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
724 if (!ret)
725 return 0;
726
727 if (trace_flags & TRACE_ITER_IRQ_INFO) {
728 ret = trace_print_lat_fmt(s, entry);
729 if (!ret)
730 return 0;
731 }
732
733 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
734 t = ns2usecs(iter->ts);
735 usec_rem = do_div(t, USEC_PER_SEC);
736 secs = (unsigned long)t;
737 return trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
738 } else
739 return trace_seq_printf(s, " %12llu: ", iter->ts);
740 }
741
742 int trace_print_lat_context(struct trace_iterator *iter)
743 {
744 u64 next_ts;
745 int ret;
746 /* trace_find_next_entry will reset ent_size */
747 int ent_size = iter->ent_size;
748 struct trace_seq *s = &iter->seq;
749 struct trace_entry *entry = iter->ent,
750 *next_entry = trace_find_next_entry(iter, NULL,
751 &next_ts);
752 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
753
754 /* Restore the original ent_size */
755 iter->ent_size = ent_size;
756
757 if (!next_entry)
758 next_ts = iter->ts;
759
760 if (verbose) {
761 char comm[TASK_COMM_LEN];
762
763 trace_find_cmdline(entry->pid, comm);
764
765 ret = trace_seq_printf(
766 s, "%16s %5d %3d %d %08x %08lx ",
767 comm, entry->pid, iter->cpu, entry->flags,
768 entry->preempt_count, iter->idx);
769 } else {
770 ret = lat_print_generic(s, entry, iter->cpu);
771 }
772
773 if (ret)
774 ret = lat_print_timestamp(iter, next_ts);
775
776 return ret;
777 }
778
779 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
780
781 static int task_state_char(unsigned long state)
782 {
783 int bit = state ? __ffs(state) + 1 : 0;
784
785 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
786 }
787
788 /**
789 * ftrace_find_event - find a registered event
790 * @type: the type of event to look for
791 *
792 * Returns an event of type @type otherwise NULL
793 * Called with trace_event_read_lock() held.
794 */
795 struct trace_event *ftrace_find_event(int type)
796 {
797 struct trace_event *event;
798 unsigned key;
799
800 key = type & (EVENT_HASHSIZE - 1);
801
802 hlist_for_each_entry(event, &event_hash[key], node) {
803 if (event->type == type)
804 return event;
805 }
806
807 return NULL;
808 }
809
810 static LIST_HEAD(ftrace_event_list);
811
812 static int trace_search_list(struct list_head **list)
813 {
814 struct trace_event *e;
815 int last = __TRACE_LAST_TYPE;
816
817 if (list_empty(&ftrace_event_list)) {
818 *list = &ftrace_event_list;
819 return last + 1;
820 }
821
822 /*
823 * We used up all possible max events,
824 * lets see if somebody freed one.
825 */
826 list_for_each_entry(e, &ftrace_event_list, list) {
827 if (e->type != last + 1)
828 break;
829 last++;
830 }
831
832 /* Did we used up all 65 thousand events??? */
833 if ((last + 1) > FTRACE_MAX_EVENT)
834 return 0;
835
836 *list = &e->list;
837 return last + 1;
838 }
839
840 void trace_event_read_lock(void)
841 {
842 down_read(&trace_event_sem);
843 }
844
845 void trace_event_read_unlock(void)
846 {
847 up_read(&trace_event_sem);
848 }
849
850 /**
851 * register_ftrace_event - register output for an event type
852 * @event: the event type to register
853 *
854 * Event types are stored in a hash and this hash is used to
855 * find a way to print an event. If the @event->type is set
856 * then it will use that type, otherwise it will assign a
857 * type to use.
858 *
859 * If you assign your own type, please make sure it is added
860 * to the trace_type enum in trace.h, to avoid collisions
861 * with the dynamic types.
862 *
863 * Returns the event type number or zero on error.
864 */
865 int register_ftrace_event(struct trace_event *event)
866 {
867 unsigned key;
868 int ret = 0;
869
870 down_write(&trace_event_sem);
871
872 if (WARN_ON(!event))
873 goto out;
874
875 if (WARN_ON(!event->funcs))
876 goto out;
877
878 INIT_LIST_HEAD(&event->list);
879
880 if (!event->type) {
881 struct list_head *list = NULL;
882
883 if (next_event_type > FTRACE_MAX_EVENT) {
884
885 event->type = trace_search_list(&list);
886 if (!event->type)
887 goto out;
888
889 } else {
890
891 event->type = next_event_type++;
892 list = &ftrace_event_list;
893 }
894
895 if (WARN_ON(ftrace_find_event(event->type)))
896 goto out;
897
898 list_add_tail(&event->list, list);
899
900 } else if (event->type > __TRACE_LAST_TYPE) {
901 printk(KERN_WARNING "Need to add type to trace.h\n");
902 WARN_ON(1);
903 goto out;
904 } else {
905 /* Is this event already used */
906 if (ftrace_find_event(event->type))
907 goto out;
908 }
909
910 if (event->funcs->trace == NULL)
911 event->funcs->trace = trace_nop_print;
912 if (event->funcs->raw == NULL)
913 event->funcs->raw = trace_nop_print;
914 if (event->funcs->hex == NULL)
915 event->funcs->hex = trace_nop_print;
916 if (event->funcs->binary == NULL)
917 event->funcs->binary = trace_nop_print;
918
919 key = event->type & (EVENT_HASHSIZE - 1);
920
921 hlist_add_head(&event->node, &event_hash[key]);
922
923 ret = event->type;
924 out:
925 up_write(&trace_event_sem);
926
927 return ret;
928 }
929 EXPORT_SYMBOL_GPL(register_ftrace_event);
930
931 /*
932 * Used by module code with the trace_event_sem held for write.
933 */
934 int __unregister_ftrace_event(struct trace_event *event)
935 {
936 hlist_del(&event->node);
937 list_del(&event->list);
938 return 0;
939 }
940
941 /**
942 * unregister_ftrace_event - remove a no longer used event
943 * @event: the event to remove
944 */
945 int unregister_ftrace_event(struct trace_event *event)
946 {
947 down_write(&trace_event_sem);
948 __unregister_ftrace_event(event);
949 up_write(&trace_event_sem);
950
951 return 0;
952 }
953 EXPORT_SYMBOL_GPL(unregister_ftrace_event);
954
955 /*
956 * Standard events
957 */
958
959 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
960 struct trace_event *event)
961 {
962 if (!trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type))
963 return TRACE_TYPE_PARTIAL_LINE;
964
965 return TRACE_TYPE_HANDLED;
966 }
967
968 /* TRACE_FN */
969 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
970 struct trace_event *event)
971 {
972 struct ftrace_entry *field;
973 struct trace_seq *s = &iter->seq;
974
975 trace_assign_type(field, iter->ent);
976
977 if (!seq_print_ip_sym(s, field->ip, flags))
978 goto partial;
979
980 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
981 if (!trace_seq_printf(s, " <-"))
982 goto partial;
983 if (!seq_print_ip_sym(s,
984 field->parent_ip,
985 flags))
986 goto partial;
987 }
988 if (!trace_seq_printf(s, "\n"))
989 goto partial;
990
991 return TRACE_TYPE_HANDLED;
992
993 partial:
994 return TRACE_TYPE_PARTIAL_LINE;
995 }
996
997 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
998 struct trace_event *event)
999 {
1000 struct ftrace_entry *field;
1001
1002 trace_assign_type(field, iter->ent);
1003
1004 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
1005 field->ip,
1006 field->parent_ip))
1007 return TRACE_TYPE_PARTIAL_LINE;
1008
1009 return TRACE_TYPE_HANDLED;
1010 }
1011
1012 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
1013 struct trace_event *event)
1014 {
1015 struct ftrace_entry *field;
1016 struct trace_seq *s = &iter->seq;
1017
1018 trace_assign_type(field, iter->ent);
1019
1020 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
1021 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
1022
1023 return TRACE_TYPE_HANDLED;
1024 }
1025
1026 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
1027 struct trace_event *event)
1028 {
1029 struct ftrace_entry *field;
1030 struct trace_seq *s = &iter->seq;
1031
1032 trace_assign_type(field, iter->ent);
1033
1034 SEQ_PUT_FIELD_RET(s, field->ip);
1035 SEQ_PUT_FIELD_RET(s, field->parent_ip);
1036
1037 return TRACE_TYPE_HANDLED;
1038 }
1039
1040 static struct trace_event_functions trace_fn_funcs = {
1041 .trace = trace_fn_trace,
1042 .raw = trace_fn_raw,
1043 .hex = trace_fn_hex,
1044 .binary = trace_fn_bin,
1045 };
1046
1047 static struct trace_event trace_fn_event = {
1048 .type = TRACE_FN,
1049 .funcs = &trace_fn_funcs,
1050 };
1051
1052 /* TRACE_GRAPH_ENT */
1053 static enum print_line_t trace_graph_ent_trace(struct trace_iterator *iter, int flags,
1054 struct trace_event *event)
1055 {
1056 struct trace_seq *s = &iter->seq;
1057 struct ftrace_graph_ent_entry *field;
1058
1059 trace_assign_type(field, iter->ent);
1060
1061 if (!trace_seq_puts(s, "graph_ent: func="))
1062 return TRACE_TYPE_PARTIAL_LINE;
1063
1064 if (!seq_print_ip_sym(s, field->graph_ent.func, flags))
1065 return TRACE_TYPE_PARTIAL_LINE;
1066
1067 if (!trace_seq_puts(s, "\n"))
1068 return TRACE_TYPE_PARTIAL_LINE;
1069
1070 return TRACE_TYPE_HANDLED;
1071 }
1072
1073 static enum print_line_t trace_graph_ent_raw(struct trace_iterator *iter, int flags,
1074 struct trace_event *event)
1075 {
1076 struct ftrace_graph_ent_entry *field;
1077
1078 trace_assign_type(field, iter->ent);
1079
1080 if (!trace_seq_printf(&iter->seq, "%lx %d\n",
1081 field->graph_ent.func,
1082 field->graph_ent.depth))
1083 return TRACE_TYPE_PARTIAL_LINE;
1084
1085 return TRACE_TYPE_HANDLED;
1086 }
1087
1088 static enum print_line_t trace_graph_ent_hex(struct trace_iterator *iter, int flags,
1089 struct trace_event *event)
1090 {
1091 struct ftrace_graph_ent_entry *field;
1092 struct trace_seq *s = &iter->seq;
1093
1094 trace_assign_type(field, iter->ent);
1095
1096 SEQ_PUT_HEX_FIELD_RET(s, field->graph_ent.func);
1097 SEQ_PUT_HEX_FIELD_RET(s, field->graph_ent.depth);
1098
1099 return TRACE_TYPE_HANDLED;
1100 }
1101
1102 static enum print_line_t trace_graph_ent_bin(struct trace_iterator *iter, int flags,
1103 struct trace_event *event)
1104 {
1105 struct ftrace_graph_ent_entry *field;
1106 struct trace_seq *s = &iter->seq;
1107
1108 trace_assign_type(field, iter->ent);
1109
1110 SEQ_PUT_FIELD_RET(s, field->graph_ent.func);
1111 SEQ_PUT_FIELD_RET(s, field->graph_ent.depth);
1112
1113 return TRACE_TYPE_HANDLED;
1114 }
1115
1116 static struct trace_event_functions trace_graph_ent_funcs = {
1117 .trace = trace_graph_ent_trace,
1118 .raw = trace_graph_ent_raw,
1119 .hex = trace_graph_ent_hex,
1120 .binary = trace_graph_ent_bin,
1121 };
1122
1123 static struct trace_event trace_graph_ent_event = {
1124 .type = TRACE_GRAPH_ENT,
1125 .funcs = &trace_graph_ent_funcs,
1126 };
1127
1128 /* TRACE_GRAPH_RET */
1129 static enum print_line_t trace_graph_ret_trace(struct trace_iterator *iter, int flags,
1130 struct trace_event *event)
1131 {
1132 struct trace_seq *s = &iter->seq;
1133 struct trace_entry *entry = iter->ent;
1134 struct ftrace_graph_ret_entry *field;
1135
1136 trace_assign_type(field, entry);
1137
1138 if (!trace_seq_puts(s, "graph_ret: func="))
1139 return TRACE_TYPE_PARTIAL_LINE;
1140
1141 if (!seq_print_ip_sym(s, field->ret.func, flags))
1142 return TRACE_TYPE_PARTIAL_LINE;
1143
1144 if (!trace_seq_puts(s, "\n"))
1145 return TRACE_TYPE_PARTIAL_LINE;
1146
1147 return TRACE_TYPE_HANDLED;
1148 }
1149
1150 static enum print_line_t trace_graph_ret_raw(struct trace_iterator *iter, int flags,
1151 struct trace_event *event)
1152 {
1153 struct ftrace_graph_ret_entry *field;
1154
1155 trace_assign_type(field, iter->ent);
1156
1157 if (!trace_seq_printf(&iter->seq, "%lx %lld %lld %ld %d\n",
1158 field->ret.func,
1159 field->ret.calltime,
1160 field->ret.rettime,
1161 field->ret.overrun,
1162 field->ret.depth));
1163 return TRACE_TYPE_PARTIAL_LINE;
1164
1165 return TRACE_TYPE_HANDLED;
1166 }
1167
1168 static enum print_line_t trace_graph_ret_hex(struct trace_iterator *iter, int flags,
1169 struct trace_event *event)
1170 {
1171 struct ftrace_graph_ret_entry *field;
1172 struct trace_seq *s = &iter->seq;
1173
1174 trace_assign_type(field, iter->ent);
1175
1176 SEQ_PUT_HEX_FIELD_RET(s, field->ret.func);
1177 SEQ_PUT_HEX_FIELD_RET(s, field->ret.calltime);
1178 SEQ_PUT_HEX_FIELD_RET(s, field->ret.rettime);
1179 SEQ_PUT_HEX_FIELD_RET(s, field->ret.overrun);
1180 SEQ_PUT_HEX_FIELD_RET(s, field->ret.depth);
1181
1182 return TRACE_TYPE_HANDLED;
1183 }
1184
1185 static enum print_line_t trace_graph_ret_bin(struct trace_iterator *iter, int flags,
1186 struct trace_event *event)
1187 {
1188 struct ftrace_graph_ret_entry *field;
1189 struct trace_seq *s = &iter->seq;
1190
1191 trace_assign_type(field, iter->ent);
1192
1193 SEQ_PUT_FIELD_RET(s, field->ret.func);
1194 SEQ_PUT_FIELD_RET(s, field->ret.calltime);
1195 SEQ_PUT_FIELD_RET(s, field->ret.rettime);
1196 SEQ_PUT_FIELD_RET(s, field->ret.overrun);
1197 SEQ_PUT_FIELD_RET(s, field->ret.depth);
1198
1199 return TRACE_TYPE_HANDLED;
1200 }
1201
1202 static struct trace_event_functions trace_graph_ret_funcs = {
1203 .trace = trace_graph_ret_trace,
1204 .raw = trace_graph_ret_raw,
1205 .hex = trace_graph_ret_hex,
1206 .binary = trace_graph_ret_bin,
1207 };
1208
1209 static struct trace_event trace_graph_ret_event = {
1210 .type = TRACE_GRAPH_RET,
1211 .funcs = &trace_graph_ret_funcs,
1212 };
1213
1214 /* TRACE_CTX an TRACE_WAKE */
1215 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
1216 char *delim)
1217 {
1218 struct ctx_switch_entry *field;
1219 char comm[TASK_COMM_LEN];
1220 int S, T;
1221
1222
1223 trace_assign_type(field, iter->ent);
1224
1225 T = task_state_char(field->next_state);
1226 S = task_state_char(field->prev_state);
1227 trace_find_cmdline(field->next_pid, comm);
1228 if (!trace_seq_printf(&iter->seq,
1229 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
1230 field->prev_pid,
1231 field->prev_prio,
1232 S, delim,
1233 field->next_cpu,
1234 field->next_pid,
1235 field->next_prio,
1236 T, comm))
1237 return TRACE_TYPE_PARTIAL_LINE;
1238
1239 return TRACE_TYPE_HANDLED;
1240 }
1241
1242 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
1243 struct trace_event *event)
1244 {
1245 return trace_ctxwake_print(iter, "==>");
1246 }
1247
1248 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
1249 int flags, struct trace_event *event)
1250 {
1251 return trace_ctxwake_print(iter, " +");
1252 }
1253
1254 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
1255 {
1256 struct ctx_switch_entry *field;
1257 int T;
1258
1259 trace_assign_type(field, iter->ent);
1260
1261 if (!S)
1262 S = task_state_char(field->prev_state);
1263 T = task_state_char(field->next_state);
1264 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
1265 field->prev_pid,
1266 field->prev_prio,
1267 S,
1268 field->next_cpu,
1269 field->next_pid,
1270 field->next_prio,
1271 T))
1272 return TRACE_TYPE_PARTIAL_LINE;
1273
1274 return TRACE_TYPE_HANDLED;
1275 }
1276
1277 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
1278 struct trace_event *event)
1279 {
1280 return trace_ctxwake_raw(iter, 0);
1281 }
1282
1283 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
1284 struct trace_event *event)
1285 {
1286 return trace_ctxwake_raw(iter, '+');
1287 }
1288
1289
1290 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
1291 {
1292 struct ctx_switch_entry *field;
1293 struct trace_seq *s = &iter->seq;
1294 int T;
1295
1296 trace_assign_type(field, iter->ent);
1297
1298 if (!S)
1299 S = task_state_char(field->prev_state);
1300 T = task_state_char(field->next_state);
1301
1302 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
1303 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
1304 SEQ_PUT_HEX_FIELD_RET(s, S);
1305 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
1306 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
1307 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
1308 SEQ_PUT_HEX_FIELD_RET(s, T);
1309
1310 return TRACE_TYPE_HANDLED;
1311 }
1312
1313 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
1314 struct trace_event *event)
1315 {
1316 return trace_ctxwake_hex(iter, 0);
1317 }
1318
1319 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
1320 struct trace_event *event)
1321 {
1322 return trace_ctxwake_hex(iter, '+');
1323 }
1324
1325 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
1326 int flags, struct trace_event *event)
1327 {
1328 struct ctx_switch_entry *field;
1329 struct trace_seq *s = &iter->seq;
1330
1331 trace_assign_type(field, iter->ent);
1332
1333 SEQ_PUT_FIELD_RET(s, field->prev_pid);
1334 SEQ_PUT_FIELD_RET(s, field->prev_prio);
1335 SEQ_PUT_FIELD_RET(s, field->prev_state);
1336 SEQ_PUT_FIELD_RET(s, field->next_pid);
1337 SEQ_PUT_FIELD_RET(s, field->next_prio);
1338 SEQ_PUT_FIELD_RET(s, field->next_state);
1339
1340 return TRACE_TYPE_HANDLED;
1341 }
1342
1343 static struct trace_event_functions trace_ctx_funcs = {
1344 .trace = trace_ctx_print,
1345 .raw = trace_ctx_raw,
1346 .hex = trace_ctx_hex,
1347 .binary = trace_ctxwake_bin,
1348 };
1349
1350 static struct trace_event trace_ctx_event = {
1351 .type = TRACE_CTX,
1352 .funcs = &trace_ctx_funcs,
1353 };
1354
1355 static struct trace_event_functions trace_wake_funcs = {
1356 .trace = trace_wake_print,
1357 .raw = trace_wake_raw,
1358 .hex = trace_wake_hex,
1359 .binary = trace_ctxwake_bin,
1360 };
1361
1362 static struct trace_event trace_wake_event = {
1363 .type = TRACE_WAKE,
1364 .funcs = &trace_wake_funcs,
1365 };
1366
1367 /* TRACE_STACK */
1368
1369 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1370 int flags, struct trace_event *event)
1371 {
1372 struct stack_entry *field;
1373 struct trace_seq *s = &iter->seq;
1374 unsigned long *p;
1375 unsigned long *end;
1376
1377 trace_assign_type(field, iter->ent);
1378 end = (unsigned long *)((long)iter->ent + iter->ent_size);
1379
1380 if (!trace_seq_puts(s, "<stack trace>\n"))
1381 goto partial;
1382
1383 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
1384 if (!trace_seq_puts(s, " => "))
1385 goto partial;
1386
1387 if (!seq_print_ip_sym(s, *p, flags))
1388 goto partial;
1389 if (!trace_seq_puts(s, "\n"))
1390 goto partial;
1391 }
1392
1393 return TRACE_TYPE_HANDLED;
1394
1395 partial:
1396 return TRACE_TYPE_PARTIAL_LINE;
1397 }
1398
1399 static struct trace_event_functions trace_stack_funcs = {
1400 .trace = trace_stack_print,
1401 };
1402
1403 static struct trace_event trace_stack_event = {
1404 .type = TRACE_STACK,
1405 .funcs = &trace_stack_funcs,
1406 };
1407
1408 /* TRACE_USER_STACK */
1409 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1410 int flags, struct trace_event *event)
1411 {
1412 struct userstack_entry *field;
1413 struct trace_seq *s = &iter->seq;
1414
1415 trace_assign_type(field, iter->ent);
1416
1417 if (!trace_seq_puts(s, "<user stack trace>\n"))
1418 goto partial;
1419
1420 if (!seq_print_userip_objs(field, s, flags))
1421 goto partial;
1422
1423 return TRACE_TYPE_HANDLED;
1424
1425 partial:
1426 return TRACE_TYPE_PARTIAL_LINE;
1427 }
1428
1429 static struct trace_event_functions trace_user_stack_funcs = {
1430 .trace = trace_user_stack_print,
1431 };
1432
1433 static struct trace_event trace_user_stack_event = {
1434 .type = TRACE_USER_STACK,
1435 .funcs = &trace_user_stack_funcs,
1436 };
1437
1438 /* TRACE_BPUTS */
1439 static enum print_line_t
1440 trace_bputs_print(struct trace_iterator *iter, int flags,
1441 struct trace_event *event)
1442 {
1443 struct trace_entry *entry = iter->ent;
1444 struct trace_seq *s = &iter->seq;
1445 struct bputs_entry *field;
1446
1447 trace_assign_type(field, entry);
1448
1449 if (!seq_print_ip_sym(s, field->ip, flags))
1450 goto partial;
1451
1452 if (!trace_seq_puts(s, ": "))
1453 goto partial;
1454
1455 if (!trace_seq_puts(s, field->str))
1456 goto partial;
1457
1458 return TRACE_TYPE_HANDLED;
1459
1460 partial:
1461 return TRACE_TYPE_PARTIAL_LINE;
1462 }
1463
1464
1465 static enum print_line_t
1466 trace_bputs_raw(struct trace_iterator *iter, int flags,
1467 struct trace_event *event)
1468 {
1469 struct bputs_entry *field;
1470 struct trace_seq *s = &iter->seq;
1471
1472 trace_assign_type(field, iter->ent);
1473
1474 if (!trace_seq_printf(s, ": %lx : ", field->ip))
1475 goto partial;
1476
1477 if (!trace_seq_puts(s, field->str))
1478 goto partial;
1479
1480 return TRACE_TYPE_HANDLED;
1481
1482 partial:
1483 return TRACE_TYPE_PARTIAL_LINE;
1484 }
1485
1486 static struct trace_event_functions trace_bputs_funcs = {
1487 .trace = trace_bputs_print,
1488 .raw = trace_bputs_raw,
1489 };
1490
1491 static struct trace_event trace_bputs_event = {
1492 .type = TRACE_BPUTS,
1493 .funcs = &trace_bputs_funcs,
1494 };
1495
1496 /* TRACE_BPRINT */
1497 static enum print_line_t
1498 trace_bprint_print(struct trace_iterator *iter, int flags,
1499 struct trace_event *event)
1500 {
1501 struct trace_entry *entry = iter->ent;
1502 struct trace_seq *s = &iter->seq;
1503 struct bprint_entry *field;
1504
1505 trace_assign_type(field, entry);
1506
1507 if (!seq_print_ip_sym(s, field->ip, flags))
1508 goto partial;
1509
1510 if (!trace_seq_puts(s, ": "))
1511 goto partial;
1512
1513 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1514 goto partial;
1515
1516 return TRACE_TYPE_HANDLED;
1517
1518 partial:
1519 return TRACE_TYPE_PARTIAL_LINE;
1520 }
1521
1522
1523 static enum print_line_t
1524 trace_bprint_raw(struct trace_iterator *iter, int flags,
1525 struct trace_event *event)
1526 {
1527 struct bprint_entry *field;
1528 struct trace_seq *s = &iter->seq;
1529
1530 trace_assign_type(field, iter->ent);
1531
1532 if (!trace_seq_printf(s, ": %lx : ", field->ip))
1533 goto partial;
1534
1535 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1536 goto partial;
1537
1538 return TRACE_TYPE_HANDLED;
1539
1540 partial:
1541 return TRACE_TYPE_PARTIAL_LINE;
1542 }
1543
1544 static struct trace_event_functions trace_bprint_funcs = {
1545 .trace = trace_bprint_print,
1546 .raw = trace_bprint_raw,
1547 };
1548
1549 static struct trace_event trace_bprint_event = {
1550 .type = TRACE_BPRINT,
1551 .funcs = &trace_bprint_funcs,
1552 };
1553
1554 /* TRACE_PRINT */
1555 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1556 int flags, struct trace_event *event)
1557 {
1558 struct print_entry *field;
1559 struct trace_seq *s = &iter->seq;
1560
1561 trace_assign_type(field, iter->ent);
1562
1563 if (!seq_print_ip_sym(s, field->ip, flags))
1564 goto partial;
1565
1566 if (!trace_seq_printf(s, ": %s", field->buf))
1567 goto partial;
1568
1569 return TRACE_TYPE_HANDLED;
1570
1571 partial:
1572 return TRACE_TYPE_PARTIAL_LINE;
1573 }
1574
1575 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1576 struct trace_event *event)
1577 {
1578 struct print_entry *field;
1579
1580 trace_assign_type(field, iter->ent);
1581
1582 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
1583 goto partial;
1584
1585 return TRACE_TYPE_HANDLED;
1586
1587 partial:
1588 return TRACE_TYPE_PARTIAL_LINE;
1589 }
1590
1591 static struct trace_event_functions trace_print_funcs = {
1592 .trace = trace_print_print,
1593 .raw = trace_print_raw,
1594 };
1595
1596 static struct trace_event trace_print_event = {
1597 .type = TRACE_PRINT,
1598 .funcs = &trace_print_funcs,
1599 };
1600
1601
1602 static struct trace_event *events[] __initdata = {
1603 &trace_fn_event,
1604 &trace_graph_ent_event,
1605 &trace_graph_ret_event,
1606 &trace_ctx_event,
1607 &trace_wake_event,
1608 &trace_stack_event,
1609 &trace_user_stack_event,
1610 &trace_bputs_event,
1611 &trace_bprint_event,
1612 &trace_print_event,
1613 NULL
1614 };
1615
1616 __init static int init_events(void)
1617 {
1618 struct trace_event *event;
1619 int i, ret;
1620
1621 for (i = 0; events[i]; i++) {
1622 event = events[i];
1623
1624 ret = register_ftrace_event(event);
1625 if (!ret) {
1626 printk(KERN_WARNING "event %d failed to register\n",
1627 event->type);
1628 WARN_ON_ONCE(1);
1629 }
1630 }
1631
1632 return 0;
1633 }
1634 early_initcall(init_events);
1635