apps: use helper to create mbuf pools
[dpdk.git] / examples / vmdq_dcb / main.c
index 844f334..3c7f2b3 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
@@ -48,7 +48,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>
 #include <rte_mbuf.h>
 #include <rte_memcpy.h>
 
-#include "main.h"
-
 /* basic constants used in application */
 #define NUM_QUEUES 128
 
 #define NUM_MBUFS 64*1024
 #define MBUF_CACHE_SIZE 64
-#define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
+#define MBUF_DATA_SIZE (2048 + RTE_PKTMBUF_HEADROOM)
 
 #define INVALID_PORT_ID 0xFF
 
@@ -87,36 +84,6 @@ static uint32_t enabled_port_mask = 0;
 /* number of pools (if user does not specify any, 16 by default */
 static enum rte_eth_nb_pools num_pools = ETH_16_POOLS;
 
-/*
- * 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 */
-};
-
 /* empty vmdq+dcb configuration structure. Filled in programatically */
 static const struct rte_eth_conf vmdq_dcb_conf_default = {
        .rxmode = {
@@ -212,7 +179,8 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool)
 
        for (q = 0; q < rxRings; q ++) {
                retval = rte_eth_rx_queue_setup(port, q, rxRingSize,
-                                               rte_eth_dev_socket_id(port), &rx_conf_default,
+                                               rte_eth_dev_socket_id(port),
+                                               NULL,
                                                mbuf_pool);
                if (retval < 0)
                        return retval;
@@ -220,7 +188,8 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool)
 
        for (q = 0; q < txRings; q ++) {
                retval = rte_eth_tx_queue_setup(port, q, txRingSize,
-                                               rte_eth_dev_socket_id(port), &tx_conf_default);
+                                               rte_eth_dev_socket_id(port),
+                                               NULL);
                if (retval < 0)
                        return retval;
        }
@@ -341,7 +310,6 @@ vmdq_parse_args(int argc, char **argv)
 }
 
 
-#ifndef RTE_EXEC_ENV_BAREMETAL
 /* When we receive a HUP signal, print out our stats */
 static void
 sighup_handler(int signum)
@@ -354,7 +322,6 @@ sighup_handler(int signum)
        }
        printf("\nFinished handling signal %d\n", signum);
 }
-#endif
 
 /*
  * Main thread that does the work, reading from INPUT_PORT
@@ -368,7 +335,7 @@ lcore_main(void *arg)
        uint16_t startQueue = (uint16_t)(core_num * (NUM_QUEUES/num_cores));
        uint16_t endQueue = (uint16_t)(startQueue + (NUM_QUEUES/num_cores));
        uint16_t q, i, p;
-       
+
        printf("Core %u(lcore %u) reading queues %i-%i\n", (unsigned)core_num,
               rte_lcore_id(), startQueue, endQueue - 1);
 
@@ -400,7 +367,7 @@ lcore_main(void *arg)
        }
 }
 
-/* 
+/*
  * Update the global var NUM_PORTS and array PORTS according to system ports number
  * and return valid ports number
  */
@@ -408,13 +375,13 @@ static unsigned check_ports_num(unsigned nb_ports)
 {
        unsigned valid_num_ports = num_ports;
        unsigned portid;
+
        if (num_ports > nb_ports) {
                printf("\nSpecified port number(%u) exceeds total system port number(%u)\n",
                        num_ports, nb_ports);
                num_ports = nb_ports;
        }
+
        for (portid = 0; portid < num_ports; portid ++) {
                if (ports[portid] >= nb_ports) {
                        printf("\nSpecified port ID(%u) exceeds max system port ID(%u)\n",
@@ -429,7 +396,7 @@ static unsigned check_ports_num(unsigned nb_ports)
 
 /* Main function, does initialisation and calls the per-lcore functions */
 int
-MAIN(int argc, char *argv[])
+main(int argc, char *argv[])
 {
        unsigned cores;
        struct rte_mempool *mbuf_pool;
@@ -439,9 +406,7 @@ MAIN(int argc, char *argv[])
        unsigned nb_ports, valid_num_ports;
        uint8_t portid;
 
-#ifndef RTE_EXEC_ENV_BAREMETAL
        signal(SIGHUP, sighup_handler);
-#endif
 
        /* init EAL */
        ret = rte_eal_init(argc, argv);
@@ -455,37 +420,29 @@ MAIN(int argc, char *argv[])
        if (ret < 0)
                rte_exit(EXIT_FAILURE, "Invalid VMDQ argument\n");
 
-       if (rte_ixgbe_pmd_init() != 0 ||
-                       rte_eal_pci_probe() != 0)
-               rte_exit(EXIT_FAILURE, "Error with NIC driver initialization\n");
-       
        cores = rte_lcore_count();
        if ((cores & (cores - 1)) != 0 || cores > 128) {
                rte_exit(EXIT_FAILURE,"This program can only run on an even"
                                "number of cores(1-128)\n\n");
        }
-       
+
        nb_ports = rte_eth_dev_count();
        if (nb_ports > RTE_MAX_ETHPORTS)
                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 < 2 || valid_num_ports % 2) {
                printf("Current valid ports number is %u\n", valid_num_ports);
                rte_exit(EXIT_FAILURE, "Error with valid ports number is not even or less than 2\n");
        }
 
-       mbuf_pool = rte_mempool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
-                                      MBUF_SIZE, MBUF_CACHE_SIZE,
-                                      sizeof(struct rte_pktmbuf_pool_private),
-                                      rte_pktmbuf_pool_init, NULL,
-                                      rte_pktmbuf_init, NULL,
-                                      rte_socket_id(), 0);
+       mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
+               MBUF_CACHE_SIZE, 0, MBUF_DATA_SIZE, rte_socket_id());
        if (mbuf_pool == NULL)
                rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
 
@@ -496,7 +453,7 @@ MAIN(int argc, char *argv[])
                        printf("\nSkipping disabled port %d\n", portid);
                        continue;
                }
-               if (port_init(portid, mbuf_pool) != 0) 
+               if (port_init(portid, mbuf_pool) != 0)
                        rte_exit(EXIT_FAILURE, "Cannot initialize network ports\n");
        }