remove useless memzone includes
[dpdk.git] / examples / load_balancer / config.c
index fdb3d19..faf5198 100644 (file)
@@ -1,36 +1,34 @@
 /*-
  *   BSD LICENSE
- * 
- *   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ *
+ *   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 
+ *
+ *   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 
+ *
+ *     * 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 
- *       notice, this list of conditions and the following disclaimer in 
- *       the documentation and/or other materials provided with the 
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
  *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its 
- *       contributors may be used to endorse or promote products derived 
+ *     * 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 
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *
+ *   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
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- *  version: DPDK.L.1.2.3-3
  */
 
 #include <stdio.h>
 #include <rte_log.h>
 #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_atomic.h>
 #include <rte_cycles.h>
@@ -66,7 +61,6 @@
 #include <rte_debug.h>
 #include <rte_ether.h>
 #include <rte_ethdev.h>
-#include <rte_ring.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
 #include <rte_ip.h>
@@ -157,7 +151,7 @@ str_to_unsigned_array(
        int i, num_splits = 0;
 
        /* copy s so we don't modify original string */
-       rte_snprintf(str, sizeof(str), "%s", s);
+       snprintf(str, sizeof(str), "%s", s);
        num_splits = rte_strsplit(str, sizeof(str), splits, num_vals, separator);
 
        errno = 0;
@@ -234,7 +228,9 @@ parse_arg_rx(const char *arg)
                        return -7;
                }
                lp->type = e_APP_LCORE_IO;
-               for (i = 0; i < lp->io.rx.n_nic_queues; i ++) {
+               const size_t n_queues = RTE_MIN(lp->io.rx.n_nic_queues,
+                                               RTE_DIM(lp->io.rx.nic_queues));
+               for (i = 0; i < n_queues; i ++) {
                        if ((lp->io.rx.nic_queues[i].port == port) &&
                            (lp->io.rx.nic_queues[i].queue == queue)) {
                                return -8;
@@ -243,7 +239,7 @@ parse_arg_rx(const char *arg)
                if (lp->io.rx.n_nic_queues >= APP_MAX_NIC_RX_QUEUES_PER_IO_LCORE) {
                        return -9;
                }
-               lp->io.rx.nic_queues[lp->io.rx.n_nic_queues].port = (uint8_t) port;
+               lp->io.rx.nic_queues[lp->io.rx.n_nic_queues].port = port;
                lp->io.rx.nic_queues[lp->io.rx.n_nic_queues].queue = (uint8_t) queue;
                lp->io.rx.n_nic_queues ++;
 
@@ -311,7 +307,9 @@ parse_arg_tx(const char *arg)
                        return -7;
                }
                lp->type = e_APP_LCORE_IO;
-               for (i = 0; i < lp->io.tx.n_nic_ports; i ++) {
+               const size_t n_ports = RTE_MIN(lp->io.tx.n_nic_ports,
+                                              RTE_DIM(lp->io.tx.nic_ports));
+               for (i = 0; i < n_ports; i ++) {
                        if (lp->io.tx.nic_ports[i] == port) {
                                return -8;
                        }
@@ -319,7 +317,7 @@ parse_arg_tx(const char *arg)
                if (lp->io.tx.n_nic_ports >= APP_MAX_NIC_TX_PORTS_PER_IO_LCORE) {
                        return -9;
                }
-               lp->io.tx.nic_ports[lp->io.tx.n_nic_ports] = (uint8_t) port;
+               lp->io.tx.nic_ports[lp->io.tx.n_nic_ports] = port;
                lp->io.tx.n_nic_ports ++;
 
                n_tuples ++;
@@ -489,7 +487,7 @@ app_check_lpm_table(void)
 static int
 app_check_every_rx_port_is_tx_enabled(void)
 {
-       uint8_t port;
+       uint16_t port;
 
        for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
                if ((app_get_nic_rx_queues_per_port(port) > 0) && (app.nic_tx_port_mask[port] == 0)) {
@@ -758,12 +756,12 @@ app_parse_args(int argc, char **argv)
                argv[optind - 1] = prgname;
 
        ret = optind - 1;
-       optind = 0; /* reset getopt lib */
+       optind = 1; /* reset getopt lib */
        return ret;
 }
 
 int
-app_get_nic_rx_queues_per_port(uint8_t port)
+app_get_nic_rx_queues_per_port(uint16_t port)
 {
        uint32_t i, count;
 
@@ -782,7 +780,7 @@ app_get_nic_rx_queues_per_port(uint8_t port)
 }
 
 int
-app_get_lcore_for_nic_rx(uint8_t port, uint8_t queue, uint32_t *lcore_out)
+app_get_lcore_for_nic_rx(uint16_t port, uint8_t queue, uint32_t *lcore_out)
 {
        uint32_t lcore;
 
@@ -794,7 +792,9 @@ app_get_lcore_for_nic_rx(uint8_t port, uint8_t queue, uint32_t *lcore_out)
                        continue;
                }
 
-               for (i = 0; i < lp->rx.n_nic_queues; i ++) {
+               const size_t n_queues = RTE_MIN(lp->rx.n_nic_queues,
+                                               RTE_DIM(lp->rx.nic_queues));
+               for (i = 0; i < n_queues; i ++) {
                        if ((lp->rx.nic_queues[i].port == port) &&
                            (lp->rx.nic_queues[i].queue == queue)) {
                                *lcore_out = lcore;
@@ -807,7 +807,7 @@ app_get_lcore_for_nic_rx(uint8_t port, uint8_t queue, uint32_t *lcore_out)
 }
 
 int
-app_get_lcore_for_nic_tx(uint8_t port, uint32_t *lcore_out)
+app_get_lcore_for_nic_tx(uint16_t port, uint32_t *lcore_out)
 {
        uint32_t lcore;
 
@@ -819,7 +819,9 @@ app_get_lcore_for_nic_tx(uint8_t port, uint32_t *lcore_out)
                        continue;
                }
 
-               for (i = 0; i < lp->tx.n_nic_ports; i ++) {
+               const size_t n_ports = RTE_MIN(lp->tx.n_nic_ports,
+                                              RTE_DIM(lp->tx.nic_ports));
+               for (i = 0; i < n_ports; i ++) {
                        if (lp->tx.nic_ports[i] == port) {
                                *lcore_out = lcore;
                                return 0;
@@ -893,12 +895,12 @@ app_get_lcores_worker(void)
 void
 app_print_params(void)
 {
-       uint32_t port, queue, lcore, rule, i, j;
+       unsigned port, queue, lcore, rule, i, j;
 
        /* Print NIC RX configuration */
        printf("NIC RX ports: ");
        for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
-               uint32_t n_rx_queues = app_get_nic_rx_queues_per_port((uint8_t) port);
+               uint32_t n_rx_queues = app_get_nic_rx_queues_per_port(port);
 
                if (n_rx_queues == 0) {
                        continue;
@@ -928,8 +930,8 @@ app_print_params(void)
                printf("RX ports  ");
                for (i = 0; i < lp->rx.n_nic_queues; i ++) {
                        printf("(%u, %u)  ",
-                               (uint32_t) lp->rx.nic_queues[i].port,
-                               (uint32_t) lp->rx.nic_queues[i].queue);
+                               (unsigned) lp->rx.nic_queues[i].port,
+                               (unsigned) lp->rx.nic_queues[i].queue);
                }
                printf("; ");
 
@@ -951,7 +953,7 @@ app_print_params(void)
                printf("Worker lcore %u (socket %u) ID %u: ",
                        lcore,
                        rte_lcore_to_socket_id(lcore),
-                       lp->worker_id);
+                       (unsigned)lp->worker_id);
 
                printf("Input rings  ");
                for (i = 0; i < lp->n_rings_in; i ++) {
@@ -1010,7 +1012,7 @@ app_print_params(void)
                printf("Worker lcore %u (socket %u) ID %u: \n",
                        lcore,
                        rte_lcore_to_socket_id(lcore),
-                       lp->worker_id);
+                       (unsigned)lp->worker_id);
 
                printf("Output rings per TX port  ");
                for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
@@ -1031,28 +1033,28 @@ app_print_params(void)
 
                printf("\t%u: %u.%u.%u.%u/%u => %u;\n",
                        rule,
-                       (ip & 0xFF000000) >> 24,
-                       (ip & 0x00FF0000) >> 16,
-                       (ip & 0x0000FF00) >> 8,
-                       ip & 0x000000FF,
-                       (uint32_t) depth,
-                       (uint32_t) if_out
+                       (unsigned) (ip & 0xFF000000) >> 24,
+                       (unsigned) (ip & 0x00FF0000) >> 16,
+                       (unsigned) (ip & 0x0000FF00) >> 8,
+                       (unsigned) ip & 0x000000FF,
+                       (unsigned) depth,
+                       (unsigned) if_out
                );
        }
 
        /* Rings */
        printf("Ring sizes: NIC RX = %u; Worker in = %u; Worker out = %u; NIC TX = %u;\n",
-               app.nic_rx_ring_size,
-               app.ring_rx_size,
-               app.ring_tx_size,
-               app.nic_tx_ring_size);
+               (unsigned) app.nic_rx_ring_size,
+               (unsigned) app.ring_rx_size,
+               (unsigned) app.ring_tx_size,
+               (unsigned) app.nic_tx_ring_size);
 
        /* Bursts */
        printf("Burst sizes: I/O RX (rd = %u, wr = %u); Worker (rd = %u, wr = %u); I/O TX (rd = %u, wr = %u)\n",
-               app.burst_size_io_rx_read,
-               app.burst_size_io_rx_write,
-               app.burst_size_worker_read,
-               app.burst_size_worker_write,
-               app.burst_size_io_tx_read,
-               app.burst_size_io_tx_write);
+               (unsigned) app.burst_size_io_rx_read,
+               (unsigned) app.burst_size_io_rx_write,
+               (unsigned) app.burst_size_worker_read,
+               (unsigned) app.burst_size_worker_write,
+               (unsigned) app.burst_size_io_tx_read,
+               (unsigned) app.burst_size_io_tx_write);
 }