• Steven Rostedt's avatar
    ring-buffer: convert cpu buffer entries to local_t · e4906eff
    Steven Rostedt authored
    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: default avatarSteven Rostedt <rostedt@goodmis.org>
    e4906eff
ring_buffer.c 76.9 KB