ring-buffer: convert cpu buffer entries to local_t
commite4906eff9e6fbd2d311abcbcc53d5a531773c982
authorSteven Rostedt <srostedt@redhat.com>
Fri, 1 May 2009 00:49:44 +0000 (30 20:49 -0400)
committerSteven Rostedt <rostedt@goodmis.org>
Tue, 5 May 2009 18:25:44 +0000 (5 14:25 -0400)
tree05dd56b9336e7059cca3b651d542cc4b8bc2220b
parentc8d771835e18c938dae8690611d65fe98ad30f58
ring-buffer: convert cpu buffer entries to local_t

The entries counter in cpu buffer is not atomic. It can be updated by
other interrupts or from another CPU (readers).

But making entries into "atomic_t" causes an atomic operation that can
hurt performance. Instead we convert it to a local_t that will increment
a counter with a local CPU atomic operation (if the arch supports it).

Instead of fighting with readers and overwrites that decrement the counter,
I added a "read" counter. Every time a reader reads an entry it is
incremented.

We already have a overrun counter and with that, the entries counter and
the read counter, we can calculate the total number of entries in the
buffer with:

  (entries - overrun) - read

As long as the total number of entries in the ring buffer is less than
the word size, this will work. But since the entries counter was previously
a long, this is no different than what we had before.

Thanks to Andrew Morton for pointing out in the first version that
atomic_t does not replace unsigned long. I switched to atomic_long_t
even though it is signed. A negative count is most likely a bug.

[ Impact: keep accurate count of cpu buffer entries ]

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/ring_buffer.c