eal: set name to threads
[dpdk.git] / examples / vhost_xen / main.c
index b672bf3..3fcc138 100644 (file)
 /*
  * Calculate the number of buffers needed per port
  */
-#define NUM_MBUFS_PER_PORT ((MAX_QUEUES*RTE_TEST_RX_DESC_DEFAULT) +            \
+#define NUM_MBUFS_PER_PORT ((MAX_QUEUES*RTE_TEST_RX_DESC_DEFAULT) +            \
                                                        (num_switching_cores*MAX_PKT_BURST) +                   \
                                                        (num_switching_cores*RTE_TEST_TX_DESC_DEFAULT) +\
                                                        (num_switching_cores*MBUF_CACHE_SIZE))
 
 #define MBUF_CACHE_SIZE 64
-#define MBUF_DATA_SIZE (2048 + RTE_PKTMBUF_HEADROOM)
 
 /*
  * RX and TX Prefetch, Host, and Write-back threshold values should be
@@ -88,9 +87,9 @@
 #define TX_HTHRESH 0  /* Default values of TX host threshold reg. */
 #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 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 */
 
 /* State of virtio device. */
 #define DEVICE_NOT_READY     0
@@ -726,7 +725,7 @@ link_vmdq(struct virtio_net *dev)
 
        /* Register the MAC address. */
        ret = rte_eth_dev_mac_addr_add(ports[0], &dev->mac_address, (uint32_t)dev->device_fh);
-       if (ret) {
+       if (ret) {
                RTE_LOG(ERR, VHOST_DATA, "(%"PRIu64") Failed to add device MAC address to VMDQ\n",
                                                                                dev->device_fh);
                return -1;
@@ -874,8 +873,8 @@ virtio_tx_route(struct virtio_net* dev, struct rte_mbuf *m, struct rte_mempool *
        vlan_hdr->h_vlan_TCI = htons(vlan_tag);
 
        /* Copy the remaining packet contents to the mbuf. */
-       rte_memcpy((void *)(rte_pktmbuf_mtod(mbuf, uint8_t *) + VLAN_ETH_HLEN),
-               (const void *)(rte_pktmbuf_mtod(m, uint8_t *) + ETH_HLEN),
+       rte_memcpy(rte_pktmbuf_mtod_offset(mbuf, void *, VLAN_ETH_HLEN),
+               rte_pktmbuf_mtod_offset(m, const void *, ETH_HLEN),
                (m->data_len - ETH_HLEN));
        tx_q->m_table[len] = mbuf;
        len++;
@@ -1433,6 +1432,7 @@ main(int argc, char *argv[])
        int ret;
        uint8_t portid;
        static pthread_t tid;
+       char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        /* init EAL */
        ret = rte_eal_init(argc, argv);
@@ -1462,9 +1462,9 @@ main(int argc, char *argv[])
                nb_ports = RTE_MAX_ETHPORTS;
 
        /*
-        * Update the global var NUM_PORTS and global array PORTS
-        * and get value of var VALID_NUM_PORTS according to system ports number
-        */
+        * Update the global var NUM_PORTS and global array PORTS
+        * and get value of var VALID_NUM_PORTS according to system ports number
+        */
        valid_num_ports = check_ports_num(nb_ports);
 
        if ((valid_num_ports ==  0) || (valid_num_ports > MAX_SUP_PORTS)) {
@@ -1476,7 +1476,7 @@ main(int argc, char *argv[])
        /* Create the mbuf pool. */
        mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
                NUM_MBUFS_PER_PORT * valid_num_ports, MBUF_CACHE_SIZE, 0,
-               MBUF_DATA_SIZE, rte_socket_id());
+               RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
        if (mbuf_pool == NULL)
                rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
 
@@ -1502,8 +1502,19 @@ main(int argc, char *argv[])
        memset(&dev_statistics, 0, sizeof(dev_statistics));
 
        /* Enable stats if the user option is set. */
-       if (enable_stats)
-               pthread_create(&tid, NULL, (void*)print_stats, NULL );
+       if (enable_stats) {
+               ret = pthread_create(&tid, NULL, (void *)print_stats, NULL);
+               if (ret != 0)
+                       rte_exit(EXIT_FAILURE,
+                               "Cannot create print-stats thread\n");
+
+               /* Set thread_name for aid in debugging. */
+               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "print-xen-stats");
+               ret = pthread_setname_np(tid, thread_name);
+               if (ret != 0)
+                       RTE_LOG(ERR, VHOST_CONFIG,
+                               "Cannot set print-stats name\n");
+       }
 
        /* Launch all data cores. */
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {