From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9BC7AA2E1B for ; Thu, 5 Sep 2019 07:40:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8E8621ECDA; Thu, 5 Sep 2019 07:39:56 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 179CB1EBEC for ; Thu, 5 Sep 2019 07:39:53 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2019 22:39:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,469,1559545200"; d="scan'208";a="177188702" Received: from dpdk-xiaoyun3.sh.intel.com ([10.67.118.227]) by orsmga008.jf.intel.com with ESMTP; 04 Sep 2019 22:39:52 -0700 From: Xiaoyun Li To: jingjing.wu@intel.com, keith.wiles@intel.com, omkar.maslekar@intel.com, cunming.liang@intel.com Cc: dev@dpdk.org, Xiaoyun Li Date: Thu, 5 Sep 2019 13:39:31 +0800 Message-Id: <20190905053933.27929-3-xiaoyun.li@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190905053933.27929-1-xiaoyun.li@intel.com> References: <20190905053933.27929-1-xiaoyun.li@intel.com> Subject: [dpdk-dev] [PATCH 2/4] raw/ntb: add xstats support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Add xstats support for ntb rawdev. Support tx-packets, tx-bytes, tx-errors and rx-packets, rx-bytes, rx-missed. Signed-off-by: Xiaoyun Li --- drivers/raw/ntb/ntb.c | 135 ++++++++++++++++++++++++++++++++++++------ drivers/raw/ntb/ntb.h | 11 ++++ 2 files changed, 128 insertions(+), 18 deletions(-) diff --git a/drivers/raw/ntb/ntb.c b/drivers/raw/ntb/ntb.c index 124c82a95..c104557d4 100644 --- a/drivers/raw/ntb/ntb.c +++ b/drivers/raw/ntb/ntb.c @@ -30,6 +30,17 @@ static const struct rte_pci_id pci_id_ntb_map[] = { { .vendor_id = 0, /* sentinel */ }, }; +/* Align with enum ntb_xstats_idx */ +static struct rte_rawdev_xstats_name ntb_xstats_names[] = { + {"Tx-packtes"}, + {"Tx-bytes"}, + {"Tx-errors"}, + {"Rx-packets"}, + {"Rx-bytes"}, + {"Rx-missed"}, +}; +#define NTB_XSTATS_NUM RTE_DIM(ntb_xstats_names) + static inline void ntb_link_cleanup(struct rte_rawdev *dev) { @@ -538,6 +549,10 @@ ntb_queue_init(struct rte_rawdev *dev, uint16_t qp_id) txq->last_avail = 0; txq->nb_tx_free = txq->nb_tx_desc - 1; + /* Set per queue stats. */ + for (i = 0; i < NTB_XSTATS_NUM; i++) + hw->ntb_xstats[i + NTB_XSTATS_NUM * (qp_id + 1)] = 0; + return 0; } @@ -614,6 +629,7 @@ ntb_dev_configure(const struct rte_rawdev *dev, rte_rawdev_obj_t config) { struct ntb_dev_config *conf = config; struct ntb_hw *hw = dev->dev_private; + uint32_t xstats_num; int ret; hw->queue_pairs = conf->num_queues; @@ -624,6 +640,10 @@ ntb_dev_configure(const struct rte_rawdev *dev, rte_rawdev_obj_t config) sizeof(struct ntb_rx_queue *) * hw->queue_pairs, 0); hw->tx_queues = rte_zmalloc("ntb_tx_queues", sizeof(struct ntb_tx_queue *) * hw->queue_pairs, 0); + /* First total stats, then per queue stats. */ + xstats_num = (hw->queue_pairs + 1) * NTB_XSTATS_NUM; + hw->ntb_xstats = rte_zmalloc("ntb_xstats", xstats_num * + sizeof(uint64_t), 0); /* Start handshake with the peer. */ ret = ntb_handshake_work(dev); @@ -645,6 +665,10 @@ ntb_dev_start(struct rte_rawdev *dev) if (!hw->link_status || !hw->peer_dev_up) return -EINVAL; + /* Set total stats. */ + for (i = 0; i < NTB_XSTATS_NUM; i++) + hw->ntb_xstats[i] = 0; + for (i = 0; i < hw->queue_pairs; i++) { ret = ntb_queue_init(dev, i); if (ret) { @@ -909,38 +933,113 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name, } static int -ntb_xstats_get(const struct rte_rawdev *dev __rte_unused, - const unsigned int ids[] __rte_unused, - uint64_t values[] __rte_unused, - unsigned int n __rte_unused) +ntb_xstats_get(const struct rte_rawdev *dev, + const unsigned int ids[], + uint64_t values[], + unsigned int n) { - return 0; + struct ntb_hw *hw = dev->dev_private; + uint32_t i, j, off, xstats_num; + + /* Calculate total stats of all queues. */ + for (i = 0; i < NTB_XSTATS_NUM; i++) { + for (j = 0; j < hw->queue_pairs; j++) { + off = NTB_XSTATS_NUM * (j + 1) + i; + hw->ntb_xstats[i] += hw->ntb_xstats[off]; + } + } + + xstats_num = NTB_XSTATS_NUM * (hw->queue_pairs + 1); + for (i = 0; i < n && ids[i] < xstats_num; i++) + values[i] = hw->ntb_xstats[ids[i]]; + + return i; } static int -ntb_xstats_get_names(const struct rte_rawdev *dev __rte_unused, - struct rte_rawdev_xstats_name *xstats_names __rte_unused, - unsigned int size __rte_unused) +ntb_xstats_get_names(const struct rte_rawdev *dev, + struct rte_rawdev_xstats_name *xstats_names, + unsigned int size) { - return 0; + struct ntb_hw *hw = dev->dev_private; + uint32_t xstats_num, i, j, off; + + xstats_num = NTB_XSTATS_NUM * (hw->queue_pairs + 1); + if (xstats_names == NULL || size < xstats_num) + return xstats_num; + + /* Total stats names */ + for (i = 0; i < NTB_XSTATS_NUM; i++) { + strncpy(xstats_names[i].name, ntb_xstats_names[i].name, + sizeof(xstats_names[0].name)); + } + + /* Queue stats names */ + for (i = 0; i < hw->queue_pairs; i++) { + for (j = 0; j < NTB_XSTATS_NUM; j++) { + off = j + (i + 1) * NTB_XSTATS_NUM; + snprintf(xstats_names[off].name, + sizeof(xstats_names[0].name), + "%s_q%u", ntb_xstats_names[j].name, i); + } + } + + return xstats_num; } static uint64_t -ntb_xstats_get_by_name(const struct rte_rawdev *dev __rte_unused, - const char *name __rte_unused, - unsigned int *id __rte_unused) +ntb_xstats_get_by_name(const struct rte_rawdev *dev, + const char *name, unsigned int *id) { - return 0; + struct rte_rawdev_xstats_name *xstats_names; + struct ntb_hw *hw = dev->dev_private; + uint32_t xstats_num, i, j, off; + + if (name == NULL) + return -EINVAL; + + xstats_num = NTB_XSTATS_NUM * (hw->queue_pairs + 1); + xstats_names = rte_zmalloc("ntb_stats_name", + sizeof(struct rte_rawdev_xstats_name) * + xstats_num, 0); + ntb_xstats_get_names(dev, xstats_names, xstats_num); + + /* Calculate total stats of all queues. */ + for (i = 0; i < NTB_XSTATS_NUM; i++) { + for (j = 0; j < hw->queue_pairs; j++) { + off = NTB_XSTATS_NUM * (j + 1) + i; + hw->ntb_xstats[i] += hw->ntb_xstats[off]; + } + } + + for (i = 0; i < xstats_num; i++) { + if (!strncmp(name, xstats_names[i].name, + RTE_RAW_DEV_XSTATS_NAME_SIZE)) { + *id = i; + rte_free(xstats_names); + return hw->ntb_xstats[i]; + } + } + + NTB_LOG(ERR, "Cannot find the xstats name."); + + return -EINVAL; } static int -ntb_xstats_reset(struct rte_rawdev *dev __rte_unused, - const uint32_t ids[] __rte_unused, - uint32_t nb_ids __rte_unused) +ntb_xstats_reset(struct rte_rawdev *dev, + const uint32_t ids[], + uint32_t nb_ids) { - return 0; -} + struct ntb_hw *hw = dev->dev_private; + uint32_t i, xstats_num; + xstats_num = NTB_XSTATS_NUM * (hw->queue_pairs + 1); + for (i = 0; i < nb_ids && ids[i] < xstats_num; i++) + hw->ntb_xstats[ids[i]] = 0; + + return i; +} static const struct rte_rawdev_ops ntb_ops = { .dev_info_get = ntb_dev_info_get, diff --git a/drivers/raw/ntb/ntb.h b/drivers/raw/ntb/ntb.h index 0ad20aed3..09e28050f 100644 --- a/drivers/raw/ntb/ntb.h +++ b/drivers/raw/ntb/ntb.h @@ -27,6 +27,15 @@ extern int ntb_logtype; #define NTB_DFLT_TX_FREE_THRESH 256 +enum ntb_xstats_idx { + NTB_TX_PKTS_ID = 0, + NTB_TX_BYTES_ID, + NTB_TX_ERRS_ID, + NTB_RX_PKTS_ID, + NTB_RX_BYTES_ID, + NTB_RX_MISS_ID, +}; + enum ntb_topo { NTB_TOPO_NONE = 0, NTB_TOPO_B2B_USD, @@ -216,6 +225,8 @@ struct ntb_hw { uint8_t peer_used_mws; + uint64_t *ntb_xstats; + /* Reserve several spad for app to use. */ int spad_user_list[NTB_SPAD_USER_MAX_NUM]; }; -- 2.17.1