mirror of
https://github.com/verilator/verilator.git
synced 2026-08-30 09:48:22 +02:00
Add VerilatedContext::useNumaAssign and set on threads() call (#6954)
This commit is contained in:
@@ -2816,6 +2816,7 @@ void VerilatedContext::threads(unsigned n) {
|
||||
"%Error: Cannot set simulation threads after the thread pool has been created.");
|
||||
}
|
||||
|
||||
m_useNumaAssign = true;
|
||||
if (m_threads == n) return; // To avoid unnecessary warnings
|
||||
m_threads = n;
|
||||
const unsigned threadsAvailableToProcess = VlOs::getProcessDefaultParallelism();
|
||||
@@ -2826,6 +2827,8 @@ void VerilatedContext::threads(unsigned n) {
|
||||
}
|
||||
}
|
||||
|
||||
void VerilatedContext::useNumaAssign(bool flag) { m_useNumaAssign = flag; }
|
||||
|
||||
void VerilatedContext::commandArgs(int argc, const char** argv) VL_MT_SAFE_EXCLUDES(m_argMutex) {
|
||||
// Not locking m_argMutex here, it is done in impp()->commandArgsAddGuts
|
||||
// m_argMutex here is the same as in impp()->commandArgsAddGuts;
|
||||
|
||||
@@ -433,6 +433,8 @@ protected:
|
||||
const std::unique_ptr<VerilatedContextImpData> m_impdatap;
|
||||
// Number of threads to use for simulation (size of m_threadPool + 1 for main thread)
|
||||
unsigned m_threads = VlOs::getProcessDefaultParallelism();
|
||||
// Use numa automatic CPU-to-thread assignment
|
||||
bool m_useNumaAssign = false;
|
||||
// Number of threads in added models
|
||||
unsigned m_threadsInModels = 0;
|
||||
// The thread pool shared by all models added to this context
|
||||
@@ -599,6 +601,13 @@ public:
|
||||
/// Can only be called before the thread pool is created (before first model is added).
|
||||
void threads(unsigned n);
|
||||
|
||||
/// Use numa automatic CPU-to-thread assignment.
|
||||
bool useNumaAssign() const VL_MT_SAFE { return m_useNumaAssign; }
|
||||
/// Set numa assignment of threads to cores
|
||||
/// Defaults false; set true automatically when threads() called;
|
||||
/// call this to override back to false if numa assignment not wanted.
|
||||
void useNumaAssign(bool flag);
|
||||
|
||||
/// Trace signals in models within the context; called by application code
|
||||
void trace(VerilatedTraceBaseC* tfp, int levels, int options = 0);
|
||||
/// Allow traces to at some point be enabled (disables some optimizations)
|
||||
|
||||
@@ -137,7 +137,7 @@ VlThreadPool::VlThreadPool(VerilatedContext* contextp, unsigned nThreads) {
|
||||
m_workers.push_back(new VlWorkerThread{contextp});
|
||||
m_unassignedWorkers.push(i);
|
||||
}
|
||||
m_numaStatus = numaAssign();
|
||||
m_numaStatus = numaAssign(contextp);
|
||||
}
|
||||
|
||||
VlThreadPool::~VlThreadPool() {
|
||||
@@ -145,8 +145,9 @@ VlThreadPool::~VlThreadPool() {
|
||||
for (auto& i : m_workers) delete i;
|
||||
}
|
||||
|
||||
std::string VlThreadPool::numaAssign() {
|
||||
std::string VlThreadPool::numaAssign(VerilatedContext* contextp) {
|
||||
#if defined(__linux) || defined(CPU_ZERO) || defined(VL_CPPCHECK) // Linux-like pthreads
|
||||
if (contextp && !contextp->useNumaAssign()) { return "NUMA assignment not requested"; }
|
||||
std::string numa_strategy = VlOs::getenvStr("VERILATOR_NUMA_STRATEGY", "default");
|
||||
if (numa_strategy == "none") {
|
||||
return "no NUMA assignment requested";
|
||||
|
||||
@@ -254,7 +254,7 @@ public:
|
||||
private:
|
||||
VL_UNCOPYABLE(VlThreadPool);
|
||||
|
||||
std::string numaAssign();
|
||||
std::string numaAssign(VerilatedContext* contextp);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user