]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add ISC_TID_MAX with default being 512 threads
authorOndřej Surý <ondrej@isc.org>
Wed, 4 Jun 2025 16:00:01 +0000 (18:00 +0200)
committerOndřej Surý <ondrej@isc.org>
Sat, 28 Jun 2025 11:32:12 +0000 (13:32 +0200)
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
lib/isc/include/isc/tid.h
lib/isc/tid.c

index 14dee08c861365ef95d206a2e7c33cdafd9eb3b8..ae6f4fcc49d4873445088265dcd1e2bbc6fc7c4b 100644 (file)
@@ -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=<n> to raise the "
+                        "thread count limit)"
+                      : "");
 
        isc_managers_create(&named_g_mctx, named_g_cpus, &named_g_loopmgr,
                            &named_g_netmgr);
index b506205979f35605b37f4f112cb73b07229c4262..123e14092fb8527fc3968b36027b7b3f481796c7 100644 (file)
@@ -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);
 /*%<
index e8416a733c5fe48c574a804da64719302713f67b..909b4a949f28303ed48b38d1f4ac81633d24e75a 100644 (file)
@@ -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;
 }