Skip to contentSkip to conversation

git pull request for tip/tracing/ftace

PATCH In review Steven Rostedt 2 participants 10 messages Feb 10, 2009 – Feb 11, 2009

Subsystems (4)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover git pull request for tip/tracing/ftace

Ingo,

The following is based off of tip/tracing/ftrace.

-- Steve

The following patches are in:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git

branch: tip/tracing/ftrace

Lai Jiangshan (2):
ring_buffer: fix typing mistake
ring_buffer: fix ring_buffer_read_page()

Steven Rostedt (1):
tracing, x86: fix constraint for parent variable

Tobias Klauser (1):
tracing: storage class should be before const qualifier

Wenji Huang (3):
tracing: remove unneeded variable
tracing: provide correct return value after outputting the event
tracing: fix typos in comments

----

 arch/x86/kernel/ftrace.c             |    9 +++---
 include/linux/ring_buffer.h          |    2 +-
 kernel/trace/ring_buffer.c           |   46 +++++++++++++++++++--------------
 kernel/trace/trace.c                 |    2 +-
 kernel/trace/trace_branch.c          |    4 +--
 kernel/trace/trace_functions_graph.c |   14 +++++-----
 kernel/trace/trace_hw_branches.c     |    2 +-
 kernel/trace/trace_sysprof.c         |    2 +-
 8 files changed, 42 insertions(+), 39 deletions(-)
author maintainer
#1 lore raw

PATCH 1/7 ring_buffer: fix typing mistake

From: Lai Jiangshan <[email protected]>

Impact: Fix bug

I found several very very curious line.
It's so curious that it may be brought by typing mistake.

When (cpu_buffer->reader_page == cpu_buffer->commit_page):

1) We haven't copied it for bpage is changed:
bpage = cpu_buffer->reader_page->page; memcpy(bpage->data, cpu_buffer->reader_page->page->data + read ... )
2) We need update cpu_buffer->reader_page->read, but "cpu_buffer->reader_page += read;" is not right.

[
This bug was a typo. The commit->reader_page is a page pointer and not an index into the page. The line should have been commit->reader_page->read += read. The other changes by Lai are nice clean ups to the code. - SDR
]

---
 kernel/trace/ring_buffer.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
kernel/trace/ring_buffer.c +4 -5
index 53ba3a6..eca2827 100644
@@ -2406,7 +2406,7 @@ void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data)
  * to swap with a page in the ring buffer.
  *
  * for example:
- *	rpage = ring_buffer_alloc_page(buffer);
+ *	rpage = ring_buffer_alloc_read_page(buffer);
  *	if (!rpage)
  *		return error;
  *	ret = ring_buffer_read_page(buffer, &rpage, cpu, 0);
@@ -2461,18 +2461,17 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
 	 */
 	if (cpu_buffer->reader_page == cpu_buffer->commit_page) {
 		unsigned int read = cpu_buffer->reader_page->read;
+		unsigned int commit = rb_page_commit(cpu_buffer->reader_page);
 
 		if (full)
 			goto out;
 		/* The writer is still on the reader page, we must copy */
-		bpage = cpu_buffer->reader_page->page;
 		memcpy(bpage->data,
 		       cpu_buffer->reader_page->page->data + read,
-		       local_read(&bpage->commit) - read);
+		       commit - read);
 
 		/* consume what was read */
-		cpu_buffer->reader_page += read;
-
+		cpu_buffer->reader_page->read = commit;
 	} else {
 		/* swap the pages */
 		rb_init_page(bpage);
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#2 lore raw

PATCH 2/7 ring_buffer: fix ring_buffer_read_page()

In reply to Steven Rostedt

From: Lai Jiangshan <[email protected]>

Impact: change API and init bpage when copy

ring_buffer_read_page()/rb_remove_entries() may be called for a partially consumed page.

Add a parameter for rb_remove_entries() and make it update cpu_buffer->entries correctly for partially consumed pages.

ring_buffer_read_page() now returns the offset to the next event.

Init the bpage's time_stamp when return value is 0.

---
 kernel/trace/ring_buffer.c |   33 ++++++++++++++++++++-------------
 1 files changed, 20 insertions(+), 13 deletions(-)
kernel/trace/ring_buffer.c +20 -13
index eca2827..10d202e 100644
@@ -2332,13 +2332,14 @@ int ring_buffer_swap_cpu(struct ring_buffer *buffer_a,
 EXPORT_SYMBOL_GPL(ring_buffer_swap_cpu);
 
 static void rb_remove_entries(struct ring_buffer_per_cpu *cpu_buffer,
-			      struct buffer_data_page *bpage)
+			      struct buffer_data_page *bpage,
+			      unsigned int offset)
 {
 	struct ring_buffer_event *event;
 	unsigned long head;
 
 	__raw_spin_lock(&cpu_buffer->lock);
-	for (head = 0; head < local_read(&bpage->commit);
+	for (head = offset; head < local_read(&bpage->commit);
 	     head += rb_event_length(event)) {
 
 		event = __rb_data_page_index(bpage, head);
@@ -2410,8 +2411,8 @@ void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data)
  *	if (!rpage)
  *		return error;
  *	ret = ring_buffer_read_page(buffer, &rpage, cpu, 0);
- *	if (ret)
- *		process_page(rpage);
+ *	if (ret >= 0)
+ *		process_page(rpage, ret);
  *
  * When @full is set, the function will not return true unless
  * the writer is off the reader page.
@@ -2422,8 +2423,8 @@ void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data)
  *  responsible for that.
  *
  * Returns:
- *  1 if data has been transferred
- *  0 if no data has been transferred.
+ *  >=0 if data has been transferred, returns the offset of consumed data.
+ *  <0 if no data has been transferred.
  */
 int ring_buffer_read_page(struct ring_buffer *buffer,
 			    void **data_page, int cpu, int full)
@@ -2432,7 +2433,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
 	struct ring_buffer_event *event;
 	struct buffer_data_page *bpage;
 	unsigned long flags;
-	int ret = 0;
+	unsigned int read;
+	int ret = -1;
 
 	if (!data_page)
 		return 0;
@@ -2454,24 +2456,29 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
 	/* check for data */
 	if (!local_read(&cpu_buffer->reader_page->page->commit))
 		goto out;
+
+	read = cpu_buffer->reader_page->read;
 	/*
 	 * If the writer is already off of the read page, then simply
 	 * switch the read page with the given page. Otherwise
 	 * we need to copy the data from the reader to the writer.
 	 */
 	if (cpu_buffer->reader_page == cpu_buffer->commit_page) {
-		unsigned int read = cpu_buffer->reader_page->read;
 		unsigned int commit = rb_page_commit(cpu_buffer->reader_page);
+		struct buffer_data_page *rpage = cpu_buffer->reader_page->page;
 
 		if (full)
 			goto out;
 		/* The writer is still on the reader page, we must copy */
-		memcpy(bpage->data,
-		       cpu_buffer->reader_page->page->data + read,
-		       commit - read);
+		memcpy(bpage->data + read, rpage->data + read, commit - read);
 
 		/* consume what was read */
 		cpu_buffer->reader_page->read = commit;
+
+		/* update bpage */
+		local_set(&bpage->commit, commit);
+		if (!read)
+			bpage->time_stamp = rpage->time_stamp;
 	} else {
 		/* swap the pages */
 		rb_init_page(bpage);
@@ -2480,10 +2487,10 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
 		cpu_buffer->reader_page->read = 0;
 		*data_page = bpage;
 	}
-	ret = 1;
+	ret = read;
 
 	/* update the entry counter */
-	rb_remove_entries(cpu_buffer, bpage);
+	rb_remove_entries(cpu_buffer, bpage, read);
  out:
 	spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
 
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#3 lore raw

PATCH 3/7 tracing, x86: fix constraint for parent variable

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

The constraint used for retrieving and restoring the parent function pointer is incorrect. The parent variable is a pointer, and the address of the pointer is modified by the asm statement and not the pointer itself. It is incorrect to pass it in as an output constraint since the asm will never update the pointer.

---
 arch/x86/kernel/ftrace.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/kernel/ftrace.c +4 -5
index 18828ae..370bafa 100644
@@ -468,8 +468,8 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 	 * ignore such a protection.
 	 */
 	asm volatile(
-		"1: " _ASM_MOV " (%[parent_old]), %[old]\n"
-		"2: " _ASM_MOV " %[return_hooker], (%[parent_replaced])\n"
+		"1: " _ASM_MOV " (%[parent]), %[old]\n"
+		"2: " _ASM_MOV " %[return_hooker], (%[parent])\n"
 		"   movl $0, %[faulted]\n"
 
 		".section .fixup, \"ax\"\n"
@@ -479,9 +479,8 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 		_ASM_EXTABLE(1b, 3b)
 		_ASM_EXTABLE(2b, 3b)
 
-		: [parent_replaced] "=r" (parent), [old] "=r" (old),
-		  [faulted] "=r" (faulted)
-		: [parent_old] "0" (parent), [return_hooker] "r" (return_hooker)
+		: [old] "=r" (old), [faulted] "=r" (faulted)
+		: [parent] "r" (parent), [return_hooker] "r" (return_hooker)
 		: "memory"
 	);
 
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#4 lore raw

PATCH 4/7 tracing: storage class should be before const qualifier

In reply to Steven Rostedt

From: Tobias Klauser <[email protected]>

The C99 specification states in section 6.11.5:

The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.

---
 kernel/trace/trace_sysprof.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_sysprof.c +1 -1
index 84ca9d8..4e2de4d 100644
@@ -88,7 +88,7 @@ static void backtrace_address(void *data, unsigned long addr, int reliable)
 	}
 }
 
-const static struct stacktrace_ops backtrace_ops = {
+static const struct stacktrace_ops backtrace_ops = {
 	.warning		= backtrace_warning,
 	.warning_symbol		= backtrace_warning_symbol,
 	.stack			= backtrace_stack,
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#5 lore raw

PATCH 5/7 tracing: remove unneeded variable

In reply to Steven Rostedt

From: Wenji Huang <[email protected]>

Impact: clean up.

Remove the unnecessary variable ret.

---
 kernel/trace/trace_branch.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
kernel/trace/trace_branch.c +1 -3
index f8ae2c5..c2e68d4 100644
@@ -91,8 +91,6 @@ void trace_likely_condition(struct ftrace_branch_data *f, int val, int expect)
 
 int enable_branch_tracing(struct trace_array *tr)
 {
-	int ret = 0;
-
 	mutex_lock(&branch_tracing_mutex);
 	branch_tracer = tr;
 	/*
@@ -103,7 +101,7 @@ int enable_branch_tracing(struct trace_array *tr)
 	branch_tracing_enabled++;
 	mutex_unlock(&branch_tracing_mutex);
 
-	return ret;
+	return 0;
 }
 
 void disable_branch_tracing(void)
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#6 lore raw

PATCH 6/7 tracing: provide correct return value after outputting the event

In reply to Steven Rostedt

From: Wenji Huang <[email protected]>

This patch is to make the function return early on failure, and give correct return value on success.

---
 kernel/trace/trace_functions_graph.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
kernel/trace/trace_functions_graph.c +7 -7
index 782ec0f..519a0ca 100644
@@ -186,30 +186,30 @@ verif_pid(struct trace_seq *s, pid_t pid, int cpu, pid_t *last_pids_cpu)
 	ret = trace_seq_printf(s,
 		" ------------------------------------------\n");
 	if (!ret)
-		TRACE_TYPE_PARTIAL_LINE;
+		return TRACE_TYPE_PARTIAL_LINE;
 
 	ret = print_graph_cpu(s, cpu);
 	if (ret == TRACE_TYPE_PARTIAL_LINE)
-		TRACE_TYPE_PARTIAL_LINE;
+		return TRACE_TYPE_PARTIAL_LINE;
 
 	ret = print_graph_proc(s, prev_pid);
 	if (ret == TRACE_TYPE_PARTIAL_LINE)
-		TRACE_TYPE_PARTIAL_LINE;
+		return TRACE_TYPE_PARTIAL_LINE;
 
 	ret = trace_seq_printf(s, " => ");
 	if (!ret)
-		TRACE_TYPE_PARTIAL_LINE;
+		return TRACE_TYPE_PARTIAL_LINE;
 
 	ret = print_graph_proc(s, pid);
 	if (ret == TRACE_TYPE_PARTIAL_LINE)
-		TRACE_TYPE_PARTIAL_LINE;
+		return TRACE_TYPE_PARTIAL_LINE;
 
 	ret = trace_seq_printf(s,
 		"\n ------------------------------------------\n\n");
 	if (!ret)
-		TRACE_TYPE_PARTIAL_LINE;
+		return TRACE_TYPE_PARTIAL_LINE;
 
-	return ret;
+	return TRACE_TYPE_HANDLED;
 }
 
 static struct ftrace_graph_ret_entry *
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#7 lore raw

PATCH 7/7 tracing: fix typos in comments

In reply to Steven Rostedt

From: Wenji Huang <[email protected]>

Impact: clean up.

Fix typos in the comments.

---
 include/linux/ring_buffer.h      |    2 +-
 kernel/trace/ring_buffer.c       |    8 ++++----
 kernel/trace/trace.c             |    2 +-
 kernel/trace/trace_hw_branches.c |    2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
include/linux/ring_buffer.h +1 -1
index 3c103d6..8e6646a 100644
@@ -8,7 +8,7 @@ struct ring_buffer;
 struct ring_buffer_iter;
 
 /*
- * Don't reference this struct directly, use functions below.
+ * Don't refer to this struct directly, use functions below.
  */
 struct ring_buffer_event {
 	u32		type:2, len:3, time_delta:27;
kernel/trace/ring_buffer.c +4 -4
index 10d202e..fa64e1f 100644
@@ -91,7 +91,7 @@ EXPORT_SYMBOL_GPL(tracing_off);
  * tracing_off_permanent - permanently disable ring buffers
  *
  * This function, once called, will disable all ring buffers
- * permanenty.
+ * permanently.
  */
 void tracing_off_permanent(void)
 {
@@ -210,7 +210,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_event_data);
 
 struct buffer_data_page {
 	u64		 time_stamp;	/* page time stamp */
-	local_t		 commit;	/* write commited index */
+	local_t		 commit;	/* write committed index */
 	unsigned char	 data[];	/* data of buffer page */
 };
 
@@ -260,7 +260,7 @@ struct ring_buffer_per_cpu {
 	struct list_head		pages;
 	struct buffer_page		*head_page;	/* read from head */
 	struct buffer_page		*tail_page;	/* write to tail */
-	struct buffer_page		*commit_page;	/* commited pages */
+	struct buffer_page		*commit_page;	/* committed pages */
 	struct buffer_page		*reader_page;
 	unsigned long			overrun;
 	unsigned long			entries;
@@ -303,7 +303,7 @@ struct ring_buffer_iter {
  * check_pages - integrity check of buffer pages
  * @cpu_buffer: CPU buffer with pages to test
  *
- * As a safty measure we check to make sure the data pages have not
+ * As a safety measure we check to make sure the data pages have not
  * been corrupted.
  */
 static int rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer)
kernel/trace/trace.c +1 -1
index d898212..d7c175a 100644
@@ -1963,7 +1963,7 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf,
 	struct tracer_opt *trace_opts = current_trace->flags->opts;
 
 
-	/* calulate max size */
+	/* calculate max size */
 	for (i = 0; trace_options[i]; i++) {
 		len += strlen(trace_options[i]);
 		len += 3; /* "no" and space */
kernel/trace/trace_hw_branches.c +1 -1
index e3e7db6..0794dd3 100644
@@ -75,7 +75,7 @@ static void bts_trace_start(struct trace_array *tr)
 }
 
 /*
- * Start tracing on the current cpu.
+ * Stop tracing on the current cpu.
  * The argument is ignored.
  *
  * pre: bts_tracer_mutex must be locked.
Signature · 3 lines
1.5.6.5

-- 
#8 lore raw
In reply to Steven Rostedt
Quoted 30 lines · Steven Rostedt

Ingo,

The following is based off of tip/tracing/ftrace.

-- Steve

The following patches are in:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git

branch: tip/tracing/ftrace

Lai Jiangshan (2):
ring_buffer: fix typing mistake
ring_buffer: fix ring_buffer_read_page()

Steven Rostedt (1):
tracing, x86: fix constraint for parent variable

Tobias Klauser (1):
tracing: storage class should be before const qualifier

Wenji Huang (3):
tracing: remove unneeded variable
tracing: provide correct return value after outputting the event
tracing: fix typos in comments

----

Quoted 9 lines
 arch/x86/kernel/ftrace.c             |    9 +++---
 include/linux/ring_buffer.h          |    2 +-
 kernel/trace/ring_buffer.c           |   46 +++++++++++++++++++--------------
 kernel/trace/trace.c                 |    2 +-
 kernel/trace/trace_branch.c          |    4 +--
 kernel/trace/trace_functions_graph.c |   14 +++++-----
 kernel/trace/trace_hw_branches.c     |    2 +-
 kernel/trace/trace_sysprof.c         |    2 +-
 8 files changed, 42 insertions(+), 39 deletions(-)

Pulled into tip:tracing/ftrace, thanks Steve!

Note, i cherry-picked this fix into tip:tracing/urgent:

9666578: tracing, x86: fix constraint for parent variable

As in theory GCC can miscompile the function-return-tracer, right?

Ingo

author maintainer
#9 lore raw
Quoted 5 lines · Ingo Molnar

Note, i cherry-picked this fix into tip:tracing/urgent:

9666578: tracing, x86: fix constraint for parent variable

As in theory GCC can miscompile the function-return-tracer, right?

Yeah, I was thinking that, but I could not make it do so with the few test cases that I tried. But in theory, I guess it can.

-- Steve