]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/vhost/net.c
vhost: introduce vhost_exceeds_weight()
[mirror_ubuntu-bionic-kernel.git] / drivers / vhost / net.c
index 24314135636d9545a182822e74e846a7b5e3d0e4..7c0fcda639959ec11046f8f8c09881055794d881 100644 (file)
@@ -450,12 +450,6 @@ static bool vhost_exceeds_maxpend(struct vhost_net *net)
               min_t(unsigned int, VHOST_MAX_PEND, vq->num >> 2);
 }
 
-static bool vhost_exceeds_weight(int pkts, int total_len)
-{
-       return total_len >= VHOST_NET_WEIGHT ||
-              pkts >= VHOST_NET_PKT_WEIGHT;
-}
-
 /* Expects to be always run from workqueue - which acts as
  * read-size critical section for our kind of RCU. */
 static void handle_tx(struct vhost_net *net)
@@ -588,10 +582,9 @@ static void handle_tx(struct vhost_net *net)
                else
                        vhost_zerocopy_signal_used(net, vq);
                vhost_net_tx_packet(net);
-               if (unlikely(vhost_exceeds_weight(++sent_pkts, total_len))) {
-                       vhost_poll_queue(&vq->poll);
+               if (unlikely(vhost_exceeds_weight(vq, ++sent_pkts,
+                                                 total_len)))
                        break;
-               }
        }
 out:
        mutex_unlock(&vq->mutex);
@@ -872,10 +865,8 @@ static void handle_rx(struct vhost_net *net)
                        vhost_log_write(vq, vq_log, log, vhost_len,
                                        vq->iov, in);
                total_len += vhost_len;
-               if (unlikely(vhost_exceeds_weight(++recv_pkts, total_len))) {
-                       vhost_poll_queue(&vq->poll);
+               if (unlikely(vhost_exceeds_weight(vq, ++recv_pkts, total_len)))
                        goto out;
-               }
        }
        vhost_net_enable_vq(net, vq);
 out:
@@ -954,7 +945,8 @@ static int vhost_net_open(struct inode *inode, struct file *f)
                n->vqs[i].sock_hlen = 0;
                vhost_net_buf_init(&n->vqs[i].rxq);
        }
-       vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX);
+       vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX,
+                      VHOST_NET_WEIGHT, VHOST_NET_PKT_WEIGHT);
 
        vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, POLLOUT, dev);
        vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, POLLIN, dev);