blob: b9dc2c0093ab19057cea2196ddb016fc8243ed88 [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>
Frederic Weisbecker56010202008-10-02 13:26:05 +020011#include <linux/kallsyms.h>
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010012
13#include "trace.h"
14
15static struct trace_array *boot_trace;
16static int trace_boot_enabled;
17
18
19/* Should be started after do_pre_smp_initcalls() in init/main.c */
20void start_boot_trace(void)
21{
22 trace_boot_enabled = 1;
23}
24
25void stop_boot_trace(struct trace_array *tr)
26{
27 trace_boot_enabled = 0;
28}
29
30static void boot_trace_init(struct trace_array *tr)
31{
32 int cpu;
33 boot_trace = tr;
34
35 trace_boot_enabled = 0;
36
37 for_each_cpu_mask(cpu, cpu_possible_map)
Steven Rostedt3928a8a2008-09-29 23:02:41 -040038 tracing_reset(tr, cpu);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010039}
40
41static void boot_trace_ctrl_update(struct trace_array *tr)
42{
43 if (tr->ctrl)
44 start_boot_trace();
45 else
46 stop_boot_trace(tr);
47}
48
Frederic Weisbecker9e9efff2008-09-29 20:31:58 +020049static enum print_line_t initcall_print_line(struct trace_iterator *iter)
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010050{
Frederic Weisbecker9e9efff2008-09-29 20:31:58 +020051 int ret;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010052 struct trace_entry *entry = iter->ent;
Steven Rostedt777e2082008-09-29 23:02:42 -040053 struct trace_boot *field = (struct trace_boot *)entry;
54 struct boot_trace *it = &field->initcall;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010055 struct trace_seq *s = &iter->seq;
Frederic Weisbeckercb5ab742008-10-02 12:59:20 +020056 struct timespec calltime = ktime_to_timespec(it->calltime);
57 struct timespec rettime = ktime_to_timespec(it->rettime);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010058
Frederic Weisbecker9e9efff2008-09-29 20:31:58 +020059 if (entry->type == TRACE_BOOT) {
Frederic Weisbecker56010202008-10-02 13:26:05 +020060 ret = trace_seq_printf(s, "[%5ld.%06ld] calling %s @ %i\n",
Frederic Weisbeckercb5ab742008-10-02 12:59:20 +020061 calltime.tv_sec,
62 calltime.tv_nsec,
63 it->func, it->caller);
64 if (!ret)
Frederic Weisbecker9e9efff2008-09-29 20:31:58 +020065 return TRACE_TYPE_PARTIAL_LINE;
Frederic Weisbecker56010202008-10-02 13:26:05 +020066
67 ret = trace_seq_printf(s, "[%5ld.%06ld] initcall %s "
Frederic Weisbeckercb5ab742008-10-02 12:59:20 +020068 "returned %d after %lld msecs\n",
69 rettime.tv_sec,
70 rettime.tv_nsec,
71 it->func, it->result, it->duration);
Frederic Weisbecker56010202008-10-02 13:26:05 +020072
Frederic Weisbeckercb5ab742008-10-02 12:59:20 +020073 if (!ret)
74 return TRACE_TYPE_PARTIAL_LINE;
75 return TRACE_TYPE_HANDLED;
Frederic Weisbecker9e9efff2008-09-29 20:31:58 +020076 }
77 return TRACE_TYPE_UNHANDLED;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010078}
79
80struct tracer boot_tracer __read_mostly =
81{
82 .name = "initcall",
83 .init = boot_trace_init,
84 .reset = stop_boot_trace,
85 .ctrl_update = boot_trace_ctrl_update,
86 .print_line = initcall_print_line,
87};
88
Frederic Weisbecker56010202008-10-02 13:26:05 +020089void trace_boot(struct boot_trace *it, initcall_t fn)
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010090{
Steven Rostedt3928a8a2008-09-29 23:02:41 -040091 struct ring_buffer_event *event;
Steven Rostedt777e2082008-09-29 23:02:42 -040092 struct trace_boot *entry;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010093 struct trace_array_cpu *data;
94 unsigned long irq_flags;
95 struct trace_array *tr = boot_trace;
96
97 if (!trace_boot_enabled)
98 return;
99
Frederic Weisbecker56010202008-10-02 13:26:05 +0200100 /* Get its name now since this function could
101 * disappear because it is in the .init section.
102 */
103 sprint_symbol(it->func, (unsigned long)fn);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100104 preempt_disable();
105 data = tr->data[smp_processor_id()];
106
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400107 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
108 &irq_flags);
109 if (!event)
110 goto out;
111 entry = ring_buffer_event_data(event);
Steven Rostedt38697052008-10-01 13:14:09 -0400112 tracing_generic_entry_update(&entry->ent, 0, 0);
Steven Rostedt777e2082008-09-29 23:02:42 -0400113 entry->ent.type = TRACE_BOOT;
114 entry->initcall = *it;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400115 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100116
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100117 trace_wake_up();
118
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400119 out:
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100120 preempt_enable();
121}