remove useless memzone includes
[dpdk.git] / examples / multi_process / symmetric_mp / main.c
index 504a27a..1ebdb9e 100644 (file)
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_memory.h>
-#include <rte_memzone.h>
 #include <rte_launch.h>
-#include <rte_tailq.h>
 #include <rte_eal.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
-#include <rte_debug.h>
 #include <rte_atomic.h>
 #include <rte_branch_prediction.h>
-#include <rte_ring.h>
 #include <rte_debug.h>
 #include <rte_interrupts.h>
 #include <rte_pci.h>
@@ -79,7 +75,6 @@
 
 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
 
-#define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
 #define NB_MBUFS 64*1024 /* use 64k mbufs */
 #define MBUF_CACHE_SIZE 256
 #define PKT_BURST 32
 #define PARAM_PROC_ID "proc-id"
 #define PARAM_NUM_PROCS "num-procs"
 
-/*
- * RX and TX Prefetch, Host, and Write-back threshold values should be
- * carefully set for optimal performance. Consult the network
- * controller's datasheet and supporting DPDK documentation for guidance
- * on how these parameters should be set.
- */
-/* Default configuration for rx and tx thresholds etc. */
-static const struct rte_eth_rxconf rx_conf_default = {
-       .rx_thresh = {
-               .pthresh = 8,
-               .hthresh = 8,
-               .wthresh = 4,
-       },
-};
-
-/*
- * These default values are optimized for use with the Intel(R) 82599 10 GbE
- * Controller and the DPDK ixgbe PMD. Consider using other values for other
- * network controllers and/or network drivers.
- */
-static const struct rte_eth_txconf tx_conf_default = {
-       .tx_thresh = {
-               .pthresh = 36,
-               .hthresh = 0,
-               .wthresh = 0,
-       },
-       .tx_free_thresh = 0, /* Use PMD default values */
-       .tx_rs_thresh = 0, /* Use PMD default values */
-};
-
 /* for each lcore, record the elements of the ports array to use */
 struct lcore_ports{
        unsigned start_port;
@@ -131,12 +96,12 @@ struct port_stats{
        unsigned rx;
        unsigned tx;
        unsigned drop;
-} __attribute__((aligned(CACHE_LINE_SIZE / 2)));
+} __attribute__((aligned(RTE_CACHE_LINE_SIZE / 2)));
 
 static int proc_id = -1;
 static unsigned num_procs = 0;
 
-static uint8_t ports[RTE_MAX_ETHPORTS];
+static uint16_t ports[RTE_MAX_ETHPORTS];
 static unsigned num_ports = 0;
 
 static struct lcore_ports lcore_ports[RTE_MAX_LCORE];
@@ -226,9 +191,9 @@ smp_parse_args(int argc, char **argv)
                        ports[num_ports++] = (uint8_t)i;
 
        ret = optind-1;
-       optind = 0; /* reset getopt lib */
+       optind = 1; /* reset getopt lib */
 
-       return (ret);
+       return ret;
 }
 
 /*
@@ -236,7 +201,8 @@ smp_parse_args(int argc, char **argv)
  * coming from the mbuf_pool passed as parameter
  */
 static inline int
-smp_port_init(uint8_t port, struct rte_mempool *mbuf_pool, uint16_t num_queues)
+smp_port_init(uint16_t port, struct rte_mempool *mbuf_pool,
+              uint16_t num_queues)
 {
        struct rte_eth_conf port_conf = {
                        .rxmode = {
@@ -246,7 +212,7 @@ smp_port_init(uint8_t port, struct rte_mempool *mbuf_pool, uint16_t num_queues)
                                .hw_ip_checksum = 1, /**< IP checksum offload enabled */
                                .hw_vlan_filter = 0, /**< VLAN filtering disabled */
                                .jumbo_frame    = 0, /**< Jumbo Frame Support disabled */
-                               .hw_strip_crc   = 0, /**< CRC stripped by hardware */
+                               .hw_strip_crc   = 1, /**< CRC stripped by hardware */
                        },
                        .rx_adv_conf = {
                                .rss_conf = {
@@ -259,8 +225,11 @@ smp_port_init(uint8_t port, struct rte_mempool *mbuf_pool, uint16_t num_queues)
                        }
        };
        const uint16_t rx_rings = num_queues, tx_rings = num_queues;
+       struct rte_eth_dev_info info;
        int retval;
        uint16_t q;
+       uint16_t nb_rxd = RX_RING_SIZE;
+       uint16_t nb_txd = TX_RING_SIZE;
 
        if (rte_eal_process_type() == RTE_PROC_SECONDARY)
                return 0;
@@ -268,24 +237,33 @@ smp_port_init(uint8_t port, struct rte_mempool *mbuf_pool, uint16_t num_queues)
        if (port >= rte_eth_dev_count())
                return -1;
 
-       printf("# Initialising port %u... ", (unsigned)port);
+       printf("# Initialising port %u... ", port);
        fflush(stdout);
 
+       rte_eth_dev_info_get(port, &info);
+       info.default_rxconf.rx_drop_en = 1;
+
        retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
        if (retval < 0)
                return retval;
 
+       retval = rte_eth_dev_adjust_nb_rx_tx_desc(port, &nb_rxd, &nb_txd);
+       if (retval < 0)
+               return retval;
+
        for (q = 0; q < rx_rings; q ++) {
-               retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,
-                               rte_eth_dev_socket_id(port), &rx_conf_default,
+               retval = rte_eth_rx_queue_setup(port, q, nb_rxd,
+                               rte_eth_dev_socket_id(port),
+                               &info.default_rxconf,
                                mbuf_pool);
                if (retval < 0)
                        return retval;
        }
 
        for (q = 0; q < tx_rings; q ++) {
-               retval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE,
-                               rte_eth_dev_socket_id(port), &tx_conf_default);
+               retval = rte_eth_tx_queue_setup(port, q, nb_txd,
+                               rte_eth_dev_socket_id(port),
+                               NULL);
                if (retval < 0)
                        return retval;
        }
@@ -384,11 +362,12 @@ lcore_main(void *arg __rte_unused)
 
 /* Check the link status of all ports in up to 9s, and print them finally */
 static void
-check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)
+check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
 {
 #define CHECK_INTERVAL 100 /* 100ms */
 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
-       uint8_t portid, count, all_ports_up, print_flag = 0;
+       uint16_t portid;
+       uint8_t count, all_ports_up, print_flag = 0;
        struct rte_eth_link link;
 
        printf("\nChecking link status");
@@ -403,18 +382,17 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)
                        /* print link status if flag set */
                        if (print_flag == 1) {
                                if (link.link_status)
-                                       printf("Port %d Link Up - speed %u "
-                                               "Mbps - %s\n", (uint8_t)portid,
-                                               (unsigned)link.link_speed,
+                                       printf(
+                                       "Port%d Link Up. Speed %u Mbps - %s\n",
+                                               portid, link.link_speed,
                                (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
                                        ("full-duplex") : ("half-duplex\n"));
                                else
-                                       printf("Port %d Link Down\n",
-                                                       (uint8_t)portid);
+                                       printf("Port %d Link Down\n", portid);
                                continue;
                        }
                        /* clear all_ports_up flag if any link down */
-                       if (link.link_status == 0) {
+                       if (link.link_status == ETH_LINK_DOWN) {
                                all_ports_up = 0;
                                break;
                        }
@@ -471,11 +449,9 @@ main(int argc, char **argv)
        proc_type = rte_eal_process_type();
        mp = (proc_type == RTE_PROC_SECONDARY) ?
                        rte_mempool_lookup(_SMP_MBUF_POOL) :
-                       rte_mempool_create(_SMP_MBUF_POOL, NB_MBUFS, MBUF_SIZE,
-                                       MBUF_CACHE_SIZE, sizeof(struct rte_pktmbuf_pool_private),
-                                       rte_pktmbuf_pool_init, NULL,
-                                       rte_pktmbuf_init, NULL,
-                                       rte_socket_id(), 0);
+                       rte_pktmbuf_pool_create(_SMP_MBUF_POOL, NB_MBUFS,
+                               MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE,
+                               rte_socket_id());
        if (mp == NULL)
                rte_exit(EXIT_FAILURE, "Cannot get memory pool for buffers\n");