From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0076.outbound.protection.outlook.com [104.47.36.76]) by dpdk.org (Postfix) with ESMTP id 285701E3DB for ; Thu, 14 Jun 2018 13:50:14 +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=FYxO0GKA5R57ctOIUuMh/+ButdOn18MKlezRw5Qn0Bw=; b=bYblvJvk/haVJYjsfUp/WvRz24OjfbfjGh1nGf2nwW6OBhP5eWmlHuYLAYRDKYNdB81lNxUeJzMuR6fVDArzounaOj0o7VoEmpTH6Udpk8OE27UnZWsyvSvS1lOsIBscII5faB+aExngfb/HC+enKMy5kcvcO58zsCizx0g2mMA= 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 BN7PR07MB4898.namprd07.prod.outlook.com (2603:10b6:406:ef::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.863.16; Thu, 14 Jun 2018 11:50:10 +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 17:18:58 +0530 Message-Id: <1528976946-14396-8-git-send-email-anoob.joseph@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528976946-14396-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1528477766-15788-1-git-send-email-anoob.joseph@caviumnetworks.com> <1528976946-14396-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: PN1PR01CA0095.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00::11) To BN7PR07MB4898.namprd07.prod.outlook.com (2603:10b6:406:ef::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ba53a883-941e-4968-8738-08d5d1ecfcff X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(711020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:BN7PR07MB4898; X-Microsoft-Exchange-Diagnostics: 1; BN7PR07MB4898; 3:kkQIfoHKbJKnGhCieaOglOPUu6uko6GZf0nQuTi/Fbl3gMAoX/8AL9/j7pVeuIdZNxSGacZlqPHEhrXHuiABuY5PD1bnKiW0bjh7MD041fJxNqCBe81ofP6aB2PDwtREKr1pHw1jsorYoomHuY8LSX1LmsfHNdBBLfhAWl+4FFdGqDDgpOyzO7mLftQ5tTP6vnEuDkAGALqez7mjDco6O14SGf1lQLeuhwTm3YM6nxf6ysSWZXn32dQTo+Zu0pCu; 25:xTV8yzWoZXJPH1YOrigpWFh5BwgbeJH+uoI56BEsySAeBU9S68ioDI4ApVredimpy0f+Nd3Pbd2vzlAbg8ShSOn2oRil3YvExy0zRUe1VYYtbG6Fp4vMJib36mG60mB0/yCRYn3nGZkMJq6voBBVY5FDIzIkCAJZ+Jn7sYLcBDOnmns+14tLu86qSC5rfM/xHqmiGLp6H2nSvi2KlxJMWLnPsSjr8X3dPADR8f3uH2StQSJF2ILlTj2gRtioQZMwU1jZw+9LrS54W/aSPaxne8cXVp9BWOmserzlVEwchsEGX4y7Tu5PtDPoXWdSGygRt5IzMrtRKcc/dBT+ZAL9XQ==; 31:Bb+596c9rMFlJR79eQVaUmHtuEbjTi4cAfAurrMJ2k5ylVNZ5WlzvTy2ryWJOK1gLu6p+iaYVK+Qd9ZVDpTl1JFvDYo0HyPPtqsG7jiyRXKrO7ySpsJGx3wl17h8ma7HofaPOL5ooSrz8hBd/UH0T85kvXe8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Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231254)(944501410)(52105095)(93006095)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:BN7PR07MB4898; BCL:0; PCL:0; RULEID:; SRVR:BN7PR07MB4898; X-Forefront-PRVS: 0703B549E4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(39380400002)(396003)(376002)(346002)(366004)(199004)(189003)(446003)(956004)(2616005)(305945005)(6666003)(47776003)(476003)(54906003)(44832011)(53936002)(68736007)(486006)(110136005)(8936002)(8676002)(81156014)(16586007)(316002)(81166006)(25786009)(4326008)(7736002)(6116002)(3846002)(11346002)(97736004)(36756003)(106356001)(478600001)(105586002)(42882007)(52116002)(51416003)(26005)(16526019)(186003)(59450400001)(50226002)(66066001)(72206003)(6486002)(2906002)(55236004)(50466002)(6512007)(386003)(6506007)(5660300001)(76176011)(48376002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN7PR07MB4898; 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; BN7PR07MB4898; 23:rmy7J0TjFmeiJFPw5B+gYHN7upkpRd71cq04I8vcd?= =?us-ascii?Q?Fo/f2HQqoOuNPc4Wt3mvtb/8g71a2mez+7GR2d13X6y4rpQ+9wq20gluOGQ+?= =?us-ascii?Q?I+HRcn+ryO0a3pb8aVpwJaVho3pwXKuXKaS54QxXn4hYaYOA6YSKTWN5Ymgm?= =?us-ascii?Q?1x+Q9LMnOrz5laFCRvztpa4Z0FFZpeTAr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irG9VZN5vlDSmBPBe093ofDCinLfSiliwL+R6ToRc+Ora8hvglsxe35NH/68jM5Knff8nOEWgKyvpNv6jNtohq74T2AhGl6q1P9c00XgLd443lxSLc1/Xwc0=; 24:TwCy0MVuO3dJESXwIiv9N2k7XPJS56Se5b41z+ZGe7bvmGlqdfDUc++qza70cUmqgP46jhnA9iXCvSlFknw/cWbHpIJYogUBr3x9eDryLn4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN7PR07MB4898; 7:4AjEGAtmpukRBFy6KPnoLsAPtbwEof+QeHZcFmgryjx0crTLVtZk3DNUI/46b016kNXLjRc2Chb12VpehDOx6kidAARQ3dpbZDQV7f2Feheq3bXM7fDHWzHdlDhiBngIyWaS3yIVsOsHq3ucngOXOsz9sbxxz0scPyfAeFn1RfWNOb0Nn5OIv8j3Wr/KKuoUB9qlzebPI4bVV7XNDUkk7j88rPMp9yZVaaRf5uhXe7GDXgnqT/tDwUzT3xzf1ApH X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jun 2018 11:50:10.8850 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba53a883-941e-4968-8738-08d5d1ecfcff X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR07MB4898 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 11:50:15 -0000 Signed-off-by: Anoob Joseph --- v1: * Replaced 'unsigned' with 'unsigned int' 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