From 7219ac94b3d3f878e5b5a843c4ced619e1904c2c Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 30 Sep 2025 15:42:10 +0000 Subject: [PATCH 1/4] Add YOSYS_MAX_THREADS --- kernel/threading.cc | 19 +++++++++++++++++-- kernel/threading.h | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/kernel/threading.cc b/kernel/threading.cc index 49fddaa7c..dcc044c89 100644 --- a/kernel/threading.cc +++ b/kernel/threading.cc @@ -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(std::thread::hardware_concurrency() - reserved_cores, max_threads); + int available_threads = std::min(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; diff --git a/kernel/threading.h b/kernel/threading.h index c34abf850..b8cd62f87 100644 --- a/kernel/threading.h +++ b/kernel/threading.h @@ -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. From fc951a28d39c2135d46b020b9f6ad4be9ee225f6 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 30 Sep 2025 18:54:51 +0000 Subject: [PATCH 2/4] Limit YOSYS_MAX_THREADS to 4 when running makefile-tests so we don't overload systems when running 'make -j... test' --- tests/gen-tests-makefile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gen-tests-makefile.sh b/tests/gen-tests-makefile.sh index e3308506b..a0fb23ac3 100755 --- a/tests/gen-tests-makefile.sh +++ b/tests/gen-tests-makefile.sh @@ -9,7 +9,7 @@ generate_target() { echo "all: $target_name" echo ".PHONY: $target_name" echo "$target_name:" - printf "\t@%s\n" "$test_command" + printf "\t@YOSYS_MAX_THREADS=4 %s\n" "$test_command" printf "\t@echo 'Passed %s'\n" "$target_name" } From a871415abf3b6000c6302b35ef7781f9a58c8d87 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Thu, 27 Nov 2025 21:57:35 +0000 Subject: [PATCH 3/4] Limit YOSYS_MAX_THREADS to 4 when running seed-tests --- tests/arch/run-test.sh | 1 + tests/asicworld/run-test.sh | 1 + tests/blif/run-test.sh | 1 + tests/bram/run-test.sh | 1 + tests/common-env.sh | 1 + tests/cxxrtl/run-test.sh | 1 + tests/fmt/run-test.sh | 1 + tests/fsm/run-test.sh | 1 + tests/functional/run-test.sh | 1 + tests/hana/run-test.sh | 1 + tests/liberty/run-test.sh | 1 + tests/memfile/run-test.sh | 1 + tests/memlib/run-test.sh | 1 + tests/opt_share/run-test.sh | 1 + tests/peepopt/run-test.sh | 1 + tests/proc/run-test.sh | 1 + tests/rpc/run-test.sh | 1 + tests/select/run-test.sh | 1 + tests/share/run-test.sh | 1 + tests/simple/run-test.sh | 1 + tests/simple_abc9/run-test.sh | 1 + tests/svinterfaces/run-test.sh | 1 + tests/xprop/run-test.sh | 1 + 23 files changed, 23 insertions(+) create mode 100644 tests/common-env.sh diff --git a/tests/arch/run-test.sh b/tests/arch/run-test.sh index 68f925b34..7602717d2 100755 --- a/tests/arch/run-test.sh +++ b/tests/arch/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e diff --git a/tests/asicworld/run-test.sh b/tests/asicworld/run-test.sh index 5131ed646..c9b4118a7 100755 --- a/tests/asicworld/run-test.sh +++ b/tests/asicworld/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh OPTIND=1 seed="" # default to no seed specified diff --git a/tests/blif/run-test.sh b/tests/blif/run-test.sh index e9698386e..2e3f5235c 100755 --- a/tests/blif/run-test.sh +++ b/tests/blif/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e for x in *.ys; do echo "Running $x.." diff --git a/tests/bram/run-test.sh b/tests/bram/run-test.sh index 37fc91d0e..47f24f5dd 100755 --- a/tests/bram/run-test.sh +++ b/tests/bram/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh # run this test many times: # MAKE="make -j8" time bash -c 'for ((i=0; i<100; i++)); do echo "-- $i --"; bash run-test.sh || exit 1; done' diff --git a/tests/common-env.sh b/tests/common-env.sh new file mode 100644 index 000000000..f3a411280 --- /dev/null +++ b/tests/common-env.sh @@ -0,0 +1 @@ +export YOSYS_MAX_THREADS=4 diff --git a/tests/cxxrtl/run-test.sh b/tests/cxxrtl/run-test.sh index 4b542e180..aa7a0c26c 100755 --- a/tests/cxxrtl/run-test.sh +++ b/tests/cxxrtl/run-test.sh @@ -1,4 +1,5 @@ #!/bin/bash +source ../common-env.sh set -ex diff --git a/tests/fmt/run-test.sh b/tests/fmt/run-test.sh index 88ee6e238..a3402f953 100644 --- a/tests/fmt/run-test.sh +++ b/tests/fmt/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -ex diff --git a/tests/fsm/run-test.sh b/tests/fsm/run-test.sh index dc60c69c4..139ea8261 100755 --- a/tests/fsm/run-test.sh +++ b/tests/fsm/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh # run this test many times: # time bash -c 'for ((i=0; i<100; i++)); do echo "-- $i --"; bash run-test.sh || exit 1; done' diff --git a/tests/functional/run-test.sh b/tests/functional/run-test.sh index e0bedf8d4..7c38f3190 100755 --- a/tests/functional/run-test.sh +++ b/tests/functional/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) diff --git a/tests/hana/run-test.sh b/tests/hana/run-test.sh index 99be37f5e..8533e5544 100755 --- a/tests/hana/run-test.sh +++ b/tests/hana/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh OPTIND=1 seed="" # default to no seed specified diff --git a/tests/liberty/run-test.sh b/tests/liberty/run-test.sh index 5afdb727e..d5fb65e16 100755 --- a/tests/liberty/run-test.sh +++ b/tests/liberty/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -eo pipefail for x in *.lib; do diff --git a/tests/memfile/run-test.sh b/tests/memfile/run-test.sh index db0ec54ee..44c1e4821 100755 --- a/tests/memfile/run-test.sh +++ b/tests/memfile/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e diff --git a/tests/memlib/run-test.sh b/tests/memlib/run-test.sh index 5f230a03e..9e95fb255 100755 --- a/tests/memlib/run-test.sh +++ b/tests/memlib/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -eu OPTIND=1 diff --git a/tests/opt_share/run-test.sh b/tests/opt_share/run-test.sh index e80cd4214..e3a6e8b7b 100755 --- a/tests/opt_share/run-test.sh +++ b/tests/opt_share/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh # run this test many times: # time bash -c 'for ((i=0; i<100; i++)); do echo "-- $i --"; bash run-test.sh || exit 1; done' diff --git a/tests/peepopt/run-test.sh b/tests/peepopt/run-test.sh index e9698386e..2e3f5235c 100644 --- a/tests/peepopt/run-test.sh +++ b/tests/peepopt/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e for x in *.ys; do echo "Running $x.." diff --git a/tests/proc/run-test.sh b/tests/proc/run-test.sh index e9698386e..2e3f5235c 100755 --- a/tests/proc/run-test.sh +++ b/tests/proc/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e for x in *.ys; do echo "Running $x.." diff --git a/tests/rpc/run-test.sh b/tests/rpc/run-test.sh index 624043750..0d58b0de2 100755 --- a/tests/rpc/run-test.sh +++ b/tests/rpc/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e for x in *.ys; do echo "Running $x.." diff --git a/tests/select/run-test.sh b/tests/select/run-test.sh index e9698386e..2e3f5235c 100755 --- a/tests/select/run-test.sh +++ b/tests/select/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e for x in *.ys; do echo "Running $x.." diff --git a/tests/share/run-test.sh b/tests/share/run-test.sh index a7b5fc4a0..0cef580a7 100755 --- a/tests/share/run-test.sh +++ b/tests/share/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh # run this test many times: # time bash -c 'for ((i=0; i<100; i++)); do echo "-- $i --"; bash run-test.sh || exit 1; done' diff --git a/tests/simple/run-test.sh b/tests/simple/run-test.sh index b9e79f34a..c3711fe3e 100755 --- a/tests/simple/run-test.sh +++ b/tests/simple/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh OPTIND=1 seed="" # default to no seed specified diff --git a/tests/simple_abc9/run-test.sh b/tests/simple_abc9/run-test.sh index 5669321ac..0b3e5061f 100755 --- a/tests/simple_abc9/run-test.sh +++ b/tests/simple_abc9/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh OPTIND=1 seed="" # default to no seed specified diff --git a/tests/svinterfaces/run-test.sh b/tests/svinterfaces/run-test.sh index 71bdcd67a..28ce627d9 100755 --- a/tests/svinterfaces/run-test.sh +++ b/tests/svinterfaces/run-test.sh @@ -1,4 +1,5 @@ #/bin/bash -e +source ../common-env.sh ./runone.sh svinterface1 ./runone.sh svinterface_at_top diff --git a/tests/xprop/run-test.sh b/tests/xprop/run-test.sh index 84b7c4ac4..303c0bb3b 100755 --- a/tests/xprop/run-test.sh +++ b/tests/xprop/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e python3 generate.py $@ From 2ca28d964b1133e08e0240de2b905d41951e0186 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Thu, 27 Nov 2025 22:04:12 +0000 Subject: [PATCH 4/4] Limit YOSYS_MAX_THREADS to 4 for abcopt-tests --- tests/aiger/run-test.sh | 1 + tests/alumacc/run-test.sh | 1 + tests/memories/run-test.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/aiger/run-test.sh b/tests/aiger/run-test.sh index ca7339ff0..f0e27088b 100755 --- a/tests/aiger/run-test.sh +++ b/tests/aiger/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e diff --git a/tests/alumacc/run-test.sh b/tests/alumacc/run-test.sh index e9698386e..2e3f5235c 100644 --- a/tests/alumacc/run-test.sh +++ b/tests/alumacc/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e for x in *.ys; do echo "Running $x.." diff --git a/tests/memories/run-test.sh b/tests/memories/run-test.sh index 4f1da7ce7..8f83e11a1 100755 --- a/tests/memories/run-test.sh +++ b/tests/memories/run-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../common-env.sh set -e