Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 451
    • Merge requests 451
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #12019
Closed
Open
Created May 06, 2016 by erikd@trac-erikd

Profiling option -hb is not thread safe

This ticket is a continuation of #11978 (closed) and #12009 (closed). After fixing a couple of issues in those two tickets I found that the profiling run time is not thread safe.

Have a trivial test program (written as one of the tests for #11978 (closed)):

import Control.Concurrent
import Control.Concurrent.MVar
import Control.Exception
import Control.Monad

main :: IO ()
main = do
    putStrLn "Start ..."
    mvar <- newMVar (0 :: Int)

    let count = 50

    forM_ [ 1 .. count ] $ const $ forkIO $ do
            threadDelay 100
            i <- takeMVar mvar
            putMVar mvar $! i + 1

    threadDelay 1000000
    end <- takeMVar mvar
    putStrLn $ "Final result " ++ show end
    assert (end == count) $ return ()

Compiling that with a compiler that has bug fixes arising from #11978 (closed) and #12009 (closed) as:

inplace/bin/ghc-stage2 testsuite/tests/profiling/should_run/T11978b.hs \
    -fforce-recomp -rtsopts -fno-warn-tabs -O -prof -static -auto-all \
    -threaded -debug -o T11978b

and run as:

./T11978b +RTS -p -hb -N10 

crashes in a number of different ways. I've seen at least 3 different assertion failures and numerous segfaults (in different stg_ap_* functions).

Replace -hb with other profiling options like -hr etc do not seem to crash.

Looking at code, one example of lack of thread safetly is the function LDV_recordDead which mutates global variable censuses which does not have any locking around it. Only figured this out because the following assert (in LDV_recordDead) was being triggered occasionally.

    ASSERT(censuses[t].void_total < censuses[t].not_used);
Edited Mar 10, 2019 by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking