Opened 12 months ago

Closed 6 months 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 Revisions: Phab:D592

Description

The problem was found when i tried to eventlog ghc --make itself. I've missinterpreted is as a threadscope bug: https://github.com/haskell/ThreadScope/issues/37

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 12 months ago.
test from description

Download all attachments as: .zip

Change History (10)

Changed 12 months ago by slyfox

test from description

comment:1 Changed 11 months ago by gintas

  • Cc gintas added

comment:2 Changed 11 months ago by gintas

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

comment:3 Changed 9 months ago by MikolajKonarski

  • Milestone set to 7.10.1
  • Priority changed from normal to high

comment:4 Changed 7 months ago by qnikst

  • Cc qnikst added
  • Differential Revisions set to D592

comment:5 Changed 7 months ago by slyfox

  • Status changed from new to patch

comment:6 Changed 7 months ago by thoughtpolice

  • Differential Revisions changed from D592 to Phab:D592

comment:7 Changed 6 months 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: https://phabricator.haskell.org/D592

GHC Trac Issues: #9384

comment:8 Changed 6 months ago by slyfox

  • Status changed from patch to merge

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

comment:9 Changed 6 months ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from merge to closed

Merged to ghc-7.10.

Note: See TracTickets for help on using tickets.