Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only collapse commits and barriers where sound #284

Merged
merged 4 commits into from Jul 15, 2018
Merged

Conversation

@barrucadu
Copy link
Owner

barrucadu commented Jul 15, 2018

Summary

-- | Throw away commit actions which are followed by a memory barrier.
dropCommits :: Bool -> MemType -> [(ThreadId, ThreadAction)] -> [(ThreadId, ThreadAction)]
dropCommits _ SequentialConsistency = id
dropCommits safeIO memtype = go initialDepState where
go ds (t1@(tid1, ta1@(CommitIORef _ _)):t2@(tid2, ta2):trc)
| isBarrier (simplifyAction ta2) = go ds (t2:trc)
| independent safeIO ds tid1 ta1 tid2 ta2 = t2 : go (updateDepState memtype ds tid2 ta2) (t1:trc)
go ds (t@(tid,ta):trc) = t : go (updateDepState memtype ds tid ta) trc
go _ [] = []

This is only sound if there are no buffered writes for that IORef from other threads. This PR implements a slightly overzealous restriction, where it will only remove a commit like that if there are no other buffered writes for that IORef at all.

Related issues: closes #275

barrucadu added 4 commits Jul 15, 2018
It's only sound to remove a commit if there are no other buffered
writes for that `IORef`.  Say we have a `IORef` with two buffered
writes, followed by a memory barrier, we get (amongst others) these
two trace fragments:

    C1  ->  barrier        = C2 wins
    C2  ->  barrier        = C1 wins

If we collapse these two to just `barrier`, then we will only get one
of the results.
@barrucadu barrucadu changed the title 275 commit collapsing Only collapse commits and barriers where sound Jul 15, 2018
@barrucadu barrucadu merged commit c499ccb into master Jul 15, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@barrucadu barrucadu deleted the 275-commit-collapsing branch Jul 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.