From b84c9b2608416544f33cff916a77bb155026de30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 31 Mar 2022 11:12:41 +0200 Subject: [PATCH 1/2] Turn isc_hash_bits32() into static online function Adding extra val & 0xffff in the isc_hash_bits32() macros in the hotpath has significantly reduced the performance. Turn the macro into static inline function matching the previous hash_32() function used to compute hashval matching the hashtable->bits. --- lib/isc/include/isc/hash.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/isc/include/isc/hash.h b/lib/isc/include/isc/hash.h index 80e50da83d..c3926157d0 100644 --- a/lib/isc/include/isc/hash.h +++ b/lib/isc/include/isc/hash.h @@ -19,6 +19,7 @@ #include #include #include +#include #define ISC_HASHSIZE(bits) (UINT64_C(1) << (bits)) #define ISC_HASH_OVERCOMMIT 3 @@ -80,12 +81,12 @@ isc_hash64(const void *data, const size_t length, const bool case_sensitive); * \li a hash value of length 'bits'. */ #define ISC_HASH_GOLDENRATIO_32 0x61C88647 -#define isc_hash_bits32(val, bits) \ - ({ \ - REQUIRE(bits <= 32U); \ - uint32_t __v = (val & 0xffff); \ - __v = ((__v * ISC_HASH_GOLDENRATIO_32) >> (32 - bits)); \ - __v; \ - }) + +static inline uint32_t +isc_hash_bits32(uint32_t val, unsigned int bits) { + ISC_REQUIRE(bits <= ISC_HASH_MAX_BITS); + /* High bits are more random. */ + return (val * ISC_HASH_GOLDENRATIO_32 >> (32 - bits)); +} ISC_LANG_ENDDECLS From 96030f23a42f175c4038d1611bbae935051dcdf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 1 Apr 2022 23:05:43 +0200 Subject: [PATCH 2/2] Help gcovr find isc/hash.h when included from lib/dns Similar to other tweaks, copy the lib/isc/include/isc/hash.h to lib/dns to help gcovr find the file. --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 727b2394a6..5877c54a26 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1431,6 +1431,8 @@ gcov: # Help gcovr process the nasty tricks in lib/dns/code.h, where we include C # source files from lib/dns/rdata/*/, using an even nastier trick. - find lib/dns/rdata/* -name "*.c" -execdir cp -f "{}" ../../ \; + # Help gcovr process inline function in the isc/hash.h + - cp -f lib/isc/include/isc/hash.h lib/dns/hash.h # Generate XML file in the Cobertura XML format suitable for use by GitLab # for the purpose of displaying code coverage information in the diff view # of a given merge request.