reiserfs: fix oops while creating privroot with selinux enabled
[safe/jmp/linux-2.6] / include / linux / tracepoint.h
index c60a791..f59604e 100644 (file)
@@ -4,7 +4,7 @@
 /*
  * Kernel Tracepoint API.
  *
- * See Documentation/tracepoint.txt.
+ * See Documentation/trace/tracepoints.txt.
  *
  * (C) Copyright 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
  *
@@ -23,12 +23,20 @@ struct tracepoint;
 struct tracepoint {
        const char *name;               /* Tracepoint name */
        int state;                      /* State. */
+       void (*regfunc)(void);
+       void (*unregfunc)(void);
        void **funcs;
-} __attribute__((aligned(8)));
+} __attribute__((aligned(32)));                /*
+                                        * Aligned on 32 bytes because it is
+                                        * globally visible and gcc happily
+                                        * align these on the structure size.
+                                        * Keep in sync with vmlinux.lds.h.
+                                        */
 
+#ifndef DECLARE_TRACE
 
-#define TPPROTO(args...)       args
-#define TPARGS(args...)                args
+#define TP_PROTO(args...)      args
+#define TP_ARGS(args...)       args
 
 #ifdef CONFIG_TRACEPOINTS
 
@@ -55,35 +63,44 @@ struct tracepoint {
  * not add unwanted padding between the beginning of the section and the
  * structure. Force alignment to the same alignment as the section start.
  */
-#define DEFINE_TRACE(name, proto, args)                                        \
+#define DECLARE_TRACE(name, proto, args)                               \
+       extern struct tracepoint __tracepoint_##name;                   \
        static inline void trace_##name(proto)                          \
        {                                                               \
-               static const char __tpstrtab_##name[]                   \
-               __attribute__((section("__tracepoints_strings")))       \
-               = #name ":" #proto;                                     \
-               static struct tracepoint __tracepoint_##name            \
-               __attribute__((section("__tracepoints"), aligned(8))) = \
-               { __tpstrtab_##name, 0, NULL };                         \
                if (unlikely(__tracepoint_##name.state))                \
                        __DO_TRACE(&__tracepoint_##name,                \
-                               TPPROTO(proto), TPARGS(args));          \
+                               TP_PROTO(proto), TP_ARGS(args));        \
        }                                                               \
        static inline int register_trace_##name(void (*probe)(proto))   \
        {                                                               \
-               return tracepoint_probe_register(#name ":" #proto,      \
-                       (void *)probe);                                 \
+               return tracepoint_probe_register(#name, (void *)probe); \
        }                                                               \
        static inline int unregister_trace_##name(void (*probe)(proto)) \
        {                                                               \
-               return tracepoint_probe_unregister(#name ":" #proto,    \
-                       (void *)probe);                                 \
+               return tracepoint_probe_unregister(#name, (void *)probe);\
        }
 
+
+#define DEFINE_TRACE_FN(name, reg, unreg)                              \
+       static const char __tpstrtab_##name[]                           \
+       __attribute__((section("__tracepoints_strings"))) = #name;      \
+       struct tracepoint __tracepoint_##name                           \
+       __attribute__((section("__tracepoints"), aligned(32))) =        \
+               { __tpstrtab_##name, 0, reg, unreg, NULL }
+
+#define DEFINE_TRACE(name)                                             \
+       DEFINE_TRACE_FN(name, NULL, NULL);
+
+#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)                             \
+       EXPORT_SYMBOL_GPL(__tracepoint_##name)
+#define EXPORT_TRACEPOINT_SYMBOL(name)                                 \
+       EXPORT_SYMBOL(__tracepoint_##name)
+
 extern void tracepoint_update_probe_range(struct tracepoint *begin,
        struct tracepoint *end);
 
 #else /* !CONFIG_TRACEPOINTS */
-#define DEFINE_TRACE(name, proto, args)                        \
+#define DECLARE_TRACE(name, proto, args)                               \
        static inline void _do_trace_##name(struct tracepoint *tp, proto) \
        { }                                                             \
        static inline void trace_##name(proto)                          \
@@ -97,10 +114,16 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin,
                return -ENOSYS;                                         \
        }
 
+#define DEFINE_TRACE_FN(name, reg, unreg)
+#define DEFINE_TRACE(name)
+#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
+#define EXPORT_TRACEPOINT_SYMBOL(name)
+
 static inline void tracepoint_update_probe_range(struct tracepoint *begin,
        struct tracepoint *end)
 { }
 #endif /* CONFIG_TRACEPOINTS */
+#endif /* DECLARE_TRACE */
 
 /*
  * Connect a probe to a tracepoint.
@@ -140,4 +163,133 @@ static inline void tracepoint_synchronize_unregister(void)
        synchronize_sched();
 }
 
-#endif
+#define PARAMS(args...) args
+
+#endif /* _LINUX_TRACEPOINT_H */
+
+/*
+ * Note: we keep the TRACE_EVENT outside the include file ifdef protection.
+ *  This is due to the way trace events work. If a file includes two
+ *  trace event headers under one "CREATE_TRACE_POINTS" the first include
+ *  will override the TRACE_EVENT and break the second include.
+ */
+
+#ifndef TRACE_EVENT
+/*
+ * For use with the TRACE_EVENT macro:
+ *
+ * We define a tracepoint, its arguments, its printk format
+ * and its 'fast binay record' layout.
+ *
+ * Firstly, name your tracepoint via TRACE_EVENT(name : the
+ * 'subsystem_event' notation is fine.
+ *
+ * Think about this whole construct as the
+ * 'trace_sched_switch() function' from now on.
+ *
+ *
+ *  TRACE_EVENT(sched_switch,
+ *
+ *     *
+ *     * A function has a regular function arguments
+ *     * prototype, declare it via TP_PROTO():
+ *     *
+ *
+ *     TP_PROTO(struct rq *rq, struct task_struct *prev,
+ *              struct task_struct *next),
+ *
+ *     *
+ *     * Define the call signature of the 'function'.
+ *     * (Design sidenote: we use this instead of a
+ *     *  TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
+ *     *
+ *
+ *     TP_ARGS(rq, prev, next),
+ *
+ *     *
+ *     * Fast binary tracing: define the trace record via
+ *     * TP_STRUCT__entry(). You can think about it like a
+ *     * regular C structure local variable definition.
+ *     *
+ *     * This is how the trace record is structured and will
+ *     * be saved into the ring buffer. These are the fields
+ *     * that will be exposed to user-space in
+ *     * /sys/kernel/debug/tracing/events/<*>/format.
+ *     *
+ *     * The declared 'local variable' is called '__entry'
+ *     *
+ *     * __field(pid_t, prev_prid) is equivalent to a standard declariton:
+ *     *
+ *     *       pid_t   prev_pid;
+ *     *
+ *     * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
+ *     *
+ *     *       char    prev_comm[TASK_COMM_LEN];
+ *     *
+ *
+ *     TP_STRUCT__entry(
+ *             __array(        char,   prev_comm,      TASK_COMM_LEN   )
+ *             __field(        pid_t,  prev_pid                        )
+ *             __field(        int,    prev_prio                       )
+ *             __array(        char,   next_comm,      TASK_COMM_LEN   )
+ *             __field(        pid_t,  next_pid                        )
+ *             __field(        int,    next_prio                       )
+ *     ),
+ *
+ *     *
+ *     * Assign the entry into the trace record, by embedding
+ *     * a full C statement block into TP_fast_assign(). You
+ *     * can refer to the trace record as '__entry' -
+ *     * otherwise you can put arbitrary C code in here.
+ *     *
+ *     * Note: this C code will execute every time a trace event
+ *     * happens, on an active tracepoint.
+ *     *
+ *
+ *     TP_fast_assign(
+ *             memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
+ *             __entry->prev_pid       = prev->pid;
+ *             __entry->prev_prio      = prev->prio;
+ *             memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
+ *             __entry->next_pid       = next->pid;
+ *             __entry->next_prio      = next->prio;
+ *     )
+ *
+ *     *
+ *     * Formatted output of a trace record via TP_printk().
+ *     * This is how the tracepoint will appear under ftrace
+ *     * plugins that make use of this tracepoint.
+ *     *
+ *     * (raw-binary tracing wont actually perform this step.)
+ *     *
+ *
+ *     TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
+ *             __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
+ *             __entry->next_comm, __entry->next_pid, __entry->next_prio),
+ *
+ * );
+ *
+ * This macro construct is thus used for the regular printk format
+ * tracing setup, it is used to construct a function pointer based
+ * tracepoint callback (this is used by programmatic plugins and
+ * can also by used by generic instrumentation like SystemTap), and
+ * it is also used to expose a structured trace record in
+ * /sys/kernel/debug/tracing/events/.
+ *
+ * A set of (un)registration functions can be passed to the variant
+ * TRACE_EVENT_FN to perform any (un)registration work.
+ */
+
+#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
+#define DEFINE_EVENT(template, name, proto, args)              \
+       DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
+       DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+
+#define TRACE_EVENT(name, proto, args, struct, assign, print)  \
+       DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+#define TRACE_EVENT_FN(name, proto, args, struct,              \
+               assign, print, reg, unreg)                      \
+       DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+
+#endif /* ifdef TRACE_EVENT (see note above) */