Skip to content

Commit e65de39

Browse files
authored
Rollup merge of rust-lang#100586 - the8472:available_parallelism_2, r=jyn514
Reland changes replacing num_cpus with available_parallelism Since rust-lang#97925 added cgroupv1 support the problem in rust-lang#97549 which lead to the previous revert should be addressed now. Cargo has reapplied the replacement too rust-lang/cargo#10969 Reverts 1ae4b25 (part of rust-lang#97911) Relands rust-lang#94524
2 parents fba3004 + 8453122 commit e65de39

File tree

10 files changed

+7
-11
lines changed

10 files changed

+7
-11
lines changed

Cargo.lock

-2
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ dependencies = [
257257
"anyhow",
258258
"flate2",
259259
"hex 0.4.2",
260-
"num_cpus",
261260
"rayon",
262261
"serde",
263262
"serde_json",
@@ -4442,7 +4441,6 @@ name = "rustc_session"
44424441
version = "0.0.0"
44434442
dependencies = [
44444443
"getopts",
4445-
"num_cpus",
44464444
"rustc_ast",
44474445
"rustc_data_structures",
44484446
"rustc_errors",

compiler/rustc_session/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ rustc_serialize = { path = "../rustc_serialize" }
1515
rustc_data_structures = { path = "../rustc_data_structures" }
1616
rustc_span = { path = "../rustc_span" }
1717
rustc_fs_util = { path = "../rustc_fs_util" }
18-
num_cpus = "1.0"
1918
rustc_ast = { path = "../rustc_ast" }
2019
rustc_lint_defs = { path = "../rustc_lint_defs" }

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ mod parse {
582582
pub(crate) fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
583583
match v.and_then(|s| s.parse().ok()) {
584584
Some(0) => {
585-
*slot = ::num_cpus::get();
585+
*slot = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get);
586586
true
587587
}
588588
Some(i) => {

src/bootstrap/Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ dependencies = [
5353
"hex",
5454
"ignore",
5555
"libc",
56-
"num_cpus",
5756
"once_cell",
5857
"opener",
5958
"pretty_assertions",

src/bootstrap/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ test = false
3838
cmake = "0.1.38"
3939
fd-lock = "3.0.6"
4040
filetime = "0.2"
41-
num_cpus = "1.0"
4241
getopts = "0.2.19"
4342
cc = "1.0.69"
4443
libc = "0.2"

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ fn set<T>(field: &mut T, val: Option<T>) {
14651465

14661466
fn threads_from_config(v: u32) -> u32 {
14671467
match v {
1468-
0 => num_cpus::get() as u32,
1468+
0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32,
14691469
n => n,
14701470
}
14711471
}

src/bootstrap/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
220220
let j_msg = format!(
221221
"number of jobs to run in parallel; \
222222
defaults to {} (this host's logical CPU count)",
223-
num_cpus::get()
223+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get)
224224
);
225225
opts.optopt("j", "jobs", &j_msg, "JOBS");
226226
opts.optflag("h", "help", "print this help message");

src/bootstrap/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,9 @@ impl Build {
10081008
/// Returns the number of parallel jobs that have been configured for this
10091009
/// build.
10101010
fn jobs(&self) -> u32 {
1011-
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
1011+
self.config.jobs.unwrap_or_else(|| {
1012+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32
1013+
})
10121014
}
10131015

10141016
fn debuginfo_map_to(&self, which: GitRepo) -> Option<String> {

src/tools/build-manifest/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ tar = "0.4.29"
1313
sha2 = "0.10.1"
1414
rayon = "1.5.1"
1515
hex = "0.4.2"
16-
num_cpus = "1.13.0"

src/tools/build-manifest/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn main() {
210210
let num_threads = if let Some(num) = env::var_os("BUILD_MANIFEST_NUM_THREADS") {
211211
num.to_str().unwrap().parse().expect("invalid number for BUILD_MANIFEST_NUM_THREADS")
212212
} else {
213-
num_cpus::get()
213+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get)
214214
};
215215
rayon::ThreadPoolBuilder::new()
216216
.num_threads(num_threads)

0 commit comments

Comments
 (0)