mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 09:57:18 +03:00
[ELF] Fix -thread-count option
This commit is contained in:
parent
3d02a3b20b
commit
32f30c304e
15
elf/main.cc
15
elf/main.cc
@ -9,6 +9,7 @@
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <tbb/global_control.h>
|
||||
#include <tbb/parallel_for_each.h>
|
||||
#include <unistd.h>
|
||||
#include <unordered_set>
|
||||
@ -301,6 +302,13 @@ static void show_stats(Context<E> &ctx) {
|
||||
Counter::print();
|
||||
}
|
||||
|
||||
static i64 get_default_thread_count() {
|
||||
// mold doesn't scale above 32 threads.
|
||||
int n = tbb::global_control::active_value(
|
||||
tbb::global_control::max_allowed_parallelism);
|
||||
return std::min(n, 32);
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
static int elf_main(int argc, char **argv) {
|
||||
Context<E> ctx;
|
||||
@ -336,7 +344,12 @@ static int elf_main(int argc, char **argv) {
|
||||
if (!ctx.arg.preload)
|
||||
try_resume_daemon(ctx);
|
||||
|
||||
set_thread_count(ctx.arg.thread_count);
|
||||
i64 thread_count = ctx.arg.thread_count;
|
||||
if (thread_count == 0)
|
||||
thread_count = get_default_thread_count();
|
||||
tbb::global_control tbb_cont(tbb::global_control::max_allowed_parallelism,
|
||||
thread_count);
|
||||
|
||||
install_signal_handler();
|
||||
|
||||
if (!ctx.arg.directory.empty() && chdir(ctx.arg.directory.c_str()) == -1)
|
||||
|
20
threads.cc
20
threads.cc
@ -1,20 +0,0 @@
|
||||
#include "mold.h"
|
||||
|
||||
#include <tbb/global_control.h>
|
||||
|
||||
namespace mold {
|
||||
|
||||
static i64 get_default_thread_count() {
|
||||
// mold doesn't scale above 32 threads.
|
||||
int n = tbb::global_control::active_value(
|
||||
tbb::global_control::max_allowed_parallelism);
|
||||
return std::min(n, 32);
|
||||
}
|
||||
|
||||
void set_thread_count(i64 n) {
|
||||
if (n == 0)
|
||||
n = get_default_thread_count();
|
||||
tbb::global_control tbb_cont(tbb::global_control::max_allowed_parallelism, n);
|
||||
}
|
||||
|
||||
} // namespace mold
|
Loading…
Reference in New Issue
Block a user