examples/ioat: add option to control DMA batch size
[dpdk.git] / examples / qos_meter / main.c
index da7afe8..a0f78e4 100644 (file)
 #include <rte_mbuf.h>
 #include <rte_meter.h>
 
-/*
- * Traffic metering configuration
- *
- */
+/* Traffic metering configuration. 8< */
 #define APP_MODE_FWD                    0
 #define APP_MODE_SRTCM_COLOR_BLIND      1
 #define APP_MODE_SRTCM_COLOR_AWARE      2
@@ -25,6 +22,7 @@
 #define APP_MODE_TRTCM_COLOR_AWARE      4
 
 #define APP_MODE       APP_MODE_SRTCM_COLOR_BLIND
+/* >8 End of traffic metering configuration. */
 
 
 #include "main.h"
@@ -53,19 +51,18 @@ static struct rte_mempool *pool = NULL;
  ***/
 static struct rte_eth_conf port_conf = {
        .rxmode = {
-               .mq_mode        = ETH_MQ_RX_RSS,
-               .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
+               .mq_mode        = RTE_ETH_MQ_RX_RSS,
                .split_hdr_size = 0,
-               .offloads = DEV_RX_OFFLOAD_CHECKSUM,
+               .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM,
        },
        .rx_adv_conf = {
                .rss_conf = {
                        .rss_key = NULL,
-                       .rss_hf = ETH_RSS_IP,
+                       .rss_hf = RTE_ETH_RSS_IP,
                },
        },
        .txmode = {
-               .mq_mode = ETH_DCB_NONE,
+               .mq_mode = RTE_ETH_MQ_TX_NONE,
        },
 };
 
@@ -79,15 +76,16 @@ static struct rte_eth_conf port_conf = {
  * Packet RX/TX
  *
  ***/
-#define PKT_RX_BURST_MAX                32
-#define PKT_TX_BURST_MAX                32
+#define RTE_MBUF_F_RX_BURST_MAX                32
+#define RTE_MBUF_F_TX_BURST_MAX                32
 #define TIME_TX_DRAIN                   200000ULL
 
 static uint16_t port_rx;
 static uint16_t port_tx;
-static struct rte_mbuf *pkts_rx[PKT_RX_BURST_MAX];
+static struct rte_mbuf *pkts_rx[RTE_MBUF_F_RX_BURST_MAX];
 struct rte_eth_dev_tx_buffer *tx_buffer;
 
+/* Traffic meter parameters are configured in the application. 8< */
 struct rte_meter_srtcm_params app_srtcm_params = {
        .cir = 1000000 * 46,
        .cbs = 2048,
@@ -102,6 +100,7 @@ struct rte_meter_trtcm_params app_trtcm_params = {
        .cbs = 2048,
        .pbs = 2048
 };
+/* >8 End of traffic meter parameters are configured in the application. */
 
 struct rte_meter_trtcm_profile app_trtcm_profile;
 
@@ -166,8 +165,8 @@ app_pkt_handle(struct rte_mbuf *pkt, uint64_t time)
 }
 
 
-static __attribute__((noreturn)) int
-main_loop(__attribute__((unused)) void *dummy)
+static __rte_noreturn int
+main_loop(__rte_unused void *dummy)
 {
        uint64_t current_time, last_time = rte_rdtsc();
        uint32_t lcore_id = rte_lcore_id();
@@ -188,7 +187,7 @@ main_loop(__attribute__((unused)) void *dummy)
                }
 
                /* Read packet burst from NIC RX */
-               nb_rx = rte_eth_rx_burst(port_rx, NIC_RX_QUEUE, pkts_rx, PKT_RX_BURST_MAX);
+               nb_rx = rte_eth_rx_burst(port_rx, NIC_RX_QUEUE, pkts_rx, RTE_MBUF_F_RX_BURST_MAX);
 
                /* Handle packets */
                for (i = 0; i < nb_rx; i ++) {
@@ -220,10 +219,7 @@ parse_portmask(const char *portmask)
        /* parse hexadecimal string */
        pm = strtoul(portmask, &end, 16);
        if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
-               return -1;
-
-       if (pm == 0)
-               return -1;
+               return 0;
 
        return pm;
 }
@@ -329,9 +325,15 @@ main(int argc, char **argv)
 
        /* NIC init */
        conf = port_conf;
-       rte_eth_dev_info_get(port_rx, &dev_info);
-       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
-               conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+
+       ret = rte_eth_dev_info_get(port_rx, &dev_info);
+       if (ret != 0)
+               rte_exit(EXIT_FAILURE,
+                       "Error during getting device (port %u) info: %s\n",
+                       port_rx, strerror(-ret));
+
+       if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
+               conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
 
        conf.rx_adv_conf.rss_conf.rss_hf &= dev_info.flow_type_rss_offloads;
        if (conf.rx_adv_conf.rss_conf.rss_hf !=
@@ -369,9 +371,15 @@ main(int argc, char **argv)
        rte_exit(EXIT_FAILURE, "Port %d TX queue setup error (%d)\n", port_rx, ret);
 
        conf = port_conf;
-       rte_eth_dev_info_get(port_tx, &dev_info);
-       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
-               conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+
+       ret = rte_eth_dev_info_get(port_tx, &dev_info);
+       if (ret != 0)
+               rte_exit(EXIT_FAILURE,
+                       "Error during getting device (port %u) info: %s\n",
+                       port_tx, strerror(-ret));
+
+       if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
+               conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
 
        conf.rx_adv_conf.rss_conf.rss_hf &= dev_info.flow_type_rss_offloads;
        if (conf.rx_adv_conf.rss_conf.rss_hf !=
@@ -411,13 +419,13 @@ main(int argc, char **argv)
                rte_exit(EXIT_FAILURE, "Port %d TX queue setup error (%d)\n", port_tx, ret);
 
        tx_buffer = rte_zmalloc_socket("tx_buffer",
-                       RTE_ETH_TX_BUFFER_SIZE(PKT_TX_BURST_MAX), 0,
+                       RTE_ETH_TX_BUFFER_SIZE(RTE_MBUF_F_TX_BURST_MAX), 0,
                        rte_eth_dev_socket_id(port_tx));
        if (tx_buffer == NULL)
                rte_exit(EXIT_FAILURE, "Port %d TX buffer allocation error\n",
                                port_tx);
 
-       rte_eth_tx_buffer_init(tx_buffer, PKT_TX_BURST_MAX);
+       rte_eth_tx_buffer_init(tx_buffer, RTE_MBUF_F_TX_BURST_MAX);
 
        ret = rte_eth_dev_start(port_rx);
        if (ret < 0)
@@ -427,9 +435,17 @@ main(int argc, char **argv)
        if (ret < 0)
                rte_exit(EXIT_FAILURE, "Port %d start error (%d)\n", port_tx, ret);
 
-       rte_eth_promiscuous_enable(port_rx);
+       ret = rte_eth_promiscuous_enable(port_rx);
+       if (ret != 0)
+               rte_exit(EXIT_FAILURE,
+                       "Port %d promiscuous mode enable error (%s)\n",
+                       port_rx, rte_strerror(-ret));
 
-       rte_eth_promiscuous_enable(port_tx);
+       ret = rte_eth_promiscuous_enable(port_tx);
+       if (ret != 0)
+               rte_exit(EXIT_FAILURE,
+                       "Port %d promiscuous mode enable error (%s)\n",
+                       port_rx, rte_strerror(-ret));
 
        /* App configuration */
        ret = app_configure_flow_table();
@@ -437,11 +453,14 @@ main(int argc, char **argv)
                rte_exit(EXIT_FAILURE, "Invalid configure flow table\n");
 
        /* Launch per-lcore init on every lcore */
-       rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
-       RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+       rte_eal_mp_remote_launch(main_loop, NULL, CALL_MAIN);
+       RTE_LCORE_FOREACH_WORKER(lcore_id) {
                if (rte_eal_wait_lcore(lcore_id) < 0)
                        return -1;
        }
 
+       /* clean up the EAL */
+       rte_eal_cleanup();
+
        return 0;
 }