21682d
From 0175b942efc2fb6a05a2c76d62a9fb9157141757 Mon Sep 17 00:00:00 2001
21682d
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
21682d
Date: Wed, 20 Jan 2021 01:01:52 +0100
21682d
Subject: [PATCH] Workaround errors in unit test on 56 CPU machine
21682d
21682d
hp.c should be just implementation detail, but unit tests use it
21682d
repeatedly without resetting tid_v_base. Reset the base counter, when
21682d
number of processors is configured. Configure it when creating network
21682d
manager.
21682d
21682d
Use id of current thread as a base. Should be usually 0, but must not be
21682d
below id of the main thread.
21682d
---
21682d
 bin/named/main.c        | 7 -------
21682d
 lib/isc/hp.c            | 1 +
21682d
 lib/isc/netmgr/netmgr.c | 8 ++++++++
21682d
 3 files changed, 9 insertions(+), 7 deletions(-)
21682d
21682d
diff --git a/bin/named/main.c b/bin/named/main.c
21682d
index 9836de9d7f..d1be43a632 100644
21682d
--- a/bin/named/main.c
21682d
+++ b/bin/named/main.c
21682d
@@ -24,7 +24,6 @@
21682d
 #include <isc/dir.h>
21682d
 #include <isc/file.h>
21682d
 #include <isc/hash.h>
21682d
-#include <isc/hp.h>
21682d
 #include <isc/httpd.h>
21682d
 #include <isc/netmgr.h>
21682d
 #include <isc/os.h>
21682d
@@ -909,12 +908,6 @@ create_managers(void) {
21682d
 		      "using %u UDP listener%s per interface", named_g_udpdisp,
21682d
 		      named_g_udpdisp == 1 ? "" : "s");
21682d
 
21682d
-	/*
21682d
-	 * We have ncpus network threads, ncpus worker threads, ncpus
21682d
-	 * old network threads - make it 4x just to be safe. The memory
21682d
-	 * impact is negligible.
21682d
-	 */
21682d
-	isc_hp_init(4 * named_g_cpus);
21682d
 	named_g_nm = isc_nm_start(named_g_mctx, named_g_cpus);
21682d
 	if (named_g_nm == NULL) {
21682d
 		UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_nm_start() failed");
21682d
diff --git a/lib/isc/hp.c b/lib/isc/hp.c
21682d
index 3ea13bbe24..e4a98afc82 100644
21682d
--- a/lib/isc/hp.c
21682d
+++ b/lib/isc/hp.c
21682d
@@ -95,6 +95,7 @@ void
21682d
 isc_hp_init(int max_threads) {
21682d
 	isc__hp_max_threads = max_threads;
21682d
 	isc__hp_max_retired = max_threads * HP_MAX_HPS;
21682d
+	atomic_store_release(&tid_v_base, tid());
21682d
 }
21682d
 
21682d
 isc_hp_t *
21682d
diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c
21682d
index 46f0758620..e3469f4c3a 100644
21682d
--- a/lib/isc/netmgr/netmgr.c
21682d
+++ b/lib/isc/netmgr/netmgr.c
21682d
@@ -17,6 +17,7 @@
21682d
 #include <isc/buffer.h>
21682d
 #include <isc/condition.h>
21682d
 #include <isc/errno.h>
21682d
+#include <isc/hp.h>
21682d
 #include <isc/magic.h>
21682d
 #include <isc/mem.h>
21682d
 #include <isc/netmgr.h>
21682d
@@ -238,6 +239,13 @@ isc_nm_start(isc_mem_t *mctx, uint32_t workers) {
21682d
 	atomic_init(&mgr->keepalive, 30000);
21682d
 	atomic_init(&mgr->advertised, 30000);
21682d
 
21682d
+	/*
21682d
+	 * We have ncpus network threads, ncpus worker threads, ncpus
21682d
+	 * old network threads - make it 4x just to be safe. The memory
21682d
+	 * impact is negligible.
21682d
+	 */
21682d
+	isc_hp_init(4 * workers);
21682d
+
21682d
 	isc_mutex_init(&mgr->reqlock);
21682d
 	isc_mempool_create(mgr->mctx, sizeof(isc__nm_uvreq_t), &mgr->reqpool);
21682d
 	isc_mempool_setname(mgr->reqpool, "nm_reqpool");
21682d
-- 
21682d
2.26.2
21682d