From: Neil Horman Date: Wed, 15 May 2024 19:34:15 +0000 (-0400) Subject: some performance improvements X-Git-Tag: openssl-3.4.0-alpha1~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14efc05314ce1bd8e8988d02f69a819a4e0a56ab;p=thirdparty%2Fopenssl.git some performance improvements Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/24504) --- diff --git a/crypto/hashtable/hashtable.c b/crypto/hashtable/hashtable.c index 77c546dbb00..de5fdbeeca1 100644 --- a/crypto/hashtable/hashtable.c +++ b/crypto/hashtable/hashtable.c @@ -76,8 +76,10 @@ */ #if defined(__GNUC__) || defined(__CLANG__) #define PREFETCH_NEIGHBORHOOD(x) __builtin_prefetch(x.entries) +#define PREFETCH(x) __builtin_prefetch(x) #else #define PREFETCH_NEIGHBORHOOD(x) +#define PREFETCH(x) #endif static ossl_unused uint64_t fnv1a_hash(uint8_t *key, size_t len) @@ -520,7 +522,9 @@ static ossl_inline int match_key(HT_KEY *a, HT_KEY *b) * keys match if they are both present, the same size * and compare equal in memory */ - if (a != NULL && b != NULL && a->keysize == b->keysize) + PREFETCH(a->keybuf); + PREFETCH(b->keybuf); + if (a->keybuf != NULL && b->keybuf != NULL && a->keysize == b->keysize) return !memcmp(a->keybuf, b->keybuf, a->keysize); return 1; @@ -548,13 +552,12 @@ static int ossl_ht_insert_locked(HT *h, uint64_t hash, if (ival == NULL) empty_idx = j; - if (compare_hash(hash, ihash)) { + if (compare_hash(hash, ihash) && match_key(&newval->value.key, + &ival->key)) { /* Its the same hash, lets make sure its not a collision */ - if (match_key(&newval->value.key, &ival->key)) { - if (olddata == NULL) { - /* invalid */ - return 0; - } + if (olddata == NULL) { + /* invalid */ + return 0; } /* Do a replacement */ if (!CRYPTO_atomic_store(&md->neighborhoods[neigh_idx].entries[j].hash, @@ -688,7 +691,6 @@ static void free_old_entry(void *arg) int ossl_ht_delete(HT *h, HT_KEY *key) { - struct ht_mutable_data_st *md = ossl_rcu_deref(&h->md); uint64_t hash; uint64_t neigh_idx; size_t j; @@ -702,9 +704,8 @@ int ossl_ht_delete(HT *h, HT_KEY *key) PREFETCH_NEIGHBORHOOD(h->md->neighborhoods[neigh_idx]); for (j = 0; j < NEIGHBORHOOD_LEN; j++) { v = (struct ht_internal_value_st *)h->md->neighborhoods[neigh_idx].entries[j].value; - if (compare_hash(hash, h->md->neighborhoods[neigh_idx].entries[j].hash)) { - if (!match_key(key, &v->value.key)) - continue; + if (compare_hash(hash, h->md->neighborhoods[neigh_idx].entries[j].hash) + && match_key(key, &v->value.key)) { if (!CRYPTO_atomic_store(&h->md->neighborhoods[neigh_idx].entries[j].hash, 0, h->atomic_lock)) break;