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

Miri: run liballoc tests with threads #71737

Merged
merged 2 commits into from
May 12, 2020
Merged

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented May 1, 2020

Miri now supports threads, so we can run these tests. :)

@rust-highfive
Copy link
Collaborator

r? @shepmaster

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 1, 2020
}
a.store(true, SeqCst);
});

while !a2.load(SeqCst) {
let n = Arc::weak_count(&a2);
assert!(n < 2, "bad weak count: {}", n);
#[cfg(miri)] // The Miri scheduler won't reschedule if we do not yield.
thread::yield_now();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vakaras this demonstrates an issue with the current Miri scheduling policy: I had to adjust the code to avoid deadlocks. IMO we should introduce something where threads also get descheduled occasionally even when they do not yield.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to adjust the code to avoid deadlocks

If I understand correctly, Miri did not terminate in this case, right?

IMO we should introduce something where threads also get descheduled occasionally even when they do not yield.

I have to agree with you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, Miri did not terminate in this case, right?

Yes. It just ran and ran and probably was just sitting in this loop forever.

@RalfJung RalfJung force-pushed the miri-test-threads branch from 8e3a3d1 to 68b454e Compare May 3, 2020 10:38
@RalfJung RalfJung mentioned this pull request May 5, 2020
@shepmaster
Copy link
Member

The changes seem... OK... to me, but the fact that it introduced what is effectively an infinite loop seems like a downside. I don't really have enough vision to decide what the risks are here.

@RalfJung
Copy link
Member Author

RalfJung commented May 6, 2020

It did not introduce the infinite loop, the loop was already there.

@shepmaster I can gate the spin_loop hint on [cfg(miri)] to make this guaranteed no-behavioral-change outside Miri, would that help?

bors added a commit to rust-lang-ci/rust that referenced this pull request May 8, 2020
update miri

In particular this includes the change to yield on `spin_loop_hint`, which is needed for rust-lang#71737.
r? @ghost Cc @rust-lang/miri

Fixes rust-lang#71963
@RalfJung
Copy link
Member Author

@shepmaster I am confused by your last message here (see above), could you clarify?

@shepmaster
Copy link
Member

It did not introduce the infinite loop, the loop was already there.

This feels like a case of semantics. The PR enabled Miri, which caused Miri to run code forever. The fix (thread::yield_now) was only enabled for Miri. Do I understand correctly that any operating system could theoretically end up in an infinite loop depending on the vagaries of the scheduler? If so, should the yield be applied unconditionally?

My bigger question is more along the lines of "does this PR make that underlying infinite loop possible in other cases?". That is, by merging this, are we going to get "strange" failures in other code?

@RalfJung
Copy link
Member Author

Do I understand correctly that any operating system could theoretically end up in an infinite loop depending on the vagaries of the scheduler?

No. Real schedulers make liveness guarantees, i.e. they guarantee that "threads will eventually get scheduled". It might still be inefficient to spin (though yielding is probably worse on a true multicore system, which is why I made the hint Miri-only). However, Miri's scheduler currently does not guarantee liveness (rust-lang/miri#1388).

And anyway this is a weird spin loop -- it is not part of some synchronization but actually trying to catch bugs.

My bigger question is more along the lines of "does this PR make that underlying infinite loop possible in other cases?".

The PR does not add an infinite loop, so how should that be possible? If anything the PR removes the possibility of an infinite loop. I am very confused by this question.

That is, by merging this, are we going to get "strange" failures in other code?

I think I'll make the spin_loop hint Miri-only again, then it certainly cannot affect any code anywhere or reduce test coverage outside Miri.

@RalfJung RalfJung force-pushed the miri-test-threads branch from 68b454e to 7bea58e Compare May 11, 2020 14:50
@shepmaster
Copy link
Member

The PR does not add an infinite loop, so how should that be possible? If anything the PR removes the possibility of an infinite loop. I am very confused by this question.

Before this PR, the test suite did not spin infinitely in that test ("Miri did not terminate in this case, right?" "Yes. It just ran and ran and probably was just sitting in this loop forever."). Thus, the first version of the PR introduced/exposed/demonstrated/caused existing code to never terminate.

Running some kind of "normal code" in Miri results in non-termination — is it possible that this non-termination will show up in other testcases?

@RalfJung
Copy link
Member Author

Thus, the first version of the PR introduced/exposed/demonstrated/caused existing code to never terminate.

"introduced" and "demonstrated" are very different things though? The version of this code in master spins forever in Miri, due to rust-lang/miri#1388. That was just never a problem because this code never got run in Miri before. This PR doesn't introduce any new spinning. It give the Miri scheduler the hint it needs to avoid the endless spinning.

Running some kind of "normal code" in Miri results in non-termination — is it possible that this non-termination will show up in other testcases?

Yes it is. And then we'll deal with it when it comes up. Miri tests don't run as part of regular CI, they run externally, so if this ever happens (seems unlikely given that this is the only case in the entire test suite so far) it'll not concern anyone but me.

@shepmaster
Copy link
Member

they run externally, so if this ever happens (seems unlikely given that this is the only case in the entire test suite so far) it'll not concern anyone but me.

Ah, this is a key part of understanding — I didn't want to unduly hamper a rustc contributor due to a current limitation of a Miri feature.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 11, 2020

📌 Commit 7bea58e has been approved by shepmaster

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 11, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 12, 2020
…aster

Miri: run liballoc tests with threads

Miri now supports threads, so we can run these tests. :)
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 12, 2020
…aster

Miri: run liballoc tests with threads

Miri now supports threads, so we can run these tests. :)
bors added a commit to rust-lang-ci/rust that referenced this pull request May 12, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#71737 (Miri: run liballoc tests with threads)
 - rust-lang#71928 (Add strikethrough support to rustdoc)
 - rust-lang#72048 (Visit move out of `_0` when visiting `return`)
 - rust-lang#72096 (Make MIR typeck use `LocalDefId` and fix docs)
 - rust-lang#72128 (strings do not have to be valid UTF-8 any more)

Failed merges:

r? @ghost
@bors bors merged commit 2a1581c into rust-lang:master May 12, 2020
@RalfJung RalfJung deleted the miri-test-threads branch May 14, 2020 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants