examples/vhost: minor fixes
[dpdk.git] / examples / vhost / main.c
index 2ff38ab..291128e 100644 (file)
@@ -99,7 +99,6 @@
 #define TX_WTHRESH 0  /* Default values of TX write-back threshold reg. */
 
 #define MAX_PKT_BURST 32               /* Max burst size for RX/TX */
-#define MAX_MRG_PKT_BURST 16   /* Max burst for merge buffers. Set to 1 due to performance issue. */
 #define BURST_TX_DRAIN_US 100  /* TX drain every ~100us */
 
 #define BURST_RX_WAIT_US 15    /* Defines how long we wait between retries on RX */
@@ -167,13 +166,14 @@ static uint32_t num_switching_cores = 0;
 
 /* number of devices/queues to support*/
 static uint32_t num_queues = 0;
-uint32_t num_devices = 0;
+static uint32_t num_devices;
 
 /*
  * Enable zero copy, pkts buffer will directly dma to hw descriptor,
  * disabled on default.
  */
 static uint32_t zero_copy;
+static int mergeable;
 
 /* number of descriptors to apply*/
 static uint32_t num_rx_descriptor = RTE_TEST_RX_DESC_DEFAULT_ZCP;
@@ -218,9 +218,6 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;
 static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";
 
 
-/* This can be set by the user so it is made available here. */
-extern uint64_t VHOST_FEATURES;
-
 /* Default configuration for rx and tx thresholds etc. */
 static struct rte_eth_rxconf rx_conf_default = {
        .rx_thresh = {
@@ -673,11 +670,11 @@ us_vhost_parse_args(int argc, char **argv)
                                        us_vhost_usage(prgname);
                                        return -1;
                                } else {
+                                       mergeable = !!ret;
                                        if (ret) {
                                                vmdq_conf_default.rxmode.jumbo_frame = 1;
                                                vmdq_conf_default.rxmode.max_rx_pkt_len
                                                        = JUMBO_FRAME_MAX_SIZE;
-                                               VHOST_FEATURES = (1ULL << VIRTIO_NET_F_MRG_RXBUF);
                                        }
                                }
                        }
@@ -987,7 +984,7 @@ unlink_vmdq(struct vhost_dev *vdev)
  * Check if the packet destination MAC address is for a local device. If so then put
  * the packet on that devices RX queue. If not then return.
  */
-static inline unsigned __attribute__((always_inline))
+static inline int __attribute__((always_inline))
 virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
        struct virtio_net_data_ll *dev_ll;
@@ -1016,7 +1013,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 
                        LOG_DEBUG(VHOST_DATA, "(%"PRIu64") TX: MAC address is local\n", tdev->device_fh);
 
-                       if (dev_ll->vdev->remove) {
+                       if (unlikely(dev_ll->vdev->remove)) {
                                /*drop the packet if the device is marked for removal*/
                                LOG_DEBUG(VHOST_DATA, "(%"PRIu64") Device is marked for removal\n", tdev->device_fh);
                        } else {
@@ -1214,7 +1211,7 @@ switch_worker(__attribute__((unused)) void *arg)
                        vdev = dev_ll->vdev;
                        dev = vdev->dev;
 
-                       if (vdev->remove) {
+                       if (unlikely(vdev->remove)) {
                                dev_ll = dev_ll->next;
                                unlink_vmdq(vdev);
                                vdev->ready = DEVICE_SAFE_REMOVE;
@@ -1253,7 +1250,7 @@ switch_worker(__attribute__((unused)) void *arg)
                                }
                        }
 
-                       if (!vdev->remove) {
+                       if (likely(!vdev->remove)) {
                                /* Handle guest TX*/
                                tx_count = rte_vhost_dequeue_burst(dev, VIRTIO_TXQ, mbuf_pool, pkts_burst, MAX_PKT_BURST);
                                /* If this is the first received packet we need to learn the MAC and setup VMDQ */
@@ -2274,16 +2271,6 @@ init_data_ll (void)
        return 0;
 }
 
-/*
- * Set virtqueue flags so that we do not receive interrupts.
- */
-static void
-set_irq_status (struct virtio_net *dev)
-{
-       dev->virtqueue[VIRTIO_RXQ]->used->flags = VRING_USED_F_NO_NOTIFY;
-       dev->virtqueue[VIRTIO_TXQ]->used->flags = VRING_USED_F_NO_NOTIFY;
-}
-
 /*
  * Remove a device from the specific data core linked list and from the main linked list. Synchonization
  * occurs through the use of the lcore dev_removal_flag. Device is made volatile here to avoid re-ordering
@@ -2715,8 +2702,7 @@ new_device (struct virtio_net *dev)
                }
        }
        /* Add device to lcore ll */
-       ll_dev->dev->coreid = core_add;
-       ll_dev = get_data_ll_free_entry(&lcore_info[ll_dev->dev->coreid].lcore_ll->ll_root_free);
+       ll_dev = get_data_ll_free_entry(&lcore_info[core_add].lcore_ll->ll_root_free);
        if (ll_dev == NULL) {
                RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Failed to add device to data core\n", dev->device_fh);
                vdev->ready = DEVICE_SAFE_REMOVE;
@@ -2729,13 +2715,14 @@ new_device (struct virtio_net *dev)
        ll_dev->vdev = vdev;
        vdev->coreid = core_add;
 
-       add_data_ll_entry(&lcore_info[ll_dev->dev->coreid].lcore_ll->ll_root_used, ll_dev);
+       add_data_ll_entry(&lcore_info[vdev->coreid].lcore_ll->ll_root_used, ll_dev);
 
        /* Initialize device stats */
        memset(&dev_statistics[dev->device_fh], 0, sizeof(struct device_statistics));
 
        /* Disable notifications. */
-       set_irq_status(dev);
+       rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
+       rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
        lcore_info[vdev->coreid].lcore_ll->device_num++;
        dev->flags |= VIRTIO_DEV_RUNNING;
 
@@ -2876,6 +2863,13 @@ MAIN(int argc, char *argv[])
        ret = us_vhost_parse_args(argc, argv);
        if (ret < 0)
                rte_exit(EXIT_FAILURE, "Invalid argument\n");
+#ifdef RTE_IXGBE_INC_VECTOR
+       if (mergeable == 1) {
+               rte_exit(EXIT_FAILURE,
+                       "sorry, mergeable feature doesn't work with vec sg recv, " \
+                       "please disable it in cfg as a workaround\n");
+       }
+#endif
 
        for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id ++)
                if (rte_lcore_is_enabled(lcore_id))
@@ -3040,6 +3034,9 @@ MAIN(int argc, char *argv[])
                                lcore_id);
        }
 
+       if (mergeable == 0)
+               rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_MRG_RXBUF);
+
        /* Register CUSE device to handle IOCTLs. */
        ret = rte_vhost_driver_register((char *)&dev_basename);
        if (ret != 0)