apps: use helper to create mbuf pools
[dpdk.git] / examples / l3fwd-power / main.c
index 3215631..bb0b66f 100644 (file)
@@ -1,13 +1,13 @@
 /*-
  *   BSD LICENSE
- * 
+ *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
- * 
+ *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
  *   are met:
- * 
+ *
  *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above copyright
@@ -17,7 +17,7 @@
  *     * Neither the name of Intel Corporation nor the names of its
  *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
- * 
+ *
  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -50,7 +50,6 @@
 #include <rte_memory.h>
 #include <rte_memcpy.h>
 #include <rte_memzone.h>
-#include <rte_tailq.h>
 #include <rte_eal.h>
 #include <rte_per_lcore.h>
 #include <rte_launch.h>
@@ -76,8 +75,6 @@
 #include <rte_timer.h>
 #include <rte_power.h>
 
-#include "main.h"
-
 #define RTE_LOGTYPE_L3FWD_POWER RTE_LOGTYPE_USER1
 
 #define MAX_PKT_BURST 32
 
 #define MEMPOOL_CACHE_SIZE 256
 
-#define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
+#define MBUF_DATA_SIZE (2048 + RTE_PKTMBUF_HEADROOM)
 
 /*
  * This expression is used to calculate the number of mbufs needed depending on
        nb_lcores*MEMPOOL_CACHE_SIZE), \
        (unsigned)8192)
 
-/*
- * 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.
- */
-#define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
-#define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
-#define RX_WTHRESH 4 /**< Default values of RX write-back threshold reg. */
-
-/*
- * 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.
- */
-#define TX_PTHRESH 36 /**< Default values of TX prefetch threshold reg. */
-#define TX_HTHRESH 0  /**< Default values of TX host threshold reg. */
-#define TX_WTHRESH 0  /**< Default values of TX write-back threshold reg. */
-
 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
 
 #define NB_SOCKETS 8
@@ -235,6 +213,7 @@ static uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
 
 static struct rte_eth_conf port_conf = {
        .rxmode = {
+               .mq_mode        = ETH_MQ_RX_RSS,
                .max_rx_pkt_len = ETHER_MAX_LEN,
                .split_hdr_size = 0,
                .header_split   = 0, /**< Header Split disabled */
@@ -246,7 +225,7 @@ static struct rte_eth_conf port_conf = {
        .rx_adv_conf = {
                .rss_conf = {
                        .rss_key = NULL,
-                       .rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6,
+                       .rss_hf = ETH_RSS_IP,
                },
        },
        .txmode = {
@@ -254,26 +233,6 @@ static struct rte_eth_conf port_conf = {
        },
 };
 
-static const struct rte_eth_rxconf rx_conf = {
-       .rx_thresh = {
-               .pthresh = RX_PTHRESH,
-               .hthresh = RX_HTHRESH,
-               .wthresh = RX_WTHRESH,
-       },
-       .rx_free_thresh = 32,
-};
-
-static const struct rte_eth_txconf tx_conf = {
-       .tx_thresh = {
-               .pthresh = TX_PTHRESH,
-               .hthresh = TX_HTHRESH,
-               .wthresh = TX_WTHRESH,
-       },
-       .tx_free_thresh = 0, /* Use PMD default values */
-       .tx_rs_thresh = 0, /* Use PMD default values */
-       .txq_flags = 0x0,
-};
-
 static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
 
 
@@ -395,7 +354,7 @@ struct lcore_stats {
        uint64_t nb_rx_processed;
        /* total iterations looped recently */
        uint64_t nb_iteration_looped;
-       uint32_t padding[9]; 
+       uint32_t padding[9];
 } __rte_cache_aligned;
 
 static struct lcore_conf lcore_conf[RTE_MAX_LCORE] __rte_cache_aligned;
@@ -442,7 +401,7 @@ power_timer_cb(__attribute__((unused)) struct rte_timer *tim,
        /* accumulate total execution time in us when callback is invoked */
        sleep_time_ratio = (float)(stats[lcore_id].sleep_time) /
                                        (float)SCALING_PERIOD;
-               
+
        /**
         * check whether need to scale down frequency a step if it sleep a lot.
         */
@@ -686,7 +645,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid,
 
 #ifdef DO_RFC_1812_CHECKS
                /* Check to make sure the packet is valid (RFC1812) */
-               if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt.pkt_len) < 0) {
+               if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {
                        rte_pktmbuf_free(m);
                        return;
                }
@@ -815,7 +774,7 @@ main_loop(__attribute__((unused)) void *dummy)
        struct lcore_conf *qconf;
        struct lcore_rx_queue *rx_queue;
        enum freq_scale_hint_t lcore_scaleup_hint;
-       
+
        uint32_t lcore_rx_idle_count = 0;
        uint32_t lcore_idle_hint = 0;
 
@@ -948,8 +907,8 @@ main_loop(__attribute__((unused)) void *dummy)
                                                lcore_scaleup_hint)
                                        lcore_scaleup_hint =
                                                rx_queue->freq_up_hint;
-                       }       
-               
+                       }
+
                        if (lcore_scaleup_hint == FREQ_HIGHEST)
                                rte_power_freq_max(lcore_id);
                        else if (lcore_scaleup_hint == FREQ_HIGHER)
@@ -1148,7 +1107,7 @@ parse_config(const char *q_arg)
                if(size >= sizeof(s))
                        return -1;
 
-               rte_snprintf(s, sizeof(s), "%.*s", size, p);
+               snprintf(s, sizeof(s), "%.*s", size, p);
                if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') !=
                                                                _NUM_FLD)
                        return -1;
@@ -1228,7 +1187,7 @@ parse_args(int argc, char **argv)
                                printf("numa is disabled \n");
                                numa_on = 0;
                        }
-                       
+
                        if (!strncmp(lgopts[option_index].name,
                                        "enable-jumbo", 12)) {
                                struct option lenopts =
@@ -1237,7 +1196,7 @@ parse_args(int argc, char **argv)
 
                                printf("jumbo frame is enabled \n");
                                port_conf.rxmode.jumbo_frame = 1;
-       
+
                                /**
                                 * if no max-pkt-len set, use the default value
                                 * ETHER_MAX_LEN
@@ -1258,7 +1217,7 @@ parse_args(int argc, char **argv)
                                        "max packet length to %u\n",
                                (unsigned int)port_conf.rxmode.max_rx_pkt_len);
                        }
-                       
+
                        break;
 
                default:
@@ -1278,13 +1237,9 @@ parse_args(int argc, char **argv)
 static void
 print_ethaddr(const char *name, const struct ether_addr *eth_addr)
 {
-       printf ("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
-               eth_addr->addr_bytes[0],
-               eth_addr->addr_bytes[1],
-               eth_addr->addr_bytes[2],
-               eth_addr->addr_bytes[3],
-               eth_addr->addr_bytes[4],
-               eth_addr->addr_bytes[5]);
+       char buf[ETHER_ADDR_FMT_SIZE];
+       ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
+       printf("%s%s", name, buf);
 }
 
 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
@@ -1314,7 +1269,7 @@ setup_hash(int socketid)
        char s[64];
 
        /* create ipv4 hash */
-       rte_snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
+       snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
        ipv4_l3fwd_hash_params.name = s;
        ipv4_l3fwd_hash_params.socket_id = socketid;
        ipv4_l3fwd_lookup_struct[socketid] =
@@ -1324,7 +1279,7 @@ setup_hash(int socketid)
                                "socket %d\n", socketid);
 
        /* create ipv6 hash */
-       rte_snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
+       snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
        ipv6_l3fwd_hash_params.name = s;
        ipv6_l3fwd_hash_params.socket_id = socketid;
        ipv6_l3fwd_lookup_struct[socketid] =
@@ -1371,7 +1326,7 @@ setup_lpm(int socketid)
        char s[64];
 
        /* create the LPM table */
-       rte_snprintf(s, sizeof(s), "IPV4_L3FWD_LPM_%d", socketid);
+       snprintf(s, sizeof(s), "IPV4_L3FWD_LPM_%d", socketid);
        ipv4_l3fwd_lookup_struct[socketid] = rte_lpm_create(s, socketid,
                                IPV4_L3FWD_LPM_MAX_RULES, 0);
        if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
@@ -1422,14 +1377,11 @@ init_mem(unsigned nb_mbuf)
                                                lcore_id, NB_SOCKETS);
                }
                if (pktmbuf_pool[socketid] == NULL) {
-                       rte_snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
+                       snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
                        pktmbuf_pool[socketid] =
-                               rte_mempool_create(s, nb_mbuf,
-                                       MBUF_SIZE, MEMPOOL_CACHE_SIZE,
-                                       sizeof(struct rte_pktmbuf_pool_private),
-                                       rte_pktmbuf_pool_init, NULL,
-                                       rte_pktmbuf_init, NULL,
-                                       socketid, 0);
+                               rte_pktmbuf_pool_create(s, nb_mbuf,
+                                       MEMPOOL_CACHE_SIZE, 0, MBUF_DATA_SIZE,
+                                       socketid);
                        if (pktmbuf_pool[socketid] == NULL)
                                rte_exit(EXIT_FAILURE,
                                        "Cannot init mbuf pool on socket %d\n",
@@ -1509,9 +1461,11 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)
 }
 
 int
-MAIN(int argc, char **argv)
+main(int argc, char **argv)
 {
        struct lcore_conf *qconf;
+       struct rte_eth_dev_info dev_info;
+       struct rte_eth_txconf *txconf;
        int ret;
        unsigned nb_ports;
        uint16_t queueid;
@@ -1546,13 +1500,6 @@ MAIN(int argc, char **argv)
                rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
 
 
-       /* init driver(s) */
-       if (rte_pmd_init_all() < 0)
-               rte_exit(EXIT_FAILURE, "Cannot init pmd\n");
-
-       if (rte_eal_pci_probe() < 0)
-               rte_exit(EXIT_FAILURE, "Cannot probe PCI\n");
-
        nb_ports = rte_eth_dev_count();
        if (nb_ports > RTE_MAX_ETHPORTS)
                nb_ports = RTE_MAX_ETHPORTS;
@@ -1609,8 +1556,13 @@ MAIN(int argc, char **argv)
 
                        printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
                        fflush(stdout);
+
+                       rte_eth_dev_info_get(portid, &dev_info);
+                       txconf = &dev_info.default_txconf;
+                       if (port_conf.rxmode.jumbo_frame)
+                               txconf->txq_flags = 0;
                        ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
-                                                    socketid, &tx_conf);
+                                                    socketid, txconf);
                        if (ret < 0)
                                rte_exit(EXIT_FAILURE,
                                        "rte_eth_tx_queue_setup: err=%d, "
@@ -1658,7 +1610,8 @@ MAIN(int argc, char **argv)
                        fflush(stdout);
 
                        ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
-                               socketid, &rx_conf, pktmbuf_pool[socketid]);
+                               socketid, NULL,
+                               pktmbuf_pool[socketid]);
                        if (ret < 0)
                                rte_exit(EXIT_FAILURE,
                                        "rte_eth_rx_queue_setup: err=%d, "