From 303615bb378741077d83c67b76194ab70d266d72 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 10 May 2026 08:20:32 -0400 Subject: [PATCH] Support TERMUX (#7559). [Laurent CHARRIER] Fixes #7559. --- Changes | 1 + docs/CONTRIBUTORS | 1 + include/verilated_threads.cpp | 5 +++++ include/verilatedos_c.h | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/Changes b/Changes index d30379590..182469cab 100644 --- a/Changes +++ b/Changes @@ -21,6 +21,7 @@ Verilator 5.049 devel * Support procedural continuous assign/deassign (#7493). [Artur Bieniek, Antmicro Ltd.] * Support randsequence production function ports (#7522). [Yilou Wang] * Support followed-by operators `#-#` and `#=#` in properties (#7523). [Yilou Wang] +* Support TERMUX (#7559). [Laurent CHARRIER] * Add peak memory usage to `--stats`. [Geza Lore, Testorrent USA, Inc.] * Improve `--coverage-fsm` (#7490) (#7529). [Yogish Sekhar] * Change `+verilator+seed` to default to 1, and 0 to randomly select (#7325) (#7516). [Miguel] diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 9e41e6a42..f459321c9 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -165,6 +165,7 @@ Krzysztof Sychla Kuba Ober Lan Zongwei Larry Doolittle +Laurent CHARRIER Leela Pakanati Liam Braun Luca Colagrande diff --git a/include/verilated_threads.cpp b/include/verilated_threads.cpp index c35c85512..c6a2afc8c 100644 --- a/include/verilated_threads.cpp +++ b/include/verilated_threads.cpp @@ -268,8 +268,13 @@ std::string VlThreadPool::numaAssign(VerilatedContext* contextp) { } status += ";"; +#ifdef __TERMUX__ + const int rc = sched_setaffinity(m_workers[thread]->m_cthread.native_handle(), + sizeof(cpu_set_t), &cpuset); +#else const int rc = pthread_setaffinity_np(m_workers[thread]->m_cthread.native_handle(), sizeof(cpu_set_t), &cpuset); +#endif if (rc != 0) return "%Warning: pthread_setaffinity_np failed"; } // std::cout << "Status: " << status << std::endl; diff --git a/include/verilatedos_c.h b/include/verilatedos_c.h index ce55994f1..67a6ef0f3 100644 --- a/include/verilatedos_c.h +++ b/include/verilatedos_c.h @@ -118,7 +118,11 @@ unsigned getProcessAvailableParallelism() VL_MT_SAFE { #if defined(__linux) || defined(CPU_ZERO) // Linux-like; assume we have pthreads etc cpu_set_t cpuset; CPU_ZERO(&cpuset); +#ifdef __TERMUX__ + const int rc = sched_getaffinity(pthread_self(), sizeof(cpuset), &cpuset); +#else const int rc = pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); +#endif if (rc == 0) { unsigned nCpus = 0; for (int i = 0; i < CPU_SETSIZE; ++i) {