Skip to contentSkip to conversation

updates for tip/tracing/ftrace

GIT PULL New Steven Rostedt 1 participant 3 messages Mar 26, 2009 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Ingo,

Please pull the latest tip/tracing/ftrace-1 tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/ftrace-1

Steven Rostedt (2):
tracing: increase size of number of possible events
tracing: add size checks for exported ftrace internal structures

----

 kernel/trace/trace.h        |    5 ++++-
 kernel/trace/trace_events.c |    5 ++++-
 kernel/trace/trace_export.c |    4 ++++
 kernel/trace/trace_output.c |    2 ++
 4 files changed, 14 insertions(+), 2 deletions(-)
author maintainer
#1 lore raw

PATCH 1/2 tracing: increase size of number of possible events

From: Steven Rostedt <[email protected]>

With the new event tracing registration, we must increase the number of events that can be registered. Currently the type field is only one byte, which leaves us only 256 possible events.

Since we do not save the CPU number in the tracer anymore (it is determined by the per cpu ring buffer that is used) we have an extra byte to use.

This patch increases the size of type from 1 byte (256 events) to 2 bytes (65,536 events).

It also adds a WARN_ON_ONCE if we exceed that limit.

---
 kernel/trace/trace.h        |    5 ++++-
 kernel/trace/trace_events.c |    2 +-
 kernel/trace/trace_output.c |    2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)
kernel/trace/trace.h +4 -1
index d7410bb..1c7cb30 100644
@@ -48,13 +48,16 @@ enum trace_type {
  *     bash-15816 [01]   235.197585: idle_cpu <- irq_enter
  */
 struct trace_entry {
-	unsigned char		type;
+	unsigned short		type;
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
 	int			tgid;
 };
 
+#define FTRACE_MAX_EVENT						\
+	((1 << (sizeof(((struct trace_entry *)0)->type) * 8)) - 1)
+
 /*
  * Function trace entry - function address and parent function addres:
  */
kernel/trace/trace_events.c +1 -1
index 3047b56..d0f9968 100644
@@ -357,7 +357,7 @@ static int trace_write_header(struct trace_seq *s)
 				"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
 				"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
 				"\n",
-				FIELD(unsigned char, type),
+				FIELD(unsigned short, type),
 				FIELD(unsigned char, flags),
 				FIELD(unsigned char, preempt_count),
 				FIELD(int, pid),
kernel/trace/trace_output.c +2 -0
index 19261fd..b2599b0 100644
@@ -513,6 +513,8 @@ int register_ftrace_event(struct trace_event *event)
  out:
 	mutex_unlock(&trace_event_mutex);
 
+	WARN_ON_ONCE(next_event_type > FTRACE_MAX_EVENT);
+
 	return ret;
 }
 
Signature · 3 lines
1.6.2

-- 
author maintainer
#2 lore raw

PATCH 2/2 tracing: add size checks for exported ftrace internal structures

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

The events exported by TRACE_EVENT are automated and are guaranteed to be correct when used.

The internal ftrace sturctures on the other hand are more manually exported. These require the ftrace maintainer to make sure they are up to date.

This patch adds a size check to help flag when a type changes in an internal ftrace data structure, and the update needs to be reflected in the export.

If a export is incorrect, then the only harm is that the user space tools will not know how to correctly read the internal structures of ftrace.

---
 kernel/trace/trace_events.c |    3 +++
 kernel/trace/trace_export.c |    4 ++++
 2 files changed, 7 insertions(+), 0 deletions(-)
kernel/trace/trace_events.c +3 -0
index d0f9968..4a1c1bc 100644
@@ -341,8 +341,11 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
 	return cnt;
 }
 
+extern char *__bad_type_size(void);
+
 #undef FIELD
 #define FIELD(type, name)						\
+	sizeof(type) != sizeof(field.name) ? __bad_type_size() :	\
 	#type, #name, offsetof(typeof(field), name), sizeof(field.name)
 
 static int trace_write_header(struct trace_seq *s)
kernel/trace/trace_export.c +4 -0
index 4d9952d..4ae01bc 100644
@@ -19,8 +19,12 @@
 #undef TRACE_STRUCT
 #define TRACE_STRUCT(args...) args
 
+extern void __bad_type_size(void);
+
 #undef TRACE_FIELD
 #define TRACE_FIELD(type, item, assign)					\
+	if (sizeof(type) != sizeof(field.item))				\
+		__bad_type_size();					\
 	ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t"	\
 			       "offset:%u;\tsize:%u;\n",		\
 			       (unsigned int)offsetof(typeof(field), item), \
Signature · 3 lines
1.6.2

--