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

Use available_parallelism instead of num_cpus #10427

Merged
merged 2 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ libc = "0.2"
log = "0.4.6"
libgit2-sys = "0.12.24"
memchr = "2.1.3"
num_cpus = "1.0"
opener = "0.5"
os_info = "3.0.7"
percent-encoding = "2.0"
Expand Down
6 changes: 5 additions & 1 deletion src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cargo_util::ProcessBuilder;
use serde::ser;
use std::cell::RefCell;
use std::path::PathBuf;
use std::thread::available_parallelism;

/// Configuration information for a rustc build.
#[derive(Debug)]
Expand Down Expand Up @@ -70,7 +71,10 @@ impl BuildConfig {
its environment, ignoring the `-j` parameter",
)?;
}
let jobs = jobs.or(cfg.jobs).unwrap_or(::num_cpus::get() as u32);
let jobs = match jobs.or(cfg.jobs) {
Some(j) => j,
None => available_parallelism()?.get() as u32,
Copy link
Member

Choose a reason for hiding this comment

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

Could the error-propagation here have some context indicating what the error is? (e.g. something like "failed to determine the amount of parallelism available")

};
if jobs == 0 {
anyhow::bail!("jobs may not be 0");
}
Expand Down
6 changes: 5 additions & 1 deletion src/cargo/core/compiler/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use anyhow::Context as _;
use cargo_util::paths;
use std::collections::HashMap;
use std::io::{BufWriter, Write};
use std::thread::available_parallelism;
use std::time::{Duration, Instant, SystemTime};

pub struct Timings<'cfg> {
Expand Down Expand Up @@ -380,6 +381,9 @@ impl<'cfg> Timings<'cfg> {
};
let total_time = format!("{:.1}s{}", duration, time_human);
let max_concurrency = self.concurrency.iter().map(|c| c.active).max().unwrap();
let num_cpus = available_parallelism()
.map(|x| x.get().to_string())
.unwrap_or_else(|_| "n/a".into());
let max_rustc_concurrency = self
.concurrency
.iter()
Expand Down Expand Up @@ -442,7 +446,7 @@ impl<'cfg> Timings<'cfg> {
self.total_fresh + self.total_dirty,
max_concurrency,
bcx.build_config.jobs,
num_cpus::get(),
num_cpus,
self.start_str,
total_time,
rustc_info,
Expand Down