Skip to content

Commit ccbfe50

Browse files
authored
Merge pull request rust-lang#4152 from RalfJung/many-seeds
many-seeds: do not use more than 8 threads
2 parents d7e942e + d7f1656 commit ccbfe50

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/tools/miri/src/bin/miri.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::ops::Range;
3030
use std::path::PathBuf;
3131
use std::str::FromStr;
3232
use std::sync::Once;
33-
use std::sync::atomic::{AtomicI32, Ordering};
33+
use std::sync::atomic::{AtomicI32, AtomicU32, Ordering};
3434

3535
use miri::{
3636
BacktraceStyle, BorrowTrackerMethod, MiriConfig, MiriEntryFnType, ProvenanceMode, RetagFields,
@@ -183,7 +183,8 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
183183
if let Some(many_seeds) = self.many_seeds.take() {
184184
assert!(config.seed.is_none());
185185
let exit_code = sync::IntoDynSyncSend(AtomicI32::new(rustc_driver::EXIT_SUCCESS));
186-
sync::par_for_each_in(many_seeds.seeds, |seed| {
186+
let num_failed = sync::IntoDynSyncSend(AtomicU32::new(0));
187+
sync::par_for_each_in(many_seeds.seeds.clone(), |seed| {
187188
let mut config = config.clone();
188189
config.seed = Some(seed.into());
189190
eprintln!("Trying seed: {seed}");
@@ -197,8 +198,13 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
197198
std::process::exit(return_code);
198199
}
199200
exit_code.store(return_code, Ordering::Relaxed);
201+
num_failed.fetch_add(1, Ordering::Relaxed);
200202
}
201203
});
204+
let num_failed = num_failed.0.into_inner();
205+
if num_failed > 0 {
206+
eprintln!("{num_failed}/{total} SEEDS FAILED", total = many_seeds.seeds.count());
207+
}
202208
std::process::exit(exit_code.0.into_inner());
203209
} else {
204210
let return_code = miri::eval_entry(tcx, entry_def_id, entry_type, config)
@@ -717,10 +723,9 @@ fn main() {
717723

718724
// Ensure we have parallelism for many-seeds mode.
719725
if many_seeds.is_some() && !rustc_args.iter().any(|arg| arg.starts_with("-Zthreads=")) {
720-
rustc_args.push(format!(
721-
"-Zthreads={}",
722-
std::thread::available_parallelism().map_or(1, |n| n.get())
723-
));
726+
// Clamp to 8 threads; things get a lot less efficient beyond that due to lock contention.
727+
let threads = std::thread::available_parallelism().map_or(1, |n| n.get()).min(8);
728+
rustc_args.push(format!("-Zthreads={threads}"));
724729
}
725730
let many_seeds =
726731
many_seeds.map(|seeds| ManySeedsConfig { seeds, keep_going: many_seeds_keep_going });

0 commit comments

Comments
 (0)