diff options
Diffstat (limited to 'kernel/trace')
| -rw-r--r-- | kernel/trace/Makefile | 2 | ||||
| -rw-r--r-- | kernel/trace/trace.c | 741 | ||||
| -rw-r--r-- | kernel/trace/trace.h | 36 | ||||
| -rw-r--r-- | kernel/trace/trace_boot.c | 1 | ||||
| -rw-r--r-- | kernel/trace/trace_branch.c | 295 | ||||
| -rw-r--r-- | kernel/trace/trace_functions_graph.c | 4 | ||||
| -rw-r--r-- | kernel/trace/trace_hw_branches.c | 1 | ||||
| -rw-r--r-- | kernel/trace/trace_mmiotrace.c | 4 | ||||
| -rw-r--r-- | kernel/trace/trace_output.c | 832 | ||||
| -rw-r--r-- | kernel/trace/trace_output.h | 59 | ||||
| -rw-r--r-- | kernel/trace/trace_power.c | 1 | ||||
| -rw-r--r-- | kernel/trace/trace_selftest.c | 1 | ||||
| -rw-r--r-- | kernel/trace/trace_stat.c | 251 |
13 files changed, 1392 insertions, 836 deletions
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 513dc86b5dfa..05c9182061de 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile | |||
| @@ -19,6 +19,8 @@ obj-$(CONFIG_FUNCTION_TRACER) += libftrace.o | |||
| 19 | obj-$(CONFIG_RING_BUFFER) += ring_buffer.o | 19 | obj-$(CONFIG_RING_BUFFER) += ring_buffer.o |
| 20 | 20 | ||
| 21 | obj-$(CONFIG_TRACING) += trace.o | 21 | obj-$(CONFIG_TRACING) += trace.o |
| 22 | obj-$(CONFIG_TRACING) += trace_output.o | ||
| 23 | obj-$(CONFIG_TRACING) += trace_stat.o | ||
| 22 | obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o | 24 | obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o |
| 23 | obj-$(CONFIG_SYSPROF_TRACER) += trace_sysprof.o | 25 | obj-$(CONFIG_SYSPROF_TRACER) += trace_sysprof.o |
| 24 | obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o | 26 | obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index c580233add95..0418fc338b5c 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
| @@ -37,6 +37,7 @@ | |||
| 37 | #include <linux/irqflags.h> | 37 | #include <linux/irqflags.h> |
| 38 | 38 | ||
| 39 | #include "trace.h" | 39 | #include "trace.h" |
| 40 | #include "trace_output.h" | ||
| 40 | 41 | ||
| 41 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) | 42 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) |
| 42 | 43 | ||
| @@ -329,132 +330,6 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | |||
| 329 | tracing_record_cmdline(current); | 330 | tracing_record_cmdline(current); |
| 330 | } | 331 | } |
| 331 | 332 | ||
| 332 | /** | ||
| 333 | * trace_seq_printf - sequence printing of trace information | ||
| 334 | * @s: trace sequence descriptor | ||
| 335 | * @fmt: printf format string | ||
| 336 | * | ||
| 337 | * The tracer may use either sequence operations or its own | ||
| 338 | * copy to user routines. To simplify formating of a trace | ||
| 339 | * trace_seq_printf is used to store strings into a special | ||
| 340 | * buffer (@s). Then the output may be either used by | ||
| 341 | * the sequencer or pulled into another buffer. | ||
| 342 | */ | ||
| 343 | int | ||
| 344 | trace_seq_printf(struct trace_seq *s, const char *fmt, ...) | ||
| 345 | { | ||
| 346 | int len = (PAGE_SIZE - 1) - s->len; | ||
| 347 | va_list ap; | ||
| 348 | int ret; | ||
| 349 | |||
| 350 | if (!len) | ||
| 351 | return 0; | ||
| 352 | |||
| 353 | va_start(ap, fmt); | ||
| 354 | ret = vsnprintf(s->buffer + s->len, len, fmt, ap); | ||
| 355 | va_end(ap); | ||
| 356 | |||
| 357 | /* If we can't write it all, don't bother writing anything */ | ||
| 358 | if (ret >= len) | ||
| 359 | return 0; | ||
| 360 | |||
| 361 | s->len += ret; | ||
| 362 | |||
| 363 | return len; | ||
| 364 | } | ||
| 365 | |||
| 366 | /** | ||
| 367 | * trace_seq_puts - trace sequence printing of simple string | ||
| 368 | * @s: trace sequence descriptor | ||
| 369 | * @str: simple string to record | ||
| 370 | * | ||
| 371 | * The tracer may use either the sequence operations or its own | ||
| 372 | * copy to user routines. This function records a simple string | ||
| 373 | * into a special buffer (@s) for later retrieval by a sequencer | ||
| 374 | * or other mechanism. | ||
| 375 | */ | ||
| 376 | static int | ||
| 377 | trace_seq_puts(struct trace_seq *s, const char *str) | ||
| 378 | { | ||
| 379 | int len = strlen(str); | ||
| 380 | |||
| 381 | if (len > ((PAGE_SIZE - 1) - s->len)) | ||
| 382 | return 0; | ||
| 383 | |||
| 384 | memcpy(s->buffer + s->len, str, len); | ||
| 385 | s->len += len; | ||
| 386 | |||
| 387 | return len; | ||
| 388 | } | ||
| 389 | |||
| 390 | static int | ||
| 391 | trace_seq_putc(struct trace_seq *s, unsigned char c) | ||
| 392 | { | ||
| 393 | if (s->len >= (PAGE_SIZE - 1)) | ||
| 394 | return 0; | ||
| 395 | |||
| 396 | s->buffer[s->len++] = c; | ||
| 397 | |||
| 398 | return 1; | ||
| 399 | } | ||
| 400 | |||
| 401 | static int | ||
| 402 | trace_seq_putmem(struct trace_seq *s, void *mem, size_t len) | ||
| 403 | { | ||
| 404 | if (len > ((PAGE_SIZE - 1) - s->len)) | ||
| 405 | return 0; | ||
| 406 | |||
| 407 | memcpy(s->buffer + s->len, mem, len); | ||
| 408 | s->len += len; | ||
| 409 | |||
| 410 | return len; | ||
| 411 | } | ||
| 412 | |||
| 413 | #define MAX_MEMHEX_BYTES 8 | ||
| 414 | #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) | ||
| 415 | |||
| 416 | static int | ||
| 417 | trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len) | ||
| 418 | { | ||
| 419 | unsigned char hex[HEX_CHARS]; | ||
| 420 | unsigned char *data = mem; | ||
| 421 | int i, j; | ||
| 422 | |||
| 423 | #ifdef __BIG_ENDIAN | ||
| 424 | for (i = 0, j = 0; i < len; i++) { | ||
| 425 | #else | ||
| 426 | for (i = len-1, j = 0; i >= 0; i--) { | ||
| 427 | #endif | ||
| 428 | hex[j++] = hex_asc_hi(data[i]); | ||
| 429 | hex[j++] = hex_asc_lo(data[i]); | ||
| 430 | } | ||
| 431 | hex[j++] = ' '; | ||
| 432 | |||
| 433 | return trace_seq_putmem(s, hex, j); | ||
| 434 | } | ||
| 435 | |||
| 436 | static int | ||
| 437 | trace_seq_path(struct trace_seq *s, struct path *path) | ||
| 438 | { | ||
| 439 | unsigned char *p; | ||
| 440 | |||
| 441 | if (s->len >= (PAGE_SIZE - 1)) | ||
| 442 | return 0; | ||
| 443 | p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len); | ||
| 444 | if (!IS_ERR(p)) { | ||
| 445 | p = mangle_path(s->buffer + s->len, p, "\n"); | ||
| 446 | if (p) { | ||
| 447 | s->len = p - s->buffer; | ||
| 448 | return 1; | ||
| 449 | } | ||
| 450 | } else { | ||
| 451 | s->buffer[s->len++] = '?'; | ||
| 452 | return 1; | ||
| 453 | } | ||
| 454 | |||
| 455 | return 0; | ||
| 456 | } | ||
| 457 | |||
| 458 | static void | 333 | static void |
| 459 | trace_seq_reset(struct trace_seq *s) | 334 | trace_seq_reset(struct trace_seq *s) |
| 460 | { | 335 | { |
| @@ -1472,154 +1347,6 @@ static void s_stop(struct seq_file *m, void *p) | |||
| 1472 | mutex_unlock(&trace_types_lock); | 1347 | mutex_unlock(&trace_types_lock); |
| 1473 | } | 1348 | } |
| 1474 | 1349 | ||
| 1475 | #ifdef CONFIG_KRETPROBES | ||
| 1476 | static inline const char *kretprobed(const char *name) | ||
| 1477 | { | ||
| 1478 | static const char tramp_name[] = "kretprobe_trampoline"; | ||
| 1479 | int size = sizeof(tramp_name); | ||
| 1480 | |||
| 1481 | if (strncmp(tramp_name, name, size) == 0) | ||
| 1482 | return "[unknown/kretprobe'd]"; | ||
| 1483 | return name; | ||
| 1484 | } | ||
| 1485 | #else | ||
| 1486 | static inline const char *kretprobed(const char *name) | ||
| 1487 | { | ||
| 1488 | return name; | ||
| 1489 | } | ||
| 1490 | #endif /* CONFIG_KRETPROBES */ | ||
| 1491 | |||
| 1492 | static int | ||
| 1493 | seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address) | ||
| 1494 | { | ||
| 1495 | #ifdef CONFIG_KALLSYMS | ||
| 1496 | char str[KSYM_SYMBOL_LEN]; | ||
| 1497 | const char *name; | ||
| 1498 | |||
| 1499 | kallsyms_lookup(address, NULL, NULL, NULL, str); | ||
| 1500 | |||
| 1501 | name = kretprobed(str); | ||
| 1502 | |||
| 1503 | return trace_seq_printf(s, fmt, name); | ||
| 1504 | #endif | ||
| 1505 | return 1; | ||
| 1506 | } | ||
| 1507 | |||
| 1508 | static int | ||
| 1509 | seq_print_sym_offset(struct trace_seq *s, const char *fmt, | ||
| 1510 | unsigned long address) | ||
| 1511 | { | ||
| 1512 | #ifdef CONFIG_KALLSYMS | ||
| 1513 | char str[KSYM_SYMBOL_LEN]; | ||
| 1514 | const char *name; | ||
| 1515 | |||
| 1516 | sprint_symbol(str, address); | ||
| 1517 | name = kretprobed(str); | ||
| 1518 | |||
| 1519 | return trace_seq_printf(s, fmt, name); | ||
| 1520 | #endif | ||
| 1521 | return 1; | ||
| 1522 | } | ||
| 1523 | |||
| 1524 | #ifndef CONFIG_64BIT | ||
| 1525 | # define IP_FMT "%08lx" | ||
| 1526 | #else | ||
| 1527 | # define IP_FMT "%016lx" | ||
| 1528 | #endif | ||
| 1529 | |||
| 1530 | int | ||
| 1531 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) | ||
| 1532 | { | ||
| 1533 | int ret; | ||
| 1534 | |||
| 1535 | if (!ip) | ||
| 1536 | return trace_seq_printf(s, "0"); | ||
| 1537 | |||
| 1538 | if (sym_flags & TRACE_ITER_SYM_OFFSET) | ||
| 1539 | ret = seq_print_sym_offset(s, "%s", ip); | ||
| 1540 | else | ||
| 1541 | ret = seq_print_sym_short(s, "%s", ip); | ||
| 1542 | |||
| 1543 | if (!ret) | ||
| 1544 | return 0; | ||
| 1545 | |||
| 1546 | if (sym_flags & TRACE_ITER_SYM_ADDR) | ||
| 1547 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); | ||
| 1548 | return ret; | ||
| 1549 | } | ||
| 1550 | |||
| 1551 | static inline int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, | ||
| 1552 | unsigned long ip, unsigned long sym_flags) | ||
| 1553 | { | ||
| 1554 | struct file *file = NULL; | ||
| 1555 | unsigned long vmstart = 0; | ||
| 1556 | int ret = 1; | ||
| 1557 | |||
| 1558 | if (mm) { | ||
| 1559 | const struct vm_area_struct *vma; | ||
| 1560 | |||
| 1561 | down_read(&mm->mmap_sem); | ||
| 1562 | vma = find_vma(mm, ip); | ||
| 1563 | if (vma) { | ||
| 1564 | file = vma->vm_file; | ||
| 1565 | vmstart = vma->vm_start; | ||
| 1566 | } | ||
| 1567 | if (file) { | ||
| 1568 | ret = trace_seq_path(s, &file->f_path); | ||
| 1569 | if (ret) | ||
| 1570 | ret = trace_seq_printf(s, "[+0x%lx]", ip - vmstart); | ||
| 1571 | } | ||
| 1572 | up_read(&mm->mmap_sem); | ||
| 1573 | } | ||
| 1574 | if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file)) | ||
| 1575 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); | ||
| 1576 | return ret; | ||
| 1577 | } | ||
| 1578 | |||
| 1579 | static int | ||
| 1580 | seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s, | ||
| 1581 | unsigned long sym_flags) | ||
| 1582 | { | ||
| 1583 | struct mm_struct *mm = NULL; | ||
| 1584 | int ret = 1; | ||
| 1585 | unsigned int i; | ||
| 1586 | |||
| 1587 | if (trace_flags & TRACE_ITER_SYM_USEROBJ) { | ||
| 1588 | struct task_struct *task; | ||
| 1589 | /* | ||
| 1590 | * we do the lookup on the thread group leader, | ||
| 1591 | * since individual threads might have already quit! | ||
| 1592 | */ | ||
| 1593 | rcu_read_lock(); | ||
| 1594 | task = find_task_by_vpid(entry->ent.tgid); | ||
| 1595 | if (task) | ||
| 1596 | mm = get_task_mm(task); | ||
| 1597 | rcu_read_unlock(); | ||
| 1598 | } | ||
| 1599 | |||
| 1600 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | ||
| 1601 | unsigned long ip = entry->caller[i]; | ||
| 1602 | |||
| 1603 | if (ip == ULONG_MAX || !ret) | ||
| 1604 | break; | ||
| 1605 | if (i && ret) | ||
| 1606 | ret = trace_seq_puts(s, " <- "); | ||
| 1607 | if (!ip) { | ||
| 1608 | if (ret) | ||
| 1609 | ret = trace_seq_puts(s, "??"); | ||
| 1610 | continue; | ||
| 1611 | } | ||
| 1612 | if (!ret) | ||
| 1613 | break; | ||
| 1614 | if (ret) | ||
| 1615 | ret = seq_print_user_ip(s, mm, ip, sym_flags); | ||
| 1616 | } | ||
| 1617 | |||
| 1618 | if (mm) | ||
| 1619 | mmput(mm); | ||
| 1620 | return ret; | ||
| 1621 | } | ||
| 1622 | |||
| 1623 | static void print_lat_help_header(struct seq_file *m) | 1350 | static void print_lat_help_header(struct seq_file *m) |
| 1624 | { | 1351 | { |
| 1625 | seq_puts(m, "# _------=> CPU# \n"); | 1352 | seq_puts(m, "# _------=> CPU# \n"); |
| @@ -1755,52 +1482,6 @@ lat_print_timestamp(struct trace_seq *s, u64 abs_usecs, | |||
| 1755 | trace_seq_puts(s, " : "); | 1482 | trace_seq_puts(s, " : "); |
| 1756 | } | 1483 | } |
| 1757 | 1484 | ||
| 1758 | static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; | ||
| 1759 | |||
| 1760 | static int task_state_char(unsigned long state) | ||
| 1761 | { | ||
| 1762 | int bit = state ? __ffs(state) + 1 : 0; | ||
| 1763 | |||
| 1764 | return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; | ||
| 1765 | } | ||
| 1766 | |||
| 1767 | /* | ||
| 1768 | * The message is supposed to contain an ending newline. | ||
| 1769 | * If the printing stops prematurely, try to add a newline of our own. | ||
| 1770 | */ | ||
| 1771 | void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter) | ||
| 1772 | { | ||
| 1773 | struct trace_entry *ent; | ||
| 1774 | struct trace_field_cont *cont; | ||
| 1775 | bool ok = true; | ||
| 1776 | |||
| 1777 | ent = peek_next_entry(iter, iter->cpu, NULL); | ||
| 1778 | if (!ent || ent->type != TRACE_CONT) { | ||
| 1779 | trace_seq_putc(s, '\n'); | ||
| 1780 | return; | ||
| 1781 | } | ||
| 1782 | |||
| 1783 | do { | ||
| 1784 | cont = (struct trace_field_cont *)ent; | ||
| 1785 | if (ok) | ||
| 1786 | ok = (trace_seq_printf(s, "%s", cont->buf) > 0); | ||
| 1787 | |||
| 1788 | ftrace_disable_cpu(); | ||
| 1789 | |||
| 1790 | if (iter->buffer_iter[iter->cpu]) | ||
| 1791 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); | ||
| 1792 | else | ||
| 1793 | ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL); | ||
| 1794 | |||
| 1795 | ftrace_enable_cpu(); | ||
| 1796 | |||
| 1797 | ent = peek_next_entry(iter, iter->cpu, NULL); | ||
| 1798 | } while (ent && ent->type == TRACE_CONT); | ||
| 1799 | |||
| 1800 | if (!ok) | ||
| 1801 | trace_seq_putc(s, '\n'); | ||
| 1802 | } | ||
| 1803 | |||
| 1804 | static void test_cpu_buff_start(struct trace_iterator *iter) | 1485 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 1805 | { | 1486 | { |
| 1806 | struct trace_seq *s = &iter->seq; | 1487 | struct trace_seq *s = &iter->seq; |
| @@ -1824,17 +1505,14 @@ print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu) | |||
| 1824 | struct trace_seq *s = &iter->seq; | 1505 | struct trace_seq *s = &iter->seq; |
| 1825 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | 1506 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
| 1826 | struct trace_entry *next_entry; | 1507 | struct trace_entry *next_entry; |
| 1508 | struct trace_event *event; | ||
| 1827 | unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); | 1509 | unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); |
| 1828 | struct trace_entry *entry = iter->ent; | 1510 | struct trace_entry *entry = iter->ent; |
| 1829 | unsigned long abs_usecs; | 1511 | unsigned long abs_usecs; |
| 1830 | unsigned long rel_usecs; | 1512 | unsigned long rel_usecs; |
| 1831 | u64 next_ts; | 1513 | u64 next_ts; |
| 1832 | char *comm; | 1514 | char *comm; |
| 1833 | int S, T; | 1515 | int ret; |
| 1834 | int i; | ||
| 1835 | |||
| 1836 | if (entry->type == TRACE_CONT) | ||
| 1837 | return TRACE_TYPE_HANDLED; | ||
| 1838 | 1516 | ||
| 1839 | test_cpu_buff_start(iter); | 1517 | test_cpu_buff_start(iter); |
| 1840 | 1518 | ||
| @@ -1859,96 +1537,16 @@ print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu) | |||
| 1859 | lat_print_generic(s, entry, cpu); | 1537 | lat_print_generic(s, entry, cpu); |
| 1860 | lat_print_timestamp(s, abs_usecs, rel_usecs); | 1538 | lat_print_timestamp(s, abs_usecs, rel_usecs); |
| 1861 | } | 1539 | } |
| 1862 | switch (entry->type) { | ||
| 1863 | case TRACE_FN: { | ||
| 1864 | struct ftrace_entry *field; | ||
| 1865 | |||
| 1866 | trace_assign_type(field, entry); | ||
| 1867 | |||
| 1868 | seq_print_ip_sym(s, field->ip, sym_flags); | ||
| 1869 | trace_seq_puts(s, " ("); | ||
| 1870 | seq_print_ip_sym(s, field->parent_ip, sym_flags); | ||
| 1871 | trace_seq_puts(s, ")\n"); | ||
| 1872 | break; | ||
| 1873 | } | ||
| 1874 | case TRACE_CTX: | ||
| 1875 | case TRACE_WAKE: { | ||
| 1876 | struct ctx_switch_entry *field; | ||
| 1877 | |||
| 1878 | trace_assign_type(field, entry); | ||
| 1879 | |||
| 1880 | T = task_state_char(field->next_state); | ||
| 1881 | S = task_state_char(field->prev_state); | ||
| 1882 | comm = trace_find_cmdline(field->next_pid); | ||
| 1883 | trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n", | ||
| 1884 | field->prev_pid, | ||
| 1885 | field->prev_prio, | ||
| 1886 | S, entry->type == TRACE_CTX ? "==>" : " +", | ||
| 1887 | field->next_cpu, | ||
| 1888 | field->next_pid, | ||
| 1889 | field->next_prio, | ||
| 1890 | T, comm); | ||
| 1891 | break; | ||
| 1892 | } | ||
| 1893 | case TRACE_SPECIAL: { | ||
| 1894 | struct special_entry *field; | ||
| 1895 | |||
| 1896 | trace_assign_type(field, entry); | ||
| 1897 | |||
| 1898 | trace_seq_printf(s, "# %ld %ld %ld\n", | ||
| 1899 | field->arg1, | ||
| 1900 | field->arg2, | ||
| 1901 | field->arg3); | ||
| 1902 | break; | ||
| 1903 | } | ||
| 1904 | case TRACE_STACK: { | ||
| 1905 | struct stack_entry *field; | ||
| 1906 | |||
| 1907 | trace_assign_type(field, entry); | ||
| 1908 | |||
| 1909 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | ||
| 1910 | if (i) | ||
| 1911 | trace_seq_puts(s, " <= "); | ||
| 1912 | seq_print_ip_sym(s, field->caller[i], sym_flags); | ||
| 1913 | } | ||
| 1914 | trace_seq_puts(s, "\n"); | ||
| 1915 | break; | ||
| 1916 | } | ||
| 1917 | case TRACE_PRINT: { | ||
| 1918 | struct print_entry *field; | ||
| 1919 | |||
| 1920 | trace_assign_type(field, entry); | ||
| 1921 | 1540 | ||
| 1922 | seq_print_ip_sym(s, field->ip, sym_flags); | 1541 | event = ftrace_find_event(entry->type); |
| 1923 | trace_seq_printf(s, ": %s", field->buf); | 1542 | if (event && event->latency_trace) { |
| 1924 | if (entry->flags & TRACE_FLAG_CONT) | 1543 | ret = event->latency_trace(s, entry, sym_flags); |
| 1925 | trace_seq_print_cont(s, iter); | 1544 | if (ret) |
| 1926 | break; | 1545 | return ret; |
| 1927 | } | 1546 | return TRACE_TYPE_HANDLED; |
| 1928 | case TRACE_BRANCH: { | ||
| 1929 | struct trace_branch *field; | ||
| 1930 | |||
| 1931 | trace_assign_type(field, entry); | ||
| 1932 | |||
| 1933 | trace_seq_printf(s, "[%s] %s:%s:%d\n", | ||
| 1934 | field->correct ? " ok " : " MISS ", | ||
| 1935 | field->func, | ||
| 1936 | field->file, | ||
| 1937 | field->line); | ||
| 1938 | break; | ||
| 1939 | } | 1547 | } |
| 1940 | case TRACE_USER_STACK: { | ||
| 1941 | struct userstack_entry *field; | ||
| 1942 | |||
| 1943 | trace_assign_type(field, entry); | ||
| 1944 | 1548 | ||
| 1945 | seq_print_userip_objs(field, s, sym_flags); | 1549 | trace_seq_printf(s, "Unknown type %d\n", entry->type); |
| 1946 | trace_seq_putc(s, '\n'); | ||
| 1947 | break; | ||
| 1948 | } | ||
| 1949 | default: | ||
| 1950 | trace_seq_printf(s, "Unknown type %d\n", entry->type); | ||
| 1951 | } | ||
| 1952 | return TRACE_TYPE_HANDLED; | 1550 | return TRACE_TYPE_HANDLED; |
| 1953 | } | 1551 | } |
| 1954 | 1552 | ||
| @@ -1957,19 +1555,15 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter) | |||
| 1957 | struct trace_seq *s = &iter->seq; | 1555 | struct trace_seq *s = &iter->seq; |
| 1958 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | 1556 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
| 1959 | struct trace_entry *entry; | 1557 | struct trace_entry *entry; |
| 1558 | struct trace_event *event; | ||
| 1960 | unsigned long usec_rem; | 1559 | unsigned long usec_rem; |
| 1961 | unsigned long long t; | 1560 | unsigned long long t; |
| 1962 | unsigned long secs; | 1561 | unsigned long secs; |
| 1963 | char *comm; | 1562 | char *comm; |
| 1964 | int ret; | 1563 | int ret; |
| 1965 | int S, T; | ||
| 1966 | int i; | ||
| 1967 | 1564 | ||
| 1968 | entry = iter->ent; | 1565 | entry = iter->ent; |
| 1969 | 1566 | ||
| 1970 | if (entry->type == TRACE_CONT) | ||
| 1971 | return TRACE_TYPE_HANDLED; | ||
| 1972 | |||
| 1973 | test_cpu_buff_start(iter); | 1567 | test_cpu_buff_start(iter); |
| 1974 | 1568 | ||
| 1975 | comm = trace_find_cmdline(iter->ent->pid); | 1569 | comm = trace_find_cmdline(iter->ent->pid); |
| @@ -1988,129 +1582,17 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter) | |||
| 1988 | if (!ret) | 1582 | if (!ret) |
| 1989 | return TRACE_TYPE_PARTIAL_LINE; | 1583 | return TRACE_TYPE_PARTIAL_LINE; |
| 1990 | 1584 | ||
| 1991 | switch (entry->type) { | 1585 | event = ftrace_find_event(entry->type); |
| 1992 | case TRACE_FN: { | 1586 | if (event && event->trace) { |
| 1993 | struct ftrace_entry *field; | 1587 | ret = event->trace(s, entry, sym_flags); |
| 1994 | 1588 | if (ret) | |
| 1995 | trace_assign_type(field, entry); | 1589 | return ret; |
| 1996 | 1590 | return TRACE_TYPE_HANDLED; | |
| 1997 | ret = seq_print_ip_sym(s, field->ip, sym_flags); | ||
| 1998 | if (!ret) | ||
| 1999 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2000 | if ((sym_flags & TRACE_ITER_PRINT_PARENT) && | ||
| 2001 | field->parent_ip) { | ||
| 2002 | ret = trace_seq_printf(s, " <-"); | ||
| 2003 | if (!ret) | ||
| 2004 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2005 | ret = seq_print_ip_sym(s, | ||
| 2006 | field->parent_ip, | ||
| 2007 | sym_flags); | ||
| 2008 | if (!ret) | ||
| 2009 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2010 | } | ||
| 2011 | ret = trace_seq_printf(s, "\n"); | ||
| 2012 | if (!ret) | ||
| 2013 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2014 | break; | ||
| 2015 | } | ||
| 2016 | case TRACE_CTX: | ||
| 2017 | case TRACE_WAKE: { | ||
| 2018 | struct ctx_switch_entry *field; | ||
| 2019 | |||
| 2020 | trace_assign_type(field, entry); | ||
| 2021 | |||
| 2022 | T = task_state_char(field->next_state); | ||
| 2023 | S = task_state_char(field->prev_state); | ||
| 2024 | ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n", | ||
| 2025 | field->prev_pid, | ||
| 2026 | field->prev_prio, | ||
| 2027 | S, | ||
| 2028 | entry->type == TRACE_CTX ? "==>" : " +", | ||
| 2029 | field->next_cpu, | ||
| 2030 | field->next_pid, | ||
| 2031 | field->next_prio, | ||
| 2032 | T); | ||
| 2033 | if (!ret) | ||
| 2034 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2035 | break; | ||
| 2036 | } | ||
| 2037 | case TRACE_SPECIAL: { | ||
| 2038 | struct special_entry *field; | ||
| 2039 | |||
| 2040 | trace_assign_type(field, entry); | ||
| 2041 | |||
| 2042 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", | ||
| 2043 | field->arg1, | ||
| 2044 | field->arg2, | ||
| 2045 | field->arg3); | ||
| 2046 | if (!ret) | ||
| 2047 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2048 | break; | ||
| 2049 | } | ||
| 2050 | case TRACE_STACK: { | ||
| 2051 | struct stack_entry *field; | ||
| 2052 | |||
| 2053 | trace_assign_type(field, entry); | ||
| 2054 | |||
| 2055 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | ||
| 2056 | if (i) { | ||
| 2057 | ret = trace_seq_puts(s, " <= "); | ||
| 2058 | if (!ret) | ||
| 2059 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2060 | } | ||
| 2061 | ret = seq_print_ip_sym(s, field->caller[i], | ||
| 2062 | sym_flags); | ||
| 2063 | if (!ret) | ||
| 2064 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2065 | } | ||
| 2066 | ret = trace_seq_puts(s, "\n"); | ||
| 2067 | if (!ret) | ||
| 2068 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2069 | break; | ||
| 2070 | } | ||
| 2071 | case TRACE_PRINT: { | ||
| 2072 | struct print_entry *field; | ||
| 2073 | |||
| 2074 | trace_assign_type(field, entry); | ||
| 2075 | |||
| 2076 | seq_print_ip_sym(s, field->ip, sym_flags); | ||
| 2077 | trace_seq_printf(s, ": %s", field->buf); | ||
| 2078 | if (entry->flags & TRACE_FLAG_CONT) | ||
| 2079 | trace_seq_print_cont(s, iter); | ||
| 2080 | break; | ||
| 2081 | } | ||
| 2082 | case TRACE_GRAPH_RET: { | ||
| 2083 | return print_graph_function(iter); | ||
| 2084 | } | ||
| 2085 | case TRACE_GRAPH_ENT: { | ||
| 2086 | return print_graph_function(iter); | ||
| 2087 | } | ||
| 2088 | case TRACE_BRANCH: { | ||
| 2089 | struct trace_branch *field; | ||
| 2090 | |||
| 2091 | trace_assign_type(field, entry); | ||
| 2092 | |||
| 2093 | trace_seq_printf(s, "[%s] %s:%s:%d\n", | ||
| 2094 | field->correct ? " ok " : " MISS ", | ||
| 2095 | field->func, | ||
| 2096 | field->file, | ||
| 2097 | field->line); | ||
| 2098 | break; | ||
| 2099 | } | 1591 | } |
| 2100 | case TRACE_USER_STACK: { | 1592 | ret = trace_seq_printf(s, "Unknown type %d\n", entry->type); |
| 2101 | struct userstack_entry *field; | 1593 | if (!ret) |
| 2102 | 1594 | return TRACE_TYPE_PARTIAL_LINE; | |
| 2103 | trace_assign_type(field, entry); | ||
| 2104 | 1595 | ||
| 2105 | ret = seq_print_userip_objs(field, s, sym_flags); | ||
| 2106 | if (!ret) | ||
| 2107 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2108 | ret = trace_seq_putc(s, '\n'); | ||
| 2109 | if (!ret) | ||
| 2110 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2111 | break; | ||
| 2112 | } | ||
| 2113 | } | ||
| 2114 | return TRACE_TYPE_HANDLED; | 1596 | return TRACE_TYPE_HANDLED; |
| 2115 | } | 1597 | } |
| 2116 | 1598 | ||
| @@ -2118,152 +1600,47 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter) | |||
| 2118 | { | 1600 | { |
| 2119 | struct trace_seq *s = &iter->seq; | 1601 | struct trace_seq *s = &iter->seq; |
| 2120 | struct trace_entry *entry; | 1602 | struct trace_entry *entry; |
| 1603 | struct trace_event *event; | ||
| 2121 | int ret; | 1604 | int ret; |
| 2122 | int S, T; | ||
| 2123 | 1605 | ||
| 2124 | entry = iter->ent; | 1606 | entry = iter->ent; |
| 2125 | 1607 | ||
| 2126 | if (entry->type == TRACE_CONT) | ||
| 2127 | return TRACE_TYPE_HANDLED; | ||
| 2128 | |||
| 2129 | ret = trace_seq_printf(s, "%d %d %llu ", | 1608 | ret = trace_seq_printf(s, "%d %d %llu ", |
| 2130 | entry->pid, iter->cpu, iter->ts); | 1609 | entry->pid, iter->cpu, iter->ts); |
| 2131 | if (!ret) | 1610 | if (!ret) |
| 2132 | return TRACE_TYPE_PARTIAL_LINE; | 1611 | return TRACE_TYPE_PARTIAL_LINE; |
| 2133 | 1612 | ||
| 2134 | switch (entry->type) { | 1613 | event = ftrace_find_event(entry->type); |
| 2135 | case TRACE_FN: { | 1614 | if (event && event->raw) { |
| 2136 | struct ftrace_entry *field; | 1615 | ret = event->raw(s, entry, 0); |
| 2137 | 1616 | if (ret) | |
| 2138 | trace_assign_type(field, entry); | 1617 | return ret; |
| 2139 | 1618 | return TRACE_TYPE_HANDLED; | |
| 2140 | ret = trace_seq_printf(s, "%x %x\n", | ||
| 2141 | field->ip, | ||
| 2142 | field->parent_ip); | ||
| 2143 | if (!ret) | ||
| 2144 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2145 | break; | ||
| 2146 | } | ||
| 2147 | case TRACE_CTX: | ||
| 2148 | case TRACE_WAKE: { | ||
| 2149 | struct ctx_switch_entry *field; | ||
| 2150 | |||
| 2151 | trace_assign_type(field, entry); | ||
| 2152 | |||
| 2153 | T = task_state_char(field->next_state); | ||
| 2154 | S = entry->type == TRACE_WAKE ? '+' : | ||
| 2155 | task_state_char(field->prev_state); | ||
| 2156 | ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n", | ||
| 2157 | field->prev_pid, | ||
| 2158 | field->prev_prio, | ||
| 2159 | S, | ||
| 2160 | field->next_cpu, | ||
| 2161 | field->next_pid, | ||
| 2162 | field->next_prio, | ||
| 2163 | T); | ||
| 2164 | if (!ret) | ||
| 2165 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2166 | break; | ||
| 2167 | } | ||
| 2168 | case TRACE_SPECIAL: | ||
| 2169 | case TRACE_USER_STACK: | ||
| 2170 | case TRACE_STACK: { | ||
| 2171 | struct special_entry *field; | ||
| 2172 | |||
| 2173 | trace_assign_type(field, entry); | ||
| 2174 | |||
| 2175 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", | ||
| 2176 | field->arg1, | ||
| 2177 | field->arg2, | ||
| 2178 | field->arg3); | ||
| 2179 | if (!ret) | ||
| 2180 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 2181 | break; | ||
| 2182 | } | 1619 | } |
| 2183 | case TRACE_PRINT: { | 1620 | ret = trace_seq_printf(s, "%d ?\n", entry->type); |
| 2184 | struct print_entry *field; | 1621 | if (!ret) |
| 2185 | 1622 | return TRACE_TYPE_PARTIAL_LINE; | |
| 2186 | trace_assign_type(field, entry); | ||
| 2187 | 1623 | ||
| 2188 | trace_seq_printf(s, "# %lx %s", field->ip, field->buf); | ||
| 2189 | if (entry->flags & TRACE_FLAG_CONT) | ||
| 2190 | trace_seq_print_cont(s, iter); | ||
| 2191 | break; | ||
| 2192 | } | ||
| 2193 | } | ||
| 2194 | return TRACE_TYPE_HANDLED; | 1624 | return TRACE_TYPE_HANDLED; |
| 2195 | } | 1625 | } |
| 2196 | 1626 | ||
| 2197 | #define SEQ_PUT_FIELD_RET(s, x) \ | ||
| 2198 | do { \ | ||
| 2199 | if (!trace_seq_putmem(s, &(x), sizeof(x))) \ | ||
| 2200 | return 0; \ | ||
| 2201 | } while (0) | ||
| 2202 | |||
| 2203 | #define SEQ_PUT_HEX_FIELD_RET(s, x) \ | ||
| 2204 | do { \ | ||
| 2205 | BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \ | ||
| 2206 | if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \ | ||
| 2207 | return 0; \ | ||
| 2208 | } while (0) | ||
| 2209 | |||
| 2210 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) | 1627 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
| 2211 | { | 1628 | { |
| 2212 | struct trace_seq *s = &iter->seq; | 1629 | struct trace_seq *s = &iter->seq; |
| 2213 | unsigned char newline = '\n'; | 1630 | unsigned char newline = '\n'; |
| 2214 | struct trace_entry *entry; | 1631 | struct trace_entry *entry; |
| 2215 | int S, T; | 1632 | struct trace_event *event; |
| 2216 | 1633 | ||
| 2217 | entry = iter->ent; | 1634 | entry = iter->ent; |
| 2218 | 1635 | ||
| 2219 | if (entry->type == TRACE_CONT) | ||
| 2220 | return TRACE_TYPE_HANDLED; | ||
| 2221 | |||
| 2222 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); | 1636 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
| 2223 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); | 1637 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
| 2224 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); | 1638 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
| 2225 | 1639 | ||
| 2226 | switch (entry->type) { | 1640 | event = ftrace_find_event(entry->type); |
| 2227 | case TRACE_FN: { | 1641 | if (event && event->hex) |
| 2228 | struct ftrace_entry *field; | 1642 | event->hex(s, entry, 0); |
| 2229 | 1643 | ||
| 2230 | trace_assign_type(field, entry); | ||
| 2231 | |||
| 2232 | SEQ_PUT_HEX_FIELD_RET(s, field->ip); | ||
| 2233 | SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip); | ||
| 2234 | break; | ||
| 2235 | } | ||
| 2236 | case TRACE_CTX: | ||
| 2237 | case TRACE_WAKE: { | ||
| 2238 | struct ctx_switch_entry *field; | ||
| 2239 | |||
| 2240 | trace_assign_type(field, entry); | ||
| 2241 | |||
| 2242 | T = task_state_char(field->next_state); | ||
| 2243 | S = entry->type == TRACE_WAKE ? '+' : | ||
| 2244 | task_state_char(field->prev_state); | ||
| 2245 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid); | ||
| 2246 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio); | ||
| 2247 | SEQ_PUT_HEX_FIELD_RET(s, S); | ||
| 2248 | SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu); | ||
| 2249 | SEQ_PUT_HEX_FIELD_RET(s, field->next_pid); | ||
| 2250 | SEQ_PUT_HEX_FIELD_RET(s, field->next_prio); | ||
| 2251 | SEQ_PUT_HEX_FIELD_RET(s, T); | ||
| 2252 | break; | ||
| 2253 | } | ||
| 2254 | case TRACE_SPECIAL: | ||
| 2255 | case TRACE_USER_STACK: | ||
| 2256 | case TRACE_STACK: { | ||
| 2257 | struct special_entry *field; | ||
| 2258 | |||
| 2259 | trace_assign_type(field, entry); | ||
| 2260 | |||
| 2261 | SEQ_PUT_HEX_FIELD_RET(s, field->arg1); | ||
| 2262 | SEQ_PUT_HEX_FIELD_RET(s, field->arg2); | ||
| 2263 | SEQ_PUT_HEX_FIELD_RET(s, field->arg3); | ||
| 2264 | break; | ||
| 2265 | } | ||
| 2266 | } | ||
| 2267 | SEQ_PUT_FIELD_RET(s, newline); | 1644 | SEQ_PUT_FIELD_RET(s, newline); |
| 2268 | 1645 | ||
| 2269 | return TRACE_TYPE_HANDLED; | 1646 | return TRACE_TYPE_HANDLED; |
| @@ -2282,9 +1659,6 @@ static enum print_line_t print_printk_msg_only(struct trace_iterator *iter) | |||
| 2282 | if (!ret) | 1659 | if (!ret) |
| 2283 | return TRACE_TYPE_PARTIAL_LINE; | 1660 | return TRACE_TYPE_PARTIAL_LINE; |
| 2284 | 1661 | ||
| 2285 | if (entry->flags & TRACE_FLAG_CONT) | ||
| 2286 | trace_seq_print_cont(s, iter); | ||
| 2287 | |||
| 2288 | return TRACE_TYPE_HANDLED; | 1662 | return TRACE_TYPE_HANDLED; |
| 2289 | } | 1663 | } |
| 2290 | 1664 | ||
| @@ -2292,53 +1666,19 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter) | |||
| 2292 | { | 1666 | { |
| 2293 | struct trace_seq *s = &iter->seq; | 1667 | struct trace_seq *s = &iter->seq; |
| 2294 | struct trace_entry *entry; | 1668 | struct trace_entry *entry; |
| 1669 | struct trace_event *event; | ||
| 2295 | 1670 | ||
| 2296 | entry = iter->ent; | 1671 | entry = iter->ent; |
| 2297 | 1672 | ||
| 2298 | if (entry->type == TRACE_CONT) | ||
| 2299 | return TRACE_TYPE_HANDLED; | ||
| 2300 | |||
| 2301 | SEQ_PUT_FIELD_RET(s, entry->pid); | 1673 | SEQ_PUT_FIELD_RET(s, entry->pid); |
| 2302 | SEQ_PUT_FIELD_RET(s, entry->cpu); | 1674 | SEQ_PUT_FIELD_RET(s, entry->cpu); |
| 2303 | SEQ_PUT_FIELD_RET(s, iter->ts); | 1675 | SEQ_PUT_FIELD_RET(s, iter->ts); |
| 2304 | 1676 | ||
| 2305 | switch (entry->type) { | 1677 | event = ftrace_find_event(entry->type); |
| 2306 | case TRACE_FN: { | 1678 | if (event && event->binary) |
| 2307 | struct ftrace_entry *field; | 1679 | event->binary(s, entry, 0); |
| 2308 | |||
| 2309 | trace_assign_type(field, entry); | ||
| 2310 | |||
| 2311 | SEQ_PUT_FIELD_RET(s, field->ip); | ||
| 2312 | SEQ_PUT_FIELD_RET(s, field->parent_ip); | ||
| 2313 | break; | ||
| 2314 | } | ||
| 2315 | case TRACE_CTX: { | ||
| 2316 | struct ctx_switch_entry *field; | ||
| 2317 | |||
| 2318 | trace_assign_type(field, entry); | ||
| 2319 | |||
| 2320 | SEQ_PUT_FIELD_RET(s, field->prev_pid); | ||
| 2321 | SEQ_PUT_FIELD_RET(s, field->prev_prio); | ||
| 2322 | SEQ_PUT_FIELD_RET(s, field->prev_state); | ||
| 2323 | SEQ_PUT_FIELD_RET(s, field->next_pid); | ||
| 2324 | SEQ_PUT_FIELD_RET(s, field->next_prio); | ||
| 2325 | SEQ_PUT_FIELD_RET(s, field->next_state); | ||
| 2326 | break; | ||
| 2327 | } | ||
| 2328 | case TRACE_SPECIAL: | ||
| 2329 | case TRACE_USER_STACK: | ||
| 2330 | case TRACE_STACK: { | ||
| 2331 | struct special_entry *field; | ||
| 2332 | |||
| 2333 | trace_assign_type(field, entry); | ||
| 2334 | 1680 | ||
| 2335 | SEQ_PUT_FIELD_RET(s, field->arg1); | 1681 | return TRACE_TYPE_HANDLED; |
| 2336 | SEQ_PUT_FIELD_RET(s, field->arg2); | ||
| 2337 | SEQ_PUT_FIELD_RET(s, field->arg3); | ||
| 2338 | break; | ||
| 2339 | } | ||
| 2340 | } | ||
| 2341 | return 1; | ||
| 2342 | } | 1682 | } |
| 2343 | 1683 | ||
| 2344 | static int trace_empty(struct trace_iterator *iter) | 1684 | static int trace_empty(struct trace_iterator *iter) |
| @@ -3013,6 +2353,7 @@ static int tracing_set_tracer(char *buf) | |||
| 3013 | if (ret) | 2353 | if (ret) |
| 3014 | goto out; | 2354 | goto out; |
| 3015 | } | 2355 | } |
| 2356 | init_tracer_stat(t); | ||
| 3016 | 2357 | ||
| 3017 | trace_branch_enable(tr); | 2358 | trace_branch_enable(tr); |
| 3018 | out: | 2359 | out: |
| @@ -3877,7 +3218,7 @@ __init static int tracer_alloc_buffers(void) | |||
| 3877 | #else | 3218 | #else |
| 3878 | current_trace = &nop_trace; | 3219 | current_trace = &nop_trace; |
| 3879 | #endif | 3220 | #endif |
| 3880 | 3221 | init_tracer_stat(current_trace); | |
| 3881 | /* All seems OK, enable tracing */ | 3222 | /* All seems OK, enable tracing */ |
| 3882 | tracing_disabled = 0; | 3223 | tracing_disabled = 0; |
| 3883 | 3224 | ||
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 742fe1349276..94ed45e93a80 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
| @@ -17,7 +17,6 @@ enum trace_type { | |||
| 17 | TRACE_FN, | 17 | TRACE_FN, |
| 18 | TRACE_CTX, | 18 | TRACE_CTX, |
| 19 | TRACE_WAKE, | 19 | TRACE_WAKE, |
| 20 | TRACE_CONT, | ||
| 21 | TRACE_STACK, | 20 | TRACE_STACK, |
| 22 | TRACE_PRINT, | 21 | TRACE_PRINT, |
| 23 | TRACE_SPECIAL, | 22 | TRACE_SPECIAL, |
| @@ -34,7 +33,7 @@ enum trace_type { | |||
| 34 | TRACE_KMEM_FREE, | 33 | TRACE_KMEM_FREE, |
| 35 | TRACE_POWER, | 34 | TRACE_POWER, |
| 36 | 35 | ||
| 37 | __TRACE_LAST_TYPE | 36 | __TRACE_LAST_TYPE, |
| 38 | }; | 37 | }; |
| 39 | 38 | ||
| 40 | /* | 39 | /* |
| @@ -199,7 +198,6 @@ struct kmemtrace_free_entry { | |||
| 199 | * NEED_RESCED - reschedule is requested | 198 | * NEED_RESCED - reschedule is requested |
| 200 | * HARDIRQ - inside an interrupt handler | 199 | * HARDIRQ - inside an interrupt handler |
| 201 | * SOFTIRQ - inside a softirq handler | 200 | * SOFTIRQ - inside a softirq handler |
| 202 | * CONT - multiple entries hold the trace item | ||
| 203 | */ | 201 | */ |
| 204 | enum trace_flag_type { | 202 | enum trace_flag_type { |
| 205 | TRACE_FLAG_IRQS_OFF = 0x01, | 203 | TRACE_FLAG_IRQS_OFF = 0x01, |
| @@ -207,7 +205,6 @@ enum trace_flag_type { | |||
| 207 | TRACE_FLAG_NEED_RESCHED = 0x04, | 205 | TRACE_FLAG_NEED_RESCHED = 0x04, |
| 208 | TRACE_FLAG_HARDIRQ = 0x08, | 206 | TRACE_FLAG_HARDIRQ = 0x08, |
| 209 | TRACE_FLAG_SOFTIRQ = 0x10, | 207 | TRACE_FLAG_SOFTIRQ = 0x10, |
| 210 | TRACE_FLAG_CONT = 0x20, | ||
| 211 | }; | 208 | }; |
| 212 | 209 | ||
| 213 | #define TRACE_BUF_SIZE 1024 | 210 | #define TRACE_BUF_SIZE 1024 |
| @@ -283,7 +280,6 @@ extern void __ftrace_bad_type(void); | |||
| 283 | do { \ | 280 | do { \ |
| 284 | IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \ | 281 | IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \ |
| 285 | IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \ | 282 | IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \ |
| 286 | IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \ | ||
| 287 | IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \ | 283 | IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \ |
| 288 | IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\ | 284 | IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\ |
| 289 | IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \ | 285 | IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \ |
| @@ -365,6 +361,21 @@ struct tracer { | |||
| 365 | struct tracer *next; | 361 | struct tracer *next; |
| 366 | int print_max; | 362 | int print_max; |
| 367 | struct tracer_flags *flags; | 363 | struct tracer_flags *flags; |
| 364 | |||
| 365 | /* | ||
| 366 | * If you change one of the following on tracing runtime, recall | ||
| 367 | * init_tracer_stat() | ||
| 368 | */ | ||
| 369 | |||
| 370 | /* Iteration over statistic entries */ | ||
| 371 | void *(*stat_start)(void); | ||
| 372 | void *(*stat_next)(void *prev, int idx); | ||
| 373 | /* Compare two entries for sorting (optional) for stats */ | ||
| 374 | int (*stat_cmp)(void *p1, void *p2); | ||
| 375 | /* Print a stat entry */ | ||
| 376 | int (*stat_show)(struct seq_file *s, void *p); | ||
| 377 | /* Print the headers of your stat entries */ | ||
| 378 | int (*stat_headers)(struct seq_file *s); | ||
| 368 | }; | 379 | }; |
| 369 | 380 | ||
| 370 | struct trace_seq { | 381 | struct trace_seq { |
| @@ -450,6 +461,8 @@ void tracing_start_sched_switch_record(void); | |||
| 450 | int register_tracer(struct tracer *type); | 461 | int register_tracer(struct tracer *type); |
| 451 | void unregister_tracer(struct tracer *type); | 462 | void unregister_tracer(struct tracer *type); |
| 452 | 463 | ||
| 464 | void init_tracer_stat(struct tracer *trace); | ||
| 465 | |||
| 453 | extern unsigned long nsecs_to_usecs(unsigned long nsecs); | 466 | extern unsigned long nsecs_to_usecs(unsigned long nsecs); |
| 454 | 467 | ||
| 455 | extern unsigned long tracing_max_latency; | 468 | extern unsigned long tracing_max_latency; |
| @@ -481,10 +494,10 @@ struct tracer_switch_ops { | |||
| 481 | void *private; | 494 | void *private; |
| 482 | struct tracer_switch_ops *next; | 495 | struct tracer_switch_ops *next; |
| 483 | }; | 496 | }; |
| 484 | |||
| 485 | char *trace_find_cmdline(int pid); | ||
| 486 | #endif /* CONFIG_CONTEXT_SWITCH_TRACER */ | 497 | #endif /* CONFIG_CONTEXT_SWITCH_TRACER */ |
| 487 | 498 | ||
| 499 | extern char *trace_find_cmdline(int pid); | ||
| 500 | |||
| 488 | #ifdef CONFIG_DYNAMIC_FTRACE | 501 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 489 | extern unsigned long ftrace_update_tot_cnt; | 502 | extern unsigned long ftrace_update_tot_cnt; |
| 490 | #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func | 503 | #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func |
| @@ -513,15 +526,6 @@ extern int trace_selftest_startup_branch(struct tracer *trace, | |||
| 513 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ | 526 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
| 514 | 527 | ||
| 515 | extern void *head_page(struct trace_array_cpu *data); | 528 | extern void *head_page(struct trace_array_cpu *data); |
| 516 | extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...); | ||
| 517 | extern void trace_seq_print_cont(struct trace_seq *s, | ||
| 518 | struct trace_iterator *iter); | ||
| 519 | |||
| 520 | extern int | ||
| 521 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, | ||
| 522 | unsigned long sym_flags); | ||
| 523 | extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, | ||
| 524 | size_t cnt); | ||
| 525 | extern long ns2usecs(cycle_t nsec); | 529 | extern long ns2usecs(cycle_t nsec); |
| 526 | extern int | 530 | extern int |
| 527 | trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args); | 531 | trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args); |
diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c index 366c8c333e13..0e94b3d091f7 100644 --- a/kernel/trace/trace_boot.c +++ b/kernel/trace/trace_boot.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <linux/kallsyms.h> | 11 | #include <linux/kallsyms.h> |
| 12 | 12 | ||
| 13 | #include "trace.h" | 13 | #include "trace.h" |
| 14 | #include "trace_output.h" | ||
| 14 | 15 | ||
| 15 | static struct trace_array *boot_trace; | 16 | static struct trace_array *boot_trace; |
| 16 | static bool pre_initcalls_finished; | 17 | static bool pre_initcalls_finished; |
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c index 6c00feb3bac7..4785a3b9bc4a 100644 --- a/kernel/trace/trace_branch.c +++ b/kernel/trace/trace_branch.c | |||
| @@ -14,12 +14,17 @@ | |||
| 14 | #include <linux/hash.h> | 14 | #include <linux/hash.h> |
| 15 | #include <linux/fs.h> | 15 | #include <linux/fs.h> |
| 16 | #include <asm/local.h> | 16 | #include <asm/local.h> |
| 17 | |||
| 17 | #include "trace.h" | 18 | #include "trace.h" |
| 19 | #include "trace_output.h" | ||
| 20 | |||
| 21 | static struct tracer branch_trace; | ||
| 18 | 22 | ||
| 19 | #ifdef CONFIG_BRANCH_TRACER | 23 | #ifdef CONFIG_BRANCH_TRACER |
| 20 | 24 | ||
| 21 | static int branch_tracing_enabled __read_mostly; | 25 | static int branch_tracing_enabled __read_mostly; |
| 22 | static DEFINE_MUTEX(branch_tracing_mutex); | 26 | static DEFINE_MUTEX(branch_tracing_mutex); |
| 27 | |||
| 23 | static struct trace_array *branch_tracer; | 28 | static struct trace_array *branch_tracer; |
| 24 | 29 | ||
| 25 | static void | 30 | static void |
| @@ -142,22 +147,50 @@ static void branch_trace_reset(struct trace_array *tr) | |||
| 142 | stop_branch_trace(tr); | 147 | stop_branch_trace(tr); |
| 143 | } | 148 | } |
| 144 | 149 | ||
| 145 | struct tracer branch_trace __read_mostly = | 150 | static int |
| 151 | trace_print_print(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 146 | { | 152 | { |
| 147 | .name = "branch", | 153 | struct print_entry *field; |
| 148 | .init = branch_trace_init, | ||
| 149 | .reset = branch_trace_reset, | ||
| 150 | #ifdef CONFIG_FTRACE_SELFTEST | ||
| 151 | .selftest = trace_selftest_startup_branch, | ||
| 152 | #endif | ||
| 153 | }; | ||
| 154 | 154 | ||
| 155 | __init static int init_branch_trace(void) | 155 | trace_assign_type(field, entry); |
| 156 | |||
| 157 | if (seq_print_ip_sym(s, field->ip, flags)) | ||
| 158 | goto partial; | ||
| 159 | |||
| 160 | if (trace_seq_printf(s, ": %s", field->buf)) | ||
| 161 | goto partial; | ||
| 162 | |||
| 163 | partial: | ||
| 164 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 165 | } | ||
| 166 | |||
| 167 | static int | ||
| 168 | trace_branch_print(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 156 | { | 169 | { |
| 157 | return register_tracer(&branch_trace); | 170 | struct trace_branch *field; |
| 171 | |||
| 172 | trace_assign_type(field, entry); | ||
| 173 | |||
| 174 | if (trace_seq_printf(s, "[%s] %s:%s:%d\n", | ||
| 175 | field->correct ? " ok " : " MISS ", | ||
| 176 | field->func, | ||
| 177 | field->file, | ||
| 178 | field->line)) | ||
| 179 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 180 | |||
| 181 | return 0; | ||
| 158 | } | 182 | } |
| 159 | 183 | ||
| 160 | device_initcall(init_branch_trace); | 184 | |
| 185 | static struct trace_event trace_branch_event = { | ||
| 186 | .type = TRACE_BRANCH, | ||
| 187 | .trace = trace_branch_print, | ||
| 188 | .latency_trace = trace_branch_print, | ||
| 189 | .raw = trace_nop_print, | ||
| 190 | .hex = trace_nop_print, | ||
| 191 | .binary = trace_nop_print, | ||
| 192 | }; | ||
| 193 | |||
| 161 | #else | 194 | #else |
| 162 | static inline | 195 | static inline |
| 163 | void trace_likely_condition(struct ftrace_branch_data *f, int val, int expect) | 196 | void trace_likely_condition(struct ftrace_branch_data *f, int val, int expect) |
| @@ -183,66 +216,39 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect) | |||
| 183 | } | 216 | } |
| 184 | EXPORT_SYMBOL(ftrace_likely_update); | 217 | EXPORT_SYMBOL(ftrace_likely_update); |
| 185 | 218 | ||
| 186 | struct ftrace_pointer { | 219 | extern unsigned long __start_annotated_branch_profile[]; |
| 187 | void *start; | 220 | extern unsigned long __stop_annotated_branch_profile[]; |
| 188 | void *stop; | ||
| 189 | int hit; | ||
| 190 | }; | ||
| 191 | 221 | ||
| 192 | static void * | 222 | static int annotated_branch_stat_headers(struct seq_file *m) |
| 193 | t_next(struct seq_file *m, void *v, loff_t *pos) | ||
| 194 | { | 223 | { |
| 195 | const struct ftrace_pointer *f = m->private; | 224 | seq_printf(m, " correct incorrect %% "); |
| 196 | struct ftrace_branch_data *p = v; | 225 | seq_printf(m, " Function " |
| 197 | 226 | " File Line\n" | |
| 198 | (*pos)++; | 227 | " ------- --------- - " |
| 199 | 228 | " -------- " | |
| 200 | if (v == (void *)1) | 229 | " ---- ----\n"); |
| 201 | return f->start; | 230 | return 0; |
| 202 | |||
| 203 | ++p; | ||
| 204 | |||
| 205 | if ((void *)p >= (void *)f->stop) | ||
| 206 | return NULL; | ||
| 207 | |||
| 208 | return p; | ||
| 209 | } | 231 | } |
| 210 | 232 | ||
| 211 | static void *t_start(struct seq_file *m, loff_t *pos) | 233 | static inline long get_incorrect_percent(struct ftrace_branch_data *p) |
| 212 | { | 234 | { |
| 213 | void *t = (void *)1; | 235 | long percent; |
| 214 | loff_t l = 0; | ||
| 215 | |||
| 216 | for (; t && l < *pos; t = t_next(m, t, &l)) | ||
| 217 | ; | ||
| 218 | 236 | ||
| 219 | return t; | 237 | if (p->correct) { |
| 220 | } | 238 | percent = p->incorrect * 100; |
| 239 | percent /= p->correct + p->incorrect; | ||
| 240 | } else | ||
| 241 | percent = p->incorrect ? 100 : -1; | ||
| 221 | 242 | ||
| 222 | static void t_stop(struct seq_file *m, void *p) | 243 | return percent; |
| 223 | { | ||
| 224 | } | 244 | } |
| 225 | 245 | ||
| 226 | static int t_show(struct seq_file *m, void *v) | 246 | static int branch_stat_show(struct seq_file *m, void *v) |
| 227 | { | 247 | { |
| 228 | const struct ftrace_pointer *fp = m->private; | ||
| 229 | struct ftrace_branch_data *p = v; | 248 | struct ftrace_branch_data *p = v; |
| 230 | const char *f; | 249 | const char *f; |
| 231 | long percent; | 250 | long percent; |
| 232 | 251 | ||
| 233 | if (v == (void *)1) { | ||
| 234 | if (fp->hit) | ||
| 235 | seq_printf(m, " miss hit %% "); | ||
| 236 | else | ||
| 237 | seq_printf(m, " correct incorrect %% "); | ||
| 238 | seq_printf(m, " Function " | ||
| 239 | " File Line\n" | ||
| 240 | " ------- --------- - " | ||
| 241 | " -------- " | ||
| 242 | " ---- ----\n"); | ||
| 243 | return 0; | ||
| 244 | } | ||
| 245 | |||
| 246 | /* Only print the file, not the path */ | 252 | /* Only print the file, not the path */ |
| 247 | f = p->file + strlen(p->file); | 253 | f = p->file + strlen(p->file); |
| 248 | while (f >= p->file && *f != '/') | 254 | while (f >= p->file && *f != '/') |
| @@ -252,11 +258,7 @@ static int t_show(struct seq_file *m, void *v) | |||
| 252 | /* | 258 | /* |
| 253 | * The miss is overlayed on correct, and hit on incorrect. | 259 | * The miss is overlayed on correct, and hit on incorrect. |
| 254 | */ | 260 | */ |
| 255 | if (p->correct) { | 261 | percent = get_incorrect_percent(p); |
| 256 | percent = p->incorrect * 100; | ||
| 257 | percent /= p->correct + p->incorrect; | ||
| 258 | } else | ||
| 259 | percent = p->incorrect ? 100 : -1; | ||
| 260 | 262 | ||
| 261 | seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect); | 263 | seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect); |
| 262 | if (percent < 0) | 264 | if (percent < 0) |
| @@ -267,76 +269,143 @@ static int t_show(struct seq_file *m, void *v) | |||
| 267 | return 0; | 269 | return 0; |
| 268 | } | 270 | } |
| 269 | 271 | ||
| 270 | static struct seq_operations tracing_likely_seq_ops = { | 272 | static void *annotated_branch_stat_start(void) |
| 271 | .start = t_start, | 273 | { |
| 272 | .next = t_next, | 274 | return __start_annotated_branch_profile; |
| 273 | .stop = t_stop, | 275 | } |
| 274 | .show = t_show, | ||
| 275 | }; | ||
| 276 | 276 | ||
| 277 | static int tracing_branch_open(struct inode *inode, struct file *file) | 277 | static void * |
| 278 | annotated_branch_stat_next(void *v, int idx) | ||
| 278 | { | 279 | { |
| 279 | int ret; | 280 | struct ftrace_branch_data *p = v; |
| 280 | 281 | ||
| 281 | ret = seq_open(file, &tracing_likely_seq_ops); | 282 | ++p; |
| 282 | if (!ret) { | ||
| 283 | struct seq_file *m = file->private_data; | ||
| 284 | m->private = (void *)inode->i_private; | ||
| 285 | } | ||
| 286 | 283 | ||
| 287 | return ret; | 284 | if ((void *)p >= (void *)__stop_annotated_branch_profile) |
| 285 | return NULL; | ||
| 286 | |||
| 287 | return p; | ||
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | static const struct file_operations tracing_branch_fops = { | 290 | static int annotated_branch_stat_cmp(void *p1, void *p2) |
| 291 | .open = tracing_branch_open, | 291 | { |
| 292 | .read = seq_read, | 292 | struct ftrace_branch_data *a = p1; |
| 293 | .llseek = seq_lseek, | 293 | struct ftrace_branch_data *b = p2; |
| 294 | }; | 294 | |
| 295 | long percent_a, percent_b; | ||
| 296 | |||
| 297 | percent_a = get_incorrect_percent(a); | ||
| 298 | percent_b = get_incorrect_percent(b); | ||
| 299 | |||
| 300 | if (percent_a < percent_b) | ||
| 301 | return -1; | ||
| 302 | if (percent_a > percent_b) | ||
| 303 | return 1; | ||
| 304 | else | ||
| 305 | return 0; | ||
| 306 | } | ||
| 295 | 307 | ||
| 296 | #ifdef CONFIG_PROFILE_ALL_BRANCHES | 308 | #ifdef CONFIG_PROFILE_ALL_BRANCHES |
| 297 | extern unsigned long __start_branch_profile[]; | 309 | enum { |
| 298 | extern unsigned long __stop_branch_profile[]; | 310 | TRACE_BRANCH_OPT_ALL = 0x1 |
| 311 | }; | ||
| 299 | 312 | ||
| 300 | static const struct ftrace_pointer ftrace_branch_pos = { | 313 | static struct tracer_opt branch_opts[] = { |
| 301 | .start = __start_branch_profile, | 314 | { TRACER_OPT(stat_all_branch, TRACE_BRANCH_OPT_ALL) }, |
| 302 | .stop = __stop_branch_profile, | 315 | { } |
| 303 | .hit = 1, | ||
| 304 | }; | 316 | }; |
| 305 | 317 | ||
| 306 | #endif /* CONFIG_PROFILE_ALL_BRANCHES */ | 318 | static struct tracer_flags branch_flags = { |
| 319 | .val = 0, | ||
| 320 | .opts = branch_opts | ||
| 321 | }; | ||
| 307 | 322 | ||
| 308 | extern unsigned long __start_annotated_branch_profile[]; | 323 | extern unsigned long __start_branch_profile[]; |
| 309 | extern unsigned long __stop_annotated_branch_profile[]; | 324 | extern unsigned long __stop_branch_profile[]; |
| 310 | 325 | ||
| 311 | static const struct ftrace_pointer ftrace_annotated_branch_pos = { | 326 | static int all_branch_stat_headers(struct seq_file *m) |
| 312 | .start = __start_annotated_branch_profile, | 327 | { |
| 313 | .stop = __stop_annotated_branch_profile, | 328 | seq_printf(m, " miss hit %% "); |
| 314 | }; | 329 | seq_printf(m, " Function " |
| 330 | " File Line\n" | ||
| 331 | " ------- --------- - " | ||
| 332 | " -------- " | ||
| 333 | " ---- ----\n"); | ||
| 334 | return 0; | ||
| 335 | } | ||
| 336 | |||
| 337 | static void *all_branch_stat_start(void) | ||
| 338 | { | ||
| 339 | return __start_branch_profile; | ||
| 340 | } | ||
| 315 | 341 | ||
| 316 | static __init int ftrace_branch_init(void) | 342 | static void * |
| 343 | all_branch_stat_next(void *v, int idx) | ||
| 317 | { | 344 | { |
| 318 | struct dentry *d_tracer; | 345 | struct ftrace_branch_data *p = v; |
| 319 | struct dentry *entry; | ||
| 320 | 346 | ||
| 321 | d_tracer = tracing_init_dentry(); | 347 | ++p; |
| 322 | 348 | ||
| 323 | entry = debugfs_create_file("profile_annotated_branch", 0444, d_tracer, | 349 | if ((void *)p >= (void *)__stop_branch_profile) |
| 324 | (void *)&ftrace_annotated_branch_pos, | 350 | return NULL; |
| 325 | &tracing_branch_fops); | ||
| 326 | if (!entry) | ||
| 327 | pr_warning("Could not create debugfs " | ||
| 328 | "'profile_annotatet_branch' entry\n"); | ||
| 329 | 351 | ||
| 330 | #ifdef CONFIG_PROFILE_ALL_BRANCHES | 352 | return p; |
| 331 | entry = debugfs_create_file("profile_branch", 0444, d_tracer, | 353 | } |
| 332 | (void *)&ftrace_branch_pos, | ||
| 333 | &tracing_branch_fops); | ||
| 334 | if (!entry) | ||
| 335 | pr_warning("Could not create debugfs" | ||
| 336 | " 'profile_branch' entry\n"); | ||
| 337 | #endif | ||
| 338 | 354 | ||
| 355 | static int branch_set_flag(u32 old_flags, u32 bit, int set) | ||
| 356 | { | ||
| 357 | if (bit == TRACE_BRANCH_OPT_ALL) { | ||
| 358 | if (set) { | ||
| 359 | branch_trace.stat_headers = all_branch_stat_headers; | ||
| 360 | branch_trace.stat_start = all_branch_stat_start; | ||
| 361 | branch_trace.stat_next = all_branch_stat_next; | ||
| 362 | branch_trace.stat_cmp = NULL; | ||
| 363 | } else { | ||
| 364 | branch_trace.stat_headers = | ||
| 365 | annotated_branch_stat_headers; | ||
| 366 | branch_trace.stat_start = annotated_branch_stat_start; | ||
| 367 | branch_trace.stat_next = annotated_branch_stat_next; | ||
| 368 | branch_trace.stat_cmp = annotated_branch_stat_cmp; | ||
| 369 | } | ||
| 370 | init_tracer_stat(&branch_trace); | ||
| 371 | } | ||
| 339 | return 0; | 372 | return 0; |
| 340 | } | 373 | } |
| 341 | 374 | ||
| 342 | device_initcall(ftrace_branch_init); | 375 | #endif /* CONFIG_PROFILE_ALL_BRANCHES */ |
| 376 | |||
| 377 | static struct tracer branch_trace __read_mostly = | ||
| 378 | { | ||
| 379 | .name = "branch", | ||
| 380 | #ifdef CONFIG_BRANCH_TRACER | ||
| 381 | .init = branch_trace_init, | ||
| 382 | .reset = branch_trace_reset, | ||
| 383 | #ifdef CONFIG_FTRACE_SELFTEST | ||
| 384 | .selftest = trace_selftest_startup_branch, | ||
| 385 | #endif /* CONFIG_FTRACE_SELFTEST */ | ||
| 386 | #endif /* CONFIG_BRANCH_TRACER */ | ||
| 387 | .stat_start = annotated_branch_stat_start, | ||
| 388 | .stat_next = annotated_branch_stat_next, | ||
| 389 | .stat_show = branch_stat_show, | ||
| 390 | .stat_headers = annotated_branch_stat_headers, | ||
| 391 | .stat_cmp = annotated_branch_stat_cmp, | ||
| 392 | #ifdef CONFIG_PROFILE_ALL_BRANCHES | ||
| 393 | .flags = &branch_flags, | ||
| 394 | .set_flag = branch_set_flag, | ||
| 395 | #endif | ||
| 396 | }; | ||
| 397 | |||
| 398 | __init static int init_branch_trace(void) | ||
| 399 | { | ||
| 400 | #ifdef CONFIG_BRANCH_TRACER | ||
| 401 | int ret; | ||
| 402 | ret = register_ftrace_event(&trace_branch_event); | ||
| 403 | if (!ret) { | ||
| 404 | printk(KERN_WARNING "Warning: could not register branch events\n"); | ||
| 405 | return 1; | ||
| 406 | } | ||
| 407 | #endif | ||
| 408 | |||
| 409 | return register_tracer(&branch_trace); | ||
| 410 | } | ||
| 411 | device_initcall(init_branch_trace); | ||
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index 8516e4f09e1b..3c545984816f 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include <linux/fs.h> | 12 | #include <linux/fs.h> |
| 13 | 13 | ||
| 14 | #include "trace.h" | 14 | #include "trace.h" |
| 15 | #include "trace_output.h" | ||
| 15 | 16 | ||
| 16 | #define TRACE_GRAPH_INDENT 2 | 17 | #define TRACE_GRAPH_INDENT 2 |
| 17 | 18 | ||
| @@ -589,9 +590,6 @@ print_graph_comment(struct print_entry *trace, struct trace_seq *s, | |||
| 589 | if (!ret) | 590 | if (!ret) |
| 590 | return TRACE_TYPE_PARTIAL_LINE; | 591 | return TRACE_TYPE_PARTIAL_LINE; |
| 591 | 592 | ||
| 592 | if (ent->flags & TRACE_FLAG_CONT) | ||
| 593 | trace_seq_print_cont(s, iter); | ||
| 594 | |||
| 595 | /* Strip ending newline */ | 593 | /* Strip ending newline */ |
| 596 | if (s->buffer[s->len - 1] == '\n') { | 594 | if (s->buffer[s->len - 1] == '\n') { |
| 597 | s->buffer[s->len - 1] = '\0'; | 595 | s->buffer[s->len - 1] = '\0'; |
diff --git a/kernel/trace/trace_hw_branches.c b/kernel/trace/trace_hw_branches.c index 649df22d435f..df21c1e72b95 100644 --- a/kernel/trace/trace_hw_branches.c +++ b/kernel/trace/trace_hw_branches.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include <asm/ds.h> | 14 | #include <asm/ds.h> |
| 15 | 15 | ||
| 16 | #include "trace.h" | 16 | #include "trace.h" |
| 17 | #include "trace_output.h" | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | #define SIZEOF_BTS (1 << 13) | 20 | #define SIZEOF_BTS (1 << 13) |
diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c index fffcb069f1dc..fcec59ff2355 100644 --- a/kernel/trace/trace_mmiotrace.c +++ b/kernel/trace/trace_mmiotrace.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <linux/pci.h> | 11 | #include <linux/pci.h> |
| 12 | 12 | ||
| 13 | #include "trace.h" | 13 | #include "trace.h" |
| 14 | #include "trace_output.h" | ||
| 14 | 15 | ||
| 15 | struct header_iter { | 16 | struct header_iter { |
| 16 | struct pci_dev *dev; | 17 | struct pci_dev *dev; |
| @@ -262,9 +263,6 @@ static enum print_line_t mmio_print_mark(struct trace_iterator *iter) | |||
| 262 | if (!ret) | 263 | if (!ret) |
| 263 | return TRACE_TYPE_PARTIAL_LINE; | 264 | return TRACE_TYPE_PARTIAL_LINE; |
| 264 | 265 | ||
| 265 | if (entry->flags & TRACE_FLAG_CONT) | ||
| 266 | trace_seq_print_cont(s, iter); | ||
| 267 | |||
| 268 | return TRACE_TYPE_HANDLED; | 266 | return TRACE_TYPE_HANDLED; |
| 269 | } | 267 | } |
| 270 | 268 | ||
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c new file mode 100644 index 000000000000..df0c25cbed30 --- /dev/null +++ b/kernel/trace/trace_output.c | |||
| @@ -0,0 +1,832 @@ | |||
| 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 | static DEFINE_MUTEX(trace_event_mutex); | ||
| 18 | static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly; | ||
| 19 | |||
| 20 | static int next_event_type = __TRACE_LAST_TYPE + 1; | ||
| 21 | |||
| 22 | /** | ||
| 23 | * trace_seq_printf - sequence printing of trace information | ||
| 24 | * @s: trace sequence descriptor | ||
| 25 | * @fmt: printf format string | ||
| 26 | * | ||
| 27 | * The tracer may use either sequence operations or its own | ||
| 28 | * copy to user routines. To simplify formating of a trace | ||
| 29 | * trace_seq_printf is used to store strings into a special | ||
| 30 | * buffer (@s). Then the output may be either used by | ||
| 31 | * the sequencer or pulled into another buffer. | ||
| 32 | */ | ||
| 33 | int | ||
| 34 | trace_seq_printf(struct trace_seq *s, const char *fmt, ...) | ||
| 35 | { | ||
| 36 | int len = (PAGE_SIZE - 1) - s->len; | ||
| 37 | va_list ap; | ||
| 38 | int ret; | ||
| 39 | |||
| 40 | if (!len) | ||
| 41 | return 0; | ||
| 42 | |||
| 43 | va_start(ap, fmt); | ||
| 44 | ret = vsnprintf(s->buffer + s->len, len, fmt, ap); | ||
| 45 | va_end(ap); | ||
| 46 | |||
| 47 | /* If we can't write it all, don't bother writing anything */ | ||
| 48 | if (ret >= len) | ||
| 49 | return 0; | ||
| 50 | |||
| 51 | s->len += ret; | ||
| 52 | |||
| 53 | return len; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * trace_seq_puts - trace sequence printing of simple string | ||
| 58 | * @s: trace sequence descriptor | ||
| 59 | * @str: simple string to record | ||
| 60 | * | ||
| 61 | * The tracer may use either the sequence operations or its own | ||
| 62 | * copy to user routines. This function records a simple string | ||
| 63 | * into a special buffer (@s) for later retrieval by a sequencer | ||
| 64 | * or other mechanism. | ||
| 65 | */ | ||
| 66 | int trace_seq_puts(struct trace_seq *s, const char *str) | ||
| 67 | { | ||
| 68 | int len = strlen(str); | ||
| 69 | |||
| 70 | if (len > ((PAGE_SIZE - 1) - s->len)) | ||
| 71 | return 0; | ||
| 72 | |||
| 73 | memcpy(s->buffer + s->len, str, len); | ||
| 74 | s->len += len; | ||
| 75 | |||
| 76 | return len; | ||
| 77 | } | ||
| 78 | |||
| 79 | int trace_seq_putc(struct trace_seq *s, unsigned char c) | ||
| 80 | { | ||
| 81 | if (s->len >= (PAGE_SIZE - 1)) | ||
| 82 | return 0; | ||
| 83 | |||
| 84 | s->buffer[s->len++] = c; | ||
| 85 | |||
| 86 | return 1; | ||
| 87 | } | ||
| 88 | |||
| 89 | int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len) | ||
| 90 | { | ||
| 91 | if (len > ((PAGE_SIZE - 1) - s->len)) | ||
| 92 | return 0; | ||
| 93 | |||
| 94 | memcpy(s->buffer + s->len, mem, len); | ||
| 95 | s->len += len; | ||
| 96 | |||
| 97 | return len; | ||
| 98 | } | ||
| 99 | |||
| 100 | int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len) | ||
| 101 | { | ||
| 102 | unsigned char hex[HEX_CHARS]; | ||
| 103 | unsigned char *data = mem; | ||
| 104 | int i, j; | ||
| 105 | |||
| 106 | #ifdef __BIG_ENDIAN | ||
| 107 | for (i = 0, j = 0; i < len; i++) { | ||
| 108 | #else | ||
| 109 | for (i = len-1, j = 0; i >= 0; i--) { | ||
| 110 | #endif | ||
| 111 | hex[j++] = hex_asc_hi(data[i]); | ||
| 112 | hex[j++] = hex_asc_lo(data[i]); | ||
| 113 | } | ||
| 114 | hex[j++] = ' '; | ||
| 115 | |||
| 116 | return trace_seq_putmem(s, hex, j); | ||
| 117 | } | ||
| 118 | |||
| 119 | int trace_seq_path(struct trace_seq *s, struct path *path) | ||
| 120 | { | ||
| 121 | unsigned char *p; | ||
| 122 | |||
| 123 | if (s->len >= (PAGE_SIZE - 1)) | ||
| 124 | return 0; | ||
| 125 | p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len); | ||
| 126 | if (!IS_ERR(p)) { | ||
| 127 | p = mangle_path(s->buffer + s->len, p, "\n"); | ||
| 128 | if (p) { | ||
| 129 | s->len = p - s->buffer; | ||
| 130 | return 1; | ||
| 131 | } | ||
| 132 | } else { | ||
| 133 | s->buffer[s->len++] = '?'; | ||
| 134 | return 1; | ||
| 135 | } | ||
| 136 | |||
| 137 | return 0; | ||
| 138 | } | ||
| 139 | |||
| 140 | #ifdef CONFIG_KRETPROBES | ||
| 141 | static inline const char *kretprobed(const char *name) | ||
| 142 | { | ||
| 143 | static const char tramp_name[] = "kretprobe_trampoline"; | ||
| 144 | int size = sizeof(tramp_name); | ||
| 145 | |||
| 146 | if (strncmp(tramp_name, name, size) == 0) | ||
| 147 | return "[unknown/kretprobe'd]"; | ||
| 148 | return name; | ||
| 149 | } | ||
| 150 | #else | ||
| 151 | static inline const char *kretprobed(const char *name) | ||
| 152 | { | ||
| 153 | return name; | ||
| 154 | } | ||
| 155 | #endif /* CONFIG_KRETPROBES */ | ||
| 156 | |||
| 157 | static int | ||
| 158 | seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address) | ||
| 159 | { | ||
| 160 | #ifdef CONFIG_KALLSYMS | ||
| 161 | char str[KSYM_SYMBOL_LEN]; | ||
| 162 | const char *name; | ||
| 163 | |||
| 164 | kallsyms_lookup(address, NULL, NULL, NULL, str); | ||
| 165 | |||
| 166 | name = kretprobed(str); | ||
| 167 | |||
| 168 | return trace_seq_printf(s, fmt, name); | ||
| 169 | #endif | ||
| 170 | return 1; | ||
| 171 | } | ||
| 172 | |||
| 173 | static int | ||
| 174 | seq_print_sym_offset(struct trace_seq *s, const char *fmt, | ||
| 175 | unsigned long address) | ||
| 176 | { | ||
| 177 | #ifdef CONFIG_KALLSYMS | ||
| 178 | char str[KSYM_SYMBOL_LEN]; | ||
| 179 | const char *name; | ||
| 180 | |||
| 181 | sprint_symbol(str, address); | ||
| 182 | name = kretprobed(str); | ||
| 183 | |||
| 184 | return trace_seq_printf(s, fmt, name); | ||
| 185 | #endif | ||
| 186 | return 1; | ||
| 187 | } | ||
| 188 | |||
| 189 | #ifndef CONFIG_64BIT | ||
| 190 | # define IP_FMT "%08lx" | ||
| 191 | #else | ||
| 192 | # define IP_FMT "%016lx" | ||
| 193 | #endif | ||
| 194 | |||
| 195 | int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, | ||
| 196 | unsigned long ip, unsigned long sym_flags) | ||
| 197 | { | ||
| 198 | struct file *file = NULL; | ||
| 199 | unsigned long vmstart = 0; | ||
| 200 | int ret = 1; | ||
| 201 | |||
| 202 | if (mm) { | ||
| 203 | const struct vm_area_struct *vma; | ||
| 204 | |||
| 205 | down_read(&mm->mmap_sem); | ||
| 206 | vma = find_vma(mm, ip); | ||
| 207 | if (vma) { | ||
| 208 | file = vma->vm_file; | ||
| 209 | vmstart = vma->vm_start; | ||
| 210 | } | ||
| 211 | if (file) { | ||
| 212 | ret = trace_seq_path(s, &file->f_path); | ||
| 213 | if (ret) | ||
| 214 | ret = trace_seq_printf(s, "[+0x%lx]", | ||
| 215 | ip - vmstart); | ||
| 216 | } | ||
| 217 | up_read(&mm->mmap_sem); | ||
| 218 | } | ||
| 219 | if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file)) | ||
| 220 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); | ||
| 221 | return ret; | ||
| 222 | } | ||
| 223 | |||
| 224 | int | ||
| 225 | seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s, | ||
| 226 | unsigned long sym_flags) | ||
| 227 | { | ||
| 228 | struct mm_struct *mm = NULL; | ||
| 229 | int ret = 1; | ||
| 230 | unsigned int i; | ||
| 231 | |||
| 232 | if (trace_flags & TRACE_ITER_SYM_USEROBJ) { | ||
| 233 | struct task_struct *task; | ||
| 234 | /* | ||
| 235 | * we do the lookup on the thread group leader, | ||
| 236 | * since individual threads might have already quit! | ||
| 237 | */ | ||
| 238 | rcu_read_lock(); | ||
| 239 | task = find_task_by_vpid(entry->ent.tgid); | ||
| 240 | if (task) | ||
| 241 | mm = get_task_mm(task); | ||
| 242 | rcu_read_unlock(); | ||
| 243 | } | ||
| 244 | |||
| 245 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | ||
| 246 | unsigned long ip = entry->caller[i]; | ||
| 247 | |||
| 248 | if (ip == ULONG_MAX || !ret) | ||
| 249 | break; | ||
| 250 | if (i && ret) | ||
| 251 | ret = trace_seq_puts(s, " <- "); | ||
| 252 | if (!ip) { | ||
| 253 | if (ret) | ||
| 254 | ret = trace_seq_puts(s, "??"); | ||
| 255 | continue; | ||
| 256 | } | ||
| 257 | if (!ret) | ||
| 258 | break; | ||
| 259 | if (ret) | ||
| 260 | ret = seq_print_user_ip(s, mm, ip, sym_flags); | ||
| 261 | } | ||
| 262 | |||
| 263 | if (mm) | ||
| 264 | mmput(mm); | ||
| 265 | return ret; | ||
| 266 | } | ||
| 267 | |||
| 268 | int | ||
| 269 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) | ||
| 270 | { | ||
| 271 | int ret; | ||
| 272 | |||
| 273 | if (!ip) | ||
| 274 | return trace_seq_printf(s, "0"); | ||
| 275 | |||
| 276 | if (sym_flags & TRACE_ITER_SYM_OFFSET) | ||
| 277 | ret = seq_print_sym_offset(s, "%s", ip); | ||
| 278 | else | ||
| 279 | ret = seq_print_sym_short(s, "%s", ip); | ||
| 280 | |||
| 281 | if (!ret) | ||
| 282 | return 0; | ||
| 283 | |||
| 284 | if (sym_flags & TRACE_ITER_SYM_ADDR) | ||
| 285 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); | ||
| 286 | return ret; | ||
| 287 | } | ||
| 288 | |||
| 289 | static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; | ||
| 290 | |||
| 291 | static int task_state_char(unsigned long state) | ||
| 292 | { | ||
| 293 | int bit = state ? __ffs(state) + 1 : 0; | ||
| 294 | |||
| 295 | return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; | ||
| 296 | } | ||
| 297 | |||
| 298 | /** | ||
| 299 | * ftrace_find_event - find a registered event | ||
| 300 | * @type: the type of event to look for | ||
| 301 | * | ||
| 302 | * Returns an event of type @type otherwise NULL | ||
| 303 | */ | ||
| 304 | struct trace_event *ftrace_find_event(int type) | ||
| 305 | { | ||
| 306 | struct trace_event *event; | ||
| 307 | struct hlist_node *n; | ||
| 308 | unsigned key; | ||
| 309 | |||
| 310 | key = type & (EVENT_HASHSIZE - 1); | ||
| 311 | |||
| 312 | hlist_for_each_entry_rcu(event, n, &event_hash[key], node) { | ||
| 313 | if (event->type == type) | ||
| 314 | return event; | ||
| 315 | } | ||
| 316 | |||
| 317 | return NULL; | ||
| 318 | } | ||
| 319 | |||
| 320 | /** | ||
| 321 | * register_ftrace_event - register output for an event type | ||
| 322 | * @event: the event type to register | ||
| 323 | * | ||
| 324 | * Event types are stored in a hash and this hash is used to | ||
| 325 | * find a way to print an event. If the @event->type is set | ||
| 326 | * then it will use that type, otherwise it will assign a | ||
| 327 | * type to use. | ||
| 328 | * | ||
| 329 | * If you assign your own type, please make sure it is added | ||
| 330 | * to the trace_type enum in trace.h, to avoid collisions | ||
| 331 | * with the dynamic types. | ||
| 332 | * | ||
| 333 | * Returns the event type number or zero on error. | ||
| 334 | */ | ||
| 335 | int register_ftrace_event(struct trace_event *event) | ||
| 336 | { | ||
| 337 | unsigned key; | ||
| 338 | int ret = 0; | ||
| 339 | |||
| 340 | mutex_lock(&trace_event_mutex); | ||
| 341 | |||
| 342 | if (!event->type) | ||
| 343 | event->type = next_event_type++; | ||
| 344 | else if (event->type > __TRACE_LAST_TYPE) { | ||
| 345 | printk(KERN_WARNING "Need to add type to trace.h\n"); | ||
| 346 | WARN_ON(1); | ||
| 347 | } | ||
| 348 | |||
| 349 | if (ftrace_find_event(event->type)) | ||
| 350 | goto out; | ||
| 351 | |||
| 352 | key = event->type & (EVENT_HASHSIZE - 1); | ||
| 353 | |||
| 354 | hlist_add_head_rcu(&event->node, &event_hash[key]); | ||
| 355 | |||
| 356 | ret = event->type; | ||
| 357 | out: | ||
| 358 | mutex_unlock(&trace_event_mutex); | ||
| 359 | |||
| 360 | return ret; | ||
| 361 | } | ||
| 362 | |||
| 363 | /** | ||
| 364 | * unregister_ftrace_event - remove a no longer used event | ||
| 365 | * @event: the event to remove | ||
| 366 | */ | ||
| 367 | int unregister_ftrace_event(struct trace_event *event) | ||
| 368 | { | ||
| 369 | mutex_lock(&trace_event_mutex); | ||
| 370 | hlist_del(&event->node); | ||
| 371 | mutex_unlock(&trace_event_mutex); | ||
| 372 | |||
| 373 | return 0; | ||
| 374 | } | ||
| 375 | |||
| 376 | /* | ||
| 377 | * Standard events | ||
| 378 | */ | ||
| 379 | |||
| 380 | int | ||
| 381 | trace_nop_print(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 382 | { | ||
| 383 | return 0; | ||
| 384 | } | ||
| 385 | |||
| 386 | /* TRACE_FN */ | ||
| 387 | static int | ||
| 388 | trace_fn_latency(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 389 | { | ||
| 390 | struct ftrace_entry *field; | ||
| 391 | |||
| 392 | trace_assign_type(field, entry); | ||
| 393 | |||
| 394 | if (!seq_print_ip_sym(s, field->ip, flags)) | ||
| 395 | goto partial; | ||
| 396 | if (!trace_seq_puts(s, " (")) | ||
| 397 | goto partial; | ||
| 398 | if (!seq_print_ip_sym(s, field->parent_ip, flags)) | ||
| 399 | goto partial; | ||
| 400 | if (!trace_seq_puts(s, ")\n")) | ||
| 401 | goto partial; | ||
| 402 | |||
| 403 | return 0; | ||
| 404 | |||
| 405 | partial: | ||
| 406 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 407 | } | ||
| 408 | |||
| 409 | static int | ||
| 410 | trace_fn_trace(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 411 | { | ||
| 412 | struct ftrace_entry *field; | ||
| 413 | |||
| 414 | trace_assign_type(field, entry); | ||
| 415 | |||
| 416 | if (!seq_print_ip_sym(s, field->ip, flags)) | ||
| 417 | goto partial; | ||
| 418 | |||
| 419 | if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) { | ||
| 420 | if (!trace_seq_printf(s, " <-")) | ||
| 421 | goto partial; | ||
| 422 | if (!seq_print_ip_sym(s, | ||
| 423 | field->parent_ip, | ||
| 424 | flags)) | ||
| 425 | goto partial; | ||
| 426 | } | ||
| 427 | if (!trace_seq_printf(s, "\n")) | ||
| 428 | goto partial; | ||
| 429 | |||
| 430 | return 0; | ||
| 431 | |||
| 432 | partial: | ||
| 433 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 434 | } | ||
| 435 | |||
| 436 | static int | ||
| 437 | trace_fn_raw(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 438 | { | ||
| 439 | struct ftrace_entry *field; | ||
| 440 | |||
| 441 | trace_assign_type(field, entry); | ||
| 442 | |||
| 443 | if (trace_seq_printf(s, "%x %x\n", | ||
| 444 | field->ip, | ||
| 445 | field->parent_ip)) | ||
| 446 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 447 | |||
| 448 | return 0; | ||
| 449 | } | ||
| 450 | |||
| 451 | static int | ||
| 452 | trace_fn_hex(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 453 | { | ||
| 454 | struct ftrace_entry *field; | ||
| 455 | |||
| 456 | trace_assign_type(field, entry); | ||
| 457 | |||
| 458 | SEQ_PUT_HEX_FIELD_RET(s, field->ip); | ||
| 459 | SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip); | ||
| 460 | |||
| 461 | return 0; | ||
| 462 | } | ||
| 463 | |||
| 464 | static int | ||
| 465 | trace_fn_bin(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 466 | { | ||
| 467 | struct ftrace_entry *field; | ||
| 468 | |||
| 469 | trace_assign_type(field, entry); | ||
| 470 | |||
| 471 | SEQ_PUT_FIELD_RET(s, field->ip); | ||
| 472 | SEQ_PUT_FIELD_RET(s, field->parent_ip); | ||
| 473 | |||
| 474 | return 0; | ||
| 475 | } | ||
| 476 | |||
| 477 | static struct trace_event trace_fn_event = { | ||
| 478 | .type = TRACE_FN, | ||
| 479 | .trace = trace_fn_trace, | ||
| 480 | .latency_trace = trace_fn_latency, | ||
| 481 | .raw = trace_fn_raw, | ||
| 482 | .hex = trace_fn_hex, | ||
| 483 | .binary = trace_fn_bin, | ||
| 484 | }; | ||
| 485 | |||
| 486 | /* TRACE_CTX an TRACE_WAKE */ | ||
| 487 | static int | ||
| 488 | trace_ctxwake_print(struct trace_seq *s, struct trace_entry *entry, int flags, | ||
| 489 | char *delim) | ||
| 490 | { | ||
| 491 | struct ctx_switch_entry *field; | ||
| 492 | char *comm; | ||
| 493 | int S, T; | ||
| 494 | |||
| 495 | trace_assign_type(field, entry); | ||
| 496 | |||
| 497 | T = task_state_char(field->next_state); | ||
| 498 | S = task_state_char(field->prev_state); | ||
| 499 | comm = trace_find_cmdline(field->next_pid); | ||
| 500 | if (trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n", | ||
| 501 | field->prev_pid, | ||
| 502 | field->prev_prio, | ||
| 503 | S, delim, | ||
| 504 | field->next_cpu, | ||
| 505 | field->next_pid, | ||
| 506 | field->next_prio, | ||
| 507 | T, comm)) | ||
| 508 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 509 | |||
| 510 | return 0; | ||
| 511 | } | ||
| 512 | |||
| 513 | static int | ||
| 514 | trace_ctx_print(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 515 | { | ||
| 516 | return trace_ctxwake_print(s, entry, flags, "==>"); | ||
| 517 | } | ||
| 518 | |||
| 519 | static int | ||
| 520 | trace_wake_print(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 521 | { | ||
| 522 | return trace_ctxwake_print(s, entry, flags, " +"); | ||
| 523 | } | ||
| 524 | |||
| 525 | static int | ||
| 526 | trace_ctxwake_raw(struct trace_seq *s, struct trace_entry *entry, int flags, | ||
| 527 | char S) | ||
| 528 | { | ||
| 529 | struct ctx_switch_entry *field; | ||
| 530 | int T; | ||
| 531 | |||
| 532 | trace_assign_type(field, entry); | ||
| 533 | |||
| 534 | if (!S) | ||
| 535 | task_state_char(field->prev_state); | ||
| 536 | T = task_state_char(field->next_state); | ||
| 537 | if (trace_seq_printf(s, "%d %d %c %d %d %d %c\n", | ||
| 538 | field->prev_pid, | ||
| 539 | field->prev_prio, | ||
| 540 | S, | ||
| 541 | field->next_cpu, | ||
| 542 | field->next_pid, | ||
| 543 | field->next_prio, | ||
| 544 | T)) | ||
| 545 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 546 | |||
| 547 | return 0; | ||
| 548 | } | ||
| 549 | |||
| 550 | static int | ||
| 551 | trace_ctx_raw(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 552 | { | ||
| 553 | return trace_ctxwake_raw(s, entry, flags, 0); | ||
| 554 | } | ||
| 555 | |||
| 556 | static int | ||
| 557 | trace_wake_raw(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 558 | { | ||
| 559 | return trace_ctxwake_raw(s, entry, flags, '+'); | ||
| 560 | } | ||
| 561 | |||
| 562 | |||
| 563 | static int | ||
| 564 | trace_ctxwake_hex(struct trace_seq *s, struct trace_entry *entry, int flags, | ||
| 565 | char S) | ||
| 566 | { | ||
| 567 | struct ctx_switch_entry *field; | ||
| 568 | int T; | ||
| 569 | |||
| 570 | trace_assign_type(field, entry); | ||
| 571 | |||
| 572 | if (!S) | ||
| 573 | task_state_char(field->prev_state); | ||
| 574 | T = task_state_char(field->next_state); | ||
| 575 | |||
| 576 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid); | ||
| 577 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio); | ||
| 578 | SEQ_PUT_HEX_FIELD_RET(s, S); | ||
| 579 | SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu); | ||
| 580 | SEQ_PUT_HEX_FIELD_RET(s, field->next_pid); | ||
| 581 | SEQ_PUT_HEX_FIELD_RET(s, field->next_prio); | ||
| 582 | SEQ_PUT_HEX_FIELD_RET(s, T); | ||
| 583 | |||
| 584 | return 0; | ||
| 585 | } | ||
| 586 | |||
| 587 | static int | ||
| 588 | trace_ctx_hex(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 589 | { | ||
| 590 | return trace_ctxwake_hex(s, entry, flags, 0); | ||
| 591 | } | ||
| 592 | |||
| 593 | static int | ||
| 594 | trace_wake_hex(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 595 | { | ||
| 596 | return trace_ctxwake_hex(s, entry, flags, '+'); | ||
| 597 | } | ||
| 598 | |||
| 599 | static int | ||
| 600 | trace_ctxwake_bin(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 601 | { | ||
| 602 | struct ctx_switch_entry *field; | ||
| 603 | |||
| 604 | trace_assign_type(field, entry); | ||
| 605 | |||
| 606 | SEQ_PUT_FIELD_RET(s, field->prev_pid); | ||
| 607 | SEQ_PUT_FIELD_RET(s, field->prev_prio); | ||
| 608 | SEQ_PUT_FIELD_RET(s, field->prev_state); | ||
| 609 | SEQ_PUT_FIELD_RET(s, field->next_pid); | ||
| 610 | SEQ_PUT_FIELD_RET(s, field->next_prio); | ||
| 611 | SEQ_PUT_FIELD_RET(s, field->next_state); | ||
| 612 | |||
| 613 | return 0; | ||
| 614 | } | ||
| 615 | |||
| 616 | static struct trace_event trace_ctx_event = { | ||
| 617 | .type = TRACE_CTX, | ||
| 618 | .trace = trace_ctx_print, | ||
| 619 | .latency_trace = trace_ctx_print, | ||
| 620 | .raw = trace_ctx_raw, | ||
| 621 | .hex = trace_ctx_hex, | ||
| 622 | .binary = trace_ctxwake_bin, | ||
| 623 | }; | ||
| 624 | |||
| 625 | static struct trace_event trace_wake_event = { | ||
| 626 | .type = TRACE_WAKE, | ||
| 627 | .trace = trace_wake_print, | ||
| 628 | .latency_trace = trace_wake_print, | ||
| 629 | .raw = trace_wake_raw, | ||
| 630 | .hex = trace_wake_hex, | ||
| 631 | .binary = trace_ctxwake_bin, | ||
| 632 | }; | ||
| 633 | |||
| 634 | /* TRACE_SPECIAL */ | ||
| 635 | static int | ||
| 636 | trace_special_print(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 637 | { | ||
| 638 | struct special_entry *field; | ||
| 639 | |||
| 640 | trace_assign_type(field, entry); | ||
| 641 | |||
| 642 | if (trace_seq_printf(s, "# %ld %ld %ld\n", | ||
| 643 | field->arg1, | ||
| 644 | field->arg2, | ||
| 645 | field->arg3)) | ||
| 646 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 647 | |||
| 648 | return 0; | ||
| 649 | } | ||
| 650 | |||
| 651 | static int | ||
| 652 | trace_special_hex(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 653 | { | ||
| 654 | struct special_entry *field; | ||
| 655 | |||
| 656 | trace_assign_type(field, entry); | ||
| 657 | |||
| 658 | SEQ_PUT_HEX_FIELD_RET(s, field->arg1); | ||
| 659 | SEQ_PUT_HEX_FIELD_RET(s, field->arg2); | ||
| 660 | SEQ_PUT_HEX_FIELD_RET(s, field->arg3); | ||
| 661 | |||
| 662 | return 0; | ||
| 663 | } | ||
| 664 | |||
| 665 | static int | ||
| 666 | trace_special_bin(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 667 | { | ||
| 668 | struct special_entry *field; | ||
| 669 | |||
| 670 | trace_assign_type(field, entry); | ||
| 671 | |||
| 672 | SEQ_PUT_FIELD_RET(s, field->arg1); | ||
| 673 | SEQ_PUT_FIELD_RET(s, field->arg2); | ||
| 674 | SEQ_PUT_FIELD_RET(s, field->arg3); | ||
| 675 | |||
| 676 | return 0; | ||
| 677 | } | ||
| 678 | |||
| 679 | static struct trace_event trace_special_event = { | ||
| 680 | .type = TRACE_SPECIAL, | ||
| 681 | .trace = trace_special_print, | ||
| 682 | .latency_trace = trace_special_print, | ||
| 683 | .raw = trace_special_print, | ||
| 684 | .hex = trace_special_hex, | ||
| 685 | .binary = trace_special_bin, | ||
| 686 | }; | ||
| 687 | |||
| 688 | /* TRACE_STACK */ | ||
| 689 | |||
| 690 | static int | ||
| 691 | trace_stack_print(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 692 | { | ||
| 693 | struct stack_entry *field; | ||
| 694 | int i; | ||
| 695 | |||
| 696 | trace_assign_type(field, entry); | ||
| 697 | |||
| 698 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | ||
| 699 | if (i) { | ||
| 700 | if (trace_seq_puts(s, " <= ")) | ||
| 701 | goto partial; | ||
| 702 | |||
| 703 | if (seq_print_ip_sym(s, field->caller[i], flags)) | ||
| 704 | goto partial; | ||
| 705 | } | ||
| 706 | if (trace_seq_puts(s, "\n")) | ||
| 707 | goto partial; | ||
| 708 | } | ||
| 709 | |||
| 710 | return 0; | ||
| 711 | |||
| 712 | partial: | ||
| 713 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 714 | } | ||
| 715 | |||
| 716 | static struct trace_event trace_stack_event = { | ||
| 717 | .type = TRACE_STACK, | ||
| 718 | .trace = trace_stack_print, | ||
| 719 | .latency_trace = trace_stack_print, | ||
| 720 | .raw = trace_special_print, | ||
| 721 | .hex = trace_special_hex, | ||
| 722 | .binary = trace_special_bin, | ||
| 723 | }; | ||
| 724 | |||
| 725 | /* TRACE_USER_STACK */ | ||
| 726 | static int | ||
| 727 | trace_user_stack_print(struct trace_seq *s, struct trace_entry *entry, | ||
| 728 | int flags) | ||
| 729 | { | ||
| 730 | struct userstack_entry *field; | ||
| 731 | |||
| 732 | trace_assign_type(field, entry); | ||
| 733 | |||
| 734 | if (seq_print_userip_objs(field, s, flags)) | ||
| 735 | goto partial; | ||
| 736 | |||
| 737 | if (trace_seq_putc(s, '\n')) | ||
| 738 | goto partial; | ||
| 739 | |||
| 740 | return 0; | ||
| 741 | |||
| 742 | partial: | ||
| 743 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 744 | } | ||
| 745 | |||
| 746 | static struct trace_event trace_user_stack_event = { | ||
| 747 | .type = TRACE_USER_STACK, | ||
| 748 | .trace = trace_user_stack_print, | ||
| 749 | .latency_trace = trace_user_stack_print, | ||
| 750 | .raw = trace_special_print, | ||
| 751 | .hex = trace_special_hex, | ||
| 752 | .binary = trace_special_bin, | ||
| 753 | }; | ||
| 754 | |||
| 755 | /* TRACE_PRINT */ | ||
| 756 | static int | ||
| 757 | trace_print_print(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 758 | { | ||
| 759 | struct print_entry *field; | ||
| 760 | |||
| 761 | trace_assign_type(field, entry); | ||
| 762 | |||
| 763 | if (seq_print_ip_sym(s, field->ip, flags)) | ||
| 764 | goto partial; | ||
| 765 | |||
| 766 | if (trace_seq_printf(s, ": %s", field->buf)) | ||
| 767 | goto partial; | ||
| 768 | |||
| 769 | return 0; | ||
| 770 | |||
| 771 | partial: | ||
| 772 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 773 | } | ||
| 774 | |||
| 775 | static int | ||
| 776 | trace_print_raw(struct trace_seq *s, struct trace_entry *entry, int flags) | ||
| 777 | { | ||
| 778 | struct print_entry *field; | ||
| 779 | |||
| 780 | trace_assign_type(field, entry); | ||
| 781 | |||
| 782 | if (seq_print_ip_sym(s, field->ip, flags)) | ||
| 783 | goto partial; | ||
| 784 | |||
| 785 | if (trace_seq_printf(s, "# %lx %s", field->ip, field->buf)) | ||
| 786 | goto partial; | ||
| 787 | |||
| 788 | return 0; | ||
| 789 | |||
| 790 | partial: | ||
| 791 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 792 | } | ||
| 793 | |||
| 794 | static struct trace_event trace_print_event = { | ||
| 795 | .type = TRACE_PRINT, | ||
| 796 | .trace = trace_print_print, | ||
| 797 | .latency_trace = trace_print_print, | ||
| 798 | .raw = trace_print_raw, | ||
| 799 | .hex = trace_nop_print, | ||
| 800 | .binary = trace_nop_print, | ||
| 801 | }; | ||
| 802 | |||
| 803 | static struct trace_event *events[] __initdata = { | ||
| 804 | &trace_fn_event, | ||
| 805 | &trace_ctx_event, | ||
| 806 | &trace_wake_event, | ||
| 807 | &trace_special_event, | ||
| 808 | &trace_stack_event, | ||
| 809 | &trace_user_stack_event, | ||
| 810 | &trace_print_event, | ||
| 811 | NULL | ||
| 812 | }; | ||
| 813 | |||
| 814 | __init static int init_events(void) | ||
| 815 | { | ||
| 816 | struct trace_event *event; | ||
| 817 | int i, ret; | ||
| 818 | |||
| 819 | for (i = 0; events[i]; i++) { | ||
| 820 | event = events[i]; | ||
| 821 | |||
| 822 | ret = register_ftrace_event(event); | ||
| 823 | if (!ret) { | ||
| 824 | printk(KERN_WARNING "event %d failed to register\n", | ||
| 825 | event->type); | ||
| 826 | WARN_ON_ONCE(1); | ||
| 827 | } | ||
| 828 | } | ||
| 829 | |||
| 830 | return 0; | ||
| 831 | } | ||
| 832 | device_initcall(init_events); | ||
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h new file mode 100644 index 000000000000..ecab4ea4a4fd --- /dev/null +++ b/kernel/trace/trace_output.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #ifndef __TRACE_EVENTS_H | ||
| 2 | #define __TRACE_EVENTS_H | ||
| 3 | |||
| 4 | #include "trace.h" | ||
| 5 | |||
| 6 | typedef int (*trace_print_func)(struct trace_seq *s, struct trace_entry *entry, | ||
| 7 | int flags); | ||
| 8 | |||
| 9 | struct trace_event { | ||
| 10 | struct hlist_node node; | ||
| 11 | int type; | ||
| 12 | trace_print_func trace; | ||
| 13 | trace_print_func latency_trace; | ||
| 14 | trace_print_func raw; | ||
| 15 | trace_print_func hex; | ||
| 16 | trace_print_func binary; | ||
| 17 | }; | ||
| 18 | |||
| 19 | extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...); | ||
| 20 | extern int | ||
| 21 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, | ||
| 22 | unsigned long sym_flags); | ||
| 23 | extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, | ||
| 24 | size_t cnt); | ||
| 25 | int trace_seq_puts(struct trace_seq *s, const char *str); | ||
| 26 | int trace_seq_putc(struct trace_seq *s, unsigned char c); | ||
| 27 | int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len); | ||
| 28 | int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len); | ||
| 29 | int trace_seq_path(struct trace_seq *s, struct path *path); | ||
| 30 | int seq_print_userip_objs(const struct userstack_entry *entry, | ||
| 31 | struct trace_seq *s, unsigned long sym_flags); | ||
| 32 | int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, | ||
| 33 | unsigned long ip, unsigned long sym_flags); | ||
| 34 | |||
| 35 | struct trace_event *ftrace_find_event(int type); | ||
| 36 | int register_ftrace_event(struct trace_event *event); | ||
| 37 | int unregister_ftrace_event(struct trace_event *event); | ||
| 38 | |||
| 39 | int | ||
| 40 | trace_nop_print(struct trace_seq *s, struct trace_entry *entry, int flags); | ||
| 41 | |||
| 42 | #define MAX_MEMHEX_BYTES 8 | ||
| 43 | #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) | ||
| 44 | |||
| 45 | #define SEQ_PUT_FIELD_RET(s, x) \ | ||
| 46 | do { \ | ||
| 47 | if (!trace_seq_putmem(s, &(x), sizeof(x))) \ | ||
| 48 | return 0; \ | ||
| 49 | } while (0) | ||
| 50 | |||
| 51 | #define SEQ_PUT_HEX_FIELD_RET(s, x) \ | ||
| 52 | do { \ | ||
| 53 | BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \ | ||
| 54 | if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \ | ||
| 55 | return 0; \ | ||
| 56 | } while (0) | ||
| 57 | |||
| 58 | #endif | ||
| 59 | |||
diff --git a/kernel/trace/trace_power.c b/kernel/trace/trace_power.c index 7bda248daf55..faa6ab7a1f5c 100644 --- a/kernel/trace/trace_power.c +++ b/kernel/trace/trace_power.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 17 | 17 | ||
| 18 | #include "trace.h" | 18 | #include "trace.h" |
| 19 | #include "trace_output.h" | ||
| 19 | 20 | ||
| 20 | static struct trace_array *power_trace; | 21 | static struct trace_array *power_trace; |
| 21 | static int __read_mostly trace_power_enabled; | 22 | static int __read_mostly trace_power_enabled; |
diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index 88c8eb70f54a..5013812578b1 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c | |||
| @@ -9,7 +9,6 @@ static inline int trace_valid_entry(struct trace_entry *entry) | |||
| 9 | case TRACE_FN: | 9 | case TRACE_FN: |
| 10 | case TRACE_CTX: | 10 | case TRACE_CTX: |
| 11 | case TRACE_WAKE: | 11 | case TRACE_WAKE: |
| 12 | case TRACE_CONT: | ||
| 13 | case TRACE_STACK: | 12 | case TRACE_STACK: |
| 14 | case TRACE_PRINT: | 13 | case TRACE_PRINT: |
| 15 | case TRACE_SPECIAL: | 14 | case TRACE_SPECIAL: |
diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c new file mode 100644 index 000000000000..6f194a33a64a --- /dev/null +++ b/kernel/trace/trace_stat.c | |||
| @@ -0,0 +1,251 @@ | |||
| 1 | /* | ||
| 2 | * Infrastructure for statistic tracing (histogram output). | ||
| 3 | * | ||
| 4 | * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com> | ||
| 5 | * | ||
| 6 | * Based on the code from trace_branch.c which is | ||
| 7 | * Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com> | ||
| 8 | * | ||
| 9 | */ | ||
| 10 | |||
| 11 | |||
| 12 | #include <linux/list.h> | ||
| 13 | #include <linux/seq_file.h> | ||
| 14 | #include <linux/debugfs.h> | ||
| 15 | #include "trace.h" | ||
| 16 | |||
| 17 | |||
| 18 | /* List of stat entries from a tracer */ | ||
| 19 | struct trace_stat_list { | ||
| 20 | struct list_head list; | ||
| 21 | void *stat; | ||
| 22 | }; | ||
| 23 | |||
| 24 | static struct trace_stat_list stat_list; | ||
| 25 | |||
| 26 | /* | ||
| 27 | * This is a copy of the current tracer to avoid racy | ||
| 28 | * and dangerous output while the current tracer is | ||
| 29 | * switched. | ||
| 30 | */ | ||
| 31 | static struct tracer current_tracer; | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Protect both the current tracer and the global | ||
| 35 | * stat list. | ||
| 36 | */ | ||
| 37 | static DEFINE_MUTEX(stat_list_mutex); | ||
| 38 | |||
| 39 | |||
| 40 | static void reset_stat_list(void) | ||
| 41 | { | ||
| 42 | struct trace_stat_list *node; | ||
| 43 | struct list_head *next; | ||
| 44 | |||
| 45 | if (list_empty(&stat_list.list)) | ||
| 46 | return; | ||
| 47 | |||
| 48 | node = list_entry(stat_list.list.next, struct trace_stat_list, list); | ||
| 49 | next = node->list.next; | ||
| 50 | |||
| 51 | while (&node->list != next) { | ||
| 52 | kfree(node); | ||
| 53 | node = list_entry(next, struct trace_stat_list, list); | ||
| 54 | } | ||
| 55 | kfree(node); | ||
| 56 | |||
| 57 | INIT_LIST_HEAD(&stat_list.list); | ||
| 58 | } | ||
| 59 | |||
| 60 | void init_tracer_stat(struct tracer *trace) | ||
| 61 | { | ||
| 62 | mutex_lock(&stat_list_mutex); | ||
| 63 | current_tracer = *trace; | ||
| 64 | mutex_unlock(&stat_list_mutex); | ||
| 65 | } | ||
| 66 | |||
| 67 | /* | ||
| 68 | * For tracers that don't provide a stat_cmp callback. | ||
| 69 | * This one will force an immediate insertion on tail of | ||
| 70 | * the list. | ||
| 71 | */ | ||
| 72 | static int dummy_cmp(void *p1, void *p2) | ||
| 73 | { | ||
| 74 | return 1; | ||
| 75 | } | ||
| 76 | |||
| 77 | /* | ||
| 78 | * Initialize the stat list at each trace_stat file opening. | ||
| 79 | * All of these copies and sorting are required on all opening | ||
| 80 | * since the stats could have changed between two file sessions. | ||
| 81 | */ | ||
| 82 | static int stat_seq_init(void) | ||
| 83 | { | ||
| 84 | struct trace_stat_list *iter_entry, *new_entry; | ||
| 85 | void *prev_stat; | ||
| 86 | int ret = 0; | ||
| 87 | int i; | ||
| 88 | |||
| 89 | mutex_lock(&stat_list_mutex); | ||
| 90 | reset_stat_list(); | ||
| 91 | |||
| 92 | if (!current_tracer.stat_start || !current_tracer.stat_next || | ||
| 93 | !current_tracer.stat_show) | ||
| 94 | goto exit; | ||
| 95 | |||
| 96 | if (!current_tracer.stat_cmp) | ||
| 97 | current_tracer.stat_cmp = dummy_cmp; | ||
| 98 | |||
| 99 | /* | ||
| 100 | * The first entry. Actually this is the second, but the first | ||
| 101 | * one (the stat_list head) is pointless. | ||
| 102 | */ | ||
| 103 | new_entry = kmalloc(sizeof(struct trace_stat_list), GFP_KERNEL); | ||
| 104 | if (!new_entry) { | ||
| 105 | ret = -ENOMEM; | ||
| 106 | goto exit; | ||
| 107 | } | ||
| 108 | |||
| 109 | INIT_LIST_HEAD(&new_entry->list); | ||
| 110 | list_add(&new_entry->list, &stat_list.list); | ||
| 111 | new_entry->stat = current_tracer.stat_start(); | ||
| 112 | |||
| 113 | prev_stat = new_entry->stat; | ||
| 114 | |||
| 115 | /* | ||
| 116 | * Iterate over the tracer stat entries and store them in a sorted | ||
| 117 | * list. | ||
| 118 | */ | ||
| 119 | for (i = 1; ; i++) { | ||
| 120 | new_entry = kmalloc(sizeof(struct trace_stat_list), GFP_KERNEL); | ||
| 121 | if (!new_entry) { | ||
| 122 | ret = -ENOMEM; | ||
| 123 | goto exit_free_list; | ||
| 124 | } | ||
| 125 | |||
| 126 | INIT_LIST_HEAD(&new_entry->list); | ||
| 127 | new_entry->stat = current_tracer.stat_next(prev_stat, i); | ||
| 128 | |||
| 129 | /* End of insertion */ | ||
| 130 | if (!new_entry->stat) | ||
| 131 | break; | ||
| 132 | |||
| 133 | list_for_each_entry(iter_entry, &stat_list.list, list) { | ||
| 134 | /* Insertion with a descendent sorting */ | ||
| 135 | if (current_tracer.stat_cmp(new_entry->stat, | ||
| 136 | iter_entry->stat) > 0) { | ||
| 137 | |||
| 138 | list_add_tail(&new_entry->list, | ||
| 139 | &iter_entry->list); | ||
| 140 | break; | ||
| 141 | |||
| 142 | /* The current smaller value */ | ||
| 143 | } else if (list_is_last(&iter_entry->list, | ||
| 144 | &stat_list.list)) { | ||
| 145 | list_add(&new_entry->list, &iter_entry->list); | ||
| 146 | break; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | prev_stat = new_entry->stat; | ||
| 151 | } | ||
| 152 | exit: | ||
| 153 | mutex_unlock(&stat_list_mutex); | ||
| 154 | return ret; | ||
| 155 | |||
| 156 | exit_free_list: | ||
| 157 | reset_stat_list(); | ||
| 158 | mutex_unlock(&stat_list_mutex); | ||
| 159 | return ret; | ||
| 160 | } | ||
| 161 | |||
| 162 | |||
| 163 | static void *stat_seq_start(struct seq_file *s, loff_t *pos) | ||
| 164 | { | ||
| 165 | struct trace_stat_list *l = (struct trace_stat_list *)s->private; | ||
| 166 | |||
| 167 | /* Prevent from tracer switch or stat_list modification */ | ||
| 168 | mutex_lock(&stat_list_mutex); | ||
| 169 | |||
| 170 | /* If we are in the beginning of the file, print the headers */ | ||
| 171 | if (!*pos && current_tracer.stat_headers) | ||
| 172 | current_tracer.stat_headers(s); | ||
| 173 | |||
| 174 | return seq_list_start(&l->list, *pos); | ||
| 175 | } | ||
| 176 | |||
| 177 | static void *stat_seq_next(struct seq_file *s, void *p, loff_t *pos) | ||
| 178 | { | ||
| 179 | struct trace_stat_list *l = (struct trace_stat_list *)s->private; | ||
| 180 | |||
| 181 | return seq_list_next(p, &l->list, pos); | ||
| 182 | } | ||
| 183 | |||
| 184 | static void stat_seq_stop(struct seq_file *m, void *p) | ||
| 185 | { | ||
| 186 | mutex_unlock(&stat_list_mutex); | ||
| 187 | } | ||
| 188 | |||
| 189 | static int stat_seq_show(struct seq_file *s, void *v) | ||
| 190 | { | ||
| 191 | struct trace_stat_list *l = list_entry(v, struct trace_stat_list, list); | ||
| 192 | return current_tracer.stat_show(s, l->stat); | ||
| 193 | } | ||
| 194 | |||
| 195 | static const struct seq_operations trace_stat_seq_ops = { | ||
| 196 | .start = stat_seq_start, | ||
| 197 | .next = stat_seq_next, | ||
| 198 | .stop = stat_seq_stop, | ||
| 199 | .show = stat_seq_show | ||
| 200 | }; | ||
| 201 | |||
| 202 | static int tracing_stat_open(struct inode *inode, struct file *file) | ||
| 203 | { | ||
| 204 | int ret; | ||
| 205 | |||
| 206 | ret = seq_open(file, &trace_stat_seq_ops); | ||
| 207 | if (!ret) { | ||
| 208 | struct seq_file *m = file->private_data; | ||
| 209 | m->private = &stat_list; | ||
| 210 | ret = stat_seq_init(); | ||
| 211 | } | ||
| 212 | |||
| 213 | return ret; | ||
| 214 | } | ||
| 215 | |||
| 216 | |||
| 217 | /* | ||
| 218 | * Avoid consuming memory with our now useless list. | ||
| 219 | */ | ||
| 220 | static int tracing_stat_release(struct inode *i, struct file *f) | ||
| 221 | { | ||
| 222 | mutex_lock(&stat_list_mutex); | ||
| 223 | reset_stat_list(); | ||
| 224 | mutex_unlock(&stat_list_mutex); | ||
| 225 | return 0; | ||
| 226 | } | ||
| 227 | |||
| 228 | static const struct file_operations tracing_stat_fops = { | ||
| 229 | .open = tracing_stat_open, | ||
| 230 | .read = seq_read, | ||
| 231 | .llseek = seq_lseek, | ||
| 232 | .release = tracing_stat_release | ||
| 233 | }; | ||
| 234 | |||
| 235 | static int __init tracing_stat_init(void) | ||
| 236 | { | ||
| 237 | struct dentry *d_tracing; | ||
| 238 | struct dentry *entry; | ||
| 239 | |||
| 240 | INIT_LIST_HEAD(&stat_list.list); | ||
| 241 | d_tracing = tracing_init_dentry(); | ||
| 242 | |||
| 243 | entry = debugfs_create_file("trace_stat", 0444, d_tracing, | ||
| 244 | NULL, | ||
| 245 | &tracing_stat_fops); | ||
| 246 | if (!entry) | ||
| 247 | pr_warning("Could not create debugfs " | ||
| 248 | "'trace_stat' entry\n"); | ||
| 249 | return 0; | ||
| 250 | } | ||
| 251 | fs_initcall(tracing_stat_init); | ||
