From: "Frédéric Weisbecker" <fweisbec@gmail.com>
To: Ingo Molnar <mingo@elte.hu>,
linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Steven Noonan <steven@uplinklabs.net>,
Arjan van de Ven <arjan@infradead.org>
Subject: [Patch -tip 1/4] Tracing/ftrace: Add the initcall tracer
Date: Tue, 23 Sep 2008 11:32:08 +0100 [thread overview]
Message-ID: <48D8C5A8.3080803@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 451 bytes --]
Add the initcall tracer. It will be able to trace the initcalls which follow SMP initialization.
It is intended to be used with scripts/bootgraph.pl after some small improvements.
Note that it is not active after its init. To avoid tracing (and so crashing) before the whole tracing engine init,
you have to explicitly call start_initcall_trace() after do_pre_smp_initcalls() to enable it.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
[-- Attachment #2: patch1.diff --]
[-- Type: text/plain, Size: 3998 bytes --]
diff --git a/dev/null b/kernel/trace/trace_initcall.c
new file mode 100644
index 0000000..139bb9b
--- /dev/null
+++ b/kernel/trace/trace_initcall.c
@@ -0,0 +1,101 @@
+/*
+ * ring buffer based initcalls tracer
+ *
+ * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/debugfs.h>
+#include <linux/ftrace.h>
+
+#include "trace.h"
+
+static struct trace_array *initcall_trace;
+static int trace_initcall_enabled;
+
+
+/* Should be started after do_pre_smp_initcalls() in init/main.c */
+void start_initcall_trace(void)
+{
+ trace_initcall_enabled = 1;
+}
+
+void stop_initcall_trace(struct trace_array *tr)
+{
+ trace_initcall_enabled = 0;
+}
+
+static void initcall_trace_init(struct trace_array *tr)
+{
+ int cpu;
+ initcall_trace = tr;
+
+ trace_initcall_enabled = 0;
+
+ for_each_cpu_mask(cpu, cpu_possible_map)
+ tracing_reset(tr->data[cpu]);
+}
+
+static void initcall_trace_ctrl_update(struct trace_array *tr)
+{
+ if (tr->ctrl)
+ start_initcall_trace();
+ else
+ stop_initcall_trace(tr);
+}
+
+static int initcall_print_line(struct trace_iterator *iter)
+{
+ int ret = 1;
+ struct trace_entry *entry = iter->ent;
+ struct initcall_trace *it = &entry->field.initcall;
+ struct trace_seq *s = &iter->seq;
+
+ if (iter->ent->type == TRACE_INITCALL)
+ ret = trace_seq_printf(s, "%pF called from %i "
+ "returned %d after %Ld msecs\n",
+ it->func, it->caller, it->result,
+ it->duration);
+ if (ret)
+ return 1;
+ return 0;
+}
+
+struct tracer initcall_tracer __read_mostly =
+{
+ .name = "initcall",
+ .init = initcall_trace_init,
+ .reset = stop_initcall_trace,
+ .ctrl_update = initcall_trace_ctrl_update,
+ .print_line = initcall_print_line,
+};
+
+
+void trace_initcall(struct initcall_trace *it)
+{
+ struct trace_entry *entry;
+ struct trace_array_cpu *data;
+ unsigned long irq_flags;
+ struct trace_array *tr = initcall_trace;
+
+ if (!trace_initcall_enabled)
+ return;
+
+ preempt_disable();
+ data = tr->data[smp_processor_id()];
+
+ raw_local_irq_save(irq_flags);
+ __raw_spin_lock(&data->lock);
+
+ entry = tracing_get_trace_entry(tr, data);
+ tracing_generic_entry_update(entry, 0);
+ entry->type = TRACE_INITCALL;
+ entry->field.initcall = *it;
+
+ __raw_spin_unlock(&data->lock);
+ raw_local_irq_restore(irq_flags);
+ trace_wake_up();
+
+ preempt_enable();
+}
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index cb2c3fb..597c5e8 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -6,6 +6,7 @@
#include <linux/sched.h>
#include <linux/clocksource.h>
#include <linux/mmiotrace.h>
+#include <linux/ftrace.h>
enum trace_type {
__TRACE_FIRST_TYPE = 0,
@@ -19,6 +20,7 @@ enum trace_type {
TRACE_SPECIAL,
TRACE_MMIO_RW,
TRACE_MMIO_MAP,
+ TRACE_INITCALL,
__TRACE_LAST_TYPE
};
@@ -108,6 +110,7 @@ struct trace_field {
struct print_entry print;
struct mmiotrace_rw mmiorw;
struct mmiotrace_map mmiomap;
+ struct initcall_trace initcall;
};
};
@@ -370,5 +373,6 @@ enum trace_iterator_flags {
};
extern struct tracer nop_trace;
+extern struct tracer initcall_tracer;
#endif /* _LINUX_KERNEL_TRACE_H */
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 5de9903..b96b342 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -5,6 +5,8 @@
#include <linux/linkage.h>
#include <linux/fs.h>
+#include <linux/init.h>
+#include <linux/types.h>
extern int ftrace_enabled;
extern int
@@ -209,4 +211,21 @@ ftrace_init_module(unsigned long *start, unsigned long *end) { }
#endif
+struct initcall_trace {
+ pid_t caller;
+ initcall_t func;
+ int result;
+ unsigned long long duration;
+};
+
+#ifdef CONFIG_INITCALL_TRACER
+extern void trace_initcall(struct initcall_trace *it);
+extern void start_initcall_trace(void);
+#else
+static inline void trace_initcall(struct initcall_trace *it) { }
+static inline void start_initcall_trace(void) { }
+#endif
+
+
+
#endif /* _LINUX_FTRACE_H */
reply other threads:[~2008-09-23 9:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48D8C5A8.3080803@gmail.com \
--to=fweisbec@gmail.com \
--cc=arjan@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=steven@uplinklabs.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.