vhost: export queue free entries
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Tue, 10 May 2016 22:46:24 +0000 (06:46 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Wed, 22 Jun 2016 07:02:58 +0000 (09:02 +0200)
The new API rte_vhost_avail_entries() is actually a rename of
rte_vring_available_entries(), with the "vring" to "vhost" name
change to keep the consistency of other vhost exported APIs.

This change could let us avoid the dependency of "virtio_net"
struct, to prepare for the ABI refactoring.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
doc/guides/rel_notes/release_16_07.rst
examples/tep_termination/main.c
examples/vhost/main.c
lib/librte_vhost/rte_vhost_version.map
lib/librte_vhost/rte_virtio_net.h
lib/librte_vhost/virtio-net.c

index 7aeacb2..d4e09b1 100644 (file)
@@ -161,6 +161,9 @@ API Changes
 * The function ``rte_eth_dev_info_get`` fill the new fields ``nb_rx_queues``
   and ``nb_tx_queues`` in the structure ``rte_eth_dev_info``.
 
+* The vhost function ``rte_vring_available_entries`` is renamed to
+  ``rte_vhost_avail_entries``.
+
 
 ABI Changes
 -----------
index f843f36..fb0c7fc 100644 (file)
@@ -709,11 +709,11 @@ switch_worker(__rte_unused void *arg)
                                        * must be less than virtio queue size
                                        */
                                        if (enable_retry && unlikely(rx_count >
-                                               rte_vring_available_entries(dev, VIRTIO_RXQ))) {
+                                               rte_vhost_avail_entries(dev->vid, VIRTIO_RXQ))) {
                                                for (retry = 0; retry < burst_rx_retry_num;
                                                        retry++) {
                                                        rte_delay_us(burst_rx_delay_time);
-                                                       if (rx_count <= rte_vring_available_entries(dev, VIRTIO_RXQ))
+                                                       if (rx_count <= rte_vhost_avail_entries(dev->vid, VIRTIO_RXQ))
                                                                break;
                                                }
                                        }
index c886d8a..4e26a8b 100644 (file)
@@ -1055,13 +1055,13 @@ drain_eth_rx(struct vhost_dev *vdev)
         * to diminish packet loss.
         */
        if (enable_retry &&
-           unlikely(rx_count > rte_vring_available_entries(dev,
+           unlikely(rx_count > rte_vhost_avail_entries(dev->vid,
                        VIRTIO_RXQ))) {
                uint32_t retry;
 
                for (retry = 0; retry < burst_rx_retry_num; retry++) {
                        rte_delay_us(burst_rx_delay_time);
-                       if (rx_count <= rte_vring_available_entries(dev,
+                       if (rx_count <= rte_vhost_avail_entries(dev->vid,
                                        VIRTIO_RXQ))
                                break;
                }
index d12ac97..5ceaa8a 100644 (file)
@@ -24,6 +24,7 @@ DPDK_2.1 {
 DPDK_16.07 {
        global:
 
+       rte_vhost_avail_entries;
        rte_vhost_get_ifname;
        rte_vhost_get_numa_node;
        rte_vhost_get_queue_num;
index 0898e8b..0427461 100644 (file)
@@ -184,17 +184,6 @@ struct virtio_net_device_ops {
        int (*vring_state_changed)(struct virtio_net *dev, uint16_t queue_id, int enable);      /**< triggered when a vring is enabled or disabled */
 };
 
-static inline uint16_t __attribute__((always_inline))
-rte_vring_available_entries(struct virtio_net *dev, uint16_t queue_id)
-{
-       struct vhost_virtqueue *vq = dev->virtqueue[queue_id];
-
-       if (!vq->enabled)
-               return 0;
-
-       return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
-}
-
 /**
  * Function to convert guest physical addresses to vhost virtual addresses.
  * This is used to convert guest virtio buffer addresses.
@@ -284,6 +273,19 @@ uint32_t rte_vhost_get_queue_num(int vid);
  */
 int rte_vhost_get_ifname(int vid, char *buf, size_t len);
 
+/**
+ * Get how many avail entries are left in the queue
+ *
+ * @param vid
+ *  virtio-net device ID
+ * @param queue_id
+ *  virtio queue index
+ *
+ * @return
+ *  num of avail entires left
+ */
+uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
+
 /**
  * This function adds buffers to the virtio devices RX virtqueue. Buffers can
  * be received from the physical port or from another virtual device. A packet
index 375c9d4..115eba4 100644 (file)
@@ -783,6 +783,23 @@ rte_vhost_get_ifname(int vid, char *buf, size_t len)
        return 0;
 }
 
+uint16_t
+rte_vhost_avail_entries(int vid, uint16_t queue_id)
+{
+       struct virtio_net *dev;
+       struct vhost_virtqueue *vq;
+
+       dev = get_device(vid);
+       if (!dev)
+               return 0;
+
+       vq = dev->virtqueue[queue_id];
+       if (!vq->enabled)
+               return 0;
+
+       return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
+}
+
 int rte_vhost_enable_guest_notification(struct virtio_net *dev,
        uint16_t queue_id, int enable)
 {