linux/kernel/trace/trace_mmiotrace.c
Pekka Paalanen f984b51e07 ftrace: add mmiotrace plugin
On Sat, 22 Mar 2008 13:07:47 +0100
Ingo Molnar <mingo@elte.hu> wrote:

> > > i'd suggest the following: pull x86.git and sched-devel.git into a
> > > single tree [the two will combine without rejects]. Then try to add a
> > > kernel/tracing/trace_mmiotrace.c ftrace plugin. The trace_sysprof.c
> > > plugin might be a good example.
> >
> > I did this and now I have mmiotrace enabled/disabled via the tracing
> > framework (what do we call this, since ftrace is one of the tracers?).
>
> cool! could you send the patches for that? (even if they are not fully
> functional yet)

Patch attached in the end. Nice to see how much code disappeared. I tried
to mark all the features I had to break with XXX-comments.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-24 11:22:43 +02:00

84 lines
1.7 KiB
C

/*
* Memory mapped I/O tracing
*
* Copyright (C) 2008 Pekka Paalanen <pq@iki.fi>
*/
#define DEBUG 1
#include <linux/kernel.h>
#include <linux/mmiotrace.h>
#include "trace.h"
extern void
__trace_special(void *__tr, void *__data,
unsigned long arg1, unsigned long arg2, unsigned long arg3);
static struct trace_array *mmio_trace_array;
static void mmio_trace_init(struct trace_array *tr)
{
pr_debug("in %s\n", __func__);
mmio_trace_array = tr;
if (tr->ctrl)
enable_mmiotrace();
}
static void mmio_trace_reset(struct trace_array *tr)
{
pr_debug("in %s\n", __func__);
if (tr->ctrl)
disable_mmiotrace();
}
static void mmio_trace_ctrl_update(struct trace_array *tr)
{
pr_debug("in %s\n", __func__);
if (tr->ctrl)
enable_mmiotrace();
else
disable_mmiotrace();
}
static struct tracer mmio_tracer __read_mostly =
{
.name = "mmiotrace",
.init = mmio_trace_init,
.reset = mmio_trace_reset,
.ctrl_update = mmio_trace_ctrl_update,
};
__init static int init_mmio_trace(void)
{
int ret = init_mmiotrace();
if (ret)
return ret;
return register_tracer(&mmio_tracer);
}
device_initcall(init_mmio_trace);
void mmio_trace_record(u32 type, unsigned long addr, unsigned long arg)
{
struct trace_array *tr = mmio_trace_array;
struct trace_array_cpu *data = tr->data[smp_processor_id()];
if (!current || current->pid == 0) {
/*
* XXX: This is a problem. We need to able to record, no
* matter what. tracing_generic_entry_update() would crash.
*/
static unsigned limit;
if (limit++ < 12)
pr_err("Error in %s: no current.\n", __func__);
return;
}
if (!tr || !data) {
static unsigned limit;
if (limit++ < 12)
pr_err("%s: no tr or data\n", __func__);
return;
}
__trace_special(tr, data, type, addr, arg);
}