From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 18F63A0C45; Tue, 5 Oct 2021 01:57:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D707D412FF; Tue, 5 Oct 2021 01:56:23 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id BA6514125F for ; Tue, 5 Oct 2021 01:56:13 +0200 (CEST) Received: from localhost.localdomain (unknown [5.144.120.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by shelob.oktetlabs.ru (Postfix) with ESMTPSA id 708737F6D7; Tue, 5 Oct 2021 02:56:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 708737F6D7 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=oktetlabs.ru; s=default; t=1633391773; bh=FP95ADxPwW/pWf2CH5CJhdc0+BQ4+Y0/YLSwOJvdiZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZlBgx/PscnqpXlZeOlMoUDijZxepaM495naukBS56YnFBYYjSvW6YZipQmdC7Xsdp VNiP9z8AUjn/jtHfYdieEoFCuw36tguJY6O0X7b309yguwb3j1+6Rr6nSy1ySJZHIX qgnLpOK5SG062bapD83+TxbGyjbT06A9e4OrOEOA= From: Ivan Malov To: dev@dpdk.org Cc: Andrew Rybchenko Date: Tue, 5 Oct 2021 02:55:57 +0300 Message-Id: <20211004235558.14593-10-ivan.malov@oktetlabs.ru> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211004235558.14593-1-ivan.malov@oktetlabs.ru> References: <20210929205730.775-1-ivan.malov@oktetlabs.ru> <20211004235558.14593-1-ivan.malov@oktetlabs.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 09/10] net/sfc: support counters in tunnel offload JUMP rules 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 Sender: "dev" Such a counter will only report the number of hits, which is actually a sum of two contributions (the JUMP rule's own counter + indirect increments issued by counters of the associated GROUP rules. Signed-off-by: Ivan Malov Reviewed-by: Andrew Rybchenko --- drivers/net/sfc/sfc_flow.c | 2 ++ drivers/net/sfc/sfc_flow_tunnel.c | 18 ++++++++++ drivers/net/sfc/sfc_flow_tunnel.h | 5 +++ drivers/net/sfc/sfc_mae.c | 58 +++++++++++++++++++++++++++---- drivers/net/sfc/sfc_mae.h | 9 +++++ drivers/net/sfc/sfc_mae_counter.c | 41 +++++++++++++++++++--- drivers/net/sfc/sfc_mae_counter.h | 3 ++ 7 files changed, 125 insertions(+), 11 deletions(-) diff --git a/drivers/net/sfc/sfc_flow.c b/drivers/net/sfc/sfc_flow.c index 30ff911d2f..c6b8e2ec12 100644 --- a/drivers/net/sfc/sfc_flow.c +++ b/drivers/net/sfc/sfc_flow.c @@ -2993,6 +2993,8 @@ sfc_flow_start(struct sfc_adapter *sa) SFC_ASSERT(sfc_adapter_is_locked(sa)); + sfc_flow_tunnel_reset_hit_counters(sa); + TAILQ_FOREACH(flow, &sa->flow_list, entries) { rc = sfc_flow_insert(sa, flow, NULL); if (rc != 0) diff --git a/drivers/net/sfc/sfc_flow_tunnel.c b/drivers/net/sfc/sfc_flow_tunnel.c index 374510ad29..463b01c596 100644 --- a/drivers/net/sfc/sfc_flow_tunnel.c +++ b/drivers/net/sfc/sfc_flow_tunnel.c @@ -88,6 +88,8 @@ sfc_flow_tunnel_detect_jump_rule(struct sfc_adapter *sa, } switch (actions->type) { + case RTE_FLOW_ACTION_TYPE_COUNT: + break; case RTE_FLOW_ACTION_TYPE_MARK: if (action_mark == NULL) { action_mark = actions->conf; @@ -460,3 +462,19 @@ sfc_flow_tunnel_get_restore_info(struct rte_eth_dev *dev, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "tunnel offload: get_restore_info failed"); } + +void +sfc_flow_tunnel_reset_hit_counters(struct sfc_adapter *sa) +{ + unsigned int i; + + SFC_ASSERT(sfc_adapter_is_locked(sa)); + SFC_ASSERT(sa->state != SFC_ETHDEV_STARTED); + + for (i = 0; i < RTE_DIM(sa->flow_tunnels); ++i) { + struct sfc_flow_tunnel *ft = &sa->flow_tunnels[i]; + + ft->reset_jump_hit_counter = 0; + ft->group_hit_counter = 0; + } +} diff --git a/drivers/net/sfc/sfc_flow_tunnel.h b/drivers/net/sfc/sfc_flow_tunnel.h index 573585ca80..997811809a 100644 --- a/drivers/net/sfc/sfc_flow_tunnel.h +++ b/drivers/net/sfc/sfc_flow_tunnel.h @@ -63,6 +63,9 @@ struct sfc_flow_tunnel { struct rte_flow_item_mark item_mark_v; struct rte_flow_item_mark item_mark_m; struct rte_flow_item item; + + uint64_t reset_jump_hit_counter; + uint64_t group_hit_counter; }; struct sfc_adapter; @@ -106,6 +109,8 @@ int sfc_flow_tunnel_get_restore_info(struct rte_eth_dev *dev, struct rte_flow_restore_info *info, struct rte_flow_error *err); +void sfc_flow_tunnel_reset_hit_counters(struct sfc_adapter *sa); + #ifdef __cplusplus } #endif diff --git a/drivers/net/sfc/sfc_mae.c b/drivers/net/sfc/sfc_mae.c index 2ec2297632..0d6eba7f16 100644 --- a/drivers/net/sfc/sfc_mae.c +++ b/drivers/net/sfc/sfc_mae.c @@ -607,6 +607,8 @@ sfc_mae_action_set_add(struct sfc_adapter *sa, const struct rte_flow_action actions[], efx_mae_actions_t *spec, struct sfc_mae_encap_header *encap_header, + uint64_t *ft_group_hit_counter, + struct sfc_flow_tunnel *ft, unsigned int n_counters, struct sfc_mae_action_set **action_setp) { @@ -633,6 +635,16 @@ sfc_mae_action_set_add(struct sfc_adapter *sa, return ENOMEM; } + for (i = 0; i < n_counters; ++i) { + action_set->counters[i].rte_id_valid = B_FALSE; + action_set->counters[i].mae_id.id = + EFX_MAE_RSRC_ID_INVALID; + + action_set->counters[i].ft_group_hit_counter = + ft_group_hit_counter; + action_set->counters[i].ft = ft; + } + for (action = actions, i = 0; action->type != RTE_FLOW_ACTION_TYPE_END && i < n_counters; ++action) { @@ -643,8 +655,7 @@ sfc_mae_action_set_add(struct sfc_adapter *sa, conf = action->conf; - action_set->counters[i].mae_id.id = - EFX_MAE_RSRC_ID_INVALID; + action_set->counters[i].rte_id_valid = B_TRUE; action_set->counters[i].rte_id = conf->id; i++; } @@ -3373,10 +3384,12 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa, { struct sfc_mae_encap_header *encap_header = NULL; struct sfc_mae_actions_bundle bundle = {0}; + struct sfc_flow_tunnel *counter_ft = NULL; + uint64_t *ft_group_hit_counter = NULL; const struct rte_flow_action *action; struct sfc_mae *mae = &sa->mae; + unsigned int n_count = 0; efx_mae_actions_t *spec; - unsigned int n_count; int rc; rte_errno = 0; @@ -3391,11 +3404,31 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa, if (rc != 0) goto fail_action_set_spec_init; + for (action = actions; + action->type != RTE_FLOW_ACTION_TYPE_END; ++action) { + if (action->type == RTE_FLOW_ACTION_TYPE_COUNT) + ++n_count; + } + if (spec_mae->ft_rule_type == SFC_FT_RULE_GROUP) { /* JUMP rules don't decapsulate packets. GROUP rules do. */ rc = efx_mae_action_set_populate_decap(spec); if (rc != 0) goto fail_enforce_ft_decap; + + if (n_count == 0 && sfc_mae_counter_stream_enabled(sa)) { + /* + * The user opted not to use action COUNT in this rule, + * but the counter should be enabled implicitly because + * packets hitting this rule contribute to the tunnel's + * total number of hits. See sfc_mae_counter_get(). + */ + rc = efx_mae_action_set_populate_count(spec); + if (rc != 0) + goto fail_enforce_ft_count; + + n_count = 1; + } } /* Cleanup after previous encap. header bounce buffer usage. */ @@ -3421,7 +3454,6 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa, if (rc != 0) goto fail_process_encap_header; - n_count = efx_mae_action_set_get_nb_count(spec); if (n_count > 1) { rc = ENOTSUP; sfc_err(sa, "too many count actions requested: %u", n_count); @@ -3436,6 +3468,8 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa, rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec); if (rc != 0) goto fail_workaround_jump_delivery; + + counter_ft = spec_mae->ft; break; case SFC_FT_RULE_GROUP: /* @@ -3445,6 +3479,8 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa, * MARK above, so don't check the return value here. */ (void)efx_mae_action_set_populate_mark(spec, 0); + + ft_group_hit_counter = &spec_mae->ft->group_hit_counter; break; default: SFC_ASSERT(B_FALSE); @@ -3458,7 +3494,8 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa, return 0; } - rc = sfc_mae_action_set_add(sa, actions, spec, encap_header, n_count, + rc = sfc_mae_action_set_add(sa, actions, spec, encap_header, + ft_group_hit_counter, counter_ft, n_count, &spec_mae->action_set); if (rc != 0) goto fail_action_set_add; @@ -3474,6 +3511,7 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa, fail_rule_parse_action: efx_mae_action_set_spec_fini(sa->nic, spec); +fail_enforce_ft_count: fail_enforce_ft_decap: fail_action_set_spec_init: if (rc > 0 && rte_errno == 0) { @@ -3621,6 +3659,11 @@ sfc_mae_flow_insert(struct sfc_adapter *sa, goto fail_outer_rule_enable; } + if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) { + spec_mae->ft->reset_jump_hit_counter = + spec_mae->ft->group_hit_counter; + } + if (action_set == NULL) { sfc_dbg(sa, "enabled flow=%p (no AR)", flow); return 0; @@ -3720,7 +3763,8 @@ sfc_mae_query_counter(struct sfc_adapter *sa, for (i = 0; i < action_set->n_counters; i++) { /* * Get the first available counter of the flow rule if - * counter ID is not specified. + * counter ID is not specified, provided that this + * counter is not an automatic (implicit) one. */ if (conf != NULL && action_set->counters[i].rte_id != conf->id) continue; @@ -3738,7 +3782,7 @@ sfc_mae_query_counter(struct sfc_adapter *sa, return rte_flow_error_set(error, ENOENT, RTE_FLOW_ERROR_TYPE_ACTION, action, - "No such flow rule action count ID"); + "no such flow rule action or such count ID"); } int diff --git a/drivers/net/sfc/sfc_mae.h b/drivers/net/sfc/sfc_mae.h index 907e292dd1..b2a62fc10b 100644 --- a/drivers/net/sfc/sfc_mae.h +++ b/drivers/net/sfc/sfc_mae.h @@ -62,6 +62,13 @@ struct sfc_mae_counter_id { efx_counter_t mae_id; /* ID of a counter in RTE */ uint32_t rte_id; + /* RTE counter ID validity status */ + bool rte_id_valid; + + /* Flow Tunnel (FT) GROUP hit counter (or NULL) */ + uint64_t *ft_group_hit_counter; + /* Flow Tunnel (FT) context (for JUMP rules; otherwise, NULL) */ + struct sfc_flow_tunnel *ft; }; /** Action set registry entry */ @@ -101,6 +108,8 @@ struct sfc_mae_counter { uint32_t generation_count; union sfc_pkts_bytes value; union sfc_pkts_bytes reset; + + uint64_t *ft_group_hit_counter; }; struct sfc_mae_counters_xstats { diff --git a/drivers/net/sfc/sfc_mae_counter.c b/drivers/net/sfc/sfc_mae_counter.c index 5afd450a11..418caffe59 100644 --- a/drivers/net/sfc/sfc_mae_counter.c +++ b/drivers/net/sfc/sfc_mae_counter.c @@ -99,6 +99,8 @@ sfc_mae_counter_enable(struct sfc_adapter *sa, &p->value.pkts_bytes.int128, __ATOMIC_RELAXED); p->generation_count = generation_count; + p->ft_group_hit_counter = counterp->ft_group_hit_counter; + /* * The flag is set at the very end of add operation and reset * at the beginning of delete operation. Release ordering is @@ -210,6 +212,14 @@ sfc_mae_counter_increment(struct sfc_adapter *sa, __atomic_store(&p->value.pkts_bytes, &cnt_val.pkts_bytes, __ATOMIC_RELAXED); + if (p->ft_group_hit_counter != NULL) { + uint64_t ft_group_hit_counter; + + ft_group_hit_counter = *p->ft_group_hit_counter + pkts; + __atomic_store_n(p->ft_group_hit_counter, ft_group_hit_counter, + __ATOMIC_RELAXED); + } + sfc_info(sa, "update MAE counter #%u: pkts+%" PRIu64 "=%" PRIu64 ", bytes+%" PRIu64 "=%" PRIu64, mae_counter_id, pkts, cnt_val.pkts, bytes, cnt_val.bytes); @@ -799,6 +809,8 @@ sfc_mae_counter_get(struct sfc_mae_counters *counters, const struct sfc_mae_counter_id *counter, struct rte_flow_query_count *data) { + struct sfc_flow_tunnel *ft = counter->ft; + uint64_t non_reset_jump_hit_counter; struct sfc_mae_counter *p; union sfc_pkts_bytes value; @@ -814,14 +826,35 @@ sfc_mae_counter_get(struct sfc_mae_counters *counters, __ATOMIC_RELAXED); data->hits_set = 1; - data->bytes_set = 1; data->hits = value.pkts - p->reset.pkts; - data->bytes = value.bytes - p->reset.bytes; + + if (ft != NULL) { + data->hits += ft->group_hit_counter; + non_reset_jump_hit_counter = data->hits; + data->hits -= ft->reset_jump_hit_counter; + } else { + data->bytes_set = 1; + data->bytes = value.bytes - p->reset.bytes; + } if (data->reset != 0) { - p->reset.pkts = value.pkts; - p->reset.bytes = value.bytes; + if (ft != NULL) { + ft->reset_jump_hit_counter = non_reset_jump_hit_counter; + } else { + p->reset.pkts = value.pkts; + p->reset.bytes = value.bytes; + } } return 0; } + +bool +sfc_mae_counter_stream_enabled(struct sfc_adapter *sa) +{ + if ((sa->counter_rxq.state & SFC_COUNTER_RXQ_INITIALIZED) == 0 || + sfc_get_service_lcore(SOCKET_ID_ANY) == RTE_MAX_LCORE) + return B_FALSE; + else + return B_TRUE; +} diff --git a/drivers/net/sfc/sfc_mae_counter.h b/drivers/net/sfc/sfc_mae_counter.h index 2c953c2968..28d70f7d69 100644 --- a/drivers/net/sfc/sfc_mae_counter.h +++ b/drivers/net/sfc/sfc_mae_counter.h @@ -52,6 +52,9 @@ int sfc_mae_counter_get(struct sfc_mae_counters *counters, int sfc_mae_counter_start(struct sfc_adapter *sa); void sfc_mae_counter_stop(struct sfc_adapter *sa); +/* Check whether MAE Counter-on-Queue (CoQ) prerequisites are satisfied */ +bool sfc_mae_counter_stream_enabled(struct sfc_adapter *sa); + #ifdef __cplusplus } #endif -- 2.20.1