DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Subject: [PATCH V2] pipeline: remove limitation on number of input ports
Date: Wed, 14 Feb 2024 20:58:36 +0000	[thread overview]
Message-ID: <20240214205836.1561803-1-cristian.dumitrescu@intel.com> (raw)
In-Reply-To: <20240214205151.1559571-1-cristian.dumitrescu@intel.com>

Removed the requirement that the number of pipeline input ports be a
power of 2, which is problematic for many real life use-cases. Also
adding checks for the output port validity used for sending the
current packet.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c          |  1 -
 lib/pipeline/rte_swx_pipeline_internal.h | 38 ++++++++++++++++++++----
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 147c1c2ad4..6ba86bee1f 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -340,7 +340,6 @@ port_in_build(struct rte_swx_pipeline *p)
 	uint32_t i;
 
 	CHECK(p->n_ports_in, EINVAL);
-	CHECK(rte_is_power_of_2(p->n_ports_in), EINVAL);
 
 	for (i = 0; i < p->n_ports_in; i++)
 		CHECK(port_in_find(p, i), EINVAL);
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index f5a64e0fe1..8b3e79e8fe 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -1612,7 +1612,13 @@ struct rte_swx_pipeline {
 static inline void
 pipeline_port_inc(struct rte_swx_pipeline *p)
 {
-	p->port_id = (p->port_id + 1) & (p->n_ports_in - 1);
+	uint32_t port_id = p->port_id;
+
+	port_id++;
+	if (port_id == p->n_ports_in)
+		port_id = 0;
+
+	p->port_id = port_id;
 }
 
 static inline void
@@ -1825,9 +1831,9 @@ mirroring_handler(struct rte_swx_pipeline *p, struct thread *t, struct rte_swx_p
 static inline void
 __instr_tx_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
 {
-	uint64_t port_id = METADATA_READ(t, ip->io.io.offset, ip->io.io.n_bits);
-	struct port_out_runtime *port = &p->out[port_id];
 	struct rte_swx_pkt *pkt = &t->pkt;
+	struct port_out_runtime *port;
+	uint64_t port_id;
 
 	/* Recirculation: keep the current packet. */
 	if (t->recirculate) {
@@ -1843,6 +1849,15 @@ __instr_tx_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instr
 		return;
 	}
 
+	/* If the output port ID is invalid, then set it to the drop output port that has been set
+	 * up internally by the pipeline for this purpose.
+	 */
+	port_id = METADATA_READ(t, ip->io.io.offset, ip->io.io.n_bits);
+	if (port_id >= p->n_ports_out)
+		port_id = p->n_ports_out - 1;
+
+	port = &p->out[port_id];
+
 	TRACE("[Thread %2u]: tx 1 pkt to port %u\n",
 	      p->thread_id,
 	      (uint32_t)port_id);
@@ -1858,9 +1873,9 @@ __instr_tx_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instr
 static inline void
 __instr_tx_i_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
 {
-	uint64_t port_id = ip->io.io.val;
-	struct port_out_runtime *port = &p->out[port_id];
 	struct rte_swx_pkt *pkt = &t->pkt;
+	struct port_out_runtime *port;
+	uint64_t port_id;
 
 	/* Recirculation: keep the current packet. */
 	if (t->recirculate) {
@@ -1876,6 +1891,19 @@ __instr_tx_i_exec(struct rte_swx_pipeline *p, struct thread *t, const struct ins
 		return;
 	}
 
+	/* If the output port ID is invalid, then set it to the drop output port that has been set
+	 * up internally by the pipeline for this purpose.
+	 *
+	 * This test cannot be done earlier at instruction translation time, even though the output
+	 * port ID is an immediate value, as the number of output ports is only known later at the
+	 * pipeline build time.
+	 */
+	port_id = ip->io.io.val;
+	if (port_id >= p->n_ports_out)
+		port_id = p->n_ports_out - 1;
+
+	port = &p->out[port_id];
+
 	TRACE("[Thread %2u]: tx (i) 1 pkt to port %u\n",
 	      p->thread_id,
 	      (uint32_t)port_id);
-- 
2.34.1


  reply	other threads:[~2024-02-14 20:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 20:51 [PATCH] " Cristian Dumitrescu
2024-02-14 20:58 ` Cristian Dumitrescu [this message]
2024-02-18 23:48   ` [PATCH V2] " Thomas Monjalon

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=20240214205836.1561803-1-cristian.dumitrescu@intel.com \
    --to=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /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).