Skip to contentSkip to conversation

Fix ftrace stack traces on x86_64

PATCH Applied Wolfgang Mauerer 2 participants 6 messages Mar 22, 2012 – Jul 6, 2012 Tracing

lore
Share & tools
lore
#0 lore raw

cover Fix ftrace stack traces on x86_64

Stack tracing with ftrace does currently not work properly when trace-cmd is used on x86_64 machines -- only half of each stack entry is shown (things work fine with the ftrace debugfs interface):

mutextest-7604 [001] 664.978289: user_stack:
=> (000000002a7ac565)
=> (000000002a7a6070)
=> (00000000ffffffff)

The following two patches modify the kernel to use the proper trace_printk format, and fix trace_cmd to parse the format correctly:

mutextest-7604 [001] 664.978289: user_stack:
=> (00007f342a7ac565)
=> (00007f342a7a6070)
=> (ffffffffffffffff)

Cheers, Wolfgang

--
Siemens AG
Corporate Competence Centre Embedded Linux

Quoted 1 line

From Wolfgang Mauerer <[email protected]> # This line is ignored.

From: Wolfgang Mauerer <[email protected]> Subject:
In-Reply-To:

#1 lore raw

PATCH 1/2 Fix ftrace stack trace entries

8 hex characters tell only half the tale for 64 bit CPUs, so use the appropriate length.

---
 kernel/trace/trace_entries.h |   16 ++++++++++++----
 kernel/trace/trace_export.c  |    2 +-
 2 files changed, 13 insertions(+), 5 deletions(-)
kernel/trace/trace_entries.h +12 -4
index d91eb05..4108e12 100644
@@ -166,6 +166,12 @@ FTRACE_ENTRY_DUP(wakeup, ctx_switch_entry,
 
 #define FTRACE_STACK_ENTRIES	8
 
+#ifndef CONFIG_64BIT
+# define IP_FMT "%08lx"
+#else
+# define IP_FMT "%016lx"
+#endif
+
 FTRACE_ENTRY(kernel_stack, stack_entry,
 
 	TRACE_STACK,
@@ -175,8 +181,9 @@ FTRACE_ENTRY(kernel_stack, stack_entry,
 		__dynamic_array(unsigned long,	caller	)
 	),
 
-	F_printk("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n"
-		 "\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n",
+	F_printk("\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
+		 "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
+		 "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n",
 		 __entry->caller[0], __entry->caller[1], __entry->caller[2],
 		 __entry->caller[3], __entry->caller[4], __entry->caller[5],
 		 __entry->caller[6], __entry->caller[7]),
@@ -193,8 +200,9 @@ FTRACE_ENTRY(user_stack, userstack_entry,
 		__array(	unsigned long,	caller, FTRACE_STACK_ENTRIES	)
 	),
 
-	F_printk("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n"
-		 "\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n",
+	F_printk("\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
+		 "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
+		 "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n",
 		 __entry->caller[0], __entry->caller[1], __entry->caller[2],
 		 __entry->caller[3], __entry->caller[4], __entry->caller[5],
 		 __entry->caller[6], __entry->caller[7]),
kernel/trace/trace_export.c +1 -1
index 7b46c9b..3dd15e8 100644
@@ -162,7 +162,7 @@ ftrace_define_fields_##name(struct ftrace_event_call *event_call)	\
 #define __dynamic_array(type, item)
 
 #undef F_printk
-#define F_printk(fmt, args...) #fmt ", "  __stringify(args)
+#define F_printk(fmt, args...) __stringify(fmt) ", "  __stringify(args)
 
 #undef FTRACE_ENTRY_REG
 #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, filter,\
Signature · 1 line
1.7.6.4
#2 lore raw

[tip:perf/urgent] tracing: Fix ftrace stack trace entries

Commit-ID:  01de982abf8c9e10fc3089e10585cd2cc914bdab
Gitweb:     http://git.kernel.org/tip/01de982abf8c9e10fc3089e10585cd2cc914bdab
Author:     Wolfgang Mauerer <[email protected]>
AuthorDate: Thu, 22 Mar 2012 11:18:20 +0100
Committer:  Steven Rostedt <[email protected]>
CommitDate: Thu, 22 Mar 2012 12:19:23 -0400

tracing: Fix ftrace stack trace entries

8 hex characters tell only half the tale for 64 bit CPUs, so use the appropriate length.

---
 kernel/trace/trace_entries.h |   16 ++++++++++++----
 kernel/trace/trace_export.c  |    2 +-
 2 files changed, 13 insertions(+), 5 deletions(-)
kernel/trace/trace_entries.h +12 -4
index 9336590..205dcac 100644
@@ -156,6 +156,12 @@ FTRACE_ENTRY_DUP(wakeup, ctx_switch_entry,
 
 #define FTRACE_STACK_ENTRIES	8
 
+#ifndef CONFIG_64BIT
+# define IP_FMT "%08lx"
+#else
+# define IP_FMT "%016lx"
+#endif
+
 FTRACE_ENTRY(kernel_stack, stack_entry,
 
 	TRACE_STACK,
@@ -165,8 +171,9 @@ FTRACE_ENTRY(kernel_stack, stack_entry,
 		__dynamic_array(unsigned long,	caller	)
 	),
 
-	F_printk("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n"
-		 "\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n",
+	F_printk("\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
+		 "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
+		 "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n",
 		 __entry->caller[0], __entry->caller[1], __entry->caller[2],
 		 __entry->caller[3], __entry->caller[4], __entry->caller[5],
 		 __entry->caller[6], __entry->caller[7])
@@ -181,8 +188,9 @@ FTRACE_ENTRY(user_stack, userstack_entry,
 		__array(	unsigned long,	caller, FTRACE_STACK_ENTRIES	)
 	),
 
-	F_printk("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n"
-		 "\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n",
+	F_printk("\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
+		 "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
+		 "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n",
 		 __entry->caller[0], __entry->caller[1], __entry->caller[2],
 		 __entry->caller[3], __entry->caller[4], __entry->caller[5],
 		 __entry->caller[6], __entry->caller[7])
kernel/trace/trace_export.c +1 -1
index bbeec31..ad4000c 100644
@@ -150,7 +150,7 @@ ftrace_define_fields_##name(struct ftrace_event_call *event_call)	\
 #define __dynamic_array(type, item)
 
 #undef F_printk
-#define F_printk(fmt, args...) #fmt ", "  __stringify(args)
+#define F_printk(fmt, args...) __stringify(fmt) ", "  __stringify(args)
 
 #undef FTRACE_ENTRY
 #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print)		\
#3 lore raw

PATCH 2/2 Fix trace_printk for long integers

In reply to Wolfgang Mauerer

On 32 bit systems, a conversion of the trace_printk format string "%lu" -> "%llu" is intended (similar for %lx etc.) when a trace was taken on a machine with 64 bit long integers. However, the current code computes the bogus transformation "%lu" -> "%u". Fix this.

Besides that, the transformation is only required on systems that don't use 64 bits for long integers natively.

---
 parse-events.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
parse-events.c +3 -2
index f8ba6a5..5214771 100644
@@ -3789,14 +3789,15 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 						break;
 					}
 				}
-				if (pevent->long_size == 8 && ls) {
+				if (pevent->long_size == 8 && ls &&
+				    sizeof(long) != 8) {
 					char *p;
 
 					ls = 2;
 					/* make %l into %ll */
 					p = strchr(format, 'l');
 					if (p)
-						memmove(p, p+1, strlen(p)+1);
+						memmove(p+1, p, strlen(p)+1);
 					else if (strcmp(format, "%p") == 0)
 						strcpy(format, "0x%llx");
 				}
Signature · 1 line
1.7.6.4
maintainer Applied
#4 lore raw

Re: [PATCH 2/2, trace-cmd] Fix trace_printk for long integers

Quoted 10 lines · Wolfgang Mauerer

On 32 bit systems, a conversion of the trace_printk format string "%lu" -> "%llu" is intended (similar for %lx etc.) when a trace was taken on a machine with 64 bit long integers. However, the current code computes the bogus transformation "%lu" -> "%u". Fix this.

Besides that, the transformation is only required on systems that don't use 64 bits for long integers natively.

Applied, thanks!

-- Steve

#5 lore raw

[tip:perf/core] tools lib traceevent: Fix trace_printk for long integers

In reply to Wolfgang Mauerer
Commit-ID:  c5b35b731965d16fa8c966e288489857097e0b25
Gitweb:     http://git.kernel.org/tip/c5b35b731965d16fa8c966e288489857097e0b25
Author:     Wolfgang Mauerer <[email protected]>
AuthorDate: Thu, 22 Mar 2012 11:18:21 +0100
Committer:  Namhyung Kim <[email protected]>
CommitDate: Wed, 4 Jul 2012 13:40:30 +0900

tools lib traceevent: Fix trace_printk for long integers

On 32 bit systems, a conversion of the trace_printk format string "%lu" -> "%llu" is intended (similar for %lx etc.) when a trace was taken on a machine with 64 bit long integers. However, the current code computes the bogus transformation "%lu" -> "%u". Fix this.

Besides that, the transformation is only required on systems that don't use 64 bits for long integers natively.

---
 tools/lib/traceevent/event-parse.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
tools/lib/traceevent/event-parse.c +3 -2
index da06c33..ddee5a8 100644
@@ -3895,14 +3895,15 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 						break;
 					}
 				}
-				if (pevent->long_size == 8 && ls) {
+				if (pevent->long_size == 8 && ls &&
+				    sizeof(long) != 8) {
 					char *p;
 
 					ls = 2;
 					/* make %l into %ll */
 					p = strchr(format, 'l');
 					if (p)
-						memmove(p, p+1, strlen(p)+1);
+						memmove(p+1, p, strlen(p)+1);
 					else if (strcmp(format, "%p") == 0)
 						strcpy(format, "0x%llx");
 				}