diff mbox series

[net-next,1/2] net: tap: replay while() loop with % operator in tap_get_queue()

Message ID 1512998801-17852-1-git-send-email-cugyly@163.com
State Changes Requested, archived
Delegated to: David Miller
Headers show
Series net: tap: two minor issue | expand

Commit Message

yuan linyu Dec. 11, 2017, 1:26 p.m. UTC
From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>

Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
---
 drivers/net/tap.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Stephen Hemminger Dec. 11, 2017, 4:58 p.m. UTC | #1
On Mon, 11 Dec 2017 21:26:41 +0800
yuan linyu <cugyly@163.com> wrote:

> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> 
> Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> ---
>  drivers/net/tap.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/net/tap.c b/drivers/net/tap.c
> index 0a886fda..78900a0 100644
> --- a/drivers/net/tap.c
> +++ b/drivers/net/tap.c
> @@ -275,11 +275,7 @@ static struct tap_queue *tap_get_queue(struct tap_dev *tap,
>  
>  	if (likely(skb_rx_queue_recorded(skb))) {
>  		rxq = skb_get_rx_queue(skb);
> -
> -		while (unlikely(rxq >= numvtaps))
> -			rxq -= numvtaps;
> -
> -		queue = rcu_dereference(tap->taps[rxq]);
> +		queue = rcu_dereference(tap->taps[rxq % numvtaps]);
>  		goto out;
>  	}
>  

Modulus is slower than the loop.
David Miller Dec. 11, 2017, 5:02 p.m. UTC | #2
From: Stephen Hemminger <stephen@networkplumber.org>
Date: Mon, 11 Dec 2017 08:58:11 -0800

> On Mon, 11 Dec 2017 21:26:41 +0800
> yuan linyu <cugyly@163.com> wrote:
> 
>> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
>> 
>> Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
>> ---
>>  drivers/net/tap.c | 6 +-----
>>  1 file changed, 1 insertion(+), 5 deletions(-)
>> 
>> diff --git a/drivers/net/tap.c b/drivers/net/tap.c
>> index 0a886fda..78900a0 100644
>> --- a/drivers/net/tap.c
>> +++ b/drivers/net/tap.c
>> @@ -275,11 +275,7 @@ static struct tap_queue *tap_get_queue(struct tap_dev *tap,
>>  
>>  	if (likely(skb_rx_queue_recorded(skb))) {
>>  		rxq = skb_get_rx_queue(skb);
>> -
>> -		while (unlikely(rxq >= numvtaps))
>> -			rxq -= numvtaps;
>> -
>> -		queue = rcu_dereference(tap->taps[rxq]);
>> +		queue = rcu_dereference(tap->taps[rxq % numvtaps]);
>>  		goto out;
>>  	}
>>  
> 
> Modulus is slower than the loop.

Agreed, the loop is there intentionally.  We do this in other areas of
the kernel as well.
diff mbox series

Patch

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 0a886fda..78900a0 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -275,11 +275,7 @@  static struct tap_queue *tap_get_queue(struct tap_dev *tap,
 
 	if (likely(skb_rx_queue_recorded(skb))) {
 		rxq = skb_get_rx_queue(skb);
-
-		while (unlikely(rxq >= numvtaps))
-			rxq -= numvtaps;
-
-		queue = rcu_dereference(tap->taps[rxq]);
+		queue = rcu_dereference(tap->taps[rxq % numvtaps]);
 		goto out;
 	}