From: "David S. Miller" <davem@davemloft.net>
To: laforge@gnumonks.org
Cc: netdev@oss.sgi.com
Subject: [6/6]: jenkins hash for neigh
Date: Thu, 23 Sep 2004 22:51:58 -0700 [thread overview]
Message-ID: <20040923225158.23c2d502.davem@davemloft.net> (raw)
This makes all the neigh implementations use jenkins.
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2004/09/23 18:03:13-07:00 davem@nuts.davemloft.net
# [NET]: Convert neigh hashing over to jenkins.
#
# Based upon work by Harald Welte <laforge@netfilter.org>
#
# Signed-off-by: David S. Miller <davem@davemloft.net>
#
# net/ipv6/ndisc.c
# 2004/09/23 18:02:32-07:00 davem@nuts.davemloft.net +7 -7
# [NET]: Convert neigh hashing over to jenkins.
#
# net/ipv4/arp.c
# 2004/09/23 18:02:32-07:00 davem@nuts.davemloft.net +3 -9
# [NET]: Convert neigh hashing over to jenkins.
#
# net/decnet/dn_neigh.c
# 2004/09/23 18:02:32-07:00 davem@nuts.davemloft.net +2 -7
# [NET]: Convert neigh hashing over to jenkins.
#
# net/core/neighbour.c
# 2004/09/23 18:02:32-07:00 davem@nuts.davemloft.net +3 -0
# [NET]: Convert neigh hashing over to jenkins.
#
# net/atm/clip.c
# 2004/09/23 18:02:32-07:00 davem@nuts.davemloft.net +2 -9
# [NET]: Convert neigh hashing over to jenkins.
#
# include/net/neighbour.h
# 2004/09/23 18:02:32-07:00 davem@nuts.davemloft.net +1 -0
# [NET]: Convert neigh hashing over to jenkins.
#
diff -Nru a/include/net/neighbour.h b/include/net/neighbour.h
--- a/include/net/neighbour.h 2004-09-23 22:27:14 -07:00
+++ b/include/net/neighbour.h 2004-09-23 22:27:14 -07:00
@@ -175,6 +175,7 @@
struct neigh_statistics stats;
struct neighbour **hash_buckets;
unsigned int hash_mask;
+ __u32 hash_rnd;
struct pneigh_entry **phash_buckets;
};
diff -Nru a/net/atm/clip.c b/net/atm/clip.c
--- a/net/atm/clip.c 2004-09-23 22:27:14 -07:00
+++ b/net/atm/clip.c 2004-09-23 22:27:14 -07:00
@@ -27,6 +27,7 @@
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/rcupdate.h>
+#include <linux/jhash.h>
#include <net/route.h> /* for struct rtable and routing */
#include <net/icmp.h> /* icmp_send */
#include <asm/param.h> /* for HZ */
@@ -328,15 +329,7 @@
static u32 clip_hash(const void *pkey, const struct net_device *dev)
{
- u32 hash_val;
-
- hash_val = *(u32*)pkey;
- hash_val ^= (hash_val>>16);
- hash_val ^= hash_val>>8;
- hash_val ^= hash_val>>3;
- hash_val = (hash_val^dev->ifindex);
-
- return hash_val;
+ return jhash_2words(*(u32 *)pkey, dev->ifindex, clip_tbl.hash_rnd);
}
static struct neigh_table clip_tbl = {
diff -Nru a/net/core/neighbour.c b/net/core/neighbour.c
--- a/net/core/neighbour.c 2004-09-23 22:27:14 -07:00
+++ b/net/core/neighbour.c 2004-09-23 22:27:14 -07:00
@@ -29,6 +29,7 @@
#include <net/dst.h>
#include <net/sock.h>
#include <linux/rtnetlink.h>
+#include <linux/random.h>
#define NEIGH_DEBUG 1
@@ -1316,6 +1317,8 @@
panic("cannot allocate neighbour cache hashes");
memset(tbl->phash_buckets, 0, phsize);
+
+ get_random_bytes(&tbl->hash_rnd, sizeof(tbl->hash_rnd));
tbl->lock = RW_LOCK_UNLOCKED;
init_timer(&tbl->gc_timer);
diff -Nru a/net/decnet/dn_neigh.c b/net/decnet/dn_neigh.c
--- a/net/decnet/dn_neigh.c 2004-09-23 22:27:14 -07:00
+++ b/net/decnet/dn_neigh.c 2004-09-23 22:27:14 -07:00
@@ -36,6 +36,7 @@
#include <linux/spinlock.h>
#include <linux/seq_file.h>
#include <linux/rcupdate.h>
+#include <linux/jhash.h>
#include <asm/atomic.h>
#include <net/neighbour.h>
#include <net/dst.h>
@@ -122,13 +123,7 @@
static u32 dn_neigh_hash(const void *pkey, const struct net_device *dev)
{
- u32 hash_val;
-
- hash_val = *(dn_address *)pkey;
- hash_val ^= (hash_val >> 10);
- hash_val ^= (hash_val >> 3);
-
- return hash_val;
+ return jhash_2words(*(dn_address *)pkey, 0, dn_neigh_table.hash_rnd);
}
static int dn_neigh_construct(struct neighbour *neigh)
diff -Nru a/net/ipv4/arp.c b/net/ipv4/arp.c
--- a/net/ipv4/arp.c 2004-09-23 22:27:14 -07:00
+++ b/net/ipv4/arp.c 2004-09-23 22:27:14 -07:00
@@ -71,6 +71,7 @@
* arp_xmit so intermediate drivers like
* bonding can change the skb before
* sending (e.g. insert 8021q tag).
+ * Harald Welte : convert to make use of jenkins hash
*/
#include <linux/module.h>
@@ -97,6 +98,7 @@
#include <linux/init.h>
#include <linux/net.h>
#include <linux/rcupdate.h>
+#include <linux/jhash.h>
#ifdef CONFIG_SYSCTL
#include <linux/sysctl.h>
#endif
@@ -223,15 +225,7 @@
static u32 arp_hash(const void *pkey, const struct net_device *dev)
{
- u32 hash_val;
-
- hash_val = *(u32*)pkey;
- hash_val ^= (hash_val>>16);
- hash_val ^= hash_val>>8;
- hash_val ^= hash_val>>3;
- hash_val = (hash_val^dev->ifindex);
-
- return hash_val;
+ return jhash_2words(*(u32 *)pkey, dev->ifindex, arp_tbl.hash_rnd);
}
static int arp_constructor(struct neighbour *neigh)
diff -Nru a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
--- a/net/ipv6/ndisc.c 2004-09-23 22:27:14 -07:00
+++ b/net/ipv6/ndisc.c 2004-09-23 22:27:14 -07:00
@@ -66,6 +66,7 @@
#include <linux/if_arp.h>
#include <linux/ipv6.h>
#include <linux/icmpv6.h>
+#include <linux/jhash.h>
#include <net/sock.h>
#include <net/snmp.h>
@@ -270,15 +271,14 @@
static u32 ndisc_hash(const void *pkey, const struct net_device *dev)
{
- u32 hash_val;
+ const u32 *p32 = pkey;
+ u32 addr_hash, i;
- hash_val = *(u32*)(pkey + sizeof(struct in6_addr) - 4);
- hash_val ^= (hash_val>>16);
- hash_val ^= hash_val>>8;
- hash_val ^= hash_val>>3;
- hash_val = (hash_val^dev->ifindex);
+ addr_hash = 0;
+ for (i = 0; i < (sizeof(struct in6_addr) / sizeof(u32)); i++)
+ addr_hash ^= *p32++;
- return hash_val;
+ return jhash_2words(addr_hash, dev->ifindex, nd_tbl.hash_rnd);
}
static int ndisc_constructor(struct neighbour *neigh)
next reply other threads:[~2004-09-24 5:51 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-24 5:51 David S. Miller [this message]
2004-09-24 8:52 ` [6/6]: jenkins hash for neigh Harald Welte
2004-09-24 21:27 ` David S. Miller
2004-09-25 6:44 ` Harald Welte
2004-09-25 7:56 ` David S. Miller
2004-09-25 8:14 ` YOSHIFUJI Hideaki / 吉藤英明
2004-09-25 8:27 ` YOSHIFUJI Hideaki / 吉藤英明
2004-09-25 8:30 ` David S. Miller
2004-09-25 9:09 ` Harald Welte
2004-09-25 13:33 ` Steven Whitehouse
2004-09-26 0:48 ` David S. Miller
2004-09-26 3:31 ` David S. Miller
2004-09-26 11:21 ` Thomas Graf
2004-09-27 9:29 ` Harald Welte
2004-09-27 18:57 ` David S. Miller
2004-09-26 10:11 ` YOSHIFUJI Hideaki / 吉藤英明
2004-09-27 11:43 ` Herbert Xu
2004-09-27 19:12 ` David S. Miller
2004-09-27 11:48 ` Herbert Xu
2004-09-27 18:15 ` David S. Miller
2004-09-27 21:41 ` Herbert Xu
2004-09-27 22:00 ` Herbert Xu
2004-10-02 7:50 ` Herbert Xu
2004-10-03 21:55 ` David S. Miller
2004-09-27 11:56 ` Herbert Xu
2004-09-27 19:14 ` David S. Miller
2004-09-27 22:26 ` [6/6]: jenkins hash for neigh / Statistics Harald Welte
2004-09-27 23:06 ` David S. Miller
2004-09-27 23:27 ` Stephen Hemminger
2004-09-28 8:44 ` Robert Olsson
2004-09-28 11:19 ` [PATCH 2.6] generic network statistics (was Re: [6/6]: jenkins hash for neigh / Statistics) Harald Welte
2004-09-28 12:48 ` jamal
2004-09-28 13:33 ` Thomas Graf
2004-09-29 2:22 ` jamal
2004-09-28 14:22 ` Robert Olsson
2004-09-29 2:16 ` jamal
2004-09-28 14:55 ` Harald Welte
2004-09-28 15:17 ` Robert Olsson
2004-09-28 16:24 ` Harald Welte
2004-09-28 21:43 ` David S. Miller
2004-09-29 8:04 ` Harald Welte
2004-09-28 16:27 ` [6/6]: jenkins hash for neigh / Statistics Stephen Hemminger
2004-09-28 17:06 ` Harald Welte
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=20040923225158.23c2d502.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=laforge@gnumonks.org \
--cc=netdev@oss.sgi.com \
/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).