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 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 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 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 * 63 ftrace_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(ftrace_print_flags_seq); 99 100 const char * 101 ftrace_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(ftrace_print_symbols_seq); 124 125 #if BITS_PER_LONG == 32 126 const char * 127 ftrace_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(ftrace_print_symbols_seq_u64); 150 #endif 151 152 const char * 153 ftrace_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(ftrace_print_bitmask_seq); 164 165 const char * 166 ftrace_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(ftrace_print_hex_seq); 179 180 int ftrace_raw_output_prep(struct trace_iterator *iter, 181 struct trace_event *trace_event) 182 { 183 struct ftrace_event_call *event; 184 struct trace_seq *s = &iter->seq; 185 struct trace_seq *p = &iter->tmp_seq; 186 struct trace_entry *entry; 187 188 event = container_of(trace_event, struct ftrace_event_call, event); 189 entry = iter->ent; 190 191 if (entry->type != event->event.type) { 192 WARN_ON_ONCE(1); 193 return TRACE_TYPE_UNHANDLED; 194 } 195 196 trace_seq_init(p); 197 trace_seq_printf(s, "%s: ", ftrace_event_name(event)); 198 199 return trace_handle_return(s); 200 } 201 EXPORT_SYMBOL(ftrace_raw_output_prep); 202 203 static int ftrace_output_raw(struct trace_iterator *iter, char *name, 204 char *fmt, va_list ap) 205 { 206 struct trace_seq *s = &iter->seq; 207 208 trace_seq_printf(s, "%s: ", name); 209 trace_seq_vprintf(s, fmt, ap); 210 211 return trace_handle_return(s); 212 } 213 214 int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...) 215 { 216 va_list ap; 217 int ret; 218 219 va_start(ap, fmt); 220 ret = ftrace_output_raw(iter, name, fmt, ap); 221 va_end(ap); 222 223 return ret; 224 } 225 EXPORT_SYMBOL_GPL(ftrace_output_call); 226 227 #ifdef CONFIG_KRETPROBES 228 static inline const char *kretprobed(const char *name) 229 { 230 static const char tramp_name[] = "kretprobe_trampoline"; 231 int size = sizeof(tramp_name); 232 233 if (strncmp(tramp_name, name, size) == 0) 234 return "[unknown/kretprobe'd]"; 235 return name; 236 } 237 #else 238 static inline const char *kretprobed(const char *name) 239 { 240 return name; 241 } 242 #endif /* CONFIG_KRETPROBES */ 243 244 static void 245 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address) 246 { 247 #ifdef CONFIG_KALLSYMS 248 char str[KSYM_SYMBOL_LEN]; 249 const char *name; 250 251 kallsyms_lookup(address, NULL, NULL, NULL, str); 252 253 name = kretprobed(str); 254 255 trace_seq_printf(s, fmt, name); 256 #endif 257 } 258 259 static void 260 seq_print_sym_offset(struct trace_seq *s, const char *fmt, 261 unsigned long address) 262 { 263 #ifdef CONFIG_KALLSYMS 264 char str[KSYM_SYMBOL_LEN]; 265 const char *name; 266 267 sprint_symbol(str, address); 268 name = kretprobed(str); 269 270 trace_seq_printf(s, fmt, name); 271 #endif 272 } 273 274 #ifndef CONFIG_64BIT 275 # define IP_FMT "%08lx" 276 #else 277 # define IP_FMT "%016lx" 278 #endif 279 280 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, 281 unsigned long ip, unsigned long sym_flags) 282 { 283 struct file *file = NULL; 284 unsigned long vmstart = 0; 285 int ret = 1; 286 287 if (s->full) 288 return 0; 289 290 if (mm) { 291 const struct vm_area_struct *vma; 292 293 down_read(&mm->mmap_sem); 294 vma = find_vma(mm, ip); 295 if (vma) { 296 file = vma->vm_file; 297 vmstart = vma->vm_start; 298 } 299 if (file) { 300 ret = trace_seq_path(s, &file->f_path); 301 if (ret) 302 trace_seq_printf(s, "[+0x%lx]", 303 ip - vmstart); 304 } 305 up_read(&mm->mmap_sem); 306 } 307 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file)) 308 trace_seq_printf(s, " <" IP_FMT ">", ip); 309 return !trace_seq_has_overflowed(s); 310 } 311 312 int 313 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s, 314 unsigned long sym_flags) 315 { 316 struct mm_struct *mm = NULL; 317 unsigned int i; 318 319 if (trace_flags & TRACE_ITER_SYM_USEROBJ) { 320 struct task_struct *task; 321 /* 322 * we do the lookup on the thread group leader, 323 * since individual threads might have already quit! 324 */ 325 rcu_read_lock(); 326 task = find_task_by_vpid(entry->tgid); 327 if (task) 328 mm = get_task_mm(task); 329 rcu_read_unlock(); 330 } 331 332 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { 333 unsigned long ip = entry->caller[i]; 334 335 if (ip == ULONG_MAX || trace_seq_has_overflowed(s)) 336 break; 337 338 trace_seq_puts(s, " => "); 339 340 if (!ip) { 341 trace_seq_puts(s, "??"); 342 trace_seq_putc(s, '\n'); 343 continue; 344 } 345 346 seq_print_user_ip(s, mm, ip, sym_flags); 347 trace_seq_putc(s, '\n'); 348 } 349 350 if (mm) 351 mmput(mm); 352 353 return !trace_seq_has_overflowed(s); 354 } 355 356 int 357 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) 358 { 359 if (!ip) { 360 trace_seq_putc(s, '0'); 361 goto out; 362 } 363 364 if (sym_flags & TRACE_ITER_SYM_OFFSET) 365 seq_print_sym_offset(s, "%s", ip); 366 else 367 seq_print_sym_short(s, "%s", ip); 368 369 if (sym_flags & TRACE_ITER_SYM_ADDR) 370 trace_seq_printf(s, " <" IP_FMT ">", ip); 371 372 out: 373 return !trace_seq_has_overflowed(s); 374 } 375 376 /** 377 * trace_print_lat_fmt - print the irq, preempt and lockdep fields 378 * @s: trace seq struct to write to 379 * @entry: The trace entry field from the ring buffer 380 * 381 * Prints the generic fields of irqs off, in hard or softirq, preempt 382 * count. 383 */ 384 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry) 385 { 386 char hardsoft_irq; 387 char need_resched; 388 char irqs_off; 389 int hardirq; 390 int softirq; 391 392 hardirq = entry->flags & TRACE_FLAG_HARDIRQ; 393 softirq = entry->flags & TRACE_FLAG_SOFTIRQ; 394 395 irqs_off = 396 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : 397 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : 398 '.'; 399 400 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED | 401 TRACE_FLAG_PREEMPT_RESCHED)) { 402 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED: 403 need_resched = 'N'; 404 break; 405 case TRACE_FLAG_NEED_RESCHED: 406 need_resched = 'n'; 407 break; 408 case TRACE_FLAG_PREEMPT_RESCHED: 409 need_resched = 'p'; 410 break; 411 default: 412 need_resched = '.'; 413 break; 414 } 415 416 hardsoft_irq = 417 (hardirq && softirq) ? 'H' : 418 hardirq ? 'h' : 419 softirq ? 's' : 420 '.'; 421 422 trace_seq_printf(s, "%c%c%c", 423 irqs_off, need_resched, hardsoft_irq); 424 425 if (entry->preempt_count) 426 trace_seq_printf(s, "%x", entry->preempt_count); 427 else 428 trace_seq_putc(s, '.'); 429 430 return !trace_seq_has_overflowed(s); 431 } 432 433 static int 434 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) 435 { 436 char comm[TASK_COMM_LEN]; 437 438 trace_find_cmdline(entry->pid, comm); 439 440 trace_seq_printf(s, "%8.8s-%-5d %3d", 441 comm, entry->pid, cpu); 442 443 return trace_print_lat_fmt(s, entry); 444 } 445 446 #undef MARK 447 #define MARK(v, s) {.val = v, .sym = s} 448 /* trace overhead mark */ 449 static const struct trace_mark { 450 unsigned long long val; /* unit: nsec */ 451 char sym; 452 } mark[] = { 453 MARK(1000000000ULL , '$'), /* 1 sec */ 454 MARK(1000000ULL , '#'), /* 1000 usecs */ 455 MARK(100000ULL , '!'), /* 100 usecs */ 456 MARK(10000ULL , '+'), /* 10 usecs */ 457 }; 458 #undef MARK 459 460 char trace_find_mark(unsigned long long d) 461 { 462 int i; 463 int size = ARRAY_SIZE(mark); 464 465 for (i = 0; i < size; i++) { 466 if (d >= mark[i].val) 467 break; 468 } 469 470 return (i == size) ? ' ' : mark[i].sym; 471 } 472 473 static int 474 lat_print_timestamp(struct trace_iterator *iter, u64 next_ts) 475 { 476 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE; 477 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS; 478 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start; 479 unsigned long long rel_ts = next_ts - iter->ts; 480 struct trace_seq *s = &iter->seq; 481 482 if (in_ns) { 483 abs_ts = ns2usecs(abs_ts); 484 rel_ts = ns2usecs(rel_ts); 485 } 486 487 if (verbose && in_ns) { 488 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC); 489 unsigned long abs_msec = (unsigned long)abs_ts; 490 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC); 491 unsigned long rel_msec = (unsigned long)rel_ts; 492 493 trace_seq_printf( 494 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ", 495 ns2usecs(iter->ts), 496 abs_msec, abs_usec, 497 rel_msec, rel_usec); 498 499 } else if (verbose && !in_ns) { 500 trace_seq_printf( 501 s, "[%016llx] %lld (+%lld): ", 502 iter->ts, abs_ts, rel_ts); 503 504 } else if (!verbose && in_ns) { 505 trace_seq_printf( 506 s, " %4lldus%c: ", 507 abs_ts, 508 trace_find_mark(rel_ts * NSEC_PER_USEC)); 509 510 } else { /* !verbose && !in_ns */ 511 trace_seq_printf(s, " %4lld: ", abs_ts); 512 } 513 514 return !trace_seq_has_overflowed(s); 515 } 516 517 int trace_print_context(struct trace_iterator *iter) 518 { 519 struct trace_seq *s = &iter->seq; 520 struct trace_entry *entry = iter->ent; 521 unsigned long long t; 522 unsigned long secs, usec_rem; 523 char comm[TASK_COMM_LEN]; 524 525 trace_find_cmdline(entry->pid, comm); 526 527 trace_seq_printf(s, "%16s-%-5d [%03d] ", 528 comm, entry->pid, iter->cpu); 529 530 if (trace_flags & TRACE_ITER_IRQ_INFO) 531 trace_print_lat_fmt(s, entry); 532 533 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) { 534 t = ns2usecs(iter->ts); 535 usec_rem = do_div(t, USEC_PER_SEC); 536 secs = (unsigned long)t; 537 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem); 538 } else 539 trace_seq_printf(s, " %12llu: ", iter->ts); 540 541 return !trace_seq_has_overflowed(s); 542 } 543 544 int trace_print_lat_context(struct trace_iterator *iter) 545 { 546 u64 next_ts; 547 /* trace_find_next_entry will reset ent_size */ 548 int ent_size = iter->ent_size; 549 struct trace_seq *s = &iter->seq; 550 struct trace_entry *entry = iter->ent, 551 *next_entry = trace_find_next_entry(iter, NULL, 552 &next_ts); 553 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); 554 555 /* Restore the original ent_size */ 556 iter->ent_size = ent_size; 557 558 if (!next_entry) 559 next_ts = iter->ts; 560 561 if (verbose) { 562 char comm[TASK_COMM_LEN]; 563 564 trace_find_cmdline(entry->pid, comm); 565 566 trace_seq_printf( 567 s, "%16s %5d %3d %d %08x %08lx ", 568 comm, entry->pid, iter->cpu, entry->flags, 569 entry->preempt_count, iter->idx); 570 } else { 571 lat_print_generic(s, entry, iter->cpu); 572 } 573 574 lat_print_timestamp(iter, next_ts); 575 576 return !trace_seq_has_overflowed(s); 577 } 578 579 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; 580 581 static int task_state_char(unsigned long state) 582 { 583 int bit = state ? __ffs(state) + 1 : 0; 584 585 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; 586 } 587 588 /** 589 * ftrace_find_event - find a registered event 590 * @type: the type of event to look for 591 * 592 * Returns an event of type @type otherwise NULL 593 * Called with trace_event_read_lock() held. 594 */ 595 struct trace_event *ftrace_find_event(int type) 596 { 597 struct trace_event *event; 598 unsigned key; 599 600 key = type & (EVENT_HASHSIZE - 1); 601 602 hlist_for_each_entry(event, &event_hash[key], node) { 603 if (event->type == type) 604 return event; 605 } 606 607 return NULL; 608 } 609 610 static LIST_HEAD(ftrace_event_list); 611 612 static int trace_search_list(struct list_head **list) 613 { 614 struct trace_event *e; 615 int last = __TRACE_LAST_TYPE; 616 617 if (list_empty(&ftrace_event_list)) { 618 *list = &ftrace_event_list; 619 return last + 1; 620 } 621 622 /* 623 * We used up all possible max events, 624 * lets see if somebody freed one. 625 */ 626 list_for_each_entry(e, &ftrace_event_list, list) { 627 if (e->type != last + 1) 628 break; 629 last++; 630 } 631 632 /* Did we used up all 65 thousand events??? */ 633 if ((last + 1) > FTRACE_MAX_EVENT) 634 return 0; 635 636 *list = &e->list; 637 return last + 1; 638 } 639 640 void trace_event_read_lock(void) 641 { 642 down_read(&trace_event_sem); 643 } 644 645 void trace_event_read_unlock(void) 646 { 647 up_read(&trace_event_sem); 648 } 649 650 /** 651 * register_ftrace_event - register output for an event type 652 * @event: the event type to register 653 * 654 * Event types are stored in a hash and this hash is used to 655 * find a way to print an event. If the @event->type is set 656 * then it will use that type, otherwise it will assign a 657 * type to use. 658 * 659 * If you assign your own type, please make sure it is added 660 * to the trace_type enum in trace.h, to avoid collisions 661 * with the dynamic types. 662 * 663 * Returns the event type number or zero on error. 664 */ 665 int register_ftrace_event(struct trace_event *event) 666 { 667 unsigned key; 668 int ret = 0; 669 670 down_write(&trace_event_sem); 671 672 if (WARN_ON(!event)) 673 goto out; 674 675 if (WARN_ON(!event->funcs)) 676 goto out; 677 678 INIT_LIST_HEAD(&event->list); 679 680 if (!event->type) { 681 struct list_head *list = NULL; 682 683 if (next_event_type > FTRACE_MAX_EVENT) { 684 685 event->type = trace_search_list(&list); 686 if (!event->type) 687 goto out; 688 689 } else { 690 691 event->type = next_event_type++; 692 list = &ftrace_event_list; 693 } 694 695 if (WARN_ON(ftrace_find_event(event->type))) 696 goto out; 697 698 list_add_tail(&event->list, list); 699 700 } else if (event->type > __TRACE_LAST_TYPE) { 701 printk(KERN_WARNING "Need to add type to trace.h\n"); 702 WARN_ON(1); 703 goto out; 704 } else { 705 /* Is this event already used */ 706 if (ftrace_find_event(event->type)) 707 goto out; 708 } 709 710 if (event->funcs->trace == NULL) 711 event->funcs->trace = trace_nop_print; 712 if (event->funcs->raw == NULL) 713 event->funcs->raw = trace_nop_print; 714 if (event->funcs->hex == NULL) 715 event->funcs->hex = trace_nop_print; 716 if (event->funcs->binary == NULL) 717 event->funcs->binary = trace_nop_print; 718 719 key = event->type & (EVENT_HASHSIZE - 1); 720 721 hlist_add_head(&event->node, &event_hash[key]); 722 723 ret = event->type; 724 out: 725 up_write(&trace_event_sem); 726 727 return ret; 728 } 729 EXPORT_SYMBOL_GPL(register_ftrace_event); 730 731 /* 732 * Used by module code with the trace_event_sem held for write. 733 */ 734 int __unregister_ftrace_event(struct trace_event *event) 735 { 736 hlist_del(&event->node); 737 list_del(&event->list); 738 return 0; 739 } 740 741 /** 742 * unregister_ftrace_event - remove a no longer used event 743 * @event: the event to remove 744 */ 745 int unregister_ftrace_event(struct trace_event *event) 746 { 747 down_write(&trace_event_sem); 748 __unregister_ftrace_event(event); 749 up_write(&trace_event_sem); 750 751 return 0; 752 } 753 EXPORT_SYMBOL_GPL(unregister_ftrace_event); 754 755 /* 756 * Standard events 757 */ 758 759 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags, 760 struct trace_event *event) 761 { 762 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type); 763 764 return trace_handle_return(&iter->seq); 765 } 766 767 /* TRACE_FN */ 768 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags, 769 struct trace_event *event) 770 { 771 struct ftrace_entry *field; 772 struct trace_seq *s = &iter->seq; 773 774 trace_assign_type(field, iter->ent); 775 776 seq_print_ip_sym(s, field->ip, flags); 777 778 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) { 779 trace_seq_puts(s, " <-"); 780 seq_print_ip_sym(s, field->parent_ip, flags); 781 } 782 783 trace_seq_putc(s, '\n'); 784 785 return trace_handle_return(s); 786 } 787 788 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags, 789 struct trace_event *event) 790 { 791 struct ftrace_entry *field; 792 793 trace_assign_type(field, iter->ent); 794 795 trace_seq_printf(&iter->seq, "%lx %lx\n", 796 field->ip, 797 field->parent_ip); 798 799 return trace_handle_return(&iter->seq); 800 } 801 802 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags, 803 struct trace_event *event) 804 { 805 struct ftrace_entry *field; 806 struct trace_seq *s = &iter->seq; 807 808 trace_assign_type(field, iter->ent); 809 810 SEQ_PUT_HEX_FIELD(s, field->ip); 811 SEQ_PUT_HEX_FIELD(s, field->parent_ip); 812 813 return trace_handle_return(s); 814 } 815 816 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags, 817 struct trace_event *event) 818 { 819 struct ftrace_entry *field; 820 struct trace_seq *s = &iter->seq; 821 822 trace_assign_type(field, iter->ent); 823 824 SEQ_PUT_FIELD(s, field->ip); 825 SEQ_PUT_FIELD(s, field->parent_ip); 826 827 return trace_handle_return(s); 828 } 829 830 static struct trace_event_functions trace_fn_funcs = { 831 .trace = trace_fn_trace, 832 .raw = trace_fn_raw, 833 .hex = trace_fn_hex, 834 .binary = trace_fn_bin, 835 }; 836 837 static struct trace_event trace_fn_event = { 838 .type = TRACE_FN, 839 .funcs = &trace_fn_funcs, 840 }; 841 842 /* TRACE_CTX an TRACE_WAKE */ 843 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, 844 char *delim) 845 { 846 struct ctx_switch_entry *field; 847 char comm[TASK_COMM_LEN]; 848 int S, T; 849 850 851 trace_assign_type(field, iter->ent); 852 853 T = task_state_char(field->next_state); 854 S = task_state_char(field->prev_state); 855 trace_find_cmdline(field->next_pid, comm); 856 trace_seq_printf(&iter->seq, 857 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n", 858 field->prev_pid, 859 field->prev_prio, 860 S, delim, 861 field->next_cpu, 862 field->next_pid, 863 field->next_prio, 864 T, comm); 865 866 return trace_handle_return(&iter->seq); 867 } 868 869 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags, 870 struct trace_event *event) 871 { 872 return trace_ctxwake_print(iter, "==>"); 873 } 874 875 static enum print_line_t trace_wake_print(struct trace_iterator *iter, 876 int flags, struct trace_event *event) 877 { 878 return trace_ctxwake_print(iter, " +"); 879 } 880 881 static int trace_ctxwake_raw(struct trace_iterator *iter, char S) 882 { 883 struct ctx_switch_entry *field; 884 int T; 885 886 trace_assign_type(field, iter->ent); 887 888 if (!S) 889 S = task_state_char(field->prev_state); 890 T = task_state_char(field->next_state); 891 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n", 892 field->prev_pid, 893 field->prev_prio, 894 S, 895 field->next_cpu, 896 field->next_pid, 897 field->next_prio, 898 T); 899 900 return trace_handle_return(&iter->seq); 901 } 902 903 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags, 904 struct trace_event *event) 905 { 906 return trace_ctxwake_raw(iter, 0); 907 } 908 909 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags, 910 struct trace_event *event) 911 { 912 return trace_ctxwake_raw(iter, '+'); 913 } 914 915 916 static int trace_ctxwake_hex(struct trace_iterator *iter, char S) 917 { 918 struct ctx_switch_entry *field; 919 struct trace_seq *s = &iter->seq; 920 int T; 921 922 trace_assign_type(field, iter->ent); 923 924 if (!S) 925 S = task_state_char(field->prev_state); 926 T = task_state_char(field->next_state); 927 928 SEQ_PUT_HEX_FIELD(s, field->prev_pid); 929 SEQ_PUT_HEX_FIELD(s, field->prev_prio); 930 SEQ_PUT_HEX_FIELD(s, S); 931 SEQ_PUT_HEX_FIELD(s, field->next_cpu); 932 SEQ_PUT_HEX_FIELD(s, field->next_pid); 933 SEQ_PUT_HEX_FIELD(s, field->next_prio); 934 SEQ_PUT_HEX_FIELD(s, T); 935 936 return trace_handle_return(s); 937 } 938 939 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags, 940 struct trace_event *event) 941 { 942 return trace_ctxwake_hex(iter, 0); 943 } 944 945 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags, 946 struct trace_event *event) 947 { 948 return trace_ctxwake_hex(iter, '+'); 949 } 950 951 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, 952 int flags, struct trace_event *event) 953 { 954 struct ctx_switch_entry *field; 955 struct trace_seq *s = &iter->seq; 956 957 trace_assign_type(field, iter->ent); 958 959 SEQ_PUT_FIELD(s, field->prev_pid); 960 SEQ_PUT_FIELD(s, field->prev_prio); 961 SEQ_PUT_FIELD(s, field->prev_state); 962 SEQ_PUT_FIELD(s, field->next_cpu); 963 SEQ_PUT_FIELD(s, field->next_pid); 964 SEQ_PUT_FIELD(s, field->next_prio); 965 SEQ_PUT_FIELD(s, field->next_state); 966 967 return trace_handle_return(s); 968 } 969 970 static struct trace_event_functions trace_ctx_funcs = { 971 .trace = trace_ctx_print, 972 .raw = trace_ctx_raw, 973 .hex = trace_ctx_hex, 974 .binary = trace_ctxwake_bin, 975 }; 976 977 static struct trace_event trace_ctx_event = { 978 .type = TRACE_CTX, 979 .funcs = &trace_ctx_funcs, 980 }; 981 982 static struct trace_event_functions trace_wake_funcs = { 983 .trace = trace_wake_print, 984 .raw = trace_wake_raw, 985 .hex = trace_wake_hex, 986 .binary = trace_ctxwake_bin, 987 }; 988 989 static struct trace_event trace_wake_event = { 990 .type = TRACE_WAKE, 991 .funcs = &trace_wake_funcs, 992 }; 993 994 /* TRACE_STACK */ 995 996 static enum print_line_t trace_stack_print(struct trace_iterator *iter, 997 int flags, struct trace_event *event) 998 { 999 struct stack_entry *field; 1000 struct trace_seq *s = &iter->seq; 1001 unsigned long *p; 1002 unsigned long *end; 1003 1004 trace_assign_type(field, iter->ent); 1005 end = (unsigned long *)((long)iter->ent + iter->ent_size); 1006 1007 trace_seq_puts(s, "<stack trace>\n"); 1008 1009 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) { 1010 1011 if (trace_seq_has_overflowed(s)) 1012 break; 1013 1014 trace_seq_puts(s, " => "); 1015 seq_print_ip_sym(s, *p, flags); 1016 trace_seq_putc(s, '\n'); 1017 } 1018 1019 return trace_handle_return(s); 1020 } 1021 1022 static struct trace_event_functions trace_stack_funcs = { 1023 .trace = trace_stack_print, 1024 }; 1025 1026 static struct trace_event trace_stack_event = { 1027 .type = TRACE_STACK, 1028 .funcs = &trace_stack_funcs, 1029 }; 1030 1031 /* TRACE_USER_STACK */ 1032 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, 1033 int flags, struct trace_event *event) 1034 { 1035 struct userstack_entry *field; 1036 struct trace_seq *s = &iter->seq; 1037 1038 trace_assign_type(field, iter->ent); 1039 1040 trace_seq_puts(s, "<user stack trace>\n"); 1041 seq_print_userip_objs(field, s, flags); 1042 1043 return trace_handle_return(s); 1044 } 1045 1046 static struct trace_event_functions trace_user_stack_funcs = { 1047 .trace = trace_user_stack_print, 1048 }; 1049 1050 static struct trace_event trace_user_stack_event = { 1051 .type = TRACE_USER_STACK, 1052 .funcs = &trace_user_stack_funcs, 1053 }; 1054 1055 /* TRACE_BPUTS */ 1056 static enum print_line_t 1057 trace_bputs_print(struct trace_iterator *iter, int flags, 1058 struct trace_event *event) 1059 { 1060 struct trace_entry *entry = iter->ent; 1061 struct trace_seq *s = &iter->seq; 1062 struct bputs_entry *field; 1063 1064 trace_assign_type(field, entry); 1065 1066 seq_print_ip_sym(s, field->ip, flags); 1067 trace_seq_puts(s, ": "); 1068 trace_seq_puts(s, field->str); 1069 1070 return trace_handle_return(s); 1071 } 1072 1073 1074 static enum print_line_t 1075 trace_bputs_raw(struct trace_iterator *iter, int flags, 1076 struct trace_event *event) 1077 { 1078 struct bputs_entry *field; 1079 struct trace_seq *s = &iter->seq; 1080 1081 trace_assign_type(field, iter->ent); 1082 1083 trace_seq_printf(s, ": %lx : ", field->ip); 1084 trace_seq_puts(s, field->str); 1085 1086 return trace_handle_return(s); 1087 } 1088 1089 static struct trace_event_functions trace_bputs_funcs = { 1090 .trace = trace_bputs_print, 1091 .raw = trace_bputs_raw, 1092 }; 1093 1094 static struct trace_event trace_bputs_event = { 1095 .type = TRACE_BPUTS, 1096 .funcs = &trace_bputs_funcs, 1097 }; 1098 1099 /* TRACE_BPRINT */ 1100 static enum print_line_t 1101 trace_bprint_print(struct trace_iterator *iter, int flags, 1102 struct trace_event *event) 1103 { 1104 struct trace_entry *entry = iter->ent; 1105 struct trace_seq *s = &iter->seq; 1106 struct bprint_entry *field; 1107 1108 trace_assign_type(field, entry); 1109 1110 seq_print_ip_sym(s, field->ip, flags); 1111 trace_seq_puts(s, ": "); 1112 trace_seq_bprintf(s, field->fmt, field->buf); 1113 1114 return trace_handle_return(s); 1115 } 1116 1117 1118 static enum print_line_t 1119 trace_bprint_raw(struct trace_iterator *iter, int flags, 1120 struct trace_event *event) 1121 { 1122 struct bprint_entry *field; 1123 struct trace_seq *s = &iter->seq; 1124 1125 trace_assign_type(field, iter->ent); 1126 1127 trace_seq_printf(s, ": %lx : ", field->ip); 1128 trace_seq_bprintf(s, field->fmt, field->buf); 1129 1130 return trace_handle_return(s); 1131 } 1132 1133 static struct trace_event_functions trace_bprint_funcs = { 1134 .trace = trace_bprint_print, 1135 .raw = trace_bprint_raw, 1136 }; 1137 1138 static struct trace_event trace_bprint_event = { 1139 .type = TRACE_BPRINT, 1140 .funcs = &trace_bprint_funcs, 1141 }; 1142 1143 /* TRACE_PRINT */ 1144 static enum print_line_t trace_print_print(struct trace_iterator *iter, 1145 int flags, struct trace_event *event) 1146 { 1147 struct print_entry *field; 1148 struct trace_seq *s = &iter->seq; 1149 1150 trace_assign_type(field, iter->ent); 1151 1152 seq_print_ip_sym(s, field->ip, flags); 1153 trace_seq_printf(s, ": %s", field->buf); 1154 1155 return trace_handle_return(s); 1156 } 1157 1158 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags, 1159 struct trace_event *event) 1160 { 1161 struct print_entry *field; 1162 1163 trace_assign_type(field, iter->ent); 1164 1165 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf); 1166 1167 return trace_handle_return(&iter->seq); 1168 } 1169 1170 static struct trace_event_functions trace_print_funcs = { 1171 .trace = trace_print_print, 1172 .raw = trace_print_raw, 1173 }; 1174 1175 static struct trace_event trace_print_event = { 1176 .type = TRACE_PRINT, 1177 .funcs = &trace_print_funcs, 1178 }; 1179 1180 1181 static struct trace_event *events[] __initdata = { 1182 &trace_fn_event, 1183 &trace_ctx_event, 1184 &trace_wake_event, 1185 &trace_stack_event, 1186 &trace_user_stack_event, 1187 &trace_bputs_event, 1188 &trace_bprint_event, 1189 &trace_print_event, 1190 NULL 1191 }; 1192 1193 __init static int init_events(void) 1194 { 1195 struct trace_event *event; 1196 int i, ret; 1197 1198 for (i = 0; events[i]; i++) { 1199 event = events[i]; 1200 1201 ret = register_ftrace_event(event); 1202 if (!ret) { 1203 printk(KERN_WARNING "event %d failed to register\n", 1204 event->type); 1205 WARN_ON_ONCE(1); 1206 } 1207 } 1208 1209 return 0; 1210 } 1211 early_initcall(init_events); 1212