netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] (3/4) Support lots of netdev's -- hash ifindex
@ 2004-02-06 18:05 Stephen Hemminger
  2004-02-06 21:44 ` David S. Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2004-02-06 18:05 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev

Hash network device index entries, to allow fast lookup by routing
protocols.

diff -Nru a/include/linux/netdevice.h b/include/linux/netdevice.h
--- a/include/linux/netdevice.h	Thu Feb  5 15:17:30 2004
+++ b/include/linux/netdevice.h	Thu Feb  5 15:17:30 2004
@@ -377,6 +377,8 @@
 	struct list_head	todo_list;
 	/* device name hash chain */
 	struct hlist_node	name_hlist;
+	/* device index hash chain */
+	struct hlist_node	index_hlist;
 
 	/* register/unregister state machine */
 	enum { NETREG_UNINITIALIZED=0,
diff -Nru a/net/core/dev.c b/net/core/dev.c
--- a/net/core/dev.c	Thu Feb  5 15:17:30 2004
+++ b/net/core/dev.c	Thu Feb  5 15:17:30 2004
@@ -188,6 +188,7 @@
 
 #define NETDEV_HASHBITS	8
 static struct hlist_head dev_name_head[1<<NETDEV_HASHBITS];
+static struct hlist_head dev_index_head[1<<NETDEV_HASHBITS];
 
 static inline struct hlist_head *dev_name_hash(const char *name)
 {
@@ -195,6 +196,11 @@
 	return &dev_name_head[hash & ((1<<NETDEV_HASHBITS)-1)];
 }
 
+static inline struct hlist_head *dev_index_hash(int ifindex)
+{
+	return &dev_index_head[ifindex & ((1<<NETDEV_HASHBITS)-1)];
+}
+
 /*
  *	Our notifier list
  */
@@ -554,12 +560,15 @@
 
 struct net_device *__dev_get_by_index(int ifindex)
 {
-	struct net_device *dev;
+	struct hlist_node *p;
 
-	for (dev = dev_base; dev; dev = dev->next)
+	hlist_for_each(p, dev_index_hash(ifindex)) {
+		struct net_device *dev
+			= hlist_entry(p, struct net_device, index_hlist);
 		if (dev->ifindex == ifindex)
-			break;
-	return dev;
+			return dev;
+	}
+	return NULL;
 }
 
 
@@ -2842,6 +2851,7 @@
 	*dev_tail = dev;
 	dev_tail = &dev->next;
 	hlist_add_head(&dev->name_hlist, head);
+	hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex));
 	dev_hold(dev);
 	dev->reg_state = NETREG_REGISTERING;
 	write_unlock_bh(&dev_base_lock);
@@ -3064,6 +3074,7 @@
 		if (d == dev) {
 			write_lock_bh(&dev_base_lock);
 			hlist_del(&dev->name_hlist);
+			hlist_del(&dev->index_hlist);
 			if (dev_tail == &dev->next)
 				dev_tail = dp;
 			*dp = d->next;
@@ -3144,6 +3155,9 @@
 
 	for (i = 0; i < ARRAY_SIZE(dev_name_head); i++)
 		INIT_HLIST_HEAD(&dev_name_head[i]);
+
+	for (i = 0; i < ARRAY_SIZE(dev_index_head); i++)
+		INIT_HLIST_HEAD(&dev_index_head[i]);
 
 	/*
 	 *	Initialise the packet receive queues.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] (3/4) Support lots of netdev's -- hash ifindex
  2004-02-06 18:05 [PATCH] (3/4) Support lots of netdev's -- hash ifindex Stephen Hemminger
@ 2004-02-06 21:44 ` David S. Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David S. Miller @ 2004-02-06 21:44 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On Fri, 6 Feb 2004 10:05:01 -0800
Stephen Hemminger <shemminger@osdl.org> wrote:

> Hash network device index entries, to allow fast lookup by routing
> protocols.

Ok, I am applying this and the hash netdev by name patch.

I was going to allocate the tables at run time, not put them
into the image but since these go into the BSS it's not such
a big deal after all.

Thanks Stephen.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-02-06 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-06 18:05 [PATCH] (3/4) Support lots of netdev's -- hash ifindex Stephen Hemminger
2004-02-06 21:44 ` David S. Miller

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).