From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f48.google.com (mail-pg0-f48.google.com [74.125.83.48]) by dpdk.org (Postfix) with ESMTP id 512807CE8 for ; Fri, 18 Aug 2017 22:09:31 +0200 (CEST) Received: by mail-pg0-f48.google.com with SMTP id t3so42553020pgt.0 for ; Fri, 18 Aug 2017 13:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bigswitch-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=WIhzLSjs+LFAerEXlw0i4+4+HFHbNS5yOPTRQhHWTZE=; b=dJxSqmCL713+I+LQidxOGgPFKuk6iik3eXKtxCDubHDA4adws+JMVx5xbCF6OvzGW1 8QQubgH49jA0XRKmAucI8NTyyud6rfY/G+4bRf/b0yLOKGLwmEFPorNCQoTgfLjkkGGl LE0zpAzy0sQIrabuu3ueaVf2EJF7kIDH/nVz24naJKjktB56iMuvy14Nv7mSYW6T3BCs 2xAAIoZD27m7QWQ5VKqEdbXQ9F/LStmEDVgWxIlkc6B4fjDln1n0Sr8t3qKlg9ndIGDo glX77FiCRQWXOCH2eqIz5yJ2cQC5HkilfOWDisZwMAsJxZSQNE4tBy3esjur9vqU0G1d 4Kgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WIhzLSjs+LFAerEXlw0i4+4+HFHbNS5yOPTRQhHWTZE=; b=AW53oEfKOcxlJExChtLfHgYd66mzmzG1HjxarqKRnJacC8UAK0jgo8sXedxzTTG7in 9lLaOB6ZgqmjvRepoooTkpjIC1wNYH6j4fWupzOmt38OCXhQDhG9OdbpOIjzWeK623sg buKf6GFRmILJ8PeDvz4UpD+YNx0HGK8+kuY3XppNyxvX3nxHPW7MezVr4cF1parMRUxS xKj+pWPHMXs9s7lSRjcAld2XAasRjTDtJpnxQE/xHtu2Q0WP2aKr5zAg09DUTodd1pIz zM8TWMj6bgFWXQb4mSZ2zPnMTRTcIuk4gwHiKFMyJMfqQLO26Hr423JiGwJsyW3wkfKr xaPg== X-Gm-Message-State: AHYfb5g9AeAiOF4FeRhOgdtmF7VRtyTe3pK0p79/zAZLuBNQjLu7XfzG bdjYQivZwDUJ+BGR X-Received: by 10.101.90.136 with SMTP id c8mr9360031pgt.168.1503086970444; Fri, 18 Aug 2017 13:09:30 -0700 (PDT) Received: from dpdk-dell-430.sw.bigswitch.com ([173.227.38.50]) by smtp.gmail.com with ESMTPSA id e131sm10853195pgc.64.2017.08.18.13.09.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Aug 2017 13:09:29 -0700 (PDT) From: mstolarchuk To: bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org Date: Fri, 18 Aug 2017 13:09:32 -0700 Message-Id: <1503086972-32649-1-git-send-email-mike.stolarchuk@bigswitch.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH 1/7] Use an accessor for rte_hash_key X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Aug 2017 20:09:31 -0000 Improves consistency, allows identifcation of use-sites Signed-off-by: mstolarchuk --- lib/librte_hash/rte_cuckoo_hash.c | 64 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 87b25c0..d1fbb0b 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -500,6 +500,20 @@ struct rte_hash * rte_ring_sp_enqueue(h->free_slots, slot_id); } +/* + * Function to compute the location of rte_hash_key from an index + */ +static inline struct rte_hash_key * +__rte_hash_key_from_idx(const struct rte_hash *h, const uint32_t idx) +{ + /* private structure only to compute rte_hash_key offset */ + struct key_entry { + char element_size[h->key_entry_size]; + } __attribute__((packed)) *key_store = h->key_store; + + return (struct rte_hash_key *)(key_store + idx); +} + static inline int32_t __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig, void *data) @@ -508,7 +522,7 @@ struct rte_hash * uint32_t prim_bucket_idx, sec_bucket_idx; unsigned i; struct rte_hash_bucket *prim_bkt, *sec_bkt; - struct rte_hash_key *new_k, *k, *keys = h->key_store; + struct rte_hash_key *new_k, *k; void *slot_id = NULL; uint32_t new_idx; int ret; @@ -556,7 +570,7 @@ struct rte_hash * } } - new_k = RTE_PTR_ADD(keys, (uintptr_t)slot_id * h->key_entry_size); + new_k = __rte_hash_key_from_idx(h, (uintptr_t)slot_id); rte_prefetch0(new_k); new_idx = (uint32_t)((uintptr_t) slot_id); @@ -564,8 +578,7 @@ struct rte_hash * for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) { if (prim_bkt->sig_current[i] == sig && prim_bkt->sig_alt[i] == alt_hash) { - k = (struct rte_hash_key *) ((char *)keys + - prim_bkt->key_idx[i] * h->key_entry_size); + k = __rte_hash_key_from_idx(h, prim_bkt->key_idx[i]); if (rte_hash_cmp_eq(key, k->key, h) == 0) { /* Enqueue index of free slot back in the ring. */ enqueue_slot_back(h, cached_free_slots, slot_id); @@ -584,8 +597,7 @@ struct rte_hash * for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) { if (sec_bkt->sig_alt[i] == sig && sec_bkt->sig_current[i] == alt_hash) { - k = (struct rte_hash_key *) ((char *)keys + - sec_bkt->key_idx[i] * h->key_entry_size); + k = __rte_hash_key_from_idx(h, sec_bkt->key_idx[i]); if (rte_hash_cmp_eq(key, k->key, h) == 0) { /* Enqueue index of free slot back in the ring. */ enqueue_slot_back(h, cached_free_slots, slot_id); @@ -711,6 +723,7 @@ struct rte_hash * else return ret; } + static inline int32_t __rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig, void **data) @@ -719,7 +732,7 @@ struct rte_hash * hash_sig_t alt_hash; unsigned i; struct rte_hash_bucket *bkt; - struct rte_hash_key *k, *keys = h->key_store; + struct rte_hash_key *k; bucket_idx = sig & h->bucket_bitmask; bkt = &h->buckets[bucket_idx]; @@ -728,8 +741,7 @@ struct rte_hash * for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) { if (bkt->sig_current[i] == sig && bkt->key_idx[i] != EMPTY_SLOT) { - k = (struct rte_hash_key *) ((char *)keys + - bkt->key_idx[i] * h->key_entry_size); + k = __rte_hash_key_from_idx(h, bkt->key_idx[i]); if (rte_hash_cmp_eq(key, k->key, h) == 0) { if (data != NULL) *data = k->pdata; @@ -751,8 +763,7 @@ struct rte_hash * for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) { if (bkt->sig_current[i] == alt_hash && bkt->sig_alt[i] == sig) { - k = (struct rte_hash_key *) ((char *)keys + - bkt->key_idx[i] * h->key_entry_size); + k = __rte_hash_key_from_idx(h, bkt->key_idx[i]); if (rte_hash_cmp_eq(key, k->key, h) == 0) { if (data != NULL) *data = k->pdata; @@ -835,7 +846,7 @@ struct rte_hash * hash_sig_t alt_hash; unsigned i; struct rte_hash_bucket *bkt; - struct rte_hash_key *k, *keys = h->key_store; + struct rte_hash_key *k; int32_t ret; bucket_idx = sig & h->bucket_bitmask; @@ -845,8 +856,7 @@ struct rte_hash * for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) { if (bkt->sig_current[i] == sig && bkt->key_idx[i] != EMPTY_SLOT) { - k = (struct rte_hash_key *) ((char *)keys + - bkt->key_idx[i] * h->key_entry_size); + k = __rte_hash_key_from_idx(h, bkt->key_idx[i]); if (rte_hash_cmp_eq(key, k->key, h) == 0) { remove_entry(h, bkt, i); @@ -870,8 +880,7 @@ struct rte_hash * for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) { if (bkt->sig_current[i] == alt_hash && bkt->key_idx[i] != EMPTY_SLOT) { - k = (struct rte_hash_key *) ((char *)keys + - bkt->key_idx[i] * h->key_entry_size); + k = __rte_hash_key_from_idx(h, bkt->key_idx[i]); if (rte_hash_cmp_eq(key, k->key, h) == 0) { remove_entry(h, bkt, i); @@ -910,9 +919,7 @@ struct rte_hash * { RETURN_IF_TRUE(((h == NULL) || (key == NULL)), -EINVAL); - struct rte_hash_key *k, *keys = h->key_store; - k = (struct rte_hash_key *) ((char *) keys + (position + 1) * - h->key_entry_size); + struct rte_hash_key *k = __rte_hash_key_from_idx(h, position + 1); *key = k->key; if (position != @@ -1037,9 +1044,7 @@ struct rte_hash * uint32_t first_hit = __builtin_ctzl(prim_hitmask[i]); uint32_t key_idx = primary_bkt[i]->key_idx[first_hit]; const struct rte_hash_key *key_slot = - (const struct rte_hash_key *)( - (const char *)h->key_store + - key_idx * h->key_entry_size); + __rte_hash_key_from_idx(h, key_idx); rte_prefetch0(key_slot); continue; } @@ -1048,9 +1053,7 @@ struct rte_hash * uint32_t first_hit = __builtin_ctzl(sec_hitmask[i]); uint32_t key_idx = secondary_bkt[i]->key_idx[first_hit]; const struct rte_hash_key *key_slot = - (const struct rte_hash_key *)( - (const char *)h->key_store + - key_idx * h->key_entry_size); + __rte_hash_key_from_idx(h, key_idx); rte_prefetch0(key_slot); } } @@ -1063,9 +1066,7 @@ struct rte_hash * uint32_t key_idx = primary_bkt[i]->key_idx[hit_index]; const struct rte_hash_key *key_slot = - (const struct rte_hash_key *)( - (const char *)h->key_store + - key_idx * h->key_entry_size); + __rte_hash_key_from_idx(h, key_idx); /* * If key index is 0, do not compare key, * as it is checking the dummy slot @@ -1086,9 +1087,7 @@ struct rte_hash * uint32_t key_idx = secondary_bkt[i]->key_idx[hit_index]; const struct rte_hash_key *key_slot = - (const struct rte_hash_key *)( - (const char *)h->key_store + - key_idx * h->key_entry_size); + __rte_hash_key_from_idx(h, key_idx); /* * If key index is 0, do not compare key, * as it is checking the dummy slot @@ -1170,8 +1169,7 @@ struct rte_hash * /* Get position of entry in key table */ position = h->buckets[bucket_idx].key_idx[idx]; - next_key = (struct rte_hash_key *) ((char *)h->key_store + - position * h->key_entry_size); + next_key = __rte_hash_key_from_idx(h, position); /* Return key and data */ *key = next_key->key; *data = next_key->pdata; -- 1.9.1