hv_netvsc: Set vRSS with num_chn in RNDIS filter
Subsystems (3)
PATCH 1/2 hv_netvsc: Set vRSS with num_chn in RNDIS filter
Uses device_info->num_chn to pass user provided number of vRSS queues (from ethtool --set-channels) to rndis_filter_device_add. If nonzero and less than the maximum, set net_device->num_chn to the given value; else default to prior algorithm.
Always initialize struct device_info to 0, otherwise not all its fields are guaranteed to be 0, which is necessary when checking if num_chn has been purposefully set.
--- drivers/net/hyperv/hyperv_net.h | 1 + drivers/net/hyperv/netvsc_drv.c | 3 +++ drivers/net/hyperv/rndis_filter.c | 7 ++++++- 3 files changed, 10 insertions(+), 1 deletion(-)
drivers/net/hyperv/hyperv_net.h +1 -0
@@ -162,6 +162,7 @@ struct netvsc_device_info {bool link_state;/* 0 - link up, 1 - link down */ int ring_size;u32 max_num_vrss_chns; +u32 num_chn; };enum rndis_device_state {
drivers/net/hyperv/netvsc_drv.c +3 -0
@@ -799,6 +799,8 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu) ndevctx->device_ctx = hdev;hv_set_drvdata (hdev, ndev); + +memset (&device_info,0 ,sizeof (device_info)); device_info.ring_size = ring_size; device_info.max_num_vrss_chns = max_num_vrss_chns;rndis_filter_device_add (hdev, &device_info);
@@ -1022,6 +1024,7 @@ static int netvsc_probe(struct hv_device *dev, net->needed_headroom = max_needed_headroom;/* Notify the netvsc driver of the new device */ +memset (&device_info,0 ,sizeof (device_info)); device_info.ring_size = ring_size; device_info.max_num_vrss_chns = max_num_vrss_chns; ret =rndis_filter_device_add (dev, &device_info);
drivers/net/hyperv/rndis_filter.c +6 -1
@@ -1125,7 +1125,12 @@ int rndis_filter_device_add(struct hv_device *dev,*/ node_cpu_mask =cpumask_of_node (cpu_to_node (dev->channel->target_cpu)); num_possible_rss_qs =cpumask_weight (node_cpu_mask); - net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); + +/* We will use the given number of channels if available. */ +if (device_info->num_chn && device_info->num_chn < net_device->max_chn) + net_device->num_chn = device_info->num_chn; +else + net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); num_rss_qs = net_device->num_chn -1 ; net_device->num_sc_offered = num_rss_qs;
Signature · 1 line
2.4.2
PATCH 2/2 hv_netvsc: Implement set_channels ethtool op
This enables the use of ethtool --set-channels devname combined N to change the number of vRSS queues. Separate rx, tx, and other parameters are not supported. The maximum is rsscap.num_recv_que. It passes the given value to rndis_filter_device_add through the device_info->num_chn field.
If the procedure fails, it attempts to recover to the prior state. If the recovery fails, it logs an error and aborts.
Current num_chn is saved and restored when changing the MTU.
--- drivers/net/hyperv/netvsc_drv.c | 97 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)
drivers/net/hyperv/netvsc_drv.c +97 -0
@@ -770,6 +770,101 @@ static void netvsc_get_channels(struct net_device *net, } } +static int netvsc_set_channels (struct net_device *net, +struct ethtool_channels *channels) +{ +struct net_device_context *net_device_ctx =netdev_priv (net); +struct hv_device *dev = net_device_ctx->device_ctx; +struct netvsc_device *nvdev =hv_get_drvdata (dev); +struct netvsc_device_info device_info; +const u32 num_chn = nvdev->num_chn; +const u32 max_chn =min_t (u32, nvdev->max_chn,num_online_cpus ()); +int ret =0 ; +bool recovering = false; + +if (!nvdev || nvdev->destroy) +return -ENODEV ; + +if (nvdev->nvsp_version <NVSP_PROTOCOL_VERSION_5 ) { +pr_info ("vRSS unsupported before NVSP Version 5\n" ); +return -EINVAL ; + } + +/* We do not support rx, tx, or other */ +if (!channels || + channels->rx_count || + channels->tx_count || + channels->other_count || + (channels->combined_count <1 )) +return -EINVAL ; + +if (channels->combined_count > max_chn) { +pr_info ("combined channels too high, using %d\n" , max_chn); + channels->combined_count = max_chn; + } + + ret =netvsc_close (net); +if (ret) + goto out; + + do_set: + nvdev->start_remove = true; +rndis_filter_device_remove (dev); + + nvdev->num_chn = channels->combined_count; + + net_device_ctx->device_ctx = dev; +hv_set_drvdata (dev, net); + +memset (&device_info,0 ,sizeof (device_info)); + device_info.num_chn = nvdev->num_chn;/* passed to RNDIS */ + device_info.ring_size = ring_size; + device_info.max_num_vrss_chns = max_num_vrss_chns; + + ret =rndis_filter_device_add (dev, &device_info); +if (ret) { +if (recovering) { +netdev_err (net,"unable to add netvsc device (ret %d)\n" , ret); +return ret; + } + goto recover; + } + + nvdev =hv_get_drvdata (dev); + + ret =netif_set_real_num_tx_queues (net, nvdev->num_chn); +if (ret) { +if (recovering) { +netdev_err (net,"could not set tx queue count (ret %d)\n" , ret); +return ret; + } + goto recover; + } + + ret =netif_set_real_num_rx_queues (net, nvdev->num_chn); +if (ret) { +if (recovering) { +netdev_err (net,"could not set rx queue count (ret %d)\n" , ret); +return ret; + } + goto recover; + } + + out: +netvsc_open (net); + +return ret; + + recover: +/* If the above failed, we attempt to recover through the same +* process but with the original number of channels. +*/ +netdev_err (net,"could not set channels, recovering\n" ); + recovering = true; + channels->combined_count = num_chn; + goto do_set; +} +static int netvsc_change_mtu (struct net_device *ndev,int mtu) {struct net_device_context *ndevctx =netdev_priv (ndev);
@@ -802,6 +897,7 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)memset (&device_info,0 ,sizeof (device_info)); device_info.ring_size = ring_size; + device_info.num_chn = nvdev->num_chn; device_info.max_num_vrss_chns = max_num_vrss_chns;rndis_filter_device_add (hdev, &device_info);
@@ -891,6 +987,7 @@ static const struct ethtool_ops ethtool_ops = { .get_drvinfo = netvsc_get_drvinfo, .get_link = ethtool_op_get_link, .get_channels = netvsc_get_channels, + .set_channels = netvsc_set_channels, };static const struct net_device_ops device_ops = {
Signature · 1 line
2.4.2
Quoted 17 lines
-----Original Message-----
From: Andy Schwartzmeyer
Sent: Tuesday, August 11, 2015 8:15 PM
To: Haiyang Zhang <[email protected]>
Cc: KY Srinivasan <[email protected]>; Andy Schwartzmeyer <[email protected]>; [email protected]; linux- [email protected]
Subject: [PATCH net-next 1/2]hv_netvsc: Set vRSS withnum_chnin RNDIS filterUses
device_info->num_chnto pass user provided number of vRSS queues (from ethtool --set-channels) torndis_filter_device_add. If nonzero and less than the maximum, setnet_device->num_chnto the given value; else default to prior algorithm.
Quoted 5 lines
Always initialize struct
device_infoto 0, otherwise not all its fields are guaranteed to be 0, which is necessary when checking ifnum_chnhas been purposefully set.Signed-off-by Andrew Schwartzmeyer <[email protected]>
Thank you!
RE: [PATCH net-next 2/2] hv_netvsc: Implement set_channels ethtool op
In reply to Andrew SchwartzmeyerQuoted 18 lines
-----Original Message-----
From: Andy Schwartzmeyer
Sent: Tuesday, August 11, 2015 8:15 PM
To: Haiyang Zhang <[email protected]>
Cc: KY Srinivasan <[email protected]>; Andy Schwartzmeyer <[email protected]>; [email protected]; linux- [email protected]
Subject: [PATCH net-next 2/2]hv_netvsc: Implementset_channelsethtool opThis enables the use of ethtool --set-channels devname combined N to change the number of vRSS queues. Separate rx, tx, and other parameters are not supported. The maximum is rsscap.num_recv_que. It passes the given value to
rndis_filter_device_addthrough thedevice_info->num_chnfield.
Quoted 6 lines
If the procedure fails, it attempts to recover to the prior state. If the recovery fails, it logs an error and aborts.
Current
num_chnis saved and restored when changing the MTU.Signed-off-by Andrew Schwartzmeyer <[email protected]>
Thank you!
From: Andrew Schwartzmeyer <[email protected]>
Date: Tue, 11 Aug 2015 17:14:31 -0700
Quoted 10 lines
Uses
device_info->num_chnto pass user provided number of vRSS queues (from ethtool --set-channels) torndis_filter_device_add. If nonzero and less than the maximum, setnet_device->num_chnto the given value; else default to prior algorithm.Always initialize struct
device_infoto 0, otherwise not all its fields are guaranteed to be 0, which is necessary when checking ifnum_chnhas been purposefully set.Signed-off-by Andrew Schwartzmeyer <[email protected]>
Applied.
Re: [PATCH net-next 2/2] hv_netvsc: Implement set_channels ethtool op
In reply to Andrew SchwartzmeyerFrom: Andrew Schwartzmeyer <[email protected]>
Date: Tue, 11 Aug 2015 17:14:32 -0700
Quoted 6 lines
This enables the use of ethtool --set-channels devname combined N to change the number of vRSS queues. Separate rx, tx, and other parameters are not supported. The maximum is rsscap.num_recv_que. It passes the given value to
rndis_filter_device_addthrough thedevice_info->num_chnfield.
Quoted 6 lines
If the procedure fails, it attempts to recover to the prior state. If the recovery fails, it logs an error and aborts.
Current
num_chnis saved and restored when changing the MTU.Signed-off-by Andrew Schwartzmeyer <[email protected]>
Applied.