]> git.droids-corp.org - dpdk.git/commitdiff
vhost: add packed ring indexes increasing function
authorMarvin Liu <yong.liu@intel.com>
Thu, 24 Oct 2019 16:08:20 +0000 (00:08 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 25 Oct 2019 17:20:47 +0000 (19:20 +0200)
When enqueuing or dequeuing, the virtqueue's local available and used
indexes are increased.

Signed-off-by: Marvin Liu <yong.liu@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
lib/librte_vhost/vhost.h
lib/librte_vhost/virtio_net.c

index c76d40115503b32fb6c159aeca2b15363eb713c4..02b3c91fff6b9e04ca2168f50ff17bd60d964f84 100644 (file)
@@ -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);
index 66f0c720671e6fb12bdf4d1977a301b947ac6dd3..070d62bc094d32832beb1babefd28077a17b30e8 100644 (file)
@@ -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)) {