[commit: ghc] master: RTS: fix pushWSDeque to invoke write barrier when element is added (9ebdbb2)

Manuel Chakravarty chak at cse.unsw.edu.au
Wed Aug 10 14:04:55 CEST 2011


Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/9ebdbb27a8b26a424cab8916f5f0c2388af2ce2d

>---------------------------------------------------------------

commit 9ebdbb27a8b26a424cab8916f5f0c2388af2ce2d
Author: Karel Gardas <karel.gardas at centrum.cz>
Date:   Sat Jul 9 18:07:00 2011 +0200

    RTS: fix pushWSDeque to invoke write barrier when element is added
    
    This patch fixes RTS' pushWSDeque function. We need to invoke
    write barrier after element is added to the queue and before moving
    bottom. The reason for this is possible write reordering on modern CPUs
    (e.g. ARMv7MP) where setting of element might be done later after moving
    bottom. When such situation happen other thread might be waiting to steal
    data from the queue and when bottom is moved it eagerly steals undefined
    data from the queue since setting of element has not happened yet.

>---------------------------------------------------------------

 rts/WSDeque.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/rts/WSDeque.c b/rts/WSDeque.c
index 71633d9..8efd1bb 100644
--- a/rts/WSDeque.c
+++ b/rts/WSDeque.c
@@ -279,6 +279,15 @@ pushWSDeque (WSDeque* q, void * elem)
     }
 
     q->elements[b & sz] = elem;
+    /*
+       KG: we need to put write barrier here since otherwise we might
+       end with elem not added to q->elements, but q->bottom already
+       modified (write reordering) and with stealWSDeque_ failing
+       later when invoked from another thread since it thinks elem is
+       there (in case there is just added element in the queue). This
+       issue concretely hit me on ARMv7 multi-core CPUs
+     */
+    write_barrier();
     q->bottom = b + 1;
     
     ASSERT_WSDEQUE_INVARIANTS(q); 





More information about the Cvs-ghc mailing list