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 void trace_print_seq(struct seq_file
*m
, struct trace_seq
*s
)
28 int len
= s
->len
>= PAGE_SIZE
? PAGE_SIZE
- 1 : s
->len
;
30 seq_write(m
, s
->buffer
, len
);
35 enum print_line_t
trace_print_bprintk_msg_only(struct trace_iterator
*iter
)
37 struct trace_seq
*s
= &iter
->seq
;
38 struct trace_entry
*entry
= iter
->ent
;
39 struct bprint_entry
*field
;
42 trace_assign_type(field
, entry
);
44 ret
= trace_seq_bprintf(s
, field
->fmt
, field
->buf
);
46 return TRACE_TYPE_PARTIAL_LINE
;
48 return TRACE_TYPE_HANDLED
;
51 enum print_line_t
trace_print_printk_msg_only(struct trace_iterator
*iter
)
53 struct trace_seq
*s
= &iter
->seq
;
54 struct trace_entry
*entry
= iter
->ent
;
55 struct print_entry
*field
;
58 trace_assign_type(field
, entry
);
60 ret
= trace_seq_printf(s
, "%s", field
->buf
);
62 return TRACE_TYPE_PARTIAL_LINE
;
64 return TRACE_TYPE_HANDLED
;
68 * trace_seq_printf - sequence printing of trace information
69 * @s: trace sequence descriptor
70 * @fmt: printf format string
72 * The tracer may use either sequence operations or its own
73 * copy to user routines. To simplify formating of a trace
74 * trace_seq_printf is used to store strings into a special
75 * buffer (@s). Then the output may be either used by
76 * the sequencer or pulled into another buffer.
79 trace_seq_printf(struct trace_seq
*s
, const char *fmt
, ...)
81 int len
= (PAGE_SIZE
- 1) - s
->len
;
89 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, ap
);
92 /* If we can't write it all, don't bother writing anything */
100 EXPORT_SYMBOL_GPL(trace_seq_printf
);
103 * trace_seq_vprintf - sequence printing of trace information
104 * @s: trace sequence descriptor
105 * @fmt: printf format string
107 * The tracer may use either sequence operations or its own
108 * copy to user routines. To simplify formating of a trace
109 * trace_seq_printf is used to store strings into a special
110 * buffer (@s). Then the output may be either used by
111 * the sequencer or pulled into another buffer.
114 trace_seq_vprintf(struct trace_seq
*s
, const char *fmt
, va_list args
)
116 int len
= (PAGE_SIZE
- 1) - s
->len
;
122 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, args
);
124 /* If we can't write it all, don't bother writing anything */
132 EXPORT_SYMBOL_GPL(trace_seq_vprintf
);
134 int trace_seq_bprintf(struct trace_seq
*s
, const char *fmt
, const u32
*binary
)
136 int len
= (PAGE_SIZE
- 1) - s
->len
;
142 ret
= bstr_printf(s
->buffer
+ s
->len
, len
, fmt
, binary
);
144 /* If we can't write it all, don't bother writing anything */
154 * trace_seq_puts - trace sequence printing of simple string
155 * @s: trace sequence descriptor
156 * @str: simple string to record
158 * The tracer may use either the sequence operations or its own
159 * copy to user routines. This function records a simple string
160 * into a special buffer (@s) for later retrieval by a sequencer
161 * or other mechanism.
163 int trace_seq_puts(struct trace_seq
*s
, const char *str
)
165 int len
= strlen(str
);
167 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
170 memcpy(s
->buffer
+ s
->len
, str
, len
);
176 int trace_seq_putc(struct trace_seq
*s
, unsigned char c
)
178 if (s
->len
>= (PAGE_SIZE
- 1))
181 s
->buffer
[s
->len
++] = c
;
186 int trace_seq_putmem(struct trace_seq
*s
, const void *mem
, size_t len
)
188 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
191 memcpy(s
->buffer
+ s
->len
, mem
, len
);
197 int trace_seq_putmem_hex(struct trace_seq
*s
, const void *mem
, size_t len
)
199 unsigned char hex
[HEX_CHARS
];
200 const unsigned char *data
= mem
;
204 for (i
= 0, j
= 0; i
< len
; i
++) {
206 for (i
= len
-1, j
= 0; i
>= 0; i
--) {
208 hex
[j
++] = hex_asc_hi(data
[i
]);
209 hex
[j
++] = hex_asc_lo(data
[i
]);
213 return trace_seq_putmem(s
, hex
, j
);
216 void *trace_seq_reserve(struct trace_seq
*s
, size_t len
)
220 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
223 ret
= s
->buffer
+ s
->len
;
229 int trace_seq_path(struct trace_seq
*s
, struct path
*path
)
233 if (s
->len
>= (PAGE_SIZE
- 1))
235 p
= d_path(path
, s
->buffer
+ s
->len
, PAGE_SIZE
- s
->len
);
237 p
= mangle_path(s
->buffer
+ s
->len
, p
, "\n");
239 s
->len
= p
- s
->buffer
;
243 s
->buffer
[s
->len
++] = '?';
251 ftrace_print_flags_seq(struct trace_seq
*p
, const char *delim
,
253 const struct trace_print_flags
*flag_array
)
257 const char *ret
= p
->buffer
+ p
->len
;
260 for (i
= 0; flag_array
[i
].name
&& flags
; i
++) {
262 mask
= flag_array
[i
].mask
;
263 if ((flags
& mask
) != mask
)
266 str
= flag_array
[i
].name
;
269 trace_seq_puts(p
, delim
);
270 trace_seq_puts(p
, str
);
273 /* check for left over flags */
276 trace_seq_puts(p
, delim
);
277 trace_seq_printf(p
, "0x%lx", flags
);
280 trace_seq_putc(p
, 0);
284 EXPORT_SYMBOL(ftrace_print_flags_seq
);
287 ftrace_print_symbols_seq(struct trace_seq
*p
, unsigned long val
,
288 const struct trace_print_flags
*symbol_array
)
291 const char *ret
= p
->buffer
+ p
->len
;
293 for (i
= 0; symbol_array
[i
].name
; i
++) {
295 if (val
!= symbol_array
[i
].mask
)
298 trace_seq_puts(p
, symbol_array
[i
].name
);
303 trace_seq_printf(p
, "0x%lx", val
);
305 trace_seq_putc(p
, 0);
309 EXPORT_SYMBOL(ftrace_print_symbols_seq
);
311 #ifdef CONFIG_KRETPROBES
312 static inline const char *kretprobed(const char *name
)
314 static const char tramp_name
[] = "kretprobe_trampoline";
315 int size
= sizeof(tramp_name
);
317 if (strncmp(tramp_name
, name
, size
) == 0)
318 return "[unknown/kretprobe'd]";
322 static inline const char *kretprobed(const char *name
)
326 #endif /* CONFIG_KRETPROBES */
329 seq_print_sym_short(struct trace_seq
*s
, const char *fmt
, unsigned long address
)
331 #ifdef CONFIG_KALLSYMS
332 char str
[KSYM_SYMBOL_LEN
];
335 kallsyms_lookup(address
, NULL
, NULL
, NULL
, str
);
337 name
= kretprobed(str
);
339 return trace_seq_printf(s
, fmt
, name
);
345 seq_print_sym_offset(struct trace_seq
*s
, const char *fmt
,
346 unsigned long address
)
348 #ifdef CONFIG_KALLSYMS
349 char str
[KSYM_SYMBOL_LEN
];
352 sprint_symbol(str
, address
);
353 name
= kretprobed(str
);
355 return trace_seq_printf(s
, fmt
, name
);
361 # define IP_FMT "%08lx"
363 # define IP_FMT "%016lx"
366 int seq_print_user_ip(struct trace_seq
*s
, struct mm_struct
*mm
,
367 unsigned long ip
, unsigned long sym_flags
)
369 struct file
*file
= NULL
;
370 unsigned long vmstart
= 0;
374 const struct vm_area_struct
*vma
;
376 down_read(&mm
->mmap_sem
);
377 vma
= find_vma(mm
, ip
);
380 vmstart
= vma
->vm_start
;
383 ret
= trace_seq_path(s
, &file
->f_path
);
385 ret
= trace_seq_printf(s
, "[+0x%lx]",
388 up_read(&mm
->mmap_sem
);
390 if (ret
&& ((sym_flags
& TRACE_ITER_SYM_ADDR
) || !file
))
391 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
396 seq_print_userip_objs(const struct userstack_entry
*entry
, struct trace_seq
*s
,
397 unsigned long sym_flags
)
399 struct mm_struct
*mm
= NULL
;
403 if (trace_flags
& TRACE_ITER_SYM_USEROBJ
) {
404 struct task_struct
*task
;
406 * we do the lookup on the thread group leader,
407 * since individual threads might have already quit!
410 task
= find_task_by_vpid(entry
->tgid
);
412 mm
= get_task_mm(task
);
416 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
417 unsigned long ip
= entry
->caller
[i
];
419 if (ip
== ULONG_MAX
|| !ret
)
422 ret
= trace_seq_puts(s
, " => ");
425 ret
= trace_seq_puts(s
, "??");
427 ret
= trace_seq_puts(s
, "\n");
433 ret
= seq_print_user_ip(s
, mm
, ip
, sym_flags
);
434 ret
= trace_seq_puts(s
, "\n");
443 seq_print_ip_sym(struct trace_seq
*s
, unsigned long ip
, unsigned long sym_flags
)
448 return trace_seq_printf(s
, "0");
450 if (sym_flags
& TRACE_ITER_SYM_OFFSET
)
451 ret
= seq_print_sym_offset(s
, "%s", ip
);
453 ret
= seq_print_sym_short(s
, "%s", ip
);
458 if (sym_flags
& TRACE_ITER_SYM_ADDR
)
459 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
464 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
465 * @s: trace seq struct to write to
466 * @entry: The trace entry field from the ring buffer
468 * Prints the generic fields of irqs off, in hard or softirq, preempt
469 * count and lock depth.
471 int trace_print_lat_fmt(struct trace_seq
*s
, struct trace_entry
*entry
)
473 int hardirq
, softirq
;
476 hardirq
= entry
->flags
& TRACE_FLAG_HARDIRQ
;
477 softirq
= entry
->flags
& TRACE_FLAG_SOFTIRQ
;
479 if (!trace_seq_printf(s
, "%c%c%c",
480 (entry
->flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' :
481 (entry
->flags
& TRACE_FLAG_IRQS_NOSUPPORT
) ?
483 (entry
->flags
& TRACE_FLAG_NEED_RESCHED
) ?
485 (hardirq
&& softirq
) ? 'H' :
486 hardirq
? 'h' : softirq
? 's' : '.'))
489 if (entry
->lock_depth
< 0)
490 ret
= trace_seq_putc(s
, '.');
492 ret
= trace_seq_printf(s
, "%d", entry
->lock_depth
);
496 if (entry
->preempt_count
)
497 return trace_seq_printf(s
, "%x", entry
->preempt_count
);
498 return trace_seq_putc(s
, '.');
502 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
504 char comm
[TASK_COMM_LEN
];
506 trace_find_cmdline(entry
->pid
, comm
);
508 if (!trace_seq_printf(s
, "%8.8s-%-5d %3d",
509 comm
, entry
->pid
, cpu
))
512 return trace_print_lat_fmt(s
, entry
);
515 static unsigned long preempt_mark_thresh
= 100;
518 lat_print_timestamp(struct trace_seq
*s
, u64 abs_usecs
,
519 unsigned long rel_usecs
)
521 return trace_seq_printf(s
, " %4lldus%c: ", abs_usecs
,
522 rel_usecs
> preempt_mark_thresh
? '!' :
523 rel_usecs
> 1 ? '+' : ' ');
526 int trace_print_context(struct trace_iterator
*iter
)
528 struct trace_seq
*s
= &iter
->seq
;
529 struct trace_entry
*entry
= iter
->ent
;
530 unsigned long long t
= ns2usecs(iter
->ts
);
531 unsigned long usec_rem
= do_div(t
, USEC_PER_SEC
);
532 unsigned long secs
= (unsigned long)t
;
533 char comm
[TASK_COMM_LEN
];
535 trace_find_cmdline(entry
->pid
, comm
);
537 return trace_seq_printf(s
, "%16s-%-5d [%03d] %5lu.%06lu: ",
538 comm
, entry
->pid
, iter
->cpu
, secs
, usec_rem
);
541 int trace_print_lat_context(struct trace_iterator
*iter
)
545 struct trace_seq
*s
= &iter
->seq
;
546 struct trace_entry
*entry
= iter
->ent
,
547 *next_entry
= trace_find_next_entry(iter
, NULL
,
549 unsigned long verbose
= (trace_flags
& TRACE_ITER_VERBOSE
);
550 unsigned long abs_usecs
= ns2usecs(iter
->ts
- iter
->tr
->time_start
);
551 unsigned long rel_usecs
;
555 rel_usecs
= ns2usecs(next_ts
- iter
->ts
);
558 char comm
[TASK_COMM_LEN
];
560 trace_find_cmdline(entry
->pid
, comm
);
562 ret
= trace_seq_printf(s
, "%16s %5d %3d %d %08x %08lx [%08llx]"
563 " %ld.%03ldms (+%ld.%03ldms): ", comm
,
564 entry
->pid
, iter
->cpu
, entry
->flags
,
565 entry
->preempt_count
, iter
->idx
,
567 abs_usecs
/ USEC_PER_MSEC
,
568 abs_usecs
% USEC_PER_MSEC
,
569 rel_usecs
/ USEC_PER_MSEC
,
570 rel_usecs
% USEC_PER_MSEC
);
572 ret
= lat_print_generic(s
, entry
, iter
->cpu
);
574 ret
= lat_print_timestamp(s
, abs_usecs
, rel_usecs
);
580 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
582 static int task_state_char(unsigned long state
)
584 int bit
= state
? __ffs(state
) + 1 : 0;
586 return bit
< sizeof(state_to_char
) - 1 ? state_to_char
[bit
] : '?';
590 * ftrace_find_event - find a registered event
591 * @type: the type of event to look for
593 * Returns an event of type @type otherwise NULL
594 * Called with trace_event_read_lock() held.
596 struct trace_event
*ftrace_find_event(int type
)
598 struct trace_event
*event
;
599 struct hlist_node
*n
;
602 key
= type
& (EVENT_HASHSIZE
- 1);
604 hlist_for_each_entry(event
, n
, &event_hash
[key
], node
) {
605 if (event
->type
== type
)
612 static LIST_HEAD(ftrace_event_list
);
614 static int trace_search_list(struct list_head
**list
)
616 struct trace_event
*e
;
617 int last
= __TRACE_LAST_TYPE
;
619 if (list_empty(&ftrace_event_list
)) {
620 *list
= &ftrace_event_list
;
625 * We used up all possible max events,
626 * lets see if somebody freed one.
628 list_for_each_entry(e
, &ftrace_event_list
, list
) {
629 if (e
->type
!= last
+ 1)
634 /* Did we used up all 65 thousand events??? */
635 if ((last
+ 1) > FTRACE_MAX_EVENT
)
642 void trace_event_read_lock(void)
644 down_read(&trace_event_mutex
);
647 void trace_event_read_unlock(void)
649 up_read(&trace_event_mutex
);
653 * register_ftrace_event - register output for an event type
654 * @event: the event type to register
656 * Event types are stored in a hash and this hash is used to
657 * find a way to print an event. If the @event->type is set
658 * then it will use that type, otherwise it will assign a
661 * If you assign your own type, please make sure it is added
662 * to the trace_type enum in trace.h, to avoid collisions
663 * with the dynamic types.
665 * Returns the event type number or zero on error.
667 int register_ftrace_event(struct trace_event
*event
)
672 down_write(&trace_event_mutex
);
677 INIT_LIST_HEAD(&event
->list
);
680 struct list_head
*list
= NULL
;
682 if (next_event_type
> FTRACE_MAX_EVENT
) {
684 event
->type
= trace_search_list(&list
);
690 event
->type
= next_event_type
++;
691 list
= &ftrace_event_list
;
694 if (WARN_ON(ftrace_find_event(event
->type
)))
697 list_add_tail(&event
->list
, list
);
699 } else if (event
->type
> __TRACE_LAST_TYPE
) {
700 printk(KERN_WARNING
"Need to add type to trace.h\n");
704 /* Is this event already used */
705 if (ftrace_find_event(event
->type
))
709 if (event
->trace
== NULL
)
710 event
->trace
= trace_nop_print
;
711 if (event
->raw
== NULL
)
712 event
->raw
= trace_nop_print
;
713 if (event
->hex
== NULL
)
714 event
->hex
= trace_nop_print
;
715 if (event
->binary
== NULL
)
716 event
->binary
= trace_nop_print
;
718 key
= event
->type
& (EVENT_HASHSIZE
- 1);
720 hlist_add_head(&event
->node
, &event_hash
[key
]);
724 up_write(&trace_event_mutex
);
728 EXPORT_SYMBOL_GPL(register_ftrace_event
);
731 * Used by module code with the trace_event_mutex held for write.
733 int __unregister_ftrace_event(struct trace_event
*event
)
735 hlist_del(&event
->node
);
736 list_del(&event
->list
);
741 * unregister_ftrace_event - remove a no longer used event
742 * @event: the event to remove
744 int unregister_ftrace_event(struct trace_event
*event
)
746 down_write(&trace_event_mutex
);
747 __unregister_ftrace_event(event
);
748 up_write(&trace_event_mutex
);
752 EXPORT_SYMBOL_GPL(unregister_ftrace_event
);
758 enum print_line_t
trace_nop_print(struct trace_iterator
*iter
, int flags
)
760 return TRACE_TYPE_HANDLED
;
764 static enum print_line_t
trace_fn_trace(struct trace_iterator
*iter
, int flags
)
766 struct ftrace_entry
*field
;
767 struct trace_seq
*s
= &iter
->seq
;
769 trace_assign_type(field
, iter
->ent
);
771 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
774 if ((flags
& TRACE_ITER_PRINT_PARENT
) && field
->parent_ip
) {
775 if (!trace_seq_printf(s
, " <-"))
777 if (!seq_print_ip_sym(s
,
782 if (!trace_seq_printf(s
, "\n"))
785 return TRACE_TYPE_HANDLED
;
788 return TRACE_TYPE_PARTIAL_LINE
;
791 static enum print_line_t
trace_fn_raw(struct trace_iterator
*iter
, int flags
)
793 struct ftrace_entry
*field
;
795 trace_assign_type(field
, iter
->ent
);
797 if (!trace_seq_printf(&iter
->seq
, "%lx %lx\n",
800 return TRACE_TYPE_PARTIAL_LINE
;
802 return TRACE_TYPE_HANDLED
;
805 static enum print_line_t
trace_fn_hex(struct trace_iterator
*iter
, int flags
)
807 struct ftrace_entry
*field
;
808 struct trace_seq
*s
= &iter
->seq
;
810 trace_assign_type(field
, iter
->ent
);
812 SEQ_PUT_HEX_FIELD_RET(s
, field
->ip
);
813 SEQ_PUT_HEX_FIELD_RET(s
, field
->parent_ip
);
815 return TRACE_TYPE_HANDLED
;
818 static enum print_line_t
trace_fn_bin(struct trace_iterator
*iter
, int flags
)
820 struct ftrace_entry
*field
;
821 struct trace_seq
*s
= &iter
->seq
;
823 trace_assign_type(field
, iter
->ent
);
825 SEQ_PUT_FIELD_RET(s
, field
->ip
);
826 SEQ_PUT_FIELD_RET(s
, field
->parent_ip
);
828 return TRACE_TYPE_HANDLED
;
831 static struct trace_event trace_fn_event
= {
833 .trace
= trace_fn_trace
,
836 .binary
= trace_fn_bin
,
839 /* TRACE_CTX an TRACE_WAKE */
840 static enum print_line_t
trace_ctxwake_print(struct trace_iterator
*iter
,
843 struct ctx_switch_entry
*field
;
844 char comm
[TASK_COMM_LEN
];
848 trace_assign_type(field
, iter
->ent
);
850 T
= task_state_char(field
->next_state
);
851 S
= task_state_char(field
->prev_state
);
852 trace_find_cmdline(field
->next_pid
, comm
);
853 if (!trace_seq_printf(&iter
->seq
,
854 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
862 return TRACE_TYPE_PARTIAL_LINE
;
864 return TRACE_TYPE_HANDLED
;
867 static enum print_line_t
trace_ctx_print(struct trace_iterator
*iter
, int flags
)
869 return trace_ctxwake_print(iter
, "==>");
872 static enum print_line_t
trace_wake_print(struct trace_iterator
*iter
,
875 return trace_ctxwake_print(iter
, " +");
878 static int trace_ctxwake_raw(struct trace_iterator
*iter
, char S
)
880 struct ctx_switch_entry
*field
;
883 trace_assign_type(field
, iter
->ent
);
886 task_state_char(field
->prev_state
);
887 T
= task_state_char(field
->next_state
);
888 if (!trace_seq_printf(&iter
->seq
, "%d %d %c %d %d %d %c\n",
896 return TRACE_TYPE_PARTIAL_LINE
;
898 return TRACE_TYPE_HANDLED
;
901 static enum print_line_t
trace_ctx_raw(struct trace_iterator
*iter
, int flags
)
903 return trace_ctxwake_raw(iter
, 0);
906 static enum print_line_t
trace_wake_raw(struct trace_iterator
*iter
, int flags
)
908 return trace_ctxwake_raw(iter
, '+');
912 static int trace_ctxwake_hex(struct trace_iterator
*iter
, char S
)
914 struct ctx_switch_entry
*field
;
915 struct trace_seq
*s
= &iter
->seq
;
918 trace_assign_type(field
, iter
->ent
);
921 task_state_char(field
->prev_state
);
922 T
= task_state_char(field
->next_state
);
924 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_pid
);
925 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_prio
);
926 SEQ_PUT_HEX_FIELD_RET(s
, S
);
927 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_cpu
);
928 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_pid
);
929 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_prio
);
930 SEQ_PUT_HEX_FIELD_RET(s
, T
);
932 return TRACE_TYPE_HANDLED
;
935 static enum print_line_t
trace_ctx_hex(struct trace_iterator
*iter
, int flags
)
937 return trace_ctxwake_hex(iter
, 0);
940 static enum print_line_t
trace_wake_hex(struct trace_iterator
*iter
, int flags
)
942 return trace_ctxwake_hex(iter
, '+');
945 static enum print_line_t
trace_ctxwake_bin(struct trace_iterator
*iter
,
948 struct ctx_switch_entry
*field
;
949 struct trace_seq
*s
= &iter
->seq
;
951 trace_assign_type(field
, iter
->ent
);
953 SEQ_PUT_FIELD_RET(s
, field
->prev_pid
);
954 SEQ_PUT_FIELD_RET(s
, field
->prev_prio
);
955 SEQ_PUT_FIELD_RET(s
, field
->prev_state
);
956 SEQ_PUT_FIELD_RET(s
, field
->next_pid
);
957 SEQ_PUT_FIELD_RET(s
, field
->next_prio
);
958 SEQ_PUT_FIELD_RET(s
, field
->next_state
);
960 return TRACE_TYPE_HANDLED
;
963 static struct trace_event trace_ctx_event
= {
965 .trace
= trace_ctx_print
,
966 .raw
= trace_ctx_raw
,
967 .hex
= trace_ctx_hex
,
968 .binary
= trace_ctxwake_bin
,
971 static struct trace_event trace_wake_event
= {
973 .trace
= trace_wake_print
,
974 .raw
= trace_wake_raw
,
975 .hex
= trace_wake_hex
,
976 .binary
= trace_ctxwake_bin
,
980 static enum print_line_t
trace_special_print(struct trace_iterator
*iter
,
983 struct special_entry
*field
;
985 trace_assign_type(field
, iter
->ent
);
987 if (!trace_seq_printf(&iter
->seq
, "# %ld %ld %ld\n",
991 return TRACE_TYPE_PARTIAL_LINE
;
993 return TRACE_TYPE_HANDLED
;
996 static enum print_line_t
trace_special_hex(struct trace_iterator
*iter
,
999 struct special_entry
*field
;
1000 struct trace_seq
*s
= &iter
->seq
;
1002 trace_assign_type(field
, iter
->ent
);
1004 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg1
);
1005 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg2
);
1006 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg3
);
1008 return TRACE_TYPE_HANDLED
;
1011 static enum print_line_t
trace_special_bin(struct trace_iterator
*iter
,
1014 struct special_entry
*field
;
1015 struct trace_seq
*s
= &iter
->seq
;
1017 trace_assign_type(field
, iter
->ent
);
1019 SEQ_PUT_FIELD_RET(s
, field
->arg1
);
1020 SEQ_PUT_FIELD_RET(s
, field
->arg2
);
1021 SEQ_PUT_FIELD_RET(s
, field
->arg3
);
1023 return TRACE_TYPE_HANDLED
;
1026 static struct trace_event trace_special_event
= {
1027 .type
= TRACE_SPECIAL
,
1028 .trace
= trace_special_print
,
1029 .raw
= trace_special_print
,
1030 .hex
= trace_special_hex
,
1031 .binary
= trace_special_bin
,
1036 static enum print_line_t
trace_stack_print(struct trace_iterator
*iter
,
1039 struct stack_entry
*field
;
1040 struct trace_seq
*s
= &iter
->seq
;
1043 trace_assign_type(field
, iter
->ent
);
1045 if (!trace_seq_puts(s
, "<stack trace>\n"))
1047 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1048 if (!field
->caller
[i
] || (field
->caller
[i
] == ULONG_MAX
))
1050 if (!trace_seq_puts(s
, " => "))
1053 if (!seq_print_ip_sym(s
, field
->caller
[i
], flags
))
1055 if (!trace_seq_puts(s
, "\n"))
1059 return TRACE_TYPE_HANDLED
;
1062 return TRACE_TYPE_PARTIAL_LINE
;
1065 static struct trace_event trace_stack_event
= {
1066 .type
= TRACE_STACK
,
1067 .trace
= trace_stack_print
,
1068 .raw
= trace_special_print
,
1069 .hex
= trace_special_hex
,
1070 .binary
= trace_special_bin
,
1073 /* TRACE_USER_STACK */
1074 static enum print_line_t
trace_user_stack_print(struct trace_iterator
*iter
,
1077 struct userstack_entry
*field
;
1078 struct trace_seq
*s
= &iter
->seq
;
1080 trace_assign_type(field
, iter
->ent
);
1082 if (!trace_seq_puts(s
, "<user stack trace>\n"))
1085 if (!seq_print_userip_objs(field
, s
, flags
))
1088 return TRACE_TYPE_HANDLED
;
1091 return TRACE_TYPE_PARTIAL_LINE
;
1094 static struct trace_event trace_user_stack_event
= {
1095 .type
= TRACE_USER_STACK
,
1096 .trace
= trace_user_stack_print
,
1097 .raw
= trace_special_print
,
1098 .hex
= trace_special_hex
,
1099 .binary
= trace_special_bin
,
1103 static enum print_line_t
1104 trace_bprint_print(struct trace_iterator
*iter
, int flags
)
1106 struct trace_entry
*entry
= iter
->ent
;
1107 struct trace_seq
*s
= &iter
->seq
;
1108 struct bprint_entry
*field
;
1110 trace_assign_type(field
, entry
);
1112 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1115 if (!trace_seq_puts(s
, ": "))
1118 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1121 return TRACE_TYPE_HANDLED
;
1124 return TRACE_TYPE_PARTIAL_LINE
;
1128 static enum print_line_t
1129 trace_bprint_raw(struct trace_iterator
*iter
, int flags
)
1131 struct bprint_entry
*field
;
1132 struct trace_seq
*s
= &iter
->seq
;
1134 trace_assign_type(field
, iter
->ent
);
1136 if (!trace_seq_printf(s
, ": %lx : ", field
->ip
))
1139 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1142 return TRACE_TYPE_HANDLED
;
1145 return TRACE_TYPE_PARTIAL_LINE
;
1149 static struct trace_event trace_bprint_event
= {
1150 .type
= TRACE_BPRINT
,
1151 .trace
= trace_bprint_print
,
1152 .raw
= trace_bprint_raw
,
1156 static enum print_line_t
trace_print_print(struct trace_iterator
*iter
,
1159 struct print_entry
*field
;
1160 struct trace_seq
*s
= &iter
->seq
;
1162 trace_assign_type(field
, iter
->ent
);
1164 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1167 if (!trace_seq_printf(s
, ": %s", field
->buf
))
1170 return TRACE_TYPE_HANDLED
;
1173 return TRACE_TYPE_PARTIAL_LINE
;
1176 static enum print_line_t
trace_print_raw(struct trace_iterator
*iter
, int flags
)
1178 struct print_entry
*field
;
1180 trace_assign_type(field
, iter
->ent
);
1182 if (!trace_seq_printf(&iter
->seq
, "# %lx %s", field
->ip
, field
->buf
))
1185 return TRACE_TYPE_HANDLED
;
1188 return TRACE_TYPE_PARTIAL_LINE
;
1191 static struct trace_event trace_print_event
= {
1192 .type
= TRACE_PRINT
,
1193 .trace
= trace_print_print
,
1194 .raw
= trace_print_raw
,
1198 static struct trace_event
*events
[] __initdata
= {
1202 &trace_special_event
,
1204 &trace_user_stack_event
,
1205 &trace_bprint_event
,
1210 __init
static int init_events(void)
1212 struct trace_event
*event
;
1215 for (i
= 0; events
[i
]; i
++) {
1218 ret
= register_ftrace_event(event
);
1220 printk(KERN_WARNING
"event %d failed to register\n",
1228 device_initcall(init_events
);