From patchwork Wed Jul 11 06:07:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anoob Joseph X-Patchwork-Id: 42782 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 26A5D1B470; Wed, 11 Jul 2018 08:08:12 +0200 (CEST) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0082.outbound.protection.outlook.com [104.47.36.82]) by dpdk.org (Postfix) with ESMTP id 32BE21B4B8 for ; Wed, 11 Jul 2018 08:08:10 +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=TL9v8IraDOTkk6gXrXwk+rn8kR0O53bMsvLolUrcvFs=; b=Ek/8sE3wukOw7E9k6soOPYAjP0f3uOepfkhevsoaJLhIzKE36TXjCuly4oxGFWD1ON3/y0sUZP0M0QTKFba8LjMjj/a1cNiax3+KTFysVFzUNQRqSBvHqOFCxsa5RPRCDloSiGAeKwAWwHj1XfoRUpEjgyrS1sOO5KkJoCdTzJE= 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.930.21; Wed, 11 Jul 2018 06:08:06 +0000 From: Anoob Joseph To: Bruce Richardson , Pablo de Lara Cc: Anoob Joseph , Jerin Jacob , Narayana Prasad , dev@dpdk.org Date: Wed, 11 Jul 2018 11:37:20 +0530 Message-Id: <1531289248-20025-5-git-send-email-anoob.joseph@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531289248-20025-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1528976946-14396-1-git-send-email-anoob.joseph@caviumnetworks.com> <1531289248-20025-1-git-send-email-anoob.joseph@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: BMXPR01CA0027.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:c::13) To BN7PR07MB4898.namprd07.prod.outlook.com (2603:10b6:406:ef::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9a8198a1-633f-4202-9004-08d5e6f4ac83 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:BN7PR07MB4898; X-Microsoft-Exchange-Diagnostics: 1; BN7PR07MB4898; 3:DWa49BFmNHwIq7+aMRKjA1A/I/m2rvEyZ/LLpigI9sWjGYR+3/6NQx8xr0ipDQVG0FKA7mcJnkT7FLBOF35La/EVNJaXxzIcYfnIcHCqs29BG8qAJ0nN9vH5eTepoLENQePyXK39Quug6jNCZThjAzKoGo3Ri+F9MCv1iotUtjSdg0lQHzkAILolkrsDk0jr+PCoM25Pzb36jPeeTpuBCKBOI5UAFIcttTkN9o9Ws4DbkQHCBug168tEfBR0b0j9; 25:jIvJaVvt/UHcayyvMi3zsx/yliWaGyLSLjr8ZIWN3o8ALHerQeedJ85N9SejUEiKaOgNJMivNML3U0JpnrZPoMcRGL45CcivnXYdralw0IlwmE+etz9KKodkFumhV+LpH/8A3swLDVhh532JPHpAFsumAs2mq0r7za0bt96FGdnKE4rONpyXMWY66x/vah6ONBYYKH35ud22lMQMtl0OFF7YZRASCHyPcCXQhN+jcDng8j6Mg5LU35pxUx4NfQOOhsem1Qkh7O4vU90PW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YhMTaN0RtI8ZZNXxYzaGIGv3TkRYfCs7nODn4tk0GwB+nJYH3UB4i9GPW5dNvII1twJ1vHvRVjlOzNUUu/hgIEln1VgVgJ66zY0SRimo7jniQbOE79a0KDvGEXUsZbQGjZL5rFzvk/g0ATxK9tWcS8tZjXmfjo+TmPQfKu9ychoII/VMQSxIR8mqdRsHSGOuYnGFbOkmTXv0t7RzQ== 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)(8121501046)(5005006)(3231311)(944501410)(52105095)(10201501046)(93006095)(3002001)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:BN7PR07MB4898; BCL:0; PCL:0; RULEID:; SRVR:BN7PR07MB4898; X-Forefront-PRVS: 0730093765 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(376002)(136003)(39860400002)(366004)(396003)(189003)(199004)(68736007)(81166006)(8676002)(81156014)(44832011)(50466002)(6666003)(25786009)(6512007)(7736002)(4326008)(6486002)(48376002)(8936002)(14444005)(2906002)(3846002)(478600001)(72206003)(305945005)(6116002)(486006)(16586007)(2616005)(54906003)(110136005)(316002)(36756003)(476003)(956004)(446003)(11346002)(47776003)(26005)(42882007)(52116002)(105586002)(186003)(76176011)(16526019)(66066001)(106356001)(51416003)(97736004)(6506007)(55236004)(50226002)(53936002)(5660300001)(386003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN7PR07MB4898; 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; BN7PR07MB4898; 23:RtA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HP5B2UCyDw==; 5:Nz4itIq31iq3sf88wSfQrLAqZSKGS9cj+o5bv/CYyDIfiAKWTfGqxwQEVMOQH4QO18SzLfapCmEQihdo7w52a+1AOfAPZXXG7R8twdtlGi6y3kFAVmKgOMCeUND/MG75corlTkGGLNZUASBrZYgZGRQKPprXwPH4Gr4fj4m+PVk=; 24:SHhCGIoWvt2xAahGEpsIPqTh4A1Ti7rYftWt7wh4eSTMWyBCHFK95lToaHqJGqBjGtKvW1AgzwOIRCMTwT/60vqsTBjUyhpt12OmojPSi98= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN7PR07MB4898; 7:jCKPz21XPpJw1XbfoUh3um9Hgy1uA8obm/YdQcBLOChJVilAYibAmtjpo3ffKwI9wL2oHDZ6XjcZWmBkw8ik0aw2fxoD2VbGk0kjP+hVfSblJsxNcyTtOOF1O1NSd6/TsiIIo7WW4aAnLvs9RVhj+PxaTj2pFP0L8BmzFWkxZcJqtPdh7e6cC5t8ReFkODBo63QPM0sAJOscMpwyZqNDj0hsIkVabGLc54zni02TmSuXposuiep9hRkrpEOI7jQz X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2018 06:08:06.5622 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9a8198a1-633f-4202-9004-08d5e6f4ac83 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 v2 04/12] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Anoob Joseph --- v2: * Merged checkpatch fix patches 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 | 186 +-------------------------------- 4 files changed, 245 insertions(+), 185 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 a6089a1..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,191 +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; - 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); - - } - - 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 == rte_get_master_lcore()) { - 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)