[GHC] #8083: setNumCapabilities broken in HEAD
#8083: setNumCapabilities broken in HEAD --------------------------+------------------------------------------------ Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 7.7 Runtime System | Operating System: Unknown/Multiple Keywords: | Type of failure: Incorrect result at runtime Architecture: | Test Case: Unknown/Multiple | Blocking: Difficulty: | Unknown | Blocked By: | Related Tickets: | --------------------------+------------------------------------------------ {{{ #!haskell import GHC.Conc import Control.Monad main :: IO () main = do n <- getNumCapabilities when (n == 1) $ setNumCapabilities 2 print () }}} One would expect this program to print () just once, but when compiled with -O or -O2 it prints () repeatedly and indefinitely! This doesn't happen on GHC 7.6.2 or 7.4.1, only on HEAD. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by parcs): Even simpler test case: {{{ #!haskell import GHC.Conc import Control.Monad main :: IO () main = do n <- getNumCapabilities when (n == 1) $ setNumCapabilities 2 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by parcs): After further investigation this doesn't appear to be intrinsic to setNumCapabilities; rather, it looks like a bug in the codegen related to safe foreign ccalls. Another test case: {{{ #!haskell import GHC.Conc import Foreign.C foreign import ccall safe blah :: IO () main :: IO () main = do n <- getNumCapabilities case n of 1 -> blah _ -> return () }}} {{{ #!c void blah () { } }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonmar): * cc: simonmar (added) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: T8083 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by igloo): * testcase: => T8083 Comment: We get this: {{{ ==================== Post control-flow optimisations ==================== {offset c18y: if (Sp - <highSp> < SpLim) goto c18D; else goto c18E; c18D: R1 = Main.main1_closure; call (stg_gc_fun)(R1) args: 8, res: 0, upd: 8; c18E: _s188::I64 = %MO_SS_Conv_W32_W64(I32[n]); _s188::I64 = _s188::I64; _s189::I64 = _s188::I64; if (_s189::I64 != 1) goto c18w; else goto c18x; c18w: R1 = GHC.Tuple.()_closure+1; call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8; c18x: _c18B::I64 = blah; I64[(young<c18C> + 8)] = c18C; foreign call "ccall" arg hints: [] result hints: [] (_c18B::I64)(...) returns to c18C args: ([]) ress: ([])upd: 8; c18C: R1 = GHC.Tuple.()_closure+1; call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8; } }}} note that `c18w` and `c18C` look identical. They then get commoned up: {{{ ==================== Post common block elimination ==================== {offset c18y: if (Sp - <highSp> < SpLim) goto c18D; else goto c18E; c18D: R1 = Main.main1_closure; call (stg_gc_fun)(R1) args: 8, res: 0, upd: 8; c18E: _s188::I64 = %MO_SS_Conv_W32_W64(I32[n]); _s188::I64 = _s188::I64; _s189::I64 = _s188::I64; if (_s189::I64 != 1) goto c18w; else goto c18x; c18x: _c18B::I64 = blah; I64[(young<c18w> + 8)] = c18w; foreign call "ccall" arg hints: [] result hints: [] (_c18B::I64)(...) returns to c18w args: ([]) ress: ([])upd: 8; c18w: R1 = GHC.Tuple.()_closure+1; call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8; } }}} The problem is that the code ends up looking like this: {{{ # at this point rbp = <stg_catch_frame_info> _c18E: movslq n,%rax cmpq $1,%rax jne _c18w # if n /= 1, we jump to _c18w with rbp = <stg_catch_frame_info>, and _c18w will jump to stg_catch_frame_info. _c18x: movq $block_c18w_info,-8(%rbp) addq $-8,%rbp # Now we've pushed _c18w onto the stack movq 296(%r13),%rax movq 24(%rax),%rax # save the stack... movq %rbp,16(%rax) leaq 8(%r12),%rax movq 312(%r13),%rbx movq %rax,8(%rbx) movq %r13,%rdi xorl %esi,%esi subq $8,%rsp movl $0,%eax call suspendThread addq $8,%rsp subq $8,%rsp movq %rax,%rbx movl $0,%eax call blah addq $8,%rsp movq %rbx,%rdi subq $8,%rsp movl $0,%eax call resumeThread addq $8,%rsp movq %rax,%r13 movq 296(%r13),%rax movq 24(%rax),%rax # ...restore the stack movq 16(%rax),%rbp leaq 192(%rax),%r15 movq $0,328(%r13) movq 312(%r13),%rax movq 8(%rax),%rax leaq -8(%rax),%r12 movq 312(%r13),%rax movslq 48(%rax),%rax shlq $12,%rax decq %rax movq 312(%r13),%rbx movq (%rbx),%rbx addq %rax,%rbx movq %rbx,280(%r13) # jump to the top fo the stack - that's the _c18w that we pushed earlier. # But now _c18w will jump to the top of the stack - which is still _c18w! # Infinite loop. jmp *(%rbp) block_c18w_info: _c18w: movl $GHC.Tuple.()_closure+1,%ebx jmp *(%rbp) }}} The second jump to `_c18w` wanted to be jumping to somewhere that would also add 8 to the stack pointer. For now I've disabled the common block eliminator in `cmm/CmmPipeline.hs`, which gets everything working, but we should fix this better. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: T8083 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by igloo): * priority: normal => high * milestone: => 7.8.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: T8083 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by ian@…): commit be89c675339982cb53a5e32d6d282410c9c50f7c {{{ Author: Ian Lynagh <ian@well-typed.com> Date: Tue Jul 23 13:43:51 2013 +0100 Temporarily disable common block elimination; fixes #8083 for now compiler/cmm/CmmPipeline.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: T8083 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by jstolarek): * cc: jan.stolarek@… (added) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: T8083 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonmar): * priority: high => highest Comment: Thanks Ian, probably a bug in `CmmLayoutStack`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | simonmar Priority: highest | Status: new Component: Runtime System | Milestone: 7.8.1 Resolution: | Version: 7.7 Operating System: Unknown/Multiple | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: T8083 | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonmar): * owner: => simonmar Comment: I have a fix, just waiting for validate breakage to be fixed. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | simonmar Priority: highest | Status: new Component: Runtime System | Milestone: 7.8.1 Resolution: | Version: 7.7 Operating System: Unknown/Multiple | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: T8083 | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by marlowsd@…): commit c23488590cd65fa584ddd648cdbab2fa13f5656b {{{ Author: Simon Marlow <marlowsd@gmail.com> Date: Wed Jul 24 12:49:58 2013 +0100 Fix a bug in stack layout with safe foreign calls (#8083) We weren't properly tracking the number of stack arguments in the continuation of a foreign call. It happened to work when the continuation was not a join point, but when it was a join point we were using the wrong amount of stack fixup. compiler/cmm/CmmCommonBlockElim.hs | 2 +- compiler/cmm/CmmLayoutStack.hs | 15 ++++++++------- compiler/cmm/CmmLint.hs | 2 +- compiler/cmm/CmmNode.hs | 11 ++++++----- compiler/cmm/CmmPipeline.hs | 6 ++---- compiler/cmm/PprCmm.hs | 5 +++-- compiler/codeGen/StgCmmForeign.hs | 3 ++- 7 files changed, 23 insertions(+), 21 deletions(-) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | simonmar Priority: highest | Status: closed Component: Runtime System | Milestone: 7.8.1 Resolution: fixed | Version: 7.7 Operating System: Unknown/Multiple | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: T8083 | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonmar): * status: new => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC