Skip to content

Commit 8da3ff3

Browse files
committed
Auto merge of #43766 - michaelwoerister:trans-scheduler-touch-up, r=alexcrichton
Improve LLVM/trans scheduling a bit Currently it's possible that the main thread is waiting on LLVM threads to finish work while its implicit token is going to waste. This PR let's the main thread take over, so one of the running LLVM threads can free its token earlier. r? @alexcrichton
2 parents a7e0d3a + 07149e0 commit 8da3ff3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/librustc_trans/back/write.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,16 @@ fn start_executing_work(sess: &Session,
13561356
maybe_start_llvm_timer(&item, &mut llvm_start_time);
13571357
main_thread_worker_state = MainThreadWorkerState::LLVMing;
13581358
spawn_work(cgcx, item);
1359+
} else {
1360+
// There is no unstarted work, so let the main thread
1361+
// take over for a running worker. Otherwise the
1362+
// implicit token would just go to waste.
1363+
// We reduce the `running` counter by one. The
1364+
// `tokens.truncate()` below will take care of
1365+
// giving the Token back.
1366+
debug_assert!(running > 0);
1367+
running -= 1;
1368+
main_thread_worker_state = MainThreadWorkerState::LLVMing;
13591369
}
13601370
}
13611371
MainThreadWorkerState::Translating => {

0 commit comments

Comments
 (0)