From: Xueming Li <xuemingl@nvidia.com>
To: <dev@dpdk.org>
Cc: <xuemingl@nvidia.com>, Jerin Jacob <jerinjacobk@gmail.com>,
Ferruh Yigit <ferruh.yigit@intel.com>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
Thomas Monjalon <thomas@monjalon.net>,
Lior Margalit <lmargalit@nvidia.com>,
"Ananyev Konstantin" <konstantin.ananyev@intel.com>,
Xiaoyun Li <xiaoyun.li@intel.com>
Subject: [dpdk-dev] [PATCH v8 6/6] app/testpmd: add forwarding engine for shared Rx queue
Date: Mon, 18 Oct 2021 20:08:42 +0800 [thread overview]
Message-ID: <20211018120842.2058637-7-xuemingl@nvidia.com> (raw)
In-Reply-To: <20211018120842.2058637-1-xuemingl@nvidia.com>
To support shared Rx queue, this patch introduces dedicate forwarding
engine. The engine groups received packets by mbuf->port into sub-group,
updates stream statistics and simply frees packets.
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
app/test-pmd/meson.build | 1 +
app/test-pmd/shared_rxq_fwd.c | 148 ++++++++++++++++++++
app/test-pmd/testpmd.c | 1 +
app/test-pmd/testpmd.h | 1 +
doc/guides/testpmd_app_ug/run_app.rst | 1 +
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +-
6 files changed, 156 insertions(+), 1 deletion(-)
create mode 100644 app/test-pmd/shared_rxq_fwd.c
diff --git a/app/test-pmd/meson.build b/app/test-pmd/meson.build
index 98f3289bdfa..07042e45b12 100644
--- a/app/test-pmd/meson.build
+++ b/app/test-pmd/meson.build
@@ -21,6 +21,7 @@ sources = files(
'noisy_vnf.c',
'parameters.c',
'rxonly.c',
+ 'shared_rxq_fwd.c',
'testpmd.c',
'txonly.c',
'util.c',
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
new file mode 100644
index 00000000000..4e262b99bc7
--- /dev/null
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -0,0 +1,148 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2021 NVIDIA Corporation & Affiliates
+ */
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include <sys/queue.h>
+#include <sys/stat.h>
+
+#include <rte_common.h>
+#include <rte_byteorder.h>
+#include <rte_log.h>
+#include <rte_debug.h>
+#include <rte_cycles.h>
+#include <rte_memory.h>
+#include <rte_memcpy.h>
+#include <rte_launch.h>
+#include <rte_eal.h>
+#include <rte_per_lcore.h>
+#include <rte_lcore.h>
+#include <rte_atomic.h>
+#include <rte_branch_prediction.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+#include <rte_pci.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_string_fns.h>
+#include <rte_ip.h>
+#include <rte_udp.h>
+#include <rte_net.h>
+#include <rte_flow.h>
+
+#include "testpmd.h"
+
+/*
+ * Rx only sub-burst forwarding.
+ */
+static void
+forward_rx_only(uint16_t nb_rx, struct rte_mbuf **pkts_burst)
+{
+ rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
+}
+
+/**
+ * Get packet source stream by source port and queue.
+ * All streams of same shared Rx queue locates on same core.
+ */
+static struct fwd_stream *
+forward_stream_get(struct fwd_stream *fs, uint16_t port)
+{
+ streamid_t sm_id;
+ struct fwd_lcore *fc;
+ struct fwd_stream **fsm;
+ streamid_t nb_fs;
+
+ fc = fs->lcore;
+ fsm = &fwd_streams[fc->stream_idx];
+ nb_fs = fc->stream_nb;
+ for (sm_id = 0; sm_id < nb_fs; sm_id++) {
+ if (fsm[sm_id]->rx_port == port &&
+ fsm[sm_id]->rx_queue == fs->rx_queue)
+ return fsm[sm_id];
+ }
+ return NULL;
+}
+
+/**
+ * Forward packet by source port and queue.
+ */
+static void
+forward_sub_burst(struct fwd_stream *src_fs, uint16_t port, uint16_t nb_rx,
+ struct rte_mbuf **pkts)
+{
+ struct fwd_stream *fs = forward_stream_get(src_fs, port);
+
+ if (fs != NULL) {
+ fs->rx_packets += nb_rx;
+ forward_rx_only(nb_rx, pkts);
+ } else {
+ /* Source stream not found, drop all packets. */
+ src_fs->fwd_dropped += nb_rx;
+ while (nb_rx > 0)
+ rte_pktmbuf_free(pkts[--nb_rx]);
+ }
+}
+
+/**
+ * Forward packets from shared Rx queue.
+ *
+ * Source port of packets are identified by mbuf->port.
+ */
+static void
+forward_shared_rxq(struct fwd_stream *fs, uint16_t nb_rx,
+ struct rte_mbuf **pkts_burst)
+{
+ uint16_t i, nb_sub_burst, port, last_port;
+
+ nb_sub_burst = 0;
+ last_port = pkts_burst[0]->port;
+ /* Locate sub-burst according to mbuf->port. */
+ for (i = 0; i < nb_rx - 1; ++i) {
+ rte_prefetch0(pkts_burst[i + 1]);
+ port = pkts_burst[i]->port;
+ if (i > 0 && last_port != port) {
+ /* Forward packets with same source port. */
+ forward_sub_burst(fs, last_port, nb_sub_burst,
+ &pkts_burst[i - nb_sub_burst]);
+ nb_sub_burst = 0;
+ last_port = port;
+ }
+ nb_sub_burst++;
+ }
+ /* Last sub-burst. */
+ nb_sub_burst++;
+ forward_sub_burst(fs, last_port, nb_sub_burst,
+ &pkts_burst[nb_rx - nb_sub_burst]);
+}
+
+static void
+shared_rxq_fwd(struct fwd_stream *fs)
+{
+ struct rte_mbuf *pkts_burst[nb_pkt_per_burst];
+ uint16_t nb_rx;
+ uint64_t start_tsc = 0;
+
+ get_start_cycles(&start_tsc);
+ nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
+ nb_pkt_per_burst);
+ inc_rx_burst_stats(fs, nb_rx);
+ if (unlikely(nb_rx == 0))
+ return;
+ forward_shared_rxq(fs, nb_rx, pkts_burst);
+ get_end_cycles(fs, start_tsc);
+}
+
+struct fwd_engine shared_rxq_engine = {
+ .fwd_mode_name = "shared_rxq",
+ .port_fwd_begin = NULL,
+ .port_fwd_end = NULL,
+ .packet_fwd = shared_rxq_fwd,
+};
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index f3f81ef561f..11a85d92d9a 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -188,6 +188,7 @@ struct fwd_engine * fwd_engines[] = {
#ifdef RTE_LIBRTE_IEEE1588
&ieee1588_fwd_engine,
#endif
+ &shared_rxq_engine,
NULL,
};
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index f121a2da90c..f1fd607e365 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -299,6 +299,7 @@ extern struct fwd_engine five_tuple_swap_fwd_engine;
#ifdef RTE_LIBRTE_IEEE1588
extern struct fwd_engine ieee1588_fwd_engine;
#endif
+extern struct fwd_engine shared_rxq_engine;
extern struct fwd_engine * fwd_engines[]; /**< NULL terminated array. */
extern cmdline_parse_inst_t cmd_set_raw;
diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst
index ff5908dcd50..e4b97844ced 100644
--- a/doc/guides/testpmd_app_ug/run_app.rst
+++ b/doc/guides/testpmd_app_ug/run_app.rst
@@ -252,6 +252,7 @@ The command line options are:
tm
noisy
5tswap
+ shared-rxq
* ``--rss-ip``
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 8ead7a4a712..499874187f2 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -314,7 +314,7 @@ set fwd
Set the packet forwarding mode::
testpmd> set fwd (io|mac|macswap|flowgen| \
- rxonly|txonly|csum|icmpecho|noisy|5tswap) (""|retry)
+ rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq) (""|retry)
``retry`` can be specified for forwarding engines except ``rx_only``.
@@ -357,6 +357,9 @@ The available information categories are:
L4 swaps the source port and destination port of transport layer (TCP and UDP).
+* ``shared-rxq``: Receive only for shared Rx queue.
+ Resolve packet source port from mbuf and update stream statistics accordingly.
+
Example::
testpmd> set fwd rxonly
--
2.33.0
next prev parent reply other threads:[~2021-10-18 12:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-18 12:08 [dpdk-dev] [PATCH v8 0/6] ethdev: introduce " Xueming Li
2021-10-18 12:08 ` [dpdk-dev] [PATCH v8 1/6] " Xueming Li
2021-10-18 12:08 ` [dpdk-dev] [PATCH v8 2/6] app/testpmd: dump device capability and Rx domain info Xueming Li
2021-10-18 12:08 ` [dpdk-dev] [PATCH v8 3/6] app/testpmd: new parameter to enable shared Rx queue Xueming Li
2021-10-18 12:08 ` [dpdk-dev] [PATCH v8 4/6] app/testpmd: dump port info for " Xueming Li
2021-10-18 12:08 ` [dpdk-dev] [PATCH v8 5/6] app/testpmd: force shared Rx queue polled on same core Xueming Li
2021-10-18 12:08 ` Xueming Li [this message]
2021-10-18 13:05 ` [dpdk-dev] [PATCH v8 0/6] ethdev: introduce shared Rx queue Xueming(Steven) Li
-- strict thread matches above, loose matches on Subject: below --
2021-07-27 3:42 [dpdk-dev] [RFC] " Xueming Li
2021-10-18 12:59 ` [dpdk-dev] [PATCH v8 0/6] " Xueming Li
2021-10-18 12:59 ` [dpdk-dev] [PATCH v8 6/6] app/testpmd: add forwarding engine for " Xueming Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211018120842.2058637-7-xuemingl@nvidia.com \
--to=xuemingl@nvidia.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=jerinjacobk@gmail.com \
--cc=konstantin.ananyev@intel.com \
--cc=lmargalit@nvidia.com \
--cc=thomas@monjalon.net \
--cc=viacheslavo@nvidia.com \
--cc=xiaoyun.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).