Skip to content

Run translation and LLVM in parallel when compiling with multiple CGUs #43506

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

Merged
merged 29 commits into from
Aug 1, 2017
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c4adece
async-llvm(1): Run LLVM already in trans_crate().
michaelwoerister Jul 21, 2017
29d4725
async-llvm(2): Decouple diagnostics emission from LLVM worker coordin…
michaelwoerister Jul 21, 2017
bac57cf
async-llvm(3): Make write::CodegenContext Clone and Send.
michaelwoerister Jul 24, 2017
df6be33
async-llvm(4): Move work coordination to separate thread in order to …
michaelwoerister Jul 24, 2017
b18a61a
async-llvm(5): Do continuous error handling on main thread.
michaelwoerister Jul 24, 2017
8f6894e
async-llvm(6): Make the LLVM work coordinator get its work package th…
michaelwoerister Jul 24, 2017
4282dd8
async-llvm(7): Clean up error handling a bit.
michaelwoerister Jul 24, 2017
645841e
async-llvm(8): Clean up resource management and drop LLVM modules ASAP.
michaelwoerister Jul 25, 2017
ccb970b
async-llvm(9): Move OngoingCrateTranslation into back::write.
michaelwoerister Jul 26, 2017
28589ec
async-llvm(10): Factor compile output files cleanup into separate fun…
michaelwoerister Jul 26, 2017
f3ce505
async-llvm(11): Delay joining ongoing translation until right before …
michaelwoerister Jul 26, 2017
397b2a8
async-llvm(12): Hide no_integrated_as logic in write::run_passes.
michaelwoerister Jul 26, 2017
b924ec1
async-llvm(13): Submit LLVM work packages from base::trans_crate().
michaelwoerister Jul 26, 2017
a1be658
async-llvm(14): Move LTO/codegen-unit conflict check to beginning of …
michaelwoerister Jul 26, 2017
943a5bd
async-llvm(15): Don't require number of codegen units upfront.
michaelwoerister Jul 26, 2017
0ad9eaa
async-llvm(16): Inject allocator shim into LLVM module immediately if…
michaelwoerister Jul 26, 2017
e7d0fa3
async-llvm(17): Create MSVC __imp_ symbols immediately for each module.
michaelwoerister Jul 26, 2017
7e09d1e
async-llvm(18): Instantiate OngoingCrateTranslation before starting t…
michaelwoerister Jul 26, 2017
81b789f
async-llvm(19): Already start LLVM while still translating.
michaelwoerister Jul 26, 2017
ab3bc58
async-llvm(20): Do some cleanup.
michaelwoerister Jul 26, 2017
1480be3
async-llvm(21): Re-use worker-ids in order to simulate persistent wor…
michaelwoerister Jul 27, 2017
8819278
async-llvm(22): mw invokes mad html skillz to produce graphical LLVM …
michaelwoerister Jul 27, 2017
f5acc39
async-llvm(23): Let the main thread also do LLVM work in order to red…
michaelwoerister Jul 27, 2017
bd36df8
async-llvm(24): Improve scheduling and documentation.
michaelwoerister Jul 28, 2017
a9a0ea9
async-llvm(25): Restore -Ztime-passes output for trans and LLVM.
michaelwoerister Jul 31, 2017
cacc31f
async-llvm(26): Print error when failing to acquire Jobserver token.
michaelwoerister Jul 31, 2017
b1e043e
async-llvm(27): Move #[rustc_error] check to an earlier point in orde…
michaelwoerister Jul 31, 2017
b8d4413
async-llvm(28): Make some error messages more informative.
michaelwoerister Aug 1, 2017
6468cad
async-llvm(29): Adapt run-make/llvm-phase test case to LLVM module no…
michaelwoerister Aug 1, 2017
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
Prev Previous commit
Next Next commit
async-llvm(21): Re-use worker-ids in order to simulate persistent wor…
…ker threads.
  • Loading branch information
michaelwoerister committed Jul 31, 2017
commit 1480be37795bd25b7d7cedf9e1ef5caf985fe38c
35 changes: 29 additions & 6 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,10 @@ fn execute_work_item(cgcx: &CodegenContext, work_item: WorkItem)
#[derive(Debug)]
enum Message {
Token(io::Result<Acquired>),
Done { result: Result<CompiledModule, ()> },
Done {
result: Result<CompiledModule, ()>,
worker_id: usize,
},
WorkItem(WorkItem),
CheckErrorMessages,
TranslationDone,
Expand Down Expand Up @@ -1179,24 +1182,38 @@ fn start_executing_work(sess: &Session,
// the jobserver.

thread::spawn(move || {
let mut worker_id_counter = 0;
let mut free_worker_ids = Vec::new();
let mut get_worker_id = |free_worker_ids: &mut Vec<usize>| {
if let Some(id) = free_worker_ids.pop() {
id
} else {
let id = worker_id_counter;
worker_id_counter += 1;
id
}
};

let mut compiled_modules = vec![];
let mut compiled_metadata_module = None;
let mut compiled_allocator_module = None;

let mut translation_done = false;
let mut work_items = Vec::new();
let mut tokens = Vec::new();

let mut running = 0;

while !translation_done || work_items.len() > 0 || running > 0 {

// Spin up what work we can, only doing this while we've got available
// parallelism slots and work left to spawn.
while work_items.len() > 0 && running < tokens.len() + 1 {
let item = work_items.pop().unwrap();
let worker_index = work_items.len();
let worker_id = get_worker_id(&mut free_worker_ids);

let cgcx = CodegenContext {
worker: worker_index,
worker: worker_id,
.. cgcx.clone()
};

Expand Down Expand Up @@ -1235,9 +1252,10 @@ fn start_executing_work(sess: &Session,
//
// Note that if the thread failed that means it panicked, so we
// abort immediately.
Message::Done { result: Ok(compiled_module) } => {
Message::Done { result: Ok(compiled_module), worker_id } => {
drop(tokens.pop());
running -= 1;
free_worker_ids.push(worker_id);
drop(trans_worker_send.send(Message::CheckErrorMessages));

match compiled_module.kind {
Expand All @@ -1254,7 +1272,7 @@ fn start_executing_work(sess: &Session,
}
}
}
Message::Done { result: Err(()) } => {
Message::Done { result: Err(()), worker_id: _ } => {
shared_emitter.fatal("aborting due to worker thread panic");
drop(trans_worker_send.send(Message::CheckErrorMessages));
// Exit the coordinator thread
Expand Down Expand Up @@ -1288,6 +1306,7 @@ fn spawn_work(cgcx: CodegenContext, work: WorkItem) {
struct Bomb {
coordinator_send: Sender<Message>,
result: Option<CompiledModule>,
worker_id: usize,
}
impl Drop for Bomb {
fn drop(&mut self) {
Expand All @@ -1296,13 +1315,17 @@ fn spawn_work(cgcx: CodegenContext, work: WorkItem) {
None => Err(())
};

drop(self.coordinator_send.send(Message::Done { result }));
drop(self.coordinator_send.send(Message::Done {
result,
worker_id: self.worker_id,
}));
}
}

let mut bomb = Bomb {
coordinator_send: cgcx.coordinator_send.clone(),
result: None,
worker_id: cgcx.worker,
};

// Execute the work itself, and if it finishes successfully then flag
Expand Down