Merge branches 'tracing/docs', 'tracing/filters', 'tracing/ftrace', 'tracing/kprobes...
authorIngo Molnar <mingo@elte.hu>
Tue, 31 Mar 2009 15:46:40 +0000 (17:46 +0200)
committerIngo Molnar <mingo@elte.hu>
Tue, 31 Mar 2009 15:46:40 +0000 (17:46 +0200)
16 files changed:
Documentation/tracepoints.txt
arch/x86/kernel/kprobes.c
include/linux/ring_buffer.h
kernel/extable.c
kernel/trace/Makefile
kernel/trace/blktrace.c
kernel/trace/ring_buffer.c
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_events.c
kernel/trace/trace_events_filter.c [new file with mode: 0644]
kernel/trace/trace_events_stage_2.h
kernel/trace/trace_events_stage_3.h
kernel/trace/trace_nop.c
mm/memory.c
samples/tracepoints/tracepoint-sample.c

index 4ff43c6de299c32a40f6e718b19b7fcffedeae6f..c0e1ceed75a441b692bf447b3fcdc49d8abdd1cc 100644 (file)
@@ -103,13 +103,14 @@ used to export the defined tracepoints.
 
 * Probe / tracepoint example
 
-See the example provided in samples/tracepoints/src
+See the example provided in samples/tracepoints
 
-Compile them with your kernel.
+Compile them with your kernel.  They are built during 'make' (not
+'make modules') when CONFIG_SAMPLE_TRACEPOINTS=m.
 
 Run, as root :
-modprobe tracepoint-example (insmod order is not important)
-modprobe tracepoint-probe-example
-cat /proc/tracepoint-example (returns an expected error)
-rmmod tracepoint-example tracepoint-probe-example
+modprobe tracepoint-sample (insmod order is not important)
+modprobe tracepoint-probe-sample
+cat /proc/tracepoint-sample (returns an expected error)
+rmmod tracepoint-sample tracepoint-probe-sample
 dmesg
index 4558dd3918cf3ec66263d7ac8e705acb4a5ea5a9..759095d53a06f9e2913663cfedff5f57dc773818 100644 (file)
@@ -638,13 +638,13 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
 #else
                        "       pushf\n"
                        /*
-                        * Skip cs, ip, orig_ax.
+                        * Skip cs, ip, orig_ax and gs.
                         * trampoline_handler() will plug in these values
                         */
-                       "       subl $12, %esp\n"
+                       "       subl $16, %esp\n"
                        "       pushl %fs\n"
-                       "       pushl %ds\n"
                        "       pushl %es\n"
+                       "       pushl %ds\n"
                        "       pushl %eax\n"
                        "       pushl %ebp\n"
                        "       pushl %edi\n"
@@ -655,10 +655,10 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
                        "       movl %esp, %eax\n"
                        "       call trampoline_handler\n"
                        /* Move flags to cs */
-                       "       movl 52(%esp), %edx\n"
-                       "       movl %edx, 48(%esp)\n"
+                       "       movl 56(%esp), %edx\n"
+                       "       movl %edx, 52(%esp)\n"
                        /* Replace saved flags with true return address. */
-                       "       movl %eax, 52(%esp)\n"
+                       "       movl %eax, 56(%esp)\n"
                        "       popl %ebx\n"
                        "       popl %ecx\n"
                        "       popl %edx\n"
@@ -666,8 +666,8 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
                        "       popl %edi\n"
                        "       popl %ebp\n"
                        "       popl %eax\n"
-                       /* Skip ip, orig_ax, es, ds, fs */
-                       "       addl $20, %esp\n"
+                       /* Skip ds, es, fs, gs, orig_ax and ip */
+                       "       addl $24, %esp\n"
                        "       popf\n"
 #endif
                        "       ret\n");
@@ -691,6 +691,7 @@ static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
        regs->cs = __KERNEL_CS;
 #else
        regs->cs = __KERNEL_CS | get_kernel_rpl();
+       regs->gs = 0;
 #endif
        regs->ip = trampoline_address;
        regs->orig_ax = ~0UL;
index 9e6052bd1a1c9f42edafe3959b5b57e8f652e159..e1b7b2173885f8f14f4a8da3979d0a6eff08e186 100644 (file)
@@ -18,10 +18,13 @@ struct ring_buffer_event {
 /**
  * enum ring_buffer_type - internal ring buffer types
  *
- * @RINGBUF_TYPE_PADDING:      Left over page padding
- *                              array is ignored
- *                              size is variable depending on how much
+ * @RINGBUF_TYPE_PADDING:      Left over page padding or discarded event
+ *                              If time_delta is 0:
+ *                               array is ignored
+ *                               size is variable depending on how much
  *                               padding is needed
+ *                              If time_delta is non zero:
+ *                               everything else same as RINGBUF_TYPE_DATA
  *
  * @RINGBUF_TYPE_TIME_EXTEND:  Extend the time delta
  *                              array[0] = time delta (28 .. 59)
@@ -65,6 +68,8 @@ ring_buffer_event_time_delta(struct ring_buffer_event *event)
        return event->time_delta;
 }
 
+void ring_buffer_event_discard(struct ring_buffer_event *event);
+
 /*
  * size is in bytes for each per CPU buffer.
  */
index 25d39b0c3a1ba4aeba990e169cfa173d32e4eba3..b54a6017b6b57bd77919fedd865b6bba24fcac8e 100644 (file)
@@ -16,6 +16,7 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 #include <linux/ftrace.h>
+#include <linux/memory.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/init.h>
index 0e45c206c2f9f942f1e5119ae09827970a0025e0..2630f5121ec12467a4b05958670aac40f357dcb8 100644 (file)
@@ -45,5 +45,6 @@ obj-$(CONFIG_EVENT_TRACER) += events.o
 obj-$(CONFIG_EVENT_TRACER) += trace_export.o
 obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o
 obj-$(CONFIG_EVENT_PROFILE) += trace_event_profile.o
+obj-$(CONFIG_EVENT_TRACER) += trace_events_filter.o
 
 libftrace-y := ftrace.o
index b171778e3863ddcb4d2d8f6ef1b88cd53818b57d..947c5b3f90c4ce42dd511b04bd9b28ded2842ac3 100644 (file)
@@ -30,7 +30,7 @@
 static unsigned int blktrace_seq __read_mostly = 1;
 
 static struct trace_array *blk_tr;
-static int __read_mostly  blk_tracer_enabled;
+static bool blk_tracer_enabled __read_mostly;
 
 /* Select an alternative, minimalistic output than the original one */
 #define TRACE_BLK_OPT_CLASSIC  0x1
@@ -47,10 +47,9 @@ static struct tracer_flags blk_tracer_flags = {
 };
 
 /* Global reference count of probes */
-static DEFINE_MUTEX(blk_probe_mutex);
 static atomic_t blk_probes_ref = ATOMIC_INIT(0);
 
-static int blk_register_tracepoints(void);
+static void blk_register_tracepoints(void);
 static void blk_unregister_tracepoints(void);
 
 /*
@@ -60,22 +59,39 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
                       const void *data, size_t len)
 {
        struct blk_io_trace *t;
+       struct ring_buffer_event *event = NULL;
+       int pc = 0;
+       int cpu = smp_processor_id();
+       bool blk_tracer = blk_tracer_enabled;
+
+       if (blk_tracer) {
+               pc = preempt_count();
+               event = trace_buffer_lock_reserve(blk_tr, TRACE_BLK,
+                                                 sizeof(*t) + len,
+                                                 0, pc);
+               if (!event)
+                       return;
+               t = ring_buffer_event_data(event);
+               goto record_it;
+       }
 
        if (!bt->rchan)
                return;
 
        t = relay_reserve(bt->rchan, sizeof(*t) + len);
        if (t) {
-               const int cpu = smp_processor_id();
-
                t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
                t->time = ktime_to_ns(ktime_get());
+record_it:
                t->device = bt->dev;
                t->action = action;
                t->pid = pid;
                t->cpu = cpu;
                t->pdu_len = len;
                memcpy((void *) t + sizeof(*t), data, len);
+
+               if (blk_tracer)
+                       trace_buffer_unlock_commit(blk_tr, event, 0, pc);
        }
 }
 
@@ -111,14 +127,8 @@ void __trace_note_message(struct blk_trace *bt, const char *fmt, ...)
        unsigned long flags;
        char *buf;
 
-       if (blk_tr) {
-               va_start(args, fmt);
-               ftrace_vprintk(fmt, args);
-               va_end(args);
-               return;
-       }
-
-       if (!bt->msg_data)
+       if (unlikely(bt->trace_state != Blktrace_running &&
+                    !blk_tracer_enabled))
                return;
 
        local_irq_save(flags);
@@ -148,8 +158,8 @@ static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector,
 /*
  * Data direction bit lookup
  */
-static u32 ddir_act[2] __read_mostly = { BLK_TC_ACT(BLK_TC_READ),
-                                        BLK_TC_ACT(BLK_TC_WRITE) };
+static const u32 ddir_act[2] = { BLK_TC_ACT(BLK_TC_READ),
+                                BLK_TC_ACT(BLK_TC_WRITE) };
 
 /* The ilog2() calls fall out because they're constant */
 #define MASK_TC_BIT(rw, __name) ((rw & (1 << BIO_RW_ ## __name)) << \
@@ -169,9 +179,9 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
        unsigned long *sequence;
        pid_t pid;
        int cpu, pc = 0;
+       bool blk_tracer = blk_tracer_enabled;
 
-       if (unlikely(bt->trace_state != Blktrace_running ||
-                    !blk_tracer_enabled))
+       if (unlikely(bt->trace_state != Blktrace_running && !blk_tracer))
                return;
 
        what |= ddir_act[rw & WRITE];
@@ -186,7 +196,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
                return;
        cpu = raw_smp_processor_id();
 
-       if (blk_tr) {
+       if (blk_tracer) {
                tracing_record_cmdline(current);
 
                pc = preempt_count();
@@ -236,7 +246,7 @@ record_it:
                if (pdu_len)
                        memcpy((void *) t + sizeof(*t), pdu_data, pdu_len);
 
-               if (blk_tr) {
+               if (blk_tracer) {
                        trace_buffer_unlock_commit(blk_tr, event, 0, pc);
                        return;
                }
@@ -248,7 +258,7 @@ record_it:
 static struct dentry *blk_tree_root;
 static DEFINE_MUTEX(blk_tree_mutex);
 
-static void blk_trace_cleanup(struct blk_trace *bt)
+static void blk_trace_free(struct blk_trace *bt)
 {
        debugfs_remove(bt->msg_file);
        debugfs_remove(bt->dropped_file);
@@ -256,10 +266,13 @@ static void blk_trace_cleanup(struct blk_trace *bt)
        free_percpu(bt->sequence);
        free_percpu(bt->msg_data);
        kfree(bt);
-       mutex_lock(&blk_probe_mutex);
+}
+
+static void blk_trace_cleanup(struct blk_trace *bt)
+{
+       blk_trace_free(bt);
        if (atomic_dec_and_test(&blk_probes_ref))
                blk_unregister_tracepoints();
-       mutex_unlock(&blk_probe_mutex);
 }
 
 int blk_trace_remove(struct request_queue *q)
@@ -270,8 +283,7 @@ int blk_trace_remove(struct request_queue *q)
        if (!bt)
                return -EINVAL;
 
-       if (bt->trace_state == Blktrace_setup ||
-           bt->trace_state == Blktrace_stopped)
+       if (bt->trace_state != Blktrace_running)
                blk_trace_cleanup(bt);
 
        return 0;
@@ -414,11 +426,11 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
                if (buts->name[i] == '/')
                        buts->name[i] = '_';
 
-       ret = -ENOMEM;
        bt = kzalloc(sizeof(*bt), GFP_KERNEL);
        if (!bt)
-               goto err;
+               return -ENOMEM;
 
+       ret = -ENOMEM;
        bt->sequence = alloc_percpu(unsigned long);
        if (!bt->sequence)
                goto err;
@@ -429,11 +441,15 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
 
        ret = -ENOENT;
 
+       mutex_lock(&blk_tree_mutex);
        if (!blk_tree_root) {
                blk_tree_root = debugfs_create_dir("block", NULL);
-               if (!blk_tree_root)
-                       return -ENOMEM;
+               if (!blk_tree_root) {
+                       mutex_unlock(&blk_tree_mutex);
+                       goto err;
+               }
        }
+       mutex_unlock(&blk_tree_mutex);
 
        dir = debugfs_create_dir(buts->name, blk_tree_root);
 
@@ -471,14 +487,6 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
        bt->pid = buts->pid;
        bt->trace_state = Blktrace_setup;
 
-       mutex_lock(&blk_probe_mutex);
-       if (atomic_add_return(1, &blk_probes_ref) == 1) {
-               ret = blk_register_tracepoints();
-               if (ret)
-                       goto probe_err;
-       }
-       mutex_unlock(&blk_probe_mutex);
-
        ret = -EBUSY;
        old_bt = xchg(&q->blk_trace, bt);
        if (old_bt) {
@@ -486,22 +494,12 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
                goto err;
        }
 
+       if (atomic_inc_return(&blk_probes_ref) == 1)
+               blk_register_tracepoints();
+
        return 0;
-probe_err:
-       atomic_dec(&blk_probes_ref);
-       mutex_unlock(&blk_probe_mutex);
 err:
-       if (bt) {
-               if (bt->msg_file)
-                       debugfs_remove(bt->msg_file);
-               if (bt->dropped_file)
-                       debugfs_remove(bt->dropped_file);
-               free_percpu(bt->sequence);
-               free_percpu(bt->msg_data);
-               if (bt->rchan)
-                       relay_close(bt->rchan);
-               kfree(bt);
-       }
+       blk_trace_free(bt);
        return ret;
 }
 
@@ -863,7 +861,7 @@ void blk_add_driver_data(struct request_queue *q,
 }
 EXPORT_SYMBOL_GPL(blk_add_driver_data);
 
-static int blk_register_tracepoints(void)
+static void blk_register_tracepoints(void)
 {
        int ret;
 
@@ -901,7 +899,6 @@ static int blk_register_tracepoints(void)
        WARN_ON(ret);
        ret = register_trace_block_remap(blk_add_trace_remap);
        WARN_ON(ret);
-       return 0;
 }
 
 static void blk_unregister_tracepoints(void)
@@ -934,25 +931,31 @@ static void blk_unregister_tracepoints(void)
 static void fill_rwbs(char *rwbs, const struct blk_io_trace *t)
 {
        int i = 0;
+       int tc = t->action >> BLK_TC_SHIFT;
+
+       if (t->action == BLK_TN_MESSAGE) {
+               rwbs[i++] = 'N';
+               goto out;
+       }
 
-       if (t->action & BLK_TC_DISCARD)
+       if (tc & BLK_TC_DISCARD)
                rwbs[i++] = 'D';
-       else if (t->action & BLK_TC_WRITE)
+       else if (tc & BLK_TC_WRITE)
                rwbs[i++] = 'W';
        else if (t->bytes)
                rwbs[i++] = 'R';
        else
                rwbs[i++] = 'N';
 
-       if (t->action & BLK_TC_AHEAD)
+       if (tc & BLK_TC_AHEAD)
                rwbs[i++] = 'A';
-       if (t->action & BLK_TC_BARRIER)
+       if (tc & BLK_TC_BARRIER)
                rwbs[i++] = 'B';
-       if (t->action & BLK_TC_SYNC)
+       if (tc & BLK_TC_SYNC)
                rwbs[i++] = 'S';
-       if (t->action & BLK_TC_META)
+       if (tc & BLK_TC_META)
                rwbs[i++] = 'M';
-
+out:
        rwbs[i] = '\0';
 }
 
@@ -979,7 +982,7 @@ static inline unsigned long long t_sector(const struct trace_entry *ent)
 
 static inline __u16 t_error(const struct trace_entry *ent)
 {
-       return te_blk_io_trace(ent)->sector;
+       return te_blk_io_trace(ent)->error;
 }
 
 static __u64 get_pdu_int(const struct trace_entry *ent)
@@ -999,29 +1002,31 @@ static void get_pdu_remap(const struct trace_entry *ent,
        r->sector = be64_to_cpu(sector);
 }
 
-static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
+typedef int (blk_log_action_t) (struct trace_iterator *iter, const char *act);
+
+static int blk_log_action_classic(struct trace_iterator *iter, const char *act)
 {
        char rwbs[6];
-       unsigned long long ts  = ns2usecs(iter->ts);
-       unsigned long usec_rem = do_div(ts, USEC_PER_SEC);
+       unsigned long long ts  = iter->ts;
+       unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC);
        unsigned secs          = (unsigned long)ts;
-       const struct trace_entry *ent = iter->ent;
-       const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
+       const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
 
        fill_rwbs(rwbs, t);
 
        return trace_seq_printf(&iter->seq,
-                               "%3d,%-3d %2d %5d.%06lu %5u %2s %3s ",
+                               "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ",
                                MAJOR(t->device), MINOR(t->device), iter->cpu,
-                               secs, usec_rem, ent->pid, act, rwbs);
+                               secs, nsec_rem, iter->ent->pid, act, rwbs);
 }
 
-static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t,
-                             const char *act)
+static int blk_log_action(struct trace_iterator *iter, const char *act)
 {
        char rwbs[6];
+       const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
+
        fill_rwbs(rwbs, t);
-       return trace_seq_printf(s, "%3d,%-3d %2s %3s ",
+       return trace_seq_printf(&iter->seq, "%3d,%-3d %2s %3s ",
                                MAJOR(t->device), MINOR(t->device), act, rwbs);
 }
 
@@ -1085,6 +1090,17 @@ static int blk_log_split(struct trace_seq *s, const struct trace_entry *ent)
                                get_pdu_int(ent), cmd);
 }
 
+static int blk_log_msg(struct trace_seq *s, const struct trace_entry *ent)
+{
+       int ret;
+       const struct blk_io_trace *t = te_blk_io_trace(ent);
+
+       ret = trace_seq_putmem(s, t + 1, t->pdu_len);
+       if (ret)
+               return trace_seq_putc(s, '\n');
+       return ret;
+}
+
 /*
  * struct tracer operations
  */
@@ -1099,11 +1115,7 @@ static void blk_tracer_print_header(struct seq_file *m)
 
 static void blk_tracer_start(struct trace_array *tr)
 {
-       mutex_lock(&blk_probe_mutex);
-       if (atomic_add_return(1, &blk_probes_ref) == 1)
-               if (blk_register_tracepoints())
-                       atomic_dec(&blk_probes_ref);
-       mutex_unlock(&blk_probe_mutex);
+       blk_tracer_enabled = true;
        trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
 }
 
@@ -1111,38 +1123,24 @@ static int blk_tracer_init(struct trace_array *tr)
 {
        blk_tr = tr;
        blk_tracer_start(tr);
-       mutex_lock(&blk_probe_mutex);
-       blk_tracer_enabled++;
-       mutex_unlock(&blk_probe_mutex);
        return 0;
 }
 
 static void blk_tracer_stop(struct trace_array *tr)
 {
+       blk_tracer_enabled = false;
        trace_flags |= TRACE_ITER_CONTEXT_INFO;
-       mutex_lock(&blk_probe_mutex);
-       if (atomic_dec_and_test(&blk_probes_ref))
-               blk_unregister_tracepoints();
-       mutex_unlock(&blk_probe_mutex);
 }
 
 static void blk_tracer_reset(struct trace_array *tr)
 {
-       if (!atomic_read(&blk_probes_ref))
-               return;
-
-       mutex_lock(&blk_probe_mutex);
-       blk_tracer_enabled--;
-       WARN_ON(blk_tracer_enabled < 0);
-       mutex_unlock(&blk_probe_mutex);
-
        blk_tracer_stop(tr);
 }
 
-static struct {
+static const struct {
        const char *act[2];
        int        (*print)(struct trace_seq *s, const struct trace_entry *ent);
-} what2act[] __read_mostly = {
+} what2act[] = {
        [__BLK_TA_QUEUE]        = {{  "Q", "queue" },      blk_log_generic },
        [__BLK_TA_BACKMERGE]    = {{  "M", "backmerge" },  blk_log_generic },
        [__BLK_TA_FRONTMERGE]   = {{  "F", "frontmerge" }, blk_log_generic },
@@ -1160,29 +1158,48 @@ static struct {
        [__BLK_TA_REMAP]        = {{  "A", "remap" },      blk_log_remap },
 };
 
-static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
-                                              int flags)
+static enum print_line_t print_one_line(struct trace_iterator *iter,
+                                       bool classic)
 {
        struct trace_seq *s = &iter->seq;
-       const struct blk_io_trace *t = (struct blk_io_trace *)iter->ent;
-       const u16 what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+       const struct blk_io_trace *t;
+       u16 what;
        int ret;
+       bool long_act;
+       blk_log_action_t *log_action;
 
-       if (!trace_print_context(iter))
-               return TRACE_TYPE_PARTIAL_LINE;
+       t          = te_blk_io_trace(iter->ent);
+       what       = t->action & ((1 << BLK_TC_SHIFT) - 1);
+       long_act   = !!(trace_flags & TRACE_ITER_VERBOSE);
+       log_action = classic ? &blk_log_action_classic : &blk_log_action;
 
-       if (unlikely(what == 0 || what > ARRAY_SIZE(what2act)))
+       if (t->action == BLK_TN_MESSAGE) {
+               ret = log_action(iter, long_act ? "message" : "m");
+               if (ret)
+                       ret = blk_log_msg(s, iter->ent);
+               goto out;
+       }
+
+       if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
                ret = trace_seq_printf(s, "Bad pc action %x\n", what);
        else {
-               const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
-               ret = blk_log_action_seq(s, t, what2act[what].act[long_act]);
+               ret = log_action(iter, what2act[what].act[long_act]);
                if (ret)
                        ret = what2act[what].print(s, iter->ent);
        }
-
+out:
        return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
 }
 
+static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
+                                              int flags)
+{
+       if (!trace_print_context(iter))
+               return TRACE_TYPE_PARTIAL_LINE;
+
+       return print_one_line(iter, false);
+}
+
 static int blk_trace_synthesize_old_trace(struct trace_iterator *iter)
 {
        struct trace_seq *s = &iter->seq;
@@ -1190,7 +1207,7 @@ static int blk_trace_synthesize_old_trace(struct trace_iterator *iter)
        const int offset = offsetof(struct blk_io_trace, sector);
        struct blk_io_trace old = {
                .magic    = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION,
-               .time     = ns2usecs(iter->ts),
+               .time     = iter->ts,
        };
 
        if (!trace_seq_putmem(s, &old, offset))
@@ -1208,26 +1225,10 @@ blk_trace_event_print_binary(struct trace_iterator *iter, int flags)
 
 static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter)
 {
-       const struct blk_io_trace *t;
-       u16 what;
-       int ret;
-
        if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC))
                return TRACE_TYPE_UNHANDLED;
 
-       t = (const struct blk_io_trace *)iter->ent;
-       what = t->action & ((1 << BLK_TC_SHIFT) - 1);
-
-       if (unlikely(what == 0 || what > ARRAY_SIZE(what2act)))
-               ret = trace_seq_printf(&iter->seq, "Bad pc action %x\n", what);
-       else {
-               const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
-               ret = blk_log_action_iter(iter, what2act[what].act[long_act]);
-               if (ret)
-                       ret = what2act[what].print(&iter->seq, iter->ent);
-       }
-
-       return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
+       return print_one_line(iter, true);
 }
 
 static struct tracer blk_tracer __read_mostly = {
@@ -1273,7 +1274,10 @@ static int blk_trace_remove_queue(struct request_queue *q)
        if (bt == NULL)
                return -EINVAL;
 
-       kfree(bt);
+       if (atomic_dec_and_test(&blk_probes_ref))
+               blk_unregister_tracepoints();
+
+       blk_trace_free(bt);
        return 0;
 }
 
@@ -1283,26 +1287,33 @@ static int blk_trace_remove_queue(struct request_queue *q)
 static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
 {
        struct blk_trace *old_bt, *bt = NULL;
-       int ret;
+       int ret = -ENOMEM;
 
-       ret = -ENOMEM;
        bt = kzalloc(sizeof(*bt), GFP_KERNEL);
        if (!bt)
-               goto err;
+               return -ENOMEM;
+
+       bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
+       if (!bt->msg_data)
+               goto free_bt;
 
        bt->dev = dev;
        bt->act_mask = (u16)-1;
        bt->end_lba = -1ULL;
-       bt->trace_state = Blktrace_running;
 
        old_bt = xchg(&q->blk_trace, bt);
        if (old_bt != NULL) {
                (void)xchg(&q->blk_trace, old_bt);
-               kfree(bt);
                ret = -EBUSY;
+               goto free_bt;
        }
+
+       if (atomic_inc_return(&blk_probes_ref) == 1)
+               blk_register_tracepoints();
        return 0;
-err:
+
+free_bt:
+       blk_trace_free(bt);
        return ret;
 }
 
@@ -1310,72 +1321,6 @@ err:
  * sysfs interface to enable and configure tracing
  */
 
-static ssize_t sysfs_blk_trace_enable_show(struct device *dev,
-                                          struct device_attribute *attr,
-                                          char *buf)
-{
-       struct hd_struct *p = dev_to_part(dev);
-       struct block_device *bdev;
-       ssize_t ret = -ENXIO;
-
-       lock_kernel();
-       bdev = bdget(part_devt(p));
-       if (bdev != NULL) {
-               struct request_queue *q = bdev_get_queue(bdev);
-
-               if (q != NULL) {
-                       mutex_lock(&bdev->bd_mutex);
-                       ret = sprintf(buf, "%u\n", !!q->blk_trace);
-                       mutex_unlock(&bdev->bd_mutex);
-               }
-
-               bdput(bdev);
-       }
-
-       unlock_kernel();
-       return ret;
-}
-
-static ssize_t sysfs_blk_trace_enable_store(struct device *dev,
-                                           struct device_attribute *attr,
-                                           const char *buf, size_t count)
-{
-       struct block_device *bdev;
-       struct request_queue *q;
-       struct hd_struct *p;
-       int value;
-       ssize_t ret = -ENXIO;
-
-       if (count == 0 || sscanf(buf, "%d", &value) != 1)
-               goto out;
-
-       lock_kernel();
-       p = dev_to_part(dev);
-       bdev = bdget(part_devt(p));
-       if (bdev == NULL)
-               goto out_unlock_kernel;
-
-       q = bdev_get_queue(bdev);
-       if (q == NULL)
-               goto out_bdput;
-
-       mutex_lock(&bdev->bd_mutex);
-       if (value)
-               ret = blk_trace_setup_queue(q, bdev->bd_dev);
-       else
-               ret = blk_trace_remove_queue(q);
-       mutex_unlock(&bdev->bd_mutex);
-
-       if (ret == 0)
-               ret = count;
-out_bdput:
-       bdput(bdev);
-out_unlock_kernel:
-       unlock_kernel();
-out:
-       return ret;
-}
-
 static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
                                         struct device_attribute *attr,
                                         char *buf);
@@ -1387,8 +1332,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
                    sysfs_blk_trace_attr_show, \
                    sysfs_blk_trace_attr_store)
 
-static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR,
-                  sysfs_blk_trace_enable_show, sysfs_blk_trace_enable_store);
+static BLK_TRACE_DEVICE_ATTR(enable);
 static BLK_TRACE_DEVICE_ATTR(act_mask);
 static BLK_TRACE_DEVICE_ATTR(pid);
 static BLK_TRACE_DEVICE_ATTR(start_lba);
@@ -1408,53 +1352,85 @@ struct attribute_group blk_trace_attr_group = {
        .attrs = blk_trace_attrs,
 };
 
-static int blk_str2act_mask(const char *str)
+static const struct {
+       int mask;
+       const char *str;
+} mask_maps[] = {
+       { BLK_TC_READ,          "read"          },
+       { BLK_TC_WRITE,         "write"         },
+       { BLK_TC_BARRIER,       "barrier"       },
+       { BLK_TC_SYNC,          "sync"          },
+       { BLK_TC_QUEUE,         "queue"         },
+       { BLK_TC_REQUEUE,       "requeue"       },
+       { BLK_TC_ISSUE,         "issue"         },
+       { BLK_TC_COMPLETE,      "complete"      },
+       { BLK_TC_FS,            "fs"            },
+       { BLK_TC_PC,            "pc"            },
+       { BLK_TC_AHEAD,         "ahead"         },
+       { BLK_TC_META,          "meta"          },
+       { BLK_TC_DISCARD,       "discard"       },
+       { BLK_TC_DRV_DATA,      "drv_data"      },
+};
+
+static int blk_trace_str2mask(const char *str)
 {
+       int i;
        int mask = 0;
-       char *copy = kstrdup(str, GFP_KERNEL), *s;
+       char *s, *token;
 
-       if (copy == NULL)
+       s = kstrdup(str, GFP_KERNEL);
+       if (s == NULL)
                return -ENOMEM;
-
-       s = strstrip(copy);
+       s = strstrip(s);
 
        while (1) {
-               char *sep = strchr(s, ',');
-
-               if (sep != NULL)
-                       *sep = '\0';
-
-               if (strcasecmp(s, "barrier") == 0)
-                       mask |= BLK_TC_BARRIER;
-               else if (strcasecmp(s, "complete") == 0)
-                       mask |= BLK_TC_COMPLETE;
-               else if (strcasecmp(s, "fs") == 0)
-                       mask |= BLK_TC_FS;
-               else if (strcasecmp(s, "issue") == 0)
-                       mask |= BLK_TC_ISSUE;
-               else if (strcasecmp(s, "pc") == 0)
-                       mask |= BLK_TC_PC;
-               else if (strcasecmp(s, "queue") == 0)
-                       mask |= BLK_TC_QUEUE;
-               else if (strcasecmp(s, "read") == 0)
-                       mask |= BLK_TC_READ;
-               else if (strcasecmp(s, "requeue") == 0)
-                       mask |= BLK_TC_REQUEUE;
-               else if (strcasecmp(s, "sync") == 0)
-                       mask |= BLK_TC_SYNC;
-               else if (strcasecmp(s, "write") == 0)
-                       mask |= BLK_TC_WRITE;
-
-               if (sep == NULL)
+               token = strsep(&s, ",");
+               if (token == NULL)
                        break;
 
-               s = sep + 1;
+               if (*token == '\0')
+                       continue;
+
+               for (i = 0; i < ARRAY_SIZE(mask_maps); i++) {
+                       if (strcasecmp(token, mask_maps[i].str) == 0) {
+                               mask |= mask_maps[i].mask;
+                               break;
+                       }
+               }
+               if (i == ARRAY_SIZE(mask_maps)) {
+                       mask = -EINVAL;
+                       break;
+               }
        }
-       kfree(copy);
+       kfree(s);
 
        return mask;
 }
 
+static ssize_t blk_trace_mask2str(char *buf, int mask)
+{
+       int i;
+       char *p = buf;
+
+       for (i = 0; i < ARRAY_SIZE(mask_maps); i++) {
+               if (mask & mask_maps[i].mask) {
+                       p += sprintf(p, "%s%s",
+                                   (p == buf) ? "" : ",", mask_maps[i].str);
+               }
+       }
+       *p++ = '\n';
+
+       return p - buf;
+}
+
+static struct request_queue *blk_trace_get_queue(struct block_device *bdev)
+{
+       if (bdev->bd_disk == NULL)
+               return NULL;
+
+       return bdev_get_queue(bdev);
+}
+
 static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
                                         struct device_attribute *attr,
                                         char *buf)
@@ -1469,20 +1445,29 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
        if (bdev == NULL)
                goto out_unlock_kernel;
 
-       q = bdev_get_queue(bdev);
+       q = blk_trace_get_queue(bdev);
        if (q == NULL)
                goto out_bdput;
+
        mutex_lock(&bdev->bd_mutex);
+
+       if (attr == &dev_attr_enable) {
+               ret = sprintf(buf, "%u\n", !!q->blk_trace);
+               goto out_unlock_bdev;
+       }
+
        if (q->blk_trace == NULL)
                ret = sprintf(buf, "disabled\n");
        else if (attr == &dev_attr_act_mask)
-               ret = sprintf(buf, "%#x\n", q->blk_trace->act_mask);
+               ret = blk_trace_mask2str(buf, q->blk_trace->act_mask);
        else if (attr == &dev_attr_pid)
                ret = sprintf(buf, "%u\n", q->blk_trace->pid);
        else if (attr == &dev_attr_start_lba)
                ret = sprintf(buf, "%llu\n", q->blk_trace->start_lba);
        else if (attr == &dev_attr_end_lba)
                ret = sprintf(buf, "%llu\n", q->blk_trace->end_lba);
+
+out_unlock_bdev:
        mutex_unlock(&bdev->bd_mutex);
 out_bdput:
        bdput(bdev);
@@ -1499,7 +1484,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
        struct request_queue *q;
        struct hd_struct *p;
        u64 value;
-       ssize_t ret = -ENXIO;
+       ssize_t ret = -EINVAL;
 
        if (count == 0)
                goto out;
@@ -1507,24 +1492,36 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
        if (attr == &dev_attr_act_mask) {
                if (sscanf(buf, "%llx", &value) != 1) {
                        /* Assume it is a list of trace category names */
-                       value = blk_str2act_mask(buf);
-                       if (value < 0)
+                       ret = blk_trace_str2mask(buf);
+                       if (ret < 0)
                                goto out;
+                       value = ret;
                }
        } else if (sscanf(buf, "%llu", &value) != 1)
                goto out;
 
+       ret = -ENXIO;
+
        lock_kernel();
        p = dev_to_part(dev);
        bdev = bdget(part_devt(p));
        if (bdev == NULL)
                goto out_unlock_kernel;
 
-       q = bdev_get_queue(bdev);
+       q = blk_trace_get_queue(bdev);
        if (q == NULL)
                goto out_bdput;
 
        mutex_lock(&bdev->bd_mutex);
+
+       if (attr == &dev_attr_enable) {
+               if (value)
+                       ret = blk_trace_setup_queue(q, bdev->bd_dev);
+               else
+                       ret = blk_trace_remove_queue(q);
+               goto out_unlock_bdev;
+       }
+
        ret = 0;
        if (q->blk_trace == NULL)
                ret = blk_trace_setup_queue(q, bdev->bd_dev);
@@ -1538,13 +1535,15 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
                        q->blk_trace->start_lba = value;
                else if (attr == &dev_attr_end_lba)
                        q->blk_trace->end_lba = value;
-               ret = count;
        }
+
+out_unlock_bdev:
        mutex_unlock(&bdev->bd_mutex);
 out_bdput:
        bdput(bdev);
 out_unlock_kernel:
        unlock_kernel();
 out:
-       return ret;
+       return ret ? ret : count;
 }
+
index 808b14bbf076c607bbc4ffebf1c35148a416e082..edce2ff38944560dfd6532ee56c20ed684f69147 100644 (file)
@@ -189,16 +189,65 @@ enum {
        RB_LEN_TIME_STAMP = 16,
 };
 
-/* inline for ring buffer fast paths */
+static inline int rb_null_event(struct ring_buffer_event *event)
+{
+       return event->type == RINGBUF_TYPE_PADDING && event->time_delta == 0;
+}
+
+static inline int rb_discarded_event(struct ring_buffer_event *event)
+{
+       return event->type == RINGBUF_TYPE_PADDING && event->time_delta;
+}
+
+static void rb_event_set_padding(struct ring_buffer_event *event)
+{
+       event->type = RINGBUF_TYPE_PADDING;
+       event->time_delta = 0;
+}
+
+/**
+ * ring_buffer_event_discard - discard an event in the ring buffer
+ * @buffer: the ring buffer
+ * @event: the event to discard
+ *
+ * Sometimes a event that is in the ring buffer needs to be ignored.
+ * This function lets the user discard an event in the ring buffer
+ * and then that event will not be read later.
+ *
+ * Note, it is up to the user to be careful with this, and protect
+ * against races. If the user discards an event that has been consumed
+ * it is possible that it could corrupt the ring buffer.
+ */
+void ring_buffer_event_discard(struct ring_buffer_event *event)
+{
+       event->type = RINGBUF_TYPE_PADDING;
+       /* time delta must be non zero */
+       if (!event->time_delta)
+               event->time_delta = 1;
+}
+
 static unsigned
-rb_event_length(struct ring_buffer_event *event)
+rb_event_data_length(struct ring_buffer_event *event)
 {
        unsigned length;
 
+       if (event->len)
+               length = event->len * RB_ALIGNMENT;
+       else
+               length = event->array[0];
+       return length + RB_EVNT_HDR_SIZE;
+}
+
+/* inline for ring buffer fast paths */
+static unsigned
+rb_event_length(struct ring_buffer_event *event)
+{
        switch (event->type) {
        case RINGBUF_TYPE_PADDING:
-               /* undefined */
-               return -1;
+               if (rb_null_event(event))
+                       /* undefined */
+                       return -1;
+               return rb_event_data_length(event);
 
        case RINGBUF_TYPE_TIME_EXTEND:
                return RB_LEN_TIME_EXTEND;
@@ -207,11 +256,7 @@ rb_event_length(struct ring_buffer_event *event)
                return RB_LEN_TIME_STAMP;
 
        case RINGBUF_TYPE_DATA:
-               if (event->len)
-                       length = event->len * RB_ALIGNMENT;
-               else
-                       length = event->array[0];
-               return length + RB_EVNT_HDR_SIZE;
+               return rb_event_data_length(event);
        default:
                BUG();
        }
@@ -845,11 +890,6 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size)
 }
 EXPORT_SYMBOL_GPL(ring_buffer_resize);
 
-static inline int rb_null_event(struct ring_buffer_event *event)
-{
-       return event->type == RINGBUF_TYPE_PADDING;
-}
-
 static inline void *
 __rb_data_page_index(struct buffer_data_page *bpage, unsigned index)
 {
@@ -1219,7 +1259,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
                if (tail < BUF_PAGE_SIZE) {
                        /* Mark the rest of the page with padding */
                        event = __rb_page_index(tail_page, tail);
-                       event->type = RINGBUF_TYPE_PADDING;
+                       rb_event_set_padding(event);
                }
 
                if (tail <= BUF_PAGE_SIZE)
@@ -1969,7 +2009,7 @@ static void rb_advance_reader(struct ring_buffer_per_cpu *cpu_buffer)
 
        event = rb_reader_event(cpu_buffer);
 
-       if (event->type == RINGBUF_TYPE_DATA)
+       if (event->type == RINGBUF_TYPE_DATA || rb_discarded_event(event))
                cpu_buffer->entries--;
 
        rb_update_read_stamp(cpu_buffer, event);
@@ -2052,9 +2092,18 @@ rb_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts)
 
        switch (event->type) {
        case RINGBUF_TYPE_PADDING:
-               RB_WARN_ON(cpu_buffer, 1);
+               if (rb_null_event(event))
+                       RB_WARN_ON(cpu_buffer, 1);
+               /*
+                * Because the writer could be discarding every
+                * event it creates (which would probably be bad)
+                * if we were to go back to "again" then we may never
+                * catch up, and will trigger the warn on, or lock
+                * the box. Return the padding, and we will release
+                * the current locks, and try again.
+                */
                rb_advance_reader(cpu_buffer);
-               return NULL;
+               return event;
 
        case RINGBUF_TYPE_TIME_EXTEND:
                /* Internal data, OK to advance */
@@ -2115,8 +2164,12 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
 
        switch (event->type) {
        case RINGBUF_TYPE_PADDING:
-               rb_inc_iter(iter);
-               goto again;
+               if (rb_null_event(event)) {
+                       rb_inc_iter(iter);
+                       goto again;
+               }
+               rb_advance_iter(iter);
+               return event;
 
        case RINGBUF_TYPE_TIME_EXTEND:
                /* Internal data, OK to advance */
@@ -2163,10 +2216,16 @@ ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts)
        if (!cpumask_test_cpu(cpu, buffer->cpumask))
                return NULL;
 
+ again:
        spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
        event = rb_buffer_peek(buffer, cpu, ts);
        spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
 
+       if (event && event->type == RINGBUF_TYPE_PADDING) {
+               cpu_relax();
+               goto again;
+       }
+
        return event;
 }
 
@@ -2185,10 +2244,16 @@ ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
        struct ring_buffer_event *event;
        unsigned long flags;
 
+ again:
        spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
        event = rb_iter_peek(iter, ts);
        spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
 
+       if (event && event->type == RINGBUF_TYPE_PADDING) {
+               cpu_relax();
+               goto again;
+       }
+
        return event;
 }
 
@@ -2207,6 +2272,7 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts)
        struct ring_buffer_event *event = NULL;
        unsigned long flags;
 
+ again:
        /* might be called in atomic */
        preempt_disable();
 
@@ -2228,6 +2294,11 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts)
  out:
        preempt_enable();
 
+       if (event && event->type == RINGBUF_TYPE_PADDING) {
+               cpu_relax();
+               goto again;
+       }
+
        return event;
 }
 EXPORT_SYMBOL_GPL(ring_buffer_consume);
@@ -2306,6 +2377,7 @@ ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts)
        struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
        unsigned long flags;
 
+ again:
        spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
        event = rb_iter_peek(iter, ts);
        if (!event)
@@ -2315,6 +2387,11 @@ ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts)
  out:
        spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
 
+       if (event && event->type == RINGBUF_TYPE_PADDING) {
+               cpu_relax();
+               goto again;
+       }
+
        return event;
 }
 EXPORT_SYMBOL_GPL(ring_buffer_read);
index 67c6a21dd4274f8b52816e968aac28348a08c4ee..a0174a40c563a5141de2d33735ae0f16c791a6ae 100644 (file)
@@ -861,15 +861,25 @@ static void ftrace_trace_stack(struct trace_array *tr,
 static void ftrace_trace_userstack(struct trace_array *tr,
                                   unsigned long flags, int pc);
 
-void trace_buffer_unlock_commit(struct trace_array *tr,
-                               struct ring_buffer_event *event,
-                               unsigned long flags, int pc)
+static inline void __trace_buffer_unlock_commit(struct trace_array *tr,
+                                       struct ring_buffer_event *event,
+                                       unsigned long flags, int pc,
+                                       int wake)
 {
        ring_buffer_unlock_commit(tr->buffer, event);
 
        ftrace_trace_stack(tr, flags, 6, pc);
        ftrace_trace_userstack(tr, flags, pc);
-       trace_wake_up();
+
+       if (wake)
+               trace_wake_up();
+}
+
+void trace_buffer_unlock_commit(struct trace_array *tr,
+                                       struct ring_buffer_event *event,
+                                       unsigned long flags, int pc)
+{
+       __trace_buffer_unlock_commit(tr, event, flags, pc, 1);
 }
 
 struct ring_buffer_event *
@@ -883,7 +893,13 @@ trace_current_buffer_lock_reserve(unsigned char type, unsigned long len,
 void trace_current_buffer_unlock_commit(struct ring_buffer_event *event,
                                        unsigned long flags, int pc)
 {
-       return trace_buffer_unlock_commit(&global_trace, event, flags, pc);
+       return __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 1);
+}
+
+void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event,
+                                       unsigned long flags, int pc)
+{
+       return __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 0);
 }
 
 void
@@ -909,7 +925,7 @@ trace_function(struct trace_array *tr,
 }
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
-static void __trace_graph_entry(struct trace_array *tr,
+static int __trace_graph_entry(struct trace_array *tr,
                                struct ftrace_graph_ent *trace,
                                unsigned long flags,
                                int pc)
@@ -918,15 +934,17 @@ static void __trace_graph_entry(struct trace_array *tr,
        struct ftrace_graph_ent_entry *entry;
 
        if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
-               return;
+               return 0;
 
        event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_ENT,
                                          sizeof(*entry), flags, pc);
        if (!event)
-               return;
+               return 0;
        entry   = ring_buffer_event_data(event);
        entry->graph_ent                        = *trace;
        ring_buffer_unlock_commit(global_trace.buffer, event);
+
+       return 1;
 }
 
 static void __trace_graph_return(struct trace_array *tr,
@@ -1147,6 +1165,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
        struct trace_array_cpu *data;
        unsigned long flags;
        long disabled;
+       int ret;
        int cpu;
        int pc;
 
@@ -1162,15 +1181,18 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
        disabled = atomic_inc_return(&data->disabled);
        if (likely(disabled == 1)) {
                pc = preempt_count();
-               __trace_graph_entry(tr, trace, flags, pc);
+               ret = __trace_graph_entry(tr, trace, flags, pc);
+       } else {
+               ret = 0;
        }
        /* Only do the atomic if it is not already set */
        if (!test_tsk_trace_graph(current))
                set_tsk_trace_graph(current);
+
        atomic_dec(&data->disabled);
        local_irq_restore(flags);
 
-       return 1;
+       return ret;
 }
 
 void trace_graph_return(struct ftrace_graph_ret *trace)
index d7410bbb9a803f2052ba8c1921354991194a0234..cb0ce3fc36d31d5312c1c2952f2584fa2a62c3da 100644 (file)
@@ -483,6 +483,8 @@ trace_current_buffer_lock_reserve(unsigned char type, unsigned long len,
                                  unsigned long flags, int pc);
 void trace_current_buffer_unlock_commit(struct ring_buffer_event *event,
                                        unsigned long flags, int pc);
+void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event,
+                                       unsigned long flags, int pc);
 
 struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
                                                struct trace_array_cpu *data);
@@ -776,16 +778,27 @@ enum {
        TRACE_EVENT_TYPE_RAW            = 2,
 };
 
+struct ftrace_event_field {
+       struct list_head        link;
+       char                    *name;
+       char                    *type;
+       int                     offset;
+       int                     size;
+};
+
 struct ftrace_event_call {
-       char            *name;
-       char            *system;
-       struct dentry   *dir;
-       int             enabled;
-       int             (*regfunc)(void);
-       void            (*unregfunc)(void);
-       int             id;
-       int             (*raw_init)(void);
-       int             (*show_format)(struct trace_seq *s);
+       char                    *name;
+       char                    *system;
+       struct dentry           *dir;
+       int                     enabled;
+       int                     (*regfunc)(void);
+       void                    (*unregfunc)(void);
+       int                     id;
+       int                     (*raw_init)(void);
+       int                     (*show_format)(struct trace_seq *s);
+       int                     (*define_fields)(void);
+       struct list_head        fields;
+       struct filter_pred      **preds;
 
 #ifdef CONFIG_EVENT_PROFILE
        atomic_t        profile_count;
@@ -794,6 +807,51 @@ struct ftrace_event_call {
 #endif
 };
 
+struct event_subsystem {
+       struct list_head        list;
+       const char              *name;
+       struct dentry           *entry;
+       struct filter_pred      **preds;
+};
+
+#define events_for_each(event)                                         \
+       for (event = __start_ftrace_events;                             \
+            (unsigned long)event < (unsigned long)__stop_ftrace_events; \
+            event++)
+
+#define MAX_FILTER_PRED 8
+
+struct filter_pred;
+
+typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
+
+struct filter_pred {
+       filter_pred_fn_t fn;
+       u64 val;
+       char *str_val;
+       int str_len;
+       char *field_name;
+       int offset;
+       int not;
+       int or;
+       int compound;
+       int clear;
+};
+
+int trace_define_field(struct ftrace_event_call *call, char *type,
+                      char *name, int offset, int size);
+extern void filter_free_pred(struct filter_pred *pred);
+extern void filter_print_preds(struct filter_pred **preds,
+                              struct trace_seq *s);
+extern int filter_parse(char **pbuf, struct filter_pred *pred);
+extern int filter_add_pred(struct ftrace_event_call *call,
+                          struct filter_pred *pred);
+extern void filter_free_preds(struct ftrace_event_call *call);
+extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
+extern void filter_free_subsystem_preds(struct event_subsystem *system);
+extern int filter_add_subsystem_pred(struct event_subsystem *system,
+                                    struct filter_pred *pred);
+
 void event_trace_printk(unsigned long ip, const char *fmt, ...);
 extern struct ftrace_event_call __start_ftrace_events[];
 extern struct ftrace_event_call __stop_ftrace_events[];
index 3047b56f663732ccb1701d6535b01546d0ab1da2..64ec4d278ffbcd56b94d0d161b855914756f3e0b 100644 (file)
 
 static DEFINE_MUTEX(event_mutex);
 
+int trace_define_field(struct ftrace_event_call *call, char *type,
+                      char *name, int offset, int size)
+{
+       struct ftrace_event_field *field;
+
+       field = kzalloc(sizeof(*field), GFP_KERNEL);
+       if (!field)
+               goto err;
+
+       field->name = kstrdup(name, GFP_KERNEL);
+       if (!field->name)
+               goto err;
+
+       field->type = kstrdup(type, GFP_KERNEL);
+       if (!field->type)
+               goto err;
+
+       field->offset = offset;
+       field->size = size;
+       list_add(&field->link, &call->fields);
+
+       return 0;
+
+err:
+       if (field) {
+               kfree(field->name);
+               kfree(field->type);
+       }
+       kfree(field);
+
+       return -ENOMEM;
+}
+
 static void ftrace_clear_events(void)
 {
        struct ftrace_event_call *call = (void *)__start_ftrace_events;
@@ -343,7 +376,8 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
 
 #undef FIELD
 #define FIELD(type, name)                                              \
-       #type, #name, offsetof(typeof(field), name), sizeof(field.name)
+       #type, "common_" #name, offsetof(typeof(field), name),          \
+               sizeof(field.name)
 
 static int trace_write_header(struct trace_seq *s)
 {
@@ -430,6 +464,139 @@ event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
        return r;
 }
 
+static ssize_t
+event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
+                 loff_t *ppos)
+{
+       struct ftrace_event_call *call = filp->private_data;
+       struct trace_seq *s;
+       int r;
+
+       if (*ppos)
+               return 0;
+
+       s = kmalloc(sizeof(*s), GFP_KERNEL);
+       if (!s)
+               return -ENOMEM;
+
+       trace_seq_init(s);
+
+       filter_print_preds(call->preds, s);
+       r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
+
+       kfree(s);
+
+       return r;
+}
+
+static ssize_t
+event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
+                  loff_t *ppos)
+{
+       struct ftrace_event_call *call = filp->private_data;
+       char buf[64], *pbuf = buf;
+       struct filter_pred *pred;
+       int err;
+
+       if (cnt >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       pred = kzalloc(sizeof(*pred), GFP_KERNEL);
+       if (!pred)
+               return -ENOMEM;
+
+       err = filter_parse(&pbuf, pred);
+       if (err < 0) {
+               filter_free_pred(pred);
+               return err;
+       }
+
+       if (pred->clear) {
+               filter_free_preds(call);
+               filter_free_pred(pred);
+               return cnt;
+       }
+
+       if (filter_add_pred(call, pred)) {
+               filter_free_pred(pred);
+               return -EINVAL;
+       }
+
+       *ppos += cnt;
+
+       return cnt;
+}
+
+static ssize_t
+subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
+                     loff_t *ppos)
+{
+       struct event_subsystem *system = filp->private_data;
+       struct trace_seq *s;
+       int r;
+
+       if (*ppos)
+               return 0;
+
+       s = kmalloc(sizeof(*s), GFP_KERNEL);
+       if (!s)
+               return -ENOMEM;
+
+       trace_seq_init(s);
+
+       filter_print_preds(system->preds, s);
+       r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
+
+       kfree(s);
+
+       return r;
+}
+
+static ssize_t
+subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
+                      loff_t *ppos)
+{
+       struct event_subsystem *system = filp->private_data;
+       char buf[64], *pbuf = buf;
+       struct filter_pred *pred;
+       int err;
+
+       if (cnt >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       pred = kzalloc(sizeof(*pred), GFP_KERNEL);
+       if (!pred)
+               return -ENOMEM;
+
+       err = filter_parse(&pbuf, pred);
+       if (err < 0) {
+               filter_free_pred(pred);
+               return err;
+       }
+
+       if (pred->clear) {
+               filter_free_subsystem_preds(system);
+               filter_free_pred(pred);
+               return cnt;
+       }
+
+       if (filter_add_subsystem_pred(system, pred)) {
+               filter_free_subsystem_preds(system);
+               filter_free_pred(pred);
+               return -EINVAL;
+       }
+
+       *ppos += cnt;
+
+       return cnt;
+}
+
 static const struct seq_operations show_event_seq_ops = {
        .start = t_start,
        .next = t_next,
@@ -475,6 +642,18 @@ static const struct file_operations ftrace_event_id_fops = {
        .read = event_id_read,
 };
 
+static const struct file_operations ftrace_event_filter_fops = {
+       .open = tracing_open_generic,
+       .read = event_filter_read,
+       .write = event_filter_write,
+};
+
+static const struct file_operations ftrace_subsystem_filter_fops = {
+       .open = tracing_open_generic,
+       .read = subsystem_filter_read,
+       .write = subsystem_filter_write,
+};
+
 static struct dentry *event_trace_events_dir(void)
 {
        static struct dentry *d_tracer;
@@ -495,12 +674,6 @@ static struct dentry *event_trace_events_dir(void)
        return d_events;
 }
 
-struct event_subsystem {
-       struct list_head        list;
-       const char              *name;
-       struct dentry           *entry;
-};
-
 static LIST_HEAD(event_subsystems);
 
 static struct dentry *
@@ -533,6 +706,8 @@ event_subsystem_dir(const char *name, struct dentry *d_events)
        system->name = name;
        list_add(&system->list, &event_subsystems);
 
+       system->preds = NULL;
+
        return system->entry;
 }
 
@@ -581,6 +756,20 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events)
                                        call->name);
        }
 
+       if (call->define_fields) {
+               ret = call->define_fields();
+               if (ret < 0) {
+                       pr_warning("Could not initialize trace point"
+                                  " events/%s\n", call->name);
+                       return ret;
+               }
+               entry = debugfs_create_file("filter", 0644, call->dir, call,
+                                           &ftrace_event_filter_fops);
+               if (!entry)
+                       pr_warning("Could not create debugfs "
+                                  "'%s/filter' entry\n", call->name);
+       }
+
        /* A trace may not want to export its format */
        if (!call->show_format)
                return 0;
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
new file mode 100644 (file)
index 0000000..026be41
--- /dev/null
@@ -0,0 +1,427 @@
+/*
+ * trace_events_filter - generic event filtering
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) 2009 Tom Zanussi <tzanussi@gmail.com>
+ */
+
+#include <linux/debugfs.h>
+#include <linux/uaccess.h>
+#include <linux/module.h>
+#include <linux/ctype.h>
+
+#include "trace.h"
+#include "trace_output.h"
+
+static int filter_pred_64(struct filter_pred *pred, void *event)
+{
+       u64 *addr = (u64 *)(event + pred->offset);
+       u64 val = (u64)pred->val;
+       int match;
+
+       match = (val == *addr) ^ pred->not;
+
+       return match;
+}
+
+static int filter_pred_32(struct filter_pred *pred, void *event)
+{
+       u32 *addr = (u32 *)(event + pred->offset);
+       u32 val = (u32)pred->val;
+       int match;
+
+       match = (val == *addr) ^ pred->not;
+
+       return match;
+}
+
+static int filter_pred_16(struct filter_pred *pred, void *event)
+{
+       u16 *addr = (u16 *)(event + pred->offset);
+       u16 val = (u16)pred->val;
+       int match;
+
+       match = (val == *addr) ^ pred->not;
+
+       return match;
+}
+
+static int filter_pred_8(struct filter_pred *pred, void *event)
+{
+       u8 *addr = (u8 *)(event + pred->offset);
+       u8 val = (u8)pred->val;
+       int match;
+
+       match = (val == *addr) ^ pred->not;
+
+       return match;
+}
+
+static int filter_pred_string(struct filter_pred *pred, void *event)
+{
+       char *addr = (char *)(event + pred->offset);
+       int cmp, match;
+
+       cmp = strncmp(addr, pred->str_val, pred->str_len);
+
+       match = (!cmp) ^ pred->not;
+
+       return match;
+}
+
+/* return 1 if event matches, 0 otherwise (discard) */
+int filter_match_preds(struct ftrace_event_call *call, void *rec)
+{
+       int i, matched, and_failed = 0;
+       struct filter_pred *pred;
+
+       for (i = 0; i < MAX_FILTER_PRED; i++) {
+               if (call->preds[i]) {
+                       pred = call->preds[i];
+                       if (and_failed && !pred->or)
+                               continue;
+                       matched = pred->fn(pred, rec);
+                       if (!matched && !pred->or) {
+                               and_failed = 1;
+                               continue;
+                       } else if (matched && pred->or)
+                               return 1;
+               } else
+                       break;
+       }
+
+       if (and_failed)
+               return 0;
+
+       return 1;
+}
+
+void filter_print_preds(struct filter_pred **preds, struct trace_seq *s)
+{
+       char *field_name;
+       struct filter_pred *pred;
+       int i;
+
+       if (!preds) {
+               trace_seq_printf(s, "none\n");
+               return;
+       }
+
+       for (i = 0; i < MAX_FILTER_PRED; i++) {
+               if (preds[i]) {
+                       pred = preds[i];
+                       field_name = pred->field_name;
+                       if (i)
+                               trace_seq_printf(s, pred->or ? "|| " : "&& ");
+                       trace_seq_printf(s, "%s ", field_name);
+                       trace_seq_printf(s, pred->not ? "!= " : "== ");
+                       if (pred->str_val)
+                               trace_seq_printf(s, "%s\n", pred->str_val);
+                       else
+                               trace_seq_printf(s, "%llu\n", pred->val);
+               } else
+                       break;
+       }
+}
+
+static struct ftrace_event_field *
+find_event_field(struct ftrace_event_call *call, char *name)
+{
+       struct ftrace_event_field *field;
+
+       list_for_each_entry(field, &call->fields, link) {
+               if (!strcmp(field->name, name))
+                       return field;
+       }
+
+       return NULL;
+}
+
+void filter_free_pred(struct filter_pred *pred)
+{
+       if (!pred)
+               return;
+
+       kfree(pred->field_name);
+       kfree(pred->str_val);
+       kfree(pred);
+}
+
+void filter_free_preds(struct ftrace_event_call *call)
+{
+       int i;
+
+       if (call->preds) {
+               for (i = 0; i < MAX_FILTER_PRED; i++)
+                       filter_free_pred(call->preds[i]);
+               kfree(call->preds);
+               call->preds = NULL;
+       }
+}
+
+void filter_free_subsystem_preds(struct event_subsystem *system)
+{
+       struct ftrace_event_call *call = __start_ftrace_events;
+       int i;
+
+       if (system->preds) {
+               for (i = 0; i < MAX_FILTER_PRED; i++)
+                       filter_free_pred(system->preds[i]);
+               kfree(system->preds);
+               system->preds = NULL;
+       }
+
+       events_for_each(call) {
+               if (!call->name || !call->regfunc)
+                       continue;
+
+               if (!strcmp(call->system, system->name))
+                       filter_free_preds(call);
+       }
+}
+
+static int __filter_add_pred(struct ftrace_event_call *call,
+                            struct filter_pred *pred)
+{
+       int i;
+
+       if (call->preds && !pred->compound)
+               filter_free_preds(call);
+
+       if (!call->preds) {
+               call->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred),
+                                     GFP_KERNEL);
+               if (!call->preds)
+                       return -ENOMEM;
+       }
+
+       for (i = 0; i < MAX_FILTER_PRED; i++) {
+               if (!call->preds[i]) {
+                       call->preds[i] = pred;
+                       return 0;
+               }
+       }
+
+       return -ENOMEM;
+}
+
+static int is_string_field(const char *type)
+{
+       if (strchr(type, '[') && strstr(type, "char"))
+               return 1;
+
+       return 0;
+}
+
+int filter_add_pred(struct ftrace_event_call *call, struct filter_pred *pred)
+{
+       struct ftrace_event_field *field;
+
+       field = find_event_field(call, pred->field_name);
+       if (!field)
+               return -EINVAL;
+
+       pred->offset = field->offset;
+
+       if (is_string_field(field->type)) {
+               if (!pred->str_val)
+                       return -EINVAL;
+               pred->fn = filter_pred_string;
+               pred->str_len = field->size;
+               return __filter_add_pred(call, pred);
+       } else {
+               if (pred->str_val)
+                       return -EINVAL;
+       }
+
+       switch (field->size) {
+       case 8:
+               pred->fn = filter_pred_64;
+               break;
+       case 4:
+               pred->fn = filter_pred_32;
+               break;
+       case 2:
+               pred->fn = filter_pred_16;
+               break;
+       case 1:
+               pred->fn = filter_pred_8;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return __filter_add_pred(call, pred);
+}
+
+static struct filter_pred *copy_pred(struct filter_pred *pred)
+{
+       struct filter_pred *new_pred = kmalloc(sizeof(*pred), GFP_KERNEL);
+       if (!new_pred)
+               return NULL;
+
+       memcpy(new_pred, pred, sizeof(*pred));
+
+       if (pred->field_name) {
+               new_pred->field_name = kstrdup(pred->field_name, GFP_KERNEL);
+               if (!new_pred->field_name) {
+                       kfree(new_pred);
+                       return NULL;
+               }
+       }
+
+       if (pred->str_val) {
+               new_pred->str_val = kstrdup(pred->str_val, GFP_KERNEL);
+               if (!new_pred->str_val) {
+                       filter_free_pred(new_pred);
+                       return NULL;
+               }
+       }
+
+       return new_pred;
+}
+
+int filter_add_subsystem_pred(struct event_subsystem *system,
+                             struct filter_pred *pred)
+{
+       struct ftrace_event_call *call = __start_ftrace_events;
+       struct filter_pred *event_pred;
+       int i;
+
+       if (system->preds && !pred->compound)
+               filter_free_subsystem_preds(system);
+
+       if (!system->preds) {
+               system->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred),
+                                       GFP_KERNEL);
+               if (!system->preds)
+                       return -ENOMEM;
+       }
+
+       for (i = 0; i < MAX_FILTER_PRED; i++) {
+               if (!system->preds[i]) {
+                       system->preds[i] = pred;
+                       break;
+               }
+       }
+
+       if (i == MAX_FILTER_PRED)
+               return -EINVAL;
+
+       events_for_each(call) {
+               int err;
+
+               if (!call->name || !call->regfunc)
+                       continue;
+
+               if (strcmp(call->system, system->name))
+                       continue;
+
+               if (!find_event_field(call, pred->field_name))
+                       continue;
+
+               event_pred = copy_pred(pred);
+               if (!event_pred)
+                       goto oom;
+
+               err = filter_add_pred(call, event_pred);
+               if (err)
+                       filter_free_pred(event_pred);
+               if (err == -ENOMEM)
+                       goto oom;
+       }
+
+       return 0;
+
+oom:
+       system->preds[i] = NULL;
+       return -ENOMEM;
+}
+
+int filter_parse(char **pbuf, struct filter_pred *pred)
+{
+       char *tmp, *tok, *val_str = NULL;
+       int tok_n = 0;
+
+       /* field ==/!= number, or/and field ==/!= number, number */
+       while ((tok = strsep(pbuf, " \n"))) {
+               if (tok_n == 0) {
+                       if (!strcmp(tok, "0")) {
+                               pred->clear = 1;
+                               return 0;
+                       } else if (!strcmp(tok, "&&")) {
+                               pred->or = 0;
+                               pred->compound = 1;
+                       } else if (!strcmp(tok, "||")) {
+                               pred->or = 1;
+                               pred->compound = 1;
+                       } else
+                               pred->field_name = tok;
+                       tok_n = 1;
+                       continue;
+               }
+               if (tok_n == 1) {
+                       if (!pred->field_name)
+                               pred->field_name = tok;
+                       else if (!strcmp(tok, "!="))
+                               pred->not = 1;
+                       else if (!strcmp(tok, "=="))
+                               pred->not = 0;
+                       else {
+                               pred->field_name = NULL;
+                               return -EINVAL;
+                       }
+                       tok_n = 2;
+                       continue;
+               }
+               if (tok_n == 2) {
+                       if (pred->compound) {
+                               if (!strcmp(tok, "!="))
+                                       pred->not = 1;
+                               else if (!strcmp(tok, "=="))
+                                       pred->not = 0;
+                               else {
+                                       pred->field_name = NULL;
+                                       return -EINVAL;
+                               }
+                       } else {
+                               val_str = tok;
+                               break; /* done */
+                       }
+                       tok_n = 3;
+                       continue;
+               }
+               if (tok_n == 3) {
+                       val_str = tok;
+                       break; /* done */
+               }
+       }
+
+       pred->field_name = kstrdup(pred->field_name, GFP_KERNEL);
+       if (!pred->field_name)
+               return -ENOMEM;
+
+       pred->val = simple_strtoull(val_str, &tmp, 10);
+       if (tmp == val_str) {
+               pred->str_val = kstrdup(val_str, GFP_KERNEL);
+               if (!pred->str_val)
+                       return -ENOMEM;
+       }
+
+       return 0;
+}
+
+
index 5117c43f5c678c5dc4d46dc278d2f14574a9893c..30743f7d41108b942cc596f06856ab633b792c47 100644 (file)
@@ -129,3 +129,48 @@ ftrace_format_##call(struct trace_seq *s)                          \
 }
 
 #include <trace/trace_event_types.h>
+
+#undef __field
+#define __field(type, item)                                            \
+       ret = trace_define_field(event_call, #type, #item,              \
+                                offsetof(typeof(field), item),         \
+                                sizeof(field.item));                   \
+       if (ret)                                                        \
+               return ret;
+
+#undef __array
+#define __array(type, item, len)                                       \
+       ret = trace_define_field(event_call, #type "[" #len "]", #item, \
+                                offsetof(typeof(field), item),         \
+                                sizeof(field.item));                   \
+       if (ret)                                                        \
+               return ret;
+
+#define __common_field(type, item)                                     \
+       ret = trace_define_field(event_call, #type, "common_" #item,    \
+                                offsetof(typeof(field.ent), item),     \
+                                sizeof(field.ent.item));               \
+       if (ret)                                                        \
+               return ret;
+
+#undef TRACE_EVENT
+#define TRACE_EVENT(call, proto, args, tstruct, func, print)           \
+int                                                                    \
+ftrace_define_fields_##call(void)                                      \
+{                                                                      \
+       struct ftrace_raw_##call field;                                 \
+       struct ftrace_event_call *event_call = &event_##call;           \
+       int ret;                                                        \
+                                                                       \
+       __common_field(unsigned char, type);                            \
+       __common_field(unsigned char, flags);                           \
+       __common_field(unsigned char, preempt_count);                   \
+       __common_field(int, pid);                                       \
+       __common_field(int, tgid);                                      \
+                                                                       \
+       tstruct;                                                        \
+                                                                       \
+       return ret;                                                     \
+}
+
+#include <trace/trace_event_types.h>
index 6b3261ca988c69676c6f890420507fa5d91ad76a..9d2fa78ceccae5973c83c37bdc1e363b214d0d3b 100644 (file)
@@ -204,6 +204,7 @@ static struct ftrace_event_call event_##call;                               \
                                                                        \
 static void ftrace_raw_event_##call(proto)                             \
 {                                                                      \
+       struct ftrace_event_call *call = &event_##call;                 \
        struct ring_buffer_event *event;                                \
        struct ftrace_raw_##call *entry;                                \
        unsigned long irq_flags;                                        \
@@ -221,7 +222,11 @@ static void ftrace_raw_event_##call(proto)                         \
                                                                        \
        assign;                                                         \
                                                                        \
-       trace_current_buffer_unlock_commit(event, irq_flags, pc);       \
+       if (call->preds && !filter_match_preds(call, entry))            \
+               ring_buffer_event_discard(event);                       \
+                                                                       \
+       trace_nowake_buffer_unlock_commit(event, irq_flags, pc);        \
+                                                                       \
 }                                                                      \
                                                                        \
 static int ftrace_raw_reg_event_##call(void)                           \
@@ -252,6 +257,7 @@ static int ftrace_raw_init_event_##call(void)                               \
        if (!id)                                                        \
                return -ENODEV;                                         \
        event_##call.id = id;                                           \
+       INIT_LIST_HEAD(&event_##call.fields);                           \
        return 0;                                                       \
 }                                                                      \
                                                                        \
@@ -264,6 +270,7 @@ __attribute__((section("_ftrace_events"))) event_##call = {         \
        .regfunc                = ftrace_raw_reg_event_##call,          \
        .unregfunc              = ftrace_raw_unreg_event_##call,        \
        .show_format            = ftrace_format_##call,                 \
+       .define_fields          = ftrace_define_fields_##call,          \
        _TRACE_PROFILE_INIT(call)                                       \
 }
 
index 9aa84bde23cd2d10e2207d635a908cc958286deb..394f94417e2f9edadbfdd449a90f5b8fd9ddd166 100644 (file)
@@ -91,6 +91,7 @@ struct tracer nop_trace __read_mostly =
        .name           = "nop",
        .init           = nop_trace_init,
        .reset          = nop_trace_reset,
+       .wait_pipe      = poll_wait_pipe,
 #ifdef CONFIG_FTRACE_SELFTEST
        .selftest       = trace_selftest_startup_nop,
 #endif
index dfc9e4ea4e8b1d45144d17a418067f9ae884cc4d..baa999e87cd21d2f9e67c8e3b1093bb6831513fb 100644 (file)
@@ -48,8 +48,6 @@
 #include <linux/rmap.h>
 #include <linux/module.h>
 #include <linux/delayacct.h>
-#include <linux/kprobes.h>
-#include <linux/mutex.h>
 #include <linux/init.h>
 #include <linux/writeback.h>
 #include <linux/memcontrol.h>
index 68d5dc0310e420a889dd60a04d0da5dfc3df4507..9cf80a11e8b68aa23d6b744e3cdb0da81e438981 100644 (file)
@@ -1,6 +1,6 @@
 /* tracepoint-sample.c
  *
- * Executes a tracepoint when /proc/tracepoint-example is opened.
+ * Executes a tracepoint when /proc/tracepoint-sample is opened.
  *
  * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
  *
@@ -16,7 +16,7 @@
 DEFINE_TRACE(subsys_event);
 DEFINE_TRACE(subsys_eventb);
 
-struct proc_dir_entry *pentry_example;
+struct proc_dir_entry *pentry_sample;
 
 static int my_open(struct inode *inode, struct file *file)
 {
@@ -32,25 +32,25 @@ static struct file_operations mark_ops = {
        .open = my_open,
 };
 
-static int __init example_init(void)
+static int __init sample_init(void)
 {
-       printk(KERN_ALERT "example init\n");
-       pentry_example = proc_create("tracepoint-example", 0444, NULL,
+       printk(KERN_ALERT "sample init\n");
+       pentry_sample = proc_create("tracepoint-sample", 0444, NULL,
                &mark_ops);
-       if (!pentry_example)
+       if (!pentry_sample)
                return -EPERM;
        return 0;
 }
 
-static void __exit example_exit(void)
+static void __exit sample_exit(void)
 {
-       printk(KERN_ALERT "example exit\n");
-       remove_proc_entry("tracepoint-example", NULL);
+       printk(KERN_ALERT "sample exit\n");
+       remove_proc_entry("tracepoint-sample", NULL);
 }
 
-module_init(example_init)
-module_exit(example_exit)
+module_init(sample_init)
+module_exit(sample_exit)
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Mathieu Desnoyers");
-MODULE_DESCRIPTION("Tracepoint example");
+MODULE_DESCRIPTION("Tracepoint sample");