Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3b56cdd authored by Jason Wang's avatar Jason Wang Committed by Michael S. Tsirkin
Browse files

vhost: try avoiding avail index access when getting descriptor



If last avail idx is not equal to cached avail idx, we're sure there's
still available buffers in the virtqueue so there's no need to re-read
avail idx. So let's skip this to avoid unnecessary userspace memory
access and memory barrier. Pktgen test show about 3% improvement on rx
pps.

Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 51be7a9a
Loading
Loading
Loading
Loading
+23 −16
Original line number Diff line number Diff line
@@ -1930,6 +1930,8 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,

	/* Check it isn't doing very strange things with descriptor numbers. */
	last_avail_idx = vq->last_avail_idx;

	if (vq->avail_idx == vq->last_avail_idx) {
		if (unlikely(vhost_get_user(vq, avail_idx, &vq->avail->idx))) {
			vq_err(vq, "Failed to access avail idx at %p\n",
				&vq->avail->idx);
@@ -1943,12 +1945,17 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
			return -EFAULT;
		}

	/* If there's nothing new since last we looked, return invalid. */
		/* If there's nothing new since last we looked, return
		 * invalid.
		 */
		if (vq->avail_idx == last_avail_idx)
			return vq->num;

	/* Only get avail ring entries after they have been exposed by guest. */
		/* Only get avail ring entries after they have been
		 * exposed by guest.
		 */
		smp_rmb();
	}

	/* Grab the next descriptor number they're advertising, and increment
	 * the index we've seen. */