From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-CO1-obe.outbound.protection.outlook.com (mail-eopbgr690056.outbound.protection.outlook.com [40.107.69.56]) by dpdk.org (Postfix) with ESMTP id 4753F1E9B5 for ; Thu, 14 Jun 2018 12:19:12 +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=SJnEqS1MT9WU1Jk8C5neU/7z7SEWftzUXtR3syKlW38=; b=j1AhQYVtUJ3ihVue5mdl2Dvq6NzgQ0JTunEqGGYGk0ZCbXxIfuxQfgm0tQHtWmagtbfSJjEln+z+mDUq9CloGvyRgtZt9dNnJYEqIzAfGYB0XDSTSTDJdaCtg5diVVti6vzt7ZjaoHIQkgNfsjjWtFa0mh7mtXVs9/LkFlpEPr4= 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 BYAPR07MB4902.namprd07.prod.outlook.com (2603:10b6:a02:ef::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.841.19; Thu, 14 Jun 2018 10:19:08 +0000 From: Anoob Joseph To: Bruce Richardson , Pablo de Lara Cc: Anoob Joseph , Jerin Jacob , Narayana Prasad , dev@dpdk.org Date: Thu, 14 Jun 2018 15:47:49 +0530 Message-Id: <1528971477-14156-8-git-send-email-anoob.joseph@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528971477-14156-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1528477766-15788-1-git-send-email-anoob.joseph@caviumnetworks.com> <1528971477-14156-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: BM1PR0101CA0031.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1a::17) To BYAPR07MB4902.namprd07.prod.outlook.com (2603:10b6:a02:ef::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 673f9480-9ebf-4ad8-ebfb-08d5d1e04518 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(711020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:BYAPR07MB4902; X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4902; 3:qn7fpx15CikBPEv9of9nF0t7BYr//Vi5ENcUHKp08aD7ycx2x6fFDhec+Ol35ZdiwL1lC/irA28B/aHFflPal7jMHgXUhqXurUEuTRYi+G6Ejt2JYk07FK1nwxZ0zwgxQMPhA+rYc/SEB5I19xrUt0fgDsnDmPlYkS6Usdu52LrFh+bGoSr9XEPeuZxVSwyHzXEOStsreNM/f7cUSAHxPYj1U7inVkK6C+8o4F+fFESm2Po+FsZ2/e7AObVeKNOp; 25:LvCtdvftzKmmf9bxxB0FI0+b6pXJXfK+qWK8Fec1J6sUzWMLblbc1NPmTp9yUNXI11y38wbY5I6NYpkytX1l5lxhzWRfFIXzM+ir9aghaQjr3OEexn38ebrLeH08Ej+i4KEFdjXQG4DYrcbnPdwQwBFSAq9Weugo238pFwwZM/XfE5AHKXDCt2xG67yQlH2lc/tX0CYFD/dhBwixyF/1+L7BFtnyWJ9W+Jybh6J1jQL9HrnhimL50EyYIUovNmxu4cIX5VjnYnYCqMaKh2aibJmskY4ReQYtxRAv9C7+aieaEAG4g4T+l63npU19SQt72BsF84Mjv+rhjKhe0l/xmg==; 31:HG2I+8+i91cOwaZYf3C5fXe7EpVOIub1emON+YTAazcQ39IpcIuZmBSvY62kdWUK5pUD4hyWF0T7urpd4J3nP9ZdyCL5o5k96LEPr3KMoDsRhaw77P8r27d0o7zrs0vWnB4aEjU6t0MeJSb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-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)(3231254)(944501410)(52105095)(10201501046)(93006095)(3002001)(149027)(150027)(6041310)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:BYAPR07MB4902; BCL:0; PCL:0; RULEID:; SRVR:BYAPR07MB4902; X-Forefront-PRVS: 0703B549E4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(39380400002)(376002)(396003)(366004)(189003)(199004)(316002)(6666003)(110136005)(68736007)(2906002)(66066001)(54906003)(47776003)(6512007)(5660300001)(50466002)(72206003)(48376002)(97736004)(6116002)(3846002)(53936002)(16586007)(105586002)(478600001)(6486002)(106356001)(6506007)(36756003)(59450400001)(11346002)(956004)(25786009)(4326008)(50226002)(16526019)(186003)(81156014)(486006)(81166006)(8676002)(7736002)(26005)(8936002)(2616005)(476003)(386003)(44832011)(55236004)(52116002)(42882007)(51416003)(76176011)(446003)(305945005); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR07MB4902; H:ajoseph83.caveonetworks.com.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BYAPR07MB4902; 23:LTGagn4vrUxiqsJooWt6cJBan0SqQ6XAbH3l84fOl?= =?us-ascii?Q?PFcecY09aasoO0eKmZeLMwxSLvG3lJJ9kJkayZfnDmJCz8Pv9COfV6/2tD0+?= =?us-ascii?Q?oSgp8e9xrgCdXkZeaHGMZVYIw0oAD3hYs7F5SmO8VfNuonbUlQYd+v/X7WPm?= =?us-ascii?Q?vUNz+OvT5at/Fjm6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= =?us-ascii?Q?PQrC1kYT81VAtgP/gKKa0NJkiMyK3v9m9bcjsC0/zJMmKO4wTaDiwUN+pXfm?= =?us-ascii?Q?qKmM//VytfLFGoDOIi+0OlWneq6VtRALEoyaVNansqTm1wFl1UPa8K1+47cJ?= =?us-ascii?Q?fZqMooxk99GJA70tmJyBWU8Uht044IElhn3WfXDkmd20i4ifns5S1btrHn2r?= =?us-ascii?Q?QlkKlJT5pi/kfB+nygnkCjMHq/JV2YjkeRsRj4r7m6ylvaopmcOX2zWRj3f/?= =?us-ascii?B?Zz09?= X-Microsoft-Antispam-Message-Info: tJcEikPkMLF094Sb7sJOZDyzJ0/GKPHDvwV+EMcjIN4iZt1deHIsXAfe+BM1XCfXUFit0oUGo+N06q5ZoppKQX5MsuzfN73hT4cWBatP8/t9F4kB+PsxwkP5VPIR/CWVoJt+nMqhPRso9D4JWcINAmW98SC9y/cKeXBPpolHNhK+4syfVpld5phDD6vZdQpg X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4902; 6:dVLO8W4r2aGPaByymTgMgSy8gAVid5UoBNoq5M66X7rQ4e07Lvf7jfmTSNQQ8oYP59ViNcgfu/+nKGFXcsO37zOv1FryOM+ssxn+t8GnP7Gs576KLBGB6/G8YgyCL6YZQnJIDw82ipN5maEqCU89soY/BVlZGXFhtkiW5Dpta+PD3H18ithQySf2EZHtaNp9zCRrFuY69NF/bJFAr9hWhHBqKqb/Ut1h+8e2/cMBCCJtGBVU9gTb0U3ZF/iOSW3o7U02xyxzjRnWuQEoHlAqoqL+1VCpHj7QfPp/k8aWIoPXiQgrS3xDZnBM2zDJ+3E+aQOyZ4cM9nI1LO8ap6CQHgWRMnCIFH/wlZtioGHrxN6vGZej8Z8uPmfU+AvJoOqPaUUHEasIDpjHQ+IuuvZUfGh/FpGQtXHIKCsjViOkB410RXRxbzc40a0s5gA/an7L0cjsHTEgk7P6Synj4sxfOg==; 5:5r+tqKTRFfSkwqRfLLn2zy8uQTX+BiJ1R/USod39+EbXoQAjensELfp8fYpqGexZHDPS7ifJVAe0zLjUJ0/xA9eBQt6qN5OqCF+SarYmhvY2Bdkoh1+4EbMpI3kZQwHDylmW41rqGc2K+IUAhJO1INLkXOsAEyfqwti+7iJCwcs=; 24:pG15HcBMZBh1uViiLVEK0ZnppypHnEqrsannx3dHgBb6TabutumPIsSHS1NH/F36+YGHDwvUBpB/gvwjhsGAkmn8BXV8tVtvAjcSHwdnUM0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4902; 7:yyrtvoJKUK0DP8W1oHmdttIUsO87MbkMKiJgxUQWiMpYXvW0ins8cJqFpwCKfxPteLgkZmCKNkP4UY9/D90Dpy+oZCtKopWmseAwQGtgWolz1H9W+guX/9tgOZ43OUx50Nt5fKRkS/WE538eNBlzLRqco6gocgiCp3SLHMcVwBwYENULO0etLki6YYagSYCd1AgdBoOvOBVYpEq/vvMeHm268lmRyKMWTjswrAWYIJ24UFsZHHEPLaoCJCv5np4u X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jun 2018 10:19:08.1627 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 673f9480-9ebf-4ad8-ebfb-08d5d1e04518 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB4902 Subject: [dpdk-dev] [PATCH v1 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: Thu, 14 Jun 2018 10:19:13 -0000 v1: * Replaced 'unsigned' with 'unsigned int' 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..663c505 --- /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 int 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 int 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 int portid) +{ + unsigned int 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 int lcore_id; + unsigned int master_core_id; + uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc; + unsigned int 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 3e0269e..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 int 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