Skip to content

Commit 8de4b2f

Browse files
Wanlong Gaodavem330
authored andcommitted
virtio-net: reset virtqueue affinity when doing cpu hotplug
Add a cpu notifier to virtio-net, so that we can reset the virtqueue affinity if the cpu hotplug happens. It improve the performance through enabling or disabling the virtqueue affinity after doing cpu hotplug. Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Eric Dumazet <erdnetdev@gmail.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: virtualization@lists.linux-foundation.org Cc: netdev@vger.kernel.org Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8898c21 commit 8de4b2f

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎drivers/net/virtio_net.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/scatterlist.h>
2727
#include <linux/if_vlan.h>
2828
#include <linux/slab.h>
29+
#include <linux/cpu.h>
2930

3031
static int napi_weight = 128;
3132
module_param(napi_weight, int, 0444);
@@ -126,6 +127,9 @@ struct virtnet_info {
126127

127128
/* Per-cpu variable to show the mapping from CPU to virtqueue */
128129
int __percpu *vq_index;
130+
131+
/* CPU hot plug notifier */
132+
struct notifier_block nb;
129133
};
130134

131135
struct skb_vnet_hdr {
@@ -1067,6 +1071,26 @@ static void virtnet_set_affinity(struct virtnet_info *vi)
10671071
vi->affinity_hint_set = true;
10681072
}
10691073

1074+
static int virtnet_cpu_callback(struct notifier_block *nfb,
1075+
unsigned long action, void *hcpu)
1076+
{
1077+
struct virtnet_info *vi = container_of(nfb, struct virtnet_info, nb);
1078+
1079+
switch(action & ~CPU_TASKS_FROZEN) {
1080+
case CPU_ONLINE:
1081+
case CPU_DOWN_FAILED:
1082+
case CPU_DEAD:
1083+
virtnet_set_affinity(vi);
1084+
break;
1085+
case CPU_DOWN_PREPARE:
1086+
virtnet_clean_affinity(vi, (long)hcpu);
1087+
break;
1088+
default:
1089+
break;
1090+
}
1091+
return NOTIFY_OK;
1092+
}
1093+
10701094
static void virtnet_get_ringparam(struct net_device *dev,
10711095
struct ethtool_ringparam *ring)
10721096
{
@@ -1541,6 +1565,13 @@ static int virtnet_probe(struct virtio_device *vdev)
15411565
}
15421566
}
15431567

1568+
vi->nb.notifier_call = &virtnet_cpu_callback;
1569+
err = register_hotcpu_notifier(&vi->nb);
1570+
if (err) {
1571+
pr_debug("virtio_net: registering cpu notifier failed\n");
1572+
goto free_recv_bufs;
1573+
}
1574+
15441575
/* Assume link up if device can't report link status,
15451576
otherwise get link status from config. */
15461577
if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) {
@@ -1587,6 +1618,8 @@ static void virtnet_remove(struct virtio_device *vdev)
15871618
{
15881619
struct virtnet_info *vi = vdev->priv;
15891620

1621+
unregister_hotcpu_notifier(&vi->nb);
1622+
15901623
/* Prevent config work handler from accessing the device. */
15911624
mutex_lock(&vi->config_lock);
15921625
vi->config_enable = false;

0 commit comments

Comments
 (0)