log: do not drop debug logs at compile time
[dpdk.git] / examples / vhost / main.c
index 71f6d92..ac1f6e2 100644 (file)
@@ -106,9 +106,6 @@ static uint32_t num_devices;
 static struct rte_mempool *mbuf_pool;
 static int mergeable;
 
-/* Do vlan strip on host, enabled on default */
-static uint32_t vlan_strip = 1;
-
 /* Enable VM2VM communications. If this is disabled then the MAC address compare is skipped. */
 typedef enum {
        VM2VM_DISABLED = 0,
@@ -130,6 +127,7 @@ static uint32_t enable_tx_csum;
 static uint32_t enable_tso;
 
 static int client_mode;
+static int dequeue_zero_copy;
 
 /* Specify timeout (in useconds) between retries on RX. */
 static uint32_t burst_rx_delay_time = BURST_RX_WAIT_US;
@@ -297,6 +295,17 @@ port_init(uint8_t port)
 
        rx_ring_size = RTE_TEST_RX_DESC_DEFAULT;
        tx_ring_size = RTE_TEST_TX_DESC_DEFAULT;
+
+       /*
+        * When dequeue zero copy is enabled, guest Tx used vring will be
+        * updated only when corresponding mbuf is freed. Thus, the nb_tx_desc
+        * (tx_ring_size here) must be small enough so that the driver will
+        * hit the free threshold easily and free mbufs timely. Otherwise,
+        * guest Tx vring would be starved.
+        */
+       if (dequeue_zero_copy)
+               tx_ring_size = 64;
+
        tx_rings = (uint16_t)rte_lcore_count();
 
        retval = validate_num_devices(MAX_DEVICES);
@@ -469,12 +478,12 @@ us_vhost_usage(const char *prgname)
        "               --rx-retry-delay [0-N]: timeout(in usecond) between retries on RX. This makes effect only if retries on rx enabled\n"
        "               --rx-retry-num [0-N]: the number of retries on rx. This makes effect only if retries on rx enabled\n"
        "               --mergeable [0|1]: disable(default)/enable RX mergeable buffers\n"
-       "               --vlan-strip [0|1]: disable/enable(default) RX VLAN strip on host\n"
        "               --stats [0-N]: 0: Disable stats, N: Time in seconds to print stats\n"
        "               --socket-file: The path of the socket file.\n"
        "               --tx-csum [0|1] disable/enable TX checksum offload.\n"
        "               --tso [0|1] disable/enable TCP segment offload.\n"
-       "               --client register a vhost-user socket as client mode.\n",
+       "               --client register a vhost-user socket as client mode.\n"
+       "               --dequeue-zero-copy enables dequeue zero copy\n",
               prgname);
 }
 
@@ -494,12 +503,12 @@ us_vhost_parse_args(int argc, char **argv)
                {"rx-retry-delay", required_argument, NULL, 0},
                {"rx-retry-num", required_argument, NULL, 0},
                {"mergeable", required_argument, NULL, 0},
-               {"vlan-strip", required_argument, NULL, 0},
                {"stats", required_argument, NULL, 0},
                {"socket-file", required_argument, NULL, 0},
                {"tx-csum", required_argument, NULL, 0},
                {"tso", required_argument, NULL, 0},
                {"client", no_argument, &client_mode, 1},
+               {"dequeue-zero-copy", no_argument, &dequeue_zero_copy, 1},
                {NULL, 0, 0, 0},
        };
 
@@ -617,22 +626,6 @@ us_vhost_parse_args(int argc, char **argv)
                                }
                        }
 
-                       /* Enable/disable RX VLAN strip on host. */
-                       if (!strncmp(long_option[option_index].name,
-                               "vlan-strip", MAX_LONG_OPT_SZ)) {
-                               ret = parse_num_opt(optarg, 1);
-                               if (ret == -1) {
-                                       RTE_LOG(INFO, VHOST_CONFIG,
-                                               "Invalid argument for VLAN strip [0|1]\n");
-                                       us_vhost_usage(prgname);
-                                       return -1;
-                               } else {
-                                       vlan_strip = !!ret;
-                                       vmdq_conf_default.rxmode.hw_vlan_strip =
-                                               vlan_strip;
-                               }
-                       }
-
                        /* Enable/disable stats. */
                        if (!strncmp(long_option[option_index].name, "stats", MAX_LONG_OPT_SZ)) {
                                ret = parse_num_opt(optarg, INT32_MAX);
@@ -764,10 +757,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
                        "(%d) failed to add device MAC address to VMDQ\n",
                        vdev->vid);
 
-       /* Enable stripping of the vlan tag as we handle routing. */
-       if (vlan_strip)
-               rte_eth_dev_set_vlan_strip_on_queue(ports[0],
-                       (uint16_t)vdev->vmdq_rx_q, 1);
+       rte_eth_dev_set_vlan_strip_on_queue(ports[0], vdev->vmdq_rx_q, 1);
 
        /* Set device as ready for RX. */
        vdev->ready = DEVICE_RX;
@@ -842,17 +832,17 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
                return -1;
 
        if (vdev->vid == dst_vdev->vid) {
-               RTE_LOG(DEBUG, VHOST_DATA,
+               RTE_LOG_DP(DEBUG, VHOST_DATA,
                        "(%d) TX: src and dst MAC is same. Dropping packet.\n",
                        vdev->vid);
                return 0;
        }
 
-       RTE_LOG(DEBUG, VHOST_DATA,
+       RTE_LOG_DP(DEBUG, VHOST_DATA,
                "(%d) TX: MAC address is local\n", dst_vdev->vid);
 
        if (unlikely(dst_vdev->remove)) {
-               RTE_LOG(DEBUG, VHOST_DATA,
+               RTE_LOG_DP(DEBUG, VHOST_DATA,
                        "(%d) device is marked for removal\n", dst_vdev->vid);
                return 0;
        }
@@ -877,7 +867,7 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
                return 0;
 
        if (vdev->vid == dst_vdev->vid) {
-               RTE_LOG(DEBUG, VHOST_DATA,
+               RTE_LOG_DP(DEBUG, VHOST_DATA,
                        "(%d) TX: src and dst MAC is same. Dropping packet.\n",
                        vdev->vid);
                return -1;
@@ -891,7 +881,7 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
        *offset  = VLAN_HLEN;
        *vlan_tag = vlan_tags[vdev->vid];
 
-       RTE_LOG(DEBUG, VHOST_DATA,
+       RTE_LOG_DP(DEBUG, VHOST_DATA,
                "(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n",
                vdev->vid, dst_vdev->vid, *vlan_tag);
 
@@ -983,7 +973,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
                }
        }
 
-       RTE_LOG(DEBUG, VHOST_DATA,
+       RTE_LOG_DP(DEBUG, VHOST_DATA,
                "(%d) TX: MAC address is external\n", vdev->vid);
 
 queue2nic:
@@ -1051,7 +1041,7 @@ drain_mbuf_table(struct mbuf_table *tx_q)
        if (unlikely(cur_tsc - prev_tsc > MBUF_TABLE_DRAIN_TSC)) {
                prev_tsc = cur_tsc;
 
-               RTE_LOG(DEBUG, VHOST_DATA,
+               RTE_LOG_DP(DEBUG, VHOST_DATA,
                        "TX queue drained after timeout with burst size %u\n",
                        tx_q->len);
                do_drain_mbuf_table(tx_q);
@@ -1419,8 +1409,7 @@ create_mbuf_pool(uint16_t nr_port, uint32_t nr_switch_core, uint32_t mbuf_size,
 }
 
 /*
- * Main function, does initialisation and calls the per-lcore functions. The CUSE
- * device is also registered here to handle the IOCTLs.
+ * Main function, does initialisation and calls the per-lcore functions.
  */
 int
 main(int argc, char *argv[])
@@ -1525,6 +1514,9 @@ main(int argc, char *argv[])
        if (client_mode)
                flags |= RTE_VHOST_USER_CLIENT;
 
+       if (dequeue_zero_copy)
+               flags |= RTE_VHOST_USER_DEQUEUE_ZERO_COPY;
+
        /* Register vhost user driver to handle vhost messages. */
        for (i = 0; i < nb_sockets; i++) {
                ret = rte_vhost_driver_register
@@ -1538,7 +1530,6 @@ main(int argc, char *argv[])
 
        rte_vhost_driver_callback_register(&virtio_net_device_ops);
 
-       /* Start CUSE session. */
        rte_vhost_driver_session_start();
        return 0;