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