From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E402EA2EFC for ; Thu, 19 Sep 2019 12:14:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 460B71EE05; Thu, 19 Sep 2019 12:14:01 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 003DD1EDF6 for ; Thu, 19 Sep 2019 12:13:59 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x8JA5BZ5021411; Thu, 19 Sep 2019 03:13:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=4SdZBhG45U+gO89R87w4Ef4zdtop9ZEFwf6vAxNSHLs=; b=mAYnfE9bG4hl4hWB/8bUfKsafZ+jBIhCSs9gUhIeMZm0CgFMplIxjDboeaJArpBEt+PS k73qNGphvinYxo29zFCIOPH05nn7wQv3ETi/Oz+lfetplJJmgr2jsa9G2pkM0+Fvq+UM VZxpll51Hacly26wTXLVawj66RcJkE4eCHY4OUnUtp0SCjDgy+X6sBDYO11MMx2XKykN fWH/kMhv2QOvFiMPqR9tCD4AKQJf0PnFxS/Z+9X9ISwIJ2adUL6PmUJWKg2xxpuHJJPG Vf0uq76uFm778NRPQgXNc/Gshkd1rjbhj1IE0/PXb4RNJ+6ZpH1gBVR+Oiohh0sLmMiR ig== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0a-0016f401.pphosted.com with ESMTP id 2v3vcdtcwx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 19 Sep 2019 03:13:59 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 19 Sep 2019 03:13:58 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 19 Sep 2019 03:13:57 -0700 Received: from BG-LT7430.marvell.com (unknown [10.28.17.12]) by maili.marvell.com (Postfix) with ESMTP id C39C33F703F; Thu, 19 Sep 2019 03:13:54 -0700 (PDT) From: To: , , , Marko Kovacevic , Ori Kam , Radu Nicolau , Tomasz Kantecki , Sunil Kumar Kori , "Pavan Nikhilesh" CC: Date: Thu, 19 Sep 2019 15:43:38 +0530 Message-ID: <20190919101346.8832-3-pbhagavatula@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190919101346.8832-1-pbhagavatula@marvell.com> References: <20190919092603.5485-2-pbhagavatula@marvell.com> <20190919101346.8832-1-pbhagavatula@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-19_03:2019-09-18,2019-09-19 signatures=0 Subject: [dpdk-dev] [PATCH v3 02/10] examples/l2fwd-event: add infra for eventdev 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" From: Sunil Kumar Kori Add infra to select event device as a mode to process packets through command line arguments. Also, allow the user to select the schedule type to be either RTE_SCHED_TYPE_ORDERED or RTE_SCHED_TYPE_ATOMIC. Usage: `--mode="eventdev"` or `--mode="poll"` `--eventq-sync="ordered"` or `--eventq-sync="atomic"` Signed-off-by: Sunil Kumar Kori --- examples/l2fwd-event/Makefile | 1 + examples/l2fwd-event/l2fwd_eventdev.c | 107 ++++++++++++++++++++++++++ examples/l2fwd-event/l2fwd_eventdev.h | 62 +++++++++++++++ examples/l2fwd-event/main.c | 22 +++++- examples/l2fwd-event/meson.build | 3 +- 5 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 examples/l2fwd-event/l2fwd_eventdev.c create mode 100644 examples/l2fwd-event/l2fwd_eventdev.h diff --git a/examples/l2fwd-event/Makefile b/examples/l2fwd-event/Makefile index a156c4162..bfe0058a2 100644 --- a/examples/l2fwd-event/Makefile +++ b/examples/l2fwd-event/Makefile @@ -7,6 +7,7 @@ APP = l2fwd-event # all source are stored in SRCS-y SRCS-y := main.c +SRCS-y += l2fwd_eventdev.c # Build using pkg-config variables if possible ifeq ($(shell pkg-config --exists libdpdk && echo 0),0) diff --git a/examples/l2fwd-event/l2fwd_eventdev.c b/examples/l2fwd-event/l2fwd_eventdev.c new file mode 100644 index 000000000..19efb6d1e --- /dev/null +++ b/examples/l2fwd-event/l2fwd_eventdev.c @@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2019 Marvell International Ltd. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "l2fwd_common.h" +#include "l2fwd_eventdev.h" + +static void +parse_mode(const char *optarg) +{ + struct eventdev_resources *eventdev_rsrc = get_eventdev_rsrc(); + + if (!strncmp(optarg, "poll", 4)) + eventdev_rsrc->enabled = false; + else if (!strncmp(optarg, "eventdev", 8)) + eventdev_rsrc->enabled = true; +} + +static void +parse_eventq_sync(const char *optarg) +{ + struct eventdev_resources *eventdev_rsrc = get_eventdev_rsrc(); + + if (!strncmp(optarg, "ordered", 7)) + eventdev_rsrc->sync_mode = RTE_SCHED_TYPE_ORDERED; + else if (!strncmp(optarg, "atomic", 6)) + eventdev_rsrc->sync_mode = RTE_SCHED_TYPE_ATOMIC; +} + +static int +parse_eventdev_args(char **argv, int argc) +{ + const struct option eventdev_lgopts[] = { + {CMD_LINE_OPT_MODE, 1, 0, CMD_LINE_OPT_MODE_NUM}, + {CMD_LINE_OPT_EVENTQ_SYNC, 1, 0, CMD_LINE_OPT_EVENTQ_SYNC_NUM}, + {NULL, 0, 0, 0} + }; + char **argvopt = argv; + int32_t option_index; + int32_t opt; + + while ((opt = getopt_long(argc, argvopt, "", eventdev_lgopts, + &option_index)) != EOF) { + switch (opt) { + case CMD_LINE_OPT_MODE_NUM: + parse_mode(optarg); + break; + + case CMD_LINE_OPT_EVENTQ_SYNC_NUM: + parse_eventq_sync(optarg); + break; + + case '?': + /* skip other parameters except eventdev specific */ + break; + + default: + printf("Invalid eventdev parameter\n"); + return -1; + } + } + + return 0; +} + +void +eventdev_resource_setup(void) +{ + struct eventdev_resources *eventdev_rsrc = get_eventdev_rsrc(); + uint32_t service_id; + int32_t ret; + + /* Parse eventdev command line options */ + ret = parse_eventdev_args(eventdev_rsrc->args, eventdev_rsrc->nb_args); + if (ret < 0) + return; + + if (!rte_event_dev_count()) + rte_exit(EXIT_FAILURE, "No Eventdev found"); + /* Start event device service */ + ret = rte_event_dev_service_id_get(eventdev_rsrc->event_d_id, + &service_id); + if (ret != -ESRCH && ret != 0) + rte_exit(EXIT_FAILURE, "Error in starting eventdev"); + + rte_service_runstate_set(service_id, 1); + rte_service_set_runstate_mapped_check(service_id, 0); + eventdev_rsrc->service_id = service_id; + + /* Start event device */ + ret = rte_event_dev_start(eventdev_rsrc->event_d_id); + if (ret < 0) + rte_exit(EXIT_FAILURE, "Error in starting eventdev"); +} diff --git a/examples/l2fwd-event/l2fwd_eventdev.h b/examples/l2fwd-event/l2fwd_eventdev.h new file mode 100644 index 000000000..2e8d95e67 --- /dev/null +++ b/examples/l2fwd-event/l2fwd_eventdev.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2019 Marvell International Ltd. + */ + +#ifndef __L2FWD_EVENTDEV_H__ +#define __L2FWD_EVENTDEV_H__ + +#include +#include + +#include "l2fwd_common.h" + +#define CMD_LINE_OPT_MODE "mode" +#define CMD_LINE_OPT_EVENTQ_SYNC "eventq-sync" + +enum { + CMD_LINE_OPT_MODE_NUM = 265, + CMD_LINE_OPT_EVENTQ_SYNC_NUM, +}; + +struct eventdev_resources { + struct l2fwd_port_statistics *stats; + struct rte_mempool *pkt_pool; + uint64_t timer_period; + uint32_t *dst_ports; + uint32_t service_id; + uint32_t port_mask; + volatile bool *done; + uint8_t event_d_id; + uint8_t sync_mode; + uint8_t tx_mode_q; + uint8_t mac_updt; + uint8_t enabled; + uint8_t nb_args; + char **args; +}; + +static inline struct eventdev_resources * +get_eventdev_rsrc(void) +{ + static const char name[RTE_MEMZONE_NAMESIZE] = "l2fwd_event_rsrc"; + const struct rte_memzone *mz; + + mz = rte_memzone_lookup(name); + + if (mz != NULL) + return mz->addr; + + mz = rte_memzone_reserve(name, sizeof(struct eventdev_resources), 0, 0); + if (mz != NULL) { + memset(mz->addr, 0, sizeof(struct eventdev_resources)); + return mz->addr; + } + + rte_exit(EXIT_FAILURE, "Unable to allocate memory for eventdev cfg\n"); + + return NULL; +} + +void eventdev_resource_setup(void); + +#endif /* __L2FWD_EVENTDEV_H__ */ diff --git a/examples/l2fwd-event/main.c b/examples/l2fwd-event/main.c index cc47fa203..661f0833f 100644 --- a/examples/l2fwd-event/main.c +++ b/examples/l2fwd-event/main.c @@ -42,6 +42,7 @@ #include #include "l2fwd_common.h" +#include "l2fwd_eventdev.h" static volatile bool force_quit; @@ -288,7 +289,12 @@ l2fwd_usage(const char *prgname) " --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)\n" " When enabled:\n" " - The source MAC address is replaced by the TX port MAC address\n" - " - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n", + " - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n" + " --mode: Packet transfer mode for I/O, poll or eventdev\n" + " Default mode = eventdev\n" + " --eventq-sync:Event queue synchronization method,\n" + " ordered or atomic.\nDefault: atomic\n" + " Valid only if --mode=eventdev\n\n", prgname); } @@ -503,6 +509,7 @@ signal_handler(int signum) int main(int argc, char **argv) { + struct eventdev_resources *eventdev_rsrc; uint16_t nb_ports_available = 0; struct lcore_queue_conf *qconf; uint32_t nb_ports_in_mask = 0; @@ -524,6 +531,7 @@ main(int argc, char **argv) signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); + eventdev_rsrc = get_eventdev_rsrc(); /* parse application arguments (after the EAL ones) */ ret = l2fwd_parse_args(argc, argv); if (ret < 0) @@ -584,6 +592,17 @@ main(int argc, char **argv) if (l2fwd_pktmbuf_pool == NULL) rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n"); + eventdev_rsrc->port_mask = l2fwd_enabled_port_mask; + eventdev_rsrc->pkt_pool = l2fwd_pktmbuf_pool; + eventdev_rsrc->dst_ports = l2fwd_dst_ports; + eventdev_rsrc->timer_period = timer_period; + eventdev_rsrc->mac_updt = mac_updating; + eventdev_rsrc->stats = port_statistics; + eventdev_rsrc->done = &force_quit; + + /* Configure eventdev parameters if user has requested */ + eventdev_resource_setup(); + /* Initialize the port/queue configuration of each logical core */ RTE_ETH_FOREACH_DEV(portid) { /* skip ports that are not enabled */ @@ -610,7 +629,6 @@ main(int argc, char **argv) printf("Lcore %u: RX port %u\n", rx_lcore_id, portid); } - /* Initialise each port */ RTE_ETH_FOREACH_DEV(portid) { struct rte_eth_rxconf rxq_conf; diff --git a/examples/l2fwd-event/meson.build b/examples/l2fwd-event/meson.build index 16eadb0b4..b1ad48cc5 100644 --- a/examples/l2fwd-event/meson.build +++ b/examples/l2fwd-event/meson.build @@ -8,5 +8,6 @@ # DPDK instance, use 'make' sources = files( - 'main.c' + 'main.c', + 'l2fwd_eventdev.c' ) -- 2.17.1