netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] net: tap: replay while() loop with % operator in tap_get_queue()
@ 2017-12-11 13:26 yuan linyu
  2017-12-11 16:58 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: yuan linyu @ 2017-12-11 13:26 UTC (permalink / raw)
  To: netdev; +Cc: David S . Miller, yuan linyu

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;
 	}
 
-- 
2.7.4

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

* Re: [PATCH net-next 1/2] net: tap: replay while() loop with % operator in tap_get_queue()
  2017-12-11 13:26 [PATCH net-next 1/2] net: tap: replay while() loop with % operator in tap_get_queue() yuan linyu
@ 2017-12-11 16:58 ` Stephen Hemminger
  2017-12-11 17:02   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2017-12-11 16:58 UTC (permalink / raw)
  To: yuan linyu; +Cc: netdev, David S . Miller, yuan linyu

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.

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

* Re: [PATCH net-next 1/2] net: tap: replay while() loop with % operator in tap_get_queue()
  2017-12-11 16:58 ` Stephen Hemminger
@ 2017-12-11 17:02   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2017-12-11 17:02 UTC (permalink / raw)
  To: stephen; +Cc: cugyly, netdev, Linyu.Yuan

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.

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

end of thread, other threads:[~2017-12-11 17:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-11 13:26 [PATCH net-next 1/2] net: tap: replay while() loop with % operator in tap_get_queue() yuan linyu
2017-12-11 16:58 ` Stephen Hemminger
2017-12-11 17:02   ` 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).