trace_boot.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * ring buffer based initcalls tracer
  3. *
  4. * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
  5. *
  6. */
  7. #include <linux/init.h>
  8. #include <linux/debugfs.h>
  9. #include <linux/ftrace.h>
  10. #include <linux/kallsyms.h>
  11. #include "trace.h"
  12. static struct trace_array *boot_trace;
  13. static int trace_boot_enabled;
  14. /* Should be started after do_pre_smp_initcalls() in init/main.c */
  15. void start_boot_trace(void)
  16. {
  17. trace_boot_enabled = 1;
  18. }
  19. void stop_boot_trace(void)
  20. {
  21. trace_boot_enabled = 0;
  22. }
  23. void reset_boot_trace(struct trace_array *tr)
  24. {
  25. stop_boot_trace();
  26. }
  27. static void boot_trace_init(struct trace_array *tr)
  28. {
  29. int cpu;
  30. boot_trace = tr;
  31. trace_boot_enabled = 0;
  32. for_each_cpu_mask(cpu, cpu_possible_map)
  33. tracing_reset(tr, cpu);
  34. }
  35. static void boot_trace_ctrl_update(struct trace_array *tr)
  36. {
  37. if (tr->ctrl)
  38. start_boot_trace();
  39. else
  40. stop_boot_trace();
  41. }
  42. static enum print_line_t initcall_print_line(struct trace_iterator *iter)
  43. {
  44. int ret;
  45. struct trace_entry *entry = iter->ent;
  46. struct trace_boot *field = (struct trace_boot *)entry;
  47. struct boot_trace *it = &field->initcall;
  48. struct trace_seq *s = &iter->seq;
  49. struct timespec calltime = ktime_to_timespec(it->calltime);
  50. struct timespec rettime = ktime_to_timespec(it->rettime);
  51. if (entry->type == TRACE_BOOT) {
  52. ret = trace_seq_printf(s, "[%5ld.%09ld] calling %s @ %i\n",
  53. calltime.tv_sec,
  54. calltime.tv_nsec,
  55. it->func, it->caller);
  56. if (!ret)
  57. return TRACE_TYPE_PARTIAL_LINE;
  58. ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s "
  59. "returned %d after %lld msecs\n",
  60. rettime.tv_sec,
  61. rettime.tv_nsec,
  62. it->func, it->result, it->duration);
  63. if (!ret)
  64. return TRACE_TYPE_PARTIAL_LINE;
  65. return TRACE_TYPE_HANDLED;
  66. }
  67. return TRACE_TYPE_UNHANDLED;
  68. }
  69. struct tracer boot_tracer __read_mostly =
  70. {
  71. .name = "initcall",
  72. .init = boot_trace_init,
  73. .reset = reset_boot_trace,
  74. .ctrl_update = boot_trace_ctrl_update,
  75. .print_line = initcall_print_line,
  76. };
  77. void trace_boot(struct boot_trace *it, initcall_t fn)
  78. {
  79. struct ring_buffer_event *event;
  80. struct trace_boot *entry;
  81. struct trace_array_cpu *data;
  82. unsigned long irq_flags;
  83. struct trace_array *tr = boot_trace;
  84. if (!trace_boot_enabled)
  85. return;
  86. /* Get its name now since this function could
  87. * disappear because it is in the .init section.
  88. */
  89. sprint_symbol(it->func, (unsigned long)fn);
  90. preempt_disable();
  91. data = tr->data[smp_processor_id()];
  92. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  93. &irq_flags);
  94. if (!event)
  95. goto out;
  96. entry = ring_buffer_event_data(event);
  97. tracing_generic_entry_update(&entry->ent, 0, 0);
  98. entry->ent.type = TRACE_BOOT;
  99. entry->initcall = *it;
  100. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  101. trace_wake_up();
  102. out:
  103. preempt_enable();
  104. }