Thread (96 messages) 96 messages, 15 authors, 2013-11-08

Re: perf events ring buffer memory barrier on powerpc

From: Victor Kaplansky <hidden>
Date: 2013-10-23 07:40:06
Also in: lkml

See below.

Michael Neuling [off-list ref] wrote on 10/23/2013 02:54:54 AM:
quoted hunk ↗ jump to hunk
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index cd55144..95768c6 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -87,10 +87,10 @@ again:
       goto out;

    /*
-    * Publish the known good head. Rely on the full barrier implied
-    * by atomic_dec_and_test() order the rb->head read and this
-    * write.
+    * Publish the known good head. We need a memory barrier to order the
+    * order the rb->head read and this write.
     */
+   smp_mb ();
    rb->user_page->data_head = head;

    /*
1. As far as I understand, smp_mb() is superfluous in this case, smp_wmb()
should be enough.
   (same for the space between the name of function and open
parenthesis :-) )

2. Again, as far as I understand from ./Documentation/atomic_ops.txt, it is
mistake in architecture independent
   code to rely on memory barriers in atomic operations, all the more so in
"local" operations.

3. The solution above is sub-optimal on architectures where memory barrier
is part of "local", since we are going to execute
   two consecutive barriers. So, maybe, it would be better to use
smp_mb__after_atomic_dec().

4. I'm not sure, but I think there is another, unrelated potential problem
in function perf_output_put_handle()
   - the write to "data_head" -

kernel/events/ring_buffer.c:

 77         /*
 78          * Publish the known good head. Rely on the full barrier
implied
 79          * by atomic_dec_and_test() order the rb->head read and this
 80          * write.
 81          */
 82         rb->user_page->data_head = head;

As data_head is 64-bit wide, the update should be done by an atomic64_set
().

Regards,
-- Victor
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help