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_mutex
);
19 DEFINE_PER_CPU(struct trace_seq
, ftrace_event_seq
);
20 EXPORT_PER_CPU_SYMBOL(ftrace_event_seq
);
22 static struct hlist_head event_hash
[EVENT_HASHSIZE
] __read_mostly
;
24 static int next_event_type
= __TRACE_LAST_TYPE
+ 1;
26 int trace_print_seq(struct seq_file
*m
, struct trace_seq
*s
)
28 int len
= s
->len
>= PAGE_SIZE
? PAGE_SIZE
- 1 : s
->len
;
31 ret
= seq_write(m
, s
->buffer
, len
);
34 * Only reset this buffer if we successfully wrote to the
43 enum print_line_t
trace_print_bprintk_msg_only(struct trace_iterator
*iter
)
45 struct trace_seq
*s
= &iter
->seq
;
46 struct trace_entry
*entry
= iter
->ent
;
47 struct bprint_entry
*field
;
50 trace_assign_type(field
, entry
);
52 ret
= trace_seq_bprintf(s
, field
->fmt
, field
->buf
);
54 return TRACE_TYPE_PARTIAL_LINE
;
56 return TRACE_TYPE_HANDLED
;
59 enum print_line_t
trace_print_printk_msg_only(struct trace_iterator
*iter
)
61 struct trace_seq
*s
= &iter
->seq
;
62 struct trace_entry
*entry
= iter
->ent
;
63 struct print_entry
*field
;
66 trace_assign_type(field
, entry
);
68 ret
= trace_seq_printf(s
, "%s", field
->buf
);
70 return TRACE_TYPE_PARTIAL_LINE
;
72 return TRACE_TYPE_HANDLED
;
76 * trace_seq_printf - sequence printing of trace information
77 * @s: trace sequence descriptor
78 * @fmt: printf format string
80 * It returns 0 if the trace oversizes the buffer's free
83 * The tracer may use either sequence operations or its own
84 * copy to user routines. To simplify formating of a trace
85 * trace_seq_printf is used to store strings into a special
86 * buffer (@s). Then the output may be either used by
87 * the sequencer or pulled into another buffer.
90 trace_seq_printf(struct trace_seq
*s
, const char *fmt
, ...)
92 int len
= (PAGE_SIZE
- 1) - s
->len
;
100 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, ap
);
103 /* If we can't write it all, don't bother writing anything */
113 EXPORT_SYMBOL_GPL(trace_seq_printf
);
116 * trace_seq_vprintf - sequence printing of trace information
117 * @s: trace sequence descriptor
118 * @fmt: printf format string
120 * The tracer may use either sequence operations or its own
121 * copy to user routines. To simplify formating of a trace
122 * trace_seq_printf is used to store strings into a special
123 * buffer (@s). Then the output may be either used by
124 * the sequencer or pulled into another buffer.
127 trace_seq_vprintf(struct trace_seq
*s
, const char *fmt
, va_list args
)
129 int len
= (PAGE_SIZE
- 1) - s
->len
;
135 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, args
);
137 /* If we can't write it all, don't bother writing anything */
147 EXPORT_SYMBOL_GPL(trace_seq_vprintf
);
149 int trace_seq_bprintf(struct trace_seq
*s
, const char *fmt
, const u32
*binary
)
151 int len
= (PAGE_SIZE
- 1) - s
->len
;
157 ret
= bstr_printf(s
->buffer
+ s
->len
, len
, fmt
, binary
);
159 /* If we can't write it all, don't bother writing anything */
171 * trace_seq_puts - trace sequence printing of simple string
172 * @s: trace sequence descriptor
173 * @str: simple string to record
175 * The tracer may use either the sequence operations or its own
176 * copy to user routines. This function records a simple string
177 * into a special buffer (@s) for later retrieval by a sequencer
178 * or other mechanism.
180 int trace_seq_puts(struct trace_seq
*s
, const char *str
)
182 int len
= strlen(str
);
187 if (len
> ((PAGE_SIZE
- 1) - s
->len
)) {
192 memcpy(s
->buffer
+ s
->len
, str
, len
);
198 int trace_seq_putc(struct trace_seq
*s
, unsigned char c
)
203 if (s
->len
>= (PAGE_SIZE
- 1)) {
208 s
->buffer
[s
->len
++] = c
;
212 EXPORT_SYMBOL(trace_seq_putc
);
214 int trace_seq_putmem(struct trace_seq
*s
, const void *mem
, size_t len
)
219 if (len
> ((PAGE_SIZE
- 1) - s
->len
)) {
224 memcpy(s
->buffer
+ s
->len
, mem
, len
);
230 int trace_seq_putmem_hex(struct trace_seq
*s
, const void *mem
, size_t len
)
232 unsigned char hex
[HEX_CHARS
];
233 const unsigned char *data
= mem
;
240 for (i
= 0, j
= 0; i
< len
; i
++) {
242 for (i
= len
-1, j
= 0; i
>= 0; i
--) {
244 hex
[j
++] = hex_asc_hi(data
[i
]);
245 hex
[j
++] = hex_asc_lo(data
[i
]);
249 return trace_seq_putmem(s
, hex
, j
);
252 void *trace_seq_reserve(struct trace_seq
*s
, size_t len
)
259 if (len
> ((PAGE_SIZE
- 1) - s
->len
)) {
264 ret
= s
->buffer
+ s
->len
;
270 int trace_seq_path(struct trace_seq
*s
, struct path
*path
)
277 if (s
->len
>= (PAGE_SIZE
- 1)) {
282 p
= d_path(path
, s
->buffer
+ s
->len
, PAGE_SIZE
- s
->len
);
284 p
= mangle_path(s
->buffer
+ s
->len
, p
, "\n");
286 s
->len
= p
- s
->buffer
;
290 s
->buffer
[s
->len
++] = '?';
299 ftrace_print_flags_seq(struct trace_seq
*p
, const char *delim
,
301 const struct trace_print_flags
*flag_array
)
305 const char *ret
= p
->buffer
+ p
->len
;
308 for (i
= 0; flag_array
[i
].name
&& flags
; i
++) {
310 mask
= flag_array
[i
].mask
;
311 if ((flags
& mask
) != mask
)
314 str
= flag_array
[i
].name
;
317 trace_seq_puts(p
, delim
);
318 trace_seq_puts(p
, str
);
321 /* check for left over flags */
324 trace_seq_puts(p
, delim
);
325 trace_seq_printf(p
, "0x%lx", flags
);
328 trace_seq_putc(p
, 0);
332 EXPORT_SYMBOL(ftrace_print_flags_seq
);
335 ftrace_print_symbols_seq(struct trace_seq
*p
, unsigned long val
,
336 const struct trace_print_flags
*symbol_array
)
339 const char *ret
= p
->buffer
+ p
->len
;
341 for (i
= 0; symbol_array
[i
].name
; i
++) {
343 if (val
!= symbol_array
[i
].mask
)
346 trace_seq_puts(p
, symbol_array
[i
].name
);
351 trace_seq_printf(p
, "0x%lx", val
);
353 trace_seq_putc(p
, 0);
357 EXPORT_SYMBOL(ftrace_print_symbols_seq
);
360 ftrace_print_hex_seq(struct trace_seq
*p
, const unsigned char *buf
, int buf_len
)
363 const char *ret
= p
->buffer
+ p
->len
;
365 for (i
= 0; i
< buf_len
; i
++)
366 trace_seq_printf(p
, "%s%2.2x", i
== 0 ? "" : " ", buf
[i
]);
368 trace_seq_putc(p
, 0);
372 EXPORT_SYMBOL(ftrace_print_hex_seq
);
374 #ifdef CONFIG_KRETPROBES
375 static inline const char *kretprobed(const char *name
)
377 static const char tramp_name
[] = "kretprobe_trampoline";
378 int size
= sizeof(tramp_name
);
380 if (strncmp(tramp_name
, name
, size
) == 0)
381 return "[unknown/kretprobe'd]";
385 static inline const char *kretprobed(const char *name
)
389 #endif /* CONFIG_KRETPROBES */
392 seq_print_sym_short(struct trace_seq
*s
, const char *fmt
, unsigned long address
)
394 #ifdef CONFIG_KALLSYMS
395 char str
[KSYM_SYMBOL_LEN
];
398 kallsyms_lookup(address
, NULL
, NULL
, NULL
, str
);
400 name
= kretprobed(str
);
402 return trace_seq_printf(s
, fmt
, name
);
408 seq_print_sym_offset(struct trace_seq
*s
, const char *fmt
,
409 unsigned long address
)
411 #ifdef CONFIG_KALLSYMS
412 char str
[KSYM_SYMBOL_LEN
];
415 sprint_symbol(str
, address
);
416 name
= kretprobed(str
);
418 return trace_seq_printf(s
, fmt
, name
);
424 # define IP_FMT "%08lx"
426 # define IP_FMT "%016lx"
429 int seq_print_user_ip(struct trace_seq
*s
, struct mm_struct
*mm
,
430 unsigned long ip
, unsigned long sym_flags
)
432 struct file
*file
= NULL
;
433 unsigned long vmstart
= 0;
440 const struct vm_area_struct
*vma
;
442 down_read(&mm
->mmap_sem
);
443 vma
= find_vma(mm
, ip
);
446 vmstart
= vma
->vm_start
;
449 ret
= trace_seq_path(s
, &file
->f_path
);
451 ret
= trace_seq_printf(s
, "[+0x%lx]",
454 up_read(&mm
->mmap_sem
);
456 if (ret
&& ((sym_flags
& TRACE_ITER_SYM_ADDR
) || !file
))
457 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
462 seq_print_userip_objs(const struct userstack_entry
*entry
, struct trace_seq
*s
,
463 unsigned long sym_flags
)
465 struct mm_struct
*mm
= NULL
;
469 if (trace_flags
& TRACE_ITER_SYM_USEROBJ
) {
470 struct task_struct
*task
;
472 * we do the lookup on the thread group leader,
473 * since individual threads might have already quit!
476 task
= find_task_by_vpid(entry
->tgid
);
478 mm
= get_task_mm(task
);
482 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
483 unsigned long ip
= entry
->caller
[i
];
485 if (ip
== ULONG_MAX
|| !ret
)
488 ret
= trace_seq_puts(s
, " => ");
491 ret
= trace_seq_puts(s
, "??");
493 ret
= trace_seq_puts(s
, "\n");
499 ret
= seq_print_user_ip(s
, mm
, ip
, sym_flags
);
500 ret
= trace_seq_puts(s
, "\n");
509 seq_print_ip_sym(struct trace_seq
*s
, unsigned long ip
, unsigned long sym_flags
)
514 return trace_seq_printf(s
, "0");
516 if (sym_flags
& TRACE_ITER_SYM_OFFSET
)
517 ret
= seq_print_sym_offset(s
, "%s", ip
);
519 ret
= seq_print_sym_short(s
, "%s", ip
);
524 if (sym_flags
& TRACE_ITER_SYM_ADDR
)
525 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
530 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
531 * @s: trace seq struct to write to
532 * @entry: The trace entry field from the ring buffer
534 * Prints the generic fields of irqs off, in hard or softirq, preempt
535 * count and lock depth.
537 int trace_print_lat_fmt(struct trace_seq
*s
, struct trace_entry
*entry
)
539 int hardirq
, softirq
;
542 hardirq
= entry
->flags
& TRACE_FLAG_HARDIRQ
;
543 softirq
= entry
->flags
& TRACE_FLAG_SOFTIRQ
;
545 if (!trace_seq_printf(s
, "%c%c%c",
546 (entry
->flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' :
547 (entry
->flags
& TRACE_FLAG_IRQS_NOSUPPORT
) ?
549 (entry
->flags
& TRACE_FLAG_NEED_RESCHED
) ?
551 (hardirq
&& softirq
) ? 'H' :
552 hardirq
? 'h' : softirq
? 's' : '.'))
555 if (entry
->preempt_count
)
556 ret
= trace_seq_printf(s
, "%x", entry
->preempt_count
);
558 ret
= trace_seq_putc(s
, '.');
563 if (entry
->lock_depth
< 0)
564 return trace_seq_putc(s
, '.');
566 return trace_seq_printf(s
, "%d", entry
->lock_depth
);
570 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
572 char comm
[TASK_COMM_LEN
];
574 trace_find_cmdline(entry
->pid
, comm
);
576 if (!trace_seq_printf(s
, "%8.8s-%-5d %3d",
577 comm
, entry
->pid
, cpu
))
580 return trace_print_lat_fmt(s
, entry
);
583 static unsigned long preempt_mark_thresh
= 100;
586 lat_print_timestamp(struct trace_seq
*s
, u64 abs_usecs
,
587 unsigned long rel_usecs
)
589 return trace_seq_printf(s
, " %4lldus%c: ", abs_usecs
,
590 rel_usecs
> preempt_mark_thresh
? '!' :
591 rel_usecs
> 1 ? '+' : ' ');
594 int trace_print_context(struct trace_iterator
*iter
)
596 struct trace_seq
*s
= &iter
->seq
;
597 struct trace_entry
*entry
= iter
->ent
;
598 unsigned long long t
= ns2usecs(iter
->ts
);
599 unsigned long usec_rem
= do_div(t
, USEC_PER_SEC
);
600 unsigned long secs
= (unsigned long)t
;
601 char comm
[TASK_COMM_LEN
];
603 trace_find_cmdline(entry
->pid
, comm
);
605 return trace_seq_printf(s
, "%16s-%-5d [%03d] %5lu.%06lu: ",
606 comm
, entry
->pid
, iter
->cpu
, secs
, usec_rem
);
609 int trace_print_lat_context(struct trace_iterator
*iter
)
613 struct trace_seq
*s
= &iter
->seq
;
614 struct trace_entry
*entry
= iter
->ent
,
615 *next_entry
= trace_find_next_entry(iter
, NULL
,
617 unsigned long verbose
= (trace_flags
& TRACE_ITER_VERBOSE
);
618 unsigned long abs_usecs
= ns2usecs(iter
->ts
- iter
->tr
->time_start
);
619 unsigned long rel_usecs
;
623 rel_usecs
= ns2usecs(next_ts
- iter
->ts
);
626 char comm
[TASK_COMM_LEN
];
628 trace_find_cmdline(entry
->pid
, comm
);
630 ret
= trace_seq_printf(s
, "%16s %5d %3d %d %08x %08lx [%08llx]"
631 " %ld.%03ldms (+%ld.%03ldms): ", comm
,
632 entry
->pid
, iter
->cpu
, entry
->flags
,
633 entry
->preempt_count
, iter
->idx
,
635 abs_usecs
/ USEC_PER_MSEC
,
636 abs_usecs
% USEC_PER_MSEC
,
637 rel_usecs
/ USEC_PER_MSEC
,
638 rel_usecs
% USEC_PER_MSEC
);
640 ret
= lat_print_generic(s
, entry
, iter
->cpu
);
642 ret
= lat_print_timestamp(s
, abs_usecs
, rel_usecs
);
648 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
650 static int task_state_char(unsigned long state
)
652 int bit
= state
? __ffs(state
) + 1 : 0;
654 return bit
< sizeof(state_to_char
) - 1 ? state_to_char
[bit
] : '?';
658 * ftrace_find_event - find a registered event
659 * @type: the type of event to look for
661 * Returns an event of type @type otherwise NULL
662 * Called with trace_event_read_lock() held.
664 struct trace_event
*ftrace_find_event(int type
)
666 struct trace_event
*event
;
667 struct hlist_node
*n
;
670 key
= type
& (EVENT_HASHSIZE
- 1);
672 hlist_for_each_entry(event
, n
, &event_hash
[key
], node
) {
673 if (event
->type
== type
)
680 static LIST_HEAD(ftrace_event_list
);
682 static int trace_search_list(struct list_head
**list
)
684 struct trace_event
*e
;
685 int last
= __TRACE_LAST_TYPE
;
687 if (list_empty(&ftrace_event_list
)) {
688 *list
= &ftrace_event_list
;
693 * We used up all possible max events,
694 * lets see if somebody freed one.
696 list_for_each_entry(e
, &ftrace_event_list
, list
) {
697 if (e
->type
!= last
+ 1)
702 /* Did we used up all 65 thousand events??? */
703 if ((last
+ 1) > FTRACE_MAX_EVENT
)
710 void trace_event_read_lock(void)
712 down_read(&trace_event_mutex
);
715 void trace_event_read_unlock(void)
717 up_read(&trace_event_mutex
);
721 * register_ftrace_event - register output for an event type
722 * @event: the event type to register
724 * Event types are stored in a hash and this hash is used to
725 * find a way to print an event. If the @event->type is set
726 * then it will use that type, otherwise it will assign a
729 * If you assign your own type, please make sure it is added
730 * to the trace_type enum in trace.h, to avoid collisions
731 * with the dynamic types.
733 * Returns the event type number or zero on error.
735 int register_ftrace_event(struct trace_event
*event
)
740 down_write(&trace_event_mutex
);
745 if (WARN_ON(!event
->funcs
))
748 INIT_LIST_HEAD(&event
->list
);
751 struct list_head
*list
= NULL
;
753 if (next_event_type
> FTRACE_MAX_EVENT
) {
755 event
->type
= trace_search_list(&list
);
761 event
->type
= next_event_type
++;
762 list
= &ftrace_event_list
;
765 if (WARN_ON(ftrace_find_event(event
->type
)))
768 list_add_tail(&event
->list
, list
);
770 } else if (event
->type
> __TRACE_LAST_TYPE
) {
771 printk(KERN_WARNING
"Need to add type to trace.h\n");
775 /* Is this event already used */
776 if (ftrace_find_event(event
->type
))
780 if (event
->funcs
->trace
== NULL
)
781 event
->funcs
->trace
= trace_nop_print
;
782 if (event
->funcs
->raw
== NULL
)
783 event
->funcs
->raw
= trace_nop_print
;
784 if (event
->funcs
->hex
== NULL
)
785 event
->funcs
->hex
= trace_nop_print
;
786 if (event
->funcs
->binary
== NULL
)
787 event
->funcs
->binary
= trace_nop_print
;
789 key
= event
->type
& (EVENT_HASHSIZE
- 1);
791 hlist_add_head(&event
->node
, &event_hash
[key
]);
795 up_write(&trace_event_mutex
);
799 EXPORT_SYMBOL_GPL(register_ftrace_event
);
802 * Used by module code with the trace_event_mutex held for write.
804 int __unregister_ftrace_event(struct trace_event
*event
)
806 hlist_del(&event
->node
);
807 list_del(&event
->list
);
812 * unregister_ftrace_event - remove a no longer used event
813 * @event: the event to remove
815 int unregister_ftrace_event(struct trace_event
*event
)
817 down_write(&trace_event_mutex
);
818 __unregister_ftrace_event(event
);
819 up_write(&trace_event_mutex
);
823 EXPORT_SYMBOL_GPL(unregister_ftrace_event
);
829 enum print_line_t
trace_nop_print(struct trace_iterator
*iter
, int flags
,
830 struct trace_event
*event
)
832 return TRACE_TYPE_HANDLED
;
836 static enum print_line_t
trace_fn_trace(struct trace_iterator
*iter
, int flags
,
837 struct trace_event
*event
)
839 struct ftrace_entry
*field
;
840 struct trace_seq
*s
= &iter
->seq
;
842 trace_assign_type(field
, iter
->ent
);
844 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
847 if ((flags
& TRACE_ITER_PRINT_PARENT
) && field
->parent_ip
) {
848 if (!trace_seq_printf(s
, " <-"))
850 if (!seq_print_ip_sym(s
,
855 if (!trace_seq_printf(s
, "\n"))
858 return TRACE_TYPE_HANDLED
;
861 return TRACE_TYPE_PARTIAL_LINE
;
864 static enum print_line_t
trace_fn_raw(struct trace_iterator
*iter
, int flags
,
865 struct trace_event
*event
)
867 struct ftrace_entry
*field
;
869 trace_assign_type(field
, iter
->ent
);
871 if (!trace_seq_printf(&iter
->seq
, "%lx %lx\n",
874 return TRACE_TYPE_PARTIAL_LINE
;
876 return TRACE_TYPE_HANDLED
;
879 static enum print_line_t
trace_fn_hex(struct trace_iterator
*iter
, int flags
,
880 struct trace_event
*event
)
882 struct ftrace_entry
*field
;
883 struct trace_seq
*s
= &iter
->seq
;
885 trace_assign_type(field
, iter
->ent
);
887 SEQ_PUT_HEX_FIELD_RET(s
, field
->ip
);
888 SEQ_PUT_HEX_FIELD_RET(s
, field
->parent_ip
);
890 return TRACE_TYPE_HANDLED
;
893 static enum print_line_t
trace_fn_bin(struct trace_iterator
*iter
, int flags
,
894 struct trace_event
*event
)
896 struct ftrace_entry
*field
;
897 struct trace_seq
*s
= &iter
->seq
;
899 trace_assign_type(field
, iter
->ent
);
901 SEQ_PUT_FIELD_RET(s
, field
->ip
);
902 SEQ_PUT_FIELD_RET(s
, field
->parent_ip
);
904 return TRACE_TYPE_HANDLED
;
907 static struct trace_event_functions trace_fn_funcs
= {
908 .trace
= trace_fn_trace
,
911 .binary
= trace_fn_bin
,
914 static struct trace_event trace_fn_event
= {
916 .funcs
= &trace_fn_funcs
,
919 /* TRACE_CTX an TRACE_WAKE */
920 static enum print_line_t
trace_ctxwake_print(struct trace_iterator
*iter
,
923 struct ctx_switch_entry
*field
;
924 char comm
[TASK_COMM_LEN
];
928 trace_assign_type(field
, iter
->ent
);
930 T
= task_state_char(field
->next_state
);
931 S
= task_state_char(field
->prev_state
);
932 trace_find_cmdline(field
->next_pid
, comm
);
933 if (!trace_seq_printf(&iter
->seq
,
934 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
942 return TRACE_TYPE_PARTIAL_LINE
;
944 return TRACE_TYPE_HANDLED
;
947 static enum print_line_t
trace_ctx_print(struct trace_iterator
*iter
, int flags
,
948 struct trace_event
*event
)
950 return trace_ctxwake_print(iter
, "==>");
953 static enum print_line_t
trace_wake_print(struct trace_iterator
*iter
,
954 int flags
, struct trace_event
*event
)
956 return trace_ctxwake_print(iter
, " +");
959 static int trace_ctxwake_raw(struct trace_iterator
*iter
, char S
)
961 struct ctx_switch_entry
*field
;
964 trace_assign_type(field
, iter
->ent
);
967 S
= task_state_char(field
->prev_state
);
968 T
= task_state_char(field
->next_state
);
969 if (!trace_seq_printf(&iter
->seq
, "%d %d %c %d %d %d %c\n",
977 return TRACE_TYPE_PARTIAL_LINE
;
979 return TRACE_TYPE_HANDLED
;
982 static enum print_line_t
trace_ctx_raw(struct trace_iterator
*iter
, int flags
,
983 struct trace_event
*event
)
985 return trace_ctxwake_raw(iter
, 0);
988 static enum print_line_t
trace_wake_raw(struct trace_iterator
*iter
, int flags
,
989 struct trace_event
*event
)
991 return trace_ctxwake_raw(iter
, '+');
995 static int trace_ctxwake_hex(struct trace_iterator
*iter
, char S
)
997 struct ctx_switch_entry
*field
;
998 struct trace_seq
*s
= &iter
->seq
;
1001 trace_assign_type(field
, iter
->ent
);
1004 S
= task_state_char(field
->prev_state
);
1005 T
= task_state_char(field
->next_state
);
1007 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_pid
);
1008 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_prio
);
1009 SEQ_PUT_HEX_FIELD_RET(s
, S
);
1010 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_cpu
);
1011 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_pid
);
1012 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_prio
);
1013 SEQ_PUT_HEX_FIELD_RET(s
, T
);
1015 return TRACE_TYPE_HANDLED
;
1018 static enum print_line_t
trace_ctx_hex(struct trace_iterator
*iter
, int flags
,
1019 struct trace_event
*event
)
1021 return trace_ctxwake_hex(iter
, 0);
1024 static enum print_line_t
trace_wake_hex(struct trace_iterator
*iter
, int flags
,
1025 struct trace_event
*event
)
1027 return trace_ctxwake_hex(iter
, '+');
1030 static enum print_line_t
trace_ctxwake_bin(struct trace_iterator
*iter
,
1031 int flags
, struct trace_event
*event
)
1033 struct ctx_switch_entry
*field
;
1034 struct trace_seq
*s
= &iter
->seq
;
1036 trace_assign_type(field
, iter
->ent
);
1038 SEQ_PUT_FIELD_RET(s
, field
->prev_pid
);
1039 SEQ_PUT_FIELD_RET(s
, field
->prev_prio
);
1040 SEQ_PUT_FIELD_RET(s
, field
->prev_state
);
1041 SEQ_PUT_FIELD_RET(s
, field
->next_pid
);
1042 SEQ_PUT_FIELD_RET(s
, field
->next_prio
);
1043 SEQ_PUT_FIELD_RET(s
, field
->next_state
);
1045 return TRACE_TYPE_HANDLED
;
1048 static struct trace_event_functions trace_ctx_funcs
= {
1049 .trace
= trace_ctx_print
,
1050 .raw
= trace_ctx_raw
,
1051 .hex
= trace_ctx_hex
,
1052 .binary
= trace_ctxwake_bin
,
1055 static struct trace_event trace_ctx_event
= {
1057 .funcs
= &trace_ctx_funcs
,
1060 static struct trace_event_functions trace_wake_funcs
= {
1061 .trace
= trace_wake_print
,
1062 .raw
= trace_wake_raw
,
1063 .hex
= trace_wake_hex
,
1064 .binary
= trace_ctxwake_bin
,
1067 static struct trace_event trace_wake_event
= {
1069 .funcs
= &trace_wake_funcs
,
1073 static enum print_line_t
trace_special_print(struct trace_iterator
*iter
,
1074 int flags
, struct trace_event
*event
)
1076 struct special_entry
*field
;
1078 trace_assign_type(field
, iter
->ent
);
1080 if (!trace_seq_printf(&iter
->seq
, "# %ld %ld %ld\n",
1084 return TRACE_TYPE_PARTIAL_LINE
;
1086 return TRACE_TYPE_HANDLED
;
1089 static enum print_line_t
trace_special_hex(struct trace_iterator
*iter
,
1090 int flags
, struct trace_event
*event
)
1092 struct special_entry
*field
;
1093 struct trace_seq
*s
= &iter
->seq
;
1095 trace_assign_type(field
, iter
->ent
);
1097 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg1
);
1098 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg2
);
1099 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg3
);
1101 return TRACE_TYPE_HANDLED
;
1104 static enum print_line_t
trace_special_bin(struct trace_iterator
*iter
,
1105 int flags
, struct trace_event
*event
)
1107 struct special_entry
*field
;
1108 struct trace_seq
*s
= &iter
->seq
;
1110 trace_assign_type(field
, iter
->ent
);
1112 SEQ_PUT_FIELD_RET(s
, field
->arg1
);
1113 SEQ_PUT_FIELD_RET(s
, field
->arg2
);
1114 SEQ_PUT_FIELD_RET(s
, field
->arg3
);
1116 return TRACE_TYPE_HANDLED
;
1119 static struct trace_event_functions trace_special_funcs
= {
1120 .trace
= trace_special_print
,
1121 .raw
= trace_special_print
,
1122 .hex
= trace_special_hex
,
1123 .binary
= trace_special_bin
,
1126 static struct trace_event trace_special_event
= {
1127 .type
= TRACE_SPECIAL
,
1128 .funcs
= &trace_special_funcs
,
1133 static enum print_line_t
trace_stack_print(struct trace_iterator
*iter
,
1134 int flags
, struct trace_event
*event
)
1136 struct stack_entry
*field
;
1137 struct trace_seq
*s
= &iter
->seq
;
1140 trace_assign_type(field
, iter
->ent
);
1142 if (!trace_seq_puts(s
, "<stack trace>\n"))
1144 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1145 if (!field
->caller
[i
] || (field
->caller
[i
] == ULONG_MAX
))
1147 if (!trace_seq_puts(s
, " => "))
1150 if (!seq_print_ip_sym(s
, field
->caller
[i
], flags
))
1152 if (!trace_seq_puts(s
, "\n"))
1156 return TRACE_TYPE_HANDLED
;
1159 return TRACE_TYPE_PARTIAL_LINE
;
1162 static struct trace_event_functions trace_stack_funcs
= {
1163 .trace
= trace_stack_print
,
1164 .raw
= trace_special_print
,
1165 .hex
= trace_special_hex
,
1166 .binary
= trace_special_bin
,
1169 static struct trace_event trace_stack_event
= {
1170 .type
= TRACE_STACK
,
1171 .funcs
= &trace_stack_funcs
,
1174 /* TRACE_USER_STACK */
1175 static enum print_line_t
trace_user_stack_print(struct trace_iterator
*iter
,
1176 int flags
, struct trace_event
*event
)
1178 struct userstack_entry
*field
;
1179 struct trace_seq
*s
= &iter
->seq
;
1181 trace_assign_type(field
, iter
->ent
);
1183 if (!trace_seq_puts(s
, "<user stack trace>\n"))
1186 if (!seq_print_userip_objs(field
, s
, flags
))
1189 return TRACE_TYPE_HANDLED
;
1192 return TRACE_TYPE_PARTIAL_LINE
;
1195 static struct trace_event_functions trace_user_stack_funcs
= {
1196 .trace
= trace_user_stack_print
,
1197 .raw
= trace_special_print
,
1198 .hex
= trace_special_hex
,
1199 .binary
= trace_special_bin
,
1202 static struct trace_event trace_user_stack_event
= {
1203 .type
= TRACE_USER_STACK
,
1204 .funcs
= &trace_user_stack_funcs
,
1208 static enum print_line_t
1209 trace_bprint_print(struct trace_iterator
*iter
, int flags
,
1210 struct trace_event
*event
)
1212 struct trace_entry
*entry
= iter
->ent
;
1213 struct trace_seq
*s
= &iter
->seq
;
1214 struct bprint_entry
*field
;
1216 trace_assign_type(field
, entry
);
1218 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1221 if (!trace_seq_puts(s
, ": "))
1224 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1227 return TRACE_TYPE_HANDLED
;
1230 return TRACE_TYPE_PARTIAL_LINE
;
1234 static enum print_line_t
1235 trace_bprint_raw(struct trace_iterator
*iter
, int flags
,
1236 struct trace_event
*event
)
1238 struct bprint_entry
*field
;
1239 struct trace_seq
*s
= &iter
->seq
;
1241 trace_assign_type(field
, iter
->ent
);
1243 if (!trace_seq_printf(s
, ": %lx : ", field
->ip
))
1246 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1249 return TRACE_TYPE_HANDLED
;
1252 return TRACE_TYPE_PARTIAL_LINE
;
1255 static struct trace_event_functions trace_bprint_funcs
= {
1256 .trace
= trace_bprint_print
,
1257 .raw
= trace_bprint_raw
,
1260 static struct trace_event trace_bprint_event
= {
1261 .type
= TRACE_BPRINT
,
1262 .funcs
= &trace_bprint_funcs
,
1266 static enum print_line_t
trace_print_print(struct trace_iterator
*iter
,
1267 int flags
, struct trace_event
*event
)
1269 struct print_entry
*field
;
1270 struct trace_seq
*s
= &iter
->seq
;
1272 trace_assign_type(field
, iter
->ent
);
1274 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1277 if (!trace_seq_printf(s
, ": %s", field
->buf
))
1280 return TRACE_TYPE_HANDLED
;
1283 return TRACE_TYPE_PARTIAL_LINE
;
1286 static enum print_line_t
trace_print_raw(struct trace_iterator
*iter
, int flags
,
1287 struct trace_event
*event
)
1289 struct print_entry
*field
;
1291 trace_assign_type(field
, iter
->ent
);
1293 if (!trace_seq_printf(&iter
->seq
, "# %lx %s", field
->ip
, field
->buf
))
1296 return TRACE_TYPE_HANDLED
;
1299 return TRACE_TYPE_PARTIAL_LINE
;
1302 static struct trace_event_functions trace_print_funcs
= {
1303 .trace
= trace_print_print
,
1304 .raw
= trace_print_raw
,
1307 static struct trace_event trace_print_event
= {
1308 .type
= TRACE_PRINT
,
1309 .funcs
= &trace_print_funcs
,
1313 static struct trace_event
*events
[] __initdata
= {
1317 &trace_special_event
,
1319 &trace_user_stack_event
,
1320 &trace_bprint_event
,
1325 __init
static int init_events(void)
1327 struct trace_event
*event
;
1330 for (i
= 0; events
[i
]; i
++) {
1333 ret
= register_ftrace_event(event
);
1335 printk(KERN_WARNING
"event %d failed to register\n",
1343 device_initcall(init_events
);