Opened 4 years ago

Closed 4 years ago

#9384 closed bug (fixed)

setNumCapabilities call breaks eventlog events

Reported by: slyfox Owned by:
Priority: high Milestone: 7.10.1
Component: Profiling Version: 7.8.3
Keywords: Cc: gintas, qnikst
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Incorrect result at runtime Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D592
Wiki Page:


The problem was found when i tried to eventlog ghc --make itself. I've missinterpreted is as a threadscope bug:

Here is small program to reliably reproduce the bug:

module Main where

import qualified Data.List as L
import qualified System.Environment as E
import Control.Monad
import qualified Control.Concurrent as CC
import qualified Control.Concurrent.MVar as CC

slow_and_silly :: Int -> IO Int
slow_and_silly i = return $ length $ L.foldl' (\a v -> a ++ [v]) [] [1..i]

-- build as:
-- $ ghc --make a -O2 -threaded -eventlog

-- valid eventlog:
-- $ ./a 2 7000 +RTS -ls -N2
-- $ ghc-events validate threads a.eventlog
-- Valid eventlog:
-- ...

-- invalid eventlog
-- $ ./a 2 7000 +RTS -ls
-- $ ghc-events validate threads a.eventlog
-- Invalid eventlog:
-- ...

main = do
    [caps, count] <- E.getArgs
    let n_caps :: Int
        n_caps = read caps
        max_n :: Int
        max_n = read count

    CC.setNumCapabilities n_caps

    waits <- replicateM n_caps $ CC.newEmptyMVar

    forM_ waits $ \w -> CC.forkIO $ do
        slow_and_silly max_n >>= print
        CC.putMVar w ()

    forM_ waits $ \w -> CC.takeMVar w

How to reproduce (comments have ghc-events version):

$ ghc --make a -O2 -threaded -eventlog
$ ./a 2 7000 +RTS -ls -N2
$ threadscope a.eventlog # works
$ ./a 2 7000 +RTS -ls
$ threadscope a.eventlog # crashes

Attachments (1)

a.hs (968 bytes) - added by slyfox 4 years ago.
test from description

Download all attachments as: .zip

Change History (10)

Changed 4 years ago by slyfox

Attachment: a.hs added

test from description

comment:1 Changed 4 years ago by gintas

Cc: gintas added

comment:2 Changed 4 years ago by gintas

FWIW I also ran into this bug while trying to profile ghc itself.

comment:3 Changed 4 years ago by MikolajKonarski

Milestone: 7.10.1
Priority: normalhigh

comment:4 Changed 4 years ago by qnikst

Cc: qnikst added
Differential Rev(s): D592

comment:5 Changed 4 years ago by slyfox

Status: newpatch

comment:6 Changed 4 years ago by thoughtpolice

Differential Rev(s): D592Phab:D592

comment:7 Changed 4 years ago by Sergei Trofimovich <siarheit@…>

In 2edb4a7bd5b892ddfac75d0b549d6682a0be5c02/ghc:

Trac #9384: fix increasing capabilites number for eventlog.

Event log had inconcistent support for increacing capabilies
number, as header were not inserted in capability buffer. It
resulted in a ghc-events crash (see #9384). This commit
fixes this issue by inserting required header when number
of capabilies grows.

Reviewers: simonmar, Mikolaj, trofi, austin

Reviewed By: Mikolaj, trofi, austin

Subscribers: carter, thomie

Differential Revision:

GHC Trac Issues: #9384

comment:8 Changed 4 years ago by slyfox

Status: patchmerge

Tested manually on sample attached: works fine with threadscope-0.2.6 \o/

comment:9 Changed 4 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed

Merged to ghc-7.10.

Note: See TracTickets for help on using tickets.