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 enum print_line_t
trace_print_bputs_msg_only(struct trace_iterator
*iter
)
25 struct trace_seq
*s
= &iter
->seq
;
26 struct trace_entry
*entry
= iter
->ent
;
27 struct bputs_entry
*field
;
29 trace_assign_type(field
, entry
);
31 trace_seq_puts(s
, field
->str
);
33 return trace_handle_return(s
);
36 enum print_line_t
trace_print_bprintk_msg_only(struct trace_iterator
*iter
)
38 struct trace_seq
*s
= &iter
->seq
;
39 struct trace_entry
*entry
= iter
->ent
;
40 struct bprint_entry
*field
;
42 trace_assign_type(field
, entry
);
44 trace_seq_bprintf(s
, field
->fmt
, field
->buf
);
46 return trace_handle_return(s
);
49 enum print_line_t
trace_print_printk_msg_only(struct trace_iterator
*iter
)
51 struct trace_seq
*s
= &iter
->seq
;
52 struct trace_entry
*entry
= iter
->ent
;
53 struct print_entry
*field
;
55 trace_assign_type(field
, entry
);
57 trace_seq_puts(s
, field
->buf
);
59 return trace_handle_return(s
);
63 trace_print_flags_seq(struct trace_seq
*p
, const char *delim
,
65 const struct trace_print_flags
*flag_array
)
69 const char *ret
= trace_seq_buffer_ptr(p
);
72 for (i
= 0; flag_array
[i
].name
&& flags
; i
++) {
74 mask
= flag_array
[i
].mask
;
75 if ((flags
& mask
) != mask
)
78 str
= flag_array
[i
].name
;
81 trace_seq_puts(p
, delim
);
84 trace_seq_puts(p
, str
);
87 /* check for left over flags */
90 trace_seq_puts(p
, delim
);
91 trace_seq_printf(p
, "0x%lx", flags
);
98 EXPORT_SYMBOL(trace_print_flags_seq
);
101 trace_print_symbols_seq(struct trace_seq
*p
, unsigned long val
,
102 const struct trace_print_flags
*symbol_array
)
105 const char *ret
= trace_seq_buffer_ptr(p
);
107 for (i
= 0; symbol_array
[i
].name
; i
++) {
109 if (val
!= symbol_array
[i
].mask
)
112 trace_seq_puts(p
, symbol_array
[i
].name
);
116 if (ret
== (const char *)(trace_seq_buffer_ptr(p
)))
117 trace_seq_printf(p
, "0x%lx", val
);
119 trace_seq_putc(p
, 0);
123 EXPORT_SYMBOL(trace_print_symbols_seq
);
125 #if BITS_PER_LONG == 32
127 trace_print_symbols_seq_u64(struct trace_seq
*p
, unsigned long long val
,
128 const struct trace_print_flags_u64
*symbol_array
)
131 const char *ret
= trace_seq_buffer_ptr(p
);
133 for (i
= 0; symbol_array
[i
].name
; i
++) {
135 if (val
!= symbol_array
[i
].mask
)
138 trace_seq_puts(p
, symbol_array
[i
].name
);
142 if (ret
== (const char *)(trace_seq_buffer_ptr(p
)))
143 trace_seq_printf(p
, "0x%llx", val
);
145 trace_seq_putc(p
, 0);
149 EXPORT_SYMBOL(trace_print_symbols_seq_u64
);
153 trace_print_bitmask_seq(struct trace_seq
*p
, void *bitmask_ptr
,
154 unsigned int bitmask_size
)
156 const char *ret
= trace_seq_buffer_ptr(p
);
158 trace_seq_bitmask(p
, bitmask_ptr
, bitmask_size
* 8);
159 trace_seq_putc(p
, 0);
163 EXPORT_SYMBOL_GPL(trace_print_bitmask_seq
);
166 * trace_print_hex_seq - print buffer as hex sequence
167 * @p: trace seq struct to write to
168 * @buf: The buffer to print
169 * @buf_len: Length of @buf in bytes
170 * @concatenate: Print @buf as single hex string or with spacing
172 * Prints the passed buffer as a hex sequence either as a whole,
173 * single hex string if @concatenate is true or with spacing after
174 * each byte in case @concatenate is false.
177 trace_print_hex_seq(struct trace_seq
*p
, const unsigned char *buf
, int buf_len
,
181 const char *ret
= trace_seq_buffer_ptr(p
);
183 for (i
= 0; i
< buf_len
; i
++)
184 trace_seq_printf(p
, "%s%2.2x", concatenate
|| i
== 0 ? "" : " ",
186 trace_seq_putc(p
, 0);
190 EXPORT_SYMBOL(trace_print_hex_seq
);
193 trace_print_array_seq(struct trace_seq
*p
, const void *buf
, int count
,
196 const char *ret
= trace_seq_buffer_ptr(p
);
197 const char *prefix
= "";
198 void *ptr
= (void *)buf
;
199 size_t buf_len
= count
* el_size
;
201 trace_seq_putc(p
, '{');
203 while (ptr
< buf
+ buf_len
) {
206 trace_seq_printf(p
, "%s0x%x", prefix
,
210 trace_seq_printf(p
, "%s0x%x", prefix
,
214 trace_seq_printf(p
, "%s0x%x", prefix
,
218 trace_seq_printf(p
, "%s0x%llx", prefix
,
222 trace_seq_printf(p
, "BAD SIZE:%zu 0x%x", el_size
,
230 trace_seq_putc(p
, '}');
231 trace_seq_putc(p
, 0);
235 EXPORT_SYMBOL(trace_print_array_seq
);
237 int trace_raw_output_prep(struct trace_iterator
*iter
,
238 struct trace_event
*trace_event
)
240 struct trace_event_call
*event
;
241 struct trace_seq
*s
= &iter
->seq
;
242 struct trace_seq
*p
= &iter
->tmp_seq
;
243 struct trace_entry
*entry
;
245 event
= container_of(trace_event
, struct trace_event_call
, event
);
248 if (entry
->type
!= event
->event
.type
) {
250 return TRACE_TYPE_UNHANDLED
;
254 trace_seq_printf(s
, "%s: ", trace_event_name(event
));
256 return trace_handle_return(s
);
258 EXPORT_SYMBOL(trace_raw_output_prep
);
260 static int trace_output_raw(struct trace_iterator
*iter
, char *name
,
261 char *fmt
, va_list ap
)
263 struct trace_seq
*s
= &iter
->seq
;
265 trace_seq_printf(s
, "%s: ", name
);
266 trace_seq_vprintf(s
, fmt
, ap
);
268 return trace_handle_return(s
);
271 int trace_output_call(struct trace_iterator
*iter
, char *name
, char *fmt
, ...)
277 ret
= trace_output_raw(iter
, name
, fmt
, ap
);
282 EXPORT_SYMBOL_GPL(trace_output_call
);
284 #ifdef CONFIG_KRETPROBES
285 static inline const char *kretprobed(const char *name
)
287 static const char tramp_name
[] = "kretprobe_trampoline";
288 int size
= sizeof(tramp_name
);
290 if (strncmp(tramp_name
, name
, size
) == 0)
291 return "[unknown/kretprobe'd]";
295 static inline const char *kretprobed(const char *name
)
299 #endif /* CONFIG_KRETPROBES */
302 seq_print_sym_short(struct trace_seq
*s
, const char *fmt
, unsigned long address
)
304 #ifdef CONFIG_KALLSYMS
305 char str
[KSYM_SYMBOL_LEN
];
308 kallsyms_lookup(address
, NULL
, NULL
, NULL
, str
);
310 name
= kretprobed(str
);
312 trace_seq_printf(s
, fmt
, name
);
317 seq_print_sym_offset(struct trace_seq
*s
, const char *fmt
,
318 unsigned long address
)
320 #ifdef CONFIG_KALLSYMS
321 char str
[KSYM_SYMBOL_LEN
];
324 sprint_symbol(str
, address
);
325 name
= kretprobed(str
);
327 trace_seq_printf(s
, fmt
, name
);
332 # define IP_FMT "%08lx"
334 # define IP_FMT "%016lx"
337 static int seq_print_user_ip(struct trace_seq
*s
, struct mm_struct
*mm
,
338 unsigned long ip
, unsigned long sym_flags
)
340 struct file
*file
= NULL
;
341 unsigned long vmstart
= 0;
348 const struct vm_area_struct
*vma
;
350 down_read(&mm
->mmap_sem
);
351 vma
= find_vma(mm
, ip
);
354 vmstart
= vma
->vm_start
;
357 ret
= trace_seq_path(s
, &file
->f_path
);
359 trace_seq_printf(s
, "[+0x%lx]",
362 up_read(&mm
->mmap_sem
);
364 if (ret
&& ((sym_flags
& TRACE_ITER_SYM_ADDR
) || !file
))
365 trace_seq_printf(s
, " <" IP_FMT
">", ip
);
366 return !trace_seq_has_overflowed(s
);
370 seq_print_ip_sym(struct trace_seq
*s
, unsigned long ip
, unsigned long sym_flags
)
373 trace_seq_putc(s
, '0');
377 if (sym_flags
& TRACE_ITER_SYM_OFFSET
)
378 seq_print_sym_offset(s
, "%s", ip
);
380 seq_print_sym_short(s
, "%s", ip
);
382 if (sym_flags
& TRACE_ITER_SYM_ADDR
)
383 trace_seq_printf(s
, " <" IP_FMT
">", ip
);
386 return !trace_seq_has_overflowed(s
);
390 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
391 * @s: trace seq struct to write to
392 * @entry: The trace entry field from the ring buffer
394 * Prints the generic fields of irqs off, in hard or softirq, preempt
397 int trace_print_lat_fmt(struct trace_seq
*s
, struct trace_entry
*entry
)
406 nmi
= entry
->flags
& TRACE_FLAG_NMI
;
407 hardirq
= entry
->flags
& TRACE_FLAG_HARDIRQ
;
408 softirq
= entry
->flags
& TRACE_FLAG_SOFTIRQ
;
411 (entry
->flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' :
412 (entry
->flags
& TRACE_FLAG_IRQS_NOSUPPORT
) ? 'X' :
415 switch (entry
->flags
& (TRACE_FLAG_NEED_RESCHED
|
416 TRACE_FLAG_PREEMPT_RESCHED
)) {
417 case TRACE_FLAG_NEED_RESCHED
| TRACE_FLAG_PREEMPT_RESCHED
:
420 case TRACE_FLAG_NEED_RESCHED
:
423 case TRACE_FLAG_PREEMPT_RESCHED
:
432 (nmi
&& hardirq
) ? 'Z' :
434 (hardirq
&& softirq
) ? 'H' :
439 trace_seq_printf(s
, "%c%c%c",
440 irqs_off
, need_resched
, hardsoft_irq
);
442 if (entry
->preempt_count
)
443 trace_seq_printf(s
, "%x", entry
->preempt_count
);
445 trace_seq_putc(s
, '.');
447 return !trace_seq_has_overflowed(s
);
451 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
453 char comm
[TASK_COMM_LEN
];
455 trace_find_cmdline(entry
->pid
, comm
);
457 trace_seq_printf(s
, "%8.8s-%-5d %3d",
458 comm
, entry
->pid
, cpu
);
460 return trace_print_lat_fmt(s
, entry
);
464 #define MARK(v, s) {.val = v, .sym = s}
465 /* trace overhead mark */
466 static const struct trace_mark
{
467 unsigned long long val
; /* unit: nsec */
470 MARK(1000000000ULL , '$'), /* 1 sec */
471 MARK(100000000ULL , '@'), /* 100 msec */
472 MARK(10000000ULL , '*'), /* 10 msec */
473 MARK(1000000ULL , '#'), /* 1000 usecs */
474 MARK(100000ULL , '!'), /* 100 usecs */
475 MARK(10000ULL , '+'), /* 10 usecs */
479 char trace_find_mark(unsigned long long d
)
482 int size
= ARRAY_SIZE(mark
);
484 for (i
= 0; i
< size
; i
++) {
489 return (i
== size
) ? ' ' : mark
[i
].sym
;
493 lat_print_timestamp(struct trace_iterator
*iter
, u64 next_ts
)
495 struct trace_array
*tr
= iter
->tr
;
496 unsigned long verbose
= tr
->trace_flags
& TRACE_ITER_VERBOSE
;
497 unsigned long in_ns
= iter
->iter_flags
& TRACE_FILE_TIME_IN_NS
;
498 unsigned long long abs_ts
= iter
->ts
- iter
->trace_buffer
->time_start
;
499 unsigned long long rel_ts
= next_ts
- iter
->ts
;
500 struct trace_seq
*s
= &iter
->seq
;
503 abs_ts
= ns2usecs(abs_ts
);
504 rel_ts
= ns2usecs(rel_ts
);
507 if (verbose
&& in_ns
) {
508 unsigned long abs_usec
= do_div(abs_ts
, USEC_PER_MSEC
);
509 unsigned long abs_msec
= (unsigned long)abs_ts
;
510 unsigned long rel_usec
= do_div(rel_ts
, USEC_PER_MSEC
);
511 unsigned long rel_msec
= (unsigned long)rel_ts
;
514 s
, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
519 } else if (verbose
&& !in_ns
) {
521 s
, "[%016llx] %lld (+%lld): ",
522 iter
->ts
, abs_ts
, rel_ts
);
524 } else if (!verbose
&& in_ns
) {
528 trace_find_mark(rel_ts
* NSEC_PER_USEC
));
530 } else { /* !verbose && !in_ns */
531 trace_seq_printf(s
, " %4lld: ", abs_ts
);
534 return !trace_seq_has_overflowed(s
);
537 int trace_print_context(struct trace_iterator
*iter
)
539 struct trace_array
*tr
= iter
->tr
;
540 struct trace_seq
*s
= &iter
->seq
;
541 struct trace_entry
*entry
= iter
->ent
;
542 unsigned long long t
;
543 unsigned long secs
, usec_rem
;
544 char comm
[TASK_COMM_LEN
];
546 trace_find_cmdline(entry
->pid
, comm
);
548 trace_seq_printf(s
, "%16s-%-5d [%03d] ",
549 comm
, entry
->pid
, iter
->cpu
);
551 if (tr
->trace_flags
& TRACE_ITER_IRQ_INFO
)
552 trace_print_lat_fmt(s
, entry
);
554 if (iter
->iter_flags
& TRACE_FILE_TIME_IN_NS
) {
555 t
= ns2usecs(iter
->ts
);
556 usec_rem
= do_div(t
, USEC_PER_SEC
);
557 secs
= (unsigned long)t
;
558 trace_seq_printf(s
, " %5lu.%06lu: ", secs
, usec_rem
);
560 trace_seq_printf(s
, " %12llu: ", iter
->ts
);
562 return !trace_seq_has_overflowed(s
);
565 int trace_print_lat_context(struct trace_iterator
*iter
)
567 struct trace_array
*tr
= iter
->tr
;
568 /* trace_find_next_entry will reset ent_size */
569 int ent_size
= iter
->ent_size
;
570 struct trace_seq
*s
= &iter
->seq
;
572 struct trace_entry
*entry
= iter
->ent
,
573 *next_entry
= trace_find_next_entry(iter
, NULL
,
575 unsigned long verbose
= (tr
->trace_flags
& TRACE_ITER_VERBOSE
);
577 /* Restore the original ent_size */
578 iter
->ent_size
= ent_size
;
584 char comm
[TASK_COMM_LEN
];
586 trace_find_cmdline(entry
->pid
, comm
);
589 s
, "%16s %5d %3d %d %08x %08lx ",
590 comm
, entry
->pid
, iter
->cpu
, entry
->flags
,
591 entry
->preempt_count
, iter
->idx
);
593 lat_print_generic(s
, entry
, iter
->cpu
);
596 lat_print_timestamp(iter
, next_ts
);
598 return !trace_seq_has_overflowed(s
);
601 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
603 static int task_state_char(unsigned long state
)
605 int bit
= state
? __ffs(state
) + 1 : 0;
607 return bit
< sizeof(state_to_char
) - 1 ? state_to_char
[bit
] : '?';
611 * ftrace_find_event - find a registered event
612 * @type: the type of event to look for
614 * Returns an event of type @type otherwise NULL
615 * Called with trace_event_read_lock() held.
617 struct trace_event
*ftrace_find_event(int type
)
619 struct trace_event
*event
;
622 key
= type
& (EVENT_HASHSIZE
- 1);
624 hlist_for_each_entry(event
, &event_hash
[key
], node
) {
625 if (event
->type
== type
)
632 static LIST_HEAD(ftrace_event_list
);
634 static int trace_search_list(struct list_head
**list
)
636 struct trace_event
*e
;
637 int last
= __TRACE_LAST_TYPE
;
639 if (list_empty(&ftrace_event_list
)) {
640 *list
= &ftrace_event_list
;
645 * We used up all possible max events,
646 * lets see if somebody freed one.
648 list_for_each_entry(e
, &ftrace_event_list
, list
) {
649 if (e
->type
!= last
+ 1)
654 /* Did we used up all 65 thousand events??? */
655 if ((last
+ 1) > TRACE_EVENT_TYPE_MAX
)
662 void trace_event_read_lock(void)
664 down_read(&trace_event_sem
);
667 void trace_event_read_unlock(void)
669 up_read(&trace_event_sem
);
673 * register_trace_event - register output for an event type
674 * @event: the event type to register
676 * Event types are stored in a hash and this hash is used to
677 * find a way to print an event. If the @event->type is set
678 * then it will use that type, otherwise it will assign a
681 * If you assign your own type, please make sure it is added
682 * to the trace_type enum in trace.h, to avoid collisions
683 * with the dynamic types.
685 * Returns the event type number or zero on error.
687 int register_trace_event(struct trace_event
*event
)
692 down_write(&trace_event_sem
);
697 if (WARN_ON(!event
->funcs
))
700 INIT_LIST_HEAD(&event
->list
);
703 struct list_head
*list
= NULL
;
705 if (next_event_type
> TRACE_EVENT_TYPE_MAX
) {
707 event
->type
= trace_search_list(&list
);
713 event
->type
= next_event_type
++;
714 list
= &ftrace_event_list
;
717 if (WARN_ON(ftrace_find_event(event
->type
)))
720 list_add_tail(&event
->list
, list
);
722 } else if (event
->type
> __TRACE_LAST_TYPE
) {
723 printk(KERN_WARNING
"Need to add type to trace.h\n");
727 /* Is this event already used */
728 if (ftrace_find_event(event
->type
))
732 if (event
->funcs
->trace
== NULL
)
733 event
->funcs
->trace
= trace_nop_print
;
734 if (event
->funcs
->raw
== NULL
)
735 event
->funcs
->raw
= trace_nop_print
;
736 if (event
->funcs
->hex
== NULL
)
737 event
->funcs
->hex
= trace_nop_print
;
738 if (event
->funcs
->binary
== NULL
)
739 event
->funcs
->binary
= trace_nop_print
;
741 key
= event
->type
& (EVENT_HASHSIZE
- 1);
743 hlist_add_head(&event
->node
, &event_hash
[key
]);
747 up_write(&trace_event_sem
);
751 EXPORT_SYMBOL_GPL(register_trace_event
);
754 * Used by module code with the trace_event_sem held for write.
756 int __unregister_trace_event(struct trace_event
*event
)
758 hlist_del(&event
->node
);
759 list_del(&event
->list
);
764 * unregister_trace_event - remove a no longer used event
765 * @event: the event to remove
767 int unregister_trace_event(struct trace_event
*event
)
769 down_write(&trace_event_sem
);
770 __unregister_trace_event(event
);
771 up_write(&trace_event_sem
);
775 EXPORT_SYMBOL_GPL(unregister_trace_event
);
781 enum print_line_t
trace_nop_print(struct trace_iterator
*iter
, int flags
,
782 struct trace_event
*event
)
784 trace_seq_printf(&iter
->seq
, "type: %d\n", iter
->ent
->type
);
786 return trace_handle_return(&iter
->seq
);
790 static enum print_line_t
trace_fn_trace(struct trace_iterator
*iter
, int flags
,
791 struct trace_event
*event
)
793 struct ftrace_entry
*field
;
794 struct trace_seq
*s
= &iter
->seq
;
796 trace_assign_type(field
, iter
->ent
);
798 seq_print_ip_sym(s
, field
->ip
, flags
);
800 if ((flags
& TRACE_ITER_PRINT_PARENT
) && field
->parent_ip
) {
801 trace_seq_puts(s
, " <-");
802 seq_print_ip_sym(s
, field
->parent_ip
, flags
);
805 trace_seq_putc(s
, '\n');
807 return trace_handle_return(s
);
810 static enum print_line_t
trace_fn_raw(struct trace_iterator
*iter
, int flags
,
811 struct trace_event
*event
)
813 struct ftrace_entry
*field
;
815 trace_assign_type(field
, iter
->ent
);
817 trace_seq_printf(&iter
->seq
, "%lx %lx\n",
821 return trace_handle_return(&iter
->seq
);
824 static enum print_line_t
trace_fn_hex(struct trace_iterator
*iter
, int flags
,
825 struct trace_event
*event
)
827 struct ftrace_entry
*field
;
828 struct trace_seq
*s
= &iter
->seq
;
830 trace_assign_type(field
, iter
->ent
);
832 SEQ_PUT_HEX_FIELD(s
, field
->ip
);
833 SEQ_PUT_HEX_FIELD(s
, field
->parent_ip
);
835 return trace_handle_return(s
);
838 static enum print_line_t
trace_fn_bin(struct trace_iterator
*iter
, int flags
,
839 struct trace_event
*event
)
841 struct ftrace_entry
*field
;
842 struct trace_seq
*s
= &iter
->seq
;
844 trace_assign_type(field
, iter
->ent
);
846 SEQ_PUT_FIELD(s
, field
->ip
);
847 SEQ_PUT_FIELD(s
, field
->parent_ip
);
849 return trace_handle_return(s
);
852 static struct trace_event_functions trace_fn_funcs
= {
853 .trace
= trace_fn_trace
,
856 .binary
= trace_fn_bin
,
859 static struct trace_event trace_fn_event
= {
861 .funcs
= &trace_fn_funcs
,
864 /* TRACE_CTX an TRACE_WAKE */
865 static enum print_line_t
trace_ctxwake_print(struct trace_iterator
*iter
,
868 struct ctx_switch_entry
*field
;
869 char comm
[TASK_COMM_LEN
];
873 trace_assign_type(field
, iter
->ent
);
875 T
= task_state_char(field
->next_state
);
876 S
= task_state_char(field
->prev_state
);
877 trace_find_cmdline(field
->next_pid
, comm
);
878 trace_seq_printf(&iter
->seq
,
879 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
888 return trace_handle_return(&iter
->seq
);
891 static enum print_line_t
trace_ctx_print(struct trace_iterator
*iter
, int flags
,
892 struct trace_event
*event
)
894 return trace_ctxwake_print(iter
, "==>");
897 static enum print_line_t
trace_wake_print(struct trace_iterator
*iter
,
898 int flags
, struct trace_event
*event
)
900 return trace_ctxwake_print(iter
, " +");
903 static int trace_ctxwake_raw(struct trace_iterator
*iter
, char S
)
905 struct ctx_switch_entry
*field
;
908 trace_assign_type(field
, iter
->ent
);
911 S
= task_state_char(field
->prev_state
);
912 T
= task_state_char(field
->next_state
);
913 trace_seq_printf(&iter
->seq
, "%d %d %c %d %d %d %c\n",
922 return trace_handle_return(&iter
->seq
);
925 static enum print_line_t
trace_ctx_raw(struct trace_iterator
*iter
, int flags
,
926 struct trace_event
*event
)
928 return trace_ctxwake_raw(iter
, 0);
931 static enum print_line_t
trace_wake_raw(struct trace_iterator
*iter
, int flags
,
932 struct trace_event
*event
)
934 return trace_ctxwake_raw(iter
, '+');
938 static int trace_ctxwake_hex(struct trace_iterator
*iter
, char S
)
940 struct ctx_switch_entry
*field
;
941 struct trace_seq
*s
= &iter
->seq
;
944 trace_assign_type(field
, iter
->ent
);
947 S
= task_state_char(field
->prev_state
);
948 T
= task_state_char(field
->next_state
);
950 SEQ_PUT_HEX_FIELD(s
, field
->prev_pid
);
951 SEQ_PUT_HEX_FIELD(s
, field
->prev_prio
);
952 SEQ_PUT_HEX_FIELD(s
, S
);
953 SEQ_PUT_HEX_FIELD(s
, field
->next_cpu
);
954 SEQ_PUT_HEX_FIELD(s
, field
->next_pid
);
955 SEQ_PUT_HEX_FIELD(s
, field
->next_prio
);
956 SEQ_PUT_HEX_FIELD(s
, T
);
958 return trace_handle_return(s
);
961 static enum print_line_t
trace_ctx_hex(struct trace_iterator
*iter
, int flags
,
962 struct trace_event
*event
)
964 return trace_ctxwake_hex(iter
, 0);
967 static enum print_line_t
trace_wake_hex(struct trace_iterator
*iter
, int flags
,
968 struct trace_event
*event
)
970 return trace_ctxwake_hex(iter
, '+');
973 static enum print_line_t
trace_ctxwake_bin(struct trace_iterator
*iter
,
974 int flags
, struct trace_event
*event
)
976 struct ctx_switch_entry
*field
;
977 struct trace_seq
*s
= &iter
->seq
;
979 trace_assign_type(field
, iter
->ent
);
981 SEQ_PUT_FIELD(s
, field
->prev_pid
);
982 SEQ_PUT_FIELD(s
, field
->prev_prio
);
983 SEQ_PUT_FIELD(s
, field
->prev_state
);
984 SEQ_PUT_FIELD(s
, field
->next_cpu
);
985 SEQ_PUT_FIELD(s
, field
->next_pid
);
986 SEQ_PUT_FIELD(s
, field
->next_prio
);
987 SEQ_PUT_FIELD(s
, field
->next_state
);
989 return trace_handle_return(s
);
992 static struct trace_event_functions trace_ctx_funcs
= {
993 .trace
= trace_ctx_print
,
994 .raw
= trace_ctx_raw
,
995 .hex
= trace_ctx_hex
,
996 .binary
= trace_ctxwake_bin
,
999 static struct trace_event trace_ctx_event
= {
1001 .funcs
= &trace_ctx_funcs
,
1004 static struct trace_event_functions trace_wake_funcs
= {
1005 .trace
= trace_wake_print
,
1006 .raw
= trace_wake_raw
,
1007 .hex
= trace_wake_hex
,
1008 .binary
= trace_ctxwake_bin
,
1011 static struct trace_event trace_wake_event
= {
1013 .funcs
= &trace_wake_funcs
,
1018 static enum print_line_t
trace_stack_print(struct trace_iterator
*iter
,
1019 int flags
, struct trace_event
*event
)
1021 struct stack_entry
*field
;
1022 struct trace_seq
*s
= &iter
->seq
;
1026 trace_assign_type(field
, iter
->ent
);
1027 end
= (unsigned long *)((long)iter
->ent
+ iter
->ent_size
);
1029 trace_seq_puts(s
, "<stack trace>\n");
1031 for (p
= field
->caller
; p
&& *p
!= ULONG_MAX
&& p
< end
; p
++) {
1033 if (trace_seq_has_overflowed(s
))
1036 trace_seq_puts(s
, " => ");
1037 seq_print_ip_sym(s
, *p
, flags
);
1038 trace_seq_putc(s
, '\n');
1041 return trace_handle_return(s
);
1044 static struct trace_event_functions trace_stack_funcs
= {
1045 .trace
= trace_stack_print
,
1048 static struct trace_event trace_stack_event
= {
1049 .type
= TRACE_STACK
,
1050 .funcs
= &trace_stack_funcs
,
1053 /* TRACE_USER_STACK */
1054 static enum print_line_t
trace_user_stack_print(struct trace_iterator
*iter
,
1055 int flags
, struct trace_event
*event
)
1057 struct trace_array
*tr
= iter
->tr
;
1058 struct userstack_entry
*field
;
1059 struct trace_seq
*s
= &iter
->seq
;
1060 struct mm_struct
*mm
= NULL
;
1063 trace_assign_type(field
, iter
->ent
);
1065 trace_seq_puts(s
, "<user stack trace>\n");
1067 if (tr
->trace_flags
& TRACE_ITER_SYM_USEROBJ
) {
1068 struct task_struct
*task
;
1070 * we do the lookup on the thread group leader,
1071 * since individual threads might have already quit!
1074 task
= find_task_by_vpid(field
->tgid
);
1076 mm
= get_task_mm(task
);
1080 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1081 unsigned long ip
= field
->caller
[i
];
1083 if (ip
== ULONG_MAX
|| trace_seq_has_overflowed(s
))
1086 trace_seq_puts(s
, " => ");
1089 trace_seq_puts(s
, "??");
1090 trace_seq_putc(s
, '\n');
1094 seq_print_user_ip(s
, mm
, ip
, flags
);
1095 trace_seq_putc(s
, '\n');
1101 return trace_handle_return(s
);
1104 static struct trace_event_functions trace_user_stack_funcs
= {
1105 .trace
= trace_user_stack_print
,
1108 static struct trace_event trace_user_stack_event
= {
1109 .type
= TRACE_USER_STACK
,
1110 .funcs
= &trace_user_stack_funcs
,
1114 static enum print_line_t
1115 trace_hwlat_print(struct trace_iterator
*iter
, int flags
,
1116 struct trace_event
*event
)
1118 struct trace_entry
*entry
= iter
->ent
;
1119 struct trace_seq
*s
= &iter
->seq
;
1120 struct hwlat_entry
*field
;
1122 trace_assign_type(field
, entry
);
1124 trace_seq_printf(s
, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
1127 field
->outer_duration
,
1128 field
->timestamp
.tv_sec
,
1129 field
->timestamp
.tv_nsec
);
1131 if (field
->nmi_count
) {
1133 * The generic sched_clock() is not NMI safe, thus
1134 * we only record the count and not the time.
1136 if (!IS_ENABLED(CONFIG_GENERIC_SCHED_CLOCK
))
1137 trace_seq_printf(s
, " nmi-total:%llu",
1138 field
->nmi_total_ts
);
1139 trace_seq_printf(s
, " nmi-count:%u",
1143 trace_seq_putc(s
, '\n');
1145 return trace_handle_return(s
);
1149 static enum print_line_t
1150 trace_hwlat_raw(struct trace_iterator
*iter
, int flags
,
1151 struct trace_event
*event
)
1153 struct hwlat_entry
*field
;
1154 struct trace_seq
*s
= &iter
->seq
;
1156 trace_assign_type(field
, iter
->ent
);
1158 trace_seq_printf(s
, "%llu %lld %ld %09ld %u\n",
1160 field
->outer_duration
,
1161 field
->timestamp
.tv_sec
,
1162 field
->timestamp
.tv_nsec
,
1165 return trace_handle_return(s
);
1168 static struct trace_event_functions trace_hwlat_funcs
= {
1169 .trace
= trace_hwlat_print
,
1170 .raw
= trace_hwlat_raw
,
1173 static struct trace_event trace_hwlat_event
= {
1174 .type
= TRACE_HWLAT
,
1175 .funcs
= &trace_hwlat_funcs
,
1179 static enum print_line_t
1180 trace_bputs_print(struct trace_iterator
*iter
, int flags
,
1181 struct trace_event
*event
)
1183 struct trace_entry
*entry
= iter
->ent
;
1184 struct trace_seq
*s
= &iter
->seq
;
1185 struct bputs_entry
*field
;
1187 trace_assign_type(field
, entry
);
1189 seq_print_ip_sym(s
, field
->ip
, flags
);
1190 trace_seq_puts(s
, ": ");
1191 trace_seq_puts(s
, field
->str
);
1193 return trace_handle_return(s
);
1197 static enum print_line_t
1198 trace_bputs_raw(struct trace_iterator
*iter
, int flags
,
1199 struct trace_event
*event
)
1201 struct bputs_entry
*field
;
1202 struct trace_seq
*s
= &iter
->seq
;
1204 trace_assign_type(field
, iter
->ent
);
1206 trace_seq_printf(s
, ": %lx : ", field
->ip
);
1207 trace_seq_puts(s
, field
->str
);
1209 return trace_handle_return(s
);
1212 static struct trace_event_functions trace_bputs_funcs
= {
1213 .trace
= trace_bputs_print
,
1214 .raw
= trace_bputs_raw
,
1217 static struct trace_event trace_bputs_event
= {
1218 .type
= TRACE_BPUTS
,
1219 .funcs
= &trace_bputs_funcs
,
1223 static enum print_line_t
1224 trace_bprint_print(struct trace_iterator
*iter
, int flags
,
1225 struct trace_event
*event
)
1227 struct trace_entry
*entry
= iter
->ent
;
1228 struct trace_seq
*s
= &iter
->seq
;
1229 struct bprint_entry
*field
;
1231 trace_assign_type(field
, entry
);
1233 seq_print_ip_sym(s
, field
->ip
, flags
);
1234 trace_seq_puts(s
, ": ");
1235 trace_seq_bprintf(s
, field
->fmt
, field
->buf
);
1237 return trace_handle_return(s
);
1241 static enum print_line_t
1242 trace_bprint_raw(struct trace_iterator
*iter
, int flags
,
1243 struct trace_event
*event
)
1245 struct bprint_entry
*field
;
1246 struct trace_seq
*s
= &iter
->seq
;
1248 trace_assign_type(field
, iter
->ent
);
1250 trace_seq_printf(s
, ": %lx : ", field
->ip
);
1251 trace_seq_bprintf(s
, field
->fmt
, field
->buf
);
1253 return trace_handle_return(s
);
1256 static struct trace_event_functions trace_bprint_funcs
= {
1257 .trace
= trace_bprint_print
,
1258 .raw
= trace_bprint_raw
,
1261 static struct trace_event trace_bprint_event
= {
1262 .type
= TRACE_BPRINT
,
1263 .funcs
= &trace_bprint_funcs
,
1267 static enum print_line_t
trace_print_print(struct trace_iterator
*iter
,
1268 int flags
, struct trace_event
*event
)
1270 struct print_entry
*field
;
1271 struct trace_seq
*s
= &iter
->seq
;
1273 trace_assign_type(field
, iter
->ent
);
1275 seq_print_ip_sym(s
, field
->ip
, flags
);
1276 trace_seq_printf(s
, ": %s", field
->buf
);
1278 return trace_handle_return(s
);
1281 static enum print_line_t
trace_print_raw(struct trace_iterator
*iter
, int flags
,
1282 struct trace_event
*event
)
1284 struct print_entry
*field
;
1286 trace_assign_type(field
, iter
->ent
);
1288 trace_seq_printf(&iter
->seq
, "# %lx %s", field
->ip
, field
->buf
);
1290 return trace_handle_return(&iter
->seq
);
1293 static struct trace_event_functions trace_print_funcs
= {
1294 .trace
= trace_print_print
,
1295 .raw
= trace_print_raw
,
1298 static struct trace_event trace_print_event
= {
1299 .type
= TRACE_PRINT
,
1300 .funcs
= &trace_print_funcs
,
1303 static enum print_line_t
trace_raw_data(struct trace_iterator
*iter
, int flags
,
1304 struct trace_event
*event
)
1306 struct raw_data_entry
*field
;
1309 trace_assign_type(field
, iter
->ent
);
1311 trace_seq_printf(&iter
->seq
, "# %x buf:", field
->id
);
1313 for (i
= 0; i
< iter
->ent_size
- offsetof(struct raw_data_entry
, buf
); i
++)
1314 trace_seq_printf(&iter
->seq
, " %02x",
1315 (unsigned char)field
->buf
[i
]);
1317 trace_seq_putc(&iter
->seq
, '\n');
1319 return trace_handle_return(&iter
->seq
);
1322 static struct trace_event_functions trace_raw_data_funcs
= {
1323 .trace
= trace_raw_data
,
1324 .raw
= trace_raw_data
,
1327 static struct trace_event trace_raw_data_event
= {
1328 .type
= TRACE_RAW_DATA
,
1329 .funcs
= &trace_raw_data_funcs
,
1333 static struct trace_event
*events
[] __initdata
= {
1338 &trace_user_stack_event
,
1340 &trace_bprint_event
,
1343 &trace_raw_data_event
,
1347 __init
static int init_events(void)
1349 struct trace_event
*event
;
1352 for (i
= 0; events
[i
]; i
++) {
1355 ret
= register_trace_event(event
);
1357 printk(KERN_WARNING
"event %d failed to register\n",
1365 early_initcall(init_events
);