Skip to contentSkip to conversation

tracing: Expose event tracing infrastructure

PATCH Superseded zhangwei(Jovi) 1 participant 1 message Mar 13, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: Expose event tracing infrastructure

Currently event tracing only can be use for ftrace and perf, there don't have any mechanism to let modules(like external tracing tool) register callback tracing function.

Event tracing implement based on tracepoint, compare with raw tracepoint, event tracing infrastructure provide built-in structured event annotate format, this feature should expose to external user.

For example, simple pseudo ktap script demonstrate how to use this event tracing expose change.

function event_trace(e)

{
        printf("%s", e.annotate);
}

os.trace("sched:sched_switch", event_trace);
os.trace("irq:softirq_raise", event_trace);

The running result:
sched_switch: prev_comm=rcu_sched prev_pid=10 prev_prio=120 prev_state=S ==> next_comm=swapper/1 next_pid=0 next_prio=120
softirq_raise: vec=1 [action=TIMER]
...

This expose change can be use by other tracing tool, like systemtap/lttng, if they would implement this.

This patch introduce struct event_trace_ops, it have two function pointers, pre_trace and do_trace. when ftrace_raw_event_<call> function hit, it will call all registered event_trace_ops.

Use this unify callback mechanism, ftrace_raw_event_<call> and perf_trace_<call> is integrated into one function,
the benefit of this change is kernel size shrink ~52K(with ftrace and perf compiled in).

text data bss dec hex filename

7801238  841596 3473408 12116242         b8e112 vmlinux.old
7757064  833596 3473408 12064068         b81544 vmlinux.new
---
 include/linux/ftrace_event.h |   63 +++++++++++++-
 include/trace/ftrace.h       |  198 ++++++++----------------------------------
 kernel/trace/trace_events.c  |  173 +++++++++++++++++++++++++++++++++---
 3 files changed, 259 insertions(+), 175 deletions(-)
include/linux/ftrace_event.h +60 -3
index 13a54d0..4539a79 100644
@@ -167,9 +167,6 @@ struct ftrace_event_call;
 struct ftrace_event_class {
 	char			*system;
 	void			*probe;
-#ifdef CONFIG_PERF_EVENTS
-	void			*perf_probe;
-#endif
 	int			(*reg)(struct ftrace_event_call *event,
 				       enum trace_reg type, void *data);
 	int			(*define_fields)(struct ftrace_event_call *);
@@ -199,6 +196,57 @@ enum {
 	TRACE_EVENT_FL_IGNORE_ENABLE	= (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
 };
 
+struct ftrace_trace_descriptor_t {
+	struct ring_buffer_event *event;
+	struct ring_buffer *buffer;
+	unsigned long irq_flags;
+	int pc;
+};
+
+#ifdef CONFIG_PERF_EVENTS
+struct perf_trace_descriptor_t {
+	struct pt_regs __regs;
+	struct task_struct *__task;
+	u64 __addr;
+	u64 __count;
+	int rctx;
+};
+#endif
+
+/*
+ * trace_descriptor_t is purpose for passing arguments between
+ * pre_trace and do_trace function.
+ * this definition is ugly, change it in future.
+ */
+struct trace_descriptor_t {
+	struct ftrace_trace_descriptor_t	f;
+#ifdef CONFIG_PERF_EVENTS
+	struct perf_trace_descriptor_t		p;
+#endif
+	void  *data;
+};
+
+enum TRACE_REG_TYPE {
+	TRACE_REG_FTRACE,
+	TRACE_REG_PERF,
+};
+
+/* callback function for tracing */
+struct event_trace_ops {
+	void *(*pre_trace)(struct ftrace_event_call *event_call,
+			   int entry_size, void *data);
+	void (*do_trace)(struct ftrace_event_call *event_call,
+			 void *entry, int entry_size, void *data);
+};
+
+struct ftrace_probe {
+	struct list_head list;
+
+	/* 0: TRACE_REG_FTRACE; 1 : TRACE_REG_PERF */
+	int type;
+	struct event_trace_ops *ops;
+};
+
 struct ftrace_event_call {
 	struct list_head	list;
 	struct ftrace_event_class *class;
@@ -210,6 +258,10 @@ struct ftrace_event_call {
 	void			*mod;
 	void			*data;
 
+	/* list head of "struct ftrace_probe" */
+	struct list_head	probe_ops_list;
+	int			probe_count;
+
 	/*
 	 * 32 bit flags:
 	 *   bit 1:		enabled
@@ -274,6 +326,11 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
 extern int trace_add_event_call(struct ftrace_event_call *call);
 extern void trace_remove_event_call(struct ftrace_event_call *call);
 
+extern int ftrace_event_register(struct ftrace_event_call *call, int type,
+				 struct event_trace_ops *ops);
+extern void ftrace_event_unregister(struct ftrace_event_call *call, int type,
+				    struct event_trace_ops *ops);
+
 #define is_signed_type(type)	(((type)(-1)) < (type)0)
 
 int trace_set_clr_event(const char *system, const char *event, int set);
include/trace/ftrace.h +38 -160

245 lines not on this page · raw message

kernel/trace/trace_events.c +161 -12

194 lines not on this page · raw message

Signature · 1 line
1.7.9.7