From patchwork Fri Aug 26 11:21:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115472 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 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 ; 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 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 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 11:21:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115473 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 B41FCA0555; Fri, 26 Aug 2022 13:21:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B20FF427F6; Fri, 26 Aug 2022 13:21:34 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id A3F0940143 for ; Fri, 26 Aug 2022 13:21:31 +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=a+ZGfVh0lwX8bp1pVauqmtyRwEJ5vFF6+GqztZwiTSA=; b=KffN+WytXden/uEkaMdiGDVevkIOiXbDL/R+RgariS3z3hfe8VGF63Aq sW+Ot1nqgPrvnZpsnTJcUkFu9DG0CB7QJv6QkMhf2KtU4DNKfLrRgLOf+ A5Wm7famHpuLoLWcNFJAvHKBYzVwVw7km6wFQ1f/aOmb9u6oKSFVfictg XuxADvc6rZ4JiVQjuGolU57JA/znxc+vUTgyWdERHbHtTm4MyoZGESY3F 9LYrTzxyHni7cBOdZBxmNv0gZEQpplG9zEjqouc2YuIY0Akc8uRG2W8OA tnPmCerHYNfA9dKs9sANEkNROvXfIj1TV/pi+4McsCkvMJ2lkhnZlVpD7 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="295264073" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="295264073" 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="678834795" 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:30 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2 2/7] table: add entry ID for learner tables Date: Fri, 26 Aug 2022 11:21:22 +0000 Message-Id: <20220826112127.1580044-3-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 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 11:21:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115474 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 85232A0555; Fri, 26 Aug 2022 13:21:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 92AE840146; Fri, 26 Aug 2022 13:21:36 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 847BF40A80 for ; Fri, 26 Aug 2022 13:21:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661512892; x=1693048892; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=c5YHVF51WVwQBQOJ5eVbyFRUuGco+5s4B9CoVKSTnjw=; b=PJQG7i1+2MlR1c24d7w0xh3tGfcB+gr/S+QRHlVarbtuac9KKhfnz19/ ntl4LRFZxVEVYs5erDk+MgXMmuaMR0Ugkuk+j56hh+K5JQ24YVAwefQNp FOrgNn9/tBImcPpuCBDgBax2QRU7y5HE1osx46RvxWaI3WHyNh/H5EkQD 4R+onji/mvKcYbUgGUAlGgewrgLg7cza2/ym3iM9+Ia0+WHaW1xz7/c5c M57dbjSe3Ksn941mw9zmc1VV9thf8wPORB4Wjq7ZdQWizlfIlXXNiqgbi +CYlaA25d9lUvaYhfIPuTDkxpIcLpujibboJfpXd72MIUgHuHF71iKpxv w==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="295264077" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="295264077" 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:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="678834800" 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:31 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2 3/7] pipeline: add table entry ID read instruction Date: Fri, 26 Aug 2022 11:21:23 +0000 Message-Id: <20220826112127.1580044-4-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 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 11:21:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115475 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 A321BA0555; Fri, 26 Aug 2022 13:21:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6E9574281A; Fri, 26 Aug 2022 13:21:37 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id C24DD410D0 for ; Fri, 26 Aug 2022 13:21:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661512893; x=1693048893; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=kohfYz5OkYujxjOl5j8VnlJCSwrypbwXmoBsOpYBPio=; b=l0IksytATJJs9bODVPuDrQ6nhKlyMMpqbwe1ciAs4e0B+l0bhfGnnXlG 5+t3QnhPHm32YqOpIr3P9XKMsjfLd4HQc0Jt3pJ6C5gSH/qsMFuD343yx oabW2rGBE5XFOPoApELNNdN66+SXp/kQpAQXVOugSao+ge01oFB4+rLLx IwrhnaFRUio3XfxXfoZz6yF0W57c0oEAuBNGXEiIWKQau3r5lLcQCw+mo /pn7+ZY0wZoAkNUs3C3tkCKjmdyo8AbEVwZ0q3trSZgpy3bR72W3Vi0Wc J1LxFKpuKneqUAgi0HmL9bEb1YVGYpWoopVvnaYr2pOV6utmG5pjx/UO4 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="295264080" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="295264080" 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:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="678834802" 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:31 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2 4/7] pipeline: support direct registers on the control path Date: Fri, 26 Aug 2022 11:21:24 +0000 Message-Id: <20220826112127.1580044-5-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 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 11:21:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115476 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 8B856A0555; Fri, 26 Aug 2022 13:21:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 37A8542826; Fri, 26 Aug 2022 13:21:38 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 7F97940A80 for ; Fri, 26 Aug 2022 13:21:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661512893; x=1693048893; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=BsP9tFH10us3y0x4ESy4voEddYGI/h2vii2wf5Qjvfg=; b=a30LKsCiHlp/JkRNrHJmGu+wDDNev8w5zgxUZ+IEdhQbS31JDVLj85Ax SY3/VcmCUizv24wHipMpVXu+R09p51v0KN2GN8uFD9G4/aRnBJHfxu9JA 9TW19r8FT2mQzZcnqpTKuwEUIlnEZGg0FAhukEb40Xun0vKuhSdst0lKO mIKRZVunDIxzg/sdT4nXqOGtqoZnIqQDHxVBGGPzWOYL1Sx7iWAuvilT2 BGGiXhSHDsMUeFf1NvWyz1f0/qvYkvHTiE2TV2W42kGosJ0ZAj6/Wyf+Z AokphrNf6UhTZuLxbMIiASqSXkp7d7y8XGI30cpoMI9uD+ehPQ0yMW+rO g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="295264082" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="295264082" 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:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="678834807" 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:32 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2 5/7] pipeline: support direct meters on the control path Date: Fri, 26 Aug 2022 11:21:25 +0000 Message-Id: <20220826112127.1580044-6-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 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 11:21:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115477 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 5F6E7A0555; Fri, 26 Aug 2022 13:22:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ED2FC4282F; Fri, 26 Aug 2022 13:21:38 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 4B0E4427E9 for ; Fri, 26 Aug 2022 13:21:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661512894; x=1693048894; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=sx/iaGyaadlMWvywXnlJlbEUv5hTvQSceNb+Jn4oEVo=; b=KfUw22yWZ/K96MxO056wn6VRIcoZuSzEe7YpftS7zqh04MN1xS+wQFLy yUCkJZZAPzDIgl+v391qqImyNEyLbgfGK/a1BNh+vZ0O9FtYwOFvuKbm9 mNG2y9lx5je6eHF98ccWk51QNOOR9m78OVeXfMvDipxRpLNIsLlh66Wt8 gHmcuNbkTYahSXJCqJhlk7baFzKNwvZMbtJWa00V1f6pFXtYzN6Kfjh7Z R4Rz9zxZA94ao8lD80g74Z/QubBdlAveiq34m5sezqOiAwNSOqZNorslM +mSAHez4uIY2XJ+iCsR7rqd0JAkGJ/Eoal5z2kZf9Z/FuwLdgJJh9oqie g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="295264084" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="295264084" 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:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="678834812" 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:33 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2 6/7] examples/pipeline: add CLI commands for direct registers Date: Fri, 26 Aug 2022 11:21:26 +0000 Message-Id: <20220826112127.1580044-7-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 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..115147adfc 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 \n" + "index \n" + " | 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 \n" + "index \n" + " | 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 11:21:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115478 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 69770A0555; Fri, 26 Aug 2022 13:22:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D256142905; Fri, 26 Aug 2022 13:21:39 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 068A5427E9 for ; Fri, 26 Aug 2022 13:21:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661512895; x=1693048895; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=sIy+crgqOiVRv2UWI3s0tkPXfmZXfrpVM2YO6rDzWWs=; b=c/u+rGBEAYO31SLfx34ava7jSG0Zn6lva7iO1895q9bscNOacceZfrrL aDZay29EyjnEFd1VMBOyr32UEMUS5cZR3+m+JDI3g2zOV3AIa779D4aMa 4esJkoaULcZUwhpV0sFqXcUwnusEkkr8Jl59gFoAEjK4OHbmmVRsObaYF EpV7nIbcglGS/nPXR/GIrrQkLQry49iq13x6/5VzLirobnRJtoCu42iIm CsiywXLMNFqhnxWqalhk3Ccl6DGJk05PXQREFPrjB1DMCILkW5jUszldz S9DNlwpHAEI5ycA6sNXgMaJNSr0eeqQJ123H4DwziUICDo+bYR/J9rfuH w==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="295264086" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="295264086" 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:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="678834815" 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:34 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2 7/7] examples/pipeline: add CLI commands for direct meters Date: Fri, 26 Aug 2022 11:21:27 +0000 Message-Id: <20220826112127.1580044-8-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 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 115147adfc..829eb8fad3 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\n" + "index from to \n" + " | 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 \n" + "index from to \n" + " | 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\n" + "index from to \n" + " | 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, "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.