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 299ACA0A0C; Thu, 1 Jul 2021 16:48:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BCA1B40141; Thu, 1 Jul 2021 16:48:02 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 6A1AC4003E for ; Thu, 1 Jul 2021 16:48:01 +0200 (CEST) Received: from [192.168.38.17] (aros.oktetlabs.ru [192.168.38.17]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 05AD07F502; Thu, 1 Jul 2021 17:48:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 05AD07F502 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=oktetlabs.ru; s=default; t=1625150881; bh=TcM9/cNBVuSwZ9kje+wqWg3Y0oDJyC9xR5vmecRubLQ=; h=Subject:To:References:From:Date:In-Reply-To; b=GFLJJulXQY3h1weVU+KrNj/9vMZRiEeI5tAoQ2HU1urKzpGUJm3F6bho+gCCRIquv VgD4zv5pawWoFPesnbwjMYTUHexYOM8KD4CV9F8FMFO/LBxG5JQ48Xf4UyylsmdpU/ gEZ3bClK2tuKjtji2vSnsWb25EYQFt50sT5QCFsQ= To: Rahul Lakkireddy , dev@dpdk.org References: <47e21d539ebca77168be9f15a2a84d54d52be50a.1622738751.git.rahul.lakkireddy@chelsio.com> From: Andrew Rybchenko Organization: OKTET Labs Message-ID: Date: Thu, 1 Jul 2021 17:48:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <47e21d539ebca77168be9f15a2a84d54d52be50a.1622738751.git.rahul.lakkireddy@chelsio.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 1/2] net/cxgbe: add support for xstats API 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" On 6/3/21 6:30 PM, Rahul Lakkireddy wrote: > Add support to fetch port and queue stats via xstats API. > > Signed-off-by: Rahul Lakkireddy [snip] > + count = 0; > + xstats_str = cxgbe_dev_port_stats_strings; > + for (i = 0; i < CXGBE_NB_PORT_STATS; i++, count++) { > + if (xstats_names) != NULL DPDK coding style requires explicit comparison vs null [1] [1] https://doc.dpdk.org/guides/contributing/coding_style.html#null-pointers > + snprintf(xstats_names[count].name, > + sizeof(xstats_names[count].name), > + "%s", xstats_str[i].name); > + if (xstats) { != NULL > + stats_ptr = RTE_PTR_ADD(&ps, > + xstats_str[i].offset); > + xstats[count].value = *stats_ptr; > + xstats[count].id = count; > + } > + } > + > + /* per-txq stats */ > + xstats_str = cxgbe_dev_txq_stats_strings; > + for (qid = 0; qid < pi->n_tx_qsets; qid++) { > + struct sge_eth_txq *txq = &s->ethtxq[pi->first_txqset + qid]; > + > + for (i = 0; i < CXGBE_NB_TXQ_STATS; i++, count++) { > + if (xstats_names) != NULL > + snprintf(xstats_names[count].name, > + sizeof(xstats_names[count].name), > + "tx_q%u_%s", > + qid, xstats_str[i].name); > + if (xstats) { != NULL > + stats_ptr = RTE_PTR_ADD(&txq->stats, > + xstats_str[i].offset); > + xstats[count].value = *stats_ptr; > + xstats[count].id = count; > + } > + } > + } > + > + /* per-rxq stats */ > + xstats_str = cxgbe_dev_rxq_stats_strings; > + for (qid = 0; qid < pi->n_rx_qsets; qid++) { > + struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_rxqset + qid]; > + > + for (i = 0; i < CXGBE_NB_RXQ_STATS; i++, count++) { > + if (xstats_names) != NULL > + snprintf(xstats_names[count].name, > + sizeof(xstats_names[count].name), > + "rx_q%u_%s", > + qid, xstats_str[i].name); > + if (xstats) { != NULL > + stats_ptr = RTE_PTR_ADD(&rxq->stats, > + xstats_str[i].offset); > + xstats[count].value = *stats_ptr; > + xstats[count].id = count; > + } > + } > + } > + > + return count; > +} > + > +/* Get port extended statistics by id. > + */ > +static int cxgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, > + const uint64_t *ids, uint64_t *values, > + unsigned int n) > +{ > + struct port_info *pi = dev->data->dev_private; > + struct rte_eth_xstat *xstats_copy; > + u16 count, i; > + int ret = 0; > + > + count = cxgbe_dev_xstats_count(pi); > + if (!ids || !values) == NULL twice > + return count; > + > + xstats_copy = rte_calloc(NULL, count, sizeof(*xstats_copy), 0); > + if (!xstats_copy) == NULL > + return -ENOMEM; > + > + cxgbe_dev_xstats(dev, NULL, xstats_copy, count); > + > + for (i = 0; i < n; i++) { > + if (ids[i] >= count) { > + ret = -EINVAL; > + goto out_err; > + } > + values[i] = xstats_copy[ids[i]].value; > + } > + > + ret = n; > + > +out_err: > + rte_free(xstats_copy); > + return ret; > +} > + > +/* Get names of port extended statistics by id. > + */ > +static int cxgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, > + struct rte_eth_xstat_name *xnames, > + const uint64_t *ids, unsigned int n) > +{ > + struct port_info *pi = dev->data->dev_private; > + struct rte_eth_xstat_name *xnames_copy; > + u16 count, i; > + int ret = 0; > + > + count = cxgbe_dev_xstats_count(pi); > + if (!ids || !xnames) == NULL twice > + return count; > + > + xnames_copy = rte_calloc(NULL, count, sizeof(*xnames_copy), 0); > + if (!xnames_copy) == NULL > + return -ENOMEM; > + > + cxgbe_dev_xstats(dev, xnames_copy, NULL, count); > + > + for (i = 0; i < n; i++) { > + if (ids[i] >= count) { > + ret = -EINVAL; > + goto out_err; > + } > + strcpy(xnames[i].name, xnames_copy[ids[i]].name); rte_strlcpy, please > + } > + > + ret = n; > + > +out_err: > + rte_free(xnames_copy); > + return ret; > +} > + > +/* Get port extended statistics. > + */ > +static int cxgbe_dev_xstats_get(struct rte_eth_dev *dev, > + struct rte_eth_xstat *xstats, unsigned int n) > +{ > + return cxgbe_dev_xstats(dev, NULL, xstats, n); > +} > + > +/* Get names of port extended statistics. > + */ > +static int cxgbe_dev_xstats_get_names(struct rte_eth_dev *dev, > + struct rte_eth_xstat_name *xstats_names, > + unsigned int n) > +{ > + return cxgbe_dev_xstats(dev, xstats_names, NULL, n); > +} > + > +/* Reset port extended statistics. > + */ > +static int cxgbe_dev_xstats_reset(struct rte_eth_dev *dev) > +{ > + return cxgbe_dev_stats_reset(dev); > +} > + > static int cxgbe_flow_ctrl_get(struct rte_eth_dev *eth_dev, > struct rte_eth_fc_conf *fc_conf) > { > @@ -1351,6 +1630,11 @@ static const struct eth_dev_ops cxgbe_eth_dev_ops = { > .flow_ops_get = cxgbe_dev_flow_ops_get, > .stats_get = cxgbe_dev_stats_get, > .stats_reset = cxgbe_dev_stats_reset, > + .xstats_get = cxgbe_dev_xstats_get, > + .xstats_get_by_id = cxgbe_dev_xstats_get_by_id, > + .xstats_get_names = cxgbe_dev_xstats_get_names, > + .xstats_get_names_by_id = cxgbe_dev_xstats_get_names_by_id, > + .xstats_reset = cxgbe_dev_xstats_reset, > .flow_ctrl_get = cxgbe_flow_ctrl_get, > .flow_ctrl_set = cxgbe_flow_ctrl_set, > .get_eeprom_length = cxgbe_get_eeprom_length, >