[GHC] #12419: Scheduling bug with forkOS + MVar

#12419: Scheduling bug with forkOS + MVar -----------------------------------------+--------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.0.1 Keywords: forkOS; scheduler | Operating System: Linux Architecture: x86_64 (amd64) | Type of failure: None/Unknown Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -----------------------------------------+--------------------------------- I have noticed a weird scheduling behavior when performing some experiments with the '''fasta''' benchmark [1] from The Computer Language Benchmarks Game. When I switch `forkIO` by `forkOS` the scheduler stops to assign work for some capabilities, and they stay idle for the whole execution of the program. ThreadScope view using forkIO: https://s31.postimg.org/r3mclspe3/fork_IO_N8_ghc8.png ThreadScope view using forkOS: https://s31.postimg.org/p9n265fff/fork_OS_N8_ghc8.png I was able to reproduce this behavior in both '''GHC 7.10.2''' and '''GHC 8.0.2'''. I was also able to reproduce it on two different machines running Ubuntu Server 14.04.3 LTS (kernel 3.19.0-25): - 2x10-core Intel Xeon E5-2660 v2 processors (Ivy Bridge), 2.20 GHz, with 256GB of DDR 1600MHz - 4-core Intel i7-3770 (IvyBridge) with 8 GB of DDR 1600MHz Source code + .eventlog files: https://dl.dropboxusercontent.com/u/5798150 /fasta-bug.zip [1] http://benchmarksgame.alioth.debian.org/u64q/program.php?test=fasta&lang=ghc&id=7 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by luisgabriel): * Attachment "forkIO-N8-ghc8.png" added. ThreadScope view using forkIO -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by luisgabriel): * Attachment "forkOS-N8-ghc8.png" added. ThreadScope view using forkOS -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonmar): The .zip file doesn't download for me (I get an error from dropbox), could you try putting it up somewhere else? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by luisgabriel): Replying to [comment:1 simonmar]:
The .zip file doesn't download for me (I get an error from dropbox), could you try putting it up somewhere else?
Sure. Try this link: http://cin.ufpe.br/~lgnfl/files/fasta-bug.zip -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2430 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonmar): * differential: => Phab:D2430 Comment: I found one bug, see Phab:D2430. However, even after the patch the threadscope profiles don't look identical. I don't think there is an actual problem, just that the program itself isn't very parallel - if you zoom in, there's lots of time in each thread where no work is being done. The difference in scheduling is due to the way that `forkOS` has to hand- shake with the new thread to get its `ThreadId`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.2 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2430 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: => 8.0.2 Comment: This should go in to 8.0.2. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

I found one bug, see Phab:D2430. However, even after the patch the
#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.2 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2430 Wiki Page: | -------------------------------------+------------------------------------- Comment (by luisgabriel): Replying to [comment:3 simonmar]: threadscope profiles don't look identical. I don't think there is an actual problem, just that the program itself isn't very parallel - if you zoom in, there's lots of time in each thread where no work is being done. The difference in scheduling is due to the way that `forkOS` has to hand- shake with the new thread to get its `ThreadId`. Indeed. This example is not very good. I did not expect the profiles to look identical, but it seemed a bit odd to me having a large number of capabilities in idle. Nevertheless, I'm happy to see you identified a bug in the scheduler. Thank you very much for the quick fix! Feel free to close this ticket when the patch lands. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar
-------------------------------------+-------------------------------------
Reporter: luisgabriel | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 8.0.2
Component: Runtime System | Version: 8.0.1
Resolution: | Keywords: forkOS;
| scheduler
Operating System: Linux | Architecture: x86_64
| (amd64)
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2430
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Marlow

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2430 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonmar): * status: new => merge Comment: This also depends on https://phabricator.haskell.org/rGHC55f5aed756cd5d464942dddcb33e0bd19b05f2a4 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.2 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | Phab:D2430,Phab:2441 -------------------------------------+------------------------------------- Changes (by simonmar): * status: merge => new * differential: Phab:D2430 => Phab:D2430,Phab:2441 Comment: Please don't merge this yet, there's another fix incoming. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.2 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2430, Wiki Page: | Phab:2441 -------------------------------------+------------------------------------- Changes (by simonmar): * differential: Phab:D2430,Phab:2441 => Phab:D2430, Phab:2441 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.2 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2430, Wiki Page: | Phab:D2441 -------------------------------------+------------------------------------- Changes (by simonmar): * differential: Phab:D2430, Phab:2441 => Phab:D2430, Phab:D2441 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar
-------------------------------------+-------------------------------------
Reporter: luisgabriel | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 8.0.2
Component: Runtime System | Version: 8.0.1
Resolution: | Keywords: forkOS;
| scheduler
Operating System: Linux | Architecture: x86_64
| (amd64)
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2430,
Wiki Page: | Phab:D2441
-------------------------------------+-------------------------------------
Comment (by Simon Marlow

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2430, Wiki Page: | Phab:D2441 -------------------------------------+------------------------------------- Changes (by simonmar): * status: new => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12419: Scheduling bug with forkOS + MVar
-------------------------------------+-------------------------------------
Reporter: luisgabriel | Owner:
Type: bug | Status: merge
Priority: normal | Milestone: 8.0.2
Component: Runtime System | Version: 8.0.1
Resolution: | Keywords: forkOS;
| scheduler
Operating System: Linux | Architecture: x86_64
| (amd64)
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2430,
Wiki Page: | Phab:D2441
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12419: Scheduling bug with forkOS + MVar
-------------------------------------+-------------------------------------
Reporter: luisgabriel | Owner:
Type: bug | Status: merge
Priority: normal | Milestone: 8.0.2
Component: Runtime System | Version: 8.0.1
Resolution: | Keywords: forkOS;
| scheduler
Operating System: Linux | Architecture: x86_64
| (amd64)
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2430,
Wiki Page: | Phab:D2441
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12419: Scheduling bug with forkOS + MVar -------------------------------------+------------------------------------- Reporter: luisgabriel | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: Runtime System | Version: 8.0.1 Resolution: fixed | Keywords: forkOS; | scheduler Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2430, Wiki Page: | Phab:D2441 -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12419#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC