drm/panel-edp: Add BOE NV140FHM-NZ panel entry
[drm/drm-misc.git] / kernel / trace / trace_output.c
blobda748b7cbc4d53e0eb5fef075891f41d23361cb2
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * trace_output.c
5 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
7 */
8 #include <linux/module.h>
9 #include <linux/mutex.h>
10 #include <linux/ftrace.h>
11 #include <linux/kprobes.h>
12 #include <linux/sched/clock.h>
13 #include <linux/sched/mm.h>
14 #include <linux/idr.h>
16 #include "trace_output.h"
18 /* must be a power of 2 */
19 #define EVENT_HASHSIZE 128
21 DECLARE_RWSEM(trace_event_sem);
23 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
25 enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
27 struct trace_seq *s = &iter->seq;
28 struct trace_entry *entry = iter->ent;
29 struct bputs_entry *field;
31 trace_assign_type(field, entry);
33 trace_seq_puts(s, field->str);
35 return trace_handle_return(s);
38 enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
40 struct trace_seq *s = &iter->seq;
41 struct trace_entry *entry = iter->ent;
42 struct bprint_entry *field;
44 trace_assign_type(field, entry);
46 trace_seq_bprintf(s, field->fmt, field->buf);
48 return trace_handle_return(s);
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;
57 trace_assign_type(field, entry);
59 trace_seq_puts(s, field->buf);
61 return trace_handle_return(s);
64 const char *
65 trace_print_flags_seq(struct trace_seq *p, const char *delim,
66 unsigned long flags,
67 const struct trace_print_flags *flag_array)
69 unsigned long mask;
70 const char *str;
71 const char *ret = trace_seq_buffer_ptr(p);
72 int i, first = 1;
74 for (i = 0; flag_array[i].name && flags; i++) {
76 mask = flag_array[i].mask;
77 if ((flags & mask) != mask)
78 continue;
80 str = flag_array[i].name;
81 flags &= ~mask;
82 if (!first && delim)
83 trace_seq_puts(p, delim);
84 else
85 first = 0;
86 trace_seq_puts(p, str);
89 /* check for left over flags */
90 if (flags) {
91 if (!first && delim)
92 trace_seq_puts(p, delim);
93 trace_seq_printf(p, "0x%lx", flags);
96 trace_seq_putc(p, 0);
98 return ret;
100 EXPORT_SYMBOL(trace_print_flags_seq);
102 const char *
103 trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
104 const struct trace_print_flags *symbol_array)
106 int i;
107 const char *ret = trace_seq_buffer_ptr(p);
109 for (i = 0; symbol_array[i].name; i++) {
111 if (val != symbol_array[i].mask)
112 continue;
114 trace_seq_puts(p, symbol_array[i].name);
115 break;
118 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
119 trace_seq_printf(p, "0x%lx", val);
121 trace_seq_putc(p, 0);
123 return ret;
125 EXPORT_SYMBOL(trace_print_symbols_seq);
127 #if BITS_PER_LONG == 32
128 const char *
129 trace_print_flags_seq_u64(struct trace_seq *p, const char *delim,
130 unsigned long long flags,
131 const struct trace_print_flags_u64 *flag_array)
133 unsigned long long mask;
134 const char *str;
135 const char *ret = trace_seq_buffer_ptr(p);
136 int i, first = 1;
138 for (i = 0; flag_array[i].name && flags; i++) {
140 mask = flag_array[i].mask;
141 if ((flags & mask) != mask)
142 continue;
144 str = flag_array[i].name;
145 flags &= ~mask;
146 if (!first && delim)
147 trace_seq_puts(p, delim);
148 else
149 first = 0;
150 trace_seq_puts(p, str);
153 /* check for left over flags */
154 if (flags) {
155 if (!first && delim)
156 trace_seq_puts(p, delim);
157 trace_seq_printf(p, "0x%llx", flags);
160 trace_seq_putc(p, 0);
162 return ret;
164 EXPORT_SYMBOL(trace_print_flags_seq_u64);
166 const char *
167 trace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
168 const struct trace_print_flags_u64 *symbol_array)
170 int i;
171 const char *ret = trace_seq_buffer_ptr(p);
173 for (i = 0; symbol_array[i].name; i++) {
175 if (val != symbol_array[i].mask)
176 continue;
178 trace_seq_puts(p, symbol_array[i].name);
179 break;
182 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
183 trace_seq_printf(p, "0x%llx", val);
185 trace_seq_putc(p, 0);
187 return ret;
189 EXPORT_SYMBOL(trace_print_symbols_seq_u64);
190 #endif
192 const char *
193 trace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
194 unsigned int bitmask_size)
196 const char *ret = trace_seq_buffer_ptr(p);
198 trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8);
199 trace_seq_putc(p, 0);
201 return ret;
203 EXPORT_SYMBOL_GPL(trace_print_bitmask_seq);
206 * trace_print_hex_seq - print buffer as hex sequence
207 * @p: trace seq struct to write to
208 * @buf: The buffer to print
209 * @buf_len: Length of @buf in bytes
210 * @concatenate: Print @buf as single hex string or with spacing
212 * Prints the passed buffer as a hex sequence either as a whole,
213 * single hex string if @concatenate is true or with spacing after
214 * each byte in case @concatenate is false.
216 const char *
217 trace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len,
218 bool concatenate)
220 int i;
221 const char *ret = trace_seq_buffer_ptr(p);
222 const char *fmt = concatenate ? "%*phN" : "%*ph";
224 for (i = 0; i < buf_len; i += 16) {
225 if (!concatenate && i != 0)
226 trace_seq_putc(p, ' ');
227 trace_seq_printf(p, fmt, min(buf_len - i, 16), &buf[i]);
229 trace_seq_putc(p, 0);
231 return ret;
233 EXPORT_SYMBOL(trace_print_hex_seq);
235 const char *
236 trace_print_array_seq(struct trace_seq *p, const void *buf, int count,
237 size_t el_size)
239 const char *ret = trace_seq_buffer_ptr(p);
240 const char *prefix = "";
241 void *ptr = (void *)buf;
242 size_t buf_len = count * el_size;
244 trace_seq_putc(p, '{');
246 while (ptr < buf + buf_len) {
247 switch (el_size) {
248 case 1:
249 trace_seq_printf(p, "%s0x%x", prefix,
250 *(u8 *)ptr);
251 break;
252 case 2:
253 trace_seq_printf(p, "%s0x%x", prefix,
254 *(u16 *)ptr);
255 break;
256 case 4:
257 trace_seq_printf(p, "%s0x%x", prefix,
258 *(u32 *)ptr);
259 break;
260 case 8:
261 trace_seq_printf(p, "%s0x%llx", prefix,
262 *(u64 *)ptr);
263 break;
264 default:
265 trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size,
266 *(u8 *)ptr);
267 el_size = 1;
269 prefix = ",";
270 ptr += el_size;
273 trace_seq_putc(p, '}');
274 trace_seq_putc(p, 0);
276 return ret;
278 EXPORT_SYMBOL(trace_print_array_seq);
280 const char *
281 trace_print_hex_dump_seq(struct trace_seq *p, const char *prefix_str,
282 int prefix_type, int rowsize, int groupsize,
283 const void *buf, size_t len, bool ascii)
285 const char *ret = trace_seq_buffer_ptr(p);
287 trace_seq_putc(p, '\n');
288 trace_seq_hex_dump(p, prefix_str, prefix_type,
289 rowsize, groupsize, buf, len, ascii);
290 trace_seq_putc(p, 0);
291 return ret;
293 EXPORT_SYMBOL(trace_print_hex_dump_seq);
295 int trace_raw_output_prep(struct trace_iterator *iter,
296 struct trace_event *trace_event)
298 struct trace_event_call *event;
299 struct trace_seq *s = &iter->seq;
300 struct trace_seq *p = &iter->tmp_seq;
301 struct trace_entry *entry;
303 event = container_of(trace_event, struct trace_event_call, event);
304 entry = iter->ent;
306 if (entry->type != event->event.type) {
307 WARN_ON_ONCE(1);
308 return TRACE_TYPE_UNHANDLED;
311 trace_seq_init(p);
312 trace_seq_printf(s, "%s: ", trace_event_name(event));
314 return trace_handle_return(s);
316 EXPORT_SYMBOL(trace_raw_output_prep);
318 void trace_event_printf(struct trace_iterator *iter, const char *fmt, ...)
320 va_list ap;
322 va_start(ap, fmt);
323 trace_check_vprintf(iter, trace_event_format(iter, fmt), ap);
324 va_end(ap);
326 EXPORT_SYMBOL(trace_event_printf);
328 static __printf(3, 0)
329 int trace_output_raw(struct trace_iterator *iter, char *name,
330 char *fmt, va_list ap)
332 struct trace_seq *s = &iter->seq;
334 trace_seq_printf(s, "%s: ", name);
335 trace_seq_vprintf(s, trace_event_format(iter, fmt), ap);
337 return trace_handle_return(s);
340 int trace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
342 va_list ap;
343 int ret;
345 va_start(ap, fmt);
346 ret = trace_output_raw(iter, name, fmt, ap);
347 va_end(ap);
349 return ret;
351 EXPORT_SYMBOL_GPL(trace_output_call);
353 static inline const char *kretprobed(const char *name, unsigned long addr)
355 if (is_kretprobe_trampoline(addr))
356 return "[unknown/kretprobe'd]";
357 return name;
360 void
361 trace_seq_print_sym(struct trace_seq *s, unsigned long address, bool offset)
363 #ifdef CONFIG_KALLSYMS
364 char str[KSYM_SYMBOL_LEN];
365 const char *name;
367 if (offset)
368 sprint_symbol(str, address);
369 else
370 kallsyms_lookup(address, NULL, NULL, NULL, str);
371 name = kretprobed(str, address);
373 if (name && strlen(name)) {
374 trace_seq_puts(s, name);
375 return;
377 #endif
378 trace_seq_printf(s, "0x%08lx", address);
381 #ifndef CONFIG_64BIT
382 # define IP_FMT "%08lx"
383 #else
384 # define IP_FMT "%016lx"
385 #endif
387 static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
388 unsigned long ip, unsigned long sym_flags)
390 struct file *file = NULL;
391 unsigned long vmstart = 0;
392 int ret = 1;
394 if (s->full)
395 return 0;
397 if (mm) {
398 const struct vm_area_struct *vma;
400 mmap_read_lock(mm);
401 vma = find_vma(mm, ip);
402 if (vma) {
403 file = vma->vm_file;
404 vmstart = vma->vm_start;
406 if (file) {
407 ret = trace_seq_path(s, file_user_path(file));
408 if (ret)
409 trace_seq_printf(s, "[+0x%lx]",
410 ip - vmstart);
412 mmap_read_unlock(mm);
414 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
415 trace_seq_printf(s, " <" IP_FMT ">", ip);
416 return !trace_seq_has_overflowed(s);
420 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
422 if (!ip) {
423 trace_seq_putc(s, '0');
424 goto out;
427 trace_seq_print_sym(s, ip, sym_flags & TRACE_ITER_SYM_OFFSET);
429 if (sym_flags & TRACE_ITER_SYM_ADDR)
430 trace_seq_printf(s, " <" IP_FMT ">", ip);
432 out:
433 return !trace_seq_has_overflowed(s);
437 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
438 * @s: trace seq struct to write to
439 * @entry: The trace entry field from the ring buffer
441 * Prints the generic fields of irqs off, in hard or softirq, preempt
442 * count.
444 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
446 char hardsoft_irq;
447 char need_resched;
448 char irqs_off;
449 int hardirq;
450 int softirq;
451 int bh_off;
452 int nmi;
454 nmi = entry->flags & TRACE_FLAG_NMI;
455 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
456 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
457 bh_off = entry->flags & TRACE_FLAG_BH_OFF;
459 irqs_off =
460 (entry->flags & TRACE_FLAG_IRQS_OFF && bh_off) ? 'D' :
461 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
462 bh_off ? 'b' :
463 '.';
465 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY |
466 TRACE_FLAG_PREEMPT_RESCHED)) {
467 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY | TRACE_FLAG_PREEMPT_RESCHED:
468 need_resched = 'B';
469 break;
470 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
471 need_resched = 'N';
472 break;
473 case TRACE_FLAG_NEED_RESCHED_LAZY | TRACE_FLAG_PREEMPT_RESCHED:
474 need_resched = 'L';
475 break;
476 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY:
477 need_resched = 'b';
478 break;
479 case TRACE_FLAG_NEED_RESCHED:
480 need_resched = 'n';
481 break;
482 case TRACE_FLAG_PREEMPT_RESCHED:
483 need_resched = 'p';
484 break;
485 case TRACE_FLAG_NEED_RESCHED_LAZY:
486 need_resched = 'l';
487 break;
488 default:
489 need_resched = '.';
490 break;
493 hardsoft_irq =
494 (nmi && hardirq) ? 'Z' :
495 nmi ? 'z' :
496 (hardirq && softirq) ? 'H' :
497 hardirq ? 'h' :
498 softirq ? 's' :
499 '.' ;
501 trace_seq_printf(s, "%c%c%c",
502 irqs_off, need_resched, hardsoft_irq);
504 if (entry->preempt_count & 0xf)
505 trace_seq_printf(s, "%x", entry->preempt_count & 0xf);
506 else
507 trace_seq_putc(s, '.');
509 if (entry->preempt_count & 0xf0)
510 trace_seq_printf(s, "%x", entry->preempt_count >> 4);
511 else
512 trace_seq_putc(s, '.');
514 return !trace_seq_has_overflowed(s);
517 static int
518 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
520 char comm[TASK_COMM_LEN];
522 trace_find_cmdline(entry->pid, comm);
524 trace_seq_printf(s, "%8.8s-%-7d %3d",
525 comm, entry->pid, cpu);
527 return trace_print_lat_fmt(s, entry);
530 #undef MARK
531 #define MARK(v, s) {.val = v, .sym = s}
532 /* trace overhead mark */
533 static const struct trace_mark {
534 unsigned long long val; /* unit: nsec */
535 char sym;
536 } mark[] = {
537 MARK(1000000000ULL , '$'), /* 1 sec */
538 MARK(100000000ULL , '@'), /* 100 msec */
539 MARK(10000000ULL , '*'), /* 10 msec */
540 MARK(1000000ULL , '#'), /* 1000 usecs */
541 MARK(100000ULL , '!'), /* 100 usecs */
542 MARK(10000ULL , '+'), /* 10 usecs */
544 #undef MARK
546 char trace_find_mark(unsigned long long d)
548 int i;
549 int size = ARRAY_SIZE(mark);
551 for (i = 0; i < size; i++) {
552 if (d > mark[i].val)
553 break;
556 return (i == size) ? ' ' : mark[i].sym;
559 static int
560 lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
562 struct trace_array *tr = iter->tr;
563 unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE;
564 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
565 unsigned long long abs_ts = iter->ts - iter->array_buffer->time_start;
566 unsigned long long rel_ts = next_ts - iter->ts;
567 struct trace_seq *s = &iter->seq;
569 if (in_ns) {
570 abs_ts = ns2usecs(abs_ts);
571 rel_ts = ns2usecs(rel_ts);
574 if (verbose && in_ns) {
575 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
576 unsigned long abs_msec = (unsigned long)abs_ts;
577 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
578 unsigned long rel_msec = (unsigned long)rel_ts;
580 trace_seq_printf(
581 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
582 ns2usecs(iter->ts),
583 abs_msec, abs_usec,
584 rel_msec, rel_usec);
586 } else if (verbose && !in_ns) {
587 trace_seq_printf(
588 s, "[%016llx] %lld (+%lld): ",
589 iter->ts, abs_ts, rel_ts);
591 } else if (!verbose && in_ns) {
592 trace_seq_printf(
593 s, " %4lldus%c: ",
594 abs_ts,
595 trace_find_mark(rel_ts * NSEC_PER_USEC));
597 } else { /* !verbose && !in_ns */
598 trace_seq_printf(s, " %4lld: ", abs_ts);
601 return !trace_seq_has_overflowed(s);
604 static void trace_print_time(struct trace_seq *s, struct trace_iterator *iter,
605 unsigned long long ts)
607 unsigned long secs, usec_rem;
608 unsigned long long t;
610 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
611 t = ns2usecs(ts);
612 usec_rem = do_div(t, USEC_PER_SEC);
613 secs = (unsigned long)t;
614 trace_seq_printf(s, " %5lu.%06lu", secs, usec_rem);
615 } else
616 trace_seq_printf(s, " %12llu", ts);
619 int trace_print_context(struct trace_iterator *iter)
621 struct trace_array *tr = iter->tr;
622 struct trace_seq *s = &iter->seq;
623 struct trace_entry *entry = iter->ent;
624 char comm[TASK_COMM_LEN];
626 trace_find_cmdline(entry->pid, comm);
628 trace_seq_printf(s, "%16s-%-7d ", comm, entry->pid);
630 if (tr->trace_flags & TRACE_ITER_RECORD_TGID) {
631 unsigned int tgid = trace_find_tgid(entry->pid);
633 if (!tgid)
634 trace_seq_printf(s, "(-------) ");
635 else
636 trace_seq_printf(s, "(%7d) ", tgid);
639 trace_seq_printf(s, "[%03d] ", iter->cpu);
641 if (tr->trace_flags & TRACE_ITER_IRQ_INFO)
642 trace_print_lat_fmt(s, entry);
644 trace_print_time(s, iter, iter->ts);
645 trace_seq_puts(s, ": ");
647 return !trace_seq_has_overflowed(s);
650 int trace_print_lat_context(struct trace_iterator *iter)
652 struct trace_entry *entry, *next_entry;
653 struct trace_array *tr = iter->tr;
654 struct trace_seq *s = &iter->seq;
655 unsigned long verbose = (tr->trace_flags & TRACE_ITER_VERBOSE);
656 u64 next_ts;
658 next_entry = trace_find_next_entry(iter, NULL, &next_ts);
659 if (!next_entry)
660 next_ts = iter->ts;
662 /* trace_find_next_entry() may change iter->ent */
663 entry = iter->ent;
665 if (verbose) {
666 char comm[TASK_COMM_LEN];
668 trace_find_cmdline(entry->pid, comm);
670 trace_seq_printf(
671 s, "%16s %7d %3d %d %08x %08lx ",
672 comm, entry->pid, iter->cpu, entry->flags,
673 entry->preempt_count & 0xf, iter->idx);
674 } else {
675 lat_print_generic(s, entry, iter->cpu);
678 lat_print_timestamp(iter, next_ts);
680 return !trace_seq_has_overflowed(s);
684 * ftrace_find_event - find a registered event
685 * @type: the type of event to look for
687 * Returns an event of type @type otherwise NULL
688 * Called with trace_event_read_lock() held.
690 struct trace_event *ftrace_find_event(int type)
692 struct trace_event *event;
693 unsigned key;
695 key = type & (EVENT_HASHSIZE - 1);
697 hlist_for_each_entry(event, &event_hash[key], node) {
698 if (event->type == type)
699 return event;
702 return NULL;
705 static DEFINE_IDA(trace_event_ida);
707 static void free_trace_event_type(int type)
709 if (type >= __TRACE_LAST_TYPE)
710 ida_free(&trace_event_ida, type);
713 static int alloc_trace_event_type(void)
715 int next;
717 /* Skip static defined type numbers */
718 next = ida_alloc_range(&trace_event_ida, __TRACE_LAST_TYPE,
719 TRACE_EVENT_TYPE_MAX, GFP_KERNEL);
720 if (next < 0)
721 return 0;
722 return next;
725 void trace_event_read_lock(void)
727 down_read(&trace_event_sem);
730 void trace_event_read_unlock(void)
732 up_read(&trace_event_sem);
736 * register_trace_event - register output for an event type
737 * @event: the event type to register
739 * Event types are stored in a hash and this hash is used to
740 * find a way to print an event. If the @event->type is set
741 * then it will use that type, otherwise it will assign a
742 * type to use.
744 * If you assign your own type, please make sure it is added
745 * to the trace_type enum in trace.h, to avoid collisions
746 * with the dynamic types.
748 * Returns the event type number or zero on error.
750 int register_trace_event(struct trace_event *event)
752 unsigned key;
753 int ret = 0;
755 down_write(&trace_event_sem);
757 if (WARN_ON(!event))
758 goto out;
760 if (WARN_ON(!event->funcs))
761 goto out;
763 if (!event->type) {
764 event->type = alloc_trace_event_type();
765 if (!event->type)
766 goto out;
767 } else if (WARN(event->type > __TRACE_LAST_TYPE,
768 "Need to add type to trace.h")) {
769 goto out;
770 } else {
771 /* Is this event already used */
772 if (ftrace_find_event(event->type))
773 goto out;
776 if (event->funcs->trace == NULL)
777 event->funcs->trace = trace_nop_print;
778 if (event->funcs->raw == NULL)
779 event->funcs->raw = trace_nop_print;
780 if (event->funcs->hex == NULL)
781 event->funcs->hex = trace_nop_print;
782 if (event->funcs->binary == NULL)
783 event->funcs->binary = trace_nop_print;
785 key = event->type & (EVENT_HASHSIZE - 1);
787 hlist_add_head(&event->node, &event_hash[key]);
789 ret = event->type;
790 out:
791 up_write(&trace_event_sem);
793 return ret;
795 EXPORT_SYMBOL_GPL(register_trace_event);
798 * Used by module code with the trace_event_sem held for write.
800 int __unregister_trace_event(struct trace_event *event)
802 hlist_del(&event->node);
803 free_trace_event_type(event->type);
804 return 0;
808 * unregister_trace_event - remove a no longer used event
809 * @event: the event to remove
811 int unregister_trace_event(struct trace_event *event)
813 down_write(&trace_event_sem);
814 __unregister_trace_event(event);
815 up_write(&trace_event_sem);
817 return 0;
819 EXPORT_SYMBOL_GPL(unregister_trace_event);
822 * Standard events
825 static void print_array(struct trace_iterator *iter, void *pos,
826 struct ftrace_event_field *field)
828 int offset;
829 int len;
830 int i;
832 offset = *(int *)pos & 0xffff;
833 len = *(int *)pos >> 16;
835 if (field)
836 offset += field->offset + sizeof(int);
838 if (offset + len > iter->ent_size) {
839 trace_seq_puts(&iter->seq, "<OVERFLOW>");
840 return;
843 pos = (void *)iter->ent + offset;
845 for (i = 0; i < len; i++, pos++) {
846 if (i)
847 trace_seq_putc(&iter->seq, ',');
848 trace_seq_printf(&iter->seq, "%02x", *(unsigned char *)pos);
852 static void print_fields(struct trace_iterator *iter, struct trace_event_call *call,
853 struct list_head *head)
855 struct ftrace_event_field *field;
856 int offset;
857 int len;
858 int ret;
859 void *pos;
861 list_for_each_entry_reverse(field, head, link) {
862 trace_seq_printf(&iter->seq, " %s=", field->name);
863 if (field->offset + field->size > iter->ent_size) {
864 trace_seq_puts(&iter->seq, "<OVERFLOW>");
865 continue;
867 pos = (void *)iter->ent + field->offset;
869 switch (field->filter_type) {
870 case FILTER_COMM:
871 case FILTER_STATIC_STRING:
872 trace_seq_printf(&iter->seq, "%.*s", field->size, (char *)pos);
873 break;
874 case FILTER_RDYN_STRING:
875 case FILTER_DYN_STRING:
876 offset = *(int *)pos & 0xffff;
877 len = *(int *)pos >> 16;
879 if (field->filter_type == FILTER_RDYN_STRING)
880 offset += field->offset + sizeof(int);
882 if (offset + len > iter->ent_size) {
883 trace_seq_puts(&iter->seq, "<OVERFLOW>");
884 break;
886 pos = (void *)iter->ent + offset;
887 trace_seq_printf(&iter->seq, "%.*s", len, (char *)pos);
888 break;
889 case FILTER_PTR_STRING:
890 if (!iter->fmt_size)
891 trace_iter_expand_format(iter);
892 pos = *(void **)pos;
893 ret = strncpy_from_kernel_nofault(iter->fmt, pos,
894 iter->fmt_size);
895 if (ret < 0)
896 trace_seq_printf(&iter->seq, "(0x%px)", pos);
897 else
898 trace_seq_printf(&iter->seq, "(0x%px:%s)",
899 pos, iter->fmt);
900 break;
901 case FILTER_TRACE_FN:
902 pos = *(void **)pos;
903 trace_seq_printf(&iter->seq, "%pS", pos);
904 break;
905 case FILTER_CPU:
906 case FILTER_OTHER:
907 switch (field->size) {
908 case 1:
909 if (isprint(*(char *)pos)) {
910 trace_seq_printf(&iter->seq, "'%c'",
911 *(unsigned char *)pos);
913 trace_seq_printf(&iter->seq, "(%d)",
914 *(unsigned char *)pos);
915 break;
916 case 2:
917 trace_seq_printf(&iter->seq, "0x%x (%d)",
918 *(unsigned short *)pos,
919 *(unsigned short *)pos);
920 break;
921 case 4:
922 /* dynamic array info is 4 bytes */
923 if (strstr(field->type, "__data_loc")) {
924 print_array(iter, pos, NULL);
925 break;
928 if (strstr(field->type, "__rel_loc")) {
929 print_array(iter, pos, field);
930 break;
933 trace_seq_printf(&iter->seq, "0x%x (%d)",
934 *(unsigned int *)pos,
935 *(unsigned int *)pos);
936 break;
937 case 8:
938 trace_seq_printf(&iter->seq, "0x%llx (%lld)",
939 *(unsigned long long *)pos,
940 *(unsigned long long *)pos);
941 break;
942 default:
943 trace_seq_puts(&iter->seq, "<INVALID-SIZE>");
944 break;
946 break;
947 default:
948 trace_seq_puts(&iter->seq, "<INVALID-TYPE>");
951 trace_seq_putc(&iter->seq, '\n');
954 enum print_line_t print_event_fields(struct trace_iterator *iter,
955 struct trace_event *event)
957 struct trace_event_call *call;
958 struct list_head *head;
960 /* ftrace defined events have separate call structures */
961 if (event->type <= __TRACE_LAST_TYPE) {
962 bool found = false;
964 down_read(&trace_event_sem);
965 list_for_each_entry(call, &ftrace_events, list) {
966 if (call->event.type == event->type) {
967 found = true;
968 break;
970 /* No need to search all events */
971 if (call->event.type > __TRACE_LAST_TYPE)
972 break;
974 up_read(&trace_event_sem);
975 if (!found) {
976 trace_seq_printf(&iter->seq, "UNKNOWN TYPE %d\n", event->type);
977 goto out;
979 } else {
980 call = container_of(event, struct trace_event_call, event);
982 head = trace_get_fields(call);
984 trace_seq_printf(&iter->seq, "%s:", trace_event_name(call));
986 if (head && !list_empty(head))
987 print_fields(iter, call, head);
988 else
989 trace_seq_puts(&iter->seq, "No fields found\n");
991 out:
992 return trace_handle_return(&iter->seq);
995 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
996 struct trace_event *event)
998 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
1000 return trace_handle_return(&iter->seq);
1003 static void print_fn_trace(struct trace_seq *s, unsigned long ip,
1004 unsigned long parent_ip, long delta, int flags)
1006 ip += delta;
1007 parent_ip += delta;
1009 seq_print_ip_sym(s, ip, flags);
1011 if ((flags & TRACE_ITER_PRINT_PARENT) && parent_ip) {
1012 trace_seq_puts(s, " <-");
1013 seq_print_ip_sym(s, parent_ip, flags);
1017 /* TRACE_FN */
1018 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
1019 struct trace_event *event)
1021 struct ftrace_entry *field;
1022 struct trace_seq *s = &iter->seq;
1024 trace_assign_type(field, iter->ent);
1026 print_fn_trace(s, field->ip, field->parent_ip, iter->tr->text_delta, flags);
1027 trace_seq_putc(s, '\n');
1029 return trace_handle_return(s);
1032 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
1033 struct trace_event *event)
1035 struct ftrace_entry *field;
1037 trace_assign_type(field, iter->ent);
1039 trace_seq_printf(&iter->seq, "%lx %lx\n",
1040 field->ip,
1041 field->parent_ip);
1043 return trace_handle_return(&iter->seq);
1046 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
1047 struct trace_event *event)
1049 struct ftrace_entry *field;
1050 struct trace_seq *s = &iter->seq;
1052 trace_assign_type(field, iter->ent);
1054 SEQ_PUT_HEX_FIELD(s, field->ip);
1055 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
1057 return trace_handle_return(s);
1060 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
1061 struct trace_event *event)
1063 struct ftrace_entry *field;
1064 struct trace_seq *s = &iter->seq;
1066 trace_assign_type(field, iter->ent);
1068 SEQ_PUT_FIELD(s, field->ip);
1069 SEQ_PUT_FIELD(s, field->parent_ip);
1071 return trace_handle_return(s);
1074 static struct trace_event_functions trace_fn_funcs = {
1075 .trace = trace_fn_trace,
1076 .raw = trace_fn_raw,
1077 .hex = trace_fn_hex,
1078 .binary = trace_fn_bin,
1081 static struct trace_event trace_fn_event = {
1082 .type = TRACE_FN,
1083 .funcs = &trace_fn_funcs,
1086 /* TRACE_CTX an TRACE_WAKE */
1087 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
1088 char *delim)
1090 struct ctx_switch_entry *field;
1091 char comm[TASK_COMM_LEN];
1092 int S, T;
1095 trace_assign_type(field, iter->ent);
1097 T = task_index_to_char(field->next_state);
1098 S = task_index_to_char(field->prev_state);
1099 trace_find_cmdline(field->next_pid, comm);
1100 trace_seq_printf(&iter->seq,
1101 " %7d:%3d:%c %s [%03d] %7d:%3d:%c %s\n",
1102 field->prev_pid,
1103 field->prev_prio,
1104 S, delim,
1105 field->next_cpu,
1106 field->next_pid,
1107 field->next_prio,
1108 T, comm);
1110 return trace_handle_return(&iter->seq);
1113 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
1114 struct trace_event *event)
1116 return trace_ctxwake_print(iter, "==>");
1119 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
1120 int flags, struct trace_event *event)
1122 return trace_ctxwake_print(iter, " +");
1125 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
1127 struct ctx_switch_entry *field;
1128 int T;
1130 trace_assign_type(field, iter->ent);
1132 if (!S)
1133 S = task_index_to_char(field->prev_state);
1134 T = task_index_to_char(field->next_state);
1135 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
1136 field->prev_pid,
1137 field->prev_prio,
1139 field->next_cpu,
1140 field->next_pid,
1141 field->next_prio,
1144 return trace_handle_return(&iter->seq);
1147 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
1148 struct trace_event *event)
1150 return trace_ctxwake_raw(iter, 0);
1153 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
1154 struct trace_event *event)
1156 return trace_ctxwake_raw(iter, '+');
1160 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
1162 struct ctx_switch_entry *field;
1163 struct trace_seq *s = &iter->seq;
1164 int T;
1166 trace_assign_type(field, iter->ent);
1168 if (!S)
1169 S = task_index_to_char(field->prev_state);
1170 T = task_index_to_char(field->next_state);
1172 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
1173 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
1174 SEQ_PUT_HEX_FIELD(s, S);
1175 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
1176 SEQ_PUT_HEX_FIELD(s, field->next_pid);
1177 SEQ_PUT_HEX_FIELD(s, field->next_prio);
1178 SEQ_PUT_HEX_FIELD(s, T);
1180 return trace_handle_return(s);
1183 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
1184 struct trace_event *event)
1186 return trace_ctxwake_hex(iter, 0);
1189 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
1190 struct trace_event *event)
1192 return trace_ctxwake_hex(iter, '+');
1195 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
1196 int flags, struct trace_event *event)
1198 struct ctx_switch_entry *field;
1199 struct trace_seq *s = &iter->seq;
1201 trace_assign_type(field, iter->ent);
1203 SEQ_PUT_FIELD(s, field->prev_pid);
1204 SEQ_PUT_FIELD(s, field->prev_prio);
1205 SEQ_PUT_FIELD(s, field->prev_state);
1206 SEQ_PUT_FIELD(s, field->next_cpu);
1207 SEQ_PUT_FIELD(s, field->next_pid);
1208 SEQ_PUT_FIELD(s, field->next_prio);
1209 SEQ_PUT_FIELD(s, field->next_state);
1211 return trace_handle_return(s);
1214 static struct trace_event_functions trace_ctx_funcs = {
1215 .trace = trace_ctx_print,
1216 .raw = trace_ctx_raw,
1217 .hex = trace_ctx_hex,
1218 .binary = trace_ctxwake_bin,
1221 static struct trace_event trace_ctx_event = {
1222 .type = TRACE_CTX,
1223 .funcs = &trace_ctx_funcs,
1226 static struct trace_event_functions trace_wake_funcs = {
1227 .trace = trace_wake_print,
1228 .raw = trace_wake_raw,
1229 .hex = trace_wake_hex,
1230 .binary = trace_ctxwake_bin,
1233 static struct trace_event trace_wake_event = {
1234 .type = TRACE_WAKE,
1235 .funcs = &trace_wake_funcs,
1238 /* TRACE_STACK */
1240 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1241 int flags, struct trace_event *event)
1243 struct stack_entry *field;
1244 struct trace_seq *s = &iter->seq;
1245 unsigned long *p;
1246 unsigned long *end;
1247 long delta = iter->tr->text_delta;
1249 trace_assign_type(field, iter->ent);
1250 end = (unsigned long *)((long)iter->ent + iter->ent_size);
1252 trace_seq_puts(s, "<stack trace>\n");
1254 for (p = field->caller; p && p < end && *p != ULONG_MAX; p++) {
1256 if (trace_seq_has_overflowed(s))
1257 break;
1259 trace_seq_puts(s, " => ");
1260 if ((*p) == FTRACE_TRAMPOLINE_MARKER) {
1261 trace_seq_puts(s, "[FTRACE TRAMPOLINE]\n");
1262 continue;
1264 seq_print_ip_sym(s, (*p) + delta, flags);
1265 trace_seq_putc(s, '\n');
1268 return trace_handle_return(s);
1271 static struct trace_event_functions trace_stack_funcs = {
1272 .trace = trace_stack_print,
1275 static struct trace_event trace_stack_event = {
1276 .type = TRACE_STACK,
1277 .funcs = &trace_stack_funcs,
1280 /* TRACE_USER_STACK */
1281 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1282 int flags, struct trace_event *event)
1284 struct trace_array *tr = iter->tr;
1285 struct userstack_entry *field;
1286 struct trace_seq *s = &iter->seq;
1287 struct mm_struct *mm = NULL;
1288 unsigned int i;
1290 trace_assign_type(field, iter->ent);
1292 trace_seq_puts(s, "<user stack trace>\n");
1294 if (tr->trace_flags & TRACE_ITER_SYM_USEROBJ) {
1295 struct task_struct *task;
1297 * we do the lookup on the thread group leader,
1298 * since individual threads might have already quit!
1300 rcu_read_lock();
1301 task = find_task_by_vpid(field->tgid);
1302 if (task)
1303 mm = get_task_mm(task);
1304 rcu_read_unlock();
1307 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1308 unsigned long ip = field->caller[i];
1310 if (!ip || trace_seq_has_overflowed(s))
1311 break;
1313 trace_seq_puts(s, " => ");
1314 seq_print_user_ip(s, mm, ip, flags);
1315 trace_seq_putc(s, '\n');
1318 if (mm)
1319 mmput(mm);
1321 return trace_handle_return(s);
1324 static struct trace_event_functions trace_user_stack_funcs = {
1325 .trace = trace_user_stack_print,
1328 static struct trace_event trace_user_stack_event = {
1329 .type = TRACE_USER_STACK,
1330 .funcs = &trace_user_stack_funcs,
1333 /* TRACE_HWLAT */
1334 static enum print_line_t
1335 trace_hwlat_print(struct trace_iterator *iter, int flags,
1336 struct trace_event *event)
1338 struct trace_entry *entry = iter->ent;
1339 struct trace_seq *s = &iter->seq;
1340 struct hwlat_entry *field;
1342 trace_assign_type(field, entry);
1344 trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld count:%d",
1345 field->seqnum,
1346 field->duration,
1347 field->outer_duration,
1348 (long long)field->timestamp.tv_sec,
1349 field->timestamp.tv_nsec, field->count);
1351 if (field->nmi_count) {
1353 * The generic sched_clock() is not NMI safe, thus
1354 * we only record the count and not the time.
1356 if (!IS_ENABLED(CONFIG_GENERIC_SCHED_CLOCK))
1357 trace_seq_printf(s, " nmi-total:%llu",
1358 field->nmi_total_ts);
1359 trace_seq_printf(s, " nmi-count:%u",
1360 field->nmi_count);
1363 trace_seq_putc(s, '\n');
1365 return trace_handle_return(s);
1368 static enum print_line_t
1369 trace_hwlat_raw(struct trace_iterator *iter, int flags,
1370 struct trace_event *event)
1372 struct hwlat_entry *field;
1373 struct trace_seq *s = &iter->seq;
1375 trace_assign_type(field, iter->ent);
1377 trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
1378 field->duration,
1379 field->outer_duration,
1380 (long long)field->timestamp.tv_sec,
1381 field->timestamp.tv_nsec,
1382 field->seqnum);
1384 return trace_handle_return(s);
1387 static struct trace_event_functions trace_hwlat_funcs = {
1388 .trace = trace_hwlat_print,
1389 .raw = trace_hwlat_raw,
1392 static struct trace_event trace_hwlat_event = {
1393 .type = TRACE_HWLAT,
1394 .funcs = &trace_hwlat_funcs,
1397 /* TRACE_OSNOISE */
1398 static enum print_line_t
1399 trace_osnoise_print(struct trace_iterator *iter, int flags,
1400 struct trace_event *event)
1402 struct trace_entry *entry = iter->ent;
1403 struct trace_seq *s = &iter->seq;
1404 struct osnoise_entry *field;
1405 u64 ratio, ratio_dec;
1406 u64 net_runtime;
1408 trace_assign_type(field, entry);
1411 * compute the available % of cpu time.
1413 net_runtime = field->runtime - field->noise;
1414 ratio = net_runtime * 10000000;
1415 do_div(ratio, field->runtime);
1416 ratio_dec = do_div(ratio, 100000);
1418 trace_seq_printf(s, "%llu %10llu %3llu.%05llu %7llu",
1419 field->runtime,
1420 field->noise,
1421 ratio, ratio_dec,
1422 field->max_sample);
1424 trace_seq_printf(s, " %6u", field->hw_count);
1425 trace_seq_printf(s, " %6u", field->nmi_count);
1426 trace_seq_printf(s, " %6u", field->irq_count);
1427 trace_seq_printf(s, " %6u", field->softirq_count);
1428 trace_seq_printf(s, " %6u", field->thread_count);
1430 trace_seq_putc(s, '\n');
1432 return trace_handle_return(s);
1435 static enum print_line_t
1436 trace_osnoise_raw(struct trace_iterator *iter, int flags,
1437 struct trace_event *event)
1439 struct osnoise_entry *field;
1440 struct trace_seq *s = &iter->seq;
1442 trace_assign_type(field, iter->ent);
1444 trace_seq_printf(s, "%lld %llu %llu %u %u %u %u %u\n",
1445 field->runtime,
1446 field->noise,
1447 field->max_sample,
1448 field->hw_count,
1449 field->nmi_count,
1450 field->irq_count,
1451 field->softirq_count,
1452 field->thread_count);
1454 return trace_handle_return(s);
1457 static struct trace_event_functions trace_osnoise_funcs = {
1458 .trace = trace_osnoise_print,
1459 .raw = trace_osnoise_raw,
1462 static struct trace_event trace_osnoise_event = {
1463 .type = TRACE_OSNOISE,
1464 .funcs = &trace_osnoise_funcs,
1467 /* TRACE_TIMERLAT */
1469 static char *timerlat_lat_context[] = {"irq", "thread", "user-ret"};
1470 static enum print_line_t
1471 trace_timerlat_print(struct trace_iterator *iter, int flags,
1472 struct trace_event *event)
1474 struct trace_entry *entry = iter->ent;
1475 struct trace_seq *s = &iter->seq;
1476 struct timerlat_entry *field;
1478 trace_assign_type(field, entry);
1480 trace_seq_printf(s, "#%-5u context %6s timer_latency %9llu ns\n",
1481 field->seqnum,
1482 timerlat_lat_context[field->context],
1483 field->timer_latency);
1485 return trace_handle_return(s);
1488 static enum print_line_t
1489 trace_timerlat_raw(struct trace_iterator *iter, int flags,
1490 struct trace_event *event)
1492 struct timerlat_entry *field;
1493 struct trace_seq *s = &iter->seq;
1495 trace_assign_type(field, iter->ent);
1497 trace_seq_printf(s, "%u %d %llu\n",
1498 field->seqnum,
1499 field->context,
1500 field->timer_latency);
1502 return trace_handle_return(s);
1505 static struct trace_event_functions trace_timerlat_funcs = {
1506 .trace = trace_timerlat_print,
1507 .raw = trace_timerlat_raw,
1510 static struct trace_event trace_timerlat_event = {
1511 .type = TRACE_TIMERLAT,
1512 .funcs = &trace_timerlat_funcs,
1515 /* TRACE_BPUTS */
1516 static enum print_line_t
1517 trace_bputs_print(struct trace_iterator *iter, int flags,
1518 struct trace_event *event)
1520 struct trace_entry *entry = iter->ent;
1521 struct trace_seq *s = &iter->seq;
1522 struct bputs_entry *field;
1524 trace_assign_type(field, entry);
1526 seq_print_ip_sym(s, field->ip, flags);
1527 trace_seq_puts(s, ": ");
1528 trace_seq_puts(s, field->str);
1530 return trace_handle_return(s);
1534 static enum print_line_t
1535 trace_bputs_raw(struct trace_iterator *iter, int flags,
1536 struct trace_event *event)
1538 struct bputs_entry *field;
1539 struct trace_seq *s = &iter->seq;
1541 trace_assign_type(field, iter->ent);
1543 trace_seq_printf(s, ": %lx : ", field->ip);
1544 trace_seq_puts(s, field->str);
1546 return trace_handle_return(s);
1549 static struct trace_event_functions trace_bputs_funcs = {
1550 .trace = trace_bputs_print,
1551 .raw = trace_bputs_raw,
1554 static struct trace_event trace_bputs_event = {
1555 .type = TRACE_BPUTS,
1556 .funcs = &trace_bputs_funcs,
1559 /* TRACE_BPRINT */
1560 static enum print_line_t
1561 trace_bprint_print(struct trace_iterator *iter, int flags,
1562 struct trace_event *event)
1564 struct trace_entry *entry = iter->ent;
1565 struct trace_seq *s = &iter->seq;
1566 struct bprint_entry *field;
1568 trace_assign_type(field, entry);
1570 seq_print_ip_sym(s, field->ip, flags);
1571 trace_seq_puts(s, ": ");
1572 trace_seq_bprintf(s, field->fmt, field->buf);
1574 return trace_handle_return(s);
1578 static enum print_line_t
1579 trace_bprint_raw(struct trace_iterator *iter, int flags,
1580 struct trace_event *event)
1582 struct bprint_entry *field;
1583 struct trace_seq *s = &iter->seq;
1585 trace_assign_type(field, iter->ent);
1587 trace_seq_printf(s, ": %lx : ", field->ip);
1588 trace_seq_bprintf(s, field->fmt, field->buf);
1590 return trace_handle_return(s);
1593 static struct trace_event_functions trace_bprint_funcs = {
1594 .trace = trace_bprint_print,
1595 .raw = trace_bprint_raw,
1598 static struct trace_event trace_bprint_event = {
1599 .type = TRACE_BPRINT,
1600 .funcs = &trace_bprint_funcs,
1603 /* TRACE_PRINT */
1604 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1605 int flags, struct trace_event *event)
1607 struct print_entry *field;
1608 struct trace_seq *s = &iter->seq;
1609 unsigned long ip;
1611 trace_assign_type(field, iter->ent);
1613 ip = field->ip + iter->tr->text_delta;
1615 seq_print_ip_sym(s, ip, flags);
1616 trace_seq_printf(s, ": %s", field->buf);
1618 return trace_handle_return(s);
1621 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1622 struct trace_event *event)
1624 struct print_entry *field;
1626 trace_assign_type(field, iter->ent);
1628 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
1630 return trace_handle_return(&iter->seq);
1633 static struct trace_event_functions trace_print_funcs = {
1634 .trace = trace_print_print,
1635 .raw = trace_print_raw,
1638 static struct trace_event trace_print_event = {
1639 .type = TRACE_PRINT,
1640 .funcs = &trace_print_funcs,
1643 static enum print_line_t trace_raw_data(struct trace_iterator *iter, int flags,
1644 struct trace_event *event)
1646 struct raw_data_entry *field;
1647 int i;
1649 trace_assign_type(field, iter->ent);
1651 trace_seq_printf(&iter->seq, "# %x buf:", field->id);
1653 for (i = 0; i < iter->ent_size - offsetof(struct raw_data_entry, buf); i++)
1654 trace_seq_printf(&iter->seq, " %02x",
1655 (unsigned char)field->buf[i]);
1657 trace_seq_putc(&iter->seq, '\n');
1659 return trace_handle_return(&iter->seq);
1662 static struct trace_event_functions trace_raw_data_funcs = {
1663 .trace = trace_raw_data,
1664 .raw = trace_raw_data,
1667 static struct trace_event trace_raw_data_event = {
1668 .type = TRACE_RAW_DATA,
1669 .funcs = &trace_raw_data_funcs,
1672 static enum print_line_t
1673 trace_func_repeats_raw(struct trace_iterator *iter, int flags,
1674 struct trace_event *event)
1676 struct func_repeats_entry *field;
1677 struct trace_seq *s = &iter->seq;
1679 trace_assign_type(field, iter->ent);
1681 trace_seq_printf(s, "%lu %lu %u %llu\n",
1682 field->ip,
1683 field->parent_ip,
1684 field->count,
1685 FUNC_REPEATS_GET_DELTA_TS(field));
1687 return trace_handle_return(s);
1690 static enum print_line_t
1691 trace_func_repeats_print(struct trace_iterator *iter, int flags,
1692 struct trace_event *event)
1694 struct func_repeats_entry *field;
1695 struct trace_seq *s = &iter->seq;
1697 trace_assign_type(field, iter->ent);
1699 print_fn_trace(s, field->ip, field->parent_ip, iter->tr->text_delta, flags);
1700 trace_seq_printf(s, " (repeats: %u, last_ts:", field->count);
1701 trace_print_time(s, iter,
1702 iter->ts - FUNC_REPEATS_GET_DELTA_TS(field));
1703 trace_seq_puts(s, ")\n");
1705 return trace_handle_return(s);
1708 static struct trace_event_functions trace_func_repeats_funcs = {
1709 .trace = trace_func_repeats_print,
1710 .raw = trace_func_repeats_raw,
1713 static struct trace_event trace_func_repeats_event = {
1714 .type = TRACE_FUNC_REPEATS,
1715 .funcs = &trace_func_repeats_funcs,
1718 static struct trace_event *events[] __initdata = {
1719 &trace_fn_event,
1720 &trace_ctx_event,
1721 &trace_wake_event,
1722 &trace_stack_event,
1723 &trace_user_stack_event,
1724 &trace_bputs_event,
1725 &trace_bprint_event,
1726 &trace_print_event,
1727 &trace_hwlat_event,
1728 &trace_osnoise_event,
1729 &trace_timerlat_event,
1730 &trace_raw_data_event,
1731 &trace_func_repeats_event,
1732 NULL
1735 __init int init_events(void)
1737 struct trace_event *event;
1738 int i, ret;
1740 for (i = 0; events[i]; i++) {
1741 event = events[i];
1742 ret = register_trace_event(event);
1743 WARN_ONCE(!ret, "event %d failed to register", event->type);
1746 return 0;