replace zero-length arrays with flexible ones
[dpdk.git] / lib / vhost / vhost.c
index f8aa619..b14521e 100644 (file)
@@ -42,6 +42,11 @@ static const struct vhost_vq_stats_name_off vhost_vq_stat_strings[] = {
        {"size_512_1023_packets",  offsetof(struct vhost_virtqueue, stats.size_bins[5])},
        {"size_1024_1518_packets", offsetof(struct vhost_virtqueue, stats.size_bins[6])},
        {"size_1519_max_packets",  offsetof(struct vhost_virtqueue, stats.size_bins[7])},
+       {"guest_notifications",    offsetof(struct vhost_virtqueue, stats.guest_notifications)},
+       {"iotlb_hits",             offsetof(struct vhost_virtqueue, stats.iotlb_hits)},
+       {"iotlb_misses",           offsetof(struct vhost_virtqueue, stats.iotlb_misses)},
+       {"inflight_submitted",     offsetof(struct vhost_virtqueue, stats.inflight_submitted)},
+       {"inflight_completed",     offsetof(struct vhost_virtqueue, stats.inflight_completed)},
 };
 
 #define VHOST_NB_VQ_STATS RTE_DIM(vhost_vq_stat_strings)
@@ -59,8 +64,14 @@ __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
        tmp_size = *size;
 
        vva = vhost_user_iotlb_cache_find(vq, iova, &tmp_size, perm);
-       if (tmp_size == *size)
+       if (tmp_size == *size) {
+               if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
+                       vq->stats.iotlb_hits++;
                return vva;
+       }
+
+       if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
+               vq->stats.iotlb_misses++;
 
        iova += tmp_size;
 
@@ -1758,6 +1769,12 @@ rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id)
        if (unlikely(vq == NULL || !dev->async_copy))
                return -1;
 
+       if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) {
+               VHOST_LOG_CONFIG(ERR, "(%s) %s() called without access lock taken.\n",
+                               dev->ifname, __func__);
+               return -1;
+       }
+
        return async_channel_register(vid, queue_id);
 }
 
@@ -1818,6 +1835,12 @@ rte_vhost_async_channel_unregister_thread_unsafe(int vid, uint16_t queue_id)
        if (vq == NULL)
                return -1;
 
+       if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) {
+               VHOST_LOG_CONFIG(ERR, "(%s) %s() called without access lock taken.\n",
+                               dev->ifname, __func__);
+               return -1;
+       }
+
        if (!vq->async)
                return 0;
 
@@ -1946,6 +1969,12 @@ rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id)
        if (vq == NULL)
                return ret;
 
+       if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) {
+               VHOST_LOG_CONFIG(ERR, "(%s) %s() called without access lock taken.\n",
+                               dev->ifname, __func__);
+               return -1;
+       }
+
        if (!vq->async)
                return ret;