From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id DF00AA04B1;
	Tue,  8 Sep 2020 22:20:05 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id EF9121C124;
	Tue,  8 Sep 2020 22:19:06 +0200 (CEST)
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by dpdk.org (Postfix) with ESMTP id DA6FA1C0CC
 for <dev@dpdk.org>; Tue,  8 Sep 2020 22:18:55 +0200 (CEST)
IronPort-SDR: gAuTihM13vMJplgIy5gTgq/6ejDcUfNSi/UIS2vXGF8Yt2OKxILlpJ5rP02GjPU0i+IQXpZi7q
 RrwB75SJ5ZPQ==
X-IronPort-AV: E=McAfee;i="6000,8403,9738"; a="145939384"
X-IronPort-AV: E=Sophos;i="5.76,407,1592895600"; d="scan'208";a="145939384"
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from fmsmga006.fm.intel.com ([10.253.24.20])
 by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 08 Sep 2020 13:18:40 -0700
IronPort-SDR: Ma3tY8O+krLRst2iWnE0Xl1MPF7r+OQFQJo3V/MIPdS388ZBi60HDlWVSP93zV/xEaJwGy8MVu
 4D+wnEu5TfCg==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.76,406,1592895600"; d="scan'208";a="504493393"
Received: from silpixa00400573.ir.intel.com (HELO
 silpixa00400573.ger.corp.intel.com) ([10.237.223.107])
 by fmsmga006.fm.intel.com with ESMTP; 08 Sep 2020 13:18:39 -0700
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Date: Tue,  8 Sep 2020 21:17:57 +0100
Message-Id: <20200908201830.74206-9-cristian.dumitrescu@intel.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200908201830.74206-1-cristian.dumitrescu@intel.com>
References: <20200907214032.95052-2-cristian.dumitrescu@intel.com>
 <20200908201830.74206-1-cristian.dumitrescu@intel.com>
Subject: [dpdk-dev] [PATCH v3 08/41] pipeline: add SWX pipeline instructions
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

The SWX pipeline instructions represent the main program that defines
the life of the packet. As packets go through tables that trigger
action subroutines, the headers and meta-data get transformed along
the way.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/librte_pipeline/rte_pipeline_version.map |  1 +
 lib/librte_pipeline/rte_swx_pipeline.c       | 36 ++++++++++++++++++++
 lib/librte_pipeline/rte_swx_pipeline.h       | 20 +++++++++++
 3 files changed, 57 insertions(+)

diff --git a/lib/librte_pipeline/rte_pipeline_version.map b/lib/librte_pipeline/rte_pipeline_version.map
index b9e59bce2..7139df0d3 100644
--- a/lib/librte_pipeline/rte_pipeline_version.map
+++ b/lib/librte_pipeline/rte_pipeline_version.map
@@ -70,6 +70,7 @@ EXPERIMENTAL {
 	rte_swx_pipeline_action_config;
 	rte_swx_pipeline_table_type_register;
 	rte_swx_pipeline_table_config;
+	rte_swx_pipeline_instructions_config;
 	rte_swx_pipeline_build;
 	rte_swx_pipeline_free;
 	rte_swx_pipeline_table_state_get;
diff --git a/lib/librte_pipeline/rte_swx_pipeline.c b/lib/librte_pipeline/rte_swx_pipeline.c
index eb5b327e8..2ae6229d0 100644
--- a/lib/librte_pipeline/rte_swx_pipeline.c
+++ b/lib/librte_pipeline/rte_swx_pipeline.c
@@ -274,6 +274,10 @@ struct thread {
 	/* Extern objects and functions. */
 	struct extern_obj_runtime *extern_objs;
 	struct extern_func_runtime *extern_funcs;
+
+	/* Instructions. */
+	struct instruction *ip;
+	struct instruction *ret;
 };
 
 #ifndef RTE_SWX_PIPELINE_THREADS_MAX
@@ -300,6 +304,7 @@ struct rte_swx_pipeline {
 	struct port_out_runtime *out;
 	struct instruction **action_instructions;
 	struct rte_swx_table_state *table_state;
+	struct instruction *instructions;
 	struct thread threads[RTE_SWX_PIPELINE_THREADS_MAX];
 
 	uint32_t n_structs;
@@ -310,6 +315,7 @@ struct rte_swx_pipeline {
 	uint32_t n_actions;
 	uint32_t n_tables;
 	uint32_t n_headers;
+	uint32_t n_instructions;
 	int build_done;
 	int numa_node;
 };
@@ -1424,6 +1430,12 @@ metadata_free(struct rte_swx_pipeline *p)
 /*
  * Instruction.
  */
+static inline void
+thread_ip_reset(struct rte_swx_pipeline *p, struct thread *t)
+{
+	t->ip = p->instructions;
+}
+
 static int
 instruction_config(struct rte_swx_pipeline *p __rte_unused,
 		   struct action *a __rte_unused,
@@ -2110,6 +2122,8 @@ rte_swx_pipeline_free(struct rte_swx_pipeline *p)
 	if (!p)
 		return;
 
+	free(p->instructions);
+
 	table_state_free(p);
 	table_free(p);
 	action_free(p);
@@ -2124,6 +2138,28 @@ rte_swx_pipeline_free(struct rte_swx_pipeline *p)
 	free(p);
 }
 
+int
+rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p,
+				     const char **instructions,
+				     uint32_t n_instructions)
+{
+	int err;
+	uint32_t i;
+
+	err = instruction_config(p, NULL, instructions, n_instructions);
+	if (err)
+		return err;
+
+	/* Thread instruction pointer reset. */
+	for (i = 0; i < RTE_SWX_PIPELINE_THREADS_MAX; i++) {
+		struct thread *t = &p->threads[i];
+
+		thread_ip_reset(p, t);
+	}
+
+	return 0;
+}
+
 int
 rte_swx_pipeline_build(struct rte_swx_pipeline *p)
 {
diff --git a/lib/librte_pipeline/rte_swx_pipeline.h b/lib/librte_pipeline/rte_swx_pipeline.h
index d7e3ba1ec..47a0f8dcc 100644
--- a/lib/librte_pipeline/rte_swx_pipeline.h
+++ b/lib/librte_pipeline/rte_swx_pipeline.h
@@ -495,6 +495,26 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
 			      const char *args,
 			      uint32_t size);
 
+/**
+ * Pipeline instructions configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] instructions
+ *   Pipeline instructions.
+ * @param[in] n_instructions
+ *   Number of pipeline instructions.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p,
+				     const char **instructions,
+				     uint32_t n_instructions);
+
 /**
  * Pipeline build
  *
-- 
2.17.1