From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D9A5F43B0E; Wed, 14 Feb 2024 21:51:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6BE9742EAC; Wed, 14 Feb 2024 21:51:56 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by mails.dpdk.org (Postfix) with ESMTP id B9BE6400D5 for ; Wed, 14 Feb 2024 21:51:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707943915; x=1739479915; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=3RSYnimtg4ZE5AJwg8DH78uDdcX5M8NrA2rs2/Ak4No=; b=cWk6CwG2Og9ogkWaUNz++zaMtJi88ITgCRRnZj4iDWUNB5AQULyYygiY rcl+k57rUO0BF2FQKy9fs6rgGmnDK8kF4FKFKttTjCPRsP0Kc8hsVwr20 7ocL5I5sFUJA7+9E8J5uxKl5F4ZVIsdjV0hHIki5e+ozIk8HX4qQzzUS5 gVqDJI4LLE2dPrC8GRfN9FRFrVmVyq4aLuyNEhkN9nWwxO0GOppnIWh3N X1f0OShM1sAndaJuuZsZem7Kr7BPwQ3sheIMQZ96JHWen134N/XhoDkLQ s64e0GjNBMbtGJP9QWiZ3E/y+TxdDTVTNogno6/NaHHVcprnQ0wmL2dVZ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10984"; a="12642344" X-IronPort-AV: E=Sophos;i="6.06,160,1705392000"; d="scan'208";a="12642344" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Feb 2024 12:51:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,160,1705392000"; d="scan'208";a="3633272" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.184]) by orviesa007.jf.intel.com with ESMTP; 14 Feb 2024 12:51:53 -0800 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH] pipeline: remove limitation on number of input ports Date: Wed, 14 Feb 2024 20:51:51 +0000 Message-Id: <20240214205151.1559571-1-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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