Petr Menšík 2022-06-20 14:21:46 +02:00
parent e3377c558b
commit f887e16911
5 changed files with 9 additions and 289 deletions

2
.gitignore vendored
View File

@ -174,3 +174,5 @@ bind-9.7.2b1.tar.gz
/bind-9.16.28.tar.xz.asc /bind-9.16.28.tar.xz.asc
/bind-9.16.29.tar.xz /bind-9.16.29.tar.xz
/bind-9.16.29.tar.xz.asc /bind-9.16.29.tar.xz.asc
/bind-9.16.30.tar.xz
/bind-9.16.30.tar.xz.asc

View File

@ -1,214 +0,0 @@
From 0df59049fe13ef89d362fa7f109f289b297441dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= <ondrej@isc.org>
Date: Tue, 22 Feb 2022 23:40:39 +0100
Subject: [PATCH] Provide alternative isc_queue implementation based on locked
list
The current implementation of isc_queue uses Michael-Scott lock-free
queue that in turn uses hazard pointers. It was discovered that the way
we use the isc_queue, such complicated mechanism isn't really needed,
because most of the time, we either execute the work directly when on
nmthread (in case of UDP) or schedule the work from the matching
nmthreads.
Provide alternative implementation for the isc_queue based on locked
ISC_LIST.
PatchNumber: 11
PatchNumber: 11
---
bin/named/main.c | 1 -
configure.ac | 12 ++++
lib/isc/include/isc/queue.h | 3 +-
lib/isc/queue.c | 121 ++++++++++++++++++++++++++++++++++++
4 files changed, 134 insertions(+), 3 deletions(-)
diff --git a/bin/named/main.c b/bin/named/main.c
index 9ad2d0e..8870933 100644
--- a/bin/named/main.c
+++ b/bin/named/main.c
@@ -34,7 +34,6 @@
#include <isc/dir.h>
#include <isc/file.h>
#include <isc/hash.h>
-#include <isc/hp.h>
#include <isc/httpd.h>
#include <isc/managers.h>
#include <isc/netmgr.h>
diff --git a/configure.ac b/configure.ac
index 79d33d1..26241a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2263,8 +2263,20 @@ AS_CASE([$with_cmocka],
AC_SUBST([CMOCKA_CFLAGS])
AC_SUBST([CMOCKA_LIBS])
+#
+# Use lock-free Michael-Scott's queue implementation or locked-list queue
+#
+# [pairwise: --enable-lock-free-queue, --disable-lock-free-queue]
+AC_ARG_ENABLE([lock-free-queue],
+ [AS_HELP_STRING([--enable-lock-free-queue],[enable lock-free queue implementation (default is enabled)])],
+ [],[enable_lock_free_queue=yes])
+AS_CASE([$enable_lock_free_queue],
+ [no],[],
+ [yes],[AC_DEFINE([USE_LOCK_FREE_QUEUE],[1],[Define to 1 to enable lock-free queue])])
+
AC_DEFINE([SKIPPED_TEST_EXIT_CODE], [0], [Exit code for skipped tests])
+
#
# Check for kyua execution engine if CMocka was requested
# and bail out if execution engine was not found
diff --git a/lib/isc/include/isc/queue.h b/lib/isc/include/isc/queue.h
index 0927075..568bf18 100644
--- a/lib/isc/include/isc/queue.h
+++ b/lib/isc/include/isc/queue.h
@@ -39,8 +39,7 @@ uintptr_t
isc_queue_dequeue(isc_queue_t *queue);
/*%<
* Remove an object pointer from the head of the queue and return the
- * pointer. If the queue is empty, return `nulluintptr` (the uintptr_t
- * representation of NULL).
+ * pointer. If the queue is empty, return `NULL`.
*
* Requires:
* \li 'queue' is not null.
diff --git a/lib/isc/queue.c b/lib/isc/queue.c
index d7ea824..c4cb404 100644
--- a/lib/isc/queue.c
+++ b/lib/isc/queue.c
@@ -28,6 +28,10 @@
static uintptr_t nulluintptr = (uintptr_t)NULL;
+#if USE_LOCK_FREE_QUEUE
+
+#define BUFFER_SIZE 1024
+
typedef struct node {
atomic_uint_fast32_t deqidx;
atomic_uintptr_t items[BUFFER_SIZE];
@@ -232,3 +236,120 @@ isc_queue_destroy(isc_queue_t *queue) {
alloced = queue->alloced_ptr;
isc_mem_putanddetach(&queue->mctx, alloced, sizeof(*queue) + ALIGNMENT);
}
+
+#else /* USE_LOCK_FREE_QUEUE */
+
+typedef struct node node_t;
+
+struct node {
+ uintptr_t item;
+ ISC_LINK(node_t) link;
+};
+
+struct isc_queue {
+ isc_mem_t *mctx;
+ isc_mutex_t lock;
+ int max_threads;
+ ISC_LIST(node_t) nodes;
+ void *alloced_ptr;
+};
+
+static node_t *
+node_new(isc_mem_t *mctx, uintptr_t item) {
+ node_t *node = isc_mem_get(mctx, sizeof(*node));
+ *node = (node_t){
+ .item = item,
+ };
+
+ ISC_LINK_INIT(node, link);
+
+ return (node);
+}
+
+static void
+node_destroy(isc_mem_t *mctx, node_t *node) {
+ isc_mem_put(mctx, node, sizeof(*node));
+}
+
+isc_queue_t *
+isc_queue_new(isc_mem_t *mctx, int max_threads) {
+ isc_queue_t *queue = NULL;
+ void *qbuf = NULL;
+ uintptr_t qptr;
+
+ qbuf = isc_mem_get(mctx, sizeof(*queue) + ALIGNMENT);
+ qptr = (uintptr_t)qbuf;
+ queue = (isc_queue_t *)(qptr + (ALIGNMENT - (qptr % ALIGNMENT)));
+
+ if (max_threads == 0) {
+ max_threads = MAX_THREADS;
+ }
+
+ *queue = (isc_queue_t){
+ .max_threads = max_threads,
+ .alloced_ptr = qbuf,
+ };
+
+ ISC_LIST_INIT(queue->nodes);
+
+ isc_mutex_init(&queue->lock);
+ isc_mem_attach(mctx, &queue->mctx);
+
+ return (queue);
+}
+
+void
+isc_queue_enqueue(isc_queue_t *queue, uintptr_t item) {
+ node_t *node = node_new(queue->mctx, item);
+ REQUIRE(item != nulluintptr);
+
+ LOCK(&queue->lock);
+ ISC_LIST_ENQUEUE(queue->nodes, node, link);
+ UNLOCK(&queue->lock);
+}
+
+uintptr_t
+isc_queue_dequeue(isc_queue_t *queue) {
+ node_t *node = NULL;
+ uintptr_t item = nulluintptr;
+ REQUIRE(queue != NULL);
+
+ LOCK(&queue->lock);
+ node = ISC_LIST_HEAD(queue->nodes);
+ if (node != NULL) {
+ ISC_LIST_DEQUEUE(queue->nodes, node, link);
+ item = node->item;
+ }
+ UNLOCK(&queue->lock);
+
+ if (node != NULL) {
+ node_destroy(queue->mctx, node);
+ }
+
+ return (item);
+}
+
+void
+isc_queue_destroy(isc_queue_t *queue) {
+ node_t *node = NULL;
+ void *alloced = NULL;
+
+ REQUIRE(queue != NULL);
+
+ LOCK(&queue->lock);
+ node = ISC_LIST_HEAD(queue->nodes);
+ while (node != NULL) {
+ node_t *next = ISC_LIST_NEXT(node, link);
+ ISC_LIST_DEQUEUE(queue->nodes, node, link);
+ node_destroy(queue->mctx, node);
+ node = next;
+ }
+ UNLOCK(&queue->lock);
+
+ isc_mutex_destroy(&queue->lock);
+
+ alloced = queue->alloced_ptr;
+ isc_mem_putanddetach(&queue->mctx, alloced, sizeof(*queue) + ALIGNMENT);
+}
+
+#endif /* USE_LOCK_FREE_QUEUE */
--
2.34.1

View File

@ -1,66 +0,0 @@
From 1feb389f80f7595d2f873c3ff8678b52cd2db828 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
Date: Tue, 24 May 2022 19:42:41 +0200
Subject: [PATCH] Fix failures in isc netmgr_test on big endian machines
Typing from libuv structure to isc_region_t is not possible, because
their sizes differ on 64 bit architectures. Little endian machines seems
to be lucky and still result in test passed. But big endian machine such
as s390x fails the test reliably.
Fix by directly creating the buffer as isc_region_t and skipping the
type conversion. More readable and still more correct.
(cherry picked from commit 057438cb45f2f02615dc309e3822f23c0ca70a0a)
---
lib/isc/tests/netmgr_test.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/lib/isc/tests/netmgr_test.c b/lib/isc/tests/netmgr_test.c
index c2d7fffb32..9fa0d47e5b 100644
--- a/lib/isc/tests/netmgr_test.c
+++ b/lib/isc/tests/netmgr_test.c
@@ -62,11 +62,11 @@ static isc_sockaddr_t tcp_connect_addr;
static uint64_t send_magic = 0;
static uint64_t stop_magic = 0;
-static uv_buf_t send_msg = { .base = (char *)&send_magic,
- .len = sizeof(send_magic) };
+static isc_region_t send_msg = { .base = (unsigned char *)&send_magic,
+ .length = sizeof(send_magic) };
-static uv_buf_t stop_msg = { .base = (char *)&stop_magic,
- .len = sizeof(stop_magic) };
+static isc_region_t stop_msg = { .base = (unsigned char *)&stop_magic,
+ .length = sizeof(stop_magic) };
static atomic_bool do_send = false;
static unsigned int workers = 0;
@@ -420,11 +420,9 @@ connect_send(isc_nmhandle_t *handle) {
isc_nmhandle_attach(handle, &sendhandle);
isc_nmhandle_setwritetimeout(handle, T_IDLE);
if (atomic_fetch_sub(&nsends, 1) > 1) {
- isc_nm_send(sendhandle, (isc_region_t *)&send_msg,
- connect_send_cb, NULL);
+ isc_nm_send(sendhandle, &send_msg, connect_send_cb, NULL);
} else {
- isc_nm_send(sendhandle, (isc_region_t *)&stop_msg,
- connect_send_cb, NULL);
+ isc_nm_send(sendhandle, &stop_msg, connect_send_cb, NULL);
}
}
@@ -531,8 +529,8 @@ listen_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
isc_nmhandle_attach(handle, &sendhandle);
isc_refcount_increment0(&active_ssends);
isc_nmhandle_setwritetimeout(sendhandle, T_IDLE);
- isc_nm_send(sendhandle, (isc_region_t *)&send_msg,
- listen_send_cb, cbarg);
+ isc_nm_send(sendhandle, &send_msg, listen_send_cb,
+ cbarg);
}
return;
}
--
2.34.3

View File

@ -51,8 +51,8 @@
Summary: The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server Summary: The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server
Name: bind Name: bind
License: MPLv2.0 License: MPLv2.0
Version: 9.16.29 Version: 9.16.30
Release: 2%{?dist} Release: 1%{?dist}
Epoch: 32 Epoch: 32
Url: https://www.isc.org/downloads/bind/ Url: https://www.isc.org/downloads/bind/
# #
@ -102,13 +102,9 @@ Patch24: bind-9.9.1-P2-dlz-libdb.patch
# https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/2689 # https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/2689
Patch25:bind-9.11-rh1666814.patch Patch25:bind-9.11-rh1666814.patch
# https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/5905
Patch26: bind-9.16-locked-isc-queue.patch
# https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/5273 # https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/5273
Patch27: bind-9.16-resolv.conf-options-timeout.patch Patch27: bind-9.16-resolv.conf-options-timeout.patch
Patch28: bind-9.16-resolv.conf-options-timeout-test.patch Patch28: bind-9.16-resolv.conf-options-timeout-test.patch
# https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/6352
Patch29: bind-9.16-rhbz2088125.patch
%{?systemd_ordering} %{?systemd_ordering}
Requires: coreutils Requires: coreutils
@ -468,7 +464,6 @@ export LIBDIR_SUFFIX
--includedir=%{_includedir}/bind9 \ --includedir=%{_includedir}/bind9 \
--with-tuning=large \ --with-tuning=large \
--with-libidn2 \ --with-libidn2 \
--disable-lock-free-queue \
%if %{with GEOIP2} %if %{with GEOIP2}
--with-maxminddb \ --with-maxminddb \
%endif %endif
@ -1119,6 +1114,9 @@ fi;
%endif %endif
%changelog %changelog
* Mon Jun 20 2022 Petr Menšík <pemensik@redhat.com> - 32:9.16.30-1
- Update to 9.16.30 (#2097312)
* Mon Jun 13 2022 Python Maint <python-maint@redhat.com> - 32:9.16.29-2 * Mon Jun 13 2022 Python Maint <python-maint@redhat.com> - 32:9.16.29-2
- Rebuilt for Python 3.11 - Rebuilt for Python 3.11

View File

@ -1,2 +1,2 @@
SHA512 (bind-9.16.29.tar.xz) = b4acbafed370438ac53e73468ccb5ea5745a1c8f764dd96f9c9a027594a3b7ce0d486e7f01138b39795b456265e0e6116cd76e44f5a3329687cd718550ca79fb SHA512 (bind-9.16.30.tar.xz) = cc9bcbedf63c2efe0a23f14db3e57fdae46f0509aac58e5840a6805ce4fbd76cad5bfde4d461442adb88c4d947f8d79bf979aeb24aeb9303b6adc8d169b7118c
SHA512 (bind-9.16.29.tar.xz.asc) = 98c1fea8cc2a2465aff5f4449a122046fbb98ff648a96147885c4bdd9d1e7e578de693d14587544a8846c89c0cff97d2fa9620fb1a63c3938086b2fea0eb1112 SHA512 (bind-9.16.30.tar.xz.asc) = 943ff140aaa413f125d039748a0c10d7ae20b0fa4075227ab0b9d065816e7960a3c4e0fb2a4498946926409568c71076026cbd0be33a78db73966366d43bfdb1