trace_boot.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 bool pre_initcalls_finished;
  14. /* Tells the boot tracer that the pre_smp_initcalls are finished.
  15. * So we are ready .
  16. * It doesn't enable sched events tracing however.
  17. * You have to call enable_boot_trace to do so.
  18. */
  19. void start_boot_trace(void)
  20. {
  21. pre_initcalls_finished = true;
  22. }
  23. void enable_boot_trace(void)
  24. {
  25. if (pre_initcalls_finished)
  26. tracing_start_sched_switch_record();
  27. }
  28. void disable_boot_trace(void)
  29. {
  30. if (pre_initcalls_finished)
  31. tracing_stop_sched_switch_record();
  32. }
  33. static void reset_boot_trace(struct trace_array *tr)
  34. {
  35. int cpu;
  36. tr->time_start = ftrace_now(tr->cpu);
  37. for_each_online_cpu(cpu)
  38. tracing_reset(tr, cpu);
  39. }
  40. static void boot_trace_init(struct trace_array *tr)
  41. {
  42. int cpu;
  43. boot_trace = tr;
  44. for_each_cpu_mask(cpu, cpu_possible_map)
  45. tracing_reset(tr, cpu);
  46. tracing_sched_switch_assign_trace(tr);
  47. }
  48. static enum print_line_t
  49. initcall_call_print_line(struct trace_iterator *iter)
  50. {
  51. struct trace_entry *entry = iter->ent;
  52. struct trace_seq *s = &iter->seq;
  53. struct trace_boot_call *field;
  54. struct boot_trace_call *call;
  55. u64 ts;
  56. unsigned long nsec_rem;
  57. int ret;
  58. trace_assign_type(field, entry);
  59. call = &field->boot_call;
  60. ts = iter->ts;
  61. nsec_rem = do_div(ts, 1000000000);
  62. ret = trace_seq_printf(s, "[%5ld.%09ld] calling %s @ %i\n",
  63. (unsigned long)ts, nsec_rem, call->func, call->caller);
  64. if (!ret)
  65. return TRACE_TYPE_PARTIAL_LINE;
  66. else
  67. return TRACE_TYPE_HANDLED;
  68. }
  69. static enum print_line_t
  70. initcall_ret_print_line(struct trace_iterator *iter)
  71. {
  72. struct trace_entry *entry = iter->ent;
  73. struct trace_seq *s = &iter->seq;
  74. struct trace_boot_ret *field;
  75. struct boot_trace_ret *init_ret;
  76. u64 ts;
  77. unsigned long nsec_rem;
  78. int ret;
  79. trace_assign_type(field, entry);
  80. init_ret = &field->boot_ret;
  81. ts = iter->ts;
  82. nsec_rem = do_div(ts, 1000000000);
  83. ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s "
  84. "returned %d after %llu msecs\n",
  85. (unsigned long) ts,
  86. nsec_rem,
  87. init_ret->func, init_ret->result, init_ret->duration);
  88. if (!ret)
  89. return TRACE_TYPE_PARTIAL_LINE;
  90. else
  91. return TRACE_TYPE_HANDLED;
  92. }
  93. static enum print_line_t initcall_print_line(struct trace_iterator *iter)
  94. {
  95. struct trace_entry *entry = iter->ent;
  96. switch (entry->type) {
  97. case TRACE_BOOT_CALL:
  98. return initcall_call_print_line(iter);
  99. case TRACE_BOOT_RET:
  100. return initcall_ret_print_line(iter);
  101. default:
  102. return TRACE_TYPE_UNHANDLED;
  103. }
  104. }
  105. struct tracer boot_tracer __read_mostly =
  106. {
  107. .name = "initcall",
  108. .init = boot_trace_init,
  109. .reset = reset_boot_trace,
  110. .print_line = initcall_print_line,
  111. };
  112. void trace_boot_call(struct boot_trace_call *bt, initcall_t fn)
  113. {
  114. struct ring_buffer_event *event;
  115. struct trace_boot_call *entry;
  116. unsigned long irq_flags;
  117. struct trace_array *tr = boot_trace;
  118. if (!pre_initcalls_finished)
  119. return;
  120. /* Get its name now since this function could
  121. * disappear because it is in the .init section.
  122. */
  123. sprint_symbol(bt->func, (unsigned long)fn);
  124. preempt_disable();
  125. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  126. &irq_flags);
  127. if (!event)
  128. goto out;
  129. entry = ring_buffer_event_data(event);
  130. tracing_generic_entry_update(&entry->ent, 0, 0);
  131. entry->ent.type = TRACE_BOOT_CALL;
  132. entry->boot_call = *bt;
  133. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  134. trace_wake_up();
  135. out:
  136. preempt_enable();
  137. }
  138. void trace_boot_ret(struct boot_trace_ret *bt, initcall_t fn)
  139. {
  140. struct ring_buffer_event *event;
  141. struct trace_boot_ret *entry;
  142. unsigned long irq_flags;
  143. struct trace_array *tr = boot_trace;
  144. if (!pre_initcalls_finished)
  145. return;
  146. sprint_symbol(bt->func, (unsigned long)fn);
  147. preempt_disable();
  148. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  149. &irq_flags);
  150. if (!event)
  151. goto out;
  152. entry = ring_buffer_event_data(event);
  153. tracing_generic_entry_update(&entry->ent, 0, 0);
  154. entry->ent.type = TRACE_BOOT_RET;
  155. entry->boot_ret = *bt;
  156. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  157. trace_wake_up();
  158. out:
  159. preempt_enable();
  160. }