Skip to content

Commit 275bf96

Browse files
jasowangdavem330
authored andcommitted
vhost: better detection of available buffers
This patch tries to do several tweaks on vhost_vq_avail_empty() for a better performance: - check cached avail index first which could avoid userspace memory access. - using unlikely() for the failure of userspace access - check vq->last_avail_idx instead of cached avail index as the last step. This patch is need for batching supports which needs to peek whether or not there's still available buffers in the ring. Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Jason Wang <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1a8b6d7 commit 275bf96

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/vhost/vhost.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,11 +2241,15 @@ bool vhost_vq_avail_empty(struct vhost_dev *dev, struct vhost_virtqueue *vq)
22412241
__virtio16 avail_idx;
22422242
int r;
22432243

2244+
if (vq->avail_idx != vq->last_avail_idx)
2245+
return false;
2246+
22442247
r = vhost_get_user(vq, avail_idx, &vq->avail->idx);
2245-
if (r)
2248+
if (unlikely(r))
22462249
return false;
2250+
vq->avail_idx = vhost16_to_cpu(vq, avail_idx);
22472251

2248-
return vhost16_to_cpu(vq, avail_idx) == vq->avail_idx;
2252+
return vq->avail_idx == vq->last_avail_idx;
22492253
}
22502254
EXPORT_SYMBOL_GPL(vhost_vq_avail_empty);
22512255

0 commit comments

Comments
 (0)