blob: 3657eec6b87d2abd5ad08d557e63a504cb68a7a2 [file] [log] [blame]
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +01001/*
2 * ring buffer based initcalls tracer
3 *
4 * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
5 *
6 */
7
8#include <linux/init.h>
9#include <linux/debugfs.h>
10#include <linux/ftrace.h>
11
12#include "trace.h"
13
14static struct trace_array *boot_trace;
15static int trace_boot_enabled;
16
17
18/* Should be started after do_pre_smp_initcalls() in init/main.c */
19void start_boot_trace(void)
20{
21 trace_boot_enabled = 1;
22}
23
24void stop_boot_trace(struct trace_array *tr)
25{
26 trace_boot_enabled = 0;
27}
28
29static void boot_trace_init(struct trace_array *tr)
30{
31 int cpu;
32 boot_trace = tr;
33
34 trace_boot_enabled = 0;
35
36 for_each_cpu_mask(cpu, cpu_possible_map)
Steven Rostedt3928a8a2008-09-29 23:02:41 -040037 tracing_reset(tr, cpu);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010038}
39
40static void boot_trace_ctrl_update(struct trace_array *tr)
41{
42 if (tr->ctrl)
43 start_boot_trace();
44 else
45 stop_boot_trace(tr);
46}
47
48static int initcall_print_line(struct trace_iterator *iter)
49{
Frédéric Weisbecker7c572ac2008-09-25 13:25:30 +010050 int ret = 0;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010051 struct trace_entry *entry = iter->ent;
52 struct boot_trace *it = &entry->field.initcall;
53 struct trace_seq *s = &iter->seq;
54
55 if (iter->ent->type == TRACE_BOOT)
56 ret = trace_seq_printf(s, "%pF called from %i "
57 "returned %d after %lld msecs\n",
58 it->func, it->caller, it->result,
59 it->duration);
60 if (ret)
61 return 1;
62 return 0;
63}
64
65struct tracer boot_tracer __read_mostly =
66{
67 .name = "initcall",
68 .init = boot_trace_init,
69 .reset = stop_boot_trace,
70 .ctrl_update = boot_trace_ctrl_update,
71 .print_line = initcall_print_line,
72};
73
74
75void trace_boot(struct boot_trace *it)
76{
Steven Rostedt3928a8a2008-09-29 23:02:41 -040077 struct ring_buffer_event *event;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010078 struct trace_entry *entry;
79 struct trace_array_cpu *data;
80 unsigned long irq_flags;
81 struct trace_array *tr = boot_trace;
82
83 if (!trace_boot_enabled)
84 return;
85
86 preempt_disable();
87 data = tr->data[smp_processor_id()];
88
Steven Rostedt3928a8a2008-09-29 23:02:41 -040089 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
90 &irq_flags);
91 if (!event)
92 goto out;
93 entry = ring_buffer_event_data(event);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010094 tracing_generic_entry_update(entry, 0);
95 entry->type = TRACE_BOOT;
96 entry->field.initcall = *it;
Steven Rostedt3928a8a2008-09-29 23:02:41 -040097 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010098
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010099 trace_wake_up();
100
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400101 out:
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100102 preempt_enable();
103}