X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fexception_path%2Fmain.c;h=0bc149dacc40ff6c0e88346db7d136de5cb2bd2c;hb=e9d48c0072d36eb6423b45fba4ec49d0def6c36f;hp=70c1009e63f39cd3684c5d1bcf537c1d97160c97;hpb=32e7aa0b3a06f014e9aef647da039402fc629fda;p=dpdk.git diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c index 70c1009e63..0bc149dacc 100644 --- a/examples/exception_path/main.c +++ b/examples/exception_path/main.c @@ -1,35 +1,34 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2013 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. - * */ #include @@ -79,9 +78,6 @@ #define FATAL_ERROR(fmt, args...) rte_exit(EXIT_FAILURE, fmt "\n", ##args) #define PRINT_INFO(fmt, args...) RTE_LOG(INFO, APP, fmt "\n", ##args) -/* NUMA socket to allocate mbuf pool on */ -#define SOCKET 0 - /* Max ports than can be used (each port is associated with two lcores) */ #define MAX_PORTS (RTE_MAX_LCORE / 2) @@ -160,10 +156,10 @@ static struct rte_mempool * pktmbuf_pool = NULL; static uint32_t ports_mask = 0; /* Mask of cores that read from NIC and write to tap */ -static uint32_t input_cores_mask = 0; +static uint64_t input_cores_mask = 0; /* Mask of cores that read from tap and write to NIC */ -static uint32_t output_cores_mask = 0; +static uint64_t output_cores_mask = 0; /* Array storing port_id that is associated with each lcore */ static uint8_t port_ids[RTE_MAX_LCORE]; @@ -248,21 +244,21 @@ static int tap_create(char *name) } /* Main processing loop */ -static __attribute__((noreturn)) int +static int main_loop(__attribute__((unused)) void *arg) { const unsigned lcore_id = rte_lcore_id(); char tap_name[IFNAMSIZ]; int tap_fd; - /* Create new tap interface */ - rte_snprintf(tap_name, IFNAMSIZ, "tap_dpdk_%.2u", lcore_id); - tap_fd = tap_create(tap_name); - if (tap_fd < 0) - FATAL_ERROR("Could not create tap interface \"%s\" (%d)", - tap_name, tap_fd); + if ((1ULL << lcore_id) & input_cores_mask) { + /* Create new tap interface */ + rte_snprintf(tap_name, IFNAMSIZ, "tap_dpdk_%.2u", lcore_id); + tap_fd = tap_create(tap_name); + if (tap_fd < 0) + FATAL_ERROR("Could not create tap interface \"%s\" (%d)", + tap_name, tap_fd); - if ((1 << lcore_id) & input_cores_mask) { PRINT_INFO("Lcore %u is reading from port %u and writing to %s", lcore_id, (unsigned)port_ids[lcore_id], tap_name); fflush(stdout); @@ -288,7 +284,14 @@ main_loop(__attribute__((unused)) void *arg) } } } - else if ((1 << lcore_id) & output_cores_mask) { + else if ((1ULL << lcore_id) & output_cores_mask) { + /* Create new tap interface */ + rte_snprintf(tap_name, IFNAMSIZ, "tap_dpdk_%.2u", lcore_id); + tap_fd = tap_create(tap_name); + if (tap_fd < 0) + FATAL_ERROR("Could not create tap interface \"%s\" (%d)", + tap_name, tap_fd); + PRINT_INFO("Lcore %u is reading from %s and writing to port %u", lcore_id, tap_name, (unsigned)port_ids[lcore_id]); fflush(stdout); @@ -321,8 +324,7 @@ main_loop(__attribute__((unused)) void *arg) } else { PRINT_INFO("Lcore %u has nothing to do", lcore_id); - for (;;) - ; /* loop doing nothing */ + return 0; } /* * Tap file is closed automatically when program exits. Putting close() @@ -342,30 +344,30 @@ print_usage(const char *prgname) } /* Convert string to unsigned number. 0 is returned if error occurs */ -static uint32_t +static uint64_t parse_unsigned(const char *portmask) { char *end = NULL; - unsigned long num; + uint64_t num; - num = strtoul(portmask, &end, 16); + num = strtoull(portmask, &end, 16); if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) return 0; - return (uint32_t)num; + return (uint64_t)num; } /* Record affinities between ports and lcores in global port_ids[] array */ static void setup_port_lcore_affinities(void) { - unsigned i; + unsigned long i; uint8_t tx_port = 0; uint8_t rx_port = 0; /* Setup port_ids[] array, and check masks were ok */ RTE_LCORE_FOREACH(i) { - if (input_cores_mask & (1 << i)) { + if (input_cores_mask & (1ULL << i)) { /* Skip ports that are not enabled */ while ((ports_mask & (1 << rx_port)) == 0) { rx_port++; @@ -375,7 +377,7 @@ setup_port_lcore_affinities(void) port_ids[i] = rx_port++; } - else if (output_cores_mask & (1 << i)) { + else if (output_cores_mask & (1ULL << i)) { /* Skip ports that are not enabled */ while ((ports_mask & (1 << tx_port)) == 0) { tx_port++; @@ -457,13 +459,14 @@ init_port(uint8_t port) FATAL_ERROR("Could not configure port%u (%d)", (unsigned)port, ret); - ret = rte_eth_rx_queue_setup(port, 0, NB_RXD, SOCKET, &rx_conf, - pktmbuf_pool); + ret = rte_eth_rx_queue_setup(port, 0, NB_RXD, rte_eth_dev_socket_id(port), + &rx_conf, pktmbuf_pool); if (ret < 0) FATAL_ERROR("Could not setup up RX queue for port%u (%d)", (unsigned)port, ret); - ret = rte_eth_tx_queue_setup(port, 0, NB_TXD, SOCKET, &tx_conf); + ret = rte_eth_tx_queue_setup(port, 0, NB_TXD, rte_eth_dev_socket_id(port), + &tx_conf); if (ret < 0) FATAL_ERROR("Could not setup up TX queue for port%u (%d)", (unsigned)port, ret); @@ -557,7 +560,7 @@ main(int argc, char** argv) MEMPOOL_CACHE_SZ, sizeof(struct rte_pktmbuf_pool_private), rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL, - SOCKET, 0); + rte_socket_id(), 0); if (pktmbuf_pool == NULL) { FATAL_ERROR("Could not initialise mbuf pool"); return -1;