diff options
author | Jason Wang <jasowang@redhat.com> | 2019-05-17 00:29:49 -0400 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2019-05-27 11:08:22 -0400 |
commit | e82b9b0727ff6d665fff2d326162b460dded554d (patch) | |
tree | c88a7558ef9b90b1de6415a9cf99bb0206b71fad /drivers/vhost/vhost.c | |
parent | 6166e5330c3828699859a6ec1af21eef7c58778c (diff) |
vhost: introduce vhost_exceeds_weight()
We used to have vhost_exceeds_weight() for vhost-net to:
- prevent vhost kthread from hogging the cpu
- balance the time spent between TX and RX
This function could be useful for vsock and scsi as well. So move it
to vhost.c. Device must specify a weight which counts the number of
requests, or it can also specific a byte_weight which counts the
number of bytes that has been processed.
Signed-off-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/vhost/vhost.c')
-rw-r--r-- | drivers/vhost/vhost.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 1e3ed41ae1f3..3f3eac4bcc58 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c | |||
@@ -413,8 +413,24 @@ static void vhost_dev_free_iovecs(struct vhost_dev *dev) | |||
413 | vhost_vq_free_iovecs(dev->vqs[i]); | 413 | vhost_vq_free_iovecs(dev->vqs[i]); |
414 | } | 414 | } |
415 | 415 | ||
416 | bool vhost_exceeds_weight(struct vhost_virtqueue *vq, | ||
417 | int pkts, int total_len) | ||
418 | { | ||
419 | struct vhost_dev *dev = vq->dev; | ||
420 | |||
421 | if ((dev->byte_weight && total_len >= dev->byte_weight) || | ||
422 | pkts >= dev->weight) { | ||
423 | vhost_poll_queue(&vq->poll); | ||
424 | return true; | ||
425 | } | ||
426 | |||
427 | return false; | ||
428 | } | ||
429 | EXPORT_SYMBOL_GPL(vhost_exceeds_weight); | ||
430 | |||
416 | void vhost_dev_init(struct vhost_dev *dev, | 431 | void vhost_dev_init(struct vhost_dev *dev, |
417 | struct vhost_virtqueue **vqs, int nvqs, int iov_limit) | 432 | struct vhost_virtqueue **vqs, int nvqs, |
433 | int iov_limit, int weight, int byte_weight) | ||
418 | { | 434 | { |
419 | struct vhost_virtqueue *vq; | 435 | struct vhost_virtqueue *vq; |
420 | int i; | 436 | int i; |
@@ -428,6 +444,8 @@ void vhost_dev_init(struct vhost_dev *dev, | |||
428 | dev->mm = NULL; | 444 | dev->mm = NULL; |
429 | dev->worker = NULL; | 445 | dev->worker = NULL; |
430 | dev->iov_limit = iov_limit; | 446 | dev->iov_limit = iov_limit; |
447 | dev->weight = weight; | ||
448 | dev->byte_weight = byte_weight; | ||
431 | init_llist_head(&dev->work_list); | 449 | init_llist_head(&dev->work_list); |
432 | init_waitqueue_head(&dev->wait); | 450 | init_waitqueue_head(&dev->wait); |
433 | INIT_LIST_HEAD(&dev->read_list); | 451 | INIT_LIST_HEAD(&dev->read_list); |