From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 3AFC1A0555;
	Fri, 26 Aug 2022 13:21:37 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 8926C410D2;
	Fri, 26 Aug 2022 13:21:33 +0200 (CEST)
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by mails.dpdk.org (Postfix) with ESMTP id DD3F840143
 for <dev@dpdk.org>; Fri, 26 Aug 2022 13:21:30 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1661512891; x=1693048891;
 h=from:to:subject:date:message-id:in-reply-to:references:
 mime-version:content-transfer-encoding;
 bh=LIe1Db/ahV3Y4yVUVelEXN9T5EjffV0QH1AT7aQtB9I=;
 b=kbkJm7htJO3/uigWJt8TLxy7VpZ9oixkVolo2t1PlCjlk4nTtqtAAITi
 pEocV1VEo4hftLJOhuDS6KcwZx2TlgvvWrmtCXBClpFYpjycun+cnmj1z
 TGHjGr9e4dqRNDJUtVriW6x8/4DGt9n2jj11Y/WOQgMAeuulAIl+fFVXc
 vu74lIeqorLJ5+lkQUG1Vr7z3w5zfJn5xSQhXt9jUFL92YMcZFeGrUCZm
 4C/rrNYN+wTfghEoFNL5nieHibpV1vYAqna96gY7/1v+E6BnenO4ew3vM
 2jdlIAdiR6wNy8Z11nzTbb8sTpmKK+q8hoE9u28Q0tpfdG4VSHCB1/nru g==;
X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="295264072"
X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="295264072"
Received: from fmsmga004.fm.intel.com ([10.253.24.48])
 by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 26 Aug 2022 04:21:30 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="678834791"
Received: from silpixa00400573.ir.intel.com (HELO
 silpixa00400573.ger.corp.intel.com.) ([10.237.223.157])
 by fmsmga004.fm.intel.com with ESMTP; 26 Aug 2022 04:21:29 -0700
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Subject: [PATCH V2 1/7] table: add entry ID for regular tables
Date: Fri, 26 Aug 2022 11:21:21 +0000
Message-Id: <20220826112127.1580044-2-cristian.dumitrescu@intel.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20220826112127.1580044-1-cristian.dumitrescu@intel.com>
References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com>
 <20220826112127.1580044-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 <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

Add support for unique ID for each table entry. The entry ID is
retrieved as part of the table lookup operation and is saved by the
pipeline for later use.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c          |  9 +++++++++
 lib/pipeline/rte_swx_pipeline_internal.h |  1 +
 lib/table/rte_swx_table.h                | 13 +++++++++++++
 lib/table/rte_swx_table_em.c             |  5 +++++
 lib/table/rte_swx_table_wm.c             |  2 ++
 5 files changed, 30 insertions(+)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 1c49622be7..e271cc50eb 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2401,6 +2401,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 	struct table_statistics *stats = &p->table_stats[table_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action;
 	uint8_t *action_data;
+	size_t entry_id;
 	int done, hit;
 
 	/* Table. */
@@ -2409,6 +2410,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 			   table->key,
 			   &action_id,
 			   &action_data,
+			   &entry_id,
 			   &hit);
 	if (!done) {
 		/* Thread. */
@@ -2422,6 +2424,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
 
@@ -2433,6 +2436,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	stats->n_pkts_hit[hit] = n_pkts_hit + 1;
 	stats->n_pkts_action[action_id] = n_pkts_action + 1;
@@ -2452,6 +2456,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 	struct table_statistics *stats = &p->table_stats[table_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action;
 	uint8_t *action_data;
+	size_t entry_id;
 	action_func_t action_func;
 	int done, hit;
 
@@ -2461,6 +2466,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 			   table->key,
 			   &action_id,
 			   &action_data,
+			   &entry_id,
 			   &hit);
 	if (!done) {
 		/* Thread. */
@@ -2474,6 +2480,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	action_func = p->action_funcs[action_id];
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
@@ -2486,6 +2493,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	stats->n_pkts_hit[hit] = n_pkts_hit + 1;
 	stats->n_pkts_action[action_id] = n_pkts_action + 1;
@@ -8283,6 +8291,7 @@ table_stub_lkp(void *table __rte_unused,
 	       uint8_t **key __rte_unused,
 	       uint64_t *action_id __rte_unused,
 	       uint8_t **action_data __rte_unused,
+	       size_t *entry_id __rte_unused,
 	       int *hit)
 {
 	*hit = 0;
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index ef60288dca..8f96b67d76 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -1009,6 +1009,7 @@ struct thread {
 	struct learner_runtime *learners;
 	struct rte_swx_table_state *table_state;
 	uint64_t action_id;
+	size_t entry_id;
 	int hit; /* 0 = Miss, 1 = Hit. */
 	uint32_t learner_id;
 	uint64_t time;
diff --git a/lib/table/rte_swx_table.h b/lib/table/rte_swx_table.h
index 4b8dc06798..ac01e19781 100644
--- a/lib/table/rte_swx_table.h
+++ b/lib/table/rte_swx_table.h
@@ -233,6 +233,15 @@ typedef int
  * data likely to be read from the CPU cache with no CPU pipeline stall, which
  * significantly improves the table lookup performance.
  *
+ * The table entry consists of the action ID and the action data. Each table
+ * entry is unique, although different table entries can have identical content,
+ * i.e. same values for the action ID and the action data. The table entry ID is
+ * also returned by the table lookup operation. It can be used to index into an
+ * external array of resources such as counters, registers or meters to identify
+ * the resource directly associated with the current table entry with no need to
+ * store the corresponding index into the table entry. The index of the external
+ * resource is thus auto-generated instead of being stored in the table entry.
+ *
  * @param[in] table
  *   Table handle.
  * @param[in] mailbox
@@ -247,6 +256,9 @@ typedef int
  *   Action data for the *action_id* action. Must point to a valid array of
  *   table *action_data_size* bytes. Only valid when the function returns 1 and
  *   *hit* is set to true.
+ * @param[out] entry_id
+ *   Table entry unique ID. Must point to a valid 32-bit variable. Only valid
+ *   when the function returns 1 and *hit* is set to true.
  * @param[out] hit
  *   Only valid when the function returns 1. Set to non-zero (true) on table
  *   lookup hit and to zero (false) on table lookup miss.
@@ -260,6 +272,7 @@ typedef int
 			  uint8_t **key,
 			  uint64_t *action_id,
 			  uint8_t **action_data,
+			  size_t *entry_id,
 			  int *hit);
 
 /**
diff --git a/lib/table/rte_swx_table_em.c b/lib/table/rte_swx_table_em.c
index 568e76e249..2b5201e006 100644
--- a/lib/table/rte_swx_table_em.c
+++ b/lib/table/rte_swx_table_em.c
@@ -403,6 +403,7 @@ table_lookup_unoptimized(void *table,
 			 uint8_t **key,
 			 uint64_t *action_id,
 			 uint8_t **action_data,
+			 size_t *entry_id,
 			 int *hit)
 {
 	struct table *t = table;
@@ -431,6 +432,7 @@ table_lookup_unoptimized(void *table,
 				bkt_data = table_key_data(t, bkt_key_id);
 				*action_id = bkt_data[0];
 				*action_data = (uint8_t *)&bkt_data[1];
+				*entry_id = bkt_key_id;
 				*hit = 1;
 				return 1;
 			}
@@ -500,6 +502,7 @@ table_lookup(void *table,
 	     uint8_t **key,
 	     uint64_t *action_id,
 	     uint8_t **action_data,
+	     size_t *entry_id,
 	     int *hit)
 {
 	struct table *t = table;
@@ -576,6 +579,7 @@ table_lookup(void *table,
 		lkp_hit &= m->sig_match;
 		*action_id = bkt_data[0];
 		*action_data = (uint8_t *)&bkt_data[1];
+		*entry_id = bkt_key_id;
 		*hit = lkp_hit;
 
 		m->state = 0;
@@ -586,6 +590,7 @@ table_lookup(void *table,
 							key,
 							action_id,
 							action_data,
+							entry_id,
 							hit);
 
 		return 1;
diff --git a/lib/table/rte_swx_table_wm.c b/lib/table/rte_swx_table_wm.c
index ce2a78f94c..58afb35d46 100644
--- a/lib/table/rte_swx_table_wm.c
+++ b/lib/table/rte_swx_table_wm.c
@@ -436,6 +436,7 @@ table_lookup(void *table,
 	     const uint8_t **key,
 	     uint64_t *action_id,
 	     uint8_t **action_data,
+	     size_t *entry_id,
 	     int *hit)
 {
 	struct table *t = table;
@@ -451,6 +452,7 @@ table_lookup(void *table,
 	data = &t->data[(user_data - 1) * t->entry_data_size];
 	*action_id = ((uint64_t *)data)[0];
 	*action_data = &data[8];
+	*entry_id = user_data - 1;
 	*hit = 1;
 	return 1;
 }
-- 
2.34.1