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