trace_boot.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "trace.h"
  11. static struct trace_array *boot_trace;
  12. static int trace_boot_enabled;
  13. /* Should be started after do_pre_smp_initcalls() in init/main.c */
  14. void start_boot_trace(void)
  15. {
  16. trace_boot_enabled = 1;
  17. }
  18. void stop_boot_trace(struct trace_array *tr)
  19. {
  20. trace_boot_enabled = 0;
  21. }
  22. static void boot_trace_init(struct trace_array *tr)
  23. {
  24. int cpu;
  25. boot_trace = tr;
  26. trace_boot_enabled = 0;
  27. for_each_cpu_mask(cpu, cpu_possible_map)
  28. tracing_reset(tr, cpu);
  29. }
  30. static void boot_trace_ctrl_update(struct trace_array *tr)
  31. {
  32. if (tr->ctrl)
  33. start_boot_trace();
  34. else
  35. stop_boot_trace(tr);
  36. }
  37. static enum print_line_t initcall_print_line(struct trace_iterator *iter)
  38. {
  39. int ret;
  40. struct trace_entry *entry = iter->ent;
  41. struct trace_boot *field = (struct trace_boot *)entry;
  42. struct boot_trace *it = &field->initcall;
  43. struct trace_seq *s = &iter->seq;
  44. if (entry->type == TRACE_BOOT) {
  45. ret = trace_seq_printf(s, "%pF called from %i "
  46. "returned %d after %lld msecs\n",
  47. it->func, it->caller, it->result,
  48. it->duration);
  49. if (ret)
  50. return TRACE_TYPE_HANDLED;
  51. else
  52. return TRACE_TYPE_PARTIAL_LINE;
  53. }
  54. return TRACE_TYPE_UNHANDLED;
  55. }
  56. struct tracer boot_tracer __read_mostly =
  57. {
  58. .name = "initcall",
  59. .init = boot_trace_init,
  60. .reset = stop_boot_trace,
  61. .ctrl_update = boot_trace_ctrl_update,
  62. .print_line = initcall_print_line,
  63. };
  64. void trace_boot(struct boot_trace *it)
  65. {
  66. struct ring_buffer_event *event;
  67. struct trace_boot *entry;
  68. struct trace_array_cpu *data;
  69. unsigned long irq_flags;
  70. struct trace_array *tr = boot_trace;
  71. if (!trace_boot_enabled)
  72. return;
  73. preempt_disable();
  74. data = tr->data[smp_processor_id()];
  75. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  76. &irq_flags);
  77. if (!event)
  78. goto out;
  79. entry = ring_buffer_event_data(event);
  80. tracing_generic_entry_update(&entry->ent, 0, 0);
  81. entry->ent.type = TRACE_BOOT;
  82. entry->initcall = *it;
  83. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  84. trace_wake_up();
  85. out:
  86. preempt_enable();
  87. }