From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 3/3] ring-buffer: make cpu buffer entries counter atomic
Date: Thu, 30 Apr 2009 22:22:13 -0400 [thread overview]
Message-ID: <20090501022403.826182932@goodmis.org> (raw)
In-Reply-To: 20090501022210.851418183@goodmis.org
[-- Attachment #1: 0003-ring-buffer-make-cpu-buffer-entries-counter-atomic.patch --]
[-- Type: text/plain, Size: 3245 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
The entries counter in cpu buffer is not atomic. Although it only gets
updated by a single CPU, interrupts may come in and update the counter
too. This would cause missing entries to be added.
[ Impact: keep accurate count of cpu buffer entries ]
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/ring_buffer.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index dc8b2ab..3b9b32b 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -405,7 +405,7 @@ struct ring_buffer_per_cpu {
unsigned long nmi_dropped;
unsigned long commit_overrun;
unsigned long overrun;
- unsigned long entries;
+ atomic_t entries;
u64 write_stamp;
u64 read_stamp;
atomic_t record_disabled;
@@ -997,7 +997,7 @@ static void rb_update_overflow(struct ring_buffer_per_cpu *cpu_buffer)
if (event->type_len > RINGBUF_TYPE_DATA_TYPE_LEN_MAX)
continue;
cpu_buffer->overrun++;
- cpu_buffer->entries--;
+ atomic_dec(&cpu_buffer->entries);
}
}
@@ -1588,7 +1588,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_lock_reserve);
static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer,
struct ring_buffer_event *event)
{
- cpu_buffer->entries++;
+ atomic_inc(&cpu_buffer->entries);
/* Only process further if we own the commit */
if (!rb_is_commit(cpu_buffer, event))
@@ -1722,7 +1722,7 @@ void ring_buffer_discard_commit(struct ring_buffer *buffer,
* The commit is still visible by the reader, so we
* must increment entries.
*/
- cpu_buffer->entries++;
+ atomic_inc(&cpu_buffer->entries);
out:
/*
* If a write came in and pushed the tail page
@@ -1902,7 +1902,7 @@ unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu)
return 0;
cpu_buffer = buffer->buffers[cpu];
- ret = cpu_buffer->entries;
+ ret = atomic_read(&cpu_buffer->entries);
return ret;
}
@@ -1985,7 +1985,7 @@ unsigned long ring_buffer_entries(struct ring_buffer *buffer)
/* if you care about this being correct, lock the buffer */
for_each_buffer_cpu(buffer, cpu) {
cpu_buffer = buffer->buffers[cpu];
- entries += cpu_buffer->entries;
+ entries += atomic_read(&cpu_buffer->entries);
}
return entries;
@@ -2225,7 +2225,7 @@ static void rb_advance_reader(struct ring_buffer_per_cpu *cpu_buffer)
if (event->type_len <= RINGBUF_TYPE_DATA_TYPE_LEN_MAX
|| rb_discarded_event(event))
- cpu_buffer->entries--;
+ atomic_dec(&cpu_buffer->entries);
rb_update_read_stamp(cpu_buffer, event);
@@ -2642,7 +2642,7 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
cpu_buffer->nmi_dropped = 0;
cpu_buffer->commit_overrun = 0;
cpu_buffer->overrun = 0;
- cpu_buffer->entries = 0;
+ atomic_set(&cpu_buffer->entries, 0);
cpu_buffer->write_stamp = 0;
cpu_buffer->read_stamp = 0;
@@ -2813,7 +2813,7 @@ static void rb_remove_entries(struct ring_buffer_per_cpu *cpu_buffer,
/* Only count data entries */
if (event->type_len > RINGBUF_TYPE_DATA_TYPE_LEN_MAX)
continue;
- cpu_buffer->entries--;
+ atomic_dec(&cpu_buffer->entries);
}
__raw_spin_unlock(&cpu_buffer->lock);
}
--
1.6.2.1
--
next prev parent reply other threads:[~2009-05-01 2:25 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-01 2:22 [PATCH 0/3] [GIT PULL] tracing/ringbuffer: updates for tip Steven Rostedt
2009-05-01 2:22 ` [PATCH 1/3] ring-buffer: add counters for commit overrun and nmi dropped entries Steven Rostedt
2009-05-01 3:00 ` Andrew Morton
2009-05-01 3:11 ` Steven Rostedt
2009-05-01 3:22 ` Andrew Morton
2009-05-01 3:33 ` Steven Rostedt
2009-05-01 3:38 ` Andrew Morton
2009-05-01 3:55 ` Steven Rostedt
2009-05-01 2:22 ` [PATCH 2/3] tracing: export stats of ring buffers to userspace Steven Rostedt
2009-05-01 3:08 ` Frederic Weisbecker
2009-05-01 3:23 ` Steven Rostedt
2009-05-01 12:43 ` Frederic Weisbecker
2009-05-01 2:22 ` Steven Rostedt [this message]
2009-05-01 3:06 ` [PATCH 3/3] ring-buffer: make cpu buffer entries counter atomic Andrew Morton
2009-05-01 3:28 ` Steven Rostedt
2009-05-01 11:50 ` Ingo Molnar
2009-05-01 13:42 ` Frederic Weisbecker
2009-05-01 14:28 ` Steven Rostedt
2009-05-01 22:10 ` Frederic Weisbecker
2009-05-01 14:23 ` Steven Rostedt
2009-05-01 16:14 ` Steven Rostedt
2009-05-01 16:20 ` Ingo Molnar
2009-05-01 16:31 ` Steven Rostedt
2009-05-01 16:32 ` Steven Rostedt
2009-05-01 16:52 ` Ingo Molnar
2009-05-01 17:11 ` Steven Rostedt
2009-05-01 17:14 ` Ingo Molnar
2009-05-01 17:36 ` Steven Rostedt
2009-05-01 17:42 ` Ingo Molnar
2009-05-01 17:56 ` Steven Rostedt
2009-05-01 21:17 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090501022403.826182932@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox