From patchwork Fri Aug 26 10:35:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115464 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 906F5A0554; Fri, 26 Aug 2022 12:36:16 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4539440146; Fri, 26 Aug 2022 12:36:12 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 85B7F40143 for ; Fri, 26 Aug 2022 12:36:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661510170; x=1693046170; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=LIe1Db/ahV3Y4yVUVelEXN9T5EjffV0QH1AT7aQtB9I=; b=gkdx7dpzhrC9xUKFaQLxl/9HiICAbmkPTiOlNZc3W8u/w2vjGoyhYOtC R/VZ8RTWUIeO+yClgnLuV0KIZMSuN0MUFDexm9czqFaHHTx41de0TUFqn xDy4j8UmdBLAz+FUCdl5Uqogw5140a+AzpVtdqyJudlGfmATEZ2VA/njI fn0xh/2JU3u6sDKrUIiT6/NwVDz6nw+HVXiHUFueMzu0eeiYlzK1+X3PM 1ZBIxxw5k1UpNOIJo0tplnwZhYbYRyaYkOTx8S7/gvxW7fiMR5etLs87g vRlrUuE5yHoqGSt7jZ7ENO6lzcUt9/gsYsENiytdmIE4bx9QFqCSzbhMl A==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="356194323" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="356194323" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:36:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="671414277" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 26 Aug 2022 03:36:07 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 1/7] table: add entry ID for regular tables Date: Fri, 26 Aug 2022 10:35:59 +0000 Message-Id: <20220826103605.1579589-2-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 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 --- 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; } From patchwork Fri Aug 26 10:36:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115465 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B8B3EA0554; Fri, 26 Aug 2022 12:36:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 220F6427F7; Fri, 26 Aug 2022 12:36:13 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id D0F8A40146 for ; Fri, 26 Aug 2022 12:36:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661510171; x=1693046171; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=a+ZGfVh0lwX8bp1pVauqmtyRwEJ5vFF6+GqztZwiTSA=; b=AeLQaL+JiCG9wayxqFzdal6ghfnvYlMvlYBoumqW2dnB0+U5sFY7rRDq iMS7xjwMK5EQVQ8guf4w9rLkzKOnYKtnT4snb1U9FOLvC4pIWH97ZjtIU ruSh4yUSAzg53YETAsIvFEhRVvrHMxtCvYEMwj4UzoGShVT6VrM8aHNWG LetKGnWd1JjybTUb/LM+Ggc+JQFRx9LC9OhJmaE3PQIUXq4yRuyl9MUpv jOvlCmnO0GPe3ZfvvC2+EZTdhrIPJkAg/NZA2bwRcI13/tCjloFBB8TIg /tGlAMkc7y6r2gG+b+zO/k7FeKz8HZQoC/bVT3navTMk453IU8g31xMwb w==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="356194325" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="356194325" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:36:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="671414278" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 26 Aug 2022 03:36:08 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 2/7] table: add entry ID for learner tables Date: Fri, 26 Aug 2022 10:36:00 +0000 Message-Id: <20220826103605.1579589-3-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 Add support for unique ID for each learner table entry. The entry ID is retrieved as part of the learner table lookup operation and is saved by the pipeline for later use. Signed-off-by: Cristian Dumitrescu --- lib/pipeline/rte_swx_pipeline.c | 8 ++++++++ lib/table/rte_swx_table_learner.c | 13 ++++++++++++- lib/table/rte_swx_table_learner.h | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index e271cc50eb..80108b8916 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -2556,6 +2556,7 @@ instr_learner_exec(struct rte_swx_pipeline *p) struct learner_statistics *stats = &p->learner_stats[learner_id]; uint64_t action_id, n_pkts_hit, n_pkts_action, time; uint8_t *action_data; + size_t entry_id; int done, hit; /* Table. */ @@ -2567,6 +2568,7 @@ instr_learner_exec(struct rte_swx_pipeline *p) l->key, &action_id, &action_data, + &entry_id, &hit); if (!done) { /* Thread. */ @@ -2580,6 +2582,7 @@ instr_learner_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]; @@ -2591,6 +2594,7 @@ instr_learner_exec(struct rte_swx_pipeline *p) t->action_id = action_id; t->structs[0] = action_data; + t->entry_id = entry_id; t->hit = hit; t->learner_id = learner_id; t->time = time; @@ -2613,6 +2617,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p) struct learner_statistics *stats = &p->learner_stats[learner_id]; uint64_t action_id, n_pkts_hit, n_pkts_action, time; uint8_t *action_data; + size_t entry_id; action_func_t action_func; int done, hit; @@ -2625,6 +2630,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p) l->key, &action_id, &action_data, + &entry_id, &hit); if (!done) { /* Thread. */ @@ -2638,6 +2644,7 @@ instr_learner_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]; @@ -2650,6 +2657,7 @@ instr_learner_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; t->learner_id = learner_id; t->time = time; diff --git a/lib/table/rte_swx_table_learner.c b/lib/table/rte_swx_table_learner.c index c1045a1082..996fd3de5b 100644 --- a/lib/table/rte_swx_table_learner.c +++ b/lib/table/rte_swx_table_learner.c @@ -72,6 +72,7 @@ table_keycpy(void *dst, void *src, uint32_t n_bytes) } #define TABLE_KEYS_PER_BUCKET 4 +#define TABLE_KEYS_PER_BUCKET_LOG2 2 #define TABLE_BUCKET_USEFUL_SIZE \ (TABLE_KEYS_PER_BUCKET * (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint8_t))) @@ -263,6 +264,14 @@ table_bucket_data_get(struct table *t, struct table_bucket *b, size_t bucket_key (bucket_key_pos << t->params.data_size_log2)]; } +static inline size_t +table_entry_id_get(struct table *t, struct table_bucket *b, size_t bucket_key_pos) +{ + size_t bucket_id = ((uint8_t *)b - t->buckets) >> t->params.bucket_size_log2; + + return (bucket_id << TABLE_KEYS_PER_BUCKET_LOG2) + bucket_key_pos; +} + uint64_t rte_swx_table_learner_footprint_get(struct rte_swx_table_learner_params *params) { @@ -332,7 +341,7 @@ struct mailbox { /* Writer: lookup state 0. Reader(s): lookup state 1, add(). */ uint32_t input_sig; - /* Writer: lookup state 1. Reader(s): add(). */ + /* Writer: lookup state 0. Reader(s): lookup state 1, add(). */ uint8_t *input_key; /* Writer: lookup state 1. Reader(s): add(). Values: 0 = miss; 1 = hit. */ @@ -358,6 +367,7 @@ rte_swx_table_learner_lookup(void *table, uint8_t **key, uint64_t *action_id, uint8_t **action_data, + size_t *entry_id, int *hit) { struct table *t = table; @@ -412,6 +422,7 @@ rte_swx_table_learner_lookup(void *table, *action_id = data[0]; *action_data = (uint8_t *)&data[1]; + *entry_id = table_entry_id_get(t, b, i); *hit = 1; return 1; } diff --git a/lib/table/rte_swx_table_learner.h b/lib/table/rte_swx_table_learner.h index d72b6b88ff..62cac3f225 100644 --- a/lib/table/rte_swx_table_learner.h +++ b/lib/table/rte_swx_table_learner.h @@ -173,6 +173,14 @@ rte_swx_table_learner_timeout_update(void *table, * possibly an associated key add operation. The mailbox mechanism allows for multiple concurrent * table key lookup and add operations into the same table. * + * The table entry consists of the action ID and the action data. Each table entry is unique, even + * though 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 @@ -187,6 +195,9 @@ rte_swx_table_learner_timeout_update(void *table, * @param[out] action_data * 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. @@ -202,6 +213,7 @@ rte_swx_table_learner_lookup(void *table, uint8_t **key, uint64_t *action_id, uint8_t **action_data, + size_t *entry_id, int *hit); /** From patchwork Fri Aug 26 10:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115470 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A9DE5A0554; Fri, 26 Aug 2022 12:36:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EB7204284D; Fri, 26 Aug 2022 12:36:24 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 4787A4281A for ; Fri, 26 Aug 2022 12:36:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661510183; x=1693046183; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=c5YHVF51WVwQBQOJ5eVbyFRUuGco+5s4B9CoVKSTnjw=; b=RC/6s0BChyncaUhuuy5hMm2zgyKWWy/+X/rip6kPBYGkfIsOQCaLM+VV 5MPaz0RWqaVLJLcGMgtAnl8V/+ikkta7YrZ4Ke5MgC0ZYg9EB4KCkYAt7 reNbgcNLNfpWGA8eUGdzmra4n8//GnA9fUL5Rv3JLZfgXp/JyJxEjqSaV lmc/AgIeDlCxq2V4A/gLXh5aj0ZLxi9XEKbNRopV0qJ/LIW3vgjD31OSj YV2h3UAEZgIMZVNf16Ovoxm7DmJHjAdCMxZDCEHBl3j8d9JbK4nSaU1u6 w/GJFEaKIbcGbSW5W3q+j4ubhbLo09YtxYzMGGdg5ydr78p3tOqAsxBOR Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="294482922" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="294482922" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:36:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="671414280" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 26 Aug 2022 03:36:08 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 3/7] pipeline: add table entry ID read instruction Date: Fri, 26 Aug 2022 10:36:01 +0000 Message-Id: <20220826103605.1579589-4-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 Add the entry ID instruction that reads the entry ID of the latest table lookup operation from the pipeline into the meta-data. The entry ID is then used by the register and meter instructions as the index into the register or meter array. Signed-off-by: Cristian Dumitrescu --- lib/pipeline/rte_swx_pipeline.c | 68 ++++++++++++++++++++++++ lib/pipeline/rte_swx_pipeline_internal.h | 20 +++++++ 2 files changed, 88 insertions(+) diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index 80108b8916..ec8268b7f8 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -2834,6 +2834,43 @@ instr_forget_exec(struct rte_swx_pipeline *p) thread_ip_inc(p); } +/* + * entryid. + */ +static int +instr_entryid_translate(struct rte_swx_pipeline *p, + struct action *action __rte_unused, + char **tokens, + int n_tokens, + struct instruction *instr, + struct instruction_data *data __rte_unused) +{ + struct field *f; + + CHECK(n_tokens == 2, EINVAL); + + f = metadata_field_parse(p, tokens[1]); + CHECK(f, EINVAL); + CHECK(f->n_bits <= 64, EINVAL); + + instr->type = INSTR_ENTRYID; + instr->mov.dst.n_bits = f->n_bits; + instr->mov.dst.offset = f->offset / 8; + return 0; +} + +static inline void +instr_entryid_exec(struct rte_swx_pipeline *p) +{ + struct thread *t = &p->threads[p->thread_id]; + struct instruction *ip = t->ip; + + __instr_entryid_exec(p, t, ip); + + /* Thread. */ + thread_ip_inc(p); +} + /* * extern. */ @@ -6336,6 +6373,14 @@ instr_translate(struct rte_swx_pipeline *p, instr, data); + if (!strcmp(tokens[tpos], "entryid")) + return instr_entryid_translate(p, + action, + &tokens[tpos], + n_tokens - tpos, + instr, + data); + if (!strcmp(tokens[tpos], "extern")) return instr_extern_translate(p, action, @@ -7321,6 +7366,8 @@ static instr_exec_t instruction_table[] = { [INSTR_LEARNER_REARM] = instr_rearm_exec, [INSTR_LEARNER_REARM_NEW] = instr_rearm_new_exec, [INSTR_LEARNER_FORGET] = instr_forget_exec, + [INSTR_ENTRYID] = instr_entryid_exec, + [INSTR_EXTERN_OBJ] = instr_extern_obj_exec, [INSTR_EXTERN_FUNC] = instr_extern_func_exec, [INSTR_HASH_FUNC] = instr_hash_func_exec, @@ -11222,6 +11269,7 @@ instr_type_to_name(struct instruction *instr) case INSTR_LEARNER_REARM: return "INSTR_LEARNER_REARM"; case INSTR_LEARNER_REARM_NEW: return "INSTR_LEARNER_REARM_NEW"; case INSTR_LEARNER_FORGET: return "INSTR_LEARNER_FORGET"; + case INSTR_ENTRYID: return "INSTR_ENTRYID"; case INSTR_EXTERN_OBJ: return "INSTR_EXTERN_OBJ"; case INSTR_EXTERN_FUNC: return "INSTR_EXTERN_FUNC"; @@ -11922,6 +11970,24 @@ instr_forget_export(struct instruction *instr, FILE *f) instr_type_to_name(instr)); } +static void +instr_entryid_export(struct instruction *instr, FILE *f) +{ + fprintf(f, + "\t{\n" + "\t\t.type = %s,\n" + "\t\t.mov = {\n" + "\t\t\t.dst = {\n" + "\t\t\t\t.n_bits = %u,\n" + "\t\t\t\t.offset = %u,\n" + "\t\t\t},\n" + "\t\t},\n" + "\t},\n", + instr_type_to_name(instr), + instr->mov.dst.n_bits, + instr->mov.dst.offset); +} + static void instr_extern_export(struct instruction *instr, FILE *f) { @@ -12212,6 +12278,7 @@ static instruction_export_t export_table[] = { [INSTR_LEARNER_REARM] = instr_rearm_export, [INSTR_LEARNER_REARM_NEW] = instr_rearm_export, [INSTR_LEARNER_FORGET] = instr_forget_export, + [INSTR_ENTRYID] = instr_entryid_export, [INSTR_EXTERN_OBJ] = instr_extern_export, [INSTR_EXTERN_FUNC] = instr_extern_export, @@ -12438,6 +12505,7 @@ instr_type_to_func(struct instruction *instr) case INSTR_LEARNER_REARM: return "__instr_rearm_exec"; case INSTR_LEARNER_REARM_NEW: return "__instr_rearm_new_exec"; case INSTR_LEARNER_FORGET: return "__instr_forget_exec"; + case INSTR_ENTRYID: return "__instr_entryid_exec"; case INSTR_EXTERN_OBJ: return NULL; case INSTR_EXTERN_FUNC: return NULL; diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h index 8f96b67d76..335506039b 100644 --- a/lib/pipeline/rte_swx_pipeline_internal.h +++ b/lib/pipeline/rte_swx_pipeline_internal.h @@ -504,6 +504,11 @@ enum instruction_type { /* forget */ INSTR_LEARNER_FORGET, + /* entryid m.table_entry_id + * Read the internal table entry ID into the specified meta-data field. + */ + INSTR_ENTRYID, + /* extern e.obj.func */ INSTR_EXTERN_OBJ, @@ -2377,6 +2382,21 @@ __instr_forget_exec(struct rte_swx_pipeline *p, stats->n_pkts_forget += 1; } +/* + * entryid. + */ +static inline void +__instr_entryid_exec(struct rte_swx_pipeline *p __rte_unused, + struct thread *t, + const struct instruction *ip) +{ + TRACE("[Thread %2u]: entryid\n", + p->thread_id); + + /* Meta-data. */ + METADATA_WRITE(t, ip->mov.dst.offset, ip->mov.dst.n_bits, t->entry_id); +} + /* * extern. */ From patchwork Fri Aug 26 10:36:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115466 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1D98BA0554; Fri, 26 Aug 2022 12:36:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CD9B942829; Fri, 26 Aug 2022 12:36:15 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 5549F40143 for ; Fri, 26 Aug 2022 12:36:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661510171; x=1693046171; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=kohfYz5OkYujxjOl5j8VnlJCSwrypbwXmoBsOpYBPio=; b=IeKGE18fwDNcm08qpd+Jj291HBen59Grh0s+0vMG1ASUjOehOydXCiR6 Ij3SHcTXw8nRa+IURnEOQlSfaJ2LBOwM2QsSnVdeKPWG5pSKvV+3F6nLl 9TMn6iVzpV0yCyUses0216kumD5oZyTzdhI1TGAOkkeJt5KQTSJRF//il vZVpQ2/pLZKP63XbGW2Gk9K07zzXOBOcMTRasRO1T/jYYp9VP132Cje1u 85+sWqledPUx/hUCb4vkHIfJ2LgPdVdwhD0XfVF5UPuLCHJSkpbvbjbzS +OV0RUY5Eb0lja59lpMd5ETGk79BnDk78v52ZAoYdJiu9PDWfZjhbGHlr Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="356194327" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="356194327" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:36:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="671414283" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 26 Aug 2022 03:36:09 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 4/7] pipeline: support direct registers on the control path Date: Fri, 26 Aug 2022 10:36:02 +0000 Message-Id: <20220826103605.1579589-5-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 Add pipeline control path API to read/write direct registers. These registers are identified by a table key, whose entry ID is used as the index into the register array. Signed-off-by: Cristian Dumitrescu --- lib/pipeline/rte_swx_ctl.h | 52 ++++++++ lib/pipeline/rte_swx_pipeline.c | 214 ++++++++++++++++++++++++++++++++ lib/pipeline/version.map | 2 + 3 files changed, 268 insertions(+) diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h index 0694df557a..1b47820441 100644 --- a/lib/pipeline/rte_swx_ctl.h +++ b/lib/pipeline/rte_swx_ctl.h @@ -1237,6 +1237,58 @@ rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p, uint32_t regarray_index, uint64_t value); +/** + * Register read with table key lookup + * + * @param[in] p + * Pipeline handle. + * @param[in] regarray_name + * Register array name. + * @param[in] table_name + * Regular or learner table name. + * @param[in] table_key + * Table key. + * @param[out] value + * Current register value. + * @return + * 0 on success or the following error codes otherwise: + * -EINVAL: Invalid argument; + * -ENOMEM: Not enough memory. + */ +__rte_experimental +int +rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p, + const char *regarray_name, + const char *table_name, + uint8_t *table_key, + uint64_t *value); + +/** + * Register write with table key lookup + * + * @param[in] p + * Pipeline handle. + * @param[in] regarray_name + * Register array name. + * @param[in] table_name + * Regular or learner table name. + * @param[in] table_key + * Table key. + * @param[in] value + * Value to be written to the register. + * @return + * 0 on success or the following error codes otherwise: + * -EINVAL: Invalid argument; + * -ENOMEM: Not enough memory. + */ +__rte_experimental +int +rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p, + const char *regarray_name, + const char *table_name, + uint8_t *table_key, + uint64_t value); + /* * Meter Array Query and Configuration API. */ diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index ec8268b7f8..e726bf1575 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -11101,6 +11101,220 @@ rte_swx_ctl_pipeline_mirroring_session_set(struct rte_swx_pipeline *p, return 0; } +static int +rte_swx_ctl_pipeline_table_lookup(struct rte_swx_pipeline *p, + const char *table_name, + uint8_t *key, + uint64_t *action_id, + uint8_t **action_data, + size_t *entry_id, + int *hit) +{ + struct table *t; + void *mailbox = NULL; + + /* Check input arguments. */ + if (!p || + !p->build_done || + !table_name || + !table_name[0] || + !key || + !entry_id || + !hit) + return -EINVAL; + + /* Find the table. */ + t = table_find(p, table_name); + if (!t) + return -EINVAL; + + if (!t->type) { + *hit = 0; + return 0; + } + + /* Setup mailbox. */ + if (t->type->ops.mailbox_size_get) { + uint64_t mailbox_size; + + mailbox_size = t->type->ops.mailbox_size_get(); + if (mailbox_size) { + mailbox = calloc(1, mailbox_size); + if (!mailbox) + return -ENOMEM; + } + } + + /* Table lookup operation. */ + for ( ; ; ) { + struct rte_swx_table_state *ts = &p->table_state[t->id]; + int done; + + done = t->type->ops.lkp(ts->obj, + mailbox, + &key, + action_id, + action_data, + entry_id, + hit); + if (done) + break; + } + + /* Free mailbox. */ + free(mailbox); + + return 0; +} + +static int +rte_swx_ctl_pipeline_learner_lookup(struct rte_swx_pipeline *p, + const char *learner_name, + uint8_t *key, + uint64_t *action_id, + uint8_t **action_data, + size_t *entry_id, + int *hit) +{ + struct learner *l; + void *mailbox = NULL; + uint64_t mailbox_size, time; + + /* Check input arguments. */ + if (!p || + !p->build_done || + !learner_name || + !learner_name[0] || + !key || + !entry_id || + !hit) + return -EINVAL; + + /* Find the learner table. */ + l = learner_find(p, learner_name); + if (!l) + return -EINVAL; + + /* Setup mailbox. */ + mailbox_size = rte_swx_table_learner_mailbox_size_get(); + if (mailbox_size) { + mailbox = calloc(1, mailbox_size); + if (!mailbox) + return -ENOMEM; + } + + /* Learner table lookup operation. */ + time = rte_get_tsc_cycles(); + for ( ; ; ) { + uint32_t pos = p->n_tables + p->n_selectors + l->id; + struct rte_swx_table_state *ts = &p->table_state[pos]; + int done; + + done = rte_swx_table_learner_lookup(ts->obj, + mailbox, + time, + &key, + action_id, + action_data, + entry_id, + hit); + if (done) + break; + } + + /* Free mailbox. */ + free(mailbox); + + return 0; +} + +static int +rte_swx_ctl_pipeline_table_entry_id_get(struct rte_swx_pipeline *p, + const char *table_name, + uint8_t *table_key, + size_t *table_entry_id) +{ + struct table *t; + struct learner *l; + uint64_t action_id; + uint8_t *action_data; + size_t entry_id = 0; + int hit = 0, status; + + /* Check input arguments. */ + if (!p || + !p->build_done || + !table_name || + !table_name[0] || + !table_key || + !table_entry_id) + return -EINVAL; + + t = table_find(p, table_name); + l = learner_find(p, table_name); + if (!t && !l) + return -EINVAL; + + /* Table lookup operation. */ + if (t) + status = rte_swx_ctl_pipeline_table_lookup(p, + table_name, + table_key, + &action_id, + &action_data, + &entry_id, + &hit); + else + status = rte_swx_ctl_pipeline_learner_lookup(p, + table_name, + table_key, + &action_id, + &action_data, + &entry_id, + &hit); + if (status) + return status; + + /* Reserve entry ID 0 for the table default entry. */ + *table_entry_id = hit ? (1 + entry_id) : 0; + + return 0; +} + +int +rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p, + const char *regarray_name, + const char *table_name, + uint8_t *table_key, + uint64_t *value) +{ + size_t entry_id = 0; + int status; + + status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id); + if (status) + return status; + + return rte_swx_ctl_pipeline_regarray_read(p, regarray_name, entry_id, value); +} + +int +rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p, + const char *regarray_name, + const char *table_name, + uint8_t *table_key, + uint64_t value) +{ + size_t entry_id = 0; + int status; + + status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id); + if (status) + return status; + + return rte_swx_ctl_pipeline_regarray_write(p, regarray_name, entry_id, value); +} + /* * Pipeline compilation. */ diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map index 16806e6802..8ed92042d6 100644 --- a/lib/pipeline/version.map +++ b/lib/pipeline/version.map @@ -147,6 +147,8 @@ EXPERIMENTAL { #added in 22.11 rte_swx_ctl_pipeline_find; + rte_swx_ctl_pipeline_regarray_read_with_key; + rte_swx_ctl_pipeline_regarray_write_with_key; rte_swx_pipeline_build_from_lib; rte_swx_pipeline_codegen; rte_swx_pipeline_find; From patchwork Fri Aug 26 10:36:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115467 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BA572A0554; Fri, 26 Aug 2022 12:36:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C31C84281B; Fri, 26 Aug 2022 12:36:16 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id B3D9540146 for ; Fri, 26 Aug 2022 12:36:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661510171; x=1693046171; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=BsP9tFH10us3y0x4ESy4voEddYGI/h2vii2wf5Qjvfg=; b=jbKGU1/b9K7dVn7FSEl+QIBvRSWu9TTkcdfebXtBb4ZkHmc6CT/i1MPJ LiEq1wZ3t5Rn5AgXyp+gklc/7GgudE3uYu2wsTy4ms/837wOkMSnwmxEL YLxCFGwmnxEj0188YTSyQYL4l8TW6Fng77sQFfA2vhgYXP8X+5FlpShlb 8ZWX71jg8rlncHvywLoVhygesBxwNT08A/3voH5ljbcDV5PEAW0q2IHwh 8cF7m950TL1spHNHRMOL6uOgA25pgJds92J79rwwDTAGjWKcjio7DmloY WbjAlR7ILdZNDXg6KcnSrzvnftADeBOI0Qt+9dDdO/Kh4C9tGXoHM5lg7 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="356194329" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="356194329" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:36:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="671414290" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 26 Aug 2022 03:36:10 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 5/7] pipeline: support direct meters on the control path Date: Fri, 26 Aug 2022 10:36:03 +0000 Message-Id: <20220826103605.1579589-6-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 Add pipeline control path API to manage direct meters. These meters are identified by a table key, whose entry ID is used as the index into the meter array. Signed-off-by: Cristian Dumitrescu --- lib/pipeline/rte_swx_ctl.h | 81 +++++++++++++++++++++++++++++++++ lib/pipeline/rte_swx_pipeline.c | 50 ++++++++++++++++++++ lib/pipeline/version.map | 3 ++ 3 files changed, 134 insertions(+) diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h index 1b47820441..2eb51b2c76 100644 --- a/lib/pipeline/rte_swx_ctl.h +++ b/lib/pipeline/rte_swx_ctl.h @@ -1440,6 +1440,87 @@ rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p, uint32_t metarray_index, struct rte_swx_ctl_meter_stats *stats); +/** + * Meter reset with table key lookup + * + * Reset a meter within a given meter array to use the default profile that + * causes all the input packets to be colored as green. It is the responsibility + * of the control plane to make sure this meter is not used by the data plane + * pipeline before calling this function. + * + * @param[in] p + * Pipeline handle. + * @param[in] metarray_name + * Meter array name. + * @param[in] table_name + * Regular or learner table name. + * @param[in] table_key + * Table key. + * @return + * 0 on success or the following error codes otherwise: + * -EINVAL: Invalid argument. + */ +__rte_experimental +int +rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p, + const char *metarray_name, + const char *table_name, + uint8_t *table_key); + +/** + * Meter set with table key lookup + * + * Set a meter within a given meter array to use a specific profile. It is the + * responsibility of the control plane to make sure this meter is not used by + * the data plane pipeline before calling this function. + * + * @param[in] p + * Pipeline handle. + * @param[in] metarray_name + * Meter array name. + * @param[in] table_name + * Regular or learner table name. + * @param[in] table_key + * Table key. + * @param[in] profile_name + * Existing meter profile name. + * @return + * 0 on success or the following error codes otherwise: + * -EINVAL: Invalid argument. + */ +__rte_experimental +int +rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p, + const char *metarray_name, + const char *table_name, + uint8_t *table_key, + const char *profile_name); + +/** + * Meter statistics counters read with table key lookup + * + * @param[in] p + * Pipeline handle. + * @param[in] metarray_name + * Meter array name. + * @param[in] table_name + * Regular or learner table name. + * @param[in] table_key + * Table key. + * @param[out] stats + * Meter statistics counters. + * @return + * 0 on success or the following error codes otherwise: + * -EINVAL: Invalid argument. + */ +__rte_experimental +int +rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p, + const char *metarray_name, + const char *table_name, + uint8_t *table_key, + struct rte_swx_ctl_meter_stats *stats); + /** * Pipeline control free * diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index e726bf1575..4b1b311093 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -11315,6 +11315,56 @@ rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p, return rte_swx_ctl_pipeline_regarray_write(p, regarray_name, entry_id, value); } +int +rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p, + const char *metarray_name, + const char *table_name, + uint8_t *table_key) +{ + size_t entry_id = 0; + int status; + + status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id); + if (status) + return status; + + return rte_swx_ctl_meter_reset(p, metarray_name, entry_id); +} + +int +rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p, + const char *metarray_name, + const char *table_name, + uint8_t *table_key, + const char *profile_name) +{ + size_t entry_id = 0; + int status; + + status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id); + if (status) + return status; + + return rte_swx_ctl_meter_set(p, metarray_name, entry_id, profile_name); +} + +int +rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p, + const char *metarray_name, + const char *table_name, + uint8_t *table_key, + struct rte_swx_ctl_meter_stats *stats) +{ + size_t entry_id = 0; + int status; + + status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id); + if (status) + return status; + + return rte_swx_ctl_meter_stats_read(p, metarray_name, entry_id, stats); +} + /* * Pipeline compilation. */ diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map index 8ed92042d6..f53a037edf 100644 --- a/lib/pipeline/version.map +++ b/lib/pipeline/version.map @@ -146,6 +146,9 @@ EXPERIMENTAL { rte_swx_pipeline_hash_func_register; #added in 22.11 + rte_swx_ctl_meter_reset_with_key; + rte_swx_ctl_meter_set_with_key; + rte_swx_ctl_meter_stats_read_with_key; rte_swx_ctl_pipeline_find; rte_swx_ctl_pipeline_regarray_read_with_key; rte_swx_ctl_pipeline_regarray_write_with_key; From patchwork Fri Aug 26 10:36:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115468 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2323DA0554; Fri, 26 Aug 2022 12:36:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF5CC42905; Fri, 26 Aug 2022 12:36:17 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 31FC4410D2 for ; Fri, 26 Aug 2022 12:36:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661510172; x=1693046172; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=CKjg0OzEyV5pJFb9dwNKSMBTincPIj53asLikmsIXI0=; b=Oa/AKyVgZ8aUalcl12vwkXDniqZK32gScwsps66Fe/oWFv/m83a/ShSb LYY+SudIdU9hD6cvYk5yX0q7PeVlBS9J3nW9SrWh7rxKQPlakv270cKvF iuw7N3c0lMzZkzTbUrC5kgglCnjU17cbFw6F4v7XdUxLJxXrqRYAPZMtP DCCUHKWcGIoXU3ev/nZ5GFvFeo4q821lrS5Sr8RUV7fHG7J9ePIvOJLjb oNfNwVWT14A5vpfHREPOU+M+iXcChg/eue++8gSKbODE5xP0MxpYwjrOk HXifo4ICz3n+WfQ/YGpyvq85PK5qgey72dyEwdK0qBkx0Niqt7/xKctZ+ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="356194330" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="356194330" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:36:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="671414294" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 26 Aug 2022 03:36:11 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 6/7] examples/pipeline: add CLI commands for direct registers Date: Fri, 26 Aug 2022 10:36:04 +0000 Message-Id: <20220826103605.1579589-7-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 Add the CLI command support for reading/writing direct registers. Signed-off-by: Cristian Dumitrescu --- examples/pipeline/cli.c | 228 +++++++++++++++++++++++++++++++++------- 1 file changed, 192 insertions(+), 36 deletions(-) diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index 2e69698031..72998f580b 100644 --- a/examples/pipeline/cli.c +++ b/examples/pipeline/cli.c @@ -142,6 +142,54 @@ is_comment(char *in) return 0; } +static void +table_entry_free(struct rte_swx_table_entry *entry) +{ + if (!entry) + return; + + free(entry->key); + free(entry->key_mask); + free(entry->action_data); + free(entry); +} + +static struct rte_swx_table_entry * +parse_table_entry(struct rte_swx_ctl_pipeline *p, + char *table_name, + char **tokens, + uint32_t n_tokens) +{ + struct rte_swx_table_entry *entry; + char *line; + uint32_t i; + + /* Buffer allocation. */ + line = malloc(MAX_LINE_SIZE); + if (!line) + return NULL; + + /* Copy tokens to buffer. Since the tokens were initially part of a buffer of size + * MAX_LINE_LENGTH, it is guaranteed that putting back some of them into a buffer of the + * same size separated by a single space will not result in buffer overrun. + */ + line[0] = 0; + for (i = 0; i < n_tokens; i++) { + if (i) + strcat(line, " "); + + strcat(line, tokens[i]); + } + + /* Read the table entry from the input buffer. */ + entry = rte_swx_ctl_pipeline_table_entry_read(p, table_name, line, NULL); + + /* Buffer free. */ + free(line); + + return entry; +} + static const char cmd_mempool_help[] = "mempool \n" " buffer \n" @@ -732,18 +780,6 @@ cmd_pipeline_build(char **tokens, fclose(iospec_file); } -static void -table_entry_free(struct rte_swx_table_entry *entry) -{ - if (!entry) - return; - - free(entry->key); - free(entry->key_mask); - free(entry->action_data); - free(entry); -} - static int pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, const char *table_name, @@ -1710,7 +1746,9 @@ cmd_pipeline_abort(char **tokens, } static const char cmd_pipeline_regrd_help[] = -"pipeline regrd \n"; +"pipeline regrd " + "index " + " | table match ...\n"; static void cmd_pipeline_regrd(char **tokens, @@ -1720,18 +1758,20 @@ cmd_pipeline_regrd(char **tokens, void *obj __rte_unused) { struct rte_swx_pipeline *p; - const char *name; + struct rte_swx_ctl_pipeline *ctl; + const char *pipeline_name, *name; uint64_t value; - uint32_t idx; int status; - if (n_tokens != 5) { + if (n_tokens < 5) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } - p = rte_swx_pipeline_find(tokens[1]); - if (!p) { + pipeline_name = tokens[1]; + p = rte_swx_pipeline_find(pipeline_name); + ctl = rte_swx_ctl_pipeline_find(pipeline_name); + if (!p || !ctl) { snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); return; } @@ -1743,22 +1783,77 @@ cmd_pipeline_regrd(char **tokens, name = tokens[3]; - if (parser_read_uint32(&idx, tokens[4])) { - snprintf(out, out_size, MSG_ARG_INVALID, "index"); + /* index. */ + if (!strcmp(tokens[4], "index")) { + uint32_t idx; + + if (n_tokens != 6) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + if (parser_read_uint32(&idx, tokens[5])) { + snprintf(out, out_size, MSG_ARG_INVALID, "index"); + return; + } + + status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value); + if (status) { + snprintf(out, out_size, "Command failed.\n"); + return; + } + + snprintf(out, out_size, "0x%" PRIx64 "\n", value); return; } - status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value); - if (status) { - snprintf(out, out_size, "Command failed.\n"); + /* table. */ + if (!strcmp(tokens[4], "table")) { + struct rte_swx_table_entry *entry; + char *table_name; + + if (n_tokens < 8) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + table_name = tokens[5]; + + if (strcmp(tokens[6], "match")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); + return; + } + + entry = parse_table_entry(ctl, table_name, &tokens[6], n_tokens - 6); + if (!entry) { + snprintf(out, out_size, "Invalid match tokens.\n"); + return; + } + + status = rte_swx_ctl_pipeline_regarray_read_with_key(p, + name, + table_name, + entry->key, + &value); + table_entry_free(entry); + if (status) { + snprintf(out, out_size, "Command failed.\n"); + return; + } + + snprintf(out, out_size, "0x%" PRIx64 "\n", value); return; } - snprintf(out, out_size, "0x%" PRIx64 "\n", value); + /* anything else. */ + snprintf(out, out_size, "Invalid token %s\n.", tokens[4]); + return; } static const char cmd_pipeline_regwr_help[] = -"pipeline regwr \n"; +"pipeline regwr value " + "index " + " | table match ...\n"; static void cmd_pipeline_regwr(char **tokens, @@ -1768,18 +1863,20 @@ cmd_pipeline_regwr(char **tokens, void *obj __rte_unused) { struct rte_swx_pipeline *p; - const char *name; - uint64_t value; - uint32_t idx; + struct rte_swx_ctl_pipeline *ctl; + const char *pipeline_name, *name; + uint64_t value = 0; int status; - if (n_tokens != 6) { + if (n_tokens < 7) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } - p = rte_swx_pipeline_find(tokens[1]); - if (!p) { + pipeline_name = tokens[1]; + p = rte_swx_pipeline_find(pipeline_name); + ctl = rte_swx_ctl_pipeline_find(pipeline_name); + if (!p || !ctl) { snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); return; } @@ -1791,8 +1888,8 @@ cmd_pipeline_regwr(char **tokens, name = tokens[3]; - if (parser_read_uint32(&idx, tokens[4])) { - snprintf(out, out_size, MSG_ARG_INVALID, "index"); + if (strcmp(tokens[4], "value")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "value"); return; } @@ -1801,11 +1898,70 @@ cmd_pipeline_regwr(char **tokens, return; } - status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value); - if (status) { - snprintf(out, out_size, "Command failed.\n"); + /* index. */ + if (!strcmp(tokens[6], "index")) { + uint32_t idx; + + if (n_tokens != 8) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + if (parser_read_uint32(&idx, tokens[7])) { + snprintf(out, out_size, MSG_ARG_INVALID, "index"); + return; + } + + status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value); + if (status) { + snprintf(out, out_size, "Command failed.\n"); + return; + } + + snprintf(out, out_size, "0x%" PRIx64 "\n", value); return; } + + /* table. */ + if (!strcmp(tokens[6], "table")) { + struct rte_swx_table_entry *entry; + char *table_name; + + if (n_tokens < 10) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + table_name = tokens[7]; + + if (strcmp(tokens[8], "match")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); + return; + } + + entry = parse_table_entry(ctl, table_name, &tokens[8], n_tokens - 8); + if (!entry) { + snprintf(out, out_size, "Invalid match tokens.\n"); + return; + } + + status = rte_swx_ctl_pipeline_regarray_write_with_key(p, + name, + table_name, + entry->key, + value); + table_entry_free(entry); + if (status) { + snprintf(out, out_size, "Command failed.\n"); + return; + } + + return; + } + + /* anything else. */ + snprintf(out, out_size, "Invalid token %s\n.", tokens[6]); + return; } static const char cmd_pipeline_meter_profile_add_help[] = From patchwork Fri Aug 26 10:36:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115469 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1F6B3A0554; Fri, 26 Aug 2022 12:36:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 979E942B6F; Fri, 26 Aug 2022 12:36:18 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id E9A24410D2 for ; Fri, 26 Aug 2022 12:36:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661510173; x=1693046173; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=5raGhCc4aHNDcFVoUm+gNSoxFRD4A7HZwZivjAN4MMo=; b=RWG3kyInAWpNqerSg44aj7Qhm6UYs8yL62hbV2fiQ3H0eNZuWKbVAblw thd9nkm5u/kTJRNLz1lpxsaAVAjGfnC+UL4JhyeVShB+F4VEGrsj6Auov xUmbmN+LHFWLJHZi2GHKJYHzLHQPpqQI29D+OBk7i1/8tRK1bvpsmS+M1 jwdSznH1XhjLGb5veLSc+Wm9515G5Fn1ulJMcek54x6S5xlJ6/2AMBbtf uBAPExkSXbj4+sZY8Gzy5/9TgtKqhANwAk7jb61OjZVoPn2R2KBU4pfr+ qn/0Svf3NaUm9wzpAAPTOK859kNSr/F7ALrh6vJywak6m0PmPB/yZr9JL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="356194331" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="356194331" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 03:36:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="671414298" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 26 Aug 2022 03:36:11 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 7/7] examples/pipeline: add CLI commands for direct meters Date: Fri, 26 Aug 2022 10:36:05 +0000 Message-Id: <20220826103605.1579589-8-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 Add the CLI command support for managing direct meters. Signed-off-by: Cristian Dumitrescu --- examples/pipeline/cli.c | 414 ++++++++++++++++++++------- examples/pipeline/examples/meter.cli | 2 +- 2 files changed, 309 insertions(+), 107 deletions(-) diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index 72998f580b..4ddece3571 100644 --- a/examples/pipeline/cli.c +++ b/examples/pipeline/cli.c @@ -2105,8 +2105,9 @@ cmd_pipeline_meter_profile_delete(char **tokens, } static const char cmd_pipeline_meter_reset_help[] = -"pipeline meter from to " - "reset\n"; +"pipeline meter reset" + "index from to " + " | table match ...\n"; static void cmd_pipeline_meter_reset(char **tokens, @@ -2116,16 +2117,18 @@ cmd_pipeline_meter_reset(char **tokens, void *obj __rte_unused) { struct rte_swx_pipeline *p; - const char *name; - uint32_t idx0 = 0, idx1 = 0; + struct rte_swx_ctl_pipeline *ctl; + const char *pipeline_name, *name; - if (n_tokens != 9) { + if (n_tokens < 6) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } - p = rte_swx_pipeline_find(tokens[1]); - if (!p) { + pipeline_name = tokens[1]; + p = rte_swx_pipeline_find(pipeline_name); + ctl = rte_swx_ctl_pipeline_find(pipeline_name); + if (!p || !ctl) { snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); return; } @@ -2137,45 +2140,96 @@ cmd_pipeline_meter_reset(char **tokens, name = tokens[3]; - if (strcmp(tokens[4], "from")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); + if (strcmp(tokens[4], "reset")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset"); return; } - if (parser_read_uint32(&idx0, tokens[5])) { - snprintf(out, out_size, MSG_ARG_INVALID, "index0"); - return; - } + /* index. */ + if (!strcmp(tokens[5], "index")) { + uint32_t idx0 = 0, idx1 = 0; - if (strcmp(tokens[6], "to")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); - return; - } + if (n_tokens != 10) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } - if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { - snprintf(out, out_size, MSG_ARG_INVALID, "index1"); - return; - } + if (strcmp(tokens[6], "from")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); + return; + } + + if (parser_read_uint32(&idx0, tokens[7])) { + snprintf(out, out_size, MSG_ARG_INVALID, "index0"); + return; + } + + if (strcmp(tokens[8], "to")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); + return; + } + + if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) { + snprintf(out, out_size, MSG_ARG_INVALID, "index1"); + return; + } + + for ( ; idx0 <= idx1; idx0++) { + int status; + + status = rte_swx_ctl_meter_reset(p, name, idx0); + if (status) { + snprintf(out, out_size, "Command failed for index %u.\n", idx0); + return; + } + } - if (strcmp(tokens[8], "reset")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset"); return; } - for ( ; idx0 <= idx1; idx0++) { + /* table. */ + if (!strcmp(tokens[5], "table")) { + struct rte_swx_table_entry *entry; + char *table_name; int status; - status = rte_swx_ctl_meter_reset(p, name, idx0); + if (n_tokens < 9) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + table_name = tokens[6]; + + if (strcmp(tokens[7], "match")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); + return; + } + + entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7); + if (!entry) { + snprintf(out, out_size, "Invalid match tokens.\n"); + return; + } + + status = rte_swx_ctl_meter_reset_with_key(p, name, table_name, entry->key); + table_entry_free(entry); if (status) { - snprintf(out, out_size, "Command failed for index %u.\n", idx0); + snprintf(out, out_size, "Command failed.\n"); return; } + + return; } + + /* anything else. */ + snprintf(out, out_size, "Invalid token %s\n.", tokens[5]); + return; } static const char cmd_pipeline_meter_set_help[] = -"pipeline meter from to " - "set profile \n"; +"pipeline meter set profile " + "index from to " + " | table match ...\n"; static void cmd_pipeline_meter_set(char **tokens, @@ -2185,16 +2239,18 @@ cmd_pipeline_meter_set(char **tokens, void *obj __rte_unused) { struct rte_swx_pipeline *p; - const char *name, *profile_name; - uint32_t idx0 = 0, idx1 = 0; + struct rte_swx_ctl_pipeline *ctl; + const char *pipeline_name, *name, *profile_name; - if (n_tokens != 11) { + if (n_tokens < 8) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } - p = rte_swx_pipeline_find(tokens[1]); - if (!p) { + pipeline_name = tokens[1]; + p = rte_swx_pipeline_find(pipeline_name); + ctl = rte_swx_ctl_pipeline_find(pipeline_name); + if (!p || !ctl) { snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); return; } @@ -2206,52 +2262,107 @@ cmd_pipeline_meter_set(char **tokens, name = tokens[3]; - if (strcmp(tokens[4], "from")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); + if (strcmp(tokens[4], "set")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set"); return; } - if (parser_read_uint32(&idx0, tokens[5])) { - snprintf(out, out_size, MSG_ARG_INVALID, "index0"); + if (strcmp(tokens[5], "profile")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); return; } - if (strcmp(tokens[6], "to")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); - return; - } + profile_name = tokens[6]; - if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { - snprintf(out, out_size, MSG_ARG_INVALID, "index1"); - return; - } + /* index. */ + if (!strcmp(tokens[7], "index")) { + uint32_t idx0 = 0, idx1 = 0; - if (strcmp(tokens[8], "set")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set"); - return; - } + if (n_tokens != 12) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + if (strcmp(tokens[8], "from")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); + return; + } + + if (parser_read_uint32(&idx0, tokens[9])) { + snprintf(out, out_size, MSG_ARG_INVALID, "index0"); + return; + } + + if (strcmp(tokens[10], "to")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); + return; + } + + if (parser_read_uint32(&idx1, tokens[11]) || (idx1 < idx0)) { + snprintf(out, out_size, MSG_ARG_INVALID, "index1"); + return; + } + + for ( ; idx0 <= idx1; idx0++) { + int status; + + status = rte_swx_ctl_meter_set(p, name, idx0, profile_name); + if (status) { + snprintf(out, out_size, "Command failed for index %u.\n", idx0); + return; + } + } - if (strcmp(tokens[9], "profile")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); return; } - profile_name = tokens[10]; - - for ( ; idx0 <= idx1; idx0++) { + /* table. */ + if (!strcmp(tokens[7], "table")) { + struct rte_swx_table_entry *entry; + char *table_name; int status; - status = rte_swx_ctl_meter_set(p, name, idx0, profile_name); + if (n_tokens < 11) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + table_name = tokens[8]; + + if (strcmp(tokens[9], "match")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); + return; + } + + entry = parse_table_entry(ctl, table_name, &tokens[9], n_tokens - 9); + if (!entry) { + snprintf(out, out_size, "Invalid match tokens.\n"); + return; + } + + status = rte_swx_ctl_meter_set_with_key(p, + name, + table_name, + entry->key, + profile_name); + table_entry_free(entry); if (status) { - snprintf(out, out_size, "Command failed for index %u.\n", idx0); + snprintf(out, out_size, "Command failed.\n"); return; } + + return; } + + /* anything else. */ + snprintf(out, out_size, "Invalid token %s\n.", tokens[7]); + return; } static const char cmd_pipeline_meter_stats_help[] = -"pipeline meter from to " - "stats\n"; +"pipeline meter stats" + "index from to " + " | table match ...\n"; static void cmd_pipeline_meter_stats(char **tokens, @@ -2262,16 +2373,18 @@ cmd_pipeline_meter_stats(char **tokens, { struct rte_swx_ctl_meter_stats stats; struct rte_swx_pipeline *p; - const char *name; - uint32_t idx0 = 0, idx1 = 0; + struct rte_swx_ctl_pipeline *ctl; + const char *pipeline_name, *name; - if (n_tokens != 9) { + if (n_tokens != 6) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } - p = rte_swx_pipeline_find(tokens[1]); - if (!p) { + pipeline_name = tokens[1]; + p = rte_swx_pipeline_find(pipeline_name); + ctl = rte_swx_ctl_pipeline_find(pipeline_name); + if (!p || !ctl) { snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); return; } @@ -2283,68 +2396,151 @@ cmd_pipeline_meter_stats(char **tokens, name = tokens[3]; - if (strcmp(tokens[4], "from")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); + if (strcmp(tokens[4], "stats")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); return; } - if (parser_read_uint32(&idx0, tokens[5])) { - snprintf(out, out_size, MSG_ARG_INVALID, "index0"); - return; - } + /* index. */ + if (!strcmp(tokens[5], "index")) { + uint32_t idx0 = 0, idx1 = 0; - if (strcmp(tokens[6], "to")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); - return; - } + if (n_tokens != 10) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } - if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { - snprintf(out, out_size, MSG_ARG_INVALID, "index1"); - return; - } + if (strcmp(tokens[6], "from")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); + return; + } + + if (parser_read_uint32(&idx0, tokens[7])) { + snprintf(out, out_size, MSG_ARG_INVALID, "index0"); + return; + } + + if (strcmp(tokens[8], "to")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); + return; + } + + if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) { + snprintf(out, out_size, MSG_ARG_INVALID, "index1"); + return; + } + + /* Table header. */ + snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", + "-------", + "----------------", "----------------", "----------------", + "----------------", "----------------", "----------------"); + out_size -= strlen(out); + out += strlen(out); + + snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n", + "METER #", + "GREEN (packets)", "YELLOW (packets)", "RED (packets)", + "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)"); + out_size -= strlen(out); + out += strlen(out); + + snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", + "-------", + "----------------", "----------------", "----------------", + "----------------", "----------------", "----------------"); + out_size -= strlen(out); + out += strlen(out); + + /* Table rows. */ + for ( ; idx0 <= idx1; idx0++) { + int status; + + status = rte_swx_ctl_meter_stats_read(p, name, idx0, &stats); + if (status) { + snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0); + out_size -= strlen(out); + out += strlen(out); + return; + } + + snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 + " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n", + idx0, + stats.n_pkts[RTE_COLOR_GREEN], + stats.n_pkts[RTE_COLOR_YELLOW], + stats.n_pkts[RTE_COLOR_RED], + stats.n_bytes[RTE_COLOR_GREEN], + stats.n_bytes[RTE_COLOR_YELLOW], + stats.n_bytes[RTE_COLOR_RED]); + out_size -= strlen(out); + out += strlen(out); + } - if (strcmp(tokens[8], "stats")) { - snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); return; } - /* Table header. */ - snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", - "-------", - "----------------", "----------------", "----------------", - "----------------", "----------------", "----------------"); - out_size -= strlen(out); - out += strlen(out); + /* table. */ + if (!strcmp(tokens[5], "table")) { + struct rte_swx_table_entry *entry; + char *table_name; + int status; - snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n", - "METER #", - "GREEN (packets)", "YELLOW (packets)", "RED (packets)", - "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)"); - out_size -= strlen(out); - out += strlen(out); + if (n_tokens < 9) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } - snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", - "-------", - "----------------", "----------------", "----------------", - "----------------", "----------------", "----------------"); - out_size -= strlen(out); - out += strlen(out); + table_name = tokens[6]; - /* Table rows. */ - for ( ; idx0 <= idx1; idx0++) { - int status; + if (strcmp(tokens[7], "match")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); + return; + } + + entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7); + if (!entry) { + snprintf(out, out_size, "Invalid match tokens.\n"); + return; + } - status = rte_swx_ctl_meter_stats_read(p, name, idx0, &stats); + status = rte_swx_ctl_meter_stats_read_with_key(p, + name, + table_name, + entry->key, + &stats); + table_entry_free(entry); if (status) { - snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0); - out_size -= strlen(out); - out += strlen(out); + snprintf(out, out_size, "Command failed.\n"); return; } + /* Table header. */ + snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", + "-------", + "----------------", "----------------", "----------------", + "----------------", "----------------", "----------------"); + out_size -= strlen(out); + out += strlen(out); + + snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n", + "METER #", + "GREEN (packets)", "YELLOW (packets)", "RED (packets)", + "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)"); + out_size -= strlen(out); + out += strlen(out); + + snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", + "-------", + "----------------", "----------------", "----------------", + "----------------", "----------------", "----------------"); + out_size -= strlen(out); + out += strlen(out); + + /* Table row. */ snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n", - idx0, + 0, stats.n_pkts[RTE_COLOR_GREEN], stats.n_pkts[RTE_COLOR_YELLOW], stats.n_pkts[RTE_COLOR_RED], @@ -2353,7 +2549,13 @@ cmd_pipeline_meter_stats(char **tokens, stats.n_bytes[RTE_COLOR_RED]); out_size -= strlen(out); out += strlen(out); + + return; } + + /* anything else. */ + snprintf(out, out_size, "Invalid token %s\n.", tokens[5]); + return; } static const char cmd_pipeline_stats_help[] = diff --git a/examples/pipeline/examples/meter.cli b/examples/pipeline/examples/meter.cli index c1b88c882a..21582554b9 100644 --- a/examples/pipeline/examples/meter.cli +++ b/examples/pipeline/examples/meter.cli @@ -35,7 +35,7 @@ pipeline PIPELINE0 build lib /tmp/meter.so io ./examples/pipeline/examples/ethde ; The table entries can later be updated at run-time through the CLI commands. ; pipeline PIPELINE0 meter profile platinum add cir 46000000 pir 138000000 cbs 1000000 pbs 1000000 -pipeline PIPELINE0 meter meters from 0 to 15 set profile platinum +pipeline PIPELINE0 meter meters set profile platinum index from 0 to 15 ; ; Pipelines-to-threads mapping.