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 * It returns 0 if the trace oversizes the buffer's free
75 * The tracer may use either sequence operations or its own
76 * copy to user routines. To simplify formating of a trace
77 * trace_seq_printf is used to store strings into a special
78 * buffer (@s). Then the output may be either used by
79 * the sequencer or pulled into another buffer.
82 trace_seq_printf(struct trace_seq
*s
, const char *fmt
, ...)
84 int len
= (PAGE_SIZE
- 1) - s
->len
;
92 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, ap
);
95 /* If we can't write it all, don't bother writing anything */
103 EXPORT_SYMBOL_GPL(trace_seq_printf
);
106 * trace_seq_vprintf - sequence printing of trace information
107 * @s: trace sequence descriptor
108 * @fmt: printf format string
110 * The tracer may use either sequence operations or its own
111 * copy to user routines. To simplify formating of a trace
112 * trace_seq_printf is used to store strings into a special
113 * buffer (@s). Then the output may be either used by
114 * the sequencer or pulled into another buffer.
117 trace_seq_vprintf(struct trace_seq
*s
, const char *fmt
, va_list args
)
119 int len
= (PAGE_SIZE
- 1) - s
->len
;
125 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, args
);
127 /* If we can't write it all, don't bother writing anything */
135 EXPORT_SYMBOL_GPL(trace_seq_vprintf
);
137 int trace_seq_bprintf(struct trace_seq
*s
, const char *fmt
, const u32
*binary
)
139 int len
= (PAGE_SIZE
- 1) - s
->len
;
145 ret
= bstr_printf(s
->buffer
+ s
->len
, len
, fmt
, binary
);
147 /* If we can't write it all, don't bother writing anything */
157 * trace_seq_puts - trace sequence printing of simple string
158 * @s: trace sequence descriptor
159 * @str: simple string to record
161 * The tracer may use either the sequence operations or its own
162 * copy to user routines. This function records a simple string
163 * into a special buffer (@s) for later retrieval by a sequencer
164 * or other mechanism.
166 int trace_seq_puts(struct trace_seq
*s
, const char *str
)
168 int len
= strlen(str
);
170 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
173 memcpy(s
->buffer
+ s
->len
, str
, len
);
179 int trace_seq_putc(struct trace_seq
*s
, unsigned char c
)
181 if (s
->len
>= (PAGE_SIZE
- 1))
184 s
->buffer
[s
->len
++] = c
;
189 int trace_seq_putmem(struct trace_seq
*s
, const void *mem
, size_t len
)
191 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
194 memcpy(s
->buffer
+ s
->len
, mem
, len
);
200 int trace_seq_putmem_hex(struct trace_seq
*s
, const void *mem
, size_t len
)
202 unsigned char hex
[HEX_CHARS
];
203 const unsigned char *data
= mem
;
207 for (i
= 0, j
= 0; i
< len
; i
++) {
209 for (i
= len
-1, j
= 0; i
>= 0; i
--) {
211 hex
[j
++] = hex_asc_hi(data
[i
]);
212 hex
[j
++] = hex_asc_lo(data
[i
]);
216 return trace_seq_putmem(s
, hex
, j
);
219 void *trace_seq_reserve(struct trace_seq
*s
, size_t len
)
223 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
226 ret
= s
->buffer
+ s
->len
;
232 int trace_seq_path(struct trace_seq
*s
, struct path
*path
)
236 if (s
->len
>= (PAGE_SIZE
- 1))
238 p
= d_path(path
, s
->buffer
+ s
->len
, PAGE_SIZE
- s
->len
);
240 p
= mangle_path(s
->buffer
+ s
->len
, p
, "\n");
242 s
->len
= p
- s
->buffer
;
246 s
->buffer
[s
->len
++] = '?';
254 ftrace_print_flags_seq(struct trace_seq
*p
, const char *delim
,
256 const struct trace_print_flags
*flag_array
)
260 const char *ret
= p
->buffer
+ p
->len
;
263 for (i
= 0; flag_array
[i
].name
&& flags
; i
++) {
265 mask
= flag_array
[i
].mask
;
266 if ((flags
& mask
) != mask
)
269 str
= flag_array
[i
].name
;
272 trace_seq_puts(p
, delim
);
273 trace_seq_puts(p
, str
);
276 /* check for left over flags */
279 trace_seq_puts(p
, delim
);
280 trace_seq_printf(p
, "0x%lx", flags
);
283 trace_seq_putc(p
, 0);
287 EXPORT_SYMBOL(ftrace_print_flags_seq
);
290 ftrace_print_symbols_seq(struct trace_seq
*p
, unsigned long val
,
291 const struct trace_print_flags
*symbol_array
)
294 const char *ret
= p
->buffer
+ p
->len
;
296 for (i
= 0; symbol_array
[i
].name
; i
++) {
298 if (val
!= symbol_array
[i
].mask
)
301 trace_seq_puts(p
, symbol_array
[i
].name
);
306 trace_seq_printf(p
, "0x%lx", val
);
308 trace_seq_putc(p
, 0);
312 EXPORT_SYMBOL(ftrace_print_symbols_seq
);
314 #ifdef CONFIG_KRETPROBES
315 static inline const char *kretprobed(const char *name
)
317 static const char tramp_name
[] = "kretprobe_trampoline";
318 int size
= sizeof(tramp_name
);
320 if (strncmp(tramp_name
, name
, size
) == 0)
321 return "[unknown/kretprobe'd]";
325 static inline const char *kretprobed(const char *name
)
329 #endif /* CONFIG_KRETPROBES */
332 seq_print_sym_short(struct trace_seq
*s
, const char *fmt
, unsigned long address
)
334 #ifdef CONFIG_KALLSYMS
335 char str
[KSYM_SYMBOL_LEN
];
338 kallsyms_lookup(address
, NULL
, NULL
, NULL
, str
);
340 name
= kretprobed(str
);
342 return trace_seq_printf(s
, fmt
, name
);
348 seq_print_sym_offset(struct trace_seq
*s
, const char *fmt
,
349 unsigned long address
)
351 #ifdef CONFIG_KALLSYMS
352 char str
[KSYM_SYMBOL_LEN
];
355 sprint_symbol(str
, address
);
356 name
= kretprobed(str
);
358 return trace_seq_printf(s
, fmt
, name
);
364 # define IP_FMT "%08lx"
366 # define IP_FMT "%016lx"
369 int seq_print_user_ip(struct trace_seq
*s
, struct mm_struct
*mm
,
370 unsigned long ip
, unsigned long sym_flags
)
372 struct file
*file
= NULL
;
373 unsigned long vmstart
= 0;
377 const struct vm_area_struct
*vma
;
379 down_read(&mm
->mmap_sem
);
380 vma
= find_vma(mm
, ip
);
383 vmstart
= vma
->vm_start
;
386 ret
= trace_seq_path(s
, &file
->f_path
);
388 ret
= trace_seq_printf(s
, "[+0x%lx]",
391 up_read(&mm
->mmap_sem
);
393 if (ret
&& ((sym_flags
& TRACE_ITER_SYM_ADDR
) || !file
))
394 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
399 seq_print_userip_objs(const struct userstack_entry
*entry
, struct trace_seq
*s
,
400 unsigned long sym_flags
)
402 struct mm_struct
*mm
= NULL
;
406 if (trace_flags
& TRACE_ITER_SYM_USEROBJ
) {
407 struct task_struct
*task
;
409 * we do the lookup on the thread group leader,
410 * since individual threads might have already quit!
413 task
= find_task_by_vpid(entry
->tgid
);
415 mm
= get_task_mm(task
);
419 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
420 unsigned long ip
= entry
->caller
[i
];
422 if (ip
== ULONG_MAX
|| !ret
)
425 ret
= trace_seq_puts(s
, " => ");
428 ret
= trace_seq_puts(s
, "??");
430 ret
= trace_seq_puts(s
, "\n");
436 ret
= seq_print_user_ip(s
, mm
, ip
, sym_flags
);
437 ret
= trace_seq_puts(s
, "\n");
446 seq_print_ip_sym(struct trace_seq
*s
, unsigned long ip
, unsigned long sym_flags
)
451 return trace_seq_printf(s
, "0");
453 if (sym_flags
& TRACE_ITER_SYM_OFFSET
)
454 ret
= seq_print_sym_offset(s
, "%s", ip
);
456 ret
= seq_print_sym_short(s
, "%s", ip
);
461 if (sym_flags
& TRACE_ITER_SYM_ADDR
)
462 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
467 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
468 * @s: trace seq struct to write to
469 * @entry: The trace entry field from the ring buffer
471 * Prints the generic fields of irqs off, in hard or softirq, preempt
472 * count and lock depth.
474 int trace_print_lat_fmt(struct trace_seq
*s
, struct trace_entry
*entry
)
476 int hardirq
, softirq
;
479 hardirq
= entry
->flags
& TRACE_FLAG_HARDIRQ
;
480 softirq
= entry
->flags
& TRACE_FLAG_SOFTIRQ
;
482 if (!trace_seq_printf(s
, "%c%c%c",
483 (entry
->flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' :
484 (entry
->flags
& TRACE_FLAG_IRQS_NOSUPPORT
) ?
486 (entry
->flags
& TRACE_FLAG_NEED_RESCHED
) ?
488 (hardirq
&& softirq
) ? 'H' :
489 hardirq
? 'h' : softirq
? 's' : '.'))
492 if (entry
->preempt_count
)
493 ret
= trace_seq_printf(s
, "%x", entry
->preempt_count
);
495 ret
= trace_seq_putc(s
, '.');
500 if (entry
->lock_depth
< 0)
501 return trace_seq_putc(s
, '.');
503 return trace_seq_printf(s
, "%d", entry
->lock_depth
);
507 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
509 char comm
[TASK_COMM_LEN
];
511 trace_find_cmdline(entry
->pid
, comm
);
513 if (!trace_seq_printf(s
, "%8.8s-%-5d %3d",
514 comm
, entry
->pid
, cpu
))
517 return trace_print_lat_fmt(s
, entry
);
520 static unsigned long preempt_mark_thresh
= 100;
523 lat_print_timestamp(struct trace_seq
*s
, u64 abs_usecs
,
524 unsigned long rel_usecs
)
526 return trace_seq_printf(s
, " %4lldus%c: ", abs_usecs
,
527 rel_usecs
> preempt_mark_thresh
? '!' :
528 rel_usecs
> 1 ? '+' : ' ');
531 int trace_print_context(struct trace_iterator
*iter
)
533 struct trace_seq
*s
= &iter
->seq
;
534 struct trace_entry
*entry
= iter
->ent
;
535 unsigned long long t
= ns2usecs(iter
->ts
);
536 unsigned long usec_rem
= do_div(t
, USEC_PER_SEC
);
537 unsigned long secs
= (unsigned long)t
;
538 char comm
[TASK_COMM_LEN
];
540 trace_find_cmdline(entry
->pid
, comm
);
542 return trace_seq_printf(s
, "%16s-%-5d [%03d] %5lu.%06lu: ",
543 comm
, entry
->pid
, iter
->cpu
, secs
, usec_rem
);
546 int trace_print_lat_context(struct trace_iterator
*iter
)
550 struct trace_seq
*s
= &iter
->seq
;
551 struct trace_entry
*entry
= iter
->ent
,
552 *next_entry
= trace_find_next_entry(iter
, NULL
,
554 unsigned long verbose
= (trace_flags
& TRACE_ITER_VERBOSE
);
555 unsigned long abs_usecs
= ns2usecs(iter
->ts
- iter
->tr
->time_start
);
556 unsigned long rel_usecs
;
560 rel_usecs
= ns2usecs(next_ts
- iter
->ts
);
563 char comm
[TASK_COMM_LEN
];
565 trace_find_cmdline(entry
->pid
, comm
);
567 ret
= trace_seq_printf(s
, "%16s %5d %3d %d %08x %08lx [%08llx]"
568 " %ld.%03ldms (+%ld.%03ldms): ", comm
,
569 entry
->pid
, iter
->cpu
, entry
->flags
,
570 entry
->preempt_count
, iter
->idx
,
572 abs_usecs
/ USEC_PER_MSEC
,
573 abs_usecs
% USEC_PER_MSEC
,
574 rel_usecs
/ USEC_PER_MSEC
,
575 rel_usecs
% USEC_PER_MSEC
);
577 ret
= lat_print_generic(s
, entry
, iter
->cpu
);
579 ret
= lat_print_timestamp(s
, abs_usecs
, rel_usecs
);
585 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
587 static int task_state_char(unsigned long state
)
589 int bit
= state
? __ffs(state
) + 1 : 0;
591 return bit
< sizeof(state_to_char
) - 1 ? state_to_char
[bit
] : '?';
595 * ftrace_find_event - find a registered event
596 * @type: the type of event to look for
598 * Returns an event of type @type otherwise NULL
599 * Called with trace_event_read_lock() held.
601 struct trace_event
*ftrace_find_event(int type
)
603 struct trace_event
*event
;
604 struct hlist_node
*n
;
607 key
= type
& (EVENT_HASHSIZE
- 1);
609 hlist_for_each_entry(event
, n
, &event_hash
[key
], node
) {
610 if (event
->type
== type
)
617 static LIST_HEAD(ftrace_event_list
);
619 static int trace_search_list(struct list_head
**list
)
621 struct trace_event
*e
;
622 int last
= __TRACE_LAST_TYPE
;
624 if (list_empty(&ftrace_event_list
)) {
625 *list
= &ftrace_event_list
;
630 * We used up all possible max events,
631 * lets see if somebody freed one.
633 list_for_each_entry(e
, &ftrace_event_list
, list
) {
634 if (e
->type
!= last
+ 1)
639 /* Did we used up all 65 thousand events??? */
640 if ((last
+ 1) > FTRACE_MAX_EVENT
)
647 void trace_event_read_lock(void)
649 down_read(&trace_event_mutex
);
652 void trace_event_read_unlock(void)
654 up_read(&trace_event_mutex
);
658 * register_ftrace_event - register output for an event type
659 * @event: the event type to register
661 * Event types are stored in a hash and this hash is used to
662 * find a way to print an event. If the @event->type is set
663 * then it will use that type, otherwise it will assign a
666 * If you assign your own type, please make sure it is added
667 * to the trace_type enum in trace.h, to avoid collisions
668 * with the dynamic types.
670 * Returns the event type number or zero on error.
672 int register_ftrace_event(struct trace_event
*event
)
677 down_write(&trace_event_mutex
);
682 INIT_LIST_HEAD(&event
->list
);
685 struct list_head
*list
= NULL
;
687 if (next_event_type
> FTRACE_MAX_EVENT
) {
689 event
->type
= trace_search_list(&list
);
695 event
->type
= next_event_type
++;
696 list
= &ftrace_event_list
;
699 if (WARN_ON(ftrace_find_event(event
->type
)))
702 list_add_tail(&event
->list
, list
);
704 } else if (event
->type
> __TRACE_LAST_TYPE
) {
705 printk(KERN_WARNING
"Need to add type to trace.h\n");
709 /* Is this event already used */
710 if (ftrace_find_event(event
->type
))
714 if (event
->trace
== NULL
)
715 event
->trace
= trace_nop_print
;
716 if (event
->raw
== NULL
)
717 event
->raw
= trace_nop_print
;
718 if (event
->hex
== NULL
)
719 event
->hex
= trace_nop_print
;
720 if (event
->binary
== NULL
)
721 event
->binary
= trace_nop_print
;
723 key
= event
->type
& (EVENT_HASHSIZE
- 1);
725 hlist_add_head(&event
->node
, &event_hash
[key
]);
729 up_write(&trace_event_mutex
);
733 EXPORT_SYMBOL_GPL(register_ftrace_event
);
736 * Used by module code with the trace_event_mutex held for write.
738 int __unregister_ftrace_event(struct trace_event
*event
)
740 hlist_del(&event
->node
);
741 list_del(&event
->list
);
746 * unregister_ftrace_event - remove a no longer used event
747 * @event: the event to remove
749 int unregister_ftrace_event(struct trace_event
*event
)
751 down_write(&trace_event_mutex
);
752 __unregister_ftrace_event(event
);
753 up_write(&trace_event_mutex
);
757 EXPORT_SYMBOL_GPL(unregister_ftrace_event
);
763 enum print_line_t
trace_nop_print(struct trace_iterator
*iter
, int flags
)
765 return TRACE_TYPE_HANDLED
;
769 static enum print_line_t
trace_fn_trace(struct trace_iterator
*iter
, int flags
)
771 struct ftrace_entry
*field
;
772 struct trace_seq
*s
= &iter
->seq
;
774 trace_assign_type(field
, iter
->ent
);
776 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
779 if ((flags
& TRACE_ITER_PRINT_PARENT
) && field
->parent_ip
) {
780 if (!trace_seq_printf(s
, " <-"))
782 if (!seq_print_ip_sym(s
,
787 if (!trace_seq_printf(s
, "\n"))
790 return TRACE_TYPE_HANDLED
;
793 return TRACE_TYPE_PARTIAL_LINE
;
796 static enum print_line_t
trace_fn_raw(struct trace_iterator
*iter
, int flags
)
798 struct ftrace_entry
*field
;
800 trace_assign_type(field
, iter
->ent
);
802 if (!trace_seq_printf(&iter
->seq
, "%lx %lx\n",
805 return TRACE_TYPE_PARTIAL_LINE
;
807 return TRACE_TYPE_HANDLED
;
810 static enum print_line_t
trace_fn_hex(struct trace_iterator
*iter
, int flags
)
812 struct ftrace_entry
*field
;
813 struct trace_seq
*s
= &iter
->seq
;
815 trace_assign_type(field
, iter
->ent
);
817 SEQ_PUT_HEX_FIELD_RET(s
, field
->ip
);
818 SEQ_PUT_HEX_FIELD_RET(s
, field
->parent_ip
);
820 return TRACE_TYPE_HANDLED
;
823 static enum print_line_t
trace_fn_bin(struct trace_iterator
*iter
, int flags
)
825 struct ftrace_entry
*field
;
826 struct trace_seq
*s
= &iter
->seq
;
828 trace_assign_type(field
, iter
->ent
);
830 SEQ_PUT_FIELD_RET(s
, field
->ip
);
831 SEQ_PUT_FIELD_RET(s
, field
->parent_ip
);
833 return TRACE_TYPE_HANDLED
;
836 static struct trace_event trace_fn_event
= {
838 .trace
= trace_fn_trace
,
841 .binary
= trace_fn_bin
,
844 /* TRACE_CTX an TRACE_WAKE */
845 static enum print_line_t
trace_ctxwake_print(struct trace_iterator
*iter
,
848 struct ctx_switch_entry
*field
;
849 char comm
[TASK_COMM_LEN
];
853 trace_assign_type(field
, iter
->ent
);
855 T
= task_state_char(field
->next_state
);
856 S
= task_state_char(field
->prev_state
);
857 trace_find_cmdline(field
->next_pid
, comm
);
858 if (!trace_seq_printf(&iter
->seq
,
859 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
867 return TRACE_TYPE_PARTIAL_LINE
;
869 return TRACE_TYPE_HANDLED
;
872 static enum print_line_t
trace_ctx_print(struct trace_iterator
*iter
, int flags
)
874 return trace_ctxwake_print(iter
, "==>");
877 static enum print_line_t
trace_wake_print(struct trace_iterator
*iter
,
880 return trace_ctxwake_print(iter
, " +");
883 static int trace_ctxwake_raw(struct trace_iterator
*iter
, char S
)
885 struct ctx_switch_entry
*field
;
888 trace_assign_type(field
, iter
->ent
);
891 S
= task_state_char(field
->prev_state
);
892 T
= task_state_char(field
->next_state
);
893 if (!trace_seq_printf(&iter
->seq
, "%d %d %c %d %d %d %c\n",
901 return TRACE_TYPE_PARTIAL_LINE
;
903 return TRACE_TYPE_HANDLED
;
906 static enum print_line_t
trace_ctx_raw(struct trace_iterator
*iter
, int flags
)
908 return trace_ctxwake_raw(iter
, 0);
911 static enum print_line_t
trace_wake_raw(struct trace_iterator
*iter
, int flags
)
913 return trace_ctxwake_raw(iter
, '+');
917 static int trace_ctxwake_hex(struct trace_iterator
*iter
, char S
)
919 struct ctx_switch_entry
*field
;
920 struct trace_seq
*s
= &iter
->seq
;
923 trace_assign_type(field
, iter
->ent
);
926 S
= task_state_char(field
->prev_state
);
927 T
= task_state_char(field
->next_state
);
929 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_pid
);
930 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_prio
);
931 SEQ_PUT_HEX_FIELD_RET(s
, S
);
932 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_cpu
);
933 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_pid
);
934 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_prio
);
935 SEQ_PUT_HEX_FIELD_RET(s
, T
);
937 return TRACE_TYPE_HANDLED
;
940 static enum print_line_t
trace_ctx_hex(struct trace_iterator
*iter
, int flags
)
942 return trace_ctxwake_hex(iter
, 0);
945 static enum print_line_t
trace_wake_hex(struct trace_iterator
*iter
, int flags
)
947 return trace_ctxwake_hex(iter
, '+');
950 static enum print_line_t
trace_ctxwake_bin(struct trace_iterator
*iter
,
953 struct ctx_switch_entry
*field
;
954 struct trace_seq
*s
= &iter
->seq
;
956 trace_assign_type(field
, iter
->ent
);
958 SEQ_PUT_FIELD_RET(s
, field
->prev_pid
);
959 SEQ_PUT_FIELD_RET(s
, field
->prev_prio
);
960 SEQ_PUT_FIELD_RET(s
, field
->prev_state
);
961 SEQ_PUT_FIELD_RET(s
, field
->next_pid
);
962 SEQ_PUT_FIELD_RET(s
, field
->next_prio
);
963 SEQ_PUT_FIELD_RET(s
, field
->next_state
);
965 return TRACE_TYPE_HANDLED
;
968 static struct trace_event trace_ctx_event
= {
970 .trace
= trace_ctx_print
,
971 .raw
= trace_ctx_raw
,
972 .hex
= trace_ctx_hex
,
973 .binary
= trace_ctxwake_bin
,
976 static struct trace_event trace_wake_event
= {
978 .trace
= trace_wake_print
,
979 .raw
= trace_wake_raw
,
980 .hex
= trace_wake_hex
,
981 .binary
= trace_ctxwake_bin
,
985 static enum print_line_t
trace_special_print(struct trace_iterator
*iter
,
988 struct special_entry
*field
;
990 trace_assign_type(field
, iter
->ent
);
992 if (!trace_seq_printf(&iter
->seq
, "# %ld %ld %ld\n",
996 return TRACE_TYPE_PARTIAL_LINE
;
998 return TRACE_TYPE_HANDLED
;
1001 static enum print_line_t
trace_special_hex(struct trace_iterator
*iter
,
1004 struct special_entry
*field
;
1005 struct trace_seq
*s
= &iter
->seq
;
1007 trace_assign_type(field
, iter
->ent
);
1009 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg1
);
1010 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg2
);
1011 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg3
);
1013 return TRACE_TYPE_HANDLED
;
1016 static enum print_line_t
trace_special_bin(struct trace_iterator
*iter
,
1019 struct special_entry
*field
;
1020 struct trace_seq
*s
= &iter
->seq
;
1022 trace_assign_type(field
, iter
->ent
);
1024 SEQ_PUT_FIELD_RET(s
, field
->arg1
);
1025 SEQ_PUT_FIELD_RET(s
, field
->arg2
);
1026 SEQ_PUT_FIELD_RET(s
, field
->arg3
);
1028 return TRACE_TYPE_HANDLED
;
1031 static struct trace_event trace_special_event
= {
1032 .type
= TRACE_SPECIAL
,
1033 .trace
= trace_special_print
,
1034 .raw
= trace_special_print
,
1035 .hex
= trace_special_hex
,
1036 .binary
= trace_special_bin
,
1041 static enum print_line_t
trace_stack_print(struct trace_iterator
*iter
,
1044 struct stack_entry
*field
;
1045 struct trace_seq
*s
= &iter
->seq
;
1048 trace_assign_type(field
, iter
->ent
);
1050 if (!trace_seq_puts(s
, "<stack trace>\n"))
1052 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1053 if (!field
->caller
[i
] || (field
->caller
[i
] == ULONG_MAX
))
1055 if (!trace_seq_puts(s
, " => "))
1058 if (!seq_print_ip_sym(s
, field
->caller
[i
], flags
))
1060 if (!trace_seq_puts(s
, "\n"))
1064 return TRACE_TYPE_HANDLED
;
1067 return TRACE_TYPE_PARTIAL_LINE
;
1070 static struct trace_event trace_stack_event
= {
1071 .type
= TRACE_STACK
,
1072 .trace
= trace_stack_print
,
1073 .raw
= trace_special_print
,
1074 .hex
= trace_special_hex
,
1075 .binary
= trace_special_bin
,
1078 /* TRACE_USER_STACK */
1079 static enum print_line_t
trace_user_stack_print(struct trace_iterator
*iter
,
1082 struct userstack_entry
*field
;
1083 struct trace_seq
*s
= &iter
->seq
;
1085 trace_assign_type(field
, iter
->ent
);
1087 if (!trace_seq_puts(s
, "<user stack trace>\n"))
1090 if (!seq_print_userip_objs(field
, s
, flags
))
1093 return TRACE_TYPE_HANDLED
;
1096 return TRACE_TYPE_PARTIAL_LINE
;
1099 static struct trace_event trace_user_stack_event
= {
1100 .type
= TRACE_USER_STACK
,
1101 .trace
= trace_user_stack_print
,
1102 .raw
= trace_special_print
,
1103 .hex
= trace_special_hex
,
1104 .binary
= trace_special_bin
,
1108 static enum print_line_t
1109 trace_bprint_print(struct trace_iterator
*iter
, int flags
)
1111 struct trace_entry
*entry
= iter
->ent
;
1112 struct trace_seq
*s
= &iter
->seq
;
1113 struct bprint_entry
*field
;
1115 trace_assign_type(field
, entry
);
1117 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1120 if (!trace_seq_puts(s
, ": "))
1123 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1126 return TRACE_TYPE_HANDLED
;
1129 return TRACE_TYPE_PARTIAL_LINE
;
1133 static enum print_line_t
1134 trace_bprint_raw(struct trace_iterator
*iter
, int flags
)
1136 struct bprint_entry
*field
;
1137 struct trace_seq
*s
= &iter
->seq
;
1139 trace_assign_type(field
, iter
->ent
);
1141 if (!trace_seq_printf(s
, ": %lx : ", field
->ip
))
1144 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1147 return TRACE_TYPE_HANDLED
;
1150 return TRACE_TYPE_PARTIAL_LINE
;
1154 static struct trace_event trace_bprint_event
= {
1155 .type
= TRACE_BPRINT
,
1156 .trace
= trace_bprint_print
,
1157 .raw
= trace_bprint_raw
,
1161 static enum print_line_t
trace_print_print(struct trace_iterator
*iter
,
1164 struct print_entry
*field
;
1165 struct trace_seq
*s
= &iter
->seq
;
1167 trace_assign_type(field
, iter
->ent
);
1169 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1172 if (!trace_seq_printf(s
, ": %s", field
->buf
))
1175 return TRACE_TYPE_HANDLED
;
1178 return TRACE_TYPE_PARTIAL_LINE
;
1181 static enum print_line_t
trace_print_raw(struct trace_iterator
*iter
, int flags
)
1183 struct print_entry
*field
;
1185 trace_assign_type(field
, iter
->ent
);
1187 if (!trace_seq_printf(&iter
->seq
, "# %lx %s", field
->ip
, field
->buf
))
1190 return TRACE_TYPE_HANDLED
;
1193 return TRACE_TYPE_PARTIAL_LINE
;
1196 static struct trace_event trace_print_event
= {
1197 .type
= TRACE_PRINT
,
1198 .trace
= trace_print_print
,
1199 .raw
= trace_print_raw
,
1203 static struct trace_event
*events
[] __initdata
= {
1207 &trace_special_event
,
1209 &trace_user_stack_event
,
1210 &trace_bprint_event
,
1215 __init
static int init_events(void)
1217 struct trace_event
*event
;
1220 for (i
= 0; events
[i
]; i
++) {
1223 ret
= register_ftrace_event(event
);
1225 printk(KERN_WARNING
"event %d failed to register\n",
1233 device_initcall(init_events
);