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