From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Dumazet Subject: Re: [PATCH] net: core: improve the tx_hash calculating Date: Fri, 1 Jun 2018 05:54:24 -0400 Message-ID: <37887992-72ad-7125-d58e-b411a551b9ec@gmail.com> References: <1527761641-22034-1-git-send-email-xiangxia.m.yue@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit To: Tonghao Zhang , netdev@vger.kernel.org Return-path: Received: from mail-qk0-f195.google.com ([209.85.220.195]:44807 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750964AbeFAJy3 (ORCPT ); Fri, 1 Jun 2018 05:54:29 -0400 Received: by mail-qk0-f195.google.com with SMTP id 185-v6so19400673qkk.11 for ; Fri, 01 Jun 2018 02:54:29 -0700 (PDT) In-Reply-To: <1527761641-22034-1-git-send-email-xiangxia.m.yue@gmail.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 05/31/2018 06:14 AM, Tonghao Zhang wrote: > Use the % instead of while, and it may simple code and improve > the calculating. The real_num_tx_queues has been checked when > allocating and setting it. > > Signed-off-by: Tonghao Zhang > --- > net/core/dev.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/net/core/dev.c b/net/core/dev.c > index 1844d9b..edc5b75 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -2617,15 +2617,13 @@ void netif_device_attach(struct net_device *dev) > */ > static u16 skb_tx_hash(const struct net_device *dev, struct sk_buff *skb) > { > - u32 hash; > u16 qoffset = 0; > u16 qcount = dev->real_num_tx_queues; > > if (skb_rx_queue_recorded(skb)) { > - hash = skb_get_rx_queue(skb); > - while (unlikely(hash >= qcount)) > - hash -= qcount; > - return hash; > + /* When setting the real_num_tx_queues, we make sure > + * real_num_tx_queues != 0. */ > + return skb_get_rx_queue(skb) % qcount; > } > > if (dev->num_tc) { > This patch is adding a divide. We do not need it most of the time.