4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
7 #include <linux/module.h>
8 #include <linux/mutex.h>
9 #include <linux/ftrace.h>
10 #include <linux/sched/clock.h>
11 #include <linux/sched/mm.h>
13 #include "trace_output.h"
15 /* must be a power of 2 */
16 #define EVENT_HASHSIZE 128
18 DECLARE_RWSEM(trace_event_sem);
20 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
22 static int next_event_type = __TRACE_LAST_TYPE + 1;
24 enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
26 struct trace_seq *s = &iter->seq;
27 struct trace_entry *entry = iter->ent;
28 struct bputs_entry *field;
30 trace_assign_type(field, entry);
32 trace_seq_puts(s, field->str);
34 return trace_handle_return(s);
37 enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
39 struct trace_seq *s = &iter->seq;
40 struct trace_entry *entry = iter->ent;
41 struct bprint_entry *field;
43 trace_assign_type(field, entry);
45 trace_seq_bprintf(s, field->fmt, field->buf);
47 return trace_handle_return(s);
50 enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
52 struct trace_seq *s = &iter->seq;
53 struct trace_entry *entry = iter->ent;
54 struct print_entry *field;
56 trace_assign_type(field, entry);
58 trace_seq_puts(s, field->buf);
60 return trace_handle_return(s);
64 trace_print_flags_seq(struct trace_seq *p, const char *delim,
66 const struct trace_print_flags *flag_array)
70 const char *ret = trace_seq_buffer_ptr(p);
73 for (i = 0; flag_array[i].name && flags; i++) {
75 mask = flag_array[i].mask;
76 if ((flags & mask) != mask)
79 str = flag_array[i].name;
82 trace_seq_puts(p, delim);
85 trace_seq_puts(p, str);
88 /* check for left over flags */
91 trace_seq_puts(p, delim);
92 trace_seq_printf(p, "0x%lx", flags);
99 EXPORT_SYMBOL(trace_print_flags_seq);
102 trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
103 const struct trace_print_flags *symbol_array)
106 const char *ret = trace_seq_buffer_ptr(p);
108 for (i = 0; symbol_array[i].name; i++) {
110 if (val != symbol_array[i].mask)
113 trace_seq_puts(p, symbol_array[i].name);
117 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
118 trace_seq_printf(p, "0x%lx", val);
120 trace_seq_putc(p, 0);
124 EXPORT_SYMBOL(trace_print_symbols_seq);
126 #if BITS_PER_LONG == 32
128 trace_print_flags_seq_u64(struct trace_seq *p, const char *delim,
129 unsigned long long flags,
130 const struct trace_print_flags_u64 *flag_array)
132 unsigned long long mask;
134 const char *ret = trace_seq_buffer_ptr(p);
137 for (i = 0; flag_array[i].name && flags; i++) {
139 mask = flag_array[i].mask;
140 if ((flags & mask) != mask)
143 str = flag_array[i].name;
146 trace_seq_puts(p, delim);
149 trace_seq_puts(p, str);
152 /* check for left over flags */
155 trace_seq_puts(p, delim);
156 trace_seq_printf(p, "0x%llx", flags);
159 trace_seq_putc(p, 0);
163 EXPORT_SYMBOL(trace_print_flags_seq_u64);
166 trace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
167 const struct trace_print_flags_u64 *symbol_array)
170 const char *ret = trace_seq_buffer_ptr(p);
172 for (i = 0; symbol_array[i].name; i++) {
174 if (val != symbol_array[i].mask)
177 trace_seq_puts(p, symbol_array[i].name);
181 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
182 trace_seq_printf(p, "0x%llx", val);
184 trace_seq_putc(p, 0);
188 EXPORT_SYMBOL(trace_print_symbols_seq_u64);
192 trace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
193 unsigned int bitmask_size)
195 const char *ret = trace_seq_buffer_ptr(p);
197 trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8);
198 trace_seq_putc(p, 0);
202 EXPORT_SYMBOL_GPL(trace_print_bitmask_seq);
205 * trace_print_hex_seq - print buffer as hex sequence
206 * @p: trace seq struct to write to
207 * @buf: The buffer to print
208 * @buf_len: Length of @buf in bytes
209 * @concatenate: Print @buf as single hex string or with spacing
211 * Prints the passed buffer as a hex sequence either as a whole,
212 * single hex string if @concatenate is true or with spacing after
213 * each byte in case @concatenate is false.
216 trace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len,
220 const char *ret = trace_seq_buffer_ptr(p);
222 for (i = 0; i < buf_len; i++)
223 trace_seq_printf(p, "%s%2.2x", concatenate || i == 0 ? "" : " ",
225 trace_seq_putc(p, 0);
229 EXPORT_SYMBOL(trace_print_hex_seq);
232 trace_print_array_seq(struct trace_seq *p, const void *buf, int count,
235 const char *ret = trace_seq_buffer_ptr(p);
236 const char *prefix = "";
237 void *ptr = (void *)buf;
238 size_t buf_len = count * el_size;
240 trace_seq_putc(p, '{');
242 while (ptr < buf + buf_len) {
245 trace_seq_printf(p, "%s0x%x", prefix,
249 trace_seq_printf(p, "%s0x%x", prefix,
253 trace_seq_printf(p, "%s0x%x", prefix,
257 trace_seq_printf(p, "%s0x%llx", prefix,
261 trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size,
269 trace_seq_putc(p, '}');
270 trace_seq_putc(p, 0);
274 EXPORT_SYMBOL(trace_print_array_seq);
276 int trace_raw_output_prep(struct trace_iterator *iter,
277 struct trace_event *trace_event)
279 struct trace_event_call *event;
280 struct trace_seq *s = &iter->seq;
281 struct trace_seq *p = &iter->tmp_seq;
282 struct trace_entry *entry;
284 event = container_of(trace_event, struct trace_event_call, event);
287 if (entry->type != event->event.type) {
289 return TRACE_TYPE_UNHANDLED;
293 trace_seq_printf(s, "%s: ", trace_event_name(event));
295 return trace_handle_return(s);
297 EXPORT_SYMBOL(trace_raw_output_prep);
299 static int trace_output_raw(struct trace_iterator *iter, char *name,
300 char *fmt, va_list ap)
302 struct trace_seq *s = &iter->seq;
304 trace_seq_printf(s, "%s: ", name);
305 trace_seq_vprintf(s, fmt, ap);
307 return trace_handle_return(s);
310 int trace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
316 ret = trace_output_raw(iter, name, fmt, ap);
321 EXPORT_SYMBOL_GPL(trace_output_call);
323 #ifdef CONFIG_KRETPROBES
324 static inline const char *kretprobed(const char *name)
326 static const char tramp_name[] = "kretprobe_trampoline";
327 int size = sizeof(tramp_name);
329 if (strncmp(tramp_name, name, size) == 0)
330 return "[unknown/kretprobe'd]";
334 static inline const char *kretprobed(const char *name)
338 #endif /* CONFIG_KRETPROBES */
341 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
343 #ifdef CONFIG_KALLSYMS
344 char str[KSYM_SYMBOL_LEN];
347 kallsyms_lookup(address, NULL, NULL, NULL, str);
349 name = kretprobed(str);
351 trace_seq_printf(s, fmt, name);
356 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
357 unsigned long address)
359 #ifdef CONFIG_KALLSYMS
360 char str[KSYM_SYMBOL_LEN];
363 sprint_symbol(str, address);
364 name = kretprobed(str);
366 trace_seq_printf(s, fmt, name);
371 # define IP_FMT "%08lx"
373 # define IP_FMT "%016lx"
376 static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
377 unsigned long ip, unsigned long sym_flags)
379 struct file *file = NULL;
380 unsigned long vmstart = 0;
387 const struct vm_area_struct *vma;
389 down_read(&mm->mmap_sem);
390 vma = find_vma(mm, ip);
393 vmstart = vma->vm_start;
396 ret = trace_seq_path(s, &file->f_path);
398 trace_seq_printf(s, "[+0x%lx]",
401 up_read(&mm->mmap_sem);
403 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
404 trace_seq_printf(s, " <" IP_FMT ">", ip);
405 return !trace_seq_has_overflowed(s);
409 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
412 trace_seq_putc(s, '0');
416 if (sym_flags & TRACE_ITER_SYM_OFFSET)
417 seq_print_sym_offset(s, "%s", ip);
419 seq_print_sym_short(s, "%s", ip);
421 if (sym_flags & TRACE_ITER_SYM_ADDR)
422 trace_seq_printf(s, " <" IP_FMT ">", ip);
425 return !trace_seq_has_overflowed(s);
429 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
430 * @s: trace seq struct to write to
431 * @entry: The trace entry field from the ring buffer
433 * Prints the generic fields of irqs off, in hard or softirq, preempt
436 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
445 nmi = entry->flags & TRACE_FLAG_NMI;
446 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
447 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
450 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
451 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
454 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
455 TRACE_FLAG_PREEMPT_RESCHED)) {
456 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
459 case TRACE_FLAG_NEED_RESCHED:
462 case TRACE_FLAG_PREEMPT_RESCHED:
471 (nmi && hardirq) ? 'Z' :
473 (hardirq && softirq) ? 'H' :
478 trace_seq_printf(s, "%c%c%c",
479 irqs_off, need_resched, hardsoft_irq);
481 if (entry->preempt_count)
482 trace_seq_printf(s, "%x", entry->preempt_count);
484 trace_seq_putc(s, '.');
486 return !trace_seq_has_overflowed(s);
490 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
492 char comm[TASK_COMM_LEN];
494 trace_find_cmdline(entry->pid, comm);
496 trace_seq_printf(s, "%8.8s-%-5d %3d",
497 comm, entry->pid, cpu);
499 return trace_print_lat_fmt(s, entry);
503 #define MARK(v, s) {.val = v, .sym = s}
504 /* trace overhead mark */
505 static const struct trace_mark {
506 unsigned long long val; /* unit: nsec */
509 MARK(1000000000ULL , '$'), /* 1 sec */
510 MARK(100000000ULL , '@'), /* 100 msec */
511 MARK(10000000ULL , '*'), /* 10 msec */
512 MARK(1000000ULL , '#'), /* 1000 usecs */
513 MARK(100000ULL , '!'), /* 100 usecs */
514 MARK(10000ULL , '+'), /* 10 usecs */
518 char trace_find_mark(unsigned long long d)
521 int size = ARRAY_SIZE(mark);
523 for (i = 0; i < size; i++) {
528 return (i == size) ? ' ' : mark[i].sym;
532 lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
534 struct trace_array *tr = iter->tr;
535 unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE;
536 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
537 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
538 unsigned long long rel_ts = next_ts - iter->ts;
539 struct trace_seq *s = &iter->seq;
542 abs_ts = ns2usecs(abs_ts);
543 rel_ts = ns2usecs(rel_ts);
546 if (verbose && in_ns) {
547 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
548 unsigned long abs_msec = (unsigned long)abs_ts;
549 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
550 unsigned long rel_msec = (unsigned long)rel_ts;
553 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
558 } else if (verbose && !in_ns) {
560 s, "[%016llx] %lld (+%lld): ",
561 iter->ts, abs_ts, rel_ts);
563 } else if (!verbose && in_ns) {
567 trace_find_mark(rel_ts * NSEC_PER_USEC));
569 } else { /* !verbose && !in_ns */
570 trace_seq_printf(s, " %4lld: ", abs_ts);
573 return !trace_seq_has_overflowed(s);
576 int trace_print_context(struct trace_iterator *iter)
578 struct trace_array *tr = iter->tr;
579 struct trace_seq *s = &iter->seq;
580 struct trace_entry *entry = iter->ent;
581 unsigned long long t;
582 unsigned long secs, usec_rem;
583 char comm[TASK_COMM_LEN];
585 trace_find_cmdline(entry->pid, comm);
587 trace_seq_printf(s, "%16s-%-5d [%03d] ",
588 comm, entry->pid, iter->cpu);
590 if (tr->trace_flags & TRACE_ITER_IRQ_INFO)
591 trace_print_lat_fmt(s, entry);
593 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
594 t = ns2usecs(iter->ts);
595 usec_rem = do_div(t, USEC_PER_SEC);
596 secs = (unsigned long)t;
597 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
599 trace_seq_printf(s, " %12llu: ", iter->ts);
601 return !trace_seq_has_overflowed(s);
604 int trace_print_lat_context(struct trace_iterator *iter)
606 struct trace_array *tr = iter->tr;
607 /* trace_find_next_entry will reset ent_size */
608 int ent_size = iter->ent_size;
609 struct trace_seq *s = &iter->seq;
611 struct trace_entry *entry = iter->ent,
612 *next_entry = trace_find_next_entry(iter, NULL,
614 unsigned long verbose = (tr->trace_flags & TRACE_ITER_VERBOSE);
616 /* Restore the original ent_size */
617 iter->ent_size = ent_size;
623 char comm[TASK_COMM_LEN];
625 trace_find_cmdline(entry->pid, comm);
628 s, "%16s %5d %3d %d %08x %08lx ",
629 comm, entry->pid, iter->cpu, entry->flags,
630 entry->preempt_count, iter->idx);
632 lat_print_generic(s, entry, iter->cpu);
635 lat_print_timestamp(iter, next_ts);
637 return !trace_seq_has_overflowed(s);
640 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
642 static int task_state_char(unsigned long state)
644 int bit = state ? __ffs(state) + 1 : 0;
646 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
650 * ftrace_find_event - find a registered event
651 * @type: the type of event to look for
653 * Returns an event of type @type otherwise NULL
654 * Called with trace_event_read_lock() held.
656 struct trace_event *ftrace_find_event(int type)
658 struct trace_event *event;
661 key = type & (EVENT_HASHSIZE - 1);
663 hlist_for_each_entry(event, &event_hash[key], node) {
664 if (event->type == type)
671 static LIST_HEAD(ftrace_event_list);
673 static int trace_search_list(struct list_head **list)
675 struct trace_event *e;
676 int last = __TRACE_LAST_TYPE;
678 if (list_empty(&ftrace_event_list)) {
679 *list = &ftrace_event_list;
684 * We used up all possible max events,
685 * lets see if somebody freed one.
687 list_for_each_entry(e, &ftrace_event_list, list) {
688 if (e->type != last + 1)
693 /* Did we used up all 65 thousand events??? */
694 if ((last + 1) > TRACE_EVENT_TYPE_MAX)
701 void trace_event_read_lock(void)
703 down_read(&trace_event_sem);
706 void trace_event_read_unlock(void)
708 up_read(&trace_event_sem);
712 * register_trace_event - register output for an event type
713 * @event: the event type to register
715 * Event types are stored in a hash and this hash is used to
716 * find a way to print an event. If the @event->type is set
717 * then it will use that type, otherwise it will assign a
720 * If you assign your own type, please make sure it is added
721 * to the trace_type enum in trace.h, to avoid collisions
722 * with the dynamic types.
724 * Returns the event type number or zero on error.
726 int register_trace_event(struct trace_event *event)
731 down_write(&trace_event_sem);
736 if (WARN_ON(!event->funcs))
739 INIT_LIST_HEAD(&event->list);
742 struct list_head *list = NULL;
744 if (next_event_type > TRACE_EVENT_TYPE_MAX) {
746 event->type = trace_search_list(&list);
752 event->type = next_event_type++;
753 list = &ftrace_event_list;
756 if (WARN_ON(ftrace_find_event(event->type)))
759 list_add_tail(&event->list, list);
761 } else if (event->type > __TRACE_LAST_TYPE) {
762 printk(KERN_WARNING "Need to add type to trace.h\n");
766 /* Is this event already used */
767 if (ftrace_find_event(event->type))
771 if (event->funcs->trace == NULL)
772 event->funcs->trace = trace_nop_print;
773 if (event->funcs->raw == NULL)
774 event->funcs->raw = trace_nop_print;
775 if (event->funcs->hex == NULL)
776 event->funcs->hex = trace_nop_print;
777 if (event->funcs->binary == NULL)
778 event->funcs->binary = trace_nop_print;
780 key = event->type & (EVENT_HASHSIZE - 1);
782 hlist_add_head(&event->node, &event_hash[key]);
786 up_write(&trace_event_sem);
790 EXPORT_SYMBOL_GPL(register_trace_event);
793 * Used by module code with the trace_event_sem held for write.
795 int __unregister_trace_event(struct trace_event *event)
797 hlist_del(&event->node);
798 list_del(&event->list);
803 * unregister_trace_event - remove a no longer used event
804 * @event: the event to remove
806 int unregister_trace_event(struct trace_event *event)
808 down_write(&trace_event_sem);
809 __unregister_trace_event(event);
810 up_write(&trace_event_sem);
814 EXPORT_SYMBOL_GPL(unregister_trace_event);
820 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
821 struct trace_event *event)
823 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
825 return trace_handle_return(&iter->seq);
829 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
830 struct trace_event *event)
832 struct ftrace_entry *field;
833 struct trace_seq *s = &iter->seq;
835 trace_assign_type(field, iter->ent);
837 seq_print_ip_sym(s, field->ip, flags);
839 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
840 trace_seq_puts(s, " <-");
841 seq_print_ip_sym(s, field->parent_ip, flags);
844 trace_seq_putc(s, '\n');
846 return trace_handle_return(s);
849 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
850 struct trace_event *event)
852 struct ftrace_entry *field;
854 trace_assign_type(field, iter->ent);
856 trace_seq_printf(&iter->seq, "%lx %lx\n",
860 return trace_handle_return(&iter->seq);
863 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
864 struct trace_event *event)
866 struct ftrace_entry *field;
867 struct trace_seq *s = &iter->seq;
869 trace_assign_type(field, iter->ent);
871 SEQ_PUT_HEX_FIELD(s, field->ip);
872 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
874 return trace_handle_return(s);
877 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
878 struct trace_event *event)
880 struct ftrace_entry *field;
881 struct trace_seq *s = &iter->seq;
883 trace_assign_type(field, iter->ent);
885 SEQ_PUT_FIELD(s, field->ip);
886 SEQ_PUT_FIELD(s, field->parent_ip);
888 return trace_handle_return(s);
891 static struct trace_event_functions trace_fn_funcs = {
892 .trace = trace_fn_trace,
895 .binary = trace_fn_bin,
898 static struct trace_event trace_fn_event = {
900 .funcs = &trace_fn_funcs,
903 /* TRACE_CTX an TRACE_WAKE */
904 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
907 struct ctx_switch_entry *field;
908 char comm[TASK_COMM_LEN];
912 trace_assign_type(field, iter->ent);
914 T = task_state_char(field->next_state);
915 S = task_state_char(field->prev_state);
916 trace_find_cmdline(field->next_pid, comm);
917 trace_seq_printf(&iter->seq,
918 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
927 return trace_handle_return(&iter->seq);
930 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
931 struct trace_event *event)
933 return trace_ctxwake_print(iter, "==>");
936 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
937 int flags, struct trace_event *event)
939 return trace_ctxwake_print(iter, " +");
942 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
944 struct ctx_switch_entry *field;
947 trace_assign_type(field, iter->ent);
950 S = task_state_char(field->prev_state);
951 T = task_state_char(field->next_state);
952 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
961 return trace_handle_return(&iter->seq);
964 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
965 struct trace_event *event)
967 return trace_ctxwake_raw(iter, 0);
970 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
971 struct trace_event *event)
973 return trace_ctxwake_raw(iter, '+');
977 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
979 struct ctx_switch_entry *field;
980 struct trace_seq *s = &iter->seq;
983 trace_assign_type(field, iter->ent);
986 S = task_state_char(field->prev_state);
987 T = task_state_char(field->next_state);
989 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
990 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
991 SEQ_PUT_HEX_FIELD(s, S);
992 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
993 SEQ_PUT_HEX_FIELD(s, field->next_pid);
994 SEQ_PUT_HEX_FIELD(s, field->next_prio);
995 SEQ_PUT_HEX_FIELD(s, T);
997 return trace_handle_return(s);
1000 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
1001 struct trace_event *event)
1003 return trace_ctxwake_hex(iter, 0);
1006 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
1007 struct trace_event *event)
1009 return trace_ctxwake_hex(iter, '+');
1012 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
1013 int flags, struct trace_event *event)
1015 struct ctx_switch_entry *field;
1016 struct trace_seq *s = &iter->seq;
1018 trace_assign_type(field, iter->ent);
1020 SEQ_PUT_FIELD(s, field->prev_pid);
1021 SEQ_PUT_FIELD(s, field->prev_prio);
1022 SEQ_PUT_FIELD(s, field->prev_state);
1023 SEQ_PUT_FIELD(s, field->next_cpu);
1024 SEQ_PUT_FIELD(s, field->next_pid);
1025 SEQ_PUT_FIELD(s, field->next_prio);
1026 SEQ_PUT_FIELD(s, field->next_state);
1028 return trace_handle_return(s);
1031 static struct trace_event_functions trace_ctx_funcs = {
1032 .trace = trace_ctx_print,
1033 .raw = trace_ctx_raw,
1034 .hex = trace_ctx_hex,
1035 .binary = trace_ctxwake_bin,
1038 static struct trace_event trace_ctx_event = {
1040 .funcs = &trace_ctx_funcs,
1043 static struct trace_event_functions trace_wake_funcs = {
1044 .trace = trace_wake_print,
1045 .raw = trace_wake_raw,
1046 .hex = trace_wake_hex,
1047 .binary = trace_ctxwake_bin,
1050 static struct trace_event trace_wake_event = {
1052 .funcs = &trace_wake_funcs,
1057 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1058 int flags, struct trace_event *event)
1060 struct stack_entry *field;
1061 struct trace_seq *s = &iter->seq;
1065 trace_assign_type(field, iter->ent);
1066 end = (unsigned long *)((long)iter->ent + iter->ent_size);
1068 trace_seq_puts(s, "<stack trace>\n");
1070 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
1072 if (trace_seq_has_overflowed(s))
1075 trace_seq_puts(s, " => ");
1076 seq_print_ip_sym(s, *p, flags);
1077 trace_seq_putc(s, '\n');
1080 return trace_handle_return(s);
1083 static struct trace_event_functions trace_stack_funcs = {
1084 .trace = trace_stack_print,
1087 static struct trace_event trace_stack_event = {
1088 .type = TRACE_STACK,
1089 .funcs = &trace_stack_funcs,
1092 /* TRACE_USER_STACK */
1093 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1094 int flags, struct trace_event *event)
1096 struct trace_array *tr = iter->tr;
1097 struct userstack_entry *field;
1098 struct trace_seq *s = &iter->seq;
1099 struct mm_struct *mm = NULL;
1102 trace_assign_type(field, iter->ent);
1104 trace_seq_puts(s, "<user stack trace>\n");
1106 if (tr->trace_flags & TRACE_ITER_SYM_USEROBJ) {
1107 struct task_struct *task;
1109 * we do the lookup on the thread group leader,
1110 * since individual threads might have already quit!
1113 task = find_task_by_vpid(field->tgid);
1115 mm = get_task_mm(task);
1119 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1120 unsigned long ip = field->caller[i];
1122 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
1125 trace_seq_puts(s, " => ");
1128 trace_seq_puts(s, "??");
1129 trace_seq_putc(s, '\n');
1133 seq_print_user_ip(s, mm, ip, flags);
1134 trace_seq_putc(s, '\n');
1140 return trace_handle_return(s);
1143 static struct trace_event_functions trace_user_stack_funcs = {
1144 .trace = trace_user_stack_print,
1147 static struct trace_event trace_user_stack_event = {
1148 .type = TRACE_USER_STACK,
1149 .funcs = &trace_user_stack_funcs,
1153 static enum print_line_t
1154 trace_hwlat_print(struct trace_iterator *iter, int flags,
1155 struct trace_event *event)
1157 struct trace_entry *entry = iter->ent;
1158 struct trace_seq *s = &iter->seq;
1159 struct hwlat_entry *field;
1161 trace_assign_type(field, entry);
1163 trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
1166 field->outer_duration,
1167 (long long)field->timestamp.tv_sec,
1168 field->timestamp.tv_nsec);
1170 if (field->nmi_count) {
1172 * The generic sched_clock() is not NMI safe, thus
1173 * we only record the count and not the time.
1175 if (!IS_ENABLED(CONFIG_GENERIC_SCHED_CLOCK))
1176 trace_seq_printf(s, " nmi-total:%llu",
1177 field->nmi_total_ts);
1178 trace_seq_printf(s, " nmi-count:%u",
1182 trace_seq_putc(s, '\n');
1184 return trace_handle_return(s);
1188 static enum print_line_t
1189 trace_hwlat_raw(struct trace_iterator *iter, int flags,
1190 struct trace_event *event)
1192 struct hwlat_entry *field;
1193 struct trace_seq *s = &iter->seq;
1195 trace_assign_type(field, iter->ent);
1197 trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
1199 field->outer_duration,
1200 (long long)field->timestamp.tv_sec,
1201 field->timestamp.tv_nsec,
1204 return trace_handle_return(s);
1207 static struct trace_event_functions trace_hwlat_funcs = {
1208 .trace = trace_hwlat_print,
1209 .raw = trace_hwlat_raw,
1212 static struct trace_event trace_hwlat_event = {
1213 .type = TRACE_HWLAT,
1214 .funcs = &trace_hwlat_funcs,
1218 static enum print_line_t
1219 trace_bputs_print(struct trace_iterator *iter, int flags,
1220 struct trace_event *event)
1222 struct trace_entry *entry = iter->ent;
1223 struct trace_seq *s = &iter->seq;
1224 struct bputs_entry *field;
1226 trace_assign_type(field, entry);
1228 seq_print_ip_sym(s, field->ip, flags);
1229 trace_seq_puts(s, ": ");
1230 trace_seq_puts(s, field->str);
1232 return trace_handle_return(s);
1236 static enum print_line_t
1237 trace_bputs_raw(struct trace_iterator *iter, int flags,
1238 struct trace_event *event)
1240 struct bputs_entry *field;
1241 struct trace_seq *s = &iter->seq;
1243 trace_assign_type(field, iter->ent);
1245 trace_seq_printf(s, ": %lx : ", field->ip);
1246 trace_seq_puts(s, field->str);
1248 return trace_handle_return(s);
1251 static struct trace_event_functions trace_bputs_funcs = {
1252 .trace = trace_bputs_print,
1253 .raw = trace_bputs_raw,
1256 static struct trace_event trace_bputs_event = {
1257 .type = TRACE_BPUTS,
1258 .funcs = &trace_bputs_funcs,
1262 static enum print_line_t
1263 trace_bprint_print(struct trace_iterator *iter, int flags,
1264 struct trace_event *event)
1266 struct trace_entry *entry = iter->ent;
1267 struct trace_seq *s = &iter->seq;
1268 struct bprint_entry *field;
1270 trace_assign_type(field, entry);
1272 seq_print_ip_sym(s, field->ip, flags);
1273 trace_seq_puts(s, ": ");
1274 trace_seq_bprintf(s, field->fmt, field->buf);
1276 return trace_handle_return(s);
1280 static enum print_line_t
1281 trace_bprint_raw(struct trace_iterator *iter, int flags,
1282 struct trace_event *event)
1284 struct bprint_entry *field;
1285 struct trace_seq *s = &iter->seq;
1287 trace_assign_type(field, iter->ent);
1289 trace_seq_printf(s, ": %lx : ", field->ip);
1290 trace_seq_bprintf(s, field->fmt, field->buf);
1292 return trace_handle_return(s);
1295 static struct trace_event_functions trace_bprint_funcs = {
1296 .trace = trace_bprint_print,
1297 .raw = trace_bprint_raw,
1300 static struct trace_event trace_bprint_event = {
1301 .type = TRACE_BPRINT,
1302 .funcs = &trace_bprint_funcs,
1306 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1307 int flags, struct trace_event *event)
1309 struct print_entry *field;
1310 struct trace_seq *s = &iter->seq;
1312 trace_assign_type(field, iter->ent);
1314 seq_print_ip_sym(s, field->ip, flags);
1315 trace_seq_printf(s, ": %s", field->buf);
1317 return trace_handle_return(s);
1320 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1321 struct trace_event *event)
1323 struct print_entry *field;
1325 trace_assign_type(field, iter->ent);
1327 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
1329 return trace_handle_return(&iter->seq);
1332 static struct trace_event_functions trace_print_funcs = {
1333 .trace = trace_print_print,
1334 .raw = trace_print_raw,
1337 static struct trace_event trace_print_event = {
1338 .type = TRACE_PRINT,
1339 .funcs = &trace_print_funcs,
1342 static enum print_line_t trace_raw_data(struct trace_iterator *iter, int flags,
1343 struct trace_event *event)
1345 struct raw_data_entry *field;
1348 trace_assign_type(field, iter->ent);
1350 trace_seq_printf(&iter->seq, "# %x buf:", field->id);
1352 for (i = 0; i < iter->ent_size - offsetof(struct raw_data_entry, buf); i++)
1353 trace_seq_printf(&iter->seq, " %02x",
1354 (unsigned char)field->buf[i]);
1356 trace_seq_putc(&iter->seq, '\n');
1358 return trace_handle_return(&iter->seq);
1361 static struct trace_event_functions trace_raw_data_funcs = {
1362 .trace = trace_raw_data,
1363 .raw = trace_raw_data,
1366 static struct trace_event trace_raw_data_event = {
1367 .type = TRACE_RAW_DATA,
1368 .funcs = &trace_raw_data_funcs,
1372 static struct trace_event *events[] __initdata = {
1377 &trace_user_stack_event,
1379 &trace_bprint_event,
1382 &trace_raw_data_event,
1386 __init static int init_events(void)
1388 struct trace_event *event;
1391 for (i = 0; events[i]; i++) {
1394 ret = register_trace_event(event);
1396 printk(KERN_WARNING "event %d failed to register\n",
1404 early_initcall(init_events);