All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: core: improve the tx_hash calculating
@ 2018-05-31 10:14 Tonghao Zhang
  2018-06-01  8:58 ` Sergei Shtylyov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tonghao Zhang @ 2018-05-31 10:14 UTC (permalink / raw)
  To: netdev; +Cc: Tonghao Zhang

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 <xiangxia.m.yue@gmail.com>
---
 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) {
-- 
1.8.3.1

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

* Re: [PATCH] net: core: improve the tx_hash calculating
  2018-05-31 10:14 [PATCH] net: core: improve the tx_hash calculating Tonghao Zhang
@ 2018-06-01  8:58 ` Sergei Shtylyov
  2018-06-01  9:54 ` Eric Dumazet
  2018-06-01 17:27 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2018-06-01  8:58 UTC (permalink / raw)
  To: Tonghao Zhang, netdev

Hello!

On 5/31/2018 1:14 PM, 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 <xiangxia.m.yue@gmail.com>
> ---
>   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. */

    In the networking code, multiline comments should look like:

/* bla
  * bla
  */

> +		return skb_get_rx_queue(skb) % qcount;
>   	}
>   
>   	if (dev->num_tc) {

MBR, Sergei

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

* Re: [PATCH] net: core: improve the tx_hash calculating
  2018-05-31 10:14 [PATCH] net: core: improve the tx_hash calculating Tonghao Zhang
  2018-06-01  8:58 ` Sergei Shtylyov
@ 2018-06-01  9:54 ` Eric Dumazet
  2018-06-01 17:27 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2018-06-01  9:54 UTC (permalink / raw)
  To: Tonghao Zhang, netdev



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 <xiangxia.m.yue@gmail.com>
> ---
>  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.

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

* Re: [PATCH] net: core: improve the tx_hash calculating
  2018-05-31 10:14 [PATCH] net: core: improve the tx_hash calculating Tonghao Zhang
  2018-06-01  8:58 ` Sergei Shtylyov
  2018-06-01  9:54 ` Eric Dumazet
@ 2018-06-01 17:27 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-06-01 17:27 UTC (permalink / raw)
  To: xiangxia.m.yue; +Cc: netdev

From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Date: Thu, 31 May 2018 03:14:01 -0700

> 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 <xiangxia.m.yue@gmail.com>

The loop is there to avoid the expensive modulus operation,
not to avoid the real_num_tx_queues == 0 case.

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

end of thread, other threads:[~2018-06-01 17:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-31 10:14 [PATCH] net: core: improve the tx_hash calculating Tonghao Zhang
2018-06-01  8:58 ` Sergei Shtylyov
2018-06-01  9:54 ` Eric Dumazet
2018-06-01 17:27 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.