[GHC] #16044: Transition to C11 memory model

#16044: Transition to C11 memory model -------------------------------------+------------------------------------- Reporter: ulan | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Runtime | Version: 8.6.3 System | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Following offline discussion with Ben Gamari and [https://mail.haskell.org/pipermail/ghc-devs/2018-November/016581.html Cmm Memory Model thread on ghc-devs@], I would like to propose to gradually transition RTS and Cmm to C11 memory model. There are multiple benefits: 1) Correctness: C11 atomics are properly specified and are easier to reason about than the existing SMP.h barriers. 2) Performance: compilers can optimize and generate better code for C11 atomics. For example, on ARMv8 acquire/release operations use specialized LDA/STL instructions. 3) Tooling support: once all code transitions to C11 atomics, tools like ThreadSanitizer can be used to find subtle data races. To make sure that code continues to compile with old compilers (pre C11), I plan to introduce wrapper functions (acquire_load, release_store, etc.) that are implemented either using C11 atomics or SMP.h barriers depending on the STDC_VERSION. Here is a [https://github.com/ulan/ghc/commit/0e8822a8038c3d0c770f4582c8f65b20d7823769 prototype implementation]. The idea is that newly written code should use the wrappers and we can gradually update the existing code. I think updating C code in RTS would work with this approach, but I am not sure about Cmm. Please let me know if you see potential issues, a better way to implement it, or oppose moving to C11 memory model. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16044 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16044: Transition to C11 memory model -------------------------------------+------------------------------------- Reporter: ulan | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: simonmar (added) Comment: Thank you for doing this, Ulan! CCing Simon Marlow, who I have also discussed this briefly with at a ICFP. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16044#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16044: Transition to C11 memory model -------------------------------------+------------------------------------- Reporter: ulan | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by adamse): * cc: adamse (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16044#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16044: Transition to C11 memory model -------------------------------------+------------------------------------- Reporter: ulan | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonmar): What would it mean for Cmm to use the C11 memory model? Do you imagine having new atomic types, and adding all the C11 atomic operations to MachOp? What about the memory order stuff? My understand is that since GHC compiles Cmm to native code, the implementation of the memory model would entail inserting barriers in the appropriate places according to the target architecture. So we still need the barriers, right? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16044#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16044: Transition to C11 memory model -------------------------------------+------------------------------------- Reporter: ulan | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ulan): [re-entering my reply via Trac UI as my email reply was not picked up] That's a good question. I am not sure what would be the best approach for Cmm. I am thinking about extending the existing atomic MachOps (MO_AtomicRead, MO_AtomicWrite, etc) with the memory order that would be similar to LlvmSyncOrdering. Then compiling to LLVM would be straightforward. For other backends, we indeed would have to provide architecture specific implementation of the atomics ops (e.g. https://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16044#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16044: Transition to C11 memory model -------------------------------------+------------------------------------- Reporter: ulan | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by lelf): * cc: lelf (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16044#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16044: Transition to C11 memory model -------------------------------------+------------------------------------- Reporter: ulan | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by osa1): * cc: osa1 (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16044#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16044: Transition to C11 memory model -------------------------------------+------------------------------------- Reporter: ulan | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by trommler): * cc: trommler (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16044#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC