trace_boot.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 int initcall_print_line(struct trace_iterator *iter)
  38. {
  39. int ret = 0;
  40. struct trace_entry *entry = iter->ent;
  41. struct boot_trace *it = &entry->field.initcall;
  42. struct trace_seq *s = &iter->seq;
  43. if (iter->ent->type == TRACE_BOOT)
  44. ret = trace_seq_printf(s, "%pF called from %i "
  45. "returned %d after %lld msecs\n",
  46. it->func, it->caller, it->result,
  47. it->duration);
  48. if (ret)
  49. return 1;
  50. return 0;
  51. }
  52. struct tracer boot_tracer __read_mostly =
  53. {
  54. .name = "initcall",
  55. .init = boot_trace_init,
  56. .reset = stop_boot_trace,
  57. .ctrl_update = boot_trace_ctrl_update,
  58. .print_line = initcall_print_line,
  59. };
  60. void trace_boot(struct boot_trace *it)
  61. {
  62. struct ring_buffer_event *event;
  63. struct trace_entry *entry;
  64. struct trace_array_cpu *data;
  65. unsigned long irq_flags;
  66. struct trace_array *tr = boot_trace;
  67. if (!trace_boot_enabled)
  68. return;
  69. preempt_disable();
  70. data = tr->data[smp_processor_id()];
  71. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  72. &irq_flags);
  73. if (!event)
  74. goto out;
  75. entry = ring_buffer_event_data(event);
  76. tracing_generic_entry_update(entry, 0);
  77. entry->type = TRACE_BOOT;
  78. entry->field.initcall = *it;
  79. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  80. trace_wake_up();
  81. out:
  82. preempt_enable();
  83. }