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 0E0E543B0E; Wed, 14 Feb 2024 21:58:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CFDA642E10; Wed, 14 Feb 2024 21:58:40 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by mails.dpdk.org (Postfix) with ESMTP id 1DF0F400D5 for ; Wed, 14 Feb 2024 21:58:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707944319; x=1739480319; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=XSB7uNbRxVttOPxhGUeF8PBxbYGgV5tjPuMGk3SKp0o=; b=LsfbG8mVIvV2LQfD3YQfxQ4qEjJOAohjLL7WXGEqxEezqu95UjNo7v8T 91/Iq7GU89cd/LFawPtgiLZH6XJ6toAHrigwQ30UwsSsvtOgZBm8M7Qod HE05yrRaq4EuVloPN3KoRQ4olRiiJKkNJI7wDOnDc8RbZExV8TXaQwCrc Mslkfy8ln6txh5JKUDmgoqOzyhW1UHTnPIHN3WwpahxwRq0l1L9Y2eM3G PnKiLKZoQqPNcf5WYcvPW7fAkgPYPbkWrVKSJQpGLyNTNOL3BgMWA/DY0 FADlk8P3Us7cDJBFRC4sCUjNy8UYwZmkwk+0TUOPuSqVtx7SRiAUBbuZb Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10984"; a="12643060" X-IronPort-AV: E=Sophos;i="6.06,160,1705392000"; d="scan'208";a="12643060" 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:58:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,160,1705392000"; d="scan'208";a="3633908" 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:58:38 -0800 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2] pipeline: remove limitation on number of input ports Date: Wed, 14 Feb 2024 20:58:36 +0000 Message-Id: <20240214205836.1561803-1-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240214205151.1559571-1-cristian.dumitrescu@intel.com> References: <20240214205151.1559571-1-cristian.dumitrescu@intel.com> 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..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