diff mbox

[net-next,1/3] hv_netvsc: Use per socket hash when available

Message ID 1491699241-9944-1-git-send-email-haiyangz@exchange.microsoft.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Haiyang Zhang April 9, 2017, 12:53 a.m. UTC
From: Haiyang Zhang <haiyangz@microsoft.com>

The per socket hash is set when a socket is connected. Use it, when
available, to save CPU cycles on repeatedly computing hash on the same
connection.

Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Reviewed-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

Comments

David Miller April 12, 2017, 2:12 a.m. UTC | #1
From: Haiyang Zhang <haiyangz@exchange.microsoft.com>
Date: Sat,  8 Apr 2017 17:53:59 -0700

> diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
> index f24c289..0a129cb 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c
> @@ -211,9 +211,14 @@ static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
>  	int q_idx = sk_tx_queue_get(sk);
>  
>  	if (q_idx < 0 || skb->ooo_okay || q_idx >= num_tx_queues) {
> -		u16 hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE);
> +		u16 hash;
>  		int new_idx;
>  
> +		if (sk)
> +			skb_set_hash_from_sk(skb, sk);
> +
> +		hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE);

Please do not do this.

TCP performs this operation for you for every pack it emits.

And also every socket family that uses skb_set_owner_w() either
directly or indirectly gets this done as well.

I do not want to see drivers start to get peppered with calls to this
thing.

Explain the case which is missing that matters, and we can address
that instead.

Thanks.
Haiyang Zhang April 12, 2017, 4:24 p.m. UTC | #2
> -----Original Message-----
> From: David Miller [mailto:davem@davemloft.net]
> Sent: Tuesday, April 11, 2017 10:13 PM
> To: Haiyang Zhang <haiyangz@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>
> Cc: netdev@vger.kernel.org; KY Srinivasan <kys@microsoft.com>;
> olaf@aepfle.de; vkuznets@redhat.com; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH net-next,1/3] hv_netvsc: Use per socket hash when
> available
> 
> From: Haiyang Zhang <haiyangz@exchange.microsoft.com>
> Date: Sat,  8 Apr 2017 17:53:59 -0700
> 
> > diff --git a/drivers/net/hyperv/netvsc_drv.c
> b/drivers/net/hyperv/netvsc_drv.c
> > index f24c289..0a129cb 100644
> > --- a/drivers/net/hyperv/netvsc_drv.c
> > +++ b/drivers/net/hyperv/netvsc_drv.c
> > @@ -211,9 +211,14 @@ static u16 netvsc_select_queue(struct net_device
> *ndev, struct sk_buff *skb,
> >  	int q_idx = sk_tx_queue_get(sk);
> >
> >  	if (q_idx < 0 || skb->ooo_okay || q_idx >= num_tx_queues) {
> > -		u16 hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE);
> > +		u16 hash;
> >  		int new_idx;
> >
> > +		if (sk)
> > +			skb_set_hash_from_sk(skb, sk);
> > +
> > +		hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE);
> 
> Please do not do this.
> 
> TCP performs this operation for you for every pack it emits.
> 
> And also every socket family that uses skb_set_owner_w() either
> directly or indirectly gets this done as well.
> 
> I do not want to see drivers start to get peppered with calls to this
> thing.
> 
> Explain the case which is missing that matters, and we can address
> that instead.
> 
> Thanks.

Thanks for pointing this out. I did some tests, the skb->hash is indeed
set to the sk->sk_txhash by upper layer. I will remove this patch, and
re-submit other patches.

Thanks,
- Haiyang
diff mbox

Patch

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index f24c289..0a129cb 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -211,9 +211,14 @@  static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
 	int q_idx = sk_tx_queue_get(sk);
 
 	if (q_idx < 0 || skb->ooo_okay || q_idx >= num_tx_queues) {
-		u16 hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE);
+		u16 hash;
 		int new_idx;
 
+		if (sk)
+			skb_set_hash_from_sk(skb, sk);
+
+		hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE);
+
 		new_idx = net_device_ctx->tx_send_table[hash] % num_tx_queues;
 
 		if (q_idx != new_idx && sk &&