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(struct trace_seq *p, const unsigned char *buf, int buf_len,
170 const char *ret = trace_seq_buffer_ptr(p);
172 for (i = 0; i < buf_len; i++)
173 trace_seq_printf(p, "%s%2.2x", !spacing || i == 0 ? "" : " ",
175 trace_seq_putc(p, 0);
179 EXPORT_SYMBOL(trace_print_hex_seq);
182 trace_print_array_seq(struct trace_seq *p, const void *buf, int count,
185 const char *ret = trace_seq_buffer_ptr(p);
186 const char *prefix = "";
187 void *ptr = (void *)buf;
188 size_t buf_len = count * el_size;
190 trace_seq_putc(p, '{');
192 while (ptr < buf + buf_len) {
195 trace_seq_printf(p, "%s0x%x", prefix,
199 trace_seq_printf(p, "%s0x%x", prefix,
203 trace_seq_printf(p, "%s0x%x", prefix,
207 trace_seq_printf(p, "%s0x%llx", prefix,
211 trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size,
219 trace_seq_putc(p, '}');
220 trace_seq_putc(p, 0);
224 EXPORT_SYMBOL(trace_print_array_seq);
226 int trace_raw_output_prep(struct trace_iterator *iter,
227 struct trace_event *trace_event)
229 struct trace_event_call *event;
230 struct trace_seq *s = &iter->seq;
231 struct trace_seq *p = &iter->tmp_seq;
232 struct trace_entry *entry;
234 event = container_of(trace_event, struct trace_event_call, event);
237 if (entry->type != event->event.type) {
239 return TRACE_TYPE_UNHANDLED;
243 trace_seq_printf(s, "%s: ", trace_event_name(event));
245 return trace_handle_return(s);
247 EXPORT_SYMBOL(trace_raw_output_prep);
249 static int trace_output_raw(struct trace_iterator *iter, char *name,
250 char *fmt, va_list ap)
252 struct trace_seq *s = &iter->seq;
254 trace_seq_printf(s, "%s: ", name);
255 trace_seq_vprintf(s, fmt, ap);
257 return trace_handle_return(s);
260 int trace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
266 ret = trace_output_raw(iter, name, fmt, ap);
271 EXPORT_SYMBOL_GPL(trace_output_call);
273 #ifdef CONFIG_KRETPROBES
274 static inline const char *kretprobed(const char *name)
276 static const char tramp_name[] = "kretprobe_trampoline";
277 int size = sizeof(tramp_name);
279 if (strncmp(tramp_name, name, size) == 0)
280 return "[unknown/kretprobe'd]";
284 static inline const char *kretprobed(const char *name)
288 #endif /* CONFIG_KRETPROBES */
291 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
293 #ifdef CONFIG_KALLSYMS
294 char str[KSYM_SYMBOL_LEN];
297 kallsyms_lookup(address, NULL, NULL, NULL, str);
299 name = kretprobed(str);
301 trace_seq_printf(s, fmt, name);
306 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
307 unsigned long address)
309 #ifdef CONFIG_KALLSYMS
310 char str[KSYM_SYMBOL_LEN];
313 sprint_symbol(str, address);
314 name = kretprobed(str);
316 trace_seq_printf(s, fmt, name);
321 # define IP_FMT "%08lx"
323 # define IP_FMT "%016lx"
326 static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
327 unsigned long ip, unsigned long sym_flags)
329 struct file *file = NULL;
330 unsigned long vmstart = 0;
337 const struct vm_area_struct *vma;
339 down_read(&mm->mmap_sem);
340 vma = find_vma(mm, ip);
343 vmstart = vma->vm_start;
346 ret = trace_seq_path(s, &file->f_path);
348 trace_seq_printf(s, "[+0x%lx]",
351 up_read(&mm->mmap_sem);
353 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
354 trace_seq_printf(s, " <" IP_FMT ">", ip);
355 return !trace_seq_has_overflowed(s);
359 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
362 trace_seq_putc(s, '0');
366 if (sym_flags & TRACE_ITER_SYM_OFFSET)
367 seq_print_sym_offset(s, "%s", ip);
369 seq_print_sym_short(s, "%s", ip);
371 if (sym_flags & TRACE_ITER_SYM_ADDR)
372 trace_seq_printf(s, " <" IP_FMT ">", ip);
375 return !trace_seq_has_overflowed(s);
379 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
380 * @s: trace seq struct to write to
381 * @entry: The trace entry field from the ring buffer
383 * Prints the generic fields of irqs off, in hard or softirq, preempt
386 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
395 nmi = entry->flags & TRACE_FLAG_NMI;
396 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
397 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
400 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
401 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
404 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
405 TRACE_FLAG_PREEMPT_RESCHED)) {
406 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
409 case TRACE_FLAG_NEED_RESCHED:
412 case TRACE_FLAG_PREEMPT_RESCHED:
421 (nmi && hardirq) ? 'Z' :
423 (hardirq && softirq) ? 'H' :
428 trace_seq_printf(s, "%c%c%c",
429 irqs_off, need_resched, hardsoft_irq);
431 if (entry->preempt_count)
432 trace_seq_printf(s, "%x", entry->preempt_count);
434 trace_seq_putc(s, '.');
436 return !trace_seq_has_overflowed(s);
440 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
442 char comm[TASK_COMM_LEN];
444 trace_find_cmdline(entry->pid, comm);
446 trace_seq_printf(s, "%8.8s-%-5d %3d",
447 comm, entry->pid, cpu);
449 return trace_print_lat_fmt(s, entry);
453 #define MARK(v, s) {.val = v, .sym = s}
454 /* trace overhead mark */
455 static const struct trace_mark {
456 unsigned long long val; /* unit: nsec */
459 MARK(1000000000ULL , '$'), /* 1 sec */
460 MARK(100000000ULL , '@'), /* 100 msec */
461 MARK(10000000ULL , '*'), /* 10 msec */
462 MARK(1000000ULL , '#'), /* 1000 usecs */
463 MARK(100000ULL , '!'), /* 100 usecs */
464 MARK(10000ULL , '+'), /* 10 usecs */
468 char trace_find_mark(unsigned long long d)
471 int size = ARRAY_SIZE(mark);
473 for (i = 0; i < size; i++) {
478 return (i == size) ? ' ' : mark[i].sym;
482 lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
484 struct trace_array *tr = iter->tr;
485 unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE;
486 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
487 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
488 unsigned long long rel_ts = next_ts - iter->ts;
489 struct trace_seq *s = &iter->seq;
492 abs_ts = ns2usecs(abs_ts);
493 rel_ts = ns2usecs(rel_ts);
496 if (verbose && in_ns) {
497 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
498 unsigned long abs_msec = (unsigned long)abs_ts;
499 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
500 unsigned long rel_msec = (unsigned long)rel_ts;
503 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
508 } else if (verbose && !in_ns) {
510 s, "[%016llx] %lld (+%lld): ",
511 iter->ts, abs_ts, rel_ts);
513 } else if (!verbose && in_ns) {
517 trace_find_mark(rel_ts * NSEC_PER_USEC));
519 } else { /* !verbose && !in_ns */
520 trace_seq_printf(s, " %4lld: ", abs_ts);
523 return !trace_seq_has_overflowed(s);
526 int trace_print_context(struct trace_iterator *iter)
528 struct trace_array *tr = iter->tr;
529 struct trace_seq *s = &iter->seq;
530 struct trace_entry *entry = iter->ent;
531 unsigned long long t;
532 unsigned long secs, usec_rem;
533 char comm[TASK_COMM_LEN];
535 trace_find_cmdline(entry->pid, comm);
537 trace_seq_printf(s, "%16s-%-5d [%03d] ",
538 comm, entry->pid, iter->cpu);
540 if (tr->trace_flags & TRACE_ITER_IRQ_INFO)
541 trace_print_lat_fmt(s, entry);
543 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
544 t = ns2usecs(iter->ts);
545 usec_rem = do_div(t, USEC_PER_SEC);
546 secs = (unsigned long)t;
547 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
549 trace_seq_printf(s, " %12llu: ", iter->ts);
551 return !trace_seq_has_overflowed(s);
554 int trace_print_lat_context(struct trace_iterator *iter)
556 struct trace_array *tr = iter->tr;
557 /* trace_find_next_entry will reset ent_size */
558 int ent_size = iter->ent_size;
559 struct trace_seq *s = &iter->seq;
561 struct trace_entry *entry = iter->ent,
562 *next_entry = trace_find_next_entry(iter, NULL,
564 unsigned long verbose = (tr->trace_flags & TRACE_ITER_VERBOSE);
566 /* Restore the original ent_size */
567 iter->ent_size = ent_size;
573 char comm[TASK_COMM_LEN];
575 trace_find_cmdline(entry->pid, comm);
578 s, "%16s %5d %3d %d %08x %08lx ",
579 comm, entry->pid, iter->cpu, entry->flags,
580 entry->preempt_count, iter->idx);
582 lat_print_generic(s, entry, iter->cpu);
585 lat_print_timestamp(iter, next_ts);
587 return !trace_seq_has_overflowed(s);
590 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
592 static int task_state_char(unsigned long state)
594 int bit = state ? __ffs(state) + 1 : 0;
596 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
600 * ftrace_find_event - find a registered event
601 * @type: the type of event to look for
603 * Returns an event of type @type otherwise NULL
604 * Called with trace_event_read_lock() held.
606 struct trace_event *ftrace_find_event(int type)
608 struct trace_event *event;
611 key = type & (EVENT_HASHSIZE - 1);
613 hlist_for_each_entry(event, &event_hash[key], node) {
614 if (event->type == type)
621 static LIST_HEAD(ftrace_event_list);
623 static int trace_search_list(struct list_head **list)
625 struct trace_event *e;
626 int last = __TRACE_LAST_TYPE;
628 if (list_empty(&ftrace_event_list)) {
629 *list = &ftrace_event_list;
634 * We used up all possible max events,
635 * lets see if somebody freed one.
637 list_for_each_entry(e, &ftrace_event_list, list) {
638 if (e->type != last + 1)
643 /* Did we used up all 65 thousand events??? */
644 if ((last + 1) > TRACE_EVENT_TYPE_MAX)
651 void trace_event_read_lock(void)
653 down_read(&trace_event_sem);
656 void trace_event_read_unlock(void)
658 up_read(&trace_event_sem);
662 * register_trace_event - register output for an event type
663 * @event: the event type to register
665 * Event types are stored in a hash and this hash is used to
666 * find a way to print an event. If the @event->type is set
667 * then it will use that type, otherwise it will assign a
670 * If you assign your own type, please make sure it is added
671 * to the trace_type enum in trace.h, to avoid collisions
672 * with the dynamic types.
674 * Returns the event type number or zero on error.
676 int register_trace_event(struct trace_event *event)
681 down_write(&trace_event_sem);
686 if (WARN_ON(!event->funcs))
689 INIT_LIST_HEAD(&event->list);
692 struct list_head *list = NULL;
694 if (next_event_type > TRACE_EVENT_TYPE_MAX) {
696 event->type = trace_search_list(&list);
702 event->type = next_event_type++;
703 list = &ftrace_event_list;
706 if (WARN_ON(ftrace_find_event(event->type)))
709 list_add_tail(&event->list, list);
711 } else if (event->type > __TRACE_LAST_TYPE) {
712 printk(KERN_WARNING "Need to add type to trace.h\n");
716 /* Is this event already used */
717 if (ftrace_find_event(event->type))
721 if (event->funcs->trace == NULL)
722 event->funcs->trace = trace_nop_print;
723 if (event->funcs->raw == NULL)
724 event->funcs->raw = trace_nop_print;
725 if (event->funcs->hex == NULL)
726 event->funcs->hex = trace_nop_print;
727 if (event->funcs->binary == NULL)
728 event->funcs->binary = trace_nop_print;
730 key = event->type & (EVENT_HASHSIZE - 1);
732 hlist_add_head(&event->node, &event_hash[key]);
736 up_write(&trace_event_sem);
740 EXPORT_SYMBOL_GPL(register_trace_event);
743 * Used by module code with the trace_event_sem held for write.
745 int __unregister_trace_event(struct trace_event *event)
747 hlist_del(&event->node);
748 list_del(&event->list);
753 * unregister_trace_event - remove a no longer used event
754 * @event: the event to remove
756 int unregister_trace_event(struct trace_event *event)
758 down_write(&trace_event_sem);
759 __unregister_trace_event(event);
760 up_write(&trace_event_sem);
764 EXPORT_SYMBOL_GPL(unregister_trace_event);
770 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
771 struct trace_event *event)
773 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
775 return trace_handle_return(&iter->seq);
779 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
780 struct trace_event *event)
782 struct ftrace_entry *field;
783 struct trace_seq *s = &iter->seq;
785 trace_assign_type(field, iter->ent);
787 seq_print_ip_sym(s, field->ip, flags);
789 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
790 trace_seq_puts(s, " <-");
791 seq_print_ip_sym(s, field->parent_ip, flags);
794 trace_seq_putc(s, '\n');
796 return trace_handle_return(s);
799 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
800 struct trace_event *event)
802 struct ftrace_entry *field;
804 trace_assign_type(field, iter->ent);
806 trace_seq_printf(&iter->seq, "%lx %lx\n",
810 return trace_handle_return(&iter->seq);
813 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
814 struct trace_event *event)
816 struct ftrace_entry *field;
817 struct trace_seq *s = &iter->seq;
819 trace_assign_type(field, iter->ent);
821 SEQ_PUT_HEX_FIELD(s, field->ip);
822 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
824 return trace_handle_return(s);
827 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
828 struct trace_event *event)
830 struct ftrace_entry *field;
831 struct trace_seq *s = &iter->seq;
833 trace_assign_type(field, iter->ent);
835 SEQ_PUT_FIELD(s, field->ip);
836 SEQ_PUT_FIELD(s, field->parent_ip);
838 return trace_handle_return(s);
841 static struct trace_event_functions trace_fn_funcs = {
842 .trace = trace_fn_trace,
845 .binary = trace_fn_bin,
848 static struct trace_event trace_fn_event = {
850 .funcs = &trace_fn_funcs,
853 /* TRACE_CTX an TRACE_WAKE */
854 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
857 struct ctx_switch_entry *field;
858 char comm[TASK_COMM_LEN];
862 trace_assign_type(field, iter->ent);
864 T = task_state_char(field->next_state);
865 S = task_state_char(field->prev_state);
866 trace_find_cmdline(field->next_pid, comm);
867 trace_seq_printf(&iter->seq,
868 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
877 return trace_handle_return(&iter->seq);
880 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
881 struct trace_event *event)
883 return trace_ctxwake_print(iter, "==>");
886 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
887 int flags, struct trace_event *event)
889 return trace_ctxwake_print(iter, " +");
892 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
894 struct ctx_switch_entry *field;
897 trace_assign_type(field, iter->ent);
900 S = task_state_char(field->prev_state);
901 T = task_state_char(field->next_state);
902 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
911 return trace_handle_return(&iter->seq);
914 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
915 struct trace_event *event)
917 return trace_ctxwake_raw(iter, 0);
920 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
921 struct trace_event *event)
923 return trace_ctxwake_raw(iter, '+');
927 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
929 struct ctx_switch_entry *field;
930 struct trace_seq *s = &iter->seq;
933 trace_assign_type(field, iter->ent);
936 S = task_state_char(field->prev_state);
937 T = task_state_char(field->next_state);
939 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
940 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
941 SEQ_PUT_HEX_FIELD(s, S);
942 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
943 SEQ_PUT_HEX_FIELD(s, field->next_pid);
944 SEQ_PUT_HEX_FIELD(s, field->next_prio);
945 SEQ_PUT_HEX_FIELD(s, T);
947 return trace_handle_return(s);
950 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
951 struct trace_event *event)
953 return trace_ctxwake_hex(iter, 0);
956 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
957 struct trace_event *event)
959 return trace_ctxwake_hex(iter, '+');
962 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
963 int flags, struct trace_event *event)
965 struct ctx_switch_entry *field;
966 struct trace_seq *s = &iter->seq;
968 trace_assign_type(field, iter->ent);
970 SEQ_PUT_FIELD(s, field->prev_pid);
971 SEQ_PUT_FIELD(s, field->prev_prio);
972 SEQ_PUT_FIELD(s, field->prev_state);
973 SEQ_PUT_FIELD(s, field->next_cpu);
974 SEQ_PUT_FIELD(s, field->next_pid);
975 SEQ_PUT_FIELD(s, field->next_prio);
976 SEQ_PUT_FIELD(s, field->next_state);
978 return trace_handle_return(s);
981 static struct trace_event_functions trace_ctx_funcs = {
982 .trace = trace_ctx_print,
983 .raw = trace_ctx_raw,
984 .hex = trace_ctx_hex,
985 .binary = trace_ctxwake_bin,
988 static struct trace_event trace_ctx_event = {
990 .funcs = &trace_ctx_funcs,
993 static struct trace_event_functions trace_wake_funcs = {
994 .trace = trace_wake_print,
995 .raw = trace_wake_raw,
996 .hex = trace_wake_hex,
997 .binary = trace_ctxwake_bin,
1000 static struct trace_event trace_wake_event = {
1002 .funcs = &trace_wake_funcs,
1007 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1008 int flags, struct trace_event *event)
1010 struct stack_entry *field;
1011 struct trace_seq *s = &iter->seq;
1015 trace_assign_type(field, iter->ent);
1016 end = (unsigned long *)((long)iter->ent + iter->ent_size);
1018 trace_seq_puts(s, "<stack trace>\n");
1020 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
1022 if (trace_seq_has_overflowed(s))
1025 trace_seq_puts(s, " => ");
1026 seq_print_ip_sym(s, *p, flags);
1027 trace_seq_putc(s, '\n');
1030 return trace_handle_return(s);
1033 static struct trace_event_functions trace_stack_funcs = {
1034 .trace = trace_stack_print,
1037 static struct trace_event trace_stack_event = {
1038 .type = TRACE_STACK,
1039 .funcs = &trace_stack_funcs,
1042 /* TRACE_USER_STACK */
1043 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1044 int flags, struct trace_event *event)
1046 struct trace_array *tr = iter->tr;
1047 struct userstack_entry *field;
1048 struct trace_seq *s = &iter->seq;
1049 struct mm_struct *mm = NULL;
1052 trace_assign_type(field, iter->ent);
1054 trace_seq_puts(s, "<user stack trace>\n");
1056 if (tr->trace_flags & TRACE_ITER_SYM_USEROBJ) {
1057 struct task_struct *task;
1059 * we do the lookup on the thread group leader,
1060 * since individual threads might have already quit!
1063 task = find_task_by_vpid(field->tgid);
1065 mm = get_task_mm(task);
1069 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1070 unsigned long ip = field->caller[i];
1072 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
1075 trace_seq_puts(s, " => ");
1078 trace_seq_puts(s, "??");
1079 trace_seq_putc(s, '\n');
1083 seq_print_user_ip(s, mm, ip, flags);
1084 trace_seq_putc(s, '\n');
1090 return trace_handle_return(s);
1093 static struct trace_event_functions trace_user_stack_funcs = {
1094 .trace = trace_user_stack_print,
1097 static struct trace_event trace_user_stack_event = {
1098 .type = TRACE_USER_STACK,
1099 .funcs = &trace_user_stack_funcs,
1103 static enum print_line_t
1104 trace_hwlat_print(struct trace_iterator *iter, int flags,
1105 struct trace_event *event)
1107 struct trace_entry *entry = iter->ent;
1108 struct trace_seq *s = &iter->seq;
1109 struct hwlat_entry *field;
1111 trace_assign_type(field, entry);
1113 trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
1116 field->outer_duration,
1117 field->timestamp.tv_sec,
1118 field->timestamp.tv_nsec);
1120 if (field->nmi_count) {
1122 * The generic sched_clock() is not NMI safe, thus
1123 * we only record the count and not the time.
1125 if (!IS_ENABLED(CONFIG_GENERIC_SCHED_CLOCK))
1126 trace_seq_printf(s, " nmi-total:%llu",
1127 field->nmi_total_ts);
1128 trace_seq_printf(s, " nmi-count:%u",
1132 trace_seq_putc(s, '\n');
1134 return trace_handle_return(s);
1138 static enum print_line_t
1139 trace_hwlat_raw(struct trace_iterator *iter, int flags,
1140 struct trace_event *event)
1142 struct hwlat_entry *field;
1143 struct trace_seq *s = &iter->seq;
1145 trace_assign_type(field, iter->ent);
1147 trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
1149 field->outer_duration,
1150 field->timestamp.tv_sec,
1151 field->timestamp.tv_nsec,
1154 return trace_handle_return(s);
1157 static struct trace_event_functions trace_hwlat_funcs = {
1158 .trace = trace_hwlat_print,
1159 .raw = trace_hwlat_raw,
1162 static struct trace_event trace_hwlat_event = {
1163 .type = TRACE_HWLAT,
1164 .funcs = &trace_hwlat_funcs,
1168 static enum print_line_t
1169 trace_bputs_print(struct trace_iterator *iter, int flags,
1170 struct trace_event *event)
1172 struct trace_entry *entry = iter->ent;
1173 struct trace_seq *s = &iter->seq;
1174 struct bputs_entry *field;
1176 trace_assign_type(field, entry);
1178 seq_print_ip_sym(s, field->ip, flags);
1179 trace_seq_puts(s, ": ");
1180 trace_seq_puts(s, field->str);
1182 return trace_handle_return(s);
1186 static enum print_line_t
1187 trace_bputs_raw(struct trace_iterator *iter, int flags,
1188 struct trace_event *event)
1190 struct bputs_entry *field;
1191 struct trace_seq *s = &iter->seq;
1193 trace_assign_type(field, iter->ent);
1195 trace_seq_printf(s, ": %lx : ", field->ip);
1196 trace_seq_puts(s, field->str);
1198 return trace_handle_return(s);
1201 static struct trace_event_functions trace_bputs_funcs = {
1202 .trace = trace_bputs_print,
1203 .raw = trace_bputs_raw,
1206 static struct trace_event trace_bputs_event = {
1207 .type = TRACE_BPUTS,
1208 .funcs = &trace_bputs_funcs,
1212 static enum print_line_t
1213 trace_bprint_print(struct trace_iterator *iter, int flags,
1214 struct trace_event *event)
1216 struct trace_entry *entry = iter->ent;
1217 struct trace_seq *s = &iter->seq;
1218 struct bprint_entry *field;
1220 trace_assign_type(field, entry);
1222 seq_print_ip_sym(s, field->ip, flags);
1223 trace_seq_puts(s, ": ");
1224 trace_seq_bprintf(s, field->fmt, field->buf);
1226 return trace_handle_return(s);
1230 static enum print_line_t
1231 trace_bprint_raw(struct trace_iterator *iter, int flags,
1232 struct trace_event *event)
1234 struct bprint_entry *field;
1235 struct trace_seq *s = &iter->seq;
1237 trace_assign_type(field, iter->ent);
1239 trace_seq_printf(s, ": %lx : ", field->ip);
1240 trace_seq_bprintf(s, field->fmt, field->buf);
1242 return trace_handle_return(s);
1245 static struct trace_event_functions trace_bprint_funcs = {
1246 .trace = trace_bprint_print,
1247 .raw = trace_bprint_raw,
1250 static struct trace_event trace_bprint_event = {
1251 .type = TRACE_BPRINT,
1252 .funcs = &trace_bprint_funcs,
1256 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1257 int flags, struct trace_event *event)
1259 struct print_entry *field;
1260 struct trace_seq *s = &iter->seq;
1262 trace_assign_type(field, iter->ent);
1264 seq_print_ip_sym(s, field->ip, flags);
1265 trace_seq_printf(s, ": %s", field->buf);
1267 return trace_handle_return(s);
1270 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1271 struct trace_event *event)
1273 struct print_entry *field;
1275 trace_assign_type(field, iter->ent);
1277 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
1279 return trace_handle_return(&iter->seq);
1282 static struct trace_event_functions trace_print_funcs = {
1283 .trace = trace_print_print,
1284 .raw = trace_print_raw,
1287 static struct trace_event trace_print_event = {
1288 .type = TRACE_PRINT,
1289 .funcs = &trace_print_funcs,
1292 static enum print_line_t trace_raw_data(struct trace_iterator *iter, int flags,
1293 struct trace_event *event)
1295 struct raw_data_entry *field;
1298 trace_assign_type(field, iter->ent);
1300 trace_seq_printf(&iter->seq, "# %x buf:", field->id);
1302 for (i = 0; i < iter->ent_size - offsetof(struct raw_data_entry, buf); i++)
1303 trace_seq_printf(&iter->seq, " %02x",
1304 (unsigned char)field->buf[i]);
1306 trace_seq_putc(&iter->seq, '\n');
1308 return trace_handle_return(&iter->seq);
1311 static struct trace_event_functions trace_raw_data_funcs = {
1312 .trace = trace_raw_data,
1313 .raw = trace_raw_data,
1316 static struct trace_event trace_raw_data_event = {
1317 .type = TRACE_RAW_DATA,
1318 .funcs = &trace_raw_data_funcs,
1322 static struct trace_event *events[] __initdata = {
1327 &trace_user_stack_event,
1329 &trace_bprint_event,
1332 &trace_raw_data_event,
1336 __init static int init_events(void)
1338 struct trace_event *event;
1341 for (i = 0; events[i]; i++) {
1344 ret = register_trace_event(event);
1346 printk(KERN_WARNING "event %d failed to register\n",
1354 early_initcall(init_events);