Skip to content

Commit

Permalink
virtio_ring: introduce helper for indirect feature
Browse files Browse the repository at this point in the history
Introduce a helper to check whether we will use indirect
feature. It will be used by packed ring too.

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Tiwei Bie authored and David S. Miller committed Nov 27, 2018
1 parent 4d6a105 commit 2f18c2d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions drivers/virtio/virtio_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ struct vring_virtqueue {

#define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)

static inline bool virtqueue_use_indirect(struct virtqueue *_vq,
unsigned int total_sg)
{
struct vring_virtqueue *vq = to_vvq(_vq);

/*
* If the host supports indirect descriptor tables, and we have multiple
* buffers, then go indirect. FIXME: tune this threshold
*/
return (vq->indirect && total_sg > 1 && vq->vq.num_free);
}

/*
* Modern virtio devices have feature bits to specify whether they need a
* quirk and bypass the IOMMU. If not there, just use the DMA API.
Expand Down Expand Up @@ -324,9 +336,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,

head = vq->free_head;

/* If the host supports indirect descriptor tables, and we have multiple
* buffers, then go indirect. FIXME: tune this threshold */
if (vq->indirect && total_sg > 1 && vq->vq.num_free)
if (virtqueue_use_indirect(_vq, total_sg))
desc = alloc_indirect_split(_vq, total_sg, gfp);
else {
desc = NULL;
Expand Down

0 comments on commit 2f18c2d

Please sign in to comment.