DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: Ferruh Yigit <ferruh.yigit@amd.com>,
	Aman Singh <aman.deep.singh@intel.com>,
	Yuying Zhang <yuying.zhang@intel.com>,
	Robin Jarry <rjarry@redhat.com>
Subject: [PATCH v2 7/9] app/testpmd: factorize fwd engine init
Date: Mon, 20 Feb 2023 17:41:01 +0100	[thread overview]
Message-ID: <20230220164103.3041538-8-david.marchand@redhat.com> (raw)
In-Reply-To: <20230220164103.3041538-1-david.marchand@redhat.com>

Reduce code duplication by introducing a helper that takes care of
initialising the fs object.

While at it, remove unneeded initialisation of fwd_engine empty fields.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Changes since v1:
- updated ieee1588,

---
 app/test-pmd/5tswap.c         | 16 +---------------
 app/test-pmd/csumonly.c       | 16 +---------------
 app/test-pmd/flowgen.c        | 15 +--------------
 app/test-pmd/icmpecho.c       | 16 +---------------
 app/test-pmd/ieee1588fwd.c    |  8 +-------
 app/test-pmd/iofwd.c          | 16 +---------------
 app/test-pmd/macfwd.c         | 16 +---------------
 app/test-pmd/macswap.c        | 16 +---------------
 app/test-pmd/noisy_vnf.c      | 14 +-------------
 app/test-pmd/rxonly.c         |  2 --
 app/test-pmd/shared_rxq_fwd.c |  2 --
 app/test-pmd/testpmd.c        | 10 ++++++++++
 app/test-pmd/testpmd.h        |  2 ++
 app/test-pmd/txonly.c         |  1 -
 14 files changed, 21 insertions(+), 129 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 0a3a897e7b..7b5f58f4d4 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -180,22 +180,8 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_5tuple_swap(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine five_tuple_swap_fwd_engine = {
 	.fwd_mode_name  = "5tswap",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_5tuple_swap,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_5tuple_swap,
 };
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 07850501f4..f72e2d74c7 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1201,22 +1201,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_checksum_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine csum_fwd_engine = {
 	.fwd_mode_name  = "csum",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_checksum_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_checksum_forward,
 };
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index b3bd4f7c65..6f42019353 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -199,22 +199,9 @@ flowgen_begin(portid_t pi)
 	return 0;
 }
 
-static void
-flowgen_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine flow_gen_engine = {
 	.fwd_mode_name  = "flowgen",
 	.port_fwd_begin = flowgen_begin,
-	.port_fwd_end   = NULL,
-	.stream_init    = flowgen_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_flow_gen,
 };
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 5ef1116141..eba8b99f1e 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -507,22 +507,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-icmpecho_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine icmp_echo_engine = {
 	.fwd_mode_name  = "icmpecho",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = icmpecho_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = reply_to_icmp_echo_rqsts,
 };
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 103c01fcb7..fd8ba27b2f 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -215,16 +215,10 @@ port_ieee1588_fwd_end(portid_t pi)
 static void
 port_ieee1588_stream_init(struct fwd_stream *fs)
 {
-	bool rx_stopped, tx_stopped;
-
 	/* Force transmission on reception port */
 	fs->tx_port = fs->rx_port;
 
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
+	common_fwd_stream_init(fs);
 }
 
 struct fwd_engine ieee1588_fwd_engine = {
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 9d0af5f667..12be06fa79 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -82,22 +82,8 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine io_fwd_engine = {
 	.fwd_mode_name  = "io",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_io_forward,
 };
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index 3a840247c7..953d9ea089 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -113,22 +113,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_mac_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine mac_fwd_engine = {
 	.fwd_mode_name  = "mac",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_mac_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_mac_forward,
 };
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 14b3eefffd..062542dc53 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -92,22 +92,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_mac_swap(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine mac_swap_engine = {
 	.fwd_mode_name  = "macswap",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_mac_swap,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_mac_swap,
 };
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 396fdd7814..7bcab84db3 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -278,22 +278,10 @@ noisy_fwd_begin(portid_t pi)
 	return 0;
 }
 
-static void
-stream_init_noisy_vnf(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine noisy_vnf_engine = {
 	.fwd_mode_name  = "noisy",
 	.port_fwd_begin = noisy_fwd_begin,
 	.port_fwd_end   = noisy_fwd_end,
-	.stream_init    = stream_init_noisy_vnf,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_noisy_vnf,
 };
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index ad4597cf9a..d4bff9b5ea 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -71,8 +71,6 @@ stream_init_receive(struct fwd_stream *fs)
 
 struct fwd_engine rx_only_engine = {
 	.fwd_mode_name  = "rxonly",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
 	.stream_init    = stream_init_receive,
 	.packet_fwd     = pkt_burst_receive,
 };
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 4902ec407e..67e5494735 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -114,8 +114,6 @@ shared_rxq_stream_init(struct fwd_stream *fs)
 
 struct fwd_engine shared_rxq_engine = {
 	.fwd_mode_name  = "shared_rxq",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
 	.stream_init    = shared_rxq_stream_init,
 	.packet_fwd     = shared_rxq_fwd,
 };
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index cf2215d390..99eea989ae 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2386,6 +2386,16 @@ launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
 	}
 }
 
+void
+common_fwd_stream_init(struct fwd_stream *fs)
+{
+	bool rx_stopped, tx_stopped;
+
+	rx_stopped = (ports[fs->rx_port].rxq[fs->rx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
+	tx_stopped = (ports[fs->tx_port].txq[fs->tx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
+	fs->disabled = rx_stopped || tx_stopped;
+}
+
 /*
  * Launch packet forwarding configuration.
  */
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ce47d1ed92..4b28cd0d0d 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -392,6 +392,8 @@ struct fwd_engine {
 	packet_fwd_t     packet_fwd;     /**< Mandatory. */
 };
 
+void common_fwd_stream_init(struct fwd_stream *fs);
+
 #define FLEX_ITEM_MAX_SAMPLES_NUM 16
 #define FLEX_ITEM_MAX_LINKS_NUM 16
 #define FLEX_MAX_FLOW_PATTERN_LENGTH 64
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 63ad5e69bf..b80ab6f5df 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -508,7 +508,6 @@ tx_only_stream_init(struct fwd_stream *fs)
 struct fwd_engine tx_only_engine = {
 	.fwd_mode_name  = "txonly",
 	.port_fwd_begin = tx_only_begin,
-	.port_fwd_end   = NULL,
 	.stream_init    = tx_only_stream_init,
 	.packet_fwd     = pkt_burst_transmit,
 };
-- 
2.39.2


  parent reply	other threads:[~2023-02-20 16:42 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
2023-01-24 10:47 ` [PATCH 1/6] app/testpmd: factorize core cycles record David Marchand
2023-02-14 18:14   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 2/6] app/testpmd: don't send unprepared packets David Marchand
2023-02-14 18:14   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 3/6] app/testpmd: bulk free mbufs David Marchand
2023-02-14 18:14   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 4/6] app/testpmd: factorize fwd engine init David Marchand
2023-02-14 18:14   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 5/6] app/testpmd: factorize fwd engine Rx David Marchand
2023-02-14 18:15   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 6/6] app/testpmd: factorize fwd engine Tx David Marchand
2023-02-14 11:03   ` Singh, Aman Deep
2023-02-14 18:17     ` Ferruh Yigit
2023-02-16  8:01       ` Singh, Aman Deep
2023-02-16 10:07         ` Ferruh Yigit
2023-02-14 18:16   ` Ferruh Yigit
2023-02-20 16:33     ` David Marchand
2023-01-25 13:50 ` [PATCH 0/6] Testpmd code cleanup Robin Jarry
2023-02-14 18:22   ` Ferruh Yigit
2023-02-20 15:02     ` David Marchand
2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
2023-02-20 16:40   ` [PATCH v2 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
2023-02-20 16:40   ` [PATCH v2 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
2023-02-20 16:40   ` [PATCH v2 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
2023-02-24  9:11     ` Singh, Aman Deep
2023-02-20 16:40   ` [PATCH v2 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
2023-02-20 16:40   ` [PATCH v2 5/9] app/testpmd: bulk free mbufs David Marchand
2023-02-20 16:41   ` [PATCH v2 6/9] app/testpmd: factorize core cycles record David Marchand
2023-02-20 16:41   ` David Marchand [this message]
2023-02-20 16:41   ` [PATCH v2 8/9] app/testpmd: factorize fwd engine Rx David Marchand
2023-02-20 16:41   ` [PATCH v2 9/9] app/testpmd: factorize fwd engine Tx David Marchand
2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
2023-02-20 18:34   ` [PATCH v3 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
2023-02-20 18:34   ` [PATCH v3 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
2023-02-24  8:24     ` Singh, Aman Deep
2023-02-20 18:34   ` [PATCH v3 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
2023-02-28 18:50     ` Ferruh Yigit
2023-02-20 18:34   ` [PATCH v3 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
2023-02-28 18:51     ` Ferruh Yigit
2023-02-20 18:34   ` [PATCH v3 5/9] app/testpmd: bulk free mbufs David Marchand
2023-02-20 18:45     ` Stephen Hemminger
2023-02-20 18:34   ` [PATCH v3 6/9] app/testpmd: factorize core cycles record David Marchand
2023-02-20 18:35   ` [PATCH v3 7/9] app/testpmd: factorize fwd engine init David Marchand
2023-02-20 18:35   ` [PATCH v3 8/9] app/testpmd: factorize fwd engine Rx David Marchand
2023-02-20 18:35   ` [PATCH v3 9/9] app/testpmd: factorize fwd engine Tx David Marchand
2023-02-28 18:35     ` Ferruh Yigit
2023-02-28 18:54   ` [PATCH v3 0/9] Testpmd code cleanup Ferruh Yigit

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=20230220164103.3041538-8-david.marchand@redhat.com \
    --to=david.marchand@redhat.com \
    --cc=aman.deep.singh@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=rjarry@redhat.com \
    --cc=yuying.zhang@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).