Skip to content

Commit

Permalink
Auto merge of #67398 - Mark-Simulacrum:no-jobserver-herds, r=<try>
Browse files Browse the repository at this point in the history
Communicate over stderr jobserver token acquiring/releasing

This set of commits revises the jobserver communication inside rustc to always go through a shim around the real jobserver crate to allow us to inform Cargo of when tokens are intended to be acquired/released.

The Cargo side of this hasn't yet been implemented at all yet.
  • Loading branch information
bors committed Dec 18, 2019
2 parents 19bd934 + 0689914 commit db9d3a5
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 83 deletions.
15 changes: 12 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,6 @@ dependencies = [
"chalk-engine",
"fmt_macros",
"graphviz",
"jobserver",
"log",
"measureme",
"num_cpus",
Expand All @@ -3166,6 +3165,7 @@ dependencies = [
"rustc_feature",
"rustc_fs_util",
"rustc_index",
"rustc_jobserver",
"rustc_macros",
"rustc_session",
"rustc_target",
Expand Down Expand Up @@ -3464,7 +3464,6 @@ version = "0.0.0"
dependencies = [
"bitflags",
"cc",
"jobserver",
"libc",
"log",
"memmap",
Expand All @@ -3478,6 +3477,7 @@ dependencies = [
"rustc_fs_util",
"rustc_incremental",
"rustc_index",
"rustc_jobserver",
"rustc_session",
"rustc_target",
"serialize",
Expand Down Expand Up @@ -3511,7 +3511,6 @@ dependencies = [
"ena",
"graphviz",
"indexmap",
"jobserver",
"lazy_static 1.3.0",
"log",
"measureme",
Expand Down Expand Up @@ -3623,6 +3622,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_incremental",
"rustc_jobserver",
"rustc_lint",
"rustc_metadata",
"rustc_mir",
Expand All @@ -3643,6 +3643,15 @@ dependencies = [
"tempfile",
]

[[package]]
name = "rustc_jobserver"
version = "0.0.0"
dependencies = [
"jobserver",
"lazy_static 1.3.0",
"serialize",
]

[[package]]
name = "rustc_lexer"
version = "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ arena = { path = "../libarena" }
bitflags = "1.2.1"
fmt_macros = { path = "../libfmt_macros" }
graphviz = { path = "../libgraphviz" }
jobserver = "0.1"
rustc_jobserver = { path = "../librustc_jobserver" }
num_cpus = "1.0"
scoped-tls = "1.0"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/ty/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use std::ptr;
#[cfg(parallel_compiler)]
use {
parking_lot::{Mutex, Condvar},
rustc_data_structures::{jobserver, OnDrop},
rustc_data_structures::{OnDrop},
rustc_jobserver as jobserver,
rustc_data_structures::fx::FxHashSet,
rustc_data_structures::stable_hasher::{StableHasher, HashStable},
rustc_data_structures::sync::Lock,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ num_cpus = "1.0"
memmap = "0.7"
log = "0.4.5"
libc = "0.2.44"
jobserver = "0.1.11"
tempfile = "3.1"

rustc_serialize = { path = "../libserialize", package = "serialize" }
Expand All @@ -33,3 +32,4 @@ rustc_index = { path = "../librustc_index" }
rustc_target = { path = "../librustc_target" }
rustc_error_codes = { path = "../librustc_error_codes" }
rustc_session = { path = "../librustc_session" }
rustc_jobserver = { path = "../librustc_jobserver" }
39 changes: 13 additions & 26 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ use rustc_target::spec::MergeFunctions;
use syntax::attr;
use syntax_pos::hygiene::ExpnId;
use syntax_pos::symbol::{Symbol, sym};
use jobserver::{Client, Acquired};
use rustc_jobserver::Acquired;

use std::any::Any;
use std::fs;
use std::io;
use std::mem;
use std::path::{Path, PathBuf};
use std::str;
Expand Down Expand Up @@ -433,7 +432,6 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
codegen_worker_send,
coordinator_receive,
total_cgus,
sess.jobserver.clone(),
Arc::new(modules_config),
Arc::new(metadata_config),
Arc::new(allocator_config),
Expand Down Expand Up @@ -890,7 +888,7 @@ fn execute_lto_work_item<B: ExtraBackendMethods>(
}

pub enum Message<B: WriteBackendMethods> {
Token(io::Result<Acquired>),
Token(Acquired),
NeedsFatLTO {
result: FatLTOInput<B>,
worker_id: usize,
Expand Down Expand Up @@ -938,7 +936,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
codegen_worker_send: Sender<Message<B>>,
coordinator_receive: Receiver<Box<dyn Any + Send>>,
total_cgus: usize,
jobserver: Client,
modules_config: Arc<ModuleConfig>,
metadata_config: Arc<ModuleConfig>,
allocator_config: Arc<ModuleConfig>,
Expand Down Expand Up @@ -981,9 +978,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
// get tokens on `coordinator_receive` which will
// get managed in the main loop below.
let coordinator_send2 = coordinator_send.clone();
let helper = jobserver.into_helper_thread(move |token| {
let helper = rustc_jobserver::helper_thread(move |token| {
drop(coordinator_send2.send(Box::new(Message::Token::<B>(token))));
}).expect("failed to spawn helper thread");
});

let mut each_linked_rlib_for_lto = Vec::new();
drop(link::each_linked_rlib(crate_info, &mut |cnum, path| {
Expand Down Expand Up @@ -1374,25 +1371,15 @@ fn start_executing_work<B: ExtraBackendMethods>(
// this to spawn a new unit of work, or it may get dropped
// immediately if we have no more work to spawn.
Message::Token(token) => {
match token {
Ok(token) => {
tokens.push(token);

if main_thread_worker_state == MainThreadWorkerState::LLVMing {
// If the main thread token is used for LLVM work
// at the moment, we turn that thread into a regular
// LLVM worker thread, so the main thread is free
// to react to codegen demand.
main_thread_worker_state = MainThreadWorkerState::Idle;
running += 1;
}
}
Err(e) => {
let msg = &format!("failed to acquire jobserver token: {}", e);
shared_emitter.fatal(msg);
// Exit the coordinator thread
panic!("{}", msg)
}
tokens.push(token);

if main_thread_worker_state == MainThreadWorkerState::LLVMing {
// If the main thread token is used for LLVM work
// at the moment, we turn that thread into a regular
// LLVM worker thread, so the main thread is free
// to react to codegen demand.
main_thread_worker_state = MainThreadWorkerState::Idle;
running += 1;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ doctest = false
ena = "0.13.1"
indexmap = "1"
log = "0.4"
jobserver_crate = { version = "0.1.13", package = "jobserver" }
lazy_static = "1"
rustc_serialize = { path = "../libserialize", package = "serialize" }
graphviz = { path = "../libgraphviz" }
Expand Down
42 changes: 0 additions & 42 deletions src/librustc_data_structures/jobserver.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pub mod flock;
pub mod fx;
pub mod stable_map;
pub mod graph;
pub mod jobserver;
pub mod obligation_forest;
pub mod owning_ref;
pub mod ptr_key;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rustc = { path = "../librustc" }
rustc_incremental = { path = "../librustc_incremental" }
rustc_traits = { path = "../librustc_traits" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_jobserver = { path = "../librustc_jobserver" }
rustc_codegen_ssa = { path = "../librustc_codegen_ssa" }
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
rustc_codegen_llvm = { path = "../librustc_codegen_llvm", optional = true }
Expand Down
14 changes: 14 additions & 0 deletions src/librustc_interface/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ pub fn run_compiler_in_existing_thread_pool<R>(

pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
let stderr = config.stderr.take();

if config.opts.debugging_opts.jobserver_token_requests {
if let config::ErrorOutputType::Json { .. } = config.opts.error_format {
if stderr.is_some() {
panic!("Non-default output not supported with -Zjobserver-token-requests");
}
} else {
panic!("-Zjobserver-token-requests can only be specified if using \
JSON error output type");
}
}

rustc_jobserver::initialize(config.opts.debugging_opts.jobserver_token_requests);

util::spawn_thread_pool(
config.opts.edition,
config.opts.debugging_opts.threads,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc::ty;
use rustc::lint;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
#[cfg(parallel_compiler)]
use rustc_data_structures::jobserver;
use rustc_jobserver as jobserver;
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_data_structures::fingerprint::Fingerprint;
Expand Down
15 changes: 15 additions & 0 deletions src/librustc_jobserver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
authors = ["The Rust Project Developers"]
name = "rustc_jobserver"
version = "0.0.0"
edition = "2018"

[lib]
name = "rustc_jobserver"
path = "lib.rs"
doctest = false

[dependencies]
jobserver_crate = { version = "0.1.13", package = "jobserver" }
lazy_static = "1"
rustc_serialize = { path = "../libserialize", package = "serialize" }
Loading

0 comments on commit db9d3a5

Please sign in to comment.