forked from luck/tmp_suning_uos_patched
bd8ac686c7
here is a patch that makes mmiotrace work almost well within the tracing framework. The patch applies on top of my previous patch. I have my own output formatting in place now. Summary of changes: - fix the NULL dereference that was due to not calling tracing_reset() - add print_line() callback into struct tracer - implement print_line() for mmiotrace, producing up-to-spec text - add my output header, but that is not really called in the right place - rewrote the main structs in mmiotrace - added two new trace entry types: TRACE_MMIO_RW and TRACE_MMIO_MAP - made some functions in trace.c non-static - check current==NULL in tracing_generic_entry_update() - fix(?) comparison in trace_seq_printf() Things seem to work fine except a few issues. Markers (text lines injected into mmiotrace log) are missing, I did not feel hacking them in before we have variable length entries. My output header is printed only for 'trace' file, but not 'trace_pipe'. For some reason, despite my quick fix, iter->trace is NULL in print_trace_line() when called from 'trace_pipe' file, which means I don't get proper output formatting. I only tried by loading nouveau.ko, which just detects the card, and that is traced fine. I didn't try further. Map, two reads and unmap. Works perfectly. I am missing the information about overflows, I'd prefer to have a counter for lost events. I didn't try, but I guess currently there is no way of knowning when it overflows? So, not too far from being fully operational, it seems :-) And looking at the diffstat, there also is some 700-900 lines of user space code that just became obsolete. Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
180 lines
4.1 KiB
C
180 lines
4.1 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"
|
|
|
|
static struct trace_array *mmio_trace_array;
|
|
|
|
static void mmio_reset_data(struct trace_array *tr)
|
|
{
|
|
int cpu;
|
|
|
|
tr->time_start = ftrace_now(tr->cpu);
|
|
|
|
for_each_online_cpu(cpu)
|
|
tracing_reset(tr->data[cpu]);
|
|
}
|
|
|
|
static void mmio_trace_init(struct trace_array *tr)
|
|
{
|
|
pr_debug("in %s\n", __func__);
|
|
mmio_trace_array = tr;
|
|
if (tr->ctrl) {
|
|
mmio_reset_data(tr);
|
|
enable_mmiotrace();
|
|
}
|
|
}
|
|
|
|
static void mmio_trace_reset(struct trace_array *tr)
|
|
{
|
|
pr_debug("in %s\n", __func__);
|
|
if (tr->ctrl)
|
|
disable_mmiotrace();
|
|
mmio_reset_data(tr);
|
|
mmio_trace_array = NULL;
|
|
}
|
|
|
|
static void mmio_trace_ctrl_update(struct trace_array *tr)
|
|
{
|
|
pr_debug("in %s\n", __func__);
|
|
if (tr->ctrl) {
|
|
mmio_reset_data(tr);
|
|
enable_mmiotrace();
|
|
} else {
|
|
disable_mmiotrace();
|
|
}
|
|
}
|
|
|
|
/* XXX: This is not called for trace_pipe file! */
|
|
void mmio_print_header(struct trace_iterator *iter)
|
|
{
|
|
struct trace_seq *s = &iter->seq;
|
|
trace_seq_printf(s, "VERSION broken 20070824\n");
|
|
/* TODO: print /proc/bus/pci/devices contents as PCIDEV lines */
|
|
}
|
|
|
|
static int mmio_print_rw(struct trace_iterator *iter)
|
|
{
|
|
struct trace_entry *entry = iter->ent;
|
|
struct mmiotrace_rw *rw = &entry->mmiorw;
|
|
struct trace_seq *s = &iter->seq;
|
|
unsigned long long t = ns2usecs(entry->t);
|
|
unsigned long usec_rem = do_div(t, 1000000ULL);
|
|
unsigned secs = (unsigned long)t;
|
|
int ret = 1;
|
|
|
|
switch (entry->mmiorw.opcode) {
|
|
case MMIO_READ:
|
|
ret = trace_seq_printf(s,
|
|
"R %d %lu.%06lu %d 0x%lx 0x%lx 0x%lx %d\n",
|
|
rw->width, secs, usec_rem, rw->map_id, rw->phys,
|
|
rw->value, rw->pc, entry->pid);
|
|
break;
|
|
case MMIO_WRITE:
|
|
ret = trace_seq_printf(s,
|
|
"W %d %lu.%06lu %d 0x%lx 0x%lx 0x%lx %d\n",
|
|
rw->width, secs, usec_rem, rw->map_id, rw->phys,
|
|
rw->value, rw->pc, entry->pid);
|
|
break;
|
|
case MMIO_UNKNOWN_OP:
|
|
ret = trace_seq_printf(s,
|
|
"UNKNOWN %lu.%06lu %d 0x%lx %02x,%02x,%02x 0x%lx %d\n",
|
|
secs, usec_rem, rw->map_id, rw->phys,
|
|
(rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff,
|
|
(rw->value >> 0) & 0xff, rw->pc, entry->pid);
|
|
break;
|
|
default:
|
|
ret = trace_seq_printf(s, "rw what?\n");
|
|
break;
|
|
}
|
|
if (ret)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
static int mmio_print_map(struct trace_iterator *iter)
|
|
{
|
|
struct trace_entry *entry = iter->ent;
|
|
struct mmiotrace_map *m = &entry->mmiomap;
|
|
struct trace_seq *s = &iter->seq;
|
|
unsigned long long t = ns2usecs(entry->t);
|
|
unsigned long usec_rem = do_div(t, 1000000ULL);
|
|
unsigned secs = (unsigned long)t;
|
|
int ret = 1;
|
|
|
|
switch (entry->mmiorw.opcode) {
|
|
case MMIO_PROBE:
|
|
ret = trace_seq_printf(s,
|
|
"MAP %lu.%06lu %d 0x%lx 0x%lx 0x%lx 0x%lx %d\n",
|
|
secs, usec_rem, m->map_id, m->phys, m->virt, m->len,
|
|
0UL, entry->pid);
|
|
break;
|
|
case MMIO_UNPROBE:
|
|
ret = trace_seq_printf(s,
|
|
"UNMAP %lu.%06lu %d 0x%lx %d\n",
|
|
secs, usec_rem, m->map_id, 0UL, entry->pid);
|
|
break;
|
|
default:
|
|
ret = trace_seq_printf(s, "map what?\n");
|
|
break;
|
|
}
|
|
if (ret)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
/* return 0 to abort printing without consuming current entry in pipe mode */
|
|
static int mmio_print_line(struct trace_iterator *iter)
|
|
{
|
|
switch (iter->ent->type) {
|
|
case TRACE_MMIO_RW:
|
|
return mmio_print_rw(iter);
|
|
case TRACE_MMIO_MAP:
|
|
return mmio_print_map(iter);
|
|
default:
|
|
return 1; /* ignore unknown entries */
|
|
}
|
|
}
|
|
|
|
static struct tracer mmio_tracer __read_mostly =
|
|
{
|
|
.name = "mmiotrace",
|
|
.init = mmio_trace_init,
|
|
.reset = mmio_trace_reset,
|
|
.open = mmio_print_header,
|
|
.ctrl_update = mmio_trace_ctrl_update,
|
|
.print_line = mmio_print_line,
|
|
};
|
|
|
|
__init static int init_mmio_trace(void)
|
|
{
|
|
return register_tracer(&mmio_tracer);
|
|
}
|
|
device_initcall(init_mmio_trace);
|
|
|
|
void mmio_trace_rw(struct mmiotrace_rw *rw)
|
|
{
|
|
struct trace_array *tr = mmio_trace_array;
|
|
struct trace_array_cpu *data = tr->data[smp_processor_id()];
|
|
__trace_mmiotrace_rw(tr, data, rw);
|
|
}
|
|
|
|
void mmio_trace_mapping(struct mmiotrace_map *map)
|
|
{
|
|
struct trace_array *tr = mmio_trace_array;
|
|
struct trace_array_cpu *data;
|
|
|
|
preempt_disable();
|
|
data = tr->data[smp_processor_id()];
|
|
__trace_mmiotrace_map(tr, data, map);
|
|
preempt_enable();
|
|
}
|