From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0041.outbound.protection.outlook.com [104.47.34.41]) by dpdk.org (Postfix) with ESMTP id E9F271BB93 for ; Fri, 8 Jun 2018 19:10:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pcUnaW/nKXCCf2j8pzi6It/1P6mvxhNgOlwdX4uYHfs=; b=B6Pb+fF5/AiHNDHw572upYLhbeLbxCbr1uR7v02GwUQr1ppcpdvKpNvzGv2khK+jPaPt7oM4hQqFJM58yMMvRGjVdV2fpAP8desa4dRw45fCw4EWRXqp5BYHCDZgWWulC510HuJUdTzvUWfUcxqy3faxMU3CzuzHs8FW1RkIqnw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Anoob.Joseph@cavium.com; Received: from ajoseph83.caveonetworks.com.caveonetworks.com (115.113.156.2) by SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.15; Fri, 8 Jun 2018 17:10:34 +0000 From: Anoob Joseph To: Bruce Richardson , Pablo de Lara Cc: Anoob Joseph , Jerin Jacob , Narayana Prasad , dev@dpdk.org Date: Fri, 8 Jun 2018 22:39:18 +0530 Message-Id: <1528477766-15788-8-git-send-email-anoob.joseph@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528477766-15788-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1528477766-15788-1-git-send-email-anoob.joseph@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: BM1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00::27) To SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:SN6PR07MB4911; X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 3:SHxPtwJSWbTnjgHzGTLi7iGSWNIZFM9dGveaoHpHjCdMgaZrxgjIKtfFfhKR82o2sqNZQ6Ry3CvzKhOSJsSiH804pacF+e3alPm8gO4ehFbqmoicdnjUc5z4+X+MqvLiMPZb1a7YkxsV2184Mm8JCOGfgF4sLF6+mVjGeOAY4chfP7llGMuV2haXKL7Px2EsP0PR8/8gW+816OS6ti9ClkPeFyYVbapTSXPOliGmXeGVrpJDUEK9gc2wbdYxgVkz; 25:q3Fn3JcBVnoemT0qIb0LYQQ4t05Q2rMNgUee/cEFUnoVc3wSi1b/S5TgaYb3HLgh8A9LArRax0OYDHPep5eY2qYIqL+5VC63VepfzPHDc0zZU1KVqaqwJULd565oOq8Y+ZA3kodwgsl3eJuoOQaS9JdyzFeWJKzJjlw9AfMJX7tmsh+2tkRmGSCv1xEaO9N4IzJbQvPrwOGhdlnFwd7tLWlzkd+6q2YuJgmISac2B18saD2e+0ujHsPP9AoTv5TlzUaXM5RLxE8gnpDw2JERuoYwrisa4iEJWxTcVe64z95mjbS50I43rjGiJjq3FUqqJHzCivS3zbFjqsd9mpnGDg==; 31:P++l0IjIZiflLygALFFGL3Kt85xEEV5TZAD89CdsvW1e7kLPUFozATbxUgiMjLUI9HM/rny5ahYNz4w+fiK1HcsvusHBsgQkn8SlCiCsiG+mAk1iPQgqnZxnKZ0E0O/D6Q7SZFLfzk5pJtO3ZPoxhZ7qW0MagzaoCqSy7DZUuIisYcbmplayRB9qmAMksFc7eCKkdXVTap5WPiGt+5h7ENjJyg1DgUxX055UDVUAFfo= X-MS-TrafficTypeDiagnostic: SN6PR07MB4911: X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 20:l01747wZVs0cEZLROUfldLrZpwhdwf5pQ0YMwQWRXXJA7qWxiXmwBk2VpontTcxgWJW1WnUNXxnaos4K1Qs6AvCQlDZqX4YMKU0zIqH3OVsLJ/rEmdPdhdo8d6n5evOsj69bx8sbG+9Ci8gO+40LeKf7L4YuKpVeOZ5Ga7iAiwjSK5+21xl2Cm4lZNTd0KxE4uqk0rs8MJWikyAbMoL9PFqv02ij3H1xvF4FLTHUJgmHCP9DpTspbaClIVWYjjhtyCISnB047ef/2TvLoDHJ5bJ/naqEnwdQ7ly5hXVYAJr0As7by4lkpTJJgvIzsQiyjVMEXeDf6Zf7FnglFSSnKLACyBNECU3ifXIG+SyHvSuBEzw+PxsZsRuQJ3f5fE3RQqiZJ1+Yl95XGyYhC3Z8C/sRhNG6UJve/P4MxUXILRn12B5O6XVk1X5PXSKrS8xuBrqX6cYqr8enlr2RmH7qdn9Iam+Y8yGtMFTBmZWEmQuLMxUHRh3wHktVrTvGBKIaR0+fUHDWDnpmBhUxF2fFp69r+GdbbkwHwZpi6TeRoU8xh/BuaWlPP5SR6HfQtVaqghGq/1GTaUKzRNGQltrTJOnLlFPoyGwAzHE9db+ce+E=; 4:vKzkkK0mFCBUxpTVvBlZ3b+hxffz295rJwcRDKP3+WQ9656TS0F3ZokrXkNAi0dqlj5PrpWM23WIS5TADGpWqaUGiBn8A9yOLsGczN0OdkiHNksbdlcKlFDbjWXTt7TrQav3CpP+g9x8WDi5fTD0XI3jvlWBFXdBl6xwnxYQ0UwWg0Ha9akisGzVH2huF+qUOhVTo3T8ja3/rvtQOAjNLAl1apxxd90eDltltoPQ1WbQJDm16wyCHJOGyxyGFNy/lcJOt2dh8oor9nmgn5cINQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(3231254)(944501410)(52105095)(10201501046)(93006095)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:SN6PR07MB4911; BCL:0; PCL:0; RULEID:; SRVR:SN6PR07MB4911; X-Forefront-PRVS: 06973FFAD3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(39380400002)(39860400002)(376002)(396003)(346002)(199004)(189003)(6666003)(4326008)(54906003)(76176011)(5660300001)(25786009)(48376002)(50466002)(59450400001)(446003)(386003)(186003)(11346002)(16526019)(2616005)(42882007)(44832011)(51416003)(476003)(66066001)(110136005)(36756003)(316002)(55236004)(2906002)(7736002)(81156014)(81166006)(8936002)(50226002)(106356001)(105586002)(68736007)(52116002)(26005)(956004)(8676002)(305945005)(53936002)(6512007)(47776003)(486006)(478600001)(6486002)(6116002)(72206003)(3846002)(16586007)(6506007)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR07MB4911; H:ajoseph83.caveonetworks.com.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN6PR07MB4911; 23:CTpnuuVV7MjR7ks1CA4gJ7UFY2f1U+3syXAuMhuHw?= =?us-ascii?Q?oDzbiBl8GdWzieqZ6z0wIW682IMhO1DB/oISE9Ukhb2AyfR7xv0XLWn9wx4n?= =?us-ascii?Q?eAa0B2tkTlc4h2gbRH5MFOIfNka3J/bsLdtFUDeLDvE89WK2qX9CPJo3jx6X?= =?us-ascii?Q?TO7bM34Ri2cXd8nHUPVY9mLExhDlr0X4n6E6ACGLBbdF5643dcFGroQT7h6x?= =?us-ascii?Q?w8gecWqAwyHdw7cPCyb3bWk3srNMW/+0m8gce+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pMd3VGSKqJ0iT3TAoniVKYeTyoMS5Edn4tupdJEIkq2jL6XsWIaDOXydQ=; 24:MaaSaTIMZ9A1cSoGgIZXJehnjM81GNJ9Ca+AhNsZNb52R2MACIuQ/xTiqX//iOjzrGmiIPC1LgCyWQd9kV1yyNHpGfmcjF2BBL8WJLHXNw4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 7:BKa/dQAvbq+jX2uIBs9aVJv1ceBz8XD0M+HNdHOJhYUWHc55BaxZDrRLuB2NhPVNDKBykVxZSvTMB3G1UR07KJYk9hm1n7n36PSimPQ2OPwXQTKVx6gSakmg6wG8/ZyfSCiE/kkgcHNqQZr5gJfeqEnKKUwkcPiR0c9qkIvk0WwMVsUsUy8eWh07k9tDrkW8mgWuJPWIMIWs8RbE++qycqrkPUxqubeIOlOKEX0I+qpcXqZ1ME2iqD3SsKT2IbNZ X-MS-Office365-Filtering-Correlation-Id: 57b5bfc0-9e7f-4e79-20cd-08d5cd62c103 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2018 17:10:34.8984 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57b5bfc0-9e7f-4e79-20cd-08d5cd62c103 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR07MB4911 Subject: [dpdk-dev] [PATCH 07/15] examples/l2fwd: move dataplane code to new file X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jun 2018 17:10:39 -0000 Signed-off-by: Anoob Joseph --- examples/l2fwd/Makefile | 1 + examples/l2fwd/l2fwd_worker.c | 233 ++++++++++++++++++++++++++++++++++++++++++ examples/l2fwd/l2fwd_worker.h | 10 ++ examples/l2fwd/main.c | 191 +--------------------------------- 4 files changed, 245 insertions(+), 190 deletions(-) create mode 100644 examples/l2fwd/l2fwd_worker.c create mode 100644 examples/l2fwd/l2fwd_worker.h diff --git a/examples/l2fwd/Makefile b/examples/l2fwd/Makefile index a8a47ad..24d1e4e 100644 --- a/examples/l2fwd/Makefile +++ b/examples/l2fwd/Makefile @@ -6,6 +6,7 @@ APP = l2fwd # all source are stored in SRCS-y SRCS-y := main.c +SRCS-y += l2fwd_worker.c # Build using pkg-config variables if possible $(shell pkg-config --exists libdpdk) diff --git a/examples/l2fwd/l2fwd_worker.c b/examples/l2fwd/l2fwd_worker.c new file mode 100644 index 0000000..1f97911 --- /dev/null +++ b/examples/l2fwd/l2fwd_worker.c @@ -0,0 +1,233 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2016 Intel Corporation + * Copyright(c) 2018 Cavium, Inc + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "l2fwd_common.h" +#include "l2fwd_worker.h" + +/* Print out statistics on packets dropped */ +static void +print_stats(void) +{ + uint64_t total_packets_dropped, total_packets_tx, total_packets_rx; + unsigned portid; + + total_packets_dropped = 0; + total_packets_tx = 0; + total_packets_rx = 0; + + const char clr[] = { 27, '[', '2', 'J', '\0' }; + const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' }; + + /* Clear screen and move to top left */ + printf("%s%s", clr, topLeft); + + printf("\nPort statistics ===================================="); + + for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { + /* skip disabled ports */ + if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) + continue; + printf("\nStatistics for port %u ------------------------------" + "\nPackets sent: %24"PRIu64 + "\nPackets received: %20"PRIu64 + "\nPackets dropped: %21"PRIu64, + portid, + port_statistics[portid].tx, + port_statistics[portid].rx, + port_statistics[portid].dropped); + + total_packets_dropped += port_statistics[portid].dropped; + total_packets_tx += port_statistics[portid].tx; + total_packets_rx += port_statistics[portid].rx; + } + printf("\nAggregate statistics ===============================" + "\nTotal packets sent: %18"PRIu64 + "\nTotal packets received: %14"PRIu64 + "\nTotal packets dropped: %15"PRIu64, + total_packets_tx, + total_packets_rx, + total_packets_dropped); + printf("\n====================================================\n"); +} + +static void +l2fwd_mac_updating(struct rte_mbuf *m, unsigned dest_portid) +{ + struct ether_hdr *eth; + void *tmp; + + eth = rte_pktmbuf_mtod(m, struct ether_hdr *); + + /* 02:00:00:00:00:xx */ + tmp = ð->d_addr.addr_bytes[0]; + *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dest_portid << 40); + + /* src addr */ + ether_addr_copy(&l2fwd_ports_eth_addr[dest_portid], ð->s_addr); +} + +static void +l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid) +{ + unsigned dst_port; + int sent; + struct rte_eth_dev_tx_buffer *buffer; + + dst_port = l2fwd_dst_ports[portid]; + + if (mac_updating) + l2fwd_mac_updating(m, dst_port); + + buffer = tx_buffer[dst_port]; + sent = rte_eth_tx_buffer(dst_port, 0, buffer, m); + if (sent) + port_statistics[dst_port].tx += sent; +} + +/* main processing loop */ +static void +l2fwd_main_loop(void) +{ + struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; + struct rte_mbuf *m; + int sent; + unsigned lcore_id; + unsigned master_core_id; + uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc; + unsigned i, j, portid, nb_rx; + struct lcore_queue_conf *qconf; + const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) + / US_PER_S * BURST_TX_DRAIN_US; + struct rte_eth_dev_tx_buffer *buffer; + + prev_tsc = 0; + timer_tsc = 0; + + lcore_id = rte_lcore_id(); + qconf = &lcore_queue_conf[lcore_id]; + + if (qconf->n_rx_port == 0) { + RTE_LOG(INFO, L2FWD, "lcore %u has nothing to do\n", lcore_id); + return; + } + + RTE_LOG(INFO, L2FWD, "entering main loop on lcore %u\n", lcore_id); + + for (i = 0; i < qconf->n_rx_port; i++) { + + portid = qconf->rx_port_list[i]; + RTE_LOG(INFO, L2FWD, " -- lcoreid=%u portid=%u\n", lcore_id, + portid); + + } + + master_core_id = rte_get_master_lcore(); + + while (!force_quit) { + + cur_tsc = rte_rdtsc(); + + /* + * TX burst queue drain + */ + diff_tsc = cur_tsc - prev_tsc; + if (unlikely(diff_tsc > drain_tsc)) { + + for (i = 0; i < qconf->n_rx_port; i++) { + + portid = + l2fwd_dst_ports[qconf->rx_port_list[i]]; + buffer = tx_buffer[portid]; + + sent = rte_eth_tx_buffer_flush(portid, 0, + buffer); + if (sent) + port_statistics[portid].tx += sent; + + } + + /* if timer is enabled */ + if (timer_period > 0) { + + /* advance the timer */ + timer_tsc += diff_tsc; + + /* if timer has reached its timeout */ + if (unlikely(timer_tsc >= timer_period)) { + + /* do this only on master core */ + if (lcore_id == master_core_id) { + print_stats(); + /* reset the timer */ + timer_tsc = 0; + } + } + } + + prev_tsc = cur_tsc; + } + + /* + * Read packet from RX queues + */ + for (i = 0; i < qconf->n_rx_port; i++) { + + portid = qconf->rx_port_list[i]; + nb_rx = rte_eth_rx_burst(portid, 0, + pkts_burst, MAX_PKT_BURST); + + port_statistics[portid].rx += nb_rx; + + for (j = 0; j < nb_rx; j++) { + m = pkts_burst[j]; + rte_prefetch0(rte_pktmbuf_mtod(m, void *)); + l2fwd_simple_forward(m, portid); + } + } + } +} + +int +l2fwd_launch_one_lcore(__attribute__((unused)) void *dummy) +{ + l2fwd_main_loop(); + return 0; +} diff --git a/examples/l2fwd/l2fwd_worker.h b/examples/l2fwd/l2fwd_worker.h new file mode 100644 index 0000000..8971a6a --- /dev/null +++ b/examples/l2fwd/l2fwd_worker.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Cavium, Inc + */ +#ifndef _L2FWD_WORKER_H_ +#define _L2FWD_WORKER_H_ + +int +l2fwd_launch_one_lcore(__attribute__((unused)) void *dummy); + +#endif /* _L2FWD_WORKER_H_ */ diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index bd48295..05f9d28 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -40,6 +40,7 @@ #include #include "l2fwd_common.h" +#include "l2fwd_worker.h" static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; @@ -59,196 +60,6 @@ static struct rte_eth_conf port_conf = { struct rte_mempool * l2fwd_pktmbuf_pool = NULL; -/* Print out statistics on packets dropped */ -static void -print_stats(void) -{ - uint64_t total_packets_dropped, total_packets_tx, total_packets_rx; - unsigned portid; - - total_packets_dropped = 0; - total_packets_tx = 0; - total_packets_rx = 0; - - const char clr[] = { 27, '[', '2', 'J', '\0' }; - const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' }; - - /* Clear screen and move to top left */ - printf("%s%s", clr, topLeft); - - printf("\nPort statistics ===================================="); - - for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { - /* skip disabled ports */ - if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) - continue; - printf("\nStatistics for port %u ------------------------------" - "\nPackets sent: %24"PRIu64 - "\nPackets received: %20"PRIu64 - "\nPackets dropped: %21"PRIu64, - portid, - port_statistics[portid].tx, - port_statistics[portid].rx, - port_statistics[portid].dropped); - - total_packets_dropped += port_statistics[portid].dropped; - total_packets_tx += port_statistics[portid].tx; - total_packets_rx += port_statistics[portid].rx; - } - printf("\nAggregate statistics ===============================" - "\nTotal packets sent: %18"PRIu64 - "\nTotal packets received: %14"PRIu64 - "\nTotal packets dropped: %15"PRIu64, - total_packets_tx, - total_packets_rx, - total_packets_dropped); - printf("\n====================================================\n"); -} - -static void -l2fwd_mac_updating(struct rte_mbuf *m, unsigned dest_portid) -{ - struct ether_hdr *eth; - void *tmp; - - eth = rte_pktmbuf_mtod(m, struct ether_hdr *); - - /* 02:00:00:00:00:xx */ - tmp = ð->d_addr.addr_bytes[0]; - *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dest_portid << 40); - - /* src addr */ - ether_addr_copy(&l2fwd_ports_eth_addr[dest_portid], ð->s_addr); -} - -static void -l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid) -{ - unsigned dst_port; - int sent; - struct rte_eth_dev_tx_buffer *buffer; - - dst_port = l2fwd_dst_ports[portid]; - - if (mac_updating) - l2fwd_mac_updating(m, dst_port); - - buffer = tx_buffer[dst_port]; - sent = rte_eth_tx_buffer(dst_port, 0, buffer, m); - if (sent) - port_statistics[dst_port].tx += sent; -} - -/* main processing loop */ -static void -l2fwd_main_loop(void) -{ - struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; - struct rte_mbuf *m; - int sent; - unsigned lcore_id; - unsigned master_core_id; - uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc; - unsigned i, j, portid, nb_rx; - struct lcore_queue_conf *qconf; - const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) - / US_PER_S * BURST_TX_DRAIN_US; - struct rte_eth_dev_tx_buffer *buffer; - - prev_tsc = 0; - timer_tsc = 0; - - lcore_id = rte_lcore_id(); - qconf = &lcore_queue_conf[lcore_id]; - - if (qconf->n_rx_port == 0) { - RTE_LOG(INFO, L2FWD, "lcore %u has nothing to do\n", lcore_id); - return; - } - - RTE_LOG(INFO, L2FWD, "entering main loop on lcore %u\n", lcore_id); - - for (i = 0; i < qconf->n_rx_port; i++) { - - portid = qconf->rx_port_list[i]; - RTE_LOG(INFO, L2FWD, " -- lcoreid=%u portid=%u\n", lcore_id, - portid); - - } - - master_core_id = rte_get_master_lcore(); - - while (!force_quit) { - - cur_tsc = rte_rdtsc(); - - /* - * TX burst queue drain - */ - diff_tsc = cur_tsc - prev_tsc; - if (unlikely(diff_tsc > drain_tsc)) { - - for (i = 0; i < qconf->n_rx_port; i++) { - - portid = - l2fwd_dst_ports[qconf->rx_port_list[i]]; - buffer = tx_buffer[portid]; - - sent = rte_eth_tx_buffer_flush(portid, 0, - buffer); - if (sent) - port_statistics[portid].tx += sent; - - } - - /* if timer is enabled */ - if (timer_period > 0) { - - /* advance the timer */ - timer_tsc += diff_tsc; - - /* if timer has reached its timeout */ - if (unlikely(timer_tsc >= timer_period)) { - - /* do this only on master core */ - if (lcore_id == master_core_id) { - print_stats(); - /* reset the timer */ - timer_tsc = 0; - } - } - } - - prev_tsc = cur_tsc; - } - - /* - * Read packet from RX queues - */ - for (i = 0; i < qconf->n_rx_port; i++) { - - portid = qconf->rx_port_list[i]; - nb_rx = rte_eth_rx_burst(portid, 0, - pkts_burst, MAX_PKT_BURST); - - port_statistics[portid].rx += nb_rx; - - for (j = 0; j < nb_rx; j++) { - m = pkts_burst[j]; - rte_prefetch0(rte_pktmbuf_mtod(m, void *)); - l2fwd_simple_forward(m, portid); - } - } - } -} - -static int -l2fwd_launch_one_lcore(__attribute__((unused)) void *dummy) -{ - l2fwd_main_loop(); - return 0; -} - /* display usage */ static void l2fwd_usage(const char *prgname) -- 2.7.4