netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] macvlan: slight optimization for fast path
@ 2014-05-27 10:53 Ding Tianhong
  2014-05-27 10:53 ` [PATCH net-next 1/2] macvlan: slight optimization for passthru mode Ding Tianhong
  2014-05-27 10:53 ` [PATCH net-next 2/2] macvlan: slight optimization for macvlan_handle_frame Ding Tianhong
  0 siblings, 2 replies; 6+ messages in thread
From: Ding Tianhong @ 2014-05-27 10:53 UTC (permalink / raw)
  To: kaber, davem; +Cc: netdev

Ding Tianhong (2):
  macvlan: slight optimization for passthru mode
  macvlan: slight optimization for macvlan_handle_frame

 drivers/net/macvlan.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

-- 
1.8.0

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

* [PATCH net-next 1/2] macvlan: slight optimization for passthru mode
  2014-05-27 10:53 [PATCH net-next 0/2] macvlan: slight optimization for fast path Ding Tianhong
@ 2014-05-27 10:53 ` Ding Tianhong
  2014-05-28 16:55   ` Vlad Yasevich
  2014-05-27 10:53 ` [PATCH net-next 2/2] macvlan: slight optimization for macvlan_handle_frame Ding Tianhong
  1 sibling, 1 reply; 6+ messages in thread
From: Ding Tianhong @ 2014-05-27 10:53 UTC (permalink / raw)
  To: kaber, davem; +Cc: netdev

When the maclvan is in passthru mode, there should be one(and only one)
macvlan dev, so no need to check the vlan point, remove the judgement and
the redundant variables.

Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
---
 drivers/net/macvlan.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 55faff3..c9ada17 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -274,7 +274,6 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
 	const struct ethhdr *eth = eth_hdr(skb);
 	const struct macvlan_dev *vlan;
 	const struct macvlan_dev *src;
-	struct net_device *dev;
 	unsigned int len = 0;
 	int ret = NET_RX_DROP;
 
@@ -300,16 +299,16 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
 		return RX_HANDLER_PASS;
 	}
 
-	if (port->passthru)
+	if (port->passthru) {
 		vlan = list_first_or_null_rcu(&port->vlans,
 					      struct macvlan_dev, list);
-	else
+	} else {
 		vlan = macvlan_hash_lookup(port, eth->h_dest);
-	if (vlan == NULL)
-		return RX_HANDLER_PASS;
+		if (vlan == NULL)
+			return RX_HANDLER_PASS;
+	}
 
-	dev = vlan->dev;
-	if (unlikely(!(dev->flags & IFF_UP))) {
+	if (unlikely(!(vlan->dev->flags & IFF_UP))) {
 		kfree_skb(skb);
 		return RX_HANDLER_CONSUMED;
 	}
@@ -318,7 +317,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
 	if (!skb)
 		goto out;
 
-	skb->dev = dev;
+	skb->dev = vlan->dev;
 	skb->pkt_type = PACKET_HOST;
 
 	ret = netif_rx(skb);
-- 
1.8.0

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

* [PATCH net-next 2/2] macvlan: slight optimization for macvlan_handle_frame
  2014-05-27 10:53 [PATCH net-next 0/2] macvlan: slight optimization for fast path Ding Tianhong
  2014-05-27 10:53 ` [PATCH net-next 1/2] macvlan: slight optimization for passthru mode Ding Tianhong
@ 2014-05-27 10:53 ` Ding Tianhong
  2014-05-27 16:58   ` Stephen Hemminger
  1 sibling, 1 reply; 6+ messages in thread
From: Ding Tianhong @ 2014-05-27 10:53 UTC (permalink / raw)
  To: kaber, davem; +Cc: netdev

Add unlikely() micro to the unlikely conditions in the macvlan_handle_frame
for slight optimization.

Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
---
 drivers/net/macvlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index c9ada17..88694d5 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -314,7 +314,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
 	}
 	len = skb->len + ETH_HLEN;
 	skb = skb_share_check(skb, GFP_ATOMIC);
-	if (!skb)
+	if (unlikely(!skb))
 		goto out;
 
 	skb->dev = vlan->dev;
-- 
1.8.0

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

* Re: [PATCH net-next 2/2] macvlan: slight optimization for macvlan_handle_frame
  2014-05-27 10:53 ` [PATCH net-next 2/2] macvlan: slight optimization for macvlan_handle_frame Ding Tianhong
@ 2014-05-27 16:58   ` Stephen Hemminger
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2014-05-27 16:58 UTC (permalink / raw)
  To: Ding Tianhong; +Cc: kaber, davem, netdev

On Tue, 27 May 2014 18:53:16 +0800
Ding Tianhong <dingtianhong@huawei.com> wrote:

> Add unlikely() micro to the unlikely conditions in the macvlan_handle_frame
> for slight optimization.
> 
> Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>

Unnecessary, a goto is equivalent to unlikely

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

* Re: [PATCH net-next 1/2] macvlan: slight optimization for passthru mode
  2014-05-27 10:53 ` [PATCH net-next 1/2] macvlan: slight optimization for passthru mode Ding Tianhong
@ 2014-05-28 16:55   ` Vlad Yasevich
  2014-05-29  4:16     ` Ding Tianhong
  0 siblings, 1 reply; 6+ messages in thread
From: Vlad Yasevich @ 2014-05-28 16:55 UTC (permalink / raw)
  To: Ding Tianhong, kaber, davem; +Cc: netdev

On 05/27/2014 06:53 AM, Ding Tianhong wrote:
> When the maclvan is in passthru mode, there should be one(and only one)
> macvlan dev, so no need to check the vlan point, remove the judgement and
> the redundant variables.
> 
> Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
> ---
>  drivers/net/macvlan.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
> index 55faff3..c9ada17 100644
> --- a/drivers/net/macvlan.c
> +++ b/drivers/net/macvlan.c
> @@ -274,7 +274,6 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
>  	const struct ethhdr *eth = eth_hdr(skb);
>  	const struct macvlan_dev *vlan;
>  	const struct macvlan_dev *src;
> -	struct net_device *dev;
>  	unsigned int len = 0;
>  	int ret = NET_RX_DROP;
>  
> @@ -300,16 +299,16 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
>  		return RX_HANDLER_PASS;
>  	}
>  
> -	if (port->passthru)
> +	if (port->passthru) {
>  		vlan = list_first_or_null_rcu(&port->vlans,
>  					      struct macvlan_dev, list);
> -	else
> +	} else {
>  		vlan = macvlan_hash_lookup(port, eth->h_dest);
> -	if (vlan == NULL)
> -		return RX_HANDLER_PASS;
> +		if (vlan == NULL)
> +			return RX_HANDLER_PASS;
> +	}
>  

I don't think you can do that.  del_link() happens before ndo_uninit(),
and we unregister the rx_handler in ndo_uninit().  As such it is
possible to enter the rx_handler while the ports->vlans is empty.

-vlad

> -	dev = vlan->dev;
> -	if (unlikely(!(dev->flags & IFF_UP))) {
> +	if (unlikely(!(vlan->dev->flags & IFF_UP))) {
>  		kfree_skb(skb);
>  		return RX_HANDLER_CONSUMED;
>  	}
> @@ -318,7 +317,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
>  	if (!skb)
>  		goto out;
>  
> -	skb->dev = dev;
> +	skb->dev = vlan->dev;
>  	skb->pkt_type = PACKET_HOST;
>  
>  	ret = netif_rx(skb);
> 

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

* Re: [PATCH net-next 1/2] macvlan: slight optimization for passthru mode
  2014-05-28 16:55   ` Vlad Yasevich
@ 2014-05-29  4:16     ` Ding Tianhong
  0 siblings, 0 replies; 6+ messages in thread
From: Ding Tianhong @ 2014-05-29  4:16 UTC (permalink / raw)
  To: Vlad Yasevich, kaber, davem; +Cc: netdev

On 2014/5/29 0:55, Vlad Yasevich wrote:
> On 05/27/2014 06:53 AM, Ding Tianhong wrote:
>> When the maclvan is in passthru mode, there should be one(and only one)
>> macvlan dev, so no need to check the vlan point, remove the judgement and
>> the redundant variables.
>>
>> Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
>> ---
>>  drivers/net/macvlan.c | 15 +++++++--------
>>  1 file changed, 7 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
>> index 55faff3..c9ada17 100644
>> --- a/drivers/net/macvlan.c
>> +++ b/drivers/net/macvlan.c
>> @@ -274,7 +274,6 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
>>  	const struct ethhdr *eth = eth_hdr(skb);
>>  	const struct macvlan_dev *vlan;
>>  	const struct macvlan_dev *src;
>> -	struct net_device *dev;
>>  	unsigned int len = 0;
>>  	int ret = NET_RX_DROP;
>>  
>> @@ -300,16 +299,16 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
>>  		return RX_HANDLER_PASS;
>>  	}
>>  
>> -	if (port->passthru)
>> +	if (port->passthru) {
>>  		vlan = list_first_or_null_rcu(&port->vlans,
>>  					      struct macvlan_dev, list);
>> -	else
>> +	} else {
>>  		vlan = macvlan_hash_lookup(port, eth->h_dest);
>> -	if (vlan == NULL)
>> -		return RX_HANDLER_PASS;
>> +		if (vlan == NULL)
>> +			return RX_HANDLER_PASS;
>> +	}
>>  
> 
> I don't think you can do that.  del_link() happens before ndo_uninit(),
> and we unregister the rx_handler in ndo_uninit().  As such it is
> possible to enter the rx_handler while the ports->vlans is empty.
> 
> -vlad

Yes, I miss it, the ports->vlans is already empty when unregister rx_handler, thanks.

Ding

> 
>> -	dev = vlan->dev;
>> -	if (unlikely(!(dev->flags & IFF_UP))) {
>> +	if (unlikely(!(vlan->dev->flags & IFF_UP))) {
>>  		kfree_skb(skb);
>>  		return RX_HANDLER_CONSUMED;
>>  	}
>> @@ -318,7 +317,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
>>  	if (!skb)
>>  		goto out;
>>  
>> -	skb->dev = dev;
>> +	skb->dev = vlan->dev;
>>  	skb->pkt_type = PACKET_HOST;
>>  
>>  	ret = netif_rx(skb);
>>
> 
> 
> 

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

end of thread, other threads:[~2014-05-29  4:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-27 10:53 [PATCH net-next 0/2] macvlan: slight optimization for fast path Ding Tianhong
2014-05-27 10:53 ` [PATCH net-next 1/2] macvlan: slight optimization for passthru mode Ding Tianhong
2014-05-28 16:55   ` Vlad Yasevich
2014-05-29  4:16     ` Ding Tianhong
2014-05-27 10:53 ` [PATCH net-next 2/2] macvlan: slight optimization for macvlan_handle_frame Ding Tianhong
2014-05-27 16:58   ` Stephen Hemminger

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).