]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add #define ISC_OS_CACHELINE_SIZE 64
authorOndřej Surý <ondrej@sury.org>
Tue, 14 Dec 2021 20:49:53 +0000 (21:49 +0100)
committerOndřej Surý <ondrej@isc.org>
Wed, 5 Jan 2022 16:07:35 +0000 (17:07 +0100)
Add library ctor and dtor for isc_os compilation unit which initializes
the numbers of the CPUs and also checks whether L1 cacheline size is
really 64 if the sysconf() call is available.

lib/isc/Makefile.am
lib/isc/include/isc/os.h
lib/isc/lib.c
lib/isc/os.c
lib/isc/os_p.h [new file with mode: 0644]
util/copyrights

index 70358f8a8212c1af48b3f0d3f1747a68e7ea9168..c6f800d5c683f3ddfe5ad9655921362960b9d95f 100644 (file)
@@ -168,6 +168,7 @@ libisc_la_SOURCES =         \
        openssl_shim.c          \
        openssl_shim.h          \
        os.c                    \
+       os_p.h                  \
        parseint.c              \
        pool.c                  \
        portset.c               \
index f9e90e0d82c707f65548c17625db193017be14f2..96c9f0f3ea0342912970db8b4bd728d326d28ab2 100644 (file)
 /*! \file isc/os.h */
 
 #include <isc/lang.h>
+#include <isc/types.h>
 
 ISC_LANG_BEGINDECLS
 
+/*%<
+ * Hardcode the L1 cacheline size of the CPU to 64, this is checked in
+ * the os.c library constructor if operating system provide means to
+ * get the L1 cacheline size using sysconf().
+ */
+#define ISC_OS_CACHELINE_SIZE 64
+
 unsigned int
 isc_os_ncpus(void);
 /*%<
index 5f9173ff4cb2c61aab0627364de9d3449b3f14e9..e591b08780ffdd4ccb886ec2a4ac416b4860e15f 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "config.h"
 #include "mem_p.h"
+#include "os_p.h"
 #include "tls_p.h"
 #include "trampoline_p.h"
 
@@ -37,6 +38,7 @@ isc__shutdown(void) ISC_DESTRUCTOR;
 
 void
 isc__initialize(void) {
+       isc__os_initialize();
        isc__mem_initialize();
        isc__tls_initialize();
        isc__trampoline_initialize();
@@ -48,4 +50,5 @@ isc__shutdown(void) {
        isc__trampoline_shutdown();
        isc__tls_shutdown();
        isc__mem_shutdown();
+       isc__os_shutdown();
 }
index 6a75b6097664f5b675239d677291435e407f0f61..660d94af5789c402ab8e0f54a91f8679d02efc39 100644 (file)
@@ -9,12 +9,15 @@
  * information regarding copyright ownership.
  */
 
-#include <isc/once.h>
+#include <inttypes.h>
+
 #include <isc/os.h>
+#include <isc/types.h>
 #include <isc/util.h>
 
-static isc_once_t ncpus_once = ISC_ONCE_INIT;
-static unsigned int ncpus = 0;
+#include "os_p.h"
+
+static unsigned int isc__os_ncpus = 0;
 
 #ifdef HAVE_SYSCONF
 
@@ -54,23 +57,33 @@ sysctl_ncpus(void) {
 static void
 ncpus_initialize(void) {
 #if defined(HAVE_SYSCONF)
-       ncpus = sysconf_ncpus();
+       isc__os_ncpus = sysconf_ncpus();
 #endif /* if defined(HAVE_SYSCONF) */
 #if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
-       if (ncpus <= 0) {
-               ncpus = sysctl_ncpus();
+       if (isc__os_ncpus <= 0) {
+               isc__os_ncpus = sysctl_ncpus();
        }
 #endif /* if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME) */
-       if (ncpus <= 0) {
-               ncpus = 1;
+       if (isc__os_ncpus == 0) {
+               isc__os_ncpus = 1;
        }
 }
 
 unsigned int
 isc_os_ncpus(void) {
-       isc_result_t result = isc_once_do(&ncpus_once, ncpus_initialize);
-       RUNTIME_CHECK(result == ISC_R_SUCCESS);
-       INSIST(ncpus > 0);
+       return (isc__os_ncpus);
+}
+
+void
+isc__os_initialize(void) {
+       ncpus_initialize();
+#if defined(HAVE_SYSCONF) && defined(_SC_LEVEL1_DCACHE_LINESIZE)
+       long s = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+       RUNTIME_CHECK((size_t)s == (size_t)ISC_OS_CACHELINE_SIZE);
+#endif
+}
 
-       return (ncpus);
+void
+isc__os_shutdown(void) {
+       /* empty, but defined for completeness */;
 }
diff --git a/lib/isc/os_p.h b/lib/isc/os_p.h
new file mode 100644 (file)
index 0000000..0c28a06
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#pragma once
+
+#include <stdio.h>
+
+#include <isc/os.h>
+
+/*! \file */
+
+void
+isc__os_initialize(void);
+
+void
+isc__os_shutdown(void);
index 150f956e9d952086c8e1ea825d328266820f76c9..e57b83189ee337d63cd7dbb550909726f1094678 100644 (file)
 ./lib/isc/openssl_shim.c                       C       2018,2019,2020,2021,2022
 ./lib/isc/openssl_shim.h                       C       2020,2021,2022
 ./lib/isc/os.c                                 C       2000,2001,2004,2005,2007,2016,2018,2019,2020,2021,2022
+./lib/isc/os_p.h                               C       2022
 ./lib/isc/parseint.c                           C       2001,2002,2003,2004,2005,2007,2012,2016,2018,2019,2020,2021,2022
 ./lib/isc/pool.c                               C       2013,2015,2016,2018,2019,2020,2021,2022
 ./lib/isc/portset.c                            C       2008,2016,2017,2018,2019,2020,2021,2022