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 BD612A2EDB for ; Wed, 2 Oct 2019 22:59:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E22431BFA7; Wed, 2 Oct 2019 22:58:33 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id C4A0E1BF67 for ; Wed, 2 Oct 2019 22:58:32 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x92KsWdR015442; Wed, 2 Oct 2019 13:58:32 -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=BjJZtOAyu3d0e4WABIX+tL/u+W+tn2W1oSib5Ezgwgk=; b=YzeOHpziVqhKuXhx1HfuKd3JokH4r5sSnEipZCqmqhPQS0wY24G71em83EsZgXocopf6 DNiCyt/n+3C6krdomcYFqkBY1+4r+YREy/IINtRSZzTI86NarjHpvHm9Qusx1DYjkLR2 zofDp0a3IiTn/0T7ZL20oQuYluKqQYTm/Tx6hNf2+yvybd/BWRGW0rE2a0LYEBL9GCLB dG4OErs1xtj7QSFJhixIj69X4rdXb86T0xWSnLVcCLJtr2LOkskKXYy1HFaNi8aa0zUC reAMt1dmNSIAW+vZJSUQAm24F5ANZjWEGmcXmTp6jhX903JrddDKVscWkaGtda4+4uB/ mQ== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2vd0ya0kth-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 02 Oct 2019 13:58:32 -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; Wed, 2 Oct 2019 13:58:30 -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; Wed, 2 Oct 2019 13:58:30 -0700 Received: from BG-LT7430.marvell.com (unknown [10.28.17.68]) by maili.marvell.com (Postfix) with ESMTP id 26E6D3F7040; Wed, 2 Oct 2019 13:58:26 -0700 (PDT) From: To: , , , Marko Kovacevic , Ori Kam , Radu Nicolau , Tomasz Kantecki , Sunil Kumar Kori , "Pavan Nikhilesh" CC: Date: Thu, 3 Oct 2019 02:27:52 +0530 Message-ID: <20191002205754.11746-9-pbhagavatula@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191002205754.11746-1-pbhagavatula@marvell.com> References: <20190924094209.3827-1-pbhagavatula@marvell.com> <20191002205754.11746-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.95,1.0.8 definitions=2019-10-02_08:2019-10-01,2019-10-02 signatures=0 Subject: [dpdk-dev] [PATCH v5 08/10] examples/l2fwd-event: add eventdev main loop 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: Pavan Nikhilesh Add event dev main loop based on enabled l2fwd options and eventdev capabilities. Signed-off-by: Pavan Nikhilesh --- examples/l2fwd-event/l2fwd_common.c | 6 + examples/l2fwd-event/l2fwd_common.h | 2 + examples/l2fwd-event/l2fwd_event.c | 294 ++++++++++++++++++++++++++++ examples/l2fwd-event/l2fwd_event.h | 2 + examples/l2fwd-event/main.c | 6 +- 5 files changed, 309 insertions(+), 1 deletion(-) diff --git a/examples/l2fwd-event/l2fwd_common.c b/examples/l2fwd-event/l2fwd_common.c index 213652d72..40e933c91 100644 --- a/examples/l2fwd-event/l2fwd_common.c +++ b/examples/l2fwd-event/l2fwd_common.c @@ -65,6 +65,12 @@ l2fwd_event_init_ports(struct l2fwd_resources *l2fwd_rsrc) uint16_t port_id; int ret; + if (l2fwd_rsrc->event_mode) { + port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS; + port_conf.rx_adv_conf.rss_conf.rss_key = NULL; + port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP; + } + /* Initialise each port */ RTE_ETH_FOREACH_DEV(port_id) { struct rte_eth_conf local_port_conf = port_conf; diff --git a/examples/l2fwd-event/l2fwd_common.h b/examples/l2fwd-event/l2fwd_common.h index cdafa52c7..852c6d321 100644 --- a/examples/l2fwd-event/l2fwd_common.h +++ b/examples/l2fwd-event/l2fwd_common.h @@ -114,7 +114,9 @@ l2fwd_get_rsrc(void) memset(l2fwd_rsrc, 0, sizeof(struct l2fwd_resources)); l2fwd_rsrc->mac_updating = true; + l2fwd_rsrc->event_mode = true; l2fwd_rsrc->rx_queue_per_lcore = 1; + l2fwd_rsrc->sched_type = RTE_SCHED_TYPE_ATOMIC; l2fwd_rsrc->timer_period = 10 * rte_get_timer_hz(); return mz->addr; diff --git a/examples/l2fwd-event/l2fwd_event.c b/examples/l2fwd-event/l2fwd_event.c index adba40069..df0b56773 100644 --- a/examples/l2fwd-event/l2fwd_event.c +++ b/examples/l2fwd-event/l2fwd_event.c @@ -17,6 +17,12 @@ #include "l2fwd_event.h" +#define L2FWD_EVENT_SINGLE 0x1 +#define L2FWD_EVENT_BURST 0x2 +#define L2FWD_EVENT_TX_DIRECT 0x4 +#define L2FWD_EVENT_TX_ENQ 0x8 +#define L2FWD_EVENT_UPDT_MAC 0x10 + static inline int l2fwd_event_service_enable(uint32_t service_id) { @@ -128,11 +134,289 @@ l2fwd_event_capability_setup(struct l2fwd_event_resources *event_rsrc) l2fwd_event_set_internal_port_ops(&event_rsrc->ops); } +static __rte_noinline int +l2fwd_get_free_event_port(struct l2fwd_event_resources *event_rsrc) +{ + static int index; + int port_id; + + rte_spinlock_lock(&event_rsrc->evp.lock); + if (index >= event_rsrc->evp.nb_ports) { + printf("No free event port is available\n"); + return -1; + } + + port_id = event_rsrc->evp.event_p_id[index]; + index++; + rte_spinlock_unlock(&event_rsrc->evp.lock); + + return port_id; +} + +static __rte_always_inline void +l2fwd_event_loop_single(struct l2fwd_resources *l2fwd_rsrc, + const uint32_t flags) +{ + const uint8_t is_master = rte_get_master_lcore() == rte_lcore_id(); + struct l2fwd_event_resources *event_rsrc = l2fwd_rsrc->event_rsrc; + const int port_id = l2fwd_get_free_event_port(event_rsrc); + uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0; + const uint64_t timer_period = l2fwd_rsrc->timer_period; + const uint8_t tx_q_id = event_rsrc->evq.event_q_id[ + event_rsrc->evq.nb_queues - 1]; + const uint8_t event_d_id = event_rsrc->event_d_id; + struct rte_mbuf *mbuf; + uint16_t dst_port; + struct rte_event ev; + + if (port_id < 0) + return; + + printf("%s(): entering eventdev main loop on lcore %u\n", __func__, + rte_lcore_id()); + + while (!l2fwd_rsrc->force_quit) { + /* if timer is enabled */ + if (is_master && timer_period > 0) { + cur_tsc = rte_rdtsc(); + diff_tsc = cur_tsc - prev_tsc; + + /* advance the timer */ + timer_tsc += diff_tsc; + + /* if timer has reached its timeout */ + if (unlikely(timer_tsc >= timer_period)) { + print_stats(l2fwd_rsrc); + /* reset the timer */ + timer_tsc = 0; + } + prev_tsc = cur_tsc; + } + + /* Read packet from eventdev */ + if (!rte_event_dequeue_burst(event_d_id, port_id, &ev, 1, 0)) + continue; + + + mbuf = ev.mbuf; + dst_port = l2fwd_rsrc->dst_ports[mbuf->port]; + rte_prefetch0(rte_pktmbuf_mtod(mbuf, void *)); + + if (timer_period > 0) + __atomic_fetch_add( + &l2fwd_rsrc->port_stats[mbuf->port].rx, + 1, __ATOMIC_RELAXED); + + mbuf->port = dst_port; + if (flags & L2FWD_EVENT_UPDT_MAC) + l2fwd_mac_updating(mbuf, dst_port, + &l2fwd_rsrc->eth_addr[dst_port]); + + if (flags & L2FWD_EVENT_TX_ENQ) { + ev.queue_id = tx_q_id; + ev.op = RTE_EVENT_OP_FORWARD; + while (rte_event_enqueue_burst(event_d_id, port_id, + &ev, 1) && + !l2fwd_rsrc->force_quit) + ; + } + + if (flags & L2FWD_EVENT_TX_DIRECT) { + rte_event_eth_tx_adapter_txq_set(mbuf, 0); + while (!rte_event_eth_tx_adapter_enqueue(event_d_id, + port_id, + &ev, 1) && + !l2fwd_rsrc->force_quit) + ; + } + + if (timer_period > 0) + __atomic_fetch_add( + &l2fwd_rsrc->port_stats[mbuf->port].tx, + 1, __ATOMIC_RELAXED); + } +} + +static __rte_always_inline void +l2fwd_event_loop_burst(struct l2fwd_resources *l2fwd_rsrc, + const uint32_t flags) +{ + const uint8_t is_master = rte_get_master_lcore() == rte_lcore_id(); + struct l2fwd_event_resources *event_rsrc = l2fwd_rsrc->event_rsrc; + const int port_id = l2fwd_get_free_event_port(event_rsrc); + uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0; + const uint64_t timer_period = l2fwd_rsrc->timer_period; + const uint8_t tx_q_id = event_rsrc->evq.event_q_id[ + event_rsrc->evq.nb_queues - 1]; + const uint8_t event_d_id = event_rsrc->event_d_id; + const uint8_t deq_len = event_rsrc->deq_depth; + struct rte_event ev[MAX_PKT_BURST]; + struct rte_mbuf *mbuf; + uint16_t nb_rx, nb_tx; + uint16_t dst_port; + uint8_t i; + + if (port_id < 0) + return; + + printf("%s(): entering eventdev main loop on lcore %u\n", __func__, + rte_lcore_id()); + + while (!l2fwd_rsrc->force_quit) { + /* if timer is enabled */ + if (is_master && timer_period > 0) { + cur_tsc = rte_rdtsc(); + diff_tsc = cur_tsc - prev_tsc; + + /* advance the timer */ + timer_tsc += diff_tsc; + + /* if timer has reached its timeout */ + if (unlikely(timer_tsc >= timer_period)) { + print_stats(l2fwd_rsrc); + /* reset the timer */ + timer_tsc = 0; + } + prev_tsc = cur_tsc; + } + + /* Read packet from eventdev */ + nb_rx = rte_event_dequeue_burst(event_d_id, port_id, ev, + deq_len, 0); + if (nb_rx == 0) + continue; + + + for (i = 0; i < nb_rx; i++) { + mbuf = ev[i].mbuf; + dst_port = l2fwd_rsrc->dst_ports[mbuf->port]; + rte_prefetch0(rte_pktmbuf_mtod(mbuf, void *)); + + if (timer_period > 0) { + __atomic_fetch_add( + &l2fwd_rsrc->port_stats[mbuf->port].rx, + 1, __ATOMIC_RELAXED); + __atomic_fetch_add( + &l2fwd_rsrc->port_stats[mbuf->port].tx, + 1, __ATOMIC_RELAXED); + } + mbuf->port = dst_port; + if (flags & L2FWD_EVENT_UPDT_MAC) + l2fwd_mac_updating(mbuf, dst_port, + &l2fwd_rsrc->eth_addr[ + dst_port]); + + if (flags & L2FWD_EVENT_TX_ENQ) { + ev[i].queue_id = tx_q_id; + ev[i].op = RTE_EVENT_OP_FORWARD; + } + + if (flags & L2FWD_EVENT_TX_DIRECT) + rte_event_eth_tx_adapter_txq_set(mbuf, 0); + + } + + if (flags & L2FWD_EVENT_TX_ENQ) { + nb_tx = rte_event_enqueue_burst(event_d_id, port_id, + ev, nb_rx); + while (nb_tx < nb_rx && !l2fwd_rsrc->force_quit) + nb_tx += rte_event_enqueue_burst(event_d_id, + port_id, ev + nb_tx, + nb_rx - nb_tx); + } + + if (flags & L2FWD_EVENT_TX_DIRECT) { + nb_tx = rte_event_eth_tx_adapter_enqueue(event_d_id, + port_id, ev, + nb_rx); + while (nb_tx < nb_rx && !l2fwd_rsrc->force_quit) + nb_tx += rte_event_eth_tx_adapter_enqueue( + event_d_id, port_id, + ev + nb_tx, nb_rx - nb_tx); + } + } +} + +static __rte_always_inline void +l2fwd_event_loop(struct l2fwd_resources *l2fwd_rsrc, + const uint32_t flags) +{ + if (flags & L2FWD_EVENT_SINGLE) + l2fwd_event_loop_single(l2fwd_rsrc, flags); + if (flags & L2FWD_EVENT_BURST) + l2fwd_event_loop_burst(l2fwd_rsrc, flags); +} + +static void __rte_noinline +l2fwd_event_main_loop_tx_d(struct l2fwd_resources *l2fwd_rsrc) +{ + l2fwd_event_loop(l2fwd_rsrc, + L2FWD_EVENT_TX_DIRECT | L2FWD_EVENT_SINGLE); +} + +static void __rte_noinline +l2fwd_event_main_loop_tx_d_brst(struct l2fwd_resources *l2fwd_rsrc) +{ + l2fwd_event_loop(l2fwd_rsrc, L2FWD_EVENT_TX_DIRECT | L2FWD_EVENT_BURST); +} + +static void __rte_noinline +l2fwd_event_main_loop_tx_q(struct l2fwd_resources *l2fwd_rsrc) +{ + l2fwd_event_loop(l2fwd_rsrc, L2FWD_EVENT_TX_ENQ | L2FWD_EVENT_SINGLE); +} + +static void __rte_noinline +l2fwd_event_main_loop_tx_q_brst(struct l2fwd_resources *l2fwd_rsrc) +{ + l2fwd_event_loop(l2fwd_rsrc, L2FWD_EVENT_TX_ENQ | L2FWD_EVENT_BURST); +} + +static void __rte_noinline +l2fwd_event_main_loop_tx_d_mac(struct l2fwd_resources *l2fwd_rsrc) +{ + l2fwd_event_loop(l2fwd_rsrc, L2FWD_EVENT_UPDT_MAC | + L2FWD_EVENT_TX_DIRECT | L2FWD_EVENT_SINGLE); +} + +static void __rte_noinline +l2fwd_event_main_loop_tx_d_brst_mac(struct l2fwd_resources *l2fwd_rsrc) +{ + l2fwd_event_loop(l2fwd_rsrc, L2FWD_EVENT_UPDT_MAC | + L2FWD_EVENT_TX_DIRECT | L2FWD_EVENT_BURST); +} + +static void __rte_noinline +l2fwd_event_main_loop_tx_q_mac(struct l2fwd_resources *l2fwd_rsrc) +{ + l2fwd_event_loop(l2fwd_rsrc, L2FWD_EVENT_UPDT_MAC | + L2FWD_EVENT_TX_ENQ | L2FWD_EVENT_SINGLE); +} + +static void __rte_noinline +l2fwd_event_main_loop_tx_q_brst_mac(struct l2fwd_resources *l2fwd_rsrc) +{ + l2fwd_event_loop(l2fwd_rsrc, L2FWD_EVENT_UPDT_MAC | + L2FWD_EVENT_TX_ENQ | L2FWD_EVENT_BURST); +} + void l2fwd_event_resource_setup(struct l2fwd_resources *l2fwd_rsrc) { + /* [MAC_UPDT][TX_MODE][BURST] */ + const event_loop_cb event_loop[2][2][2] = { + [0][0][0] = l2fwd_event_main_loop_tx_d, + [0][0][1] = l2fwd_event_main_loop_tx_d_brst, + [0][1][0] = l2fwd_event_main_loop_tx_q, + [0][1][1] = l2fwd_event_main_loop_tx_q_brst, + [1][0][0] = l2fwd_event_main_loop_tx_d_mac, + [1][0][1] = l2fwd_event_main_loop_tx_d_brst_mac, + [1][1][0] = l2fwd_event_main_loop_tx_q_mac, + [1][1][1] = l2fwd_event_main_loop_tx_q_brst_mac, + }; struct l2fwd_event_resources *event_rsrc; uint32_t event_queue_cfg; + int ret; if (!rte_event_dev_count()) rte_exit(EXIT_FAILURE, "No Eventdev found\n"); @@ -158,4 +442,14 @@ l2fwd_event_resource_setup(struct l2fwd_resources *l2fwd_rsrc) /* Rx/Tx adapters configuration */ event_rsrc->ops.adapter_setup(l2fwd_rsrc); + + /* Start event device */ + ret = rte_event_dev_start(event_rsrc->event_d_id); + if (ret < 0) + rte_exit(EXIT_FAILURE, "Error in starting eventdev"); + + event_rsrc->ops.l2fwd_event_loop = event_loop + [l2fwd_rsrc->mac_updating] + [event_rsrc->tx_mode_q] + [event_rsrc->has_burst]; } diff --git a/examples/l2fwd-event/l2fwd_event.h b/examples/l2fwd-event/l2fwd_event.h index e0c589f93..cef7b5d1a 100644 --- a/examples/l2fwd-event/l2fwd_event.h +++ b/examples/l2fwd-event/l2fwd_event.h @@ -18,6 +18,7 @@ typedef void (*event_port_setup_cb)(struct l2fwd_resources *l2fwd_rsrc); typedef void (*event_queue_setup_cb)(struct l2fwd_resources *l2fwd_rsrc, uint32_t event_queue_cfg); typedef void (*adapter_setup_cb)(struct l2fwd_resources *l2fwd_rsrc); +typedef void (*event_loop_cb)(struct l2fwd_resources *l2fwd_rsrc); struct event_queues { uint8_t *event_q_id; @@ -47,6 +48,7 @@ struct event_setup_ops { event_queue_setup_cb event_queue_setup; event_port_setup_cb event_port_setup; adapter_setup_cb adapter_setup; + event_loop_cb l2fwd_event_loop; }; struct l2fwd_event_resources { diff --git a/examples/l2fwd-event/main.c b/examples/l2fwd-event/main.c index 3c27bfb4f..958a6e0b7 100644 --- a/examples/l2fwd-event/main.c +++ b/examples/l2fwd-event/main.c @@ -212,8 +212,12 @@ l2fwd_launch_one_lcore(void *args) { struct l2fwd_resources *l2fwd_rsrc = args; struct l2fwd_poll_resources *poll_rsrc = l2fwd_rsrc->poll_rsrc; + struct l2fwd_event_resources *event_rsrc = l2fwd_rsrc->event_rsrc; - poll_rsrc->poll_main_loop(l2fwd_rsrc); + if (l2fwd_rsrc->event_mode) + event_rsrc->ops.l2fwd_event_loop(l2fwd_rsrc); + else + poll_rsrc->poll_main_loop(l2fwd_rsrc); return 0; } -- 2.17.1