]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - kernel/trace/trace_output.c
Merge tag 'docs-4.12' of git://git.lwn.net/linux
[mirror_ubuntu-artful-kernel.git] / kernel / trace / trace_output.c
CommitLineData
f0868d1e
SR
1/*
2 * trace_output.c
3 *
4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
5 *
6 */
7
8#include <linux/module.h>
9#include <linux/mutex.h>
10#include <linux/ftrace.h>
e6017571 11#include <linux/sched/clock.h>
6e84f315 12#include <linux/sched/mm.h>
f0868d1e
SR
13
14#include "trace_output.h"
15
16/* must be a power of 2 */
17#define EVENT_HASHSIZE 128
18
52f6ad6d 19DECLARE_RWSEM(trace_event_sem);
be74b73a 20
f0868d1e
SR
21static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
22
23static int next_event_type = __TRACE_LAST_TYPE + 1;
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);
5a2e3995
KT
222
223 for (i = 0; i < buf_len; i++)
3898fac1 224 trace_seq_printf(p, "%s%2.2x", concatenate || i == 0 ? "" : " ",
2acae0d5 225 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
892c505a
SRRH
277int trace_raw_output_prep(struct trace_iterator *iter,
278 struct trace_event *trace_event)
f71130de 279{
2425bcb9 280 struct trace_event_call *event;
f71130de
LZ
281 struct trace_seq *s = &iter->seq;
282 struct trace_seq *p = &iter->tmp_seq;
283 struct trace_entry *entry;
f71130de 284
2425bcb9 285 event = container_of(trace_event, struct trace_event_call, event);
f71130de
LZ
286 entry = iter->ent;
287
288 if (entry->type != event->event.type) {
289 WARN_ON_ONCE(1);
290 return TRACE_TYPE_UNHANDLED;
291 }
292
293 trace_seq_init(p);
687fcc4a 294 trace_seq_printf(s, "%s: ", trace_event_name(event));
19a7fe20 295
8e2e095c 296 return trace_handle_return(s);
f71130de 297}
892c505a 298EXPORT_SYMBOL(trace_raw_output_prep);
f71130de 299
892c505a
SRRH
300static int trace_output_raw(struct trace_iterator *iter, char *name,
301 char *fmt, va_list ap)
1d6bae96
SR
302{
303 struct trace_seq *s = &iter->seq;
1d6bae96 304
19a7fe20
SRRH
305 trace_seq_printf(s, "%s: ", name);
306 trace_seq_vprintf(s, fmt, ap);
1d6bae96 307
19a7fe20 308 return trace_handle_return(s);
1d6bae96
SR
309}
310
892c505a 311int trace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
1d6bae96
SR
312{
313 va_list ap;
314 int ret;
315
316 va_start(ap, fmt);
892c505a 317 ret = trace_output_raw(iter, name, fmt, ap);
1d6bae96
SR
318 va_end(ap);
319
320 return ret;
321}
892c505a 322EXPORT_SYMBOL_GPL(trace_output_call);
1d6bae96 323
f0868d1e
SR
324#ifdef CONFIG_KRETPROBES
325static inline const char *kretprobed(const char *name)
326{
327 static const char tramp_name[] = "kretprobe_trampoline";
328 int size = sizeof(tramp_name);
329
330 if (strncmp(tramp_name, name, size) == 0)
331 return "[unknown/kretprobe'd]";
332 return name;
333}
334#else
335static inline const char *kretprobed(const char *name)
336{
337 return name;
338}
339#endif /* CONFIG_KRETPROBES */
340
19a7fe20 341static void
f0868d1e
SR
342seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
343{
344#ifdef CONFIG_KALLSYMS
345 char str[KSYM_SYMBOL_LEN];
346 const char *name;
347
348 kallsyms_lookup(address, NULL, NULL, NULL, str);
349
350 name = kretprobed(str);
351
19a7fe20 352 trace_seq_printf(s, fmt, name);
f0868d1e 353#endif
f0868d1e
SR
354}
355
19a7fe20 356static void
f0868d1e
SR
357seq_print_sym_offset(struct trace_seq *s, const char *fmt,
358 unsigned long address)
359{
360#ifdef CONFIG_KALLSYMS
361 char str[KSYM_SYMBOL_LEN];
362 const char *name;
363
364 sprint_symbol(str, address);
365 name = kretprobed(str);
366
19a7fe20 367 trace_seq_printf(s, fmt, name);
f0868d1e 368#endif
f0868d1e
SR
369}
370
371#ifndef CONFIG_64BIT
372# define IP_FMT "%08lx"
373#else
374# define IP_FMT "%016lx"
375#endif
376
ef92480a
SRRH
377static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
378 unsigned long ip, unsigned long sym_flags)
f0868d1e
SR
379{
380 struct file *file = NULL;
381 unsigned long vmstart = 0;
382 int ret = 1;
383
d184b31c
JB
384 if (s->full)
385 return 0;
386
f0868d1e
SR
387 if (mm) {
388 const struct vm_area_struct *vma;
389
390 down_read(&mm->mmap_sem);
391 vma = find_vma(mm, ip);
392 if (vma) {
393 file = vma->vm_file;
394 vmstart = vma->vm_start;
395 }
396 if (file) {
397 ret = trace_seq_path(s, &file->f_path);
398 if (ret)
19a7fe20
SRRH
399 trace_seq_printf(s, "[+0x%lx]",
400 ip - vmstart);
f0868d1e
SR
401 }
402 up_read(&mm->mmap_sem);
403 }
404 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
19a7fe20
SRRH
405 trace_seq_printf(s, " <" IP_FMT ">", ip);
406 return !trace_seq_has_overflowed(s);
f0868d1e
SR
407}
408
f0868d1e
SR
409int
410seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
411{
19a7fe20
SRRH
412 if (!ip) {
413 trace_seq_putc(s, '0');
414 goto out;
415 }
f0868d1e
SR
416
417 if (sym_flags & TRACE_ITER_SYM_OFFSET)
19a7fe20 418 seq_print_sym_offset(s, "%s", ip);
f0868d1e 419 else
19a7fe20 420 seq_print_sym_short(s, "%s", ip);
f0868d1e
SR
421
422 if (sym_flags & TRACE_ITER_SYM_ADDR)
19a7fe20
SRRH
423 trace_seq_printf(s, " <" IP_FMT ">", ip);
424
425 out:
426 return !trace_seq_has_overflowed(s);
f0868d1e
SR
427}
428
f81c972d
SR
429/**
430 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
431 * @s: trace seq struct to write to
432 * @entry: The trace entry field from the ring buffer
433 *
434 * Prints the generic fields of irqs off, in hard or softirq, preempt
e6e1e259 435 * count.
f81c972d
SR
436 */
437int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
c4a8e8be 438{
10da37a6
DS
439 char hardsoft_irq;
440 char need_resched;
441 char irqs_off;
442 int hardirq;
443 int softirq;
7e6867bf 444 int nmi;
c4a8e8be 445
7e6867bf 446 nmi = entry->flags & TRACE_FLAG_NMI;
c4a8e8be
FW
447 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
448 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
d9793bd8 449
10da37a6
DS
450 irqs_off =
451 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
452 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
453 '.';
e5137b50
PZ
454
455 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
456 TRACE_FLAG_PREEMPT_RESCHED)) {
457 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
458 need_resched = 'N';
459 break;
460 case TRACE_FLAG_NEED_RESCHED:
461 need_resched = 'n';
462 break;
463 case TRACE_FLAG_PREEMPT_RESCHED:
464 need_resched = 'p';
465 break;
466 default:
467 need_resched = '.';
468 break;
469 }
470
10da37a6 471 hardsoft_irq =
7e6867bf
PZ
472 (nmi && hardirq) ? 'Z' :
473 nmi ? 'z' :
10da37a6 474 (hardirq && softirq) ? 'H' :
7e6867bf
PZ
475 hardirq ? 'h' :
476 softirq ? 's' :
477 '.' ;
10da37a6 478
19a7fe20
SRRH
479 trace_seq_printf(s, "%c%c%c",
480 irqs_off, need_resched, hardsoft_irq);
c4a8e8be 481
829b876d 482 if (entry->preempt_count)
19a7fe20 483 trace_seq_printf(s, "%x", entry->preempt_count);
637e7e86 484 else
19a7fe20 485 trace_seq_putc(s, '.');
829b876d 486
19a7fe20 487 return !trace_seq_has_overflowed(s);
c4a8e8be
FW
488}
489
f81c972d
SR
490static int
491lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
492{
493 char comm[TASK_COMM_LEN];
494
495 trace_find_cmdline(entry->pid, comm);
496
19a7fe20
SRRH
497 trace_seq_printf(s, "%8.8s-%-5d %3d",
498 comm, entry->pid, cpu);
f81c972d
SR
499
500 return trace_print_lat_fmt(s, entry);
501}
502
8e1e1df2
BP
503#undef MARK
504#define MARK(v, s) {.val = v, .sym = s}
505/* trace overhead mark */
506static const struct trace_mark {
507 unsigned long long val; /* unit: nsec */
508 char sym;
509} mark[] = {
510 MARK(1000000000ULL , '$'), /* 1 sec */
b838e1d9
JL
511 MARK(100000000ULL , '@'), /* 100 msec */
512 MARK(10000000ULL , '*'), /* 10 msec */
8e1e1df2
BP
513 MARK(1000000ULL , '#'), /* 1000 usecs */
514 MARK(100000ULL , '!'), /* 100 usecs */
515 MARK(10000ULL , '+'), /* 10 usecs */
516};
517#undef MARK
518
519char trace_find_mark(unsigned long long d)
520{
521 int i;
522 int size = ARRAY_SIZE(mark);
523
524 for (i = 0; i < size; i++) {
b838e1d9 525 if (d > mark[i].val)
8e1e1df2
BP
526 break;
527 }
528
529 return (i == size) ? ' ' : mark[i].sym;
530}
c4a8e8be 531
d9793bd8 532static int
8be0709f 533lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
c4a8e8be 534{
983f938a
SRRH
535 struct trace_array *tr = iter->tr;
536 unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE;
8be0709f 537 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
12883efb 538 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
8be0709f
DS
539 unsigned long long rel_ts = next_ts - iter->ts;
540 struct trace_seq *s = &iter->seq;
541
542 if (in_ns) {
543 abs_ts = ns2usecs(abs_ts);
544 rel_ts = ns2usecs(rel_ts);
545 }
546
547 if (verbose && in_ns) {
548 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
549 unsigned long abs_msec = (unsigned long)abs_ts;
550 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
551 unsigned long rel_msec = (unsigned long)rel_ts;
552
19a7fe20
SRRH
553 trace_seq_printf(
554 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
555 ns2usecs(iter->ts),
556 abs_msec, abs_usec,
557 rel_msec, rel_usec);
558
8be0709f 559 } else if (verbose && !in_ns) {
19a7fe20
SRRH
560 trace_seq_printf(
561 s, "[%016llx] %lld (+%lld): ",
562 iter->ts, abs_ts, rel_ts);
563
8be0709f 564 } else if (!verbose && in_ns) {
19a7fe20
SRRH
565 trace_seq_printf(
566 s, " %4lldus%c: ",
567 abs_ts,
8e1e1df2 568 trace_find_mark(rel_ts * NSEC_PER_USEC));
19a7fe20 569
8be0709f 570 } else { /* !verbose && !in_ns */
19a7fe20 571 trace_seq_printf(s, " %4lld: ", abs_ts);
8be0709f 572 }
19a7fe20
SRRH
573
574 return !trace_seq_has_overflowed(s);
c4a8e8be
FW
575}
576
577int trace_print_context(struct trace_iterator *iter)
578{
983f938a 579 struct trace_array *tr = iter->tr;
c4a8e8be
FW
580 struct trace_seq *s = &iter->seq;
581 struct trace_entry *entry = iter->ent;
8be0709f
DS
582 unsigned long long t;
583 unsigned long secs, usec_rem;
4ca53085
SR
584 char comm[TASK_COMM_LEN];
585
586 trace_find_cmdline(entry->pid, comm);
c4a8e8be 587
19a7fe20 588 trace_seq_printf(s, "%16s-%-5d [%03d] ",
77271ce4 589 comm, entry->pid, iter->cpu);
77271ce4 590
983f938a 591 if (tr->trace_flags & TRACE_ITER_IRQ_INFO)
19a7fe20 592 trace_print_lat_fmt(s, entry);
77271ce4 593
8be0709f
DS
594 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
595 t = ns2usecs(iter->ts);
596 usec_rem = do_div(t, USEC_PER_SEC);
597 secs = (unsigned long)t;
19a7fe20 598 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
8be0709f 599 } else
19a7fe20
SRRH
600 trace_seq_printf(s, " %12llu: ", iter->ts);
601
602 return !trace_seq_has_overflowed(s);
c4a8e8be
FW
603}
604
605int trace_print_lat_context(struct trace_iterator *iter)
606{
983f938a 607 struct trace_array *tr = iter->tr;
db4c75cb
SR
608 /* trace_find_next_entry will reset ent_size */
609 int ent_size = iter->ent_size;
c4a8e8be 610 struct trace_seq *s = &iter->seq;
983f938a 611 u64 next_ts;
c4a8e8be
FW
612 struct trace_entry *entry = iter->ent,
613 *next_entry = trace_find_next_entry(iter, NULL,
614 &next_ts);
983f938a 615 unsigned long verbose = (tr->trace_flags & TRACE_ITER_VERBOSE);
c4a8e8be 616
db4c75cb
SR
617 /* Restore the original ent_size */
618 iter->ent_size = ent_size;
619
c4a8e8be
FW
620 if (!next_entry)
621 next_ts = iter->ts;
c4a8e8be
FW
622
623 if (verbose) {
4ca53085
SR
624 char comm[TASK_COMM_LEN];
625
626 trace_find_cmdline(entry->pid, comm);
627
19a7fe20
SRRH
628 trace_seq_printf(
629 s, "%16s %5d %3d %d %08x %08lx ",
630 comm, entry->pid, iter->cpu, entry->flags,
631 entry->preempt_count, iter->idx);
c4a8e8be 632 } else {
19a7fe20 633 lat_print_generic(s, entry, iter->cpu);
c4a8e8be
FW
634 }
635
19a7fe20 636 lat_print_timestamp(iter, next_ts);
8be0709f 637
19a7fe20 638 return !trace_seq_has_overflowed(s);
c4a8e8be
FW
639}
640
f633cef0
SR
641static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
642
643static int task_state_char(unsigned long state)
644{
645 int bit = state ? __ffs(state) + 1 : 0;
646
647 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
648}
649
f0868d1e
SR
650/**
651 * ftrace_find_event - find a registered event
652 * @type: the type of event to look for
653 *
654 * Returns an event of type @type otherwise NULL
4f535968 655 * Called with trace_event_read_lock() held.
f0868d1e
SR
656 */
657struct trace_event *ftrace_find_event(int type)
658{
659 struct trace_event *event;
f0868d1e
SR
660 unsigned key;
661
662 key = type & (EVENT_HASHSIZE - 1);
663
b67bfe0d 664 hlist_for_each_entry(event, &event_hash[key], node) {
f0868d1e
SR
665 if (event->type == type)
666 return event;
667 }
668
669 return NULL;
670}
671
060fa5c8
SR
672static LIST_HEAD(ftrace_event_list);
673
674static int trace_search_list(struct list_head **list)
675{
676 struct trace_event *e;
677 int last = __TRACE_LAST_TYPE;
678
679 if (list_empty(&ftrace_event_list)) {
680 *list = &ftrace_event_list;
681 return last + 1;
682 }
683
684 /*
685 * We used up all possible max events,
686 * lets see if somebody freed one.
687 */
688 list_for_each_entry(e, &ftrace_event_list, list) {
689 if (e->type != last + 1)
690 break;
691 last++;
692 }
693
694 /* Did we used up all 65 thousand events??? */
609a7404 695 if ((last + 1) > TRACE_EVENT_TYPE_MAX)
060fa5c8
SR
696 return 0;
697
698 *list = &e->list;
699 return last + 1;
700}
701
4f535968
LJ
702void trace_event_read_lock(void)
703{
52f6ad6d 704 down_read(&trace_event_sem);
4f535968
LJ
705}
706
707void trace_event_read_unlock(void)
708{
52f6ad6d 709 up_read(&trace_event_sem);
4f535968
LJ
710}
711
f0868d1e 712/**
9023c930 713 * register_trace_event - register output for an event type
f0868d1e
SR
714 * @event: the event type to register
715 *
716 * Event types are stored in a hash and this hash is used to
717 * find a way to print an event. If the @event->type is set
718 * then it will use that type, otherwise it will assign a
719 * type to use.
720 *
721 * If you assign your own type, please make sure it is added
722 * to the trace_type enum in trace.h, to avoid collisions
723 * with the dynamic types.
724 *
725 * Returns the event type number or zero on error.
726 */
9023c930 727int register_trace_event(struct trace_event *event)
f0868d1e
SR
728{
729 unsigned key;
730 int ret = 0;
731
52f6ad6d 732 down_write(&trace_event_sem);
f0868d1e 733
060fa5c8 734 if (WARN_ON(!event))
28bea271 735 goto out;
28bea271 736
a9a57763
SR
737 if (WARN_ON(!event->funcs))
738 goto out;
739
060fa5c8
SR
740 INIT_LIST_HEAD(&event->list);
741
742 if (!event->type) {
48dd0fed 743 struct list_head *list = NULL;
060fa5c8 744
609a7404 745 if (next_event_type > TRACE_EVENT_TYPE_MAX) {
060fa5c8
SR
746
747 event->type = trace_search_list(&list);
748 if (!event->type)
749 goto out;
750
751 } else {
8e1e1df2 752
060fa5c8
SR
753 event->type = next_event_type++;
754 list = &ftrace_event_list;
755 }
756
757 if (WARN_ON(ftrace_find_event(event->type)))
758 goto out;
759
760 list_add_tail(&event->list, list);
761
762 } else if (event->type > __TRACE_LAST_TYPE) {
f0868d1e
SR
763 printk(KERN_WARNING "Need to add type to trace.h\n");
764 WARN_ON(1);
f0868d1e 765 goto out;
060fa5c8
SR
766 } else {
767 /* Is this event already used */
768 if (ftrace_find_event(event->type))
769 goto out;
770 }
f0868d1e 771
a9a57763
SR
772 if (event->funcs->trace == NULL)
773 event->funcs->trace = trace_nop_print;
774 if (event->funcs->raw == NULL)
775 event->funcs->raw = trace_nop_print;
776 if (event->funcs->hex == NULL)
777 event->funcs->hex = trace_nop_print;
778 if (event->funcs->binary == NULL)
779 event->funcs->binary = trace_nop_print;
268ccda0 780
f0868d1e
SR
781 key = event->type & (EVENT_HASHSIZE - 1);
782
4f535968 783 hlist_add_head(&event->node, &event_hash[key]);
f0868d1e
SR
784
785 ret = event->type;
786 out:
52f6ad6d 787 up_write(&trace_event_sem);
f0868d1e
SR
788
789 return ret;
790}
9023c930 791EXPORT_SYMBOL_GPL(register_trace_event);
f0868d1e 792
110bf2b7 793/*
52f6ad6d 794 * Used by module code with the trace_event_sem held for write.
110bf2b7 795 */
9023c930 796int __unregister_trace_event(struct trace_event *event)
110bf2b7
SR
797{
798 hlist_del(&event->node);
799 list_del(&event->list);
800 return 0;
801}
802
f0868d1e 803/**
9023c930 804 * unregister_trace_event - remove a no longer used event
f0868d1e
SR
805 * @event: the event to remove
806 */
9023c930 807int unregister_trace_event(struct trace_event *event)
f0868d1e 808{
52f6ad6d 809 down_write(&trace_event_sem);
9023c930 810 __unregister_trace_event(event);
52f6ad6d 811 up_write(&trace_event_sem);
f0868d1e
SR
812
813 return 0;
814}
9023c930 815EXPORT_SYMBOL_GPL(unregister_trace_event);
f633cef0
SR
816
817/*
818 * Standard events
819 */
820
a9a57763
SR
821enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
822 struct trace_event *event)
f633cef0 823{
19a7fe20 824 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
ee5e51f5 825
19a7fe20 826 return trace_handle_return(&iter->seq);
f633cef0
SR
827}
828
829/* TRACE_FN */
a9a57763
SR
830static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
831 struct trace_event *event)
f633cef0
SR
832{
833 struct ftrace_entry *field;
2c9b238e 834 struct trace_seq *s = &iter->seq;
f633cef0 835
2c9b238e 836 trace_assign_type(field, iter->ent);
f633cef0 837
19a7fe20 838 seq_print_ip_sym(s, field->ip, flags);
f633cef0
SR
839
840 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
19a7fe20
SRRH
841 trace_seq_puts(s, " <-");
842 seq_print_ip_sym(s, field->parent_ip, flags);
f633cef0 843 }
f633cef0 844
19a7fe20 845 trace_seq_putc(s, '\n');
f633cef0 846
19a7fe20 847 return trace_handle_return(s);
f633cef0
SR
848}
849
a9a57763
SR
850static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
851 struct trace_event *event)
f633cef0
SR
852{
853 struct ftrace_entry *field;
854
2c9b238e 855 trace_assign_type(field, iter->ent);
f633cef0 856
19a7fe20
SRRH
857 trace_seq_printf(&iter->seq, "%lx %lx\n",
858 field->ip,
859 field->parent_ip);
f633cef0 860
19a7fe20 861 return trace_handle_return(&iter->seq);
f633cef0
SR
862}
863
a9a57763
SR
864static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
865 struct trace_event *event)
f633cef0
SR
866{
867 struct ftrace_entry *field;
2c9b238e 868 struct trace_seq *s = &iter->seq;
f633cef0 869
2c9b238e 870 trace_assign_type(field, iter->ent);
f633cef0 871
19a7fe20
SRRH
872 SEQ_PUT_HEX_FIELD(s, field->ip);
873 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
f633cef0 874
19a7fe20 875 return trace_handle_return(s);
f633cef0
SR
876}
877
a9a57763
SR
878static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
879 struct trace_event *event)
f633cef0
SR
880{
881 struct ftrace_entry *field;
2c9b238e 882 struct trace_seq *s = &iter->seq;
f633cef0 883
2c9b238e 884 trace_assign_type(field, iter->ent);
f633cef0 885
19a7fe20
SRRH
886 SEQ_PUT_FIELD(s, field->ip);
887 SEQ_PUT_FIELD(s, field->parent_ip);
f633cef0 888
19a7fe20 889 return trace_handle_return(s);
f633cef0
SR
890}
891
a9a57763 892static struct trace_event_functions trace_fn_funcs = {
f633cef0 893 .trace = trace_fn_trace,
f633cef0
SR
894 .raw = trace_fn_raw,
895 .hex = trace_fn_hex,
896 .binary = trace_fn_bin,
897};
898
a9a57763
SR
899static struct trace_event trace_fn_event = {
900 .type = TRACE_FN,
901 .funcs = &trace_fn_funcs,
902};
903
f633cef0 904/* TRACE_CTX an TRACE_WAKE */
ae7462b4
ACM
905static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
906 char *delim)
f633cef0
SR
907{
908 struct ctx_switch_entry *field;
4ca53085 909 char comm[TASK_COMM_LEN];
f633cef0
SR
910 int S, T;
911
4ca53085 912
2c9b238e 913 trace_assign_type(field, iter->ent);
f633cef0
SR
914
915 T = task_state_char(field->next_state);
916 S = task_state_char(field->prev_state);
4ca53085 917 trace_find_cmdline(field->next_pid, comm);
19a7fe20
SRRH
918 trace_seq_printf(&iter->seq,
919 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
920 field->prev_pid,
921 field->prev_prio,
922 S, delim,
923 field->next_cpu,
924 field->next_pid,
925 field->next_prio,
926 T, comm);
927
928 return trace_handle_return(&iter->seq);
f633cef0
SR
929}
930
a9a57763
SR
931static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
932 struct trace_event *event)
f633cef0 933{
2c9b238e 934 return trace_ctxwake_print(iter, "==>");
f633cef0
SR
935}
936
ae7462b4 937static enum print_line_t trace_wake_print(struct trace_iterator *iter,
a9a57763 938 int flags, struct trace_event *event)
f633cef0 939{
2c9b238e 940 return trace_ctxwake_print(iter, " +");
f633cef0
SR
941}
942
2c9b238e 943static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
f633cef0
SR
944{
945 struct ctx_switch_entry *field;
946 int T;
947
2c9b238e 948 trace_assign_type(field, iter->ent);
f633cef0
SR
949
950 if (!S)
b0f56f1a 951 S = task_state_char(field->prev_state);
f633cef0 952 T = task_state_char(field->next_state);
19a7fe20
SRRH
953 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
954 field->prev_pid,
955 field->prev_prio,
956 S,
957 field->next_cpu,
958 field->next_pid,
959 field->next_prio,
960 T);
961
962 return trace_handle_return(&iter->seq);
f633cef0
SR
963}
964
a9a57763
SR
965static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
966 struct trace_event *event)
f633cef0 967{
2c9b238e 968 return trace_ctxwake_raw(iter, 0);
f633cef0
SR
969}
970
a9a57763
SR
971static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
972 struct trace_event *event)
f633cef0 973{
2c9b238e 974 return trace_ctxwake_raw(iter, '+');
f633cef0
SR
975}
976
977
2c9b238e 978static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
f633cef0
SR
979{
980 struct ctx_switch_entry *field;
2c9b238e 981 struct trace_seq *s = &iter->seq;
f633cef0
SR
982 int T;
983
2c9b238e 984 trace_assign_type(field, iter->ent);
f633cef0
SR
985
986 if (!S)
b0f56f1a 987 S = task_state_char(field->prev_state);
f633cef0
SR
988 T = task_state_char(field->next_state);
989
19a7fe20
SRRH
990 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
991 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
992 SEQ_PUT_HEX_FIELD(s, S);
993 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
994 SEQ_PUT_HEX_FIELD(s, field->next_pid);
995 SEQ_PUT_HEX_FIELD(s, field->next_prio);
996 SEQ_PUT_HEX_FIELD(s, T);
f633cef0 997
19a7fe20 998 return trace_handle_return(s);
f633cef0
SR
999}
1000
a9a57763
SR
1001static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
1002 struct trace_event *event)
f633cef0 1003{
2c9b238e 1004 return trace_ctxwake_hex(iter, 0);
f633cef0
SR
1005}
1006
a9a57763
SR
1007static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
1008 struct trace_event *event)
f633cef0 1009{
2c9b238e 1010 return trace_ctxwake_hex(iter, '+');
f633cef0
SR
1011}
1012
ae7462b4 1013static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
a9a57763 1014 int flags, struct trace_event *event)
f633cef0
SR
1015{
1016 struct ctx_switch_entry *field;
2c9b238e 1017 struct trace_seq *s = &iter->seq;
f633cef0 1018
2c9b238e 1019 trace_assign_type(field, iter->ent);
f633cef0 1020
19a7fe20
SRRH
1021 SEQ_PUT_FIELD(s, field->prev_pid);
1022 SEQ_PUT_FIELD(s, field->prev_prio);
1023 SEQ_PUT_FIELD(s, field->prev_state);
1024 SEQ_PUT_FIELD(s, field->next_cpu);
1025 SEQ_PUT_FIELD(s, field->next_pid);
1026 SEQ_PUT_FIELD(s, field->next_prio);
1027 SEQ_PUT_FIELD(s, field->next_state);
f633cef0 1028
19a7fe20 1029 return trace_handle_return(s);
f633cef0
SR
1030}
1031
a9a57763 1032static struct trace_event_functions trace_ctx_funcs = {
f633cef0 1033 .trace = trace_ctx_print,
f633cef0
SR
1034 .raw = trace_ctx_raw,
1035 .hex = trace_ctx_hex,
1036 .binary = trace_ctxwake_bin,
1037};
1038
a9a57763
SR
1039static struct trace_event trace_ctx_event = {
1040 .type = TRACE_CTX,
1041 .funcs = &trace_ctx_funcs,
1042};
1043
1044static struct trace_event_functions trace_wake_funcs = {
f633cef0 1045 .trace = trace_wake_print,
f633cef0
SR
1046 .raw = trace_wake_raw,
1047 .hex = trace_wake_hex,
1048 .binary = trace_ctxwake_bin,
1049};
1050
a9a57763
SR
1051static struct trace_event trace_wake_event = {
1052 .type = TRACE_WAKE,
1053 .funcs = &trace_wake_funcs,
1054};
1055
f633cef0
SR
1056/* TRACE_STACK */
1057
ae7462b4 1058static enum print_line_t trace_stack_print(struct trace_iterator *iter,
a9a57763 1059 int flags, struct trace_event *event)
f633cef0
SR
1060{
1061 struct stack_entry *field;
2c9b238e 1062 struct trace_seq *s = &iter->seq;
4a9bd3f1
SR
1063 unsigned long *p;
1064 unsigned long *end;
f633cef0 1065
2c9b238e 1066 trace_assign_type(field, iter->ent);
4a9bd3f1 1067 end = (unsigned long *)((long)iter->ent + iter->ent_size);
f633cef0 1068
19a7fe20 1069 trace_seq_puts(s, "<stack trace>\n");
4a9bd3f1
SR
1070
1071 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
f633cef0 1072
19a7fe20
SRRH
1073 if (trace_seq_has_overflowed(s))
1074 break;
f633cef0 1075
19a7fe20
SRRH
1076 trace_seq_puts(s, " => ");
1077 seq_print_ip_sym(s, *p, flags);
1078 trace_seq_putc(s, '\n');
1079 }
f633cef0 1080
19a7fe20 1081 return trace_handle_return(s);
f633cef0
SR
1082}
1083
a9a57763 1084static struct trace_event_functions trace_stack_funcs = {
f633cef0 1085 .trace = trace_stack_print,
f633cef0
SR
1086};
1087
a9a57763
SR
1088static struct trace_event trace_stack_event = {
1089 .type = TRACE_STACK,
1090 .funcs = &trace_stack_funcs,
1091};
1092
f633cef0 1093/* TRACE_USER_STACK */
ae7462b4 1094static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
a9a57763 1095 int flags, struct trace_event *event)
f633cef0 1096{
983f938a 1097 struct trace_array *tr = iter->tr;
f633cef0 1098 struct userstack_entry *field;
2c9b238e 1099 struct trace_seq *s = &iter->seq;
6b1032d5
SRRH
1100 struct mm_struct *mm = NULL;
1101 unsigned int i;
f633cef0 1102
2c9b238e 1103 trace_assign_type(field, iter->ent);
f633cef0 1104
19a7fe20 1105 trace_seq_puts(s, "<user stack trace>\n");
6b1032d5 1106
983f938a 1107 if (tr->trace_flags & TRACE_ITER_SYM_USEROBJ) {
6b1032d5
SRRH
1108 struct task_struct *task;
1109 /*
1110 * we do the lookup on the thread group leader,
1111 * since individual threads might have already quit!
1112 */
1113 rcu_read_lock();
1114 task = find_task_by_vpid(field->tgid);
1115 if (task)
1116 mm = get_task_mm(task);
1117 rcu_read_unlock();
1118 }
1119
1120 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1121 unsigned long ip = field->caller[i];
1122
1123 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
1124 break;
1125
1126 trace_seq_puts(s, " => ");
1127
1128 if (!ip) {
1129 trace_seq_puts(s, "??");
1130 trace_seq_putc(s, '\n');
1131 continue;
1132 }
1133
1134 seq_print_user_ip(s, mm, ip, flags);
1135 trace_seq_putc(s, '\n');
1136 }
1137
1138 if (mm)
1139 mmput(mm);
f633cef0 1140
19a7fe20 1141 return trace_handle_return(s);
f633cef0
SR
1142}
1143
a9a57763 1144static struct trace_event_functions trace_user_stack_funcs = {
f633cef0 1145 .trace = trace_user_stack_print,
f633cef0
SR
1146};
1147
a9a57763
SR
1148static struct trace_event trace_user_stack_event = {
1149 .type = TRACE_USER_STACK,
1150 .funcs = &trace_user_stack_funcs,
1151};
1152
e7c15cd8
SRRH
1153/* TRACE_HWLAT */
1154static enum print_line_t
1155trace_hwlat_print(struct trace_iterator *iter, int flags,
1156 struct trace_event *event)
1157{
1158 struct trace_entry *entry = iter->ent;
1159 struct trace_seq *s = &iter->seq;
1160 struct hwlat_entry *field;
1161
1162 trace_assign_type(field, entry);
1163
7b2c8625 1164 trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
e7c15cd8
SRRH
1165 field->seqnum,
1166 field->duration,
1167 field->outer_duration,
1168 field->timestamp.tv_sec,
1169 field->timestamp.tv_nsec);
1170
7b2c8625
SRRH
1171 if (field->nmi_count) {
1172 /*
1173 * The generic sched_clock() is not NMI safe, thus
1174 * we only record the count and not the time.
1175 */
1176 if (!IS_ENABLED(CONFIG_GENERIC_SCHED_CLOCK))
1177 trace_seq_printf(s, " nmi-total:%llu",
1178 field->nmi_total_ts);
1179 trace_seq_printf(s, " nmi-count:%u",
1180 field->nmi_count);
1181 }
1182
1183 trace_seq_putc(s, '\n');
1184
e7c15cd8
SRRH
1185 return trace_handle_return(s);
1186}
1187
1188
1189static enum print_line_t
1190trace_hwlat_raw(struct trace_iterator *iter, int flags,
1191 struct trace_event *event)
1192{
1193 struct hwlat_entry *field;
1194 struct trace_seq *s = &iter->seq;
1195
1196 trace_assign_type(field, iter->ent);
1197
1198 trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
1199 field->duration,
1200 field->outer_duration,
1201 field->timestamp.tv_sec,
1202 field->timestamp.tv_nsec,
1203 field->seqnum);
1204
1205 return trace_handle_return(s);
1206}
1207
1208static struct trace_event_functions trace_hwlat_funcs = {
1209 .trace = trace_hwlat_print,
1210 .raw = trace_hwlat_raw,
1211};
1212
1213static struct trace_event trace_hwlat_event = {
1214 .type = TRACE_HWLAT,
1215 .funcs = &trace_hwlat_funcs,
1216};
1217
09ae7234
SRRH
1218/* TRACE_BPUTS */
1219static enum print_line_t
1220trace_bputs_print(struct trace_iterator *iter, int flags,
1221 struct trace_event *event)
1222{
1223 struct trace_entry *entry = iter->ent;
1224 struct trace_seq *s = &iter->seq;
1225 struct bputs_entry *field;
1226
1227 trace_assign_type(field, entry);
1228
19a7fe20
SRRH
1229 seq_print_ip_sym(s, field->ip, flags);
1230 trace_seq_puts(s, ": ");
1231 trace_seq_puts(s, field->str);
09ae7234 1232
19a7fe20 1233 return trace_handle_return(s);
09ae7234
SRRH
1234}
1235
1236
1237static enum print_line_t
1238trace_bputs_raw(struct trace_iterator *iter, int flags,
1239 struct trace_event *event)
1240{
1241 struct bputs_entry *field;
1242 struct trace_seq *s = &iter->seq;
1243
1244 trace_assign_type(field, iter->ent);
1245
19a7fe20
SRRH
1246 trace_seq_printf(s, ": %lx : ", field->ip);
1247 trace_seq_puts(s, field->str);
09ae7234 1248
19a7fe20 1249 return trace_handle_return(s);
09ae7234
SRRH
1250}
1251
1252static struct trace_event_functions trace_bputs_funcs = {
1253 .trace = trace_bputs_print,
1254 .raw = trace_bputs_raw,
1255};
1256
1257static struct trace_event trace_bputs_event = {
1258 .type = TRACE_BPUTS,
1259 .funcs = &trace_bputs_funcs,
1260};
1261
48ead020 1262/* TRACE_BPRINT */
1427cdf0 1263static enum print_line_t
a9a57763
SR
1264trace_bprint_print(struct trace_iterator *iter, int flags,
1265 struct trace_event *event)
1427cdf0
LJ
1266{
1267 struct trace_entry *entry = iter->ent;
1268 struct trace_seq *s = &iter->seq;
48ead020 1269 struct bprint_entry *field;
1427cdf0
LJ
1270
1271 trace_assign_type(field, entry);
1272
19a7fe20
SRRH
1273 seq_print_ip_sym(s, field->ip, flags);
1274 trace_seq_puts(s, ": ");
1275 trace_seq_bprintf(s, field->fmt, field->buf);
1427cdf0 1276
19a7fe20 1277 return trace_handle_return(s);
1427cdf0
LJ
1278}
1279
769b0441 1280
48ead020 1281static enum print_line_t
a9a57763
SR
1282trace_bprint_raw(struct trace_iterator *iter, int flags,
1283 struct trace_event *event)
1427cdf0 1284{
48ead020 1285 struct bprint_entry *field;
1427cdf0 1286 struct trace_seq *s = &iter->seq;
1427cdf0 1287
769b0441 1288 trace_assign_type(field, iter->ent);
1427cdf0 1289
19a7fe20
SRRH
1290 trace_seq_printf(s, ": %lx : ", field->ip);
1291 trace_seq_bprintf(s, field->fmt, field->buf);
1427cdf0 1292
19a7fe20 1293 return trace_handle_return(s);
1427cdf0
LJ
1294}
1295
a9a57763
SR
1296static struct trace_event_functions trace_bprint_funcs = {
1297 .trace = trace_bprint_print,
1298 .raw = trace_bprint_raw,
1299};
769b0441 1300
48ead020
FW
1301static struct trace_event trace_bprint_event = {
1302 .type = TRACE_BPRINT,
a9a57763 1303 .funcs = &trace_bprint_funcs,
48ead020
FW
1304};
1305
1306/* TRACE_PRINT */
1307static enum print_line_t trace_print_print(struct trace_iterator *iter,
a9a57763 1308 int flags, struct trace_event *event)
48ead020
FW
1309{
1310 struct print_entry *field;
1311 struct trace_seq *s = &iter->seq;
1312
1313 trace_assign_type(field, iter->ent);
1314
19a7fe20
SRRH
1315 seq_print_ip_sym(s, field->ip, flags);
1316 trace_seq_printf(s, ": %s", field->buf);
48ead020 1317
19a7fe20 1318 return trace_handle_return(s);
48ead020
FW
1319}
1320
a9a57763
SR
1321static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1322 struct trace_event *event)
48ead020
FW
1323{
1324 struct print_entry *field;
1325
1326 trace_assign_type(field, iter->ent);
1327
19a7fe20 1328 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
48ead020 1329
19a7fe20 1330 return trace_handle_return(&iter->seq);
48ead020
FW
1331}
1332
a9a57763 1333static struct trace_event_functions trace_print_funcs = {
769b0441
FW
1334 .trace = trace_print_print,
1335 .raw = trace_print_raw,
1427cdf0
LJ
1336};
1337
a9a57763
SR
1338static struct trace_event trace_print_event = {
1339 .type = TRACE_PRINT,
1340 .funcs = &trace_print_funcs,
1341};
1342
fa32e855
SR
1343static enum print_line_t trace_raw_data(struct trace_iterator *iter, int flags,
1344 struct trace_event *event)
1345{
1346 struct raw_data_entry *field;
1347 int i;
1348
1349 trace_assign_type(field, iter->ent);
1350
1351 trace_seq_printf(&iter->seq, "# %x buf:", field->id);
1352
1353 for (i = 0; i < iter->ent_size - offsetof(struct raw_data_entry, buf); i++)
1354 trace_seq_printf(&iter->seq, " %02x",
1355 (unsigned char)field->buf[i]);
1356
1357 trace_seq_putc(&iter->seq, '\n');
1358
1359 return trace_handle_return(&iter->seq);
1360}
1361
1362static struct trace_event_functions trace_raw_data_funcs = {
1363 .trace = trace_raw_data,
1364 .raw = trace_raw_data,
1365};
1366
1367static struct trace_event trace_raw_data_event = {
1368 .type = TRACE_RAW_DATA,
1369 .funcs = &trace_raw_data_funcs,
1370};
1371
48ead020 1372
f633cef0
SR
1373static struct trace_event *events[] __initdata = {
1374 &trace_fn_event,
1375 &trace_ctx_event,
1376 &trace_wake_event,
f633cef0
SR
1377 &trace_stack_event,
1378 &trace_user_stack_event,
09ae7234 1379 &trace_bputs_event,
48ead020 1380 &trace_bprint_event,
f633cef0 1381 &trace_print_event,
e7c15cd8 1382 &trace_hwlat_event,
fa32e855 1383 &trace_raw_data_event,
f633cef0
SR
1384 NULL
1385};
1386
1387__init static int init_events(void)
1388{
1389 struct trace_event *event;
1390 int i, ret;
1391
1392 for (i = 0; events[i]; i++) {
1393 event = events[i];
1394
9023c930 1395 ret = register_trace_event(event);
f633cef0
SR
1396 if (!ret) {
1397 printk(KERN_WARNING "event %d failed to register\n",
1398 event->type);
1399 WARN_ON_ONCE(1);
1400 }
1401 }
1402
1403 return 0;
1404}
7374e827 1405early_initcall(init_events);