nommu: ramfs: pages allocated to an inode's pagecache may get wrongly discarded
[safe/jmp/linux-2.6] / kernel / trace / trace_mmiotrace.c
index 1a266aa..80e503e 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/kernel.h>
 #include <linux/mmiotrace.h>
 #include <linux/pci.h>
+#include <asm/atomic.h>
 
 #include "trace.h"
 
@@ -18,46 +19,40 @@ struct header_iter {
 
 static struct trace_array *mmio_trace_array;
 static bool overrun_detected;
+static unsigned long prev_overruns;
+static atomic_t dropped_count;
 
 static void mmio_reset_data(struct trace_array *tr)
 {
-       int cpu;
-
        overrun_detected = false;
-       tr->time_start = ftrace_now(tr->cpu);
+       prev_overruns = 0;
 
-       for_each_online_cpu(cpu)
-               tracing_reset(tr, cpu);
+       tracing_reset_online_cpus(tr);
 }
 
-static void mmio_trace_init(struct trace_array *tr)
+static int 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();
-       }
+
+       mmio_reset_data(tr);
+       enable_mmiotrace();
+       return 0;
 }
 
 static void mmio_trace_reset(struct trace_array *tr)
 {
        pr_debug("in %s\n", __func__);
-       if (tr->ctrl)
-               disable_mmiotrace();
+
+       disable_mmiotrace();
        mmio_reset_data(tr);
        mmio_trace_array = NULL;
 }
 
-static void mmio_trace_ctrl_update(struct trace_array *tr)
+static void mmio_trace_start(struct trace_array *tr)
 {
        pr_debug("in %s\n", __func__);
-       if (tr->ctrl) {
-               mmio_reset_data(tr);
-               enable_mmiotrace();
-       } else {
-               disable_mmiotrace();
-       }
+       mmio_reset_data(tr);
 }
 
 static int mmio_print_pcidev(struct trace_seq *s, const struct pci_dev *dev)
@@ -128,16 +123,12 @@ static void mmio_close(struct trace_iterator *iter)
 
 static unsigned long count_overruns(struct trace_iterator *iter)
 {
-       int cpu;
-       unsigned long cnt = 0;
-/* FIXME: */
-#if 0
-       for_each_online_cpu(cpu) {
-               cnt += iter->overrun[cpu];
-               iter->overrun[cpu] = 0;
-       }
-#endif
-       (void)cpu;
+       unsigned long cnt = atomic_xchg(&dropped_count, 0);
+       unsigned long over = ring_buffer_overruns(iter->tr->buffer);
+
+       if (over > prev_overruns)
+               cnt += over - prev_overruns;
+       prev_overruns = over;
        return cnt;
 }
 
@@ -178,15 +169,17 @@ print_out:
 static enum print_line_t mmio_print_rw(struct trace_iterator *iter)
 {
        struct trace_entry *entry = iter->ent;
-       struct trace_mmiotrace_rw *field =
-               (struct trace_mmiotrace_rw *)entry;
-       struct mmiotrace_rw *rw = &field->rw;
+       struct trace_mmiotrace_rw *field;
+       struct mmiotrace_rw *rw;
        struct trace_seq *s     = &iter->seq;
        unsigned long long t    = ns2usecs(iter->ts);
        unsigned long usec_rem  = do_div(t, 1000000ULL);
        unsigned secs           = (unsigned long)t;
        int ret = 1;
 
+       trace_assign_type(field, entry);
+       rw = &field->rw;
+
        switch (rw->opcode) {
        case MMIO_READ:
                ret = trace_seq_printf(s,
@@ -222,13 +215,17 @@ static enum print_line_t mmio_print_rw(struct trace_iterator *iter)
 static enum print_line_t mmio_print_map(struct trace_iterator *iter)
 {
        struct trace_entry *entry = iter->ent;
-       struct mmiotrace_map *m = (struct mmiotrace_map *)entry;
+       struct trace_mmiotrace_map *field;
+       struct mmiotrace_map *m;
        struct trace_seq *s     = &iter->seq;
        unsigned long long t    = ns2usecs(iter->ts);
        unsigned long usec_rem  = do_div(t, 1000000ULL);
        unsigned secs           = (unsigned long)t;
        int ret;
 
+       trace_assign_type(field, entry);
+       m = &field->map;
+
        switch (m->opcode) {
        case MMIO_PROBE:
                ret = trace_seq_printf(s,
@@ -292,10 +289,10 @@ static struct tracer mmio_tracer __read_mostly =
        .name           = "mmiotrace",
        .init           = mmio_trace_init,
        .reset          = mmio_trace_reset,
+       .start          = mmio_trace_start,
        .pipe_open      = mmio_pipe_open,
        .close          = mmio_close,
        .read           = mmio_read,
-       .ctrl_update    = mmio_trace_ctrl_update,
        .print_line     = mmio_print_line,
 };
 
@@ -315,10 +312,12 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
 
        event   = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
                                           &irq_flags);
-       if (!event)
+       if (!event) {
+               atomic_inc(&dropped_count);
                return;
+       }
        entry   = ring_buffer_event_data(event);
-       tracing_generic_entry_update(&entry->ent, 0);
+       tracing_generic_entry_update(&entry->ent, 0, preempt_count());
        entry->ent.type                 = TRACE_MMIO_RW;
        entry->rw                       = *rw;
        ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
@@ -343,10 +342,12 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
 
        event   = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
                                           &irq_flags);
-       if (!event)
+       if (!event) {
+               atomic_inc(&dropped_count);
                return;
+       }
        entry   = ring_buffer_event_data(event);
-       tracing_generic_entry_update(&entry->ent, 0);
+       tracing_generic_entry_update(&entry->ent, 0, preempt_count());
        entry->ent.type                 = TRACE_MMIO_MAP;
        entry->map                      = *map;
        ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
@@ -367,5 +368,5 @@ void mmio_trace_mapping(struct mmiotrace_map *map)
 
 int mmio_trace_printk(const char *fmt, va_list args)
 {
-       return trace_vprintk(0, fmt, args);
+       return trace_vprintk(0, -1, fmt, args);
 }