netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: Optimize skb_tx_hash() by eliminating a comparison
@ 2009-02-18  9:20 Krishna Kumar
  2009-02-19  1:55 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Krishna Kumar @ 2009-02-18  9:20 UTC (permalink / raw)
  To: netdev; +Cc: davem, Krishna Kumar

From: Krishna Kumar <krkumar2@in.ibm.com>

Optimize skb_tx_hash() by eliminating a comparison that executes for
every packet. skb_tx_hashrnd initialization is moved to a later part of
the startup sequence, namely after the "random" driver is initialized.

Rebooted the system three times and verified that the code generates
different random numbers each time.

Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
---

 net/core/dev.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff -ruNp net-next-2.6.org/net/core/dev.c net-next-2.6.new/net/core/dev.c
--- net-next-2.6.org/net/core/dev.c	2009-02-17 18:57:15.000000000 +0530
+++ net-next-2.6.new/net/core/dev.c	2009-02-17 19:00:23.000000000 +0530
@@ -1745,17 +1745,11 @@ out_kfree_skb:
 }
 
 static u32 skb_tx_hashrnd;
-static int skb_tx_hashrnd_initialized = 0;
 
 static u16 skb_tx_hash(struct net_device *dev, struct sk_buff *skb)
 {
 	u32 hash;
 
-	if (unlikely(!skb_tx_hashrnd_initialized)) {
-		get_random_bytes(&skb_tx_hashrnd, 4);
-		skb_tx_hashrnd_initialized = 1;
-	}
-
 	if (skb_rx_queue_recorded(skb)) {
 		hash = skb_get_rx_queue(skb);
 	} else if (skb->sk && skb->sk->sk_hash) {
@@ -5291,6 +5285,14 @@ out:
 
 subsys_initcall(net_dev_init);
 
+static int __init initialize_hashrnd(void)
+{
+	get_random_bytes(&skb_tx_hashrnd, sizeof(skb_tx_hashrnd));
+	return 0;
+}
+
+late_initcall_sync(initialize_hashrnd);
+
 EXPORT_SYMBOL(__dev_get_by_index);
 EXPORT_SYMBOL(__dev_get_by_name);
 EXPORT_SYMBOL(__dev_remove_pack);

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

* Re: [PATCH] net: Optimize skb_tx_hash() by eliminating a comparison
  2009-02-18  9:20 [PATCH] net: Optimize skb_tx_hash() by eliminating a comparison Krishna Kumar
@ 2009-02-19  1:55 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2009-02-19  1:55 UTC (permalink / raw)
  To: krikku; +Cc: netdev, krkumar2

From: Krishna Kumar <krikku@gmail.com>
Date: Wed, 18 Feb 2009 14:50:16 +0530

> Optimize skb_tx_hash() by eliminating a comparison that executes for
> every packet. skb_tx_hashrnd initialization is moved to a later part of
> the startup sequence, namely after the "random" driver is initialized.
> 
> Rebooted the system three times and verified that the code generates
> different random numbers each time.
> 
> Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>

Applied to net-next-2.6, thank you!

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

end of thread, other threads:[~2009-02-19  1:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-18  9:20 [PATCH] net: Optimize skb_tx_hash() by eliminating a comparison Krishna Kumar
2009-02-19  1:55 ` David 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).