Add zsda compressdev stats interface implementation. Signed-off-by: Hanxiao Li --- drivers/common/zsda/meson.build | 1 + drivers/common/zsda/zsda_qp_common.c | 68 +++++++++++++++++++++++++++ drivers/common/zsda/zsda_qp_common.h | 17 +++++++ drivers/compress/zsda/zsda_comp_pmd.c | 24 +++++++++- 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 drivers/common/zsda/zsda_qp_common.c diff --git a/drivers/common/zsda/meson.build b/drivers/common/zsda/meson.build index 6ee2a68f4b..6e6d5ab006 100644 --- a/drivers/common/zsda/meson.build +++ b/drivers/common/zsda/meson.build @@ -12,6 +12,7 @@ sources += files( 'zsda_device.c', 'zsda_logs.c', 'zsda_qp.c', + 'zsda_qp_common.c', ) zsda_compress = true diff --git a/drivers/common/zsda/zsda_qp_common.c b/drivers/common/zsda/zsda_qp_common.c new file mode 100644 index 0000000000..9e61f96132 --- /dev/null +++ b/drivers/common/zsda/zsda_qp_common.c @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 ZTE Corporation + */ + +#include "zsda_qp_common.h" + +void +zsda_stats_get(void **queue_pairs, const uint32_t nb_queue_pairs, + struct zsda_qp_stat *stats) +{ + enum zsda_service_type type; + uint32_t i; + struct zsda_qp *qp; + + if ((stats == NULL) || (queue_pairs == NULL)) { + ZSDA_LOG(ERR, "Failed! stats or queue_pairs is NULL"); + return; + } + + for (i = 0; i < nb_queue_pairs; i++) { + qp = queue_pairs[i]; + + if (qp == NULL) { + ZSDA_LOG(ERR, "Failed! queue_pairs[i] is NULL"); + break; + } + + for (type = 0; type < ZSDA_SERVICE_INVALID; type++) { + if (qp->srv[type].used) { + stats->enqueued_count += + qp->srv[type].stats.enqueued_count; + stats->dequeued_count += + qp->srv[type].stats.dequeued_count; + stats->enqueue_err_count += + qp->srv[type].stats.enqueue_err_count; + stats->dequeue_err_count += + qp->srv[type].stats.dequeue_err_count; + } + } + } +} + +void +zsda_stats_reset(void **queue_pairs, const uint32_t nb_queue_pairs) +{ + enum zsda_service_type type; + uint32_t i; + struct zsda_qp *qp; + + if (queue_pairs == NULL) { + ZSDA_LOG(ERR, "Failed! queue_pairs is NULL"); + return; + } + + for (i = 0; i < nb_queue_pairs; i++) { + qp = queue_pairs[i]; + + if (qp == NULL) { + ZSDA_LOG(ERR, "Failed! queue_pairs[i] is NULL"); + break; + } + for (type = 0; type < ZSDA_MAX_SERVICES; type++) { + if (qp->srv[type].used) + memset(&(qp->srv[type].stats), 0, + sizeof(struct zsda_qp_stat)); + } + } +} diff --git a/drivers/common/zsda/zsda_qp_common.h b/drivers/common/zsda/zsda_qp_common.h index 550411dbc4..3108827764 100644 --- a/drivers/common/zsda/zsda_qp_common.h +++ b/drivers/common/zsda/zsda_qp_common.h @@ -80,10 +80,23 @@ struct zsda_queue { uint16_t sid; }; +struct zsda_qp_stat { + /**< Count of all operations enqueued */ + uint64_t enqueued_count; + /**< Count of all operations dequeued */ + uint64_t dequeued_count; + + /**< Total error count on operations enqueued */ + uint64_t enqueue_err_count; + /**< Total error count on operations dequeued */ + uint64_t dequeue_err_count; +}; + struct qp_srv { bool used; struct zsda_queue tx_q; struct zsda_queue rx_q; + struct zsda_qp_stat stats; struct rte_mempool *op_cookie_pool; void **op_cookies; uint16_t nb_descriptors; @@ -93,4 +106,8 @@ struct zsda_qp { struct qp_srv srv[ZSDA_MAX_SERVICES]; }; +void zsda_stats_get(void **queue_pairs, const uint32_t nb_queue_pairs, + struct zsda_qp_stat *stats); +void zsda_stats_reset(void **queue_pairs, const uint32_t nb_queue_pairs); + #endif /* _ZSDA_QP_COMMON_H_ */ diff --git a/drivers/compress/zsda/zsda_comp_pmd.c b/drivers/compress/zsda/zsda_comp_pmd.c index 07c03a8d13..f1d20e245e 100644 --- a/drivers/compress/zsda/zsda_comp_pmd.c +++ b/drivers/compress/zsda/zsda_comp_pmd.c @@ -129,6 +129,26 @@ zsda_comp_dev_info_get(struct rte_compressdev *dev, } } +static void +zsda_comp_stats_get(struct rte_compressdev *dev, + struct rte_compressdev_stats *stats) +{ + struct zsda_qp_stat stats_info = {0}; + + zsda_stats_get(dev->data->queue_pairs, dev->data->nb_queue_pairs, + &stats_info); + stats->enqueued_count = stats_info.enqueued_count; + stats->dequeued_count = stats_info.dequeued_count; + stats->enqueue_err_count = stats_info.enqueue_err_count; + stats->dequeue_err_count = stats_info.dequeue_err_count; +} + +static void +zsda_comp_stats_reset(struct rte_compressdev *dev) +{ + zsda_stats_reset(dev->data->queue_pairs, dev->data->nb_queue_pairs); +} + static struct rte_compressdev_ops compress_zsda_ops = { .dev_configure = zsda_comp_dev_config, @@ -137,8 +157,8 @@ static struct rte_compressdev_ops compress_zsda_ops = { .dev_close = zsda_comp_dev_close, .dev_infos_get = zsda_comp_dev_info_get, - .stats_get = NULL, - .stats_reset = NULL, + .stats_get = zsda_comp_stats_get, + .stats_reset = zsda_comp_stats_reset, .queue_pair_setup = NULL, .queue_pair_release = NULL, -- 2.27.0