Skip to content

Commit

Permalink
net/bnxt: tf_ulp: add stats cache for thor2
Browse files Browse the repository at this point in the history
This change adds a stats cache for Thor2 flows using counters.
Flow stats will be harvested periodically in the background
and stats reads by the application will be returned stats from
the cache and not by initiating a read from HW.

This change also adds read-clear functionality for counter resets
and restructures the stats collection while loop to
guarantee full coverage of entries added or removed during the
collection period.

Signed-off-by: Peter Spreadborough <peter.spreadborough@broadcom.com>
Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Reviewed-by: Jay Ding <jay.ding@broadcom.com>
Reviewed-by: Shahaji Bhosle <sbhosle@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
  • Loading branch information
Peter Spreadborough authored and ajitkhaparde committed Sep 20, 2024
1 parent 6950147 commit 6acd395
Show file tree
Hide file tree
Showing 11 changed files with 877 additions and 2 deletions.
2 changes: 2 additions & 0 deletions drivers/net/bnxt/tf_ulp/bnxt_ulp.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ struct bnxt_ulp_data {
uint64_t feature_bits;
uint64_t default_class_bits;
uint64_t default_act_bits;
struct ulp_fc_tfc_stats_cache_entry *stats_cache;
struct bnxt_ulp_sc_info *sc_info;
};

enum bnxt_ulp_tfo_type {
Expand Down
16 changes: 15 additions & 1 deletion drivers/net/bnxt/tf_ulp/bnxt_ulp_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ bnxt_ulp_flow_query(struct rte_eth_dev *eth_dev,
struct bnxt_ulp_context *ulp_ctx;
struct rte_flow_action_rss *rss_conf;
struct rte_flow_query_count *count;
enum bnxt_ulp_device_id dev_id;
uint32_t flow_id;

ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
Expand All @@ -681,6 +682,15 @@ bnxt_ulp_flow_query(struct rte_eth_dev *eth_dev,
return -EINVAL;
}

rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
if (rc) {
BNXT_DRV_DBG(ERR, "Can't identify the device\n");
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
"Failed to query flow.");
return -EINVAL;
}

flow_id = (uint32_t)(uintptr_t)flow;

switch (action->type) {
Expand All @@ -696,7 +706,11 @@ bnxt_ulp_flow_query(struct rte_eth_dev *eth_dev,
break;
case RTE_FLOW_ACTION_TYPE_COUNT:
count = data;
rc = ulp_fc_mgr_query_count_get(ulp_ctx, flow_id, count);
if (dev_id == BNXT_ULP_DEVICE_ID_THOR2)
rc = ulp_sc_mgr_query_count_get(ulp_ctx, flow_id, count);
else
rc = ulp_fc_mgr_query_count_get(ulp_ctx, flow_id, count);

if (unlikely(rc)) {
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
Expand Down
10 changes: 10 additions & 0 deletions drivers/net/bnxt/tf_ulp/bnxt_ulp_tfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ulp_template_struct.h"
#include "ulp_mark_mgr.h"
#include "ulp_fc_mgr.h"
#include "ulp_sc_mgr.h"
#include "ulp_flow_db.h"
#include "ulp_mapper.h"
#include "ulp_matcher.h"
Expand Down Expand Up @@ -887,6 +888,9 @@ ulp_tfc_deinit(struct bnxt *bp,
BNXT_DRV_DBG(ERR, "Failed to close HA (%d)\n", rc);
}

/* Delete the Stats Counter Manager */
ulp_sc_mgr_deinit(bp->ulp_ctx);

/* cleanup the flow database */
ulp_flow_db_deinit(bp->ulp_ctx);

Expand Down Expand Up @@ -1043,6 +1047,12 @@ ulp_tfc_init(struct bnxt *bp,
goto jump_to_error;
}

rc = ulp_sc_mgr_init(bp->ulp_ctx);
if (rc) {
BNXT_DRV_DBG(ERR, "Failed to initialize ulp stats cache mgr\n");
goto jump_to_error;
}

rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &ulp_dev_id);
if (rc) {
BNXT_DRV_DBG(ERR, "Unable to get device id from ulp.\n");
Expand Down
26 changes: 26 additions & 0 deletions drivers/net/bnxt/tf_ulp/bnxt_ulp_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ulp_template_struct.h"
#include "ulp_mark_mgr.h"
#include "ulp_fc_mgr.h"
#include "ulp_sc_mgr.h"
#include "ulp_flow_db.h"
#include "ulp_mapper.h"
#include "ulp_matcher.h"
Expand Down Expand Up @@ -739,6 +740,31 @@ bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
return ulp_ctx->cfg_data->fc_info;
}

/* Function to set the flow counter info into the context */
static inline int32_t
bnxt_ulp_cntxt_ptr2_sc_info_set(struct bnxt_ulp_context *ulp_ctx,
struct bnxt_ulp_sc_info *ulp_sc_info)
{
if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) {
BNXT_DRV_DBG(ERR, "Invalid ulp context data\n");
return -EINVAL;
}

ulp_ctx->cfg_data->sc_info = ulp_sc_info;

return 0;
}

/* Function to retrieve the flow counter info from the context. */
static inline struct bnxt_ulp_sc_info *
bnxt_ulp_cntxt_ptr2_sc_info_get(struct bnxt_ulp_context *ulp_ctx)
{
if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data))
return NULL;

return ulp_ctx->cfg_data->sc_info;
}

/* Function to get the ulp flags from the ulp context. */
static inline int32_t
bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/bnxt/tf_ulp/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ sources += files(
'bnxt_ulp_tfc.c',
'ulp_fc_mgr_tfc.c',
'ulp_fc_mgr_tf.c',
'ulp_alloc_tbl.c')
'ulp_alloc_tbl.c',
'ulp_sc_mgr.c',
'ulp_sc_mgr_tfc.c')

subdir('generic_templates')
13 changes: 13 additions & 0 deletions drivers/net/bnxt/tf_ulp/ulp_fc_mgr_tfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
#define ULP_TFC_CNTR_ALIGN 32
#define ULP_TFC_ACT_WORD_SZ 32

struct ulp_fc_tfc_stats_cache_entry {
uint32_t flags;
uint64_t timestamp;
uint8_t tsid;
uint32_t record_size;
uint32_t offset;
uint8_t dir;
uint64_t packet_count;
uint64_t byte_count;
uint16_t tcp_flags;
uint32_t tcp_timestamp;
};

static int32_t
ulp_fc_tfc_update_accum_stats(__rte_unused struct bnxt_ulp_context *ctxt,
__rte_unused struct bnxt_ulp_fc_info *fc_info,
Expand Down
4 changes: 4 additions & 0 deletions drivers/net/bnxt/tf_ulp/ulp_flow_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ulp_mapper.h"
#include "ulp_flow_db.h"
#include "ulp_fc_mgr.h"
#include "ulp_sc_mgr.h"
#include "ulp_tun.h"
#ifdef TF_FLOW_SCALE_QUERY
#include "tf_resources.h"
Expand Down Expand Up @@ -633,6 +634,9 @@ ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,

if (!ulp_fc_mgr_thread_isstarted(ulp_ctxt))
ulp_fc_mgr_thread_start(ulp_ctxt);

if (!ulp_sc_mgr_thread_isstarted(ulp_ctxt))
ulp_sc_mgr_thread_start(ulp_ctxt);
}

/* all good, return success */
Expand Down
73 changes: 73 additions & 0 deletions drivers/net/bnxt/tf_ulp/ulp_mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,72 @@ ulp_mapper_vnic_tbl_process(struct bnxt_ulp_mapper_parms *parms,
return rc;
}

static int32_t
ulp_mapper_stats_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_flow_db_res_params fid_parms;
uint64_t counter_handle;
struct ulp_blob data;
uint16_t data_len = 0;
uint8_t *tmp_data;
int32_t rc = 0;

/* Initialize the blob data */
if (unlikely(ulp_blob_init(&data, tbl->result_bit_size,
BNXT_ULP_BYTE_ORDER_BE))) {
BNXT_DRV_DBG(ERR, "Failed initial ulp_global table blob\n");
return -EINVAL;
}

/* read the arguments from the result table */
rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
"ULP Global Result");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to build the result blob\n");
return rc;
}

tmp_data = ulp_blob_data_get(&data, &data_len);
counter_handle = *(uint64_t *)tmp_data;
counter_handle = tfp_be_to_cpu_64(counter_handle);

memset(&fid_parms, 0, sizeof(fid_parms));
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_type = tbl->resource_type;
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.resource_hndl = counter_handle;
fid_parms.critical_resource = tbl->critical_resource;
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to link resource to flow rc = %d\n",
rc);
return rc;
}

rc = ulp_sc_mgr_entry_alloc(parms, counter_handle, tbl);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to link resource to flow rc = %d\n",
rc);
return rc;
}
#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
BNXT_DRV_DBG(DEBUG, "flow id =0x%x\n", parms->flow_id);
#endif
#endif
return rc;
}

static int32_t
ulp_mapper_stats_cache_tbl_res_free(struct bnxt_ulp_context *ulp,
uint32_t fid)
{
ulp_sc_mgr_entry_free(ulp, fid);
return 0;
}

/* Free the vnic resource */
static int32_t
ulp_mapper_vnic_tbl_res_free(struct bnxt_ulp_context *ulp __rte_unused,
Expand Down Expand Up @@ -4148,6 +4214,9 @@ ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, void *error)
case BNXT_ULP_RESOURCE_FUNC_ALLOCATOR_TABLE:
rc = ulp_mapper_allocator_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_STATS_CACHE:
rc = ulp_mapper_stats_cache_tbl_process(parms, tbl);
break;
default:
BNXT_DRV_DBG(ERR, "Unexpected mapper resource %d\n",
tbl->resource_func);
Expand Down Expand Up @@ -4286,6 +4355,10 @@ ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
res->direction,
res->resource_hndl);
break;
case BNXT_ULP_RESOURCE_FUNC_STATS_CACHE:
rc = ulp_mapper_stats_cache_tbl_res_free(ulp,
fid);
break;
default:
break;
}
Expand Down
Loading

0 comments on commit 6acd395

Please sign in to comment.