4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
8 #include <linux/module.h>
9 #include <linux/mutex.h>
10 #include <linux/ftrace.h>
12 #include "trace_output.h"
14 /* must be a power of 2 */
15 #define EVENT_HASHSIZE 128
17 DECLARE_RWSEM(trace_event_sem
);
19 static struct hlist_head event_hash
[EVENT_HASHSIZE
] __read_mostly
;
21 static int next_event_type
= __TRACE_LAST_TYPE
+ 1;
23 int trace_print_seq(struct seq_file
*m
, struct trace_seq
*s
)
25 int len
= s
->len
>= PAGE_SIZE
? PAGE_SIZE
- 1 : s
->len
;
28 ret
= seq_write(m
, s
->buffer
, len
);
31 * Only reset this buffer if we successfully wrote to the
40 enum print_line_t
trace_print_bputs_msg_only(struct trace_iterator
*iter
)
42 struct trace_seq
*s
= &iter
->seq
;
43 struct trace_entry
*entry
= iter
->ent
;
44 struct bputs_entry
*field
;
47 trace_assign_type(field
, entry
);
49 ret
= trace_seq_puts(s
, field
->str
);
51 return TRACE_TYPE_PARTIAL_LINE
;
53 return TRACE_TYPE_HANDLED
;
56 enum print_line_t
trace_print_bprintk_msg_only(struct trace_iterator
*iter
)
58 struct trace_seq
*s
= &iter
->seq
;
59 struct trace_entry
*entry
= iter
->ent
;
60 struct bprint_entry
*field
;
63 trace_assign_type(field
, entry
);
65 ret
= trace_seq_bprintf(s
, field
->fmt
, field
->buf
);
67 return TRACE_TYPE_PARTIAL_LINE
;
69 return TRACE_TYPE_HANDLED
;
72 enum print_line_t
trace_print_printk_msg_only(struct trace_iterator
*iter
)
74 struct trace_seq
*s
= &iter
->seq
;
75 struct trace_entry
*entry
= iter
->ent
;
76 struct print_entry
*field
;
79 trace_assign_type(field
, entry
);
81 ret
= trace_seq_puts(s
, field
->buf
);
83 return TRACE_TYPE_PARTIAL_LINE
;
85 return TRACE_TYPE_HANDLED
;
89 * trace_seq_printf - sequence printing of trace information
90 * @s: trace sequence descriptor
91 * @fmt: printf format string
93 * It returns 0 if the trace oversizes the buffer's free
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.
103 trace_seq_printf(struct trace_seq
*s
, const char *fmt
, ...)
105 int len
= (PAGE_SIZE
- 1) - s
->len
;
113 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, ap
);
116 /* If we can't write it all, don't bother writing anything */
126 EXPORT_SYMBOL_GPL(trace_seq_printf
);
129 * trace_seq_vprintf - sequence printing of trace information
130 * @s: trace sequence descriptor
131 * @fmt: printf format string
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.
140 trace_seq_vprintf(struct trace_seq
*s
, const char *fmt
, va_list args
)
142 int len
= (PAGE_SIZE
- 1) - s
->len
;
148 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, args
);
150 /* If we can't write it all, don't bother writing anything */
160 EXPORT_SYMBOL_GPL(trace_seq_vprintf
);
162 int trace_seq_bprintf(struct trace_seq
*s
, const char *fmt
, const u32
*binary
)
164 int len
= (PAGE_SIZE
- 1) - s
->len
;
170 ret
= bstr_printf(s
->buffer
+ s
->len
, len
, fmt
, binary
);
172 /* If we can't write it all, don't bother writing anything */
184 * trace_seq_puts - trace sequence printing of simple string
185 * @s: trace sequence descriptor
186 * @str: simple string to record
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.
193 int trace_seq_puts(struct trace_seq
*s
, const char *str
)
195 int len
= strlen(str
);
200 if (len
> ((PAGE_SIZE
- 1) - s
->len
)) {
205 memcpy(s
->buffer
+ s
->len
, str
, len
);
211 int trace_seq_putc(struct trace_seq
*s
, unsigned char c
)
216 if (s
->len
>= (PAGE_SIZE
- 1)) {
221 s
->buffer
[s
->len
++] = c
;
225 EXPORT_SYMBOL(trace_seq_putc
);
227 int trace_seq_putmem(struct trace_seq
*s
, const void *mem
, size_t len
)
232 if (len
> ((PAGE_SIZE
- 1) - s
->len
)) {
237 memcpy(s
->buffer
+ s
->len
, mem
, len
);
243 int trace_seq_putmem_hex(struct trace_seq
*s
, const void *mem
, size_t len
)
245 unsigned char hex
[HEX_CHARS
];
246 const unsigned char *data
= mem
;
253 for (i
= 0, j
= 0; i
< len
; i
++) {
255 for (i
= len
-1, j
= 0; i
>= 0; i
--) {
257 hex
[j
++] = hex_asc_hi(data
[i
]);
258 hex
[j
++] = hex_asc_lo(data
[i
]);
262 return trace_seq_putmem(s
, hex
, j
);
265 void *trace_seq_reserve(struct trace_seq
*s
, size_t len
)
272 if (len
> ((PAGE_SIZE
- 1) - s
->len
)) {
277 ret
= s
->buffer
+ s
->len
;
283 int trace_seq_path(struct trace_seq
*s
, const struct path
*path
)
290 if (s
->len
>= (PAGE_SIZE
- 1)) {
295 p
= d_path(path
, s
->buffer
+ s
->len
, PAGE_SIZE
- s
->len
);
297 p
= mangle_path(s
->buffer
+ s
->len
, p
, "\n");
299 s
->len
= p
- s
->buffer
;
303 s
->buffer
[s
->len
++] = '?';
312 ftrace_print_flags_seq(struct trace_seq
*p
, const char *delim
,
314 const struct trace_print_flags
*flag_array
)
318 const char *ret
= p
->buffer
+ p
->len
;
321 for (i
= 0; flag_array
[i
].name
&& flags
; i
++) {
323 mask
= flag_array
[i
].mask
;
324 if ((flags
& mask
) != mask
)
327 str
= flag_array
[i
].name
;
330 trace_seq_puts(p
, delim
);
333 trace_seq_puts(p
, str
);
336 /* check for left over flags */
339 trace_seq_puts(p
, delim
);
340 trace_seq_printf(p
, "0x%lx", flags
);
343 trace_seq_putc(p
, 0);
347 EXPORT_SYMBOL(ftrace_print_flags_seq
);
350 ftrace_print_symbols_seq(struct trace_seq
*p
, unsigned long val
,
351 const struct trace_print_flags
*symbol_array
)
354 const char *ret
= p
->buffer
+ p
->len
;
356 for (i
= 0; symbol_array
[i
].name
; i
++) {
358 if (val
!= symbol_array
[i
].mask
)
361 trace_seq_puts(p
, symbol_array
[i
].name
);
365 if (ret
== (const char *)(p
->buffer
+ p
->len
))
366 trace_seq_printf(p
, "0x%lx", val
);
368 trace_seq_putc(p
, 0);
372 EXPORT_SYMBOL(ftrace_print_symbols_seq
);
374 #if BITS_PER_LONG == 32
376 ftrace_print_symbols_seq_u64(struct trace_seq
*p
, unsigned long long val
,
377 const struct trace_print_flags_u64
*symbol_array
)
380 const char *ret
= p
->buffer
+ p
->len
;
382 for (i
= 0; symbol_array
[i
].name
; i
++) {
384 if (val
!= symbol_array
[i
].mask
)
387 trace_seq_puts(p
, symbol_array
[i
].name
);
391 if (ret
== (const char *)(p
->buffer
+ p
->len
))
392 trace_seq_printf(p
, "0x%llx", val
);
394 trace_seq_putc(p
, 0);
398 EXPORT_SYMBOL(ftrace_print_symbols_seq_u64
);
402 ftrace_print_hex_seq(struct trace_seq
*p
, const unsigned char *buf
, int buf_len
)
405 const char *ret
= p
->buffer
+ p
->len
;
407 for (i
= 0; i
< buf_len
; i
++)
408 trace_seq_printf(p
, "%s%2.2x", i
== 0 ? "" : " ", buf
[i
]);
410 trace_seq_putc(p
, 0);
414 EXPORT_SYMBOL(ftrace_print_hex_seq
);
416 int ftrace_raw_output_prep(struct trace_iterator
*iter
,
417 struct trace_event
*trace_event
)
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
;
425 event
= container_of(trace_event
, struct ftrace_event_call
, event
);
428 if (entry
->type
!= event
->event
.type
) {
430 return TRACE_TYPE_UNHANDLED
;
434 ret
= trace_seq_printf(s
, "%s: ", event
->name
);
436 return TRACE_TYPE_PARTIAL_LINE
;
440 EXPORT_SYMBOL(ftrace_raw_output_prep
);
442 #ifdef CONFIG_KRETPROBES
443 static inline const char *kretprobed(const char *name
)
445 static const char tramp_name
[] = "kretprobe_trampoline";
446 int size
= sizeof(tramp_name
);
448 if (strncmp(tramp_name
, name
, size
) == 0)
449 return "[unknown/kretprobe'd]";
453 static inline const char *kretprobed(const char *name
)
457 #endif /* CONFIG_KRETPROBES */
460 seq_print_sym_short(struct trace_seq
*s
, const char *fmt
, unsigned long address
)
462 #ifdef CONFIG_KALLSYMS
463 char str
[KSYM_SYMBOL_LEN
];
466 kallsyms_lookup(address
, NULL
, NULL
, NULL
, str
);
468 name
= kretprobed(str
);
470 return trace_seq_printf(s
, fmt
, name
);
476 seq_print_sym_offset(struct trace_seq
*s
, const char *fmt
,
477 unsigned long address
)
479 #ifdef CONFIG_KALLSYMS
480 char str
[KSYM_SYMBOL_LEN
];
483 sprint_symbol(str
, address
);
484 name
= kretprobed(str
);
486 return trace_seq_printf(s
, fmt
, name
);
492 # define IP_FMT "%08lx"
494 # define IP_FMT "%016lx"
497 int seq_print_user_ip(struct trace_seq
*s
, struct mm_struct
*mm
,
498 unsigned long ip
, unsigned long sym_flags
)
500 struct file
*file
= NULL
;
501 unsigned long vmstart
= 0;
508 const struct vm_area_struct
*vma
;
510 down_read(&mm
->mmap_sem
);
511 vma
= find_vma(mm
, ip
);
514 vmstart
= vma
->vm_start
;
517 ret
= trace_seq_path(s
, &file
->f_path
);
519 ret
= trace_seq_printf(s
, "[+0x%lx]",
522 up_read(&mm
->mmap_sem
);
524 if (ret
&& ((sym_flags
& TRACE_ITER_SYM_ADDR
) || !file
))
525 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
530 seq_print_userip_objs(const struct userstack_entry
*entry
, struct trace_seq
*s
,
531 unsigned long sym_flags
)
533 struct mm_struct
*mm
= NULL
;
537 if (trace_flags
& TRACE_ITER_SYM_USEROBJ
) {
538 struct task_struct
*task
;
540 * we do the lookup on the thread group leader,
541 * since individual threads might have already quit!
544 task
= find_task_by_vpid(entry
->tgid
);
546 mm
= get_task_mm(task
);
550 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
551 unsigned long ip
= entry
->caller
[i
];
553 if (ip
== ULONG_MAX
|| !ret
)
556 ret
= trace_seq_puts(s
, " => ");
559 ret
= trace_seq_puts(s
, "??");
561 ret
= trace_seq_putc(s
, '\n');
567 ret
= seq_print_user_ip(s
, mm
, ip
, sym_flags
);
568 ret
= trace_seq_putc(s
, '\n');
577 seq_print_ip_sym(struct trace_seq
*s
, unsigned long ip
, unsigned long sym_flags
)
582 return trace_seq_putc(s
, '0');
584 if (sym_flags
& TRACE_ITER_SYM_OFFSET
)
585 ret
= seq_print_sym_offset(s
, "%s", ip
);
587 ret
= seq_print_sym_short(s
, "%s", ip
);
592 if (sym_flags
& TRACE_ITER_SYM_ADDR
)
593 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
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
602 * Prints the generic fields of irqs off, in hard or softirq, preempt
605 int trace_print_lat_fmt(struct trace_seq
*s
, struct trace_entry
*entry
)
614 hardirq
= entry
->flags
& TRACE_FLAG_HARDIRQ
;
615 softirq
= entry
->flags
& TRACE_FLAG_SOFTIRQ
;
618 (entry
->flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' :
619 (entry
->flags
& TRACE_FLAG_IRQS_NOSUPPORT
) ? 'X' :
622 (entry
->flags
& TRACE_FLAG_NEED_RESCHED
) ? 'N' : '.';
624 (hardirq
&& softirq
) ? 'H' :
629 if (!trace_seq_printf(s
, "%c%c%c",
630 irqs_off
, need_resched
, hardsoft_irq
))
633 if (entry
->preempt_count
)
634 ret
= trace_seq_printf(s
, "%x", entry
->preempt_count
);
636 ret
= trace_seq_putc(s
, '.');
642 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
644 char comm
[TASK_COMM_LEN
];
646 trace_find_cmdline(entry
->pid
, comm
);
648 if (!trace_seq_printf(s
, "%8.8s-%-5d %3d",
649 comm
, entry
->pid
, cpu
))
652 return trace_print_lat_fmt(s
, entry
);
655 static unsigned long preempt_mark_thresh_us
= 100;
658 lat_print_timestamp(struct trace_iterator
*iter
, u64 next_ts
)
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
;
667 abs_ts
= ns2usecs(abs_ts
);
668 rel_ts
= ns2usecs(rel_ts
);
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
;
677 return trace_seq_printf(
678 s
, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
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(
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
);
697 int trace_print_context(struct trace_iterator
*iter
)
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
];
706 trace_find_cmdline(entry
->pid
, comm
);
708 ret
= trace_seq_printf(s
, "%16s-%-5d [%03d] ",
709 comm
, entry
->pid
, iter
->cpu
);
713 if (trace_flags
& TRACE_ITER_IRQ_INFO
) {
714 ret
= trace_print_lat_fmt(s
, entry
);
719 if (iter
->iter_flags
& TRACE_FILE_TIME_IN_NS
) {
720 t
= ns2usecs(iter
->ts
);
721 usec_rem
= do_div(t
, USEC_PER_SEC
);
722 secs
= (unsigned long)t
;
723 return trace_seq_printf(s
, " %5lu.%06lu: ", secs
, usec_rem
);
725 return trace_seq_printf(s
, " %12llu: ", iter
->ts
);
728 int trace_print_lat_context(struct trace_iterator
*iter
)
732 /* trace_find_next_entry will reset ent_size */
733 int ent_size
= iter
->ent_size
;
734 struct trace_seq
*s
= &iter
->seq
;
735 struct trace_entry
*entry
= iter
->ent
,
736 *next_entry
= trace_find_next_entry(iter
, NULL
,
738 unsigned long verbose
= (trace_flags
& TRACE_ITER_VERBOSE
);
740 /* Restore the original ent_size */
741 iter
->ent_size
= ent_size
;
747 char comm
[TASK_COMM_LEN
];
749 trace_find_cmdline(entry
->pid
, comm
);
751 ret
= trace_seq_printf(
752 s
, "%16s %5d %3d %d %08x %08lx ",
753 comm
, entry
->pid
, iter
->cpu
, entry
->flags
,
754 entry
->preempt_count
, iter
->idx
);
756 ret
= lat_print_generic(s
, entry
, iter
->cpu
);
760 ret
= lat_print_timestamp(iter
, next_ts
);
765 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
767 static int task_state_char(unsigned long state
)
769 int bit
= state
? __ffs(state
) + 1 : 0;
771 return bit
< sizeof(state_to_char
) - 1 ? state_to_char
[bit
] : '?';
775 * ftrace_find_event - find a registered event
776 * @type: the type of event to look for
778 * Returns an event of type @type otherwise NULL
779 * Called with trace_event_read_lock() held.
781 struct trace_event
*ftrace_find_event(int type
)
783 struct trace_event
*event
;
786 key
= type
& (EVENT_HASHSIZE
- 1);
788 hlist_for_each_entry(event
, &event_hash
[key
], node
) {
789 if (event
->type
== type
)
796 static LIST_HEAD(ftrace_event_list
);
798 static int trace_search_list(struct list_head
**list
)
800 struct trace_event
*e
;
801 int last
= __TRACE_LAST_TYPE
;
803 if (list_empty(&ftrace_event_list
)) {
804 *list
= &ftrace_event_list
;
809 * We used up all possible max events,
810 * lets see if somebody freed one.
812 list_for_each_entry(e
, &ftrace_event_list
, list
) {
813 if (e
->type
!= last
+ 1)
818 /* Did we used up all 65 thousand events??? */
819 if ((last
+ 1) > FTRACE_MAX_EVENT
)
826 void trace_event_read_lock(void)
828 down_read(&trace_event_sem
);
831 void trace_event_read_unlock(void)
833 up_read(&trace_event_sem
);
837 * register_ftrace_event - register output for an event type
838 * @event: the event type to register
840 * Event types are stored in a hash and this hash is used to
841 * find a way to print an event. If the @event->type is set
842 * then it will use that type, otherwise it will assign a
845 * If you assign your own type, please make sure it is added
846 * to the trace_type enum in trace.h, to avoid collisions
847 * with the dynamic types.
849 * Returns the event type number or zero on error.
851 int register_ftrace_event(struct trace_event
*event
)
856 down_write(&trace_event_sem
);
861 if (WARN_ON(!event
->funcs
))
864 INIT_LIST_HEAD(&event
->list
);
867 struct list_head
*list
= NULL
;
869 if (next_event_type
> FTRACE_MAX_EVENT
) {
871 event
->type
= trace_search_list(&list
);
877 event
->type
= next_event_type
++;
878 list
= &ftrace_event_list
;
881 if (WARN_ON(ftrace_find_event(event
->type
)))
884 list_add_tail(&event
->list
, list
);
886 } else if (event
->type
> __TRACE_LAST_TYPE
) {
887 printk(KERN_WARNING
"Need to add type to trace.h\n");
891 /* Is this event already used */
892 if (ftrace_find_event(event
->type
))
896 if (event
->funcs
->trace
== NULL
)
897 event
->funcs
->trace
= trace_nop_print
;
898 if (event
->funcs
->raw
== NULL
)
899 event
->funcs
->raw
= trace_nop_print
;
900 if (event
->funcs
->hex
== NULL
)
901 event
->funcs
->hex
= trace_nop_print
;
902 if (event
->funcs
->binary
== NULL
)
903 event
->funcs
->binary
= trace_nop_print
;
905 key
= event
->type
& (EVENT_HASHSIZE
- 1);
907 hlist_add_head(&event
->node
, &event_hash
[key
]);
911 up_write(&trace_event_sem
);
915 EXPORT_SYMBOL_GPL(register_ftrace_event
);
918 * Used by module code with the trace_event_sem held for write.
920 int __unregister_ftrace_event(struct trace_event
*event
)
922 hlist_del(&event
->node
);
923 list_del(&event
->list
);
928 * unregister_ftrace_event - remove a no longer used event
929 * @event: the event to remove
931 int unregister_ftrace_event(struct trace_event
*event
)
933 down_write(&trace_event_sem
);
934 __unregister_ftrace_event(event
);
935 up_write(&trace_event_sem
);
939 EXPORT_SYMBOL_GPL(unregister_ftrace_event
);
945 enum print_line_t
trace_nop_print(struct trace_iterator
*iter
, int flags
,
946 struct trace_event
*event
)
948 if (!trace_seq_printf(&iter
->seq
, "type: %d\n", iter
->ent
->type
))
949 return TRACE_TYPE_PARTIAL_LINE
;
951 return TRACE_TYPE_HANDLED
;
955 static enum print_line_t
trace_fn_trace(struct trace_iterator
*iter
, int flags
,
956 struct trace_event
*event
)
958 struct ftrace_entry
*field
;
959 struct trace_seq
*s
= &iter
->seq
;
961 trace_assign_type(field
, iter
->ent
);
963 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
966 if ((flags
& TRACE_ITER_PRINT_PARENT
) && field
->parent_ip
) {
967 if (!trace_seq_puts(s
, " <-"))
969 if (!seq_print_ip_sym(s
,
974 if (!trace_seq_putc(s
, '\n'))
977 return TRACE_TYPE_HANDLED
;
980 return TRACE_TYPE_PARTIAL_LINE
;
983 static enum print_line_t
trace_fn_raw(struct trace_iterator
*iter
, int flags
,
984 struct trace_event
*event
)
986 struct ftrace_entry
*field
;
988 trace_assign_type(field
, iter
->ent
);
990 if (!trace_seq_printf(&iter
->seq
, "%lx %lx\n",
993 return TRACE_TYPE_PARTIAL_LINE
;
995 return TRACE_TYPE_HANDLED
;
998 static enum print_line_t
trace_fn_hex(struct trace_iterator
*iter
, int flags
,
999 struct trace_event
*event
)
1001 struct ftrace_entry
*field
;
1002 struct trace_seq
*s
= &iter
->seq
;
1004 trace_assign_type(field
, iter
->ent
);
1006 SEQ_PUT_HEX_FIELD_RET(s
, field
->ip
);
1007 SEQ_PUT_HEX_FIELD_RET(s
, field
->parent_ip
);
1009 return TRACE_TYPE_HANDLED
;
1012 static enum print_line_t
trace_fn_bin(struct trace_iterator
*iter
, int flags
,
1013 struct trace_event
*event
)
1015 struct ftrace_entry
*field
;
1016 struct trace_seq
*s
= &iter
->seq
;
1018 trace_assign_type(field
, iter
->ent
);
1020 SEQ_PUT_FIELD_RET(s
, field
->ip
);
1021 SEQ_PUT_FIELD_RET(s
, field
->parent_ip
);
1023 return TRACE_TYPE_HANDLED
;
1026 static struct trace_event_functions trace_fn_funcs
= {
1027 .trace
= trace_fn_trace
,
1028 .raw
= trace_fn_raw
,
1029 .hex
= trace_fn_hex
,
1030 .binary
= trace_fn_bin
,
1033 static struct trace_event trace_fn_event
= {
1035 .funcs
= &trace_fn_funcs
,
1038 /* TRACE_CTX an TRACE_WAKE */
1039 static enum print_line_t
trace_ctxwake_print(struct trace_iterator
*iter
,
1042 struct ctx_switch_entry
*field
;
1043 char comm
[TASK_COMM_LEN
];
1047 trace_assign_type(field
, iter
->ent
);
1049 T
= task_state_char(field
->next_state
);
1050 S
= task_state_char(field
->prev_state
);
1051 trace_find_cmdline(field
->next_pid
, comm
);
1052 if (!trace_seq_printf(&iter
->seq
,
1053 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
1061 return TRACE_TYPE_PARTIAL_LINE
;
1063 return TRACE_TYPE_HANDLED
;
1066 static enum print_line_t
trace_ctx_print(struct trace_iterator
*iter
, int flags
,
1067 struct trace_event
*event
)
1069 return trace_ctxwake_print(iter
, "==>");
1072 static enum print_line_t
trace_wake_print(struct trace_iterator
*iter
,
1073 int flags
, struct trace_event
*event
)
1075 return trace_ctxwake_print(iter
, " +");
1078 static int trace_ctxwake_raw(struct trace_iterator
*iter
, char S
)
1080 struct ctx_switch_entry
*field
;
1083 trace_assign_type(field
, iter
->ent
);
1086 S
= task_state_char(field
->prev_state
);
1087 T
= task_state_char(field
->next_state
);
1088 if (!trace_seq_printf(&iter
->seq
, "%d %d %c %d %d %d %c\n",
1096 return TRACE_TYPE_PARTIAL_LINE
;
1098 return TRACE_TYPE_HANDLED
;
1101 static enum print_line_t
trace_ctx_raw(struct trace_iterator
*iter
, int flags
,
1102 struct trace_event
*event
)
1104 return trace_ctxwake_raw(iter
, 0);
1107 static enum print_line_t
trace_wake_raw(struct trace_iterator
*iter
, int flags
,
1108 struct trace_event
*event
)
1110 return trace_ctxwake_raw(iter
, '+');
1114 static int trace_ctxwake_hex(struct trace_iterator
*iter
, char S
)
1116 struct ctx_switch_entry
*field
;
1117 struct trace_seq
*s
= &iter
->seq
;
1120 trace_assign_type(field
, iter
->ent
);
1123 S
= task_state_char(field
->prev_state
);
1124 T
= task_state_char(field
->next_state
);
1126 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_pid
);
1127 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_prio
);
1128 SEQ_PUT_HEX_FIELD_RET(s
, S
);
1129 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_cpu
);
1130 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_pid
);
1131 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_prio
);
1132 SEQ_PUT_HEX_FIELD_RET(s
, T
);
1134 return TRACE_TYPE_HANDLED
;
1137 static enum print_line_t
trace_ctx_hex(struct trace_iterator
*iter
, int flags
,
1138 struct trace_event
*event
)
1140 return trace_ctxwake_hex(iter
, 0);
1143 static enum print_line_t
trace_wake_hex(struct trace_iterator
*iter
, int flags
,
1144 struct trace_event
*event
)
1146 return trace_ctxwake_hex(iter
, '+');
1149 static enum print_line_t
trace_ctxwake_bin(struct trace_iterator
*iter
,
1150 int flags
, struct trace_event
*event
)
1152 struct ctx_switch_entry
*field
;
1153 struct trace_seq
*s
= &iter
->seq
;
1155 trace_assign_type(field
, iter
->ent
);
1157 SEQ_PUT_FIELD_RET(s
, field
->prev_pid
);
1158 SEQ_PUT_FIELD_RET(s
, field
->prev_prio
);
1159 SEQ_PUT_FIELD_RET(s
, field
->prev_state
);
1160 SEQ_PUT_FIELD_RET(s
, field
->next_pid
);
1161 SEQ_PUT_FIELD_RET(s
, field
->next_prio
);
1162 SEQ_PUT_FIELD_RET(s
, field
->next_state
);
1164 return TRACE_TYPE_HANDLED
;
1167 static struct trace_event_functions trace_ctx_funcs
= {
1168 .trace
= trace_ctx_print
,
1169 .raw
= trace_ctx_raw
,
1170 .hex
= trace_ctx_hex
,
1171 .binary
= trace_ctxwake_bin
,
1174 static struct trace_event trace_ctx_event
= {
1176 .funcs
= &trace_ctx_funcs
,
1179 static struct trace_event_functions trace_wake_funcs
= {
1180 .trace
= trace_wake_print
,
1181 .raw
= trace_wake_raw
,
1182 .hex
= trace_wake_hex
,
1183 .binary
= trace_ctxwake_bin
,
1186 static struct trace_event trace_wake_event
= {
1188 .funcs
= &trace_wake_funcs
,
1193 static enum print_line_t
trace_stack_print(struct trace_iterator
*iter
,
1194 int flags
, struct trace_event
*event
)
1196 struct stack_entry
*field
;
1197 struct trace_seq
*s
= &iter
->seq
;
1201 trace_assign_type(field
, iter
->ent
);
1202 end
= (unsigned long *)((long)iter
->ent
+ iter
->ent_size
);
1204 if (!trace_seq_puts(s
, "<stack trace>\n"))
1207 for (p
= field
->caller
; p
&& *p
!= ULONG_MAX
&& p
< end
; p
++) {
1208 if (!trace_seq_puts(s
, " => "))
1211 if (!seq_print_ip_sym(s
, *p
, flags
))
1213 if (!trace_seq_putc(s
, '\n'))
1217 return TRACE_TYPE_HANDLED
;
1220 return TRACE_TYPE_PARTIAL_LINE
;
1223 static struct trace_event_functions trace_stack_funcs
= {
1224 .trace
= trace_stack_print
,
1227 static struct trace_event trace_stack_event
= {
1228 .type
= TRACE_STACK
,
1229 .funcs
= &trace_stack_funcs
,
1232 /* TRACE_USER_STACK */
1233 static enum print_line_t
trace_user_stack_print(struct trace_iterator
*iter
,
1234 int flags
, struct trace_event
*event
)
1236 struct userstack_entry
*field
;
1237 struct trace_seq
*s
= &iter
->seq
;
1239 trace_assign_type(field
, iter
->ent
);
1241 if (!trace_seq_puts(s
, "<user stack trace>\n"))
1244 if (!seq_print_userip_objs(field
, s
, flags
))
1247 return TRACE_TYPE_HANDLED
;
1250 return TRACE_TYPE_PARTIAL_LINE
;
1253 static struct trace_event_functions trace_user_stack_funcs
= {
1254 .trace
= trace_user_stack_print
,
1257 static struct trace_event trace_user_stack_event
= {
1258 .type
= TRACE_USER_STACK
,
1259 .funcs
= &trace_user_stack_funcs
,
1263 static enum print_line_t
1264 trace_bputs_print(struct trace_iterator
*iter
, int flags
,
1265 struct trace_event
*event
)
1267 struct trace_entry
*entry
= iter
->ent
;
1268 struct trace_seq
*s
= &iter
->seq
;
1269 struct bputs_entry
*field
;
1271 trace_assign_type(field
, entry
);
1273 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1276 if (!trace_seq_puts(s
, ": "))
1279 if (!trace_seq_puts(s
, field
->str
))
1282 return TRACE_TYPE_HANDLED
;
1285 return TRACE_TYPE_PARTIAL_LINE
;
1289 static enum print_line_t
1290 trace_bputs_raw(struct trace_iterator
*iter
, int flags
,
1291 struct trace_event
*event
)
1293 struct bputs_entry
*field
;
1294 struct trace_seq
*s
= &iter
->seq
;
1296 trace_assign_type(field
, iter
->ent
);
1298 if (!trace_seq_printf(s
, ": %lx : ", field
->ip
))
1301 if (!trace_seq_puts(s
, field
->str
))
1304 return TRACE_TYPE_HANDLED
;
1307 return TRACE_TYPE_PARTIAL_LINE
;
1310 static struct trace_event_functions trace_bputs_funcs
= {
1311 .trace
= trace_bputs_print
,
1312 .raw
= trace_bputs_raw
,
1315 static struct trace_event trace_bputs_event
= {
1316 .type
= TRACE_BPUTS
,
1317 .funcs
= &trace_bputs_funcs
,
1321 static enum print_line_t
1322 trace_bprint_print(struct trace_iterator
*iter
, int flags
,
1323 struct trace_event
*event
)
1325 struct trace_entry
*entry
= iter
->ent
;
1326 struct trace_seq
*s
= &iter
->seq
;
1327 struct bprint_entry
*field
;
1329 trace_assign_type(field
, entry
);
1331 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1334 if (!trace_seq_puts(s
, ": "))
1337 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1340 return TRACE_TYPE_HANDLED
;
1343 return TRACE_TYPE_PARTIAL_LINE
;
1347 static enum print_line_t
1348 trace_bprint_raw(struct trace_iterator
*iter
, int flags
,
1349 struct trace_event
*event
)
1351 struct bprint_entry
*field
;
1352 struct trace_seq
*s
= &iter
->seq
;
1354 trace_assign_type(field
, iter
->ent
);
1356 if (!trace_seq_printf(s
, ": %lx : ", field
->ip
))
1359 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1362 return TRACE_TYPE_HANDLED
;
1365 return TRACE_TYPE_PARTIAL_LINE
;
1368 static struct trace_event_functions trace_bprint_funcs
= {
1369 .trace
= trace_bprint_print
,
1370 .raw
= trace_bprint_raw
,
1373 static struct trace_event trace_bprint_event
= {
1374 .type
= TRACE_BPRINT
,
1375 .funcs
= &trace_bprint_funcs
,
1379 static enum print_line_t
trace_print_print(struct trace_iterator
*iter
,
1380 int flags
, struct trace_event
*event
)
1382 struct print_entry
*field
;
1383 struct trace_seq
*s
= &iter
->seq
;
1385 trace_assign_type(field
, iter
->ent
);
1387 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1390 if (!trace_seq_printf(s
, ": %s", field
->buf
))
1393 return TRACE_TYPE_HANDLED
;
1396 return TRACE_TYPE_PARTIAL_LINE
;
1399 static enum print_line_t
trace_print_raw(struct trace_iterator
*iter
, int flags
,
1400 struct trace_event
*event
)
1402 struct print_entry
*field
;
1404 trace_assign_type(field
, iter
->ent
);
1406 if (!trace_seq_printf(&iter
->seq
, "# %lx %s", field
->ip
, field
->buf
))
1409 return TRACE_TYPE_HANDLED
;
1412 return TRACE_TYPE_PARTIAL_LINE
;
1415 static struct trace_event_functions trace_print_funcs
= {
1416 .trace
= trace_print_print
,
1417 .raw
= trace_print_raw
,
1420 static struct trace_event trace_print_event
= {
1421 .type
= TRACE_PRINT
,
1422 .funcs
= &trace_print_funcs
,
1426 static struct trace_event
*events
[] __initdata
= {
1431 &trace_user_stack_event
,
1433 &trace_bprint_event
,
1438 __init
static int init_events(void)
1440 struct trace_event
*event
;
1443 for (i
= 0; events
[i
]; i
++) {
1446 ret
= register_ftrace_event(event
);
1448 printk(KERN_WARNING
"event %d failed to register\n",
1456 early_initcall(init_events
);