]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/blobdiff - drivers/vhost/vhost.c
vhost: introduce vhost_exceeds_weight()
[mirror_ubuntu-disco-kernel.git] / drivers / vhost / vhost.c
index 674cfc5a408486b87d4438b68325bb4b0da5774c..b8a5236ec16365d4ecaf0df5da3fe19f763838e8 100644 (file)
@@ -413,8 +413,24 @@ static void vhost_dev_free_iovecs(struct vhost_dev *dev)
                vhost_vq_free_iovecs(dev->vqs[i]);
 }
 
+bool vhost_exceeds_weight(struct vhost_virtqueue *vq,
+                         int pkts, int total_len)
+{
+       struct vhost_dev *dev = vq->dev;
+
+       if ((dev->byte_weight && total_len >= dev->byte_weight) ||
+           pkts >= dev->weight) {
+               vhost_poll_queue(&vq->poll);
+               return true;
+       }
+
+       return false;
+}
+EXPORT_SYMBOL_GPL(vhost_exceeds_weight);
+
 void vhost_dev_init(struct vhost_dev *dev,
-                   struct vhost_virtqueue **vqs, int nvqs, int iov_limit)
+                   struct vhost_virtqueue **vqs, int nvqs,
+                   int iov_limit, int weight, int byte_weight)
 {
        struct vhost_virtqueue *vq;
        int i;
@@ -428,6 +444,8 @@ void vhost_dev_init(struct vhost_dev *dev,
        dev->mm = NULL;
        dev->worker = NULL;
        dev->iov_limit = iov_limit;
+       dev->weight = weight;
+       dev->byte_weight = byte_weight;
        init_llist_head(&dev->work_list);
        init_waitqueue_head(&dev->wait);
        INIT_LIST_HEAD(&dev->read_list);