From dd37fd6a49b41b12a0f9582bc72ae171aae29e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 4 Jun 2025 18:00:01 +0200 Subject: [PATCH] Add ISC_TID_MAX with default being 512 threads The ISC_TID_MAX variable allows other units to declare static arrays with this as size for per-thread/per-loop variables. --- bin/named/main.c | 20 +++++++++++++++----- lib/isc/include/isc/tid.h | 4 ++++ lib/isc/tid.c | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/bin/named/main.c b/bin/named/main.c index 14dee08c86..ae6f4fcc49 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -946,6 +946,8 @@ parse_command_line(int argc, char *argv[]) { static isc_result_t create_managers(void) { + bool capped = false; + /* * Set the default named_g_cpus if it was not set from the command line */ @@ -954,11 +956,19 @@ create_managers(void) { named_g_cpus = named_g_cpus_detected; } - isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, - ISC_LOG_INFO, "found %u CPU%s, using %u worker thread%s", - named_g_cpus_detected, - named_g_cpus_detected == 1 ? "" : "s", named_g_cpus, - named_g_cpus == 1 ? "" : "s"); + if (named_g_cpus > ISC_TID_MAX) { + capped = true; + named_g_cpus = ISC_TID_MAX; + } + + isc_log_write( + NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, + "found %u CPU%s, using %u worker thread%s%s", + named_g_cpus_detected, named_g_cpus_detected == 1 ? "" : "s", + named_g_cpus, named_g_cpus == 1 ? "" : "s", + capped ? " (recompile with -DISC_TID_MAX= to raise the " + "thread count limit)" + : ""); isc_managers_create(&named_g_mctx, named_g_cpus, &named_g_loopmgr, &named_g_netmgr); diff --git a/lib/isc/include/isc/tid.h b/lib/isc/include/isc/tid.h index b506205979..123e14092f 100644 --- a/lib/isc/include/isc/tid.h +++ b/lib/isc/include/isc/tid.h @@ -23,6 +23,10 @@ typedef int32_t isc_tid_t; #define ISC_TID_UNKNOWN (isc_tid_t) - 1 +#ifndef ISC_TID_MAX +#define ISC_TID_MAX 512 +#endif /* ISC_TID_MAX */ + isc_tid_t isc_tid_count(void); /*%< diff --git a/lib/isc/tid.c b/lib/isc/tid.c index e8416a733c..909b4a949f 100644 --- a/lib/isc/tid.c +++ b/lib/isc/tid.c @@ -37,12 +37,14 @@ static isc_tid_t tid_count = 0; void isc__tid_init(isc_tid_t tid) { REQUIRE(isc__tid_local == ISC_TID_UNKNOWN || isc__tid_local == tid); + REQUIRE(tid < ISC_TID_MAX); isc__tid_local = tid; } void isc__tid_initcount(isc_tid_t count) { REQUIRE(tid_count == 0 || tid_count == count); + REQUIRE(tid_count < ISC_TID_MAX); tid_count = count; }