On 10/15/19 6:07 PM, Marvin Liu wrote:
> When vhost doing [de]nqueue, vq's local variable last_[used/avail]_idx
> will be inceased. Adding inline functions can avoid duplicated codes.
When enqueuing or dequeuing, the virtqueue's local available and used
indexes are increased.
Other than that:
Reviewed-by: Maxime Coquelin <maxime.coque...@redhat.com>
>
> Signed-off-by: Marvin Liu <yong....@intel.com>
>
> diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
> index 5131a97a3..22a3ddc38 100644
> --- a/lib/librte_vhost/vhost.h
> +++ b/lib/librte_vhost/vhost.h
> @@ -350,6 +350,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 5b85b832d..42b662080 100644
> --- a/lib/librte_vhost/virtio_net.c
> +++ b/lib/librte_vhost/virtio_net.c
> @@ -140,11 +140,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);
> }
>
> 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);
> @@ -1504,11 +1496,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)) {
>