Skip to contentSkip to conversation

zedtrace generic kernel filtering

PATCH In review Tom Zanussi 2 participants 4 messages Feb 27, 2009 – Mar 2, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 zedtrace generic kernel filtering

Add generic kernel filtering.

---
 kernel/trace/trace_binary/Makefile     |    2 +-
 kernel/trace/trace_binary/zed.c        |  103 +++++++++--
 kernel/trace/trace_binary/zed.h        |   15 ++
 kernel/trace/trace_binary/zed_filter.c |  301 ++++++++++++++++++++++++++++++++
 kernel/trace/trace_binary/zed_filter.h |   45 +++++
 kernel/trace/trace_binary/zed_sched.c  |    4 +
 6 files changed, 451 insertions(+), 19 deletions(-)
 create mode 100644 kernel/trace/trace_binary/zed_filter.c
 create mode 100644 kernel/trace/trace_binary/zed_filter.h
kernel/trace/trace_binary/Makefile +1 -1
index 558e17a..26b3c8e 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_ZEDTRACE) += zedtrace.o
 
-zedtrace-objs := zed.o zed_sched.o
+zedtrace-objs := zed.o zed_filter.o zed_sched.o
kernel/trace/trace_binary/zed.c +85 -18

175 lines not on this page · raw message

kernel/trace/trace_binary/zed.h +15 -0
index 3cbef4b..56a6295 100644
@@ -100,6 +100,8 @@ struct zed_event {
 	int size;
 	int *trace_flags;
 	struct list_head field_list;
+	struct zed_pred **preds;
+	int core;
 };
 
 /*
@@ -118,6 +120,8 @@ extern struct zed_event *zed_events[MAX_EVENTS];
 extern u32 *zed_trace_sequence;
 extern unsigned int zed_tracing;
 
+#include "zed_filter.h"
+
 /*
  * event definition macros
  */
@@ -169,6 +173,8 @@ ID_EVENTS(EVENTS(EVENT_ID, COMMA));
 
 EVENTS(DECLARE_EVENT, SEMICOLON);
 
+extern void zed_set_core_event(enum zed_event_id event_id);
+
 /*
  * Macros to generate boilerplate tracepoint entry/exit code.
 */
@@ -208,9 +214,18 @@ EVENTS(DECLARE_EVENT, SEMICOLON);
 
 #define ZED_TRACEPOINT_EXIT(name)					\
 	exit:								\
+	if (zed_events[name##_trace]->preds)				\
+		if (!zed_match_preds(zed_events[name##_trace], zed_event)) \
+			zed_unreserve(name##_trace, var_len);		\
 	local_irq_restore(zed_flags);					\
 	}								\
 
+static inline void zed_unreserve(enum zed_event_id event_id, int var_len)
+{
+	struct rchan_buf *buf = zed_channel->buf[smp_processor_id()];
+	buf->offset -= zed_events[event_id]->size + var_len;
+}
+
 /**
  *	zed_reserve() - reserve a slot large enough for event_id
  *	@event_id: auto-generated event id (see documentation)
kernel/trace/trace_binary/zed_filter.c new file +301 -0

301 lines not on this page · raw message

kernel/trace/trace_binary/zed_filter.h new file +45 -0

45 lines not on this page · raw message

kernel/trace/trace_binary/zed_sched.c +4 -0
index 8eba079..9d9bcc8 100644
@@ -197,5 +197,9 @@ void zed_disable_sched_tracepoints(void)
 
 void zed_sched_init(void)
 {
+	zed_set_core_event(sched_switch_trace);
+	zed_set_core_event(sched_migrate_task_trace);
+	zed_set_core_event(sched_process_fork_trace);
+	zed_set_core_event(sched_process_exit_trace);
 }
 
Signature · 1 line
1.5.6.3
#1 lore raw
Quoted 4 lines · Tom Zanussi

Add generic kernel filtering.

Quoted 10 lines
---
 kernel/trace/trace_binary/Makefile     |    2 +-
 kernel/trace/trace_binary/zed.c        |  103 +++++++++--
 kernel/trace/trace_binary/zed.h        |   15 ++
 kernel/trace/trace_binary/zed_filter.c |  301 ++++++++++++++++++++++++++++++++
 kernel/trace/trace_binary/zed_filter.h |   45 +++++
 kernel/trace/trace_binary/zed_sched.c  |    4 +
 6 files changed, 451 insertions(+), 19 deletions(-)
 create mode 100644 kernel/trace/trace_binary/zed_filter.c
 create mode 100644 kernel/trace/trace_binary/zed_filter.h

Nice!

This fits really nicely into the ftrace principles and i'd love to see this feature merged into ftrace - would you be interested in working on that? If so then you can find the latest tracing tree at:

http://people.redhat.com/mingo/tip.git/README

Note that Steve added explicit field enumeration and 'raw' C syntax tracepoints to the event tracer earlier today (partly based on your ideas here), so that would be a good basis to extend/enhance/fix, if you are interested.

Thanks,

Ingo

#2 lore raw
Quoted 17 lines · Ingo Molnar
Quoted 4 lines · Tom Zanussi

Add generic kernel filtering.

Quoted 10 lines
---
 kernel/trace/trace_binary/Makefile     |    2 +-
 kernel/trace/trace_binary/zed.c        |  103 +++++++++--
 kernel/trace/trace_binary/zed.h        |   15 ++
 kernel/trace/trace_binary/zed_filter.c |  301 ++++++++++++++++++++++++++++++++
 kernel/trace/trace_binary/zed_filter.h |   45 +++++
 kernel/trace/trace_binary/zed_sched.c  |    4 +
 6 files changed, 451 insertions(+), 19 deletions(-)
 create mode 100644 kernel/trace/trace_binary/zed_filter.c
 create mode 100644 kernel/trace/trace_binary/zed_filter.h
Quoted 2 lines

Nice!

Thanks!

Quoted 3 lines

This fits really nicely into the ftrace principles and i'd love to see this feature merged into ftrace - would you be interested in working on that? If so then you can find the latest tracing

Sure, but I'm not too familiar with the ftrace code and wouldn't have big blocks of time to devote to it, so if it's something that's needed "right away", I'll probably have to defer to letting someone else adapt the code if they wanted to.

Quoted 9 lines

tree at:

http://people.redhat.com/mingo/tip.git/README

Note that Steve added explicit field enumeration and 'raw' C syntax tracepoints to the event tracer earlier today (partly based on your ideas here), so that would be a good basis to extend/enhance/fix, if you are interested.

Yeah, I took a quick look and saw some nice improvements. Anyway, the filtering I did for this was basically a side-effect of the event description stuff, which made the filtering relatively easy to do (and the event description files give the user a way to list the available fields). What I'm wondering is if you're interested in the filtering part alone or in the event description part as well, which I hadn't thought of as separable (I guess I need to look at the current ftrace code to see what's already there).

Thanks,

Tom

Quoted 3 lines

Thanks,

Ingo

#3 lore raw
Quoted 6 lines · Tom Zanussi
Quoted 4 lines

Note that Steve added explicit field enumeration and 'raw' C syntax tracepoints to the event tracer earlier today (partly based on your ideas here), so that would be a good basis to extend/enhance/fix, if you are interested.

Yeah, I took a quick look and saw some nice improvements.

:)

Quoted 8 lines

Anyway, the filtering I did for this was basically a side-effect of the event description stuff, which made the filtering relatively easy to do (and the event description files give the user a way to list the available fields). What I'm wondering is if you're interested in the filtering part alone or in the event description part as well, which I hadn't thought of as separable (I guess I need to look at the current ftrace code to see what's already there).

No, not filtering alone - event description / field enumeration part is mandatory for user-space to be able to define filters, so yes, that bit is also needed and desired. Steve already added those bits we just dont yet have them exposed in /debug/tracing/events, like your patch does. (I think it's next on Steve's TODO list.)

Basically, i think the big picture is the following. The best model for tracepoints is for them to have the following life cycle:

- trace_printk() ad-hoc additions. Not stable, not hookable and not enumerated - but highly convenient.

- if a trace_printk() turns out to be useful it might become a bit more active and turn into a regular tracepoint. This makes it hookable by ftrace plugins and makes it faster - but it's not generally enumerated yet.

- the final stage for a tracepoint is for it to become a "C-style" tracepoint. That makes it generally available to all ftrace plugins, makes it available to opaque user-space consumption as well and all fields are enumerated. The in-kernel value filtering machinery you added can make use of them as well.

( The downside is (and there are always downsides ;-) that
such tracepoints are the hardest to add and have the highest ongoing maintenance overhead - but that aspect is easily visible and will be a well understood property of them. )

Most tracepoints would move on the most convenient-to-add first two levels - but eventually some would percolate up to the last stage as well.

I think the ones you've identified in your patchset are good candidates for that final stage already - and we've added a few more too, such as the IRQ entry/exit tracepoints.

Ingo