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 2C0EEA034F; Fri, 8 Oct 2021 12:58:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7BDD8411DE; Fri, 8 Oct 2021 12:56:30 +0200 (CEST) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mails.dpdk.org (Postfix) with ESMTP id 4BD0641217 for ; Thu, 7 Oct 2021 20:45:33 +0200 (CEST) Received: by mail-pf1-f171.google.com with SMTP id p1so6065277pfh.8 for ; Thu, 07 Oct 2021 11:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cTFUC21T25Hn2d7bIakzFL4yig0aCCoezo7K+xdhJzM=; b=K1WwRoKzJ2nnxyPWqlyy0wM9Q54/5a2XVrwaEV0DhrEFy/FQLf95LIdLG73xnFMKPd kZkC40ftlkSVEMrkTpRzWVm9zptbZ4Q17pwbztc1E65vV0FYsldw4djINrAOlWjtFy/Q ATuAFEWnYXkmeAQMhVODbBR7+59gwwlC4odI4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cTFUC21T25Hn2d7bIakzFL4yig0aCCoezo7K+xdhJzM=; b=PUow5DNH/wSdwRuGCoXsNarf8gf9UK7jcuBQjIIHa4f2RHQWUqtXTNoT+nnuTUSYpr FiYiJdxJ2go6sYCmJLuPDR70ik1911DASAZrL4H1Kur2pXCgb5v3cFsJI0EBC+Sz/SqH J9OvfsWAu4pwg5TZqbdY4PjdioHAiyGSw2SZL+2qMxKDAvE8VD60vWsnzGbIchh0tjVO UxRdBjfpSoBoLcXodv2ehaGN4KaFgQnPZPTiFSFqSsf4lEDkYfAf43QE0f2GQh1uNdd5 BLtowHVBYME/MQWyyXticuAsUDIHaUP6UeSeoLEgFRWLekohhBOiY42qX/5DOJ8le64Z waFg== X-Gm-Message-State: AOAM533hJJh3zBiuJ0mG5cBwKyhwNC8bSox1mIKzxS6dhWU+xp6EzH/P iPKHP/mb48pqlJw/aNzd5EOXIQ== X-Google-Smtp-Source: ABdhPJxNOgcL9qw+55alHVuexEiTqwCuD+af12nd6bwLXLERR5+4AENRqZ5dZFPayV1YPrN4z0D9dg== X-Received: by 2002:a63:e216:: with SMTP id q22mr954569pgh.3.1633632332441; Thu, 07 Oct 2021 11:45:32 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([136.185.113.102]) by smtp.gmail.com with ESMTPSA id c11sm3311586pji.38.2021.10.07.11.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:45:31 -0700 (PDT) From: Srikanth Kaka To: Matan Azrad , Viacheslav Ovsiienko Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Fri, 8 Oct 2021 00:13:38 +0530 Message-Id: <20211007184350.73858-30-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211007184350.73858-1-srikanth.k@oneconvergence.com> References: <20211007184350.73858-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 08 Oct 2021 12:55:54 +0200 Subject: [dpdk-dev] [PATCH v2 29/41] net/mlx5: added stats support 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" Initialize device stats and fetch them using sysctl. Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/net/mlx5/freebsd/mlx5_ethdev_os.c | 217 ++++++++++++++++++++++ 1 file changed, 217 insertions(+) diff --git a/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c b/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c index db16027244..a6e28ea4bb 100644 --- a/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -18,6 +19,8 @@ #include "mlx5.h" +static unsigned int xstats_n; + /** * Get interface name from private structure. * @@ -721,6 +724,220 @@ int mlx5_get_module_eeprom(struct rte_eth_dev *dev, return -ENOTSUP; } +/** + * Read device counters table. + * + * @param dev + * Pointer to Ethernet device. + * @param[in] pf + * PF index in case of bonding device, -1 otherwise + * @param[out] stats + * Counters table output buffer. + */ +static void +_mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; + char stat_key[RTE_ETH_XSTATS_NAME_SIZE + 16]; + unsigned int i; + size_t len = sizeof(uint64_t); + uint64_t val; + int ibvindex, ret; + + ibvindex = mlx5_get_ibvindex(priv->sh->ibdev_path); + + for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) { + snprintf(stat_key, sizeof(stat_key), "dev.mce.%d.%s", + ibvindex, xstats_ctrl->info[i].ctr_name); + ret = sysctlbyname(stat_key, &val, &len, NULL, 0); + if (ret == -1) { + DRV_LOG(WARNING, "port %u failed to get statistics: %s", + dev->data->port_id, strerror(errno)); + continue; + } + stats[i] += val; + } +} + +/** + * Read device counters. + * + * @param dev + * Pointer to Ethernet device. + * @param[out] stats + * Counters table output buffer. + */ +int +mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; + int i; + + memset(stats, 0, sizeof(*stats) * xstats_ctrl->mlx5_stats_n); + _mlx5_os_read_dev_counters(dev, stats); + /* Read IB counters. */ + for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) { + if (!xstats_ctrl->info[i].dev) + continue; + xstats_ctrl->xstats[i] = stats[i]; + } + return 0; +} + +/** + * Query the number of statistics. + * + * @param dev + * Pointer to Ethernet device. + * + * @return + * Number of statistics on success. + */ +int +mlx5_os_get_stats_n(struct rte_eth_dev *dev) +{ + RTE_SET_USED(dev); + return xstats_n; +} + +static const struct mlx5_counter_ctrl mlx5_counters_init[] = { + { + .dpdk_name = "rx_port_unicast_bytes", + .ctr_name = "vstats.rx_unicast_bytes", + }, + { + .dpdk_name = "rx_port_multicast_bytes", + .ctr_name = "vstats.rx_multicast_bytes", + }, + { + .dpdk_name = "rx_port_broadcast_bytes", + .ctr_name = "vstats.rx_broadcast_bytes", + }, + { + .dpdk_name = "rx_port_unicast_packets", + .ctr_name = "vstats.rx_unicast_packets", + }, + { + .dpdk_name = "rx_port_multicast_packets", + .ctr_name = "vstats.rx_multicast_packets", + }, + { + .dpdk_name = "rx_port_broadcast_packets", + .ctr_name = "vstats.rx_broadcast_packets", + }, + { + .dpdk_name = "tx_port_unicast_bytes", + .ctr_name = "vstats.tx_unicast_bytes", + }, + { + .dpdk_name = "tx_port_multicast_bytes", + .ctr_name = "vstats.tx_multicast_bytes", + }, + { + .dpdk_name = "tx_port_broadcast_bytes", + .ctr_name = "vstats.tx_broadcast_bytes", + }, + { + .dpdk_name = "tx_port_unicast_packets", + .ctr_name = "vstats.tx_unicast_packets", + }, + { + .dpdk_name = "tx_port_multicast_packets", + .ctr_name = "vstats.tx_multicast_packets", + }, + { + .dpdk_name = "tx_port_broadcast_packets", + .ctr_name = "vstats.tx_broadcast_packets", + }, + { + .dpdk_name = "rx_wqe_err", + .ctr_name = "vstats.rx_wqe_err", + }, + { + .dpdk_name = "rx_crc_align_errors", + .ctr_name = "pstats.crc_align_errors", + }, + { + .dpdk_name = "rx_in_range_len_errors", + .ctr_name = "pstats.in_range_len_errors", + }, + { + .dpdk_name = "rx_symbol_err", + .ctr_name = "pstats.symbol_err", + }, + { + .dpdk_name = "tx_errors_packets", + .ctr_name = "vstats.tx_error_packets", + }, + { + .dpdk_name = "rx_out_of_buffer", + .ctr_name = "vstats.rx_out_of_buffer", + }, + { + .dpdk_name = "lro_bytes", + .ctr_name = "vstats.lro_bytes", + }, + { + .dpdk_name = "lro_packets", + .ctr_name = "vstats.lro_packets", + }, + { + .dpdk_name = "tso_bytes", + .ctr_name = "vstats.tso_bytes", + }, + { + .dpdk_name = "tso_packets", + .ctr_name = "vstats.tso_packets", + }, + /* Representor only */ + { + .dpdk_name = "rx_packets", + .ctr_name = "vstats.rx_packets", + }, + { + .dpdk_name = "rx_bytes", + .ctr_name = "vstats.rx_bytes", + }, + { + .dpdk_name = "tx_packets", + .ctr_name = "vstats.tx_packets", + }, + { + .dpdk_name = "tx_bytes", + .ctr_name = "vstats.tx_bytes", + }, +}; + +/** + * Init the structures to read device counters. + * + * @param dev + * Pointer to Ethernet device. + */ +void +mlx5_os_stats_init(struct rte_eth_dev *dev) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; + struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl; + unsigned int i, idx; + + xstats_n = RTE_DIM(mlx5_counters_init); + xstats_ctrl->mlx5_stats_n = 0; + + for (i = 0; i != xstats_n; ++i) { + idx = xstats_ctrl->mlx5_stats_n++; + + xstats_ctrl->dev_table_idx[idx] = i; + xstats_ctrl->info[idx] = mlx5_counters_init[i]; + } + xstats_ctrl->stats_n = xstats_n; + mlx5_os_read_dev_counters(dev, xstats_ctrl->base); + stats_ctrl->imissed = 0; +} + /** * Get MAC address by querying netdevice. * -- 2.30.2