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 switch (entry
->flags
& (TRACE_FLAG_NEED_RESCHED
|
623 TRACE_FLAG_PREEMPT_RESCHED
)) {
624 case TRACE_FLAG_NEED_RESCHED
| TRACE_FLAG_PREEMPT_RESCHED
:
627 case TRACE_FLAG_NEED_RESCHED
:
630 case TRACE_FLAG_PREEMPT_RESCHED
:
639 (hardirq
&& softirq
) ? 'H' :
644 if (!trace_seq_printf(s
, "%c%c%c",
645 irqs_off
, need_resched
, hardsoft_irq
))
648 if (entry
->preempt_count
)
649 ret
= trace_seq_printf(s
, "%x", entry
->preempt_count
);
651 ret
= trace_seq_putc(s
, '.');
657 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
659 char comm
[TASK_COMM_LEN
];
661 trace_find_cmdline(entry
->pid
, comm
);
663 if (!trace_seq_printf(s
, "%8.8s-%-5d %3d",
664 comm
, entry
->pid
, cpu
))
667 return trace_print_lat_fmt(s
, entry
);
670 static unsigned long preempt_mark_thresh_us
= 100;
673 lat_print_timestamp(struct trace_iterator
*iter
, u64 next_ts
)
675 unsigned long verbose
= trace_flags
& TRACE_ITER_VERBOSE
;
676 unsigned long in_ns
= iter
->iter_flags
& TRACE_FILE_TIME_IN_NS
;
677 unsigned long long abs_ts
= iter
->ts
- iter
->trace_buffer
->time_start
;
678 unsigned long long rel_ts
= next_ts
- iter
->ts
;
679 struct trace_seq
*s
= &iter
->seq
;
682 abs_ts
= ns2usecs(abs_ts
);
683 rel_ts
= ns2usecs(rel_ts
);
686 if (verbose
&& in_ns
) {
687 unsigned long abs_usec
= do_div(abs_ts
, USEC_PER_MSEC
);
688 unsigned long abs_msec
= (unsigned long)abs_ts
;
689 unsigned long rel_usec
= do_div(rel_ts
, USEC_PER_MSEC
);
690 unsigned long rel_msec
= (unsigned long)rel_ts
;
692 return trace_seq_printf(
693 s
, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
697 } else if (verbose
&& !in_ns
) {
698 return trace_seq_printf(
699 s
, "[%016llx] %lld (+%lld): ",
700 iter
->ts
, abs_ts
, rel_ts
);
701 } else if (!verbose
&& in_ns
) {
702 return trace_seq_printf(
705 rel_ts
> preempt_mark_thresh_us
? '!' :
706 rel_ts
> 1 ? '+' : ' ');
707 } else { /* !verbose && !in_ns */
708 return trace_seq_printf(s
, " %4lld: ", abs_ts
);
712 int trace_print_context(struct trace_iterator
*iter
)
714 struct trace_seq
*s
= &iter
->seq
;
715 struct trace_entry
*entry
= iter
->ent
;
716 unsigned long long t
;
717 unsigned long secs
, usec_rem
;
718 char comm
[TASK_COMM_LEN
];
721 trace_find_cmdline(entry
->pid
, comm
);
723 ret
= trace_seq_printf(s
, "%16s-%-5d [%03d] ",
724 comm
, entry
->pid
, iter
->cpu
);
728 if (trace_flags
& TRACE_ITER_IRQ_INFO
) {
729 ret
= trace_print_lat_fmt(s
, entry
);
734 if (iter
->iter_flags
& TRACE_FILE_TIME_IN_NS
) {
735 t
= ns2usecs(iter
->ts
);
736 usec_rem
= do_div(t
, USEC_PER_SEC
);
737 secs
= (unsigned long)t
;
738 return trace_seq_printf(s
, " %5lu.%06lu: ", secs
, usec_rem
);
740 return trace_seq_printf(s
, " %12llu: ", iter
->ts
);
743 int trace_print_lat_context(struct trace_iterator
*iter
)
747 /* trace_find_next_entry will reset ent_size */
748 int ent_size
= iter
->ent_size
;
749 struct trace_seq
*s
= &iter
->seq
;
750 struct trace_entry
*entry
= iter
->ent
,
751 *next_entry
= trace_find_next_entry(iter
, NULL
,
753 unsigned long verbose
= (trace_flags
& TRACE_ITER_VERBOSE
);
755 /* Restore the original ent_size */
756 iter
->ent_size
= ent_size
;
762 char comm
[TASK_COMM_LEN
];
764 trace_find_cmdline(entry
->pid
, comm
);
766 ret
= trace_seq_printf(
767 s
, "%16s %5d %3d %d %08x %08lx ",
768 comm
, entry
->pid
, iter
->cpu
, entry
->flags
,
769 entry
->preempt_count
, iter
->idx
);
771 ret
= lat_print_generic(s
, entry
, iter
->cpu
);
775 ret
= lat_print_timestamp(iter
, next_ts
);
780 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
782 static int task_state_char(unsigned long state
)
784 int bit
= state
? __ffs(state
) + 1 : 0;
786 return bit
< sizeof(state_to_char
) - 1 ? state_to_char
[bit
] : '?';
790 * ftrace_find_event - find a registered event
791 * @type: the type of event to look for
793 * Returns an event of type @type otherwise NULL
794 * Called with trace_event_read_lock() held.
796 struct trace_event
*ftrace_find_event(int type
)
798 struct trace_event
*event
;
801 key
= type
& (EVENT_HASHSIZE
- 1);
803 hlist_for_each_entry(event
, &event_hash
[key
], node
) {
804 if (event
->type
== type
)
811 static LIST_HEAD(ftrace_event_list
);
813 static int trace_search_list(struct list_head
**list
)
815 struct trace_event
*e
;
816 int last
= __TRACE_LAST_TYPE
;
818 if (list_empty(&ftrace_event_list
)) {
819 *list
= &ftrace_event_list
;
824 * We used up all possible max events,
825 * lets see if somebody freed one.
827 list_for_each_entry(e
, &ftrace_event_list
, list
) {
828 if (e
->type
!= last
+ 1)
833 /* Did we used up all 65 thousand events??? */
834 if ((last
+ 1) > FTRACE_MAX_EVENT
)
841 void trace_event_read_lock(void)
843 down_read(&trace_event_sem
);
846 void trace_event_read_unlock(void)
848 up_read(&trace_event_sem
);
852 * register_ftrace_event - register output for an event type
853 * @event: the event type to register
855 * Event types are stored in a hash and this hash is used to
856 * find a way to print an event. If the @event->type is set
857 * then it will use that type, otherwise it will assign a
860 * If you assign your own type, please make sure it is added
861 * to the trace_type enum in trace.h, to avoid collisions
862 * with the dynamic types.
864 * Returns the event type number or zero on error.
866 int register_ftrace_event(struct trace_event
*event
)
871 down_write(&trace_event_sem
);
876 if (WARN_ON(!event
->funcs
))
879 INIT_LIST_HEAD(&event
->list
);
882 struct list_head
*list
= NULL
;
884 if (next_event_type
> FTRACE_MAX_EVENT
) {
886 event
->type
= trace_search_list(&list
);
892 event
->type
= next_event_type
++;
893 list
= &ftrace_event_list
;
896 if (WARN_ON(ftrace_find_event(event
->type
)))
899 list_add_tail(&event
->list
, list
);
901 } else if (event
->type
> __TRACE_LAST_TYPE
) {
902 printk(KERN_WARNING
"Need to add type to trace.h\n");
906 /* Is this event already used */
907 if (ftrace_find_event(event
->type
))
911 if (event
->funcs
->trace
== NULL
)
912 event
->funcs
->trace
= trace_nop_print
;
913 if (event
->funcs
->raw
== NULL
)
914 event
->funcs
->raw
= trace_nop_print
;
915 if (event
->funcs
->hex
== NULL
)
916 event
->funcs
->hex
= trace_nop_print
;
917 if (event
->funcs
->binary
== NULL
)
918 event
->funcs
->binary
= trace_nop_print
;
920 key
= event
->type
& (EVENT_HASHSIZE
- 1);
922 hlist_add_head(&event
->node
, &event_hash
[key
]);
926 up_write(&trace_event_sem
);
930 EXPORT_SYMBOL_GPL(register_ftrace_event
);
933 * Used by module code with the trace_event_sem held for write.
935 int __unregister_ftrace_event(struct trace_event
*event
)
937 hlist_del(&event
->node
);
938 list_del(&event
->list
);
943 * unregister_ftrace_event - remove a no longer used event
944 * @event: the event to remove
946 int unregister_ftrace_event(struct trace_event
*event
)
948 down_write(&trace_event_sem
);
949 __unregister_ftrace_event(event
);
950 up_write(&trace_event_sem
);
954 EXPORT_SYMBOL_GPL(unregister_ftrace_event
);
960 enum print_line_t
trace_nop_print(struct trace_iterator
*iter
, int flags
,
961 struct trace_event
*event
)
963 if (!trace_seq_printf(&iter
->seq
, "type: %d\n", iter
->ent
->type
))
964 return TRACE_TYPE_PARTIAL_LINE
;
966 return TRACE_TYPE_HANDLED
;
970 static enum print_line_t
trace_fn_trace(struct trace_iterator
*iter
, int flags
,
971 struct trace_event
*event
)
973 struct ftrace_entry
*field
;
974 struct trace_seq
*s
= &iter
->seq
;
976 trace_assign_type(field
, iter
->ent
);
978 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
981 if ((flags
& TRACE_ITER_PRINT_PARENT
) && field
->parent_ip
) {
982 if (!trace_seq_puts(s
, " <-"))
984 if (!seq_print_ip_sym(s
,
989 if (!trace_seq_putc(s
, '\n'))
992 return TRACE_TYPE_HANDLED
;
995 return TRACE_TYPE_PARTIAL_LINE
;
998 static enum print_line_t
trace_fn_raw(struct trace_iterator
*iter
, int flags
,
999 struct trace_event
*event
)
1001 struct ftrace_entry
*field
;
1003 trace_assign_type(field
, iter
->ent
);
1005 if (!trace_seq_printf(&iter
->seq
, "%lx %lx\n",
1008 return TRACE_TYPE_PARTIAL_LINE
;
1010 return TRACE_TYPE_HANDLED
;
1013 static enum print_line_t
trace_fn_hex(struct trace_iterator
*iter
, int flags
,
1014 struct trace_event
*event
)
1016 struct ftrace_entry
*field
;
1017 struct trace_seq
*s
= &iter
->seq
;
1019 trace_assign_type(field
, iter
->ent
);
1021 SEQ_PUT_HEX_FIELD_RET(s
, field
->ip
);
1022 SEQ_PUT_HEX_FIELD_RET(s
, field
->parent_ip
);
1024 return TRACE_TYPE_HANDLED
;
1027 static enum print_line_t
trace_fn_bin(struct trace_iterator
*iter
, int flags
,
1028 struct trace_event
*event
)
1030 struct ftrace_entry
*field
;
1031 struct trace_seq
*s
= &iter
->seq
;
1033 trace_assign_type(field
, iter
->ent
);
1035 SEQ_PUT_FIELD_RET(s
, field
->ip
);
1036 SEQ_PUT_FIELD_RET(s
, field
->parent_ip
);
1038 return TRACE_TYPE_HANDLED
;
1041 static struct trace_event_functions trace_fn_funcs
= {
1042 .trace
= trace_fn_trace
,
1043 .raw
= trace_fn_raw
,
1044 .hex
= trace_fn_hex
,
1045 .binary
= trace_fn_bin
,
1048 static struct trace_event trace_fn_event
= {
1050 .funcs
= &trace_fn_funcs
,
1053 /* TRACE_CTX an TRACE_WAKE */
1054 static enum print_line_t
trace_ctxwake_print(struct trace_iterator
*iter
,
1057 struct ctx_switch_entry
*field
;
1058 char comm
[TASK_COMM_LEN
];
1062 trace_assign_type(field
, iter
->ent
);
1064 T
= task_state_char(field
->next_state
);
1065 S
= task_state_char(field
->prev_state
);
1066 trace_find_cmdline(field
->next_pid
, comm
);
1067 if (!trace_seq_printf(&iter
->seq
,
1068 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
1076 return TRACE_TYPE_PARTIAL_LINE
;
1078 return TRACE_TYPE_HANDLED
;
1081 static enum print_line_t
trace_ctx_print(struct trace_iterator
*iter
, int flags
,
1082 struct trace_event
*event
)
1084 return trace_ctxwake_print(iter
, "==>");
1087 static enum print_line_t
trace_wake_print(struct trace_iterator
*iter
,
1088 int flags
, struct trace_event
*event
)
1090 return trace_ctxwake_print(iter
, " +");
1093 static int trace_ctxwake_raw(struct trace_iterator
*iter
, char S
)
1095 struct ctx_switch_entry
*field
;
1098 trace_assign_type(field
, iter
->ent
);
1101 S
= task_state_char(field
->prev_state
);
1102 T
= task_state_char(field
->next_state
);
1103 if (!trace_seq_printf(&iter
->seq
, "%d %d %c %d %d %d %c\n",
1111 return TRACE_TYPE_PARTIAL_LINE
;
1113 return TRACE_TYPE_HANDLED
;
1116 static enum print_line_t
trace_ctx_raw(struct trace_iterator
*iter
, int flags
,
1117 struct trace_event
*event
)
1119 return trace_ctxwake_raw(iter
, 0);
1122 static enum print_line_t
trace_wake_raw(struct trace_iterator
*iter
, int flags
,
1123 struct trace_event
*event
)
1125 return trace_ctxwake_raw(iter
, '+');
1129 static int trace_ctxwake_hex(struct trace_iterator
*iter
, char S
)
1131 struct ctx_switch_entry
*field
;
1132 struct trace_seq
*s
= &iter
->seq
;
1135 trace_assign_type(field
, iter
->ent
);
1138 S
= task_state_char(field
->prev_state
);
1139 T
= task_state_char(field
->next_state
);
1141 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_pid
);
1142 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_prio
);
1143 SEQ_PUT_HEX_FIELD_RET(s
, S
);
1144 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_cpu
);
1145 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_pid
);
1146 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_prio
);
1147 SEQ_PUT_HEX_FIELD_RET(s
, T
);
1149 return TRACE_TYPE_HANDLED
;
1152 static enum print_line_t
trace_ctx_hex(struct trace_iterator
*iter
, int flags
,
1153 struct trace_event
*event
)
1155 return trace_ctxwake_hex(iter
, 0);
1158 static enum print_line_t
trace_wake_hex(struct trace_iterator
*iter
, int flags
,
1159 struct trace_event
*event
)
1161 return trace_ctxwake_hex(iter
, '+');
1164 static enum print_line_t
trace_ctxwake_bin(struct trace_iterator
*iter
,
1165 int flags
, struct trace_event
*event
)
1167 struct ctx_switch_entry
*field
;
1168 struct trace_seq
*s
= &iter
->seq
;
1170 trace_assign_type(field
, iter
->ent
);
1172 SEQ_PUT_FIELD_RET(s
, field
->prev_pid
);
1173 SEQ_PUT_FIELD_RET(s
, field
->prev_prio
);
1174 SEQ_PUT_FIELD_RET(s
, field
->prev_state
);
1175 SEQ_PUT_FIELD_RET(s
, field
->next_pid
);
1176 SEQ_PUT_FIELD_RET(s
, field
->next_prio
);
1177 SEQ_PUT_FIELD_RET(s
, field
->next_state
);
1179 return TRACE_TYPE_HANDLED
;
1182 static struct trace_event_functions trace_ctx_funcs
= {
1183 .trace
= trace_ctx_print
,
1184 .raw
= trace_ctx_raw
,
1185 .hex
= trace_ctx_hex
,
1186 .binary
= trace_ctxwake_bin
,
1189 static struct trace_event trace_ctx_event
= {
1191 .funcs
= &trace_ctx_funcs
,
1194 static struct trace_event_functions trace_wake_funcs
= {
1195 .trace
= trace_wake_print
,
1196 .raw
= trace_wake_raw
,
1197 .hex
= trace_wake_hex
,
1198 .binary
= trace_ctxwake_bin
,
1201 static struct trace_event trace_wake_event
= {
1203 .funcs
= &trace_wake_funcs
,
1208 static enum print_line_t
trace_stack_print(struct trace_iterator
*iter
,
1209 int flags
, struct trace_event
*event
)
1211 struct stack_entry
*field
;
1212 struct trace_seq
*s
= &iter
->seq
;
1216 trace_assign_type(field
, iter
->ent
);
1217 end
= (unsigned long *)((long)iter
->ent
+ iter
->ent_size
);
1219 if (!trace_seq_puts(s
, "<stack trace>\n"))
1222 for (p
= field
->caller
; p
&& *p
!= ULONG_MAX
&& p
< end
; p
++) {
1223 if (!trace_seq_puts(s
, " => "))
1226 if (!seq_print_ip_sym(s
, *p
, flags
))
1228 if (!trace_seq_putc(s
, '\n'))
1232 return TRACE_TYPE_HANDLED
;
1235 return TRACE_TYPE_PARTIAL_LINE
;
1238 static struct trace_event_functions trace_stack_funcs
= {
1239 .trace
= trace_stack_print
,
1242 static struct trace_event trace_stack_event
= {
1243 .type
= TRACE_STACK
,
1244 .funcs
= &trace_stack_funcs
,
1247 /* TRACE_USER_STACK */
1248 static enum print_line_t
trace_user_stack_print(struct trace_iterator
*iter
,
1249 int flags
, struct trace_event
*event
)
1251 struct userstack_entry
*field
;
1252 struct trace_seq
*s
= &iter
->seq
;
1254 trace_assign_type(field
, iter
->ent
);
1256 if (!trace_seq_puts(s
, "<user stack trace>\n"))
1259 if (!seq_print_userip_objs(field
, s
, flags
))
1262 return TRACE_TYPE_HANDLED
;
1265 return TRACE_TYPE_PARTIAL_LINE
;
1268 static struct trace_event_functions trace_user_stack_funcs
= {
1269 .trace
= trace_user_stack_print
,
1272 static struct trace_event trace_user_stack_event
= {
1273 .type
= TRACE_USER_STACK
,
1274 .funcs
= &trace_user_stack_funcs
,
1278 static enum print_line_t
1279 trace_bputs_print(struct trace_iterator
*iter
, int flags
,
1280 struct trace_event
*event
)
1282 struct trace_entry
*entry
= iter
->ent
;
1283 struct trace_seq
*s
= &iter
->seq
;
1284 struct bputs_entry
*field
;
1286 trace_assign_type(field
, entry
);
1288 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1291 if (!trace_seq_puts(s
, ": "))
1294 if (!trace_seq_puts(s
, field
->str
))
1297 return TRACE_TYPE_HANDLED
;
1300 return TRACE_TYPE_PARTIAL_LINE
;
1304 static enum print_line_t
1305 trace_bputs_raw(struct trace_iterator
*iter
, int flags
,
1306 struct trace_event
*event
)
1308 struct bputs_entry
*field
;
1309 struct trace_seq
*s
= &iter
->seq
;
1311 trace_assign_type(field
, iter
->ent
);
1313 if (!trace_seq_printf(s
, ": %lx : ", field
->ip
))
1316 if (!trace_seq_puts(s
, field
->str
))
1319 return TRACE_TYPE_HANDLED
;
1322 return TRACE_TYPE_PARTIAL_LINE
;
1325 static struct trace_event_functions trace_bputs_funcs
= {
1326 .trace
= trace_bputs_print
,
1327 .raw
= trace_bputs_raw
,
1330 static struct trace_event trace_bputs_event
= {
1331 .type
= TRACE_BPUTS
,
1332 .funcs
= &trace_bputs_funcs
,
1336 static enum print_line_t
1337 trace_bprint_print(struct trace_iterator
*iter
, int flags
,
1338 struct trace_event
*event
)
1340 struct trace_entry
*entry
= iter
->ent
;
1341 struct trace_seq
*s
= &iter
->seq
;
1342 struct bprint_entry
*field
;
1344 trace_assign_type(field
, entry
);
1346 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1349 if (!trace_seq_puts(s
, ": "))
1352 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1355 return TRACE_TYPE_HANDLED
;
1358 return TRACE_TYPE_PARTIAL_LINE
;
1362 static enum print_line_t
1363 trace_bprint_raw(struct trace_iterator
*iter
, int flags
,
1364 struct trace_event
*event
)
1366 struct bprint_entry
*field
;
1367 struct trace_seq
*s
= &iter
->seq
;
1369 trace_assign_type(field
, iter
->ent
);
1371 if (!trace_seq_printf(s
, ": %lx : ", field
->ip
))
1374 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1377 return TRACE_TYPE_HANDLED
;
1380 return TRACE_TYPE_PARTIAL_LINE
;
1383 static struct trace_event_functions trace_bprint_funcs
= {
1384 .trace
= trace_bprint_print
,
1385 .raw
= trace_bprint_raw
,
1388 static struct trace_event trace_bprint_event
= {
1389 .type
= TRACE_BPRINT
,
1390 .funcs
= &trace_bprint_funcs
,
1394 static enum print_line_t
trace_print_print(struct trace_iterator
*iter
,
1395 int flags
, struct trace_event
*event
)
1397 struct print_entry
*field
;
1398 struct trace_seq
*s
= &iter
->seq
;
1400 trace_assign_type(field
, iter
->ent
);
1402 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1405 if (!trace_seq_printf(s
, ": %s", field
->buf
))
1408 return TRACE_TYPE_HANDLED
;
1411 return TRACE_TYPE_PARTIAL_LINE
;
1414 static enum print_line_t
trace_print_raw(struct trace_iterator
*iter
, int flags
,
1415 struct trace_event
*event
)
1417 struct print_entry
*field
;
1419 trace_assign_type(field
, iter
->ent
);
1421 if (!trace_seq_printf(&iter
->seq
, "# %lx %s", field
->ip
, field
->buf
))
1424 return TRACE_TYPE_HANDLED
;
1427 return TRACE_TYPE_PARTIAL_LINE
;
1430 static struct trace_event_functions trace_print_funcs
= {
1431 .trace
= trace_print_print
,
1432 .raw
= trace_print_raw
,
1435 static struct trace_event trace_print_event
= {
1436 .type
= TRACE_PRINT
,
1437 .funcs
= &trace_print_funcs
,
1441 static struct trace_event
*events
[] __initdata
= {
1446 &trace_user_stack_event
,
1448 &trace_bprint_event
,
1453 __init
static int init_events(void)
1455 struct trace_event
*event
;
1458 for (i
= 0; events
[i
]; i
++) {
1461 ret
= register_ftrace_event(event
);
1463 printk(KERN_WARNING
"event %d failed to register\n",
1471 early_initcall(init_events
);