f0ba97121345bf36bd710368b4f8c447caef5f97
[platform/kernel/linux-rpi.git] / kernel / trace / trace_output.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * trace_output.c
4  *
5  * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
6  *
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>
15
16 #include "trace_output.h"
17
18 /* must be a power of 2 */
19 #define EVENT_HASHSIZE  128
20
21 DECLARE_RWSEM(trace_event_sem);
22
23 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
24
25 enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
26 {
27         struct trace_seq *s = &iter->seq;
28         struct trace_entry *entry = iter->ent;
29         struct bputs_entry *field;
30
31         trace_assign_type(field, entry);
32
33         trace_seq_puts(s, field->str);
34
35         return trace_handle_return(s);
36 }
37
38 enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
39 {
40         struct trace_seq *s = &iter->seq;
41         struct trace_entry *entry = iter->ent;
42         struct bprint_entry *field;
43
44         trace_assign_type(field, entry);
45
46         trace_seq_bprintf(s, field->fmt, field->buf);
47
48         return trace_handle_return(s);
49 }
50
51 enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
52 {
53         struct trace_seq *s = &iter->seq;
54         struct trace_entry *entry = iter->ent;
55         struct print_entry *field;
56
57         trace_assign_type(field, entry);
58
59         trace_seq_puts(s, field->buf);
60
61         return trace_handle_return(s);
62 }
63
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)
68 {
69         unsigned long mask;
70         const char *str;
71         const char *ret = trace_seq_buffer_ptr(p);
72         int i, first = 1;
73
74         for (i = 0;  flag_array[i].name && flags; i++) {
75
76                 mask = flag_array[i].mask;
77                 if ((flags & mask) != mask)
78                         continue;
79
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);
87         }
88
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);
94         }
95
96         trace_seq_putc(p, 0);
97
98         return ret;
99 }
100 EXPORT_SYMBOL(trace_print_flags_seq);
101
102 const char *
103 trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
104                         const struct trace_print_flags *symbol_array)
105 {
106         int i;
107         const char *ret = trace_seq_buffer_ptr(p);
108
109         for (i = 0;  symbol_array[i].name; i++) {
110
111                 if (val != symbol_array[i].mask)
112                         continue;
113
114                 trace_seq_puts(p, symbol_array[i].name);
115                 break;
116         }
117
118         if (ret == (const char *)(trace_seq_buffer_ptr(p)))
119                 trace_seq_printf(p, "0x%lx", val);
120
121         trace_seq_putc(p, 0);
122
123         return ret;
124 }
125 EXPORT_SYMBOL(trace_print_symbols_seq);
126
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)
132 {
133         unsigned long long mask;
134         const char *str;
135         const char *ret = trace_seq_buffer_ptr(p);
136         int i, first = 1;
137
138         for (i = 0;  flag_array[i].name && flags; i++) {
139
140                 mask = flag_array[i].mask;
141                 if ((flags & mask) != mask)
142                         continue;
143
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);
151         }
152
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);
158         }
159
160         trace_seq_putc(p, 0);
161
162         return ret;
163 }
164 EXPORT_SYMBOL(trace_print_flags_seq_u64);
165
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)
169 {
170         int i;
171         const char *ret = trace_seq_buffer_ptr(p);
172
173         for (i = 0;  symbol_array[i].name; i++) {
174
175                 if (val != symbol_array[i].mask)
176                         continue;
177
178                 trace_seq_puts(p, symbol_array[i].name);
179                 break;
180         }
181
182         if (ret == (const char *)(trace_seq_buffer_ptr(p)))
183                 trace_seq_printf(p, "0x%llx", val);
184
185         trace_seq_putc(p, 0);
186
187         return ret;
188 }
189 EXPORT_SYMBOL(trace_print_symbols_seq_u64);
190 #endif
191
192 const char *
193 trace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
194                         unsigned int bitmask_size)
195 {
196         const char *ret = trace_seq_buffer_ptr(p);
197
198         trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8);
199         trace_seq_putc(p, 0);
200
201         return ret;
202 }
203 EXPORT_SYMBOL_GPL(trace_print_bitmask_seq);
204
205 /**
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
211  *
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.
215  */
216 const char *
217 trace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len,
218                     bool concatenate)
219 {
220         int i;
221         const char *ret = trace_seq_buffer_ptr(p);
222         const char *fmt = concatenate ? "%*phN" : "%*ph";
223
224         for (i = 0; i < buf_len; i += 16)
225                 trace_seq_printf(p, fmt, min(buf_len - i, 16), &buf[i]);
226         trace_seq_putc(p, 0);
227
228         return ret;
229 }
230 EXPORT_SYMBOL(trace_print_hex_seq);
231
232 const char *
233 trace_print_array_seq(struct trace_seq *p, const void *buf, int count,
234                       size_t el_size)
235 {
236         const char *ret = trace_seq_buffer_ptr(p);
237         const char *prefix = "";
238         void *ptr = (void *)buf;
239         size_t buf_len = count * el_size;
240
241         trace_seq_putc(p, '{');
242
243         while (ptr < buf + buf_len) {
244                 switch (el_size) {
245                 case 1:
246                         trace_seq_printf(p, "%s0x%x", prefix,
247                                          *(u8 *)ptr);
248                         break;
249                 case 2:
250                         trace_seq_printf(p, "%s0x%x", prefix,
251                                          *(u16 *)ptr);
252                         break;
253                 case 4:
254                         trace_seq_printf(p, "%s0x%x", prefix,
255                                          *(u32 *)ptr);
256                         break;
257                 case 8:
258                         trace_seq_printf(p, "%s0x%llx", prefix,
259                                          *(u64 *)ptr);
260                         break;
261                 default:
262                         trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size,
263                                          *(u8 *)ptr);
264                         el_size = 1;
265                 }
266                 prefix = ",";
267                 ptr += el_size;
268         }
269
270         trace_seq_putc(p, '}');
271         trace_seq_putc(p, 0);
272
273         return ret;
274 }
275 EXPORT_SYMBOL(trace_print_array_seq);
276
277 const char *
278 trace_print_hex_dump_seq(struct trace_seq *p, const char *prefix_str,
279                          int prefix_type, int rowsize, int groupsize,
280                          const void *buf, size_t len, bool ascii)
281 {
282         const char *ret = trace_seq_buffer_ptr(p);
283
284         trace_seq_putc(p, '\n');
285         trace_seq_hex_dump(p, prefix_str, prefix_type,
286                            rowsize, groupsize, buf, len, ascii);
287         trace_seq_putc(p, 0);
288         return ret;
289 }
290 EXPORT_SYMBOL(trace_print_hex_dump_seq);
291
292 int trace_raw_output_prep(struct trace_iterator *iter,
293                           struct trace_event *trace_event)
294 {
295         struct trace_event_call *event;
296         struct trace_seq *s = &iter->seq;
297         struct trace_seq *p = &iter->tmp_seq;
298         struct trace_entry *entry;
299
300         event = container_of(trace_event, struct trace_event_call, event);
301         entry = iter->ent;
302
303         if (entry->type != event->event.type) {
304                 WARN_ON_ONCE(1);
305                 return TRACE_TYPE_UNHANDLED;
306         }
307
308         trace_seq_init(p);
309         trace_seq_printf(s, "%s: ", trace_event_name(event));
310
311         return trace_handle_return(s);
312 }
313 EXPORT_SYMBOL(trace_raw_output_prep);
314
315 void trace_event_printf(struct trace_iterator *iter, const char *fmt, ...)
316 {
317         va_list ap;
318
319         va_start(ap, fmt);
320         trace_check_vprintf(iter, trace_event_format(iter, fmt), ap);
321         va_end(ap);
322 }
323 EXPORT_SYMBOL(trace_event_printf);
324
325 static int trace_output_raw(struct trace_iterator *iter, char *name,
326                             char *fmt, va_list ap)
327 {
328         struct trace_seq *s = &iter->seq;
329
330         trace_seq_printf(s, "%s: ", name);
331         trace_seq_vprintf(s, trace_event_format(iter, fmt), ap);
332
333         return trace_handle_return(s);
334 }
335
336 int trace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
337 {
338         va_list ap;
339         int ret;
340
341         va_start(ap, fmt);
342         ret = trace_output_raw(iter, name, fmt, ap);
343         va_end(ap);
344
345         return ret;
346 }
347 EXPORT_SYMBOL_GPL(trace_output_call);
348
349 static inline const char *kretprobed(const char *name, unsigned long addr)
350 {
351         if (is_kretprobe_trampoline(addr))
352                 return "[unknown/kretprobe'd]";
353         return name;
354 }
355
356 void
357 trace_seq_print_sym(struct trace_seq *s, unsigned long address, bool offset)
358 {
359 #ifdef CONFIG_KALLSYMS
360         char str[KSYM_SYMBOL_LEN];
361         const char *name;
362
363         if (offset)
364                 sprint_symbol(str, address);
365         else
366                 kallsyms_lookup(address, NULL, NULL, NULL, str);
367         name = kretprobed(str, address);
368
369         if (name && strlen(name)) {
370                 trace_seq_puts(s, name);
371                 return;
372         }
373 #endif
374         trace_seq_printf(s, "0x%08lx", address);
375 }
376
377 #ifndef CONFIG_64BIT
378 # define IP_FMT "%08lx"
379 #else
380 # define IP_FMT "%016lx"
381 #endif
382
383 static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
384                              unsigned long ip, unsigned long sym_flags)
385 {
386         struct file *file = NULL;
387         unsigned long vmstart = 0;
388         int ret = 1;
389
390         if (s->full)
391                 return 0;
392
393         if (mm) {
394                 const struct vm_area_struct *vma;
395
396                 mmap_read_lock(mm);
397                 vma = find_vma(mm, ip);
398                 if (vma) {
399                         file = vma->vm_file;
400                         vmstart = vma->vm_start;
401                 }
402                 if (file) {
403                         ret = trace_seq_path(s, &file->f_path);
404                         if (ret)
405                                 trace_seq_printf(s, "[+0x%lx]",
406                                                  ip - vmstart);
407                 }
408                 mmap_read_unlock(mm);
409         }
410         if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
411                 trace_seq_printf(s, " <" IP_FMT ">", ip);
412         return !trace_seq_has_overflowed(s);
413 }
414
415 int
416 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
417 {
418         if (!ip) {
419                 trace_seq_putc(s, '0');
420                 goto out;
421         }
422
423         trace_seq_print_sym(s, ip, sym_flags & TRACE_ITER_SYM_OFFSET);
424
425         if (sym_flags & TRACE_ITER_SYM_ADDR)
426                 trace_seq_printf(s, " <" IP_FMT ">", ip);
427
428  out:
429         return !trace_seq_has_overflowed(s);
430 }
431
432 /**
433  * trace_print_lat_fmt - print the irq, preempt and lockdep fields
434  * @s: trace seq struct to write to
435  * @entry: The trace entry field from the ring buffer
436  *
437  * Prints the generic fields of irqs off, in hard or softirq, preempt
438  * count.
439  */
440 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
441 {
442         char hardsoft_irq;
443         char need_resched;
444         char irqs_off;
445         int hardirq;
446         int softirq;
447         int bh_off;
448         int nmi;
449
450         nmi = entry->flags & TRACE_FLAG_NMI;
451         hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
452         softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
453         bh_off = entry->flags & TRACE_FLAG_BH_OFF;
454
455         irqs_off =
456                 (entry->flags & TRACE_FLAG_IRQS_OFF && bh_off) ? 'D' :
457                 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
458                 bh_off ? 'b' :
459                 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
460                 '.';
461
462         switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
463                                 TRACE_FLAG_PREEMPT_RESCHED)) {
464         case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
465                 need_resched = 'N';
466                 break;
467         case TRACE_FLAG_NEED_RESCHED:
468                 need_resched = 'n';
469                 break;
470         case TRACE_FLAG_PREEMPT_RESCHED:
471                 need_resched = 'p';
472                 break;
473         default:
474                 need_resched = '.';
475                 break;
476         }
477
478         hardsoft_irq =
479                 (nmi && hardirq)     ? 'Z' :
480                 nmi                  ? 'z' :
481                 (hardirq && softirq) ? 'H' :
482                 hardirq              ? 'h' :
483                 softirq              ? 's' :
484                                        '.' ;
485
486         trace_seq_printf(s, "%c%c%c",
487                          irqs_off, need_resched, hardsoft_irq);
488
489         if (entry->preempt_count & 0xf)
490                 trace_seq_printf(s, "%x", entry->preempt_count & 0xf);
491         else
492                 trace_seq_putc(s, '.');
493
494         if (entry->preempt_count & 0xf0)
495                 trace_seq_printf(s, "%x", entry->preempt_count >> 4);
496         else
497                 trace_seq_putc(s, '.');
498
499         return !trace_seq_has_overflowed(s);
500 }
501
502 static int
503 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
504 {
505         char comm[TASK_COMM_LEN];
506
507         trace_find_cmdline(entry->pid, comm);
508
509         trace_seq_printf(s, "%8.8s-%-7d %3d",
510                          comm, entry->pid, cpu);
511
512         return trace_print_lat_fmt(s, entry);
513 }
514
515 #undef MARK
516 #define MARK(v, s) {.val = v, .sym = s}
517 /* trace overhead mark */
518 static const struct trace_mark {
519         unsigned long long      val; /* unit: nsec */
520         char                    sym;
521 } mark[] = {
522         MARK(1000000000ULL      , '$'), /* 1 sec */
523         MARK(100000000ULL       , '@'), /* 100 msec */
524         MARK(10000000ULL        , '*'), /* 10 msec */
525         MARK(1000000ULL         , '#'), /* 1000 usecs */
526         MARK(100000ULL          , '!'), /* 100 usecs */
527         MARK(10000ULL           , '+'), /* 10 usecs */
528 };
529 #undef MARK
530
531 char trace_find_mark(unsigned long long d)
532 {
533         int i;
534         int size = ARRAY_SIZE(mark);
535
536         for (i = 0; i < size; i++) {
537                 if (d > mark[i].val)
538                         break;
539         }
540
541         return (i == size) ? ' ' : mark[i].sym;
542 }
543
544 static int
545 lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
546 {
547         struct trace_array *tr = iter->tr;
548         unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE;
549         unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
550         unsigned long long abs_ts = iter->ts - iter->array_buffer->time_start;
551         unsigned long long rel_ts = next_ts - iter->ts;
552         struct trace_seq *s = &iter->seq;
553
554         if (in_ns) {
555                 abs_ts = ns2usecs(abs_ts);
556                 rel_ts = ns2usecs(rel_ts);
557         }
558
559         if (verbose && in_ns) {
560                 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
561                 unsigned long abs_msec = (unsigned long)abs_ts;
562                 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
563                 unsigned long rel_msec = (unsigned long)rel_ts;
564
565                 trace_seq_printf(
566                         s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
567                         ns2usecs(iter->ts),
568                         abs_msec, abs_usec,
569                         rel_msec, rel_usec);
570
571         } else if (verbose && !in_ns) {
572                 trace_seq_printf(
573                         s, "[%016llx] %lld (+%lld): ",
574                         iter->ts, abs_ts, rel_ts);
575
576         } else if (!verbose && in_ns) {
577                 trace_seq_printf(
578                         s, " %4lldus%c: ",
579                         abs_ts,
580                         trace_find_mark(rel_ts * NSEC_PER_USEC));
581
582         } else { /* !verbose && !in_ns */
583                 trace_seq_printf(s, " %4lld: ", abs_ts);
584         }
585
586         return !trace_seq_has_overflowed(s);
587 }
588
589 static void trace_print_time(struct trace_seq *s, struct trace_iterator *iter,
590                              unsigned long long ts)
591 {
592         unsigned long secs, usec_rem;
593         unsigned long long t;
594
595         if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
596                 t = ns2usecs(ts);
597                 usec_rem = do_div(t, USEC_PER_SEC);
598                 secs = (unsigned long)t;
599                 trace_seq_printf(s, " %5lu.%06lu", secs, usec_rem);
600         } else
601                 trace_seq_printf(s, " %12llu", ts);
602 }
603
604 int trace_print_context(struct trace_iterator *iter)
605 {
606         struct trace_array *tr = iter->tr;
607         struct trace_seq *s = &iter->seq;
608         struct trace_entry *entry = iter->ent;
609         char comm[TASK_COMM_LEN];
610
611         trace_find_cmdline(entry->pid, comm);
612
613         trace_seq_printf(s, "%16s-%-7d ", comm, entry->pid);
614
615         if (tr->trace_flags & TRACE_ITER_RECORD_TGID) {
616                 unsigned int tgid = trace_find_tgid(entry->pid);
617
618                 if (!tgid)
619                         trace_seq_printf(s, "(-------) ");
620                 else
621                         trace_seq_printf(s, "(%7d) ", tgid);
622         }
623
624         trace_seq_printf(s, "[%03d] ", iter->cpu);
625
626         if (tr->trace_flags & TRACE_ITER_IRQ_INFO)
627                 trace_print_lat_fmt(s, entry);
628
629         trace_print_time(s, iter, iter->ts);
630         trace_seq_puts(s, ": ");
631
632         return !trace_seq_has_overflowed(s);
633 }
634
635 int trace_print_lat_context(struct trace_iterator *iter)
636 {
637         struct trace_entry *entry, *next_entry;
638         struct trace_array *tr = iter->tr;
639         struct trace_seq *s = &iter->seq;
640         unsigned long verbose = (tr->trace_flags & TRACE_ITER_VERBOSE);
641         u64 next_ts;
642
643         next_entry = trace_find_next_entry(iter, NULL, &next_ts);
644         if (!next_entry)
645                 next_ts = iter->ts;
646
647         /* trace_find_next_entry() may change iter->ent */
648         entry = iter->ent;
649
650         if (verbose) {
651                 char comm[TASK_COMM_LEN];
652
653                 trace_find_cmdline(entry->pid, comm);
654
655                 trace_seq_printf(
656                         s, "%16s %7d %3d %d %08x %08lx ",
657                         comm, entry->pid, iter->cpu, entry->flags,
658                         entry->preempt_count & 0xf, iter->idx);
659         } else {
660                 lat_print_generic(s, entry, iter->cpu);
661         }
662
663         lat_print_timestamp(iter, next_ts);
664
665         return !trace_seq_has_overflowed(s);
666 }
667
668 /**
669  * ftrace_find_event - find a registered event
670  * @type: the type of event to look for
671  *
672  * Returns an event of type @type otherwise NULL
673  * Called with trace_event_read_lock() held.
674  */
675 struct trace_event *ftrace_find_event(int type)
676 {
677         struct trace_event *event;
678         unsigned key;
679
680         key = type & (EVENT_HASHSIZE - 1);
681
682         hlist_for_each_entry(event, &event_hash[key], node) {
683                 if (event->type == type)
684                         return event;
685         }
686
687         return NULL;
688 }
689
690 static DEFINE_IDA(trace_event_ida);
691
692 static void free_trace_event_type(int type)
693 {
694         if (type >= __TRACE_LAST_TYPE)
695                 ida_free(&trace_event_ida, type);
696 }
697
698 static int alloc_trace_event_type(void)
699 {
700         int next;
701
702         /* Skip static defined type numbers */
703         next = ida_alloc_range(&trace_event_ida, __TRACE_LAST_TYPE,
704                                TRACE_EVENT_TYPE_MAX, GFP_KERNEL);
705         if (next < 0)
706                 return 0;
707         return next;
708 }
709
710 void trace_event_read_lock(void)
711 {
712         down_read(&trace_event_sem);
713 }
714
715 void trace_event_read_unlock(void)
716 {
717         up_read(&trace_event_sem);
718 }
719
720 /**
721  * register_trace_event - register output for an event type
722  * @event: the event type to register
723  *
724  * Event types are stored in a hash and this hash is used to
725  * find a way to print an event. If the @event->type is set
726  * then it will use that type, otherwise it will assign a
727  * type to use.
728  *
729  * If you assign your own type, please make sure it is added
730  * to the trace_type enum in trace.h, to avoid collisions
731  * with the dynamic types.
732  *
733  * Returns the event type number or zero on error.
734  */
735 int register_trace_event(struct trace_event *event)
736 {
737         unsigned key;
738         int ret = 0;
739
740         down_write(&trace_event_sem);
741
742         if (WARN_ON(!event))
743                 goto out;
744
745         if (WARN_ON(!event->funcs))
746                 goto out;
747
748         if (!event->type) {
749                 event->type = alloc_trace_event_type();
750                 if (!event->type)
751                         goto out;
752         } else if (WARN(event->type > __TRACE_LAST_TYPE,
753                         "Need to add type to trace.h")) {
754                 goto out;
755         } else {
756                 /* Is this event already used */
757                 if (ftrace_find_event(event->type))
758                         goto out;
759         }
760
761         if (event->funcs->trace == NULL)
762                 event->funcs->trace = trace_nop_print;
763         if (event->funcs->raw == NULL)
764                 event->funcs->raw = trace_nop_print;
765         if (event->funcs->hex == NULL)
766                 event->funcs->hex = trace_nop_print;
767         if (event->funcs->binary == NULL)
768                 event->funcs->binary = trace_nop_print;
769
770         key = event->type & (EVENT_HASHSIZE - 1);
771
772         hlist_add_head(&event->node, &event_hash[key]);
773
774         ret = event->type;
775  out:
776         up_write(&trace_event_sem);
777
778         return ret;
779 }
780 EXPORT_SYMBOL_GPL(register_trace_event);
781
782 /*
783  * Used by module code with the trace_event_sem held for write.
784  */
785 int __unregister_trace_event(struct trace_event *event)
786 {
787         hlist_del(&event->node);
788         free_trace_event_type(event->type);
789         return 0;
790 }
791
792 /**
793  * unregister_trace_event - remove a no longer used event
794  * @event: the event to remove
795  */
796 int unregister_trace_event(struct trace_event *event)
797 {
798         down_write(&trace_event_sem);
799         __unregister_trace_event(event);
800         up_write(&trace_event_sem);
801
802         return 0;
803 }
804 EXPORT_SYMBOL_GPL(unregister_trace_event);
805
806 /*
807  * Standard events
808  */
809
810 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
811                                   struct trace_event *event)
812 {
813         trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
814
815         return trace_handle_return(&iter->seq);
816 }
817
818 static void print_fn_trace(struct trace_seq *s, unsigned long ip,
819                            unsigned long parent_ip, int flags)
820 {
821         seq_print_ip_sym(s, ip, flags);
822
823         if ((flags & TRACE_ITER_PRINT_PARENT) && parent_ip) {
824                 trace_seq_puts(s, " <-");
825                 seq_print_ip_sym(s, parent_ip, flags);
826         }
827 }
828
829 /* TRACE_FN */
830 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
831                                         struct trace_event *event)
832 {
833         struct ftrace_entry *field;
834         struct trace_seq *s = &iter->seq;
835
836         trace_assign_type(field, iter->ent);
837
838         print_fn_trace(s, field->ip, field->parent_ip, flags);
839         trace_seq_putc(s, '\n');
840
841         return trace_handle_return(s);
842 }
843
844 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
845                                       struct trace_event *event)
846 {
847         struct ftrace_entry *field;
848
849         trace_assign_type(field, iter->ent);
850
851         trace_seq_printf(&iter->seq, "%lx %lx\n",
852                          field->ip,
853                          field->parent_ip);
854
855         return trace_handle_return(&iter->seq);
856 }
857
858 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
859                                       struct trace_event *event)
860 {
861         struct ftrace_entry *field;
862         struct trace_seq *s = &iter->seq;
863
864         trace_assign_type(field, iter->ent);
865
866         SEQ_PUT_HEX_FIELD(s, field->ip);
867         SEQ_PUT_HEX_FIELD(s, field->parent_ip);
868
869         return trace_handle_return(s);
870 }
871
872 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
873                                       struct trace_event *event)
874 {
875         struct ftrace_entry *field;
876         struct trace_seq *s = &iter->seq;
877
878         trace_assign_type(field, iter->ent);
879
880         SEQ_PUT_FIELD(s, field->ip);
881         SEQ_PUT_FIELD(s, field->parent_ip);
882
883         return trace_handle_return(s);
884 }
885
886 static struct trace_event_functions trace_fn_funcs = {
887         .trace          = trace_fn_trace,
888         .raw            = trace_fn_raw,
889         .hex            = trace_fn_hex,
890         .binary         = trace_fn_bin,
891 };
892
893 static struct trace_event trace_fn_event = {
894         .type           = TRACE_FN,
895         .funcs          = &trace_fn_funcs,
896 };
897
898 /* TRACE_CTX an TRACE_WAKE */
899 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
900                                              char *delim)
901 {
902         struct ctx_switch_entry *field;
903         char comm[TASK_COMM_LEN];
904         int S, T;
905
906
907         trace_assign_type(field, iter->ent);
908
909         T = task_index_to_char(field->next_state);
910         S = task_index_to_char(field->prev_state);
911         trace_find_cmdline(field->next_pid, comm);
912         trace_seq_printf(&iter->seq,
913                          " %7d:%3d:%c %s [%03d] %7d:%3d:%c %s\n",
914                          field->prev_pid,
915                          field->prev_prio,
916                          S, delim,
917                          field->next_cpu,
918                          field->next_pid,
919                          field->next_prio,
920                          T, comm);
921
922         return trace_handle_return(&iter->seq);
923 }
924
925 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
926                                          struct trace_event *event)
927 {
928         return trace_ctxwake_print(iter, "==>");
929 }
930
931 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
932                                           int flags, struct trace_event *event)
933 {
934         return trace_ctxwake_print(iter, "  +");
935 }
936
937 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
938 {
939         struct ctx_switch_entry *field;
940         int T;
941
942         trace_assign_type(field, iter->ent);
943
944         if (!S)
945                 S = task_index_to_char(field->prev_state);
946         T = task_index_to_char(field->next_state);
947         trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
948                          field->prev_pid,
949                          field->prev_prio,
950                          S,
951                          field->next_cpu,
952                          field->next_pid,
953                          field->next_prio,
954                          T);
955
956         return trace_handle_return(&iter->seq);
957 }
958
959 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
960                                        struct trace_event *event)
961 {
962         return trace_ctxwake_raw(iter, 0);
963 }
964
965 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
966                                         struct trace_event *event)
967 {
968         return trace_ctxwake_raw(iter, '+');
969 }
970
971
972 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
973 {
974         struct ctx_switch_entry *field;
975         struct trace_seq *s = &iter->seq;
976         int T;
977
978         trace_assign_type(field, iter->ent);
979
980         if (!S)
981                 S = task_index_to_char(field->prev_state);
982         T = task_index_to_char(field->next_state);
983
984         SEQ_PUT_HEX_FIELD(s, field->prev_pid);
985         SEQ_PUT_HEX_FIELD(s, field->prev_prio);
986         SEQ_PUT_HEX_FIELD(s, S);
987         SEQ_PUT_HEX_FIELD(s, field->next_cpu);
988         SEQ_PUT_HEX_FIELD(s, field->next_pid);
989         SEQ_PUT_HEX_FIELD(s, field->next_prio);
990         SEQ_PUT_HEX_FIELD(s, T);
991
992         return trace_handle_return(s);
993 }
994
995 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
996                                        struct trace_event *event)
997 {
998         return trace_ctxwake_hex(iter, 0);
999 }
1000
1001 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
1002                                         struct trace_event *event)
1003 {
1004         return trace_ctxwake_hex(iter, '+');
1005 }
1006
1007 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
1008                                            int flags, struct trace_event *event)
1009 {
1010         struct ctx_switch_entry *field;
1011         struct trace_seq *s = &iter->seq;
1012
1013         trace_assign_type(field, iter->ent);
1014
1015         SEQ_PUT_FIELD(s, field->prev_pid);
1016         SEQ_PUT_FIELD(s, field->prev_prio);
1017         SEQ_PUT_FIELD(s, field->prev_state);
1018         SEQ_PUT_FIELD(s, field->next_cpu);
1019         SEQ_PUT_FIELD(s, field->next_pid);
1020         SEQ_PUT_FIELD(s, field->next_prio);
1021         SEQ_PUT_FIELD(s, field->next_state);
1022
1023         return trace_handle_return(s);
1024 }
1025
1026 static struct trace_event_functions trace_ctx_funcs = {
1027         .trace          = trace_ctx_print,
1028         .raw            = trace_ctx_raw,
1029         .hex            = trace_ctx_hex,
1030         .binary         = trace_ctxwake_bin,
1031 };
1032
1033 static struct trace_event trace_ctx_event = {
1034         .type           = TRACE_CTX,
1035         .funcs          = &trace_ctx_funcs,
1036 };
1037
1038 static struct trace_event_functions trace_wake_funcs = {
1039         .trace          = trace_wake_print,
1040         .raw            = trace_wake_raw,
1041         .hex            = trace_wake_hex,
1042         .binary         = trace_ctxwake_bin,
1043 };
1044
1045 static struct trace_event trace_wake_event = {
1046         .type           = TRACE_WAKE,
1047         .funcs          = &trace_wake_funcs,
1048 };
1049
1050 /* TRACE_STACK */
1051
1052 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1053                                            int flags, struct trace_event *event)
1054 {
1055         struct stack_entry *field;
1056         struct trace_seq *s = &iter->seq;
1057         unsigned long *p;
1058         unsigned long *end;
1059
1060         trace_assign_type(field, iter->ent);
1061         end = (unsigned long *)((long)iter->ent + iter->ent_size);
1062
1063         trace_seq_puts(s, "<stack trace>\n");
1064
1065         for (p = field->caller; p && p < end && *p != ULONG_MAX; p++) {
1066
1067                 if (trace_seq_has_overflowed(s))
1068                         break;
1069
1070                 trace_seq_puts(s, " => ");
1071                 seq_print_ip_sym(s, *p, flags);
1072                 trace_seq_putc(s, '\n');
1073         }
1074
1075         return trace_handle_return(s);
1076 }
1077
1078 static struct trace_event_functions trace_stack_funcs = {
1079         .trace          = trace_stack_print,
1080 };
1081
1082 static struct trace_event trace_stack_event = {
1083         .type           = TRACE_STACK,
1084         .funcs          = &trace_stack_funcs,
1085 };
1086
1087 /* TRACE_USER_STACK */
1088 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1089                                                 int flags, struct trace_event *event)
1090 {
1091         struct trace_array *tr = iter->tr;
1092         struct userstack_entry *field;
1093         struct trace_seq *s = &iter->seq;
1094         struct mm_struct *mm = NULL;
1095         unsigned int i;
1096
1097         trace_assign_type(field, iter->ent);
1098
1099         trace_seq_puts(s, "<user stack trace>\n");
1100
1101         if (tr->trace_flags & TRACE_ITER_SYM_USEROBJ) {
1102                 struct task_struct *task;
1103                 /*
1104                  * we do the lookup on the thread group leader,
1105                  * since individual threads might have already quit!
1106                  */
1107                 rcu_read_lock();
1108                 task = find_task_by_vpid(field->tgid);
1109                 if (task)
1110                         mm = get_task_mm(task);
1111                 rcu_read_unlock();
1112         }
1113
1114         for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1115                 unsigned long ip = field->caller[i];
1116
1117                 if (!ip || trace_seq_has_overflowed(s))
1118                         break;
1119
1120                 trace_seq_puts(s, " => ");
1121                 seq_print_user_ip(s, mm, ip, flags);
1122                 trace_seq_putc(s, '\n');
1123         }
1124
1125         if (mm)
1126                 mmput(mm);
1127
1128         return trace_handle_return(s);
1129 }
1130
1131 static struct trace_event_functions trace_user_stack_funcs = {
1132         .trace          = trace_user_stack_print,
1133 };
1134
1135 static struct trace_event trace_user_stack_event = {
1136         .type           = TRACE_USER_STACK,
1137         .funcs          = &trace_user_stack_funcs,
1138 };
1139
1140 /* TRACE_HWLAT */
1141 static enum print_line_t
1142 trace_hwlat_print(struct trace_iterator *iter, int flags,
1143                   struct trace_event *event)
1144 {
1145         struct trace_entry *entry = iter->ent;
1146         struct trace_seq *s = &iter->seq;
1147         struct hwlat_entry *field;
1148
1149         trace_assign_type(field, entry);
1150
1151         trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld count:%d",
1152                          field->seqnum,
1153                          field->duration,
1154                          field->outer_duration,
1155                          (long long)field->timestamp.tv_sec,
1156                          field->timestamp.tv_nsec, field->count);
1157
1158         if (field->nmi_count) {
1159                 /*
1160                  * The generic sched_clock() is not NMI safe, thus
1161                  * we only record the count and not the time.
1162                  */
1163                 if (!IS_ENABLED(CONFIG_GENERIC_SCHED_CLOCK))
1164                         trace_seq_printf(s, " nmi-total:%llu",
1165                                          field->nmi_total_ts);
1166                 trace_seq_printf(s, " nmi-count:%u",
1167                                  field->nmi_count);
1168         }
1169
1170         trace_seq_putc(s, '\n');
1171
1172         return trace_handle_return(s);
1173 }
1174
1175 static enum print_line_t
1176 trace_hwlat_raw(struct trace_iterator *iter, int flags,
1177                 struct trace_event *event)
1178 {
1179         struct hwlat_entry *field;
1180         struct trace_seq *s = &iter->seq;
1181
1182         trace_assign_type(field, iter->ent);
1183
1184         trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
1185                          field->duration,
1186                          field->outer_duration,
1187                          (long long)field->timestamp.tv_sec,
1188                          field->timestamp.tv_nsec,
1189                          field->seqnum);
1190
1191         return trace_handle_return(s);
1192 }
1193
1194 static struct trace_event_functions trace_hwlat_funcs = {
1195         .trace          = trace_hwlat_print,
1196         .raw            = trace_hwlat_raw,
1197 };
1198
1199 static struct trace_event trace_hwlat_event = {
1200         .type           = TRACE_HWLAT,
1201         .funcs          = &trace_hwlat_funcs,
1202 };
1203
1204 /* TRACE_OSNOISE */
1205 static enum print_line_t
1206 trace_osnoise_print(struct trace_iterator *iter, int flags,
1207                     struct trace_event *event)
1208 {
1209         struct trace_entry *entry = iter->ent;
1210         struct trace_seq *s = &iter->seq;
1211         struct osnoise_entry *field;
1212         u64 ratio, ratio_dec;
1213         u64 net_runtime;
1214
1215         trace_assign_type(field, entry);
1216
1217         /*
1218          * compute the available % of cpu time.
1219          */
1220         net_runtime = field->runtime - field->noise;
1221         ratio = net_runtime * 10000000;
1222         do_div(ratio, field->runtime);
1223         ratio_dec = do_div(ratio, 100000);
1224
1225         trace_seq_printf(s, "%llu %10llu %3llu.%05llu %7llu",
1226                          field->runtime,
1227                          field->noise,
1228                          ratio, ratio_dec,
1229                          field->max_sample);
1230
1231         trace_seq_printf(s, " %6u", field->hw_count);
1232         trace_seq_printf(s, " %6u", field->nmi_count);
1233         trace_seq_printf(s, " %6u", field->irq_count);
1234         trace_seq_printf(s, " %6u", field->softirq_count);
1235         trace_seq_printf(s, " %6u", field->thread_count);
1236
1237         trace_seq_putc(s, '\n');
1238
1239         return trace_handle_return(s);
1240 }
1241
1242 static enum print_line_t
1243 trace_osnoise_raw(struct trace_iterator *iter, int flags,
1244                   struct trace_event *event)
1245 {
1246         struct osnoise_entry *field;
1247         struct trace_seq *s = &iter->seq;
1248
1249         trace_assign_type(field, iter->ent);
1250
1251         trace_seq_printf(s, "%lld %llu %llu %u %u %u %u %u\n",
1252                          field->runtime,
1253                          field->noise,
1254                          field->max_sample,
1255                          field->hw_count,
1256                          field->nmi_count,
1257                          field->irq_count,
1258                          field->softirq_count,
1259                          field->thread_count);
1260
1261         return trace_handle_return(s);
1262 }
1263
1264 static struct trace_event_functions trace_osnoise_funcs = {
1265         .trace          = trace_osnoise_print,
1266         .raw            = trace_osnoise_raw,
1267 };
1268
1269 static struct trace_event trace_osnoise_event = {
1270         .type           = TRACE_OSNOISE,
1271         .funcs          = &trace_osnoise_funcs,
1272 };
1273
1274 /* TRACE_TIMERLAT */
1275 static enum print_line_t
1276 trace_timerlat_print(struct trace_iterator *iter, int flags,
1277                      struct trace_event *event)
1278 {
1279         struct trace_entry *entry = iter->ent;
1280         struct trace_seq *s = &iter->seq;
1281         struct timerlat_entry *field;
1282
1283         trace_assign_type(field, entry);
1284
1285         trace_seq_printf(s, "#%-5u context %6s timer_latency %9llu ns\n",
1286                          field->seqnum,
1287                          field->context ? "thread" : "irq",
1288                          field->timer_latency);
1289
1290         return trace_handle_return(s);
1291 }
1292
1293 static enum print_line_t
1294 trace_timerlat_raw(struct trace_iterator *iter, int flags,
1295                    struct trace_event *event)
1296 {
1297         struct timerlat_entry *field;
1298         struct trace_seq *s = &iter->seq;
1299
1300         trace_assign_type(field, iter->ent);
1301
1302         trace_seq_printf(s, "%u %d %llu\n",
1303                          field->seqnum,
1304                          field->context,
1305                          field->timer_latency);
1306
1307         return trace_handle_return(s);
1308 }
1309
1310 static struct trace_event_functions trace_timerlat_funcs = {
1311         .trace          = trace_timerlat_print,
1312         .raw            = trace_timerlat_raw,
1313 };
1314
1315 static struct trace_event trace_timerlat_event = {
1316         .type           = TRACE_TIMERLAT,
1317         .funcs          = &trace_timerlat_funcs,
1318 };
1319
1320 /* TRACE_BPUTS */
1321 static enum print_line_t
1322 trace_bputs_print(struct trace_iterator *iter, int flags,
1323                    struct trace_event *event)
1324 {
1325         struct trace_entry *entry = iter->ent;
1326         struct trace_seq *s = &iter->seq;
1327         struct bputs_entry *field;
1328
1329         trace_assign_type(field, entry);
1330
1331         seq_print_ip_sym(s, field->ip, flags);
1332         trace_seq_puts(s, ": ");
1333         trace_seq_puts(s, field->str);
1334
1335         return trace_handle_return(s);
1336 }
1337
1338
1339 static enum print_line_t
1340 trace_bputs_raw(struct trace_iterator *iter, int flags,
1341                 struct trace_event *event)
1342 {
1343         struct bputs_entry *field;
1344         struct trace_seq *s = &iter->seq;
1345
1346         trace_assign_type(field, iter->ent);
1347
1348         trace_seq_printf(s, ": %lx : ", field->ip);
1349         trace_seq_puts(s, field->str);
1350
1351         return trace_handle_return(s);
1352 }
1353
1354 static struct trace_event_functions trace_bputs_funcs = {
1355         .trace          = trace_bputs_print,
1356         .raw            = trace_bputs_raw,
1357 };
1358
1359 static struct trace_event trace_bputs_event = {
1360         .type           = TRACE_BPUTS,
1361         .funcs          = &trace_bputs_funcs,
1362 };
1363
1364 /* TRACE_BPRINT */
1365 static enum print_line_t
1366 trace_bprint_print(struct trace_iterator *iter, int flags,
1367                    struct trace_event *event)
1368 {
1369         struct trace_entry *entry = iter->ent;
1370         struct trace_seq *s = &iter->seq;
1371         struct bprint_entry *field;
1372
1373         trace_assign_type(field, entry);
1374
1375         seq_print_ip_sym(s, field->ip, flags);
1376         trace_seq_puts(s, ": ");
1377         trace_seq_bprintf(s, field->fmt, field->buf);
1378
1379         return trace_handle_return(s);
1380 }
1381
1382
1383 static enum print_line_t
1384 trace_bprint_raw(struct trace_iterator *iter, int flags,
1385                  struct trace_event *event)
1386 {
1387         struct bprint_entry *field;
1388         struct trace_seq *s = &iter->seq;
1389
1390         trace_assign_type(field, iter->ent);
1391
1392         trace_seq_printf(s, ": %lx : ", field->ip);
1393         trace_seq_bprintf(s, field->fmt, field->buf);
1394
1395         return trace_handle_return(s);
1396 }
1397
1398 static struct trace_event_functions trace_bprint_funcs = {
1399         .trace          = trace_bprint_print,
1400         .raw            = trace_bprint_raw,
1401 };
1402
1403 static struct trace_event trace_bprint_event = {
1404         .type           = TRACE_BPRINT,
1405         .funcs          = &trace_bprint_funcs,
1406 };
1407
1408 /* TRACE_PRINT */
1409 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1410                                            int flags, struct trace_event *event)
1411 {
1412         struct print_entry *field;
1413         struct trace_seq *s = &iter->seq;
1414
1415         trace_assign_type(field, iter->ent);
1416
1417         seq_print_ip_sym(s, field->ip, flags);
1418         trace_seq_printf(s, ": %s", field->buf);
1419
1420         return trace_handle_return(s);
1421 }
1422
1423 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1424                                          struct trace_event *event)
1425 {
1426         struct print_entry *field;
1427
1428         trace_assign_type(field, iter->ent);
1429
1430         trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
1431
1432         return trace_handle_return(&iter->seq);
1433 }
1434
1435 static struct trace_event_functions trace_print_funcs = {
1436         .trace          = trace_print_print,
1437         .raw            = trace_print_raw,
1438 };
1439
1440 static struct trace_event trace_print_event = {
1441         .type           = TRACE_PRINT,
1442         .funcs          = &trace_print_funcs,
1443 };
1444
1445 static enum print_line_t trace_raw_data(struct trace_iterator *iter, int flags,
1446                                          struct trace_event *event)
1447 {
1448         struct raw_data_entry *field;
1449         int i;
1450
1451         trace_assign_type(field, iter->ent);
1452
1453         trace_seq_printf(&iter->seq, "# %x buf:", field->id);
1454
1455         for (i = 0; i < iter->ent_size - offsetof(struct raw_data_entry, buf); i++)
1456                 trace_seq_printf(&iter->seq, " %02x",
1457                                  (unsigned char)field->buf[i]);
1458
1459         trace_seq_putc(&iter->seq, '\n');
1460
1461         return trace_handle_return(&iter->seq);
1462 }
1463
1464 static struct trace_event_functions trace_raw_data_funcs = {
1465         .trace          = trace_raw_data,
1466         .raw            = trace_raw_data,
1467 };
1468
1469 static struct trace_event trace_raw_data_event = {
1470         .type           = TRACE_RAW_DATA,
1471         .funcs          = &trace_raw_data_funcs,
1472 };
1473
1474 static enum print_line_t
1475 trace_func_repeats_raw(struct trace_iterator *iter, int flags,
1476                          struct trace_event *event)
1477 {
1478         struct func_repeats_entry *field;
1479         struct trace_seq *s = &iter->seq;
1480
1481         trace_assign_type(field, iter->ent);
1482
1483         trace_seq_printf(s, "%lu %lu %u %llu\n",
1484                          field->ip,
1485                          field->parent_ip,
1486                          field->count,
1487                          FUNC_REPEATS_GET_DELTA_TS(field));
1488
1489         return trace_handle_return(s);
1490 }
1491
1492 static enum print_line_t
1493 trace_func_repeats_print(struct trace_iterator *iter, int flags,
1494                          struct trace_event *event)
1495 {
1496         struct func_repeats_entry *field;
1497         struct trace_seq *s = &iter->seq;
1498
1499         trace_assign_type(field, iter->ent);
1500
1501         print_fn_trace(s, field->ip, field->parent_ip, flags);
1502         trace_seq_printf(s, " (repeats: %u, last_ts:", field->count);
1503         trace_print_time(s, iter,
1504                          iter->ts - FUNC_REPEATS_GET_DELTA_TS(field));
1505         trace_seq_puts(s, ")\n");
1506
1507         return trace_handle_return(s);
1508 }
1509
1510 static struct trace_event_functions trace_func_repeats_funcs = {
1511         .trace          = trace_func_repeats_print,
1512         .raw            = trace_func_repeats_raw,
1513 };
1514
1515 static struct trace_event trace_func_repeats_event = {
1516         .type           = TRACE_FUNC_REPEATS,
1517         .funcs          = &trace_func_repeats_funcs,
1518 };
1519
1520 static struct trace_event *events[] __initdata = {
1521         &trace_fn_event,
1522         &trace_ctx_event,
1523         &trace_wake_event,
1524         &trace_stack_event,
1525         &trace_user_stack_event,
1526         &trace_bputs_event,
1527         &trace_bprint_event,
1528         &trace_print_event,
1529         &trace_hwlat_event,
1530         &trace_osnoise_event,
1531         &trace_timerlat_event,
1532         &trace_raw_data_event,
1533         &trace_func_repeats_event,
1534         NULL
1535 };
1536
1537 __init static int init_events(void)
1538 {
1539         struct trace_event *event;
1540         int i, ret;
1541
1542         for (i = 0; events[i]; i++) {
1543                 event = events[i];
1544                 ret = register_trace_event(event);
1545                 WARN_ONCE(!ret, "event %d failed to register", event->type);
1546         }
1547
1548         return 0;
1549 }
1550 early_initcall(init_events);