DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] pipeline: remove limitation on number of input ports
@ 2024-02-14 20:51 Cristian Dumitrescu
  2024-02-14 20:58 ` [PATCH V2] " Cristian Dumitrescu
  0 siblings, 1 reply; 3+ messages in thread
From: Cristian Dumitrescu @ 2024-02-14 20:51 UTC (permalink / raw)
  To: dev

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..bafa6cc1bc 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-18 23:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14 20:51 [PATCH] pipeline: remove limitation on number of input ports Cristian Dumitrescu
2024-02-14 20:58 ` [PATCH V2] " Cristian Dumitrescu
2024-02-18 23:48   ` Thomas Monjalon

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).