From: Tom Herbert <tom@herbertland.com>
To: <davem@davemloft.net>, <netdev@vger.kernel.org>
Cc: <tgraf@suug.ch>, <roopa@cumulusnetworks.com>, <kernel-team@fb.com>
Subject: [PATCH net-next 5/7] rhashtable: abstract out function to get hash
Date: Wed, 14 Sep 2016 16:22:54 -0700 [thread overview]
Message-ID: <1473895376-347096-6-git-send-email-tom@herbertland.com> (raw)
In-Reply-To: <1473895376-347096-1-git-send-email-tom@herbertland.com>
Split out most of rht_key_hashfn which is calculating the hash into
its own function. This way the hash function can be called separately to
get the hash value.
Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Tom Herbert <tom@herbertland.com>
---
include/linux/rhashtable.h | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index fd82584..e398a62 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -208,34 +208,42 @@ static inline unsigned int rht_bucket_index(const struct bucket_table *tbl,
return (hash >> RHT_HASH_RESERVED_SPACE) & (tbl->size - 1);
}
-static inline unsigned int rht_key_hashfn(
- struct rhashtable *ht, const struct bucket_table *tbl,
- const void *key, const struct rhashtable_params params)
+static inline unsigned int rht_key_get_hash(struct rhashtable *ht,
+ const void *key, const struct rhashtable_params params,
+ unsigned int hash_rnd)
{
unsigned int hash;
/* params must be equal to ht->p if it isn't constant. */
if (!__builtin_constant_p(params.key_len))
- hash = ht->p.hashfn(key, ht->key_len, tbl->hash_rnd);
+ hash = ht->p.hashfn(key, ht->key_len, hash_rnd);
else if (params.key_len) {
unsigned int key_len = params.key_len;
if (params.hashfn)
- hash = params.hashfn(key, key_len, tbl->hash_rnd);
+ hash = params.hashfn(key, key_len, hash_rnd);
else if (key_len & (sizeof(u32) - 1))
- hash = jhash(key, key_len, tbl->hash_rnd);
+ hash = jhash(key, key_len, hash_rnd);
else
- hash = jhash2(key, key_len / sizeof(u32),
- tbl->hash_rnd);
+ hash = jhash2(key, key_len / sizeof(u32), hash_rnd);
} else {
unsigned int key_len = ht->p.key_len;
if (params.hashfn)
- hash = params.hashfn(key, key_len, tbl->hash_rnd);
+ hash = params.hashfn(key, key_len, hash_rnd);
else
- hash = jhash(key, key_len, tbl->hash_rnd);
+ hash = jhash(key, key_len, hash_rnd);
}
+ return hash;
+}
+
+static inline unsigned int rht_key_hashfn(
+ struct rhashtable *ht, const struct bucket_table *tbl,
+ const void *key, const struct rhashtable_params params)
+{
+ unsigned int hash = rht_key_get_hash(ht, key, params, tbl->hash_rnd);
+
return rht_bucket_index(tbl, hash);
}
--
2.8.0.rc2
next prev parent reply other threads:[~2016-09-14 23:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-14 23:22 [PATCH net-next 0/7] net: ILA resolver and generic resolver backend Tom Herbert
2016-09-14 23:22 ` [PATCH net-next 1/7] lwt: Add net to build_state argument Tom Herbert
2016-09-14 23:56 ` kbuild test robot
2016-09-15 0:17 ` kbuild test robot
2016-09-15 0:42 ` kbuild test robot
2016-09-15 17:17 ` Roopa Prabhu
2016-09-14 23:22 ` [PATCH net-next 2/7] spinlock: Add library function to allocate spinlock buckets array Tom Herbert
2016-09-14 23:22 ` [PATCH net-next 3/7] rhashtable: Call library function alloc_bucket_locks Tom Herbert
2016-09-20 9:29 ` Herbert Xu
2016-09-14 23:22 ` [PATCH net-next 4/7] ila: " Tom Herbert
2016-09-14 23:22 ` Tom Herbert [this message]
2016-09-20 9:36 ` [PATCH net-next 5/7] rhashtable: abstract out function to get hash Herbert Xu
2016-09-20 17:58 ` Thomas Graf
2016-09-21 2:46 ` Herbert Xu
2016-09-21 3:17 ` Tom Herbert
2016-09-14 23:22 ` [PATCH net-next 6/7] net: Generic resolver backend Tom Herbert
2016-09-20 9:40 ` Herbert Xu
2016-09-14 23:22 ` [PATCH net-next 7/7] ila: Resolver mechanism Tom Herbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1473895376-347096-6-git-send-email-tom@herbertland.com \
--to=tom@herbertland.com \
--cc=davem@davemloft.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=roopa@cumulusnetworks.com \
--cc=tgraf@suug.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).