lkml.org 
[lkml]   [2008]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 6/9] oprofile: port to the new ring_buffer

On Tue, 16 Dec 2008, Robert Richter wrote:
>
> In the beginning, the use of separate locks for reading and writing
> would be sufficient. Then, there would be only one atomic comparison
> needed to check, if the write pointer meets the read pointer. This
> should be not as difficult since read and write is always in different
> pages (if a am not wrong) and thus only the pointer to the pages have
> to be compared.
>

Most of the ftrace work uses the ring buffer in overwrite mode. That is,
when the head meets the tail, we move the tail. The way the reader works,
is that the first read will swap a page out of the ring with a blank page.
This means, what is on that page is safe from further writes. When the
reader is finished with the page, it will swap the empty page with a tail
of the buffer.

The problem is that there needs to be a lock to protect this change. If
the writer is moving the tail and the reader is about to swap it, things
can get corrupted. There are tricks to protect this with cmpxchg, but for
now we are playing it safe with spin locks. Note, the lock is only taken
by the reader when it needs to go to the next page.

The writers do not need any locks to protect against other writers,
because the buffers are per cpu and a write may only be performed on a
buffer on the local cpu.

-- Steve


Note: I may have tail and head backwards, I do not remember which end I
called what.


\
 
 \ /
  Last update: 2008-12-16 20:41    [W:0.073 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site