mirror of https://github.com/YosysHQ/yosys.git
Add YOSYS_MAX_THREADS
This commit is contained in:
parent
52b1245547
commit
7219ac94b3
|
|
@ -3,6 +3,20 @@
|
|||
|
||||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
static int init_max_threads()
|
||||
{
|
||||
const char *v = getenv("YOSYS_MAX_THREADS");
|
||||
if (v == nullptr)
|
||||
return INT32_MAX;
|
||||
return atoi(v);
|
||||
}
|
||||
|
||||
static int get_max_threads()
|
||||
{
|
||||
static int max_threads = init_max_threads();
|
||||
return max_threads;
|
||||
}
|
||||
|
||||
void DeferredLogs::flush()
|
||||
{
|
||||
for (auto &m : logs)
|
||||
|
|
@ -12,10 +26,11 @@ void DeferredLogs::flush()
|
|||
YOSYS_NAMESPACE_PREFIX log("%s", m.text.c_str());
|
||||
}
|
||||
|
||||
int ThreadPool::pool_size(int reserved_cores, int max_threads)
|
||||
int ThreadPool::pool_size(int reserved_cores, int max_worker_threads)
|
||||
{
|
||||
#ifdef YOSYS_ENABLE_THREADS
|
||||
int num_threads = std::min<int>(std::thread::hardware_concurrency() - reserved_cores, max_threads);
|
||||
int available_threads = std::min<int>(std::thread::hardware_concurrency(), get_max_threads());
|
||||
int num_threads = std::min(available_threads - reserved_cores, max_worker_threads);
|
||||
return std::max(0, num_threads);
|
||||
#else
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -127,9 +127,9 @@ class ThreadPool
|
|||
public:
|
||||
// Computes the number of worker threads to use.
|
||||
// `reserved_cores` cores are set aside for other threads (e.g. work on the main thread).
|
||||
// `max_threads` --- don't return more workers than this.
|
||||
// `max_worker_threads` --- don't return more workers than this.
|
||||
// The result may be 0.
|
||||
static int pool_size(int reserved_cores, int max_threads);
|
||||
static int pool_size(int reserved_cores, int max_worker_threads);
|
||||
|
||||
// Create a pool of threads running the given closure (parameterized by thread number).
|
||||
// `pool_size` must be the result of a `pool_size()` call.
|
||||
|
|
|
|||
Loading…
Reference in New Issue