From patchwork Sun May 3 21:44:18 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Miller X-Patchwork-Id: 26820 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 09B99B6F35 for ; Mon, 4 May 2009 07:45:53 +1000 (EST) Received: by ozlabs.org (Postfix) id EF464DDE31; Mon, 4 May 2009 07:45:52 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 9396EDDE1F for ; Mon, 4 May 2009 07:45:52 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751481AbZECVoY (ORCPT ); Sun, 3 May 2009 17:44:24 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751467AbZECVoY (ORCPT ); Sun, 3 May 2009 17:44:24 -0400 Received: from 74-93-104-97-Washington.hfc.comcastbusiness.net ([74.93.104.97]:59303 "EHLO sunset.davemloft.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750847AbZECVoX (ORCPT ); Sun, 3 May 2009 17:44:23 -0400 Received: from localhost (localhost [127.0.0.1]) by sunset.davemloft.net (Postfix) with ESMTP id D227035C134; Sun, 3 May 2009 14:44:18 -0700 (PDT) Date: Sun, 03 May 2009 14:44:18 -0700 (PDT) Message-Id: <20090503.144418.255531526.davem@davemloft.net> To: dada1@cosmosbay.com Cc: andrew@whydna.net, jelaas@gmail.com, netdev@vger.kernel.org Subject: Re: [PATCH] net: skb_tx_hash() improvements From: David Miller In-Reply-To: <20090501.091747.240476627.davem@davemloft.net> References: <49FAB831.6020700@cosmosbay.com> <49FAC112.6090808@cosmosbay.com> <20090501.091747.240476627.davem@davemloft.net> X-Mailer: Mew version 6.2.51 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Miller Date: Fri, 01 May 2009 09:17:47 -0700 (PDT) > From: Eric Dumazet > Date: Fri, 01 May 2009 11:29:54 +0200 > >> - } else if (skb->sk && skb->sk->sk_hash) { >> + /* >> + * Try to avoid an expensive divide, for symmetric setups : >> + * number of tx queues of output device == >> + * number of rx queues of incoming device >> + */ >> + if (hash >= dev->real_num_tx_queues) >> + hash %= dev->real_num_tx_queues; >> + return hash; >> + } > > Subtraction in a while() loop is almost certainly a lot > faster. To move forward on this, I've commited the following to net-next-2.6, thanks! net: Avoid modulus in skb_tx_hash() for forwarding case. Based almost entirely upon a patch by Eric Dumazet. The common case is to have num-tx-queues <= num_rx_queues and even if num_tx_queues is larger it will not be significantly larger. Therefore, a subtraction loop is always going to be faster than modulus. Signed-off-by: David S. Miller --- net/core/dev.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 8144295..3c8073f 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1735,8 +1735,12 @@ u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb) { u32 hash; - if (skb_rx_queue_recorded(skb)) - return skb_get_rx_queue(skb) % dev->real_num_tx_queues; + if (skb_rx_queue_recorded(skb)) { + hash = skb_get_rx_queue(skb); + while (unlikely (hash >= dev->real_num_tx_queues)) + hash -= dev->real_num_tx_queues; + return hash; + } if (skb->sk && skb->sk->sk_hash) hash = skb->sk->sk_hash;