From: Ondřej Surý Date: Tue, 14 Dec 2021 20:49:53 +0000 (+0100) Subject: Add #define ISC_OS_CACHELINE_SIZE 64 X-Git-Tag: v9.17.22~9^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f78f9d72a5dc3f6a596251e662d00cb80cd5e6d;p=thirdparty%2Fbind9.git Add #define ISC_OS_CACHELINE_SIZE 64 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. --- diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 70358f8a821..c6f800d5c68 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -168,6 +168,7 @@ libisc_la_SOURCES = \ openssl_shim.c \ openssl_shim.h \ os.c \ + os_p.h \ parseint.c \ pool.c \ portset.c \ diff --git a/lib/isc/include/isc/os.h b/lib/isc/include/isc/os.h index f9e90e0d82c..96c9f0f3ea0 100644 --- a/lib/isc/include/isc/os.h +++ b/lib/isc/include/isc/os.h @@ -14,9 +14,17 @@ /*! \file isc/os.h */ #include +#include 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); /*%< diff --git a/lib/isc/lib.c b/lib/isc/lib.c index 5f9173ff4cb..e591b08780f 100644 --- a/lib/isc/lib.c +++ b/lib/isc/lib.c @@ -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(); } diff --git a/lib/isc/os.c b/lib/isc/os.c index 6a75b609766..660d94af578 100644 --- a/lib/isc/os.c +++ b/lib/isc/os.c @@ -9,12 +9,15 @@ * information regarding copyright ownership. */ -#include +#include + #include +#include #include -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 index 00000000000..0c28a06975e --- /dev/null +++ b/lib/isc/os_p.h @@ -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 + +#include + +/*! \file */ + +void +isc__os_initialize(void); + +void +isc__os_shutdown(void); diff --git a/util/copyrights b/util/copyrights index 150f956e9d9..e57b83189ee 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1790,6 +1790,7 @@ ./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