Skip to contentSkip to conversation

ring-buffer updates for tip

PATCH Applied Steven Rostedt 2 participants 5 messages Nov 12, 2008

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover ring-buffer updates for tip

Ingo,

The following patches are in:

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

branch: tip/devel

Steven Rostedt (2):
ring-buffer: fix deadlock from reader_lock in read_start
ring-buffer: no preempt for sched_clock

----

 kernel/trace/ring_buffer.c |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)
author maintainer
#1 lore raw

PATCH 1/2 ring-buffer: fix deadlock from reader_lock in read_start

Impact: deadlock fix in ring_buffer_read_start

The ring_buffer_iter_reset was called from ring_buffer_read_start where both grabbed the reader_lock.

This patch separates out the internals of ring_buffer_iter_reset to its own function so that both APIs may grab the reader_lock.

---
 kernel/trace/ring_buffer.c |   29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)
kernel/trace/ring_buffer.c +17 -12
index c04c433..86dc353 100644
@@ -1475,19 +1475,9 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
 	return overruns;
 }
 
-/**
- * ring_buffer_iter_reset - reset an iterator
- * @iter: The iterator to reset
- *
- * Resets the iterator, so that it will start from the beginning
- * again.
- */
-void ring_buffer_iter_reset(struct ring_buffer_iter *iter)
+static void rb_iter_reset(struct ring_buffer_iter *iter)
 {
 	struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
-	unsigned long flags;
-
-	spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
 
 	/* Iterator usage is expected to have record disabled */
 	if (list_empty(&cpu_buffer->reader_page->list)) {
@@ -1501,7 +1491,22 @@ void ring_buffer_iter_reset(struct ring_buffer_iter *iter)
 		iter->read_stamp = cpu_buffer->read_stamp;
 	else
 		iter->read_stamp = iter->head_page->time_stamp;
+}
 
+/**
+ * ring_buffer_iter_reset - reset an iterator
+ * @iter: The iterator to reset
+ *
+ * Resets the iterator, so that it will start from the beginning
+ * again.
+ */
+void ring_buffer_iter_reset(struct ring_buffer_iter *iter)
+{
+	struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
+	unsigned long flags;
+
+	spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
+	rb_iter_reset(iter);
 	spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
 }
 
@@ -1957,7 +1962,7 @@ ring_buffer_read_start(struct ring_buffer *buffer, int cpu)
 
 	spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
 	__raw_spin_lock(&cpu_buffer->lock);
-	ring_buffer_iter_reset(iter);
+	rb_iter_reset(iter);
 	__raw_spin_unlock(&cpu_buffer->lock);
 	spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
 
Signature · 3 lines
1.5.6.5

-- 
Applied
#2 lore raw

Re: [PATCH 1/2] ring-buffer: fix deadlock from reader_lock in read_start

Quoted 5 lines · Steven Rostedt

Impact: deadlock fix in ring_buffer_read_start

The ring_buffer_iter_reset was called from ring_buffer_read_start where both grabbed the reader_lock.

Quoted 7 lines

This patch separates out the internals of ring_buffer_iter_reset to its own function so that both APIs may grab the reader_lock.

---
 kernel/trace/ring_buffer.c |   29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)

applied to tip/tracing/ring-buffer, thanks Steve!

Ingo

author maintainer
#3 lore raw

PATCH 2/2 ring-buffer: no preempt for sched_clock

In reply to Steven Rostedt

Impact: disable preemption no calling sched_clock

The ring_buffer_time_stamp still uses sched_clock as its counter. But it is a bug to call it with preemption enabled. This requirement should not be pushed to the ring_buffer_time_stamp callers, so the ring_buffer_time_stamp needs to disable preemption when calling sched_clock.

---
 kernel/trace/ring_buffer.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
kernel/trace/ring_buffer.c +7 -1
index 86dc353..2d6c2cf 100644
@@ -53,8 +53,14 @@ void tracing_off(void)
 /* FIXME!!! */
 u64 ring_buffer_time_stamp(int cpu)
 {
+	u64 time;
+
+	preempt_disable_notrace();
 	/* shift to debug/test normalization and TIME_EXTENTS */
-	return sched_clock() << DEBUG_SHIFT;
+	time = sched_clock() << DEBUG_SHIFT;
+	preempt_enable_notrace();
+
+	return time;
 }
 
 void ring_buffer_normalize_time_stamp(int cpu, u64 *ts)
Signature · 3 lines
1.5.6.5

-- 
Applied
#4 lore raw

Re: [PATCH 2/2] ring-buffer: no preempt for sched_clock

Quoted 8 lines · Steven Rostedt

Impact: disable preemption no calling sched_clock

The ring_buffer_time_stamp still uses sched_clock as its counter. But it is a bug to call it with preemption enabled. This requirement should not be pushed to the ring_buffer_time_stamp callers, so the ring_buffer_time_stamp needs to disable preemption when calling sched_clock.

Quoted 4 lines
---
 kernel/trace/ring_buffer.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

applied to tip/tracing/urgent, thanks Steve!

Ingo