From patchwork Tue Aug 30 18:58: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: 115657 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 ABCA4A00C5; Tue, 30 Aug 2022 20:58:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9F40E40F18; Tue, 30 Aug 2022 20:58:28 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id E4BF240F35 for ; Tue, 30 Aug 2022 20:58:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661885905; x=1693421905; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=LIe1Db/ahV3Y4yVUVelEXN9T5EjffV0QH1AT7aQtB9I=; b=ARDekcJ4Rn/m5z48Punzeu6WRCq5aescFWvqZKS/szmMBFqh1bi04RXD YIJcCK20J5am89LS0m5a5wlYmBHo4nqxG3PMGDfk/lHyEZ6hY2n+9ZlIl 8OWzjH/rxAQko8EwTPHceWTDzfAOBvp6ipuIXAniCWJK/xxLM6GuiUX87 ZyA6SjACOknUnQiekqnAOa+seFgNKw/TaBLHlw9iZ3ZVhmFeyzevatr1N NtvREIzC3cAp8jXvAvc690c56XnrhsOcP8VXhl8iedoxlRTb7BQHkpN8g +Cfmm0U0ITMoM5JwIEiKM+ziCd/vNaYwfVELZ0EZHBkD1qMLka6EYaR6f g==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="296554013" X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="296554013" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 11:58:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="562770842" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga003.jf.intel.com with ESMTP; 30 Aug 2022 11:58:13 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V3 1/7] table: add entry ID for regular tables Date: Tue, 30 Aug 2022 18:58:05 +0000 Message-Id: <20220830185811.1843109-2-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830185811.1843109-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> <20220830185811.1843109-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 Tue Aug 30 18:58:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115658 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 784CEA00C5; Tue, 30 Aug 2022 20:58:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 624EF427F7; Tue, 30 Aug 2022 20:58:29 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 7A4A740FAE for ; Tue, 30 Aug 2022 20:58:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661885905; x=1693421905; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=a+ZGfVh0lwX8bp1pVauqmtyRwEJ5vFF6+GqztZwiTSA=; b=MZzugB3mpeG0V0xm32cmqs/CWOpPIENfnAiilD4UH44b+flLGCmSBPpJ 11C4YDJ+CZkbROzsEcT7HiXb137Y23MnQHYifbL6qdc1HJq2tD47mGWR1 aJyGMWNlBnVT/waD009wOSrmcJ29YXMogKnIsvMkdJM3Wgr0dz3IDzxlp +7l7hff6l/YI8xmivYXEJ/64GeB2D8/kaPgVhL5QYrqCn8win44dKE2xd iZlLlOSEniXdeo5VvOm/9llq1h+4D/2PMRk3khQon1ASWer0iw9Jb0Y2W M2pE1WuQPc/A8/qLMWgF4cv1sKT6mHYzOxvONppRj29Ok8HpryNB3WyXB g==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="296554015" X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="296554015" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 11:58:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="562770848" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga003.jf.intel.com with ESMTP; 30 Aug 2022 11:58:14 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V3 2/7] table: add entry ID for learner tables Date: Tue, 30 Aug 2022 18:58:06 +0000 Message-Id: <20220830185811.1843109-3-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830185811.1843109-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> <20220830185811.1843109-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 Tue Aug 30 18:58:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115660 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 B4A9DA00C5; Tue, 30 Aug 2022 20:58:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EBDF54282B; Tue, 30 Aug 2022 20:58:30 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 682BE427ED for ; Tue, 30 Aug 2022 20:58:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661885906; x=1693421906; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=c5YHVF51WVwQBQOJ5eVbyFRUuGco+5s4B9CoVKSTnjw=; b=fbzflHFJivheYuJvskWRx+LbfaF4YC1UYrODzErYt+xwRP5hxQwCEZCV woJBLXMkUKjVEz4h8Bz81t55K9gPxI03IZxrTnlPoKw5uIXmsluNbi31Y TWBbaACOX4CRHYsVdSNwewdlc7IpBmUHNPbHsgE/N3qt48mrG4MZ2JAbo pOJ8Mm/j20fy+9NlCwYoLtBeD04FKQrhhOQt49vEWhTPf8gCviZTXZUOH BPqjk6QilxZgUGOOU71h9G6j7LJJPI3aU4FzqyCaf9ASYZYoB4oUR0JgT aZc2KvFr+xZ4DcFNEgZ9ZWR6+CXK/U8MC1jzaP9yD16gVgDrCaohgAI41 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="296554019" X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="296554019" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 11:58:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="562770850" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga003.jf.intel.com with ESMTP; 30 Aug 2022 11:58:14 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V3 3/7] pipeline: add table entry ID read instruction Date: Tue, 30 Aug 2022 18:58:07 +0000 Message-Id: <20220830185811.1843109-4-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830185811.1843109-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> <20220830185811.1843109-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 Tue Aug 30 18:58:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115659 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 4C221A00C5; Tue, 30 Aug 2022 20:58:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 23A664281B; Tue, 30 Aug 2022 20:58:30 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id E9A3B41132 for ; Tue, 30 Aug 2022 20:58:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661885906; x=1693421906; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=K1gcF8Sfl+vp8bcFmAbR+98NorEjpsniHq5wnmwVYts=; b=N5JLiIlXkpbFBzeFvaN76B43vjUtXjt0U9N5Xn1rzhh40GiIT7ZLqFsT 7w3sPpkyd5I94aGxuraWdHX5XmaxvwJL7qTT3W2GaGDblWNcRGTyjE9SG 5Yp+Hst6S4Fo0J/YNZppkpoBGXxfTAPrrFLB1mZXjzPiTQCT8Av7KUFWG DnqXXmuZ6WnA1bFalp8NanNncC/4HHAjx1TnlXZuYq2K6up4MuJ5TKV/J yrbnwyTL9ku6hTFCoSNII9A1EWMe85ndOIPFrQfowgENnbckbSPbFpD23 EtsjLaOYGO2a/6YeNRscjni5yqVnav0DyTZH6N0SN8013KvKvXM9NW1kC g==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="296554022" X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="296554022" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 11:58:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="562770851" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga003.jf.intel.com with ESMTP; 30 Aug 2022 11:58:15 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V3 4/7] pipeline: support direct registers on the control path Date: Tue, 30 Aug 2022 18:58:08 +0000 Message-Id: <20220830185811.1843109-5-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830185811.1843109-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> <20220830185811.1843109-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 | 255 ++++++++++++++++++++++++++++++++ lib/pipeline/version.map | 2 + 3 files changed, 309 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..ab59e7ad79 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -8261,6 +8261,24 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p, return status; } +static uint32_t +table_params_offset_get(struct table *table) +{ + struct field *first; + uint32_t i; + + first = table->fields[0].field; + + for (i = 1; i < table->n_fields; i++) { + struct field *f = table->fields[i].field; + + if (f->offset < first->offset) + first = f; + } + + return first->offset / 8; +} + static struct rte_swx_table_params * table_params_get(struct table *table) { @@ -9217,6 +9235,24 @@ rte_swx_pipeline_learner_config(struct rte_swx_pipeline *p, return status; } +static uint32_t +learner_params_offset_get(struct learner *l) +{ + struct field *first; + uint32_t i; + + first = l->fields[0]; + + for (i = 1; i < l->n_fields; i++) { + struct field *f = l->fields[i]; + + if (f->offset < first->offset) + first = f; + } + + return first->offset / 8; +} + static void learner_params_free(struct rte_swx_table_learner_params *params) { @@ -11101,6 +11137,225 @@ 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. */ + key -= table_params_offset_get(t); + + 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. */ + key -= learner_params_offset_get(l); + + 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 Tue Aug 30 18:58:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115662 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 5A1E7A00C5; Tue, 30 Aug 2022 20:58:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 785A942B6D; Tue, 30 Aug 2022 20:58:32 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 0A89A40F17 for ; Tue, 30 Aug 2022 20:58:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661885907; x=1693421907; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=vZ2KPrQeTHpE/bPVobTCvfv60tNX9eeq250sreaaK10=; b=M7JczmFccvgWnTqH80Ao6EDzCDudaSrblYMyLL35x9e8oPJkjK7iZVm9 1H4YKDxlQGQ6dbDOlCCtl36Z5ceZnqMewL+xTASsVa4rnDrwDpEO0AQd1 hqossBs40bvYaVh5CnYtmNE+WVMDv39akbrWgVHOJmaPa8FETA/ymI9Xb 3aoH+99xQ3bW4uY/8H5q1ISrWPevnGMqx5XaKbpnGMNB98GUTr4nniM4o SP4SYhInXDRFBcF49Ji3dlmWnpKm3LffAKl8uHbetho7q8FdiJEFjQ1uz XXLxXMbjfblwOai5W5WzWgad/fsABEEJMYpQjc/45ZUCwW8jPa0kfobLw A==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="296554026" X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="296554026" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 11:58:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="562770852" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga003.jf.intel.com with ESMTP; 30 Aug 2022 11:58:16 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V3 5/7] pipeline: support direct meters on the control path Date: Tue, 30 Aug 2022 18:58:09 +0000 Message-Id: <20220830185811.1843109-6-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830185811.1843109-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> <20220830185811.1843109-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 ab59e7ad79..232dafb95e 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -11356,6 +11356,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 Tue Aug 30 18:58:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115663 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 1DB1BA00C5; Tue, 30 Aug 2022 20:59:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 38B7242B71; Tue, 30 Aug 2022 20:58:33 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id DE58A40F18 for ; Tue, 30 Aug 2022 20:58:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661885907; x=1693421907; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=sx/iaGyaadlMWvywXnlJlbEUv5hTvQSceNb+Jn4oEVo=; b=j3jSEQJZR6qagPJQ+MOPQ8SODjLMiam7xP8dq3ZtXU/m1GMAw6B2QWSS XX8P1uxMQSjzAv47MMcL4nR+uovESeVzLFdGtkdKLmgMLXOS8yt+r0F3e KZWuaH3BOBAaFxHRGbF96RqFtAvriEUp9LkIe63DiJFQou7hsJOw/JIWH tzF4RxlGmH3AOe4eHhcqYHETM4SlqlE63R2DgCeMwGh1LlG4fSSrFl6zK Cdusdhh3s6ynl1P0FKlE5cnoyZpmALP71YgjVYLduQUnm/Se+KeZnr5HA MwXYlXPeAKiXtpnlHWjZYauGrivB5wGZ9svPch25HIVO6FqRzzjfrC/xL Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="296554029" X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="296554029" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 11:58:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="562770854" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga003.jf.intel.com with ESMTP; 30 Aug 2022 11:58:17 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V3 6/7] examples/pipeline: add CLI commands for direct registers Date: Tue, 30 Aug 2022 18:58:10 +0000 Message-Id: <20220830185811.1843109-7-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830185811.1843109-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> <20220830185811.1843109-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 Tue Aug 30 18:58:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 115661 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 25BE0A00C5; Tue, 30 Aug 2022 20:58:54 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ABC614284D; Tue, 30 Aug 2022 20:58:31 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 89F65427F2 for ; Tue, 30 Aug 2022 20:58:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661885906; x=1693421906; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=s8RgodkfzzaVzYTgjNN1A5wGOeggk/tyuvI0JmE7EuE=; b=Wyu8UV/BhwNW5JuBNeKALX9p7i0vB3EyNRY2nimMop8QC7SAzDDe9MPP SkGaOg1khDsWfVc73hOlPCbSI11QL9jkm1YZhVsDdeIIi8XvkVj6+YfeA Pcefkk19t7sV84efiU2mXlphsSLVq91fW9UhEjqHre2RPcE0EsK36+reE c31UCMdyWSkdAQYc+RDzJ+9Wp+VUp6haE0LtJjwRj5MKy0IvhxU5WvVWX ZG1253tisPlvsXeGXm5CVazhH3LOKiaKKq3K1c0LCCelZ2dfLKKmsZ/nX mcycw4So3KoS/fzxdpQGQB6oi0CzP2SdmsksZ2fxRFd0kCXj3O/SGCyEa A==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="296554031" X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="296554031" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 11:58:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="562770856" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga003.jf.intel.com with ESMTP; 30 Aug 2022 11:58:18 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V3 7/7] examples/pipeline: add CLI commands for direct meters Date: Tue, 30 Aug 2022 18:58:11 +0000 Message-Id: <20220830185811.1843109-8-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830185811.1843109-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> <20220830185811.1843109-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 | 426 +++++++++++++++++++-------- examples/pipeline/examples/meter.cli | 2 +- 2 files changed, 312 insertions(+), 116 deletions(-) diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index 115147adfc..1426faf1f9 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; + } - status = rte_swx_ctl_meter_stats_read(p, name, idx0, &stats); + 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_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[] = @@ -3228,23 +3430,17 @@ cli_process(char *in, char *out, size_t out_size, void *obj) return; } - if ((n_tokens >= 9) && - (strcmp(tokens[2], "meter") == 0) && - (strcmp(tokens[8], "reset") == 0)) { + if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "reset")) { cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj); return; } - if ((n_tokens >= 9) && - (strcmp(tokens[2], "meter") == 0) && - (strcmp(tokens[8], "set") == 0)) { + if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "set")) { cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj); return; } - if ((n_tokens >= 9) && - (strcmp(tokens[2], "meter") == 0) && - (strcmp(tokens[8], "stats") == 0)) { + if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "stats")) { cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj); return; } 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.