[Git][ghc/ghc][wip/memory-barriers] More comments from Simon

Ben Gamari gitlab at gitlab.haskell.org
Tue Jun 18 19:37:03 UTC 2019



Ben Gamari pushed to branch wip/memory-barriers at Glasgow Haskell Compiler / GHC


Commits:
233c879a by Ben Gamari at 2019-06-18T19:36:55Z
More comments from Simon

- - - - -


3 changed files:

- includes/stg/SMP.h
- rts/sm/CNF.c
- rts/sm/MarkWeak.c


Changes:

=====================================
includes/stg/SMP.h
=====================================
@@ -176,18 +176,13 @@ EXTERN_INLINE void load_load_barrier(void);
  *    This case is protected by explicit write barriers in the the update frame
  *    entry code (see rts/Updates.h).
  *
- *  - Writing to the thread's local stack, followed by the thread blocking:
- *    This is protected by the write barrier necessary to place the thread on
- *    whichever blocking queue it is blocked on:
+ *  - Blocking on an MVar# (e.g. takeMVar#):
+ *    In this case the appropriate MVar primops (e.g. stg_takeMVarzh).  include
+ *    explicit memory barriers to ensure that the the newly-allocated
+ *    MVAR_TSO_QUEUE is visible to other cores.
  *
- *     - a BLACKHOLE's BLOCKING_QUEUE: explicit barriers in
- *       Messages.c:messageBlackHole and Messages.c:sendMessage.
- *
- *     - a TVAR's STM_TVAR_WATCH_QUEUE: The CAS in STM.c:unlock_stm, called by
- *       STM.c:stmWaitUnlock.
- *
- *     - an MVAR's MVAR_TSO_QUEUE: explicit write barriers in the appropriate
- *       MVar primops (e.g. stg_takeMVarzh).
+ *  - Write to an MVar# (e.g. putMVar#):
+ *    This protected by the full barrier implied by the CAS in putMVar#.
  *
  *  - Write to a TVar#:
  *    This is protected by the full barrier implied by the CAS in STM.c:lock_stm.
@@ -205,9 +200,6 @@ EXTERN_INLINE void load_load_barrier(void);
  *    This is protected by the full barrier implied by the cmpxchg operations
  *    in this primops.
  *
- *  - Write to an MVar#:
- *    This protected by the full barrier implied by the CAS in putMVar#.
- *
  *  - Sending a Message to another capability:
  *    This is protected by the acquition and release of the target capability's
  *    lock in Messages.c:sendMessage.


=====================================
rts/sm/CNF.c
=====================================
@@ -543,7 +543,6 @@ insertCompactHash (Capability *cap,
 {
     insertHashTable(str->hash, (StgWord)p, (const void*)to);
     const StgInfoTable *strinfo = str->header.info;
-    load_load_barrier();
     if (strinfo == &stg_COMPACT_NFDATA_CLEAN_info) {
         strinfo = &stg_COMPACT_NFDATA_DIRTY_info;
         recordClosureMutated(cap, (StgClosure*)str);
@@ -688,7 +687,6 @@ verify_consistency_block (StgCompactNFData *str, StgCompactNFDataBlock *block)
         ASSERT(LOOKS_LIKE_CLOSURE_PTR(q));
 
         info = get_itbl(q);
-        load_load_barrier();
         switch (info->type) {
         case CONSTR_1_0:
             check_object_in_compact(str, UNTAG_CLOSURE(q->payload[0]));
@@ -928,7 +926,6 @@ fixup_block(StgCompactNFDataBlock *block, StgWord *fixup_table, uint32_t count)
     while (p < bd->free) {
         ASSERT(LOOKS_LIKE_CLOSURE_PTR(p));
         info = get_itbl((StgClosure*)p);
-        load_load_barrier();
 
         switch (info->type) {
         case CONSTR_1_0:


=====================================
rts/sm/MarkWeak.c
=====================================
@@ -235,7 +235,10 @@ static bool tidyWeakList(generation *gen)
     for (w = gen->old_weak_ptr_list; w != NULL; w = next_w) {
 
         info = w->header.info;
-        load_load_barrier();
+        /* N.B. This function is executed only during the serial part of GC
+         * so consequently there is no potential for data races and therefore
+         * no need for memory barriers.
+         */
 
         /* There might be a DEAD_WEAK on the list if finalizeWeak# was
          * called on a live weak pointer object.  Just remove it.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/233c879a7f877ec3a9efcab69248556a074b4154

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/233c879a7f877ec3a9efcab69248556a074b4154
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190618/d4219865/attachment-0001.html>


More information about the ghc-commits mailing list