From: Marvin Liu Date: Thu, 24 Oct 2019 16:08:20 +0000 (+0800) Subject: vhost: add packed ring indexes increasing function X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=86202aae9402a2f181436ace1714282ab8a43871;p=dpdk.git vhost: add packed ring indexes increasing function When enqueuing or dequeuing, the virtqueue's local available and used indexes are increased. Signed-off-by: Marvin Liu Reviewed-by: Maxime Coquelin --- diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index c76d401155..02b3c91fff 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -367,6 +367,26 @@ desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter) wrap_counter != !!(flags & VRING_DESC_F_USED); } +static inline void +vq_inc_last_used_packed(struct vhost_virtqueue *vq, uint16_t num) +{ + vq->last_used_idx += num; + if (vq->last_used_idx >= vq->size) { + vq->used_wrap_counter ^= 1; + vq->last_used_idx -= vq->size; + } +} + +static inline void +vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num) +{ + vq->last_avail_idx += num; + if (vq->last_avail_idx >= vq->size) { + vq->avail_wrap_counter ^= 1; + vq->last_avail_idx -= vq->size; + } +} + void __vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t addr, uint64_t len); diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index 66f0c72067..070d62bc09 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -138,11 +138,7 @@ flush_shadow_used_ring_packed(struct virtio_net *dev, head_flags = flags; } - vq->last_used_idx += vq->shadow_used_packed[i].count; - if (vq->last_used_idx >= vq->size) { - vq->used_wrap_counter ^= 1; - vq->last_used_idx -= vq->size; - } + vq_inc_last_used_packed(vq, vq->shadow_used_packed[i].count); } __atomic_store_n(&vq->desc_packed[head_idx].flags, head_flags, @@ -865,11 +861,7 @@ virtio_dev_rx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, break; } - vq->last_avail_idx += nr_descs; - if (vq->last_avail_idx >= vq->size) { - vq->last_avail_idx -= vq->size; - vq->avail_wrap_counter ^= 1; - } + vq_inc_last_avail_packed(vq, nr_descs); } do_data_copy_enqueue(dev, vq); @@ -1585,11 +1577,7 @@ virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf, next); } - vq->last_avail_idx += desc_count; - if (vq->last_avail_idx >= vq->size) { - vq->last_avail_idx -= vq->size; - vq->avail_wrap_counter ^= 1; - } + vq_inc_last_avail_packed(vq, desc_count); } if (likely(dev->dequeue_zero_copy == 0)) {