From patchwork Sun Aug 11 16:06:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 57611 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 828FA375B; Sun, 11 Aug 2019 18:06:19 +0200 (CEST) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by dpdk.org (Postfix) with ESMTP id 659FE326D for ; Sun, 11 Aug 2019 18:06:17 +0200 (CEST) Received: by mail-pl1-f193.google.com with SMTP id g4so458767plo.3 for ; Sun, 11 Aug 2019 09:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eDlnGK4hbL/EzjLtP47RrBz4RlbUoKG7nsPFIArAhf8=; b=OHOcjRdMIpWhlW7sPrqIc9L1gu3sJfVc+1jumRFBL7lVxZhBFusjqvTL+rREVxRSvh cXp22WORUny+wlDPyR87Uut8p+pcFfJW+jFjoBuIWExJ51IC3dp5qzIhOujd9epxnItC TFwFQJV5WSmK+uHuZ0g/ycQEWwWL6oyM4o8yQFf+xTwPdrJgvKwMQ4B+QwIl1Aexu8XV VsuuJ85yh7+b9uqyt6f1NLpi7BaxgWBl43QBaPfJOvLuIIJTJZdMRi3PXBpA1rSyfmO0 A6cwm8Noha+rWNoJTOCv7L0Cg2mj/z0X4pRLg+oJevU/Dq+m0iWt6l1hNkr6L16ATL8n jiNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eDlnGK4hbL/EzjLtP47RrBz4RlbUoKG7nsPFIArAhf8=; b=iyMcmA3P6c0BhMpHcqerqefrsz/e5S7crGeHAzgzLGL380auhskPRKflknEGmpJ5ky 6l+fjOFAH7x8lozZYyFndQQQE9YhaRNNB6bUdFKAwRVnkUVERkwFbicedKAg35a9UTTz wrMpqROr/H7FZ16UbqXPkxgGj48Rt/8AFLIWxrUhSpiazjdx5yZp+tAgykTy47CLteZE B4EUd/WOhtXY4wp71S1bXYxWb8VMvVpdfZKLPoTnvd10cb2TiuU1Q//RBO+1+fICGRPo LI6Yj7HrL3EiP0bNB5SkJTjH7vKh35wp9gzxRYJvW8WkvnfGVpGL+zF15xWVK8rN6HE2 JD4w== X-Gm-Message-State: APjAAAUoeYbyQ/airQWSU3Vdp4eIrI8Dy90ybwuUVRm/JBZdd36EcRG9 MQaNzQqZWCmeimjfHWmAXJdMMdYOc60= X-Google-Smtp-Source: APXvYqy6Nz6EQeXnYQseJAunbjQiAtspLpMRBzSgT9L7ZgXWAhCHVArKLPDnrW78kq9a98rfmC9mQA== X-Received: by 2002:a17:902:7d8b:: with SMTP id a11mr28843908plm.306.1565539576156; Sun, 11 Aug 2019 09:06:16 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id v13sm116890936pfn.109.2019.08.11.09.06.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 11 Aug 2019 09:06:15 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Gaetan Rivet Date: Sun, 11 Aug 2019 09:06:06 -0700 Message-Id: <20190811160607.16441-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190811160607.16441-1-stephen@networkplumber.org> References: <20190626222135.11368-1-stephen@networkplumber.org> <20190811160607.16441-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 1/2] ethdev: expose basic xstats for driver use 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" Avoid duplication by having generic basic xstats available for use by drivers. A later patch uses this for failsafe driver. Signed-off-by: Stephen Hemminger Acked-by: Gaetan Rivet --- lib/librte_ethdev/rte_ethdev.c | 17 +++---- lib/librte_ethdev/rte_ethdev_driver.h | 65 ++++++++++++++++++++++++ lib/librte_ethdev/rte_ethdev_version.map | 24 +++++++++ 3 files changed, 97 insertions(+), 9 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 17d183e1f0ec..88e3065d06fd 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -1996,8 +1996,8 @@ rte_eth_stats_reset(uint16_t port_id) return 0; } -static inline int -get_xstats_basic_count(struct rte_eth_dev *dev) +int +rte_eth_basic_stats_count(struct rte_eth_dev *dev) { uint16_t nb_rxqs, nb_txqs; int count; @@ -2034,7 +2034,7 @@ get_xstats_count(uint16_t port_id) count = 0; - count += get_xstats_basic_count(dev); + count += rte_eth_basic_stats_count(dev); return count; } @@ -2084,7 +2084,7 @@ rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name, } /* retrieve basic stats names */ -static int +int rte_eth_basic_stats_get_names(struct rte_eth_dev *dev, struct rte_eth_xstat_name *xstats_names) { @@ -2140,7 +2140,7 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id, RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; - basic_count = get_xstats_basic_count(dev); + basic_count = rte_eth_basic_stats_count(dev); ret = get_xstats_count(port_id); if (ret < 0) return ret; @@ -2268,8 +2268,7 @@ rte_eth_xstats_get_names(uint16_t port_id, return cnt_used_entries; } - -static int +int rte_eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats) { struct rte_eth_dev *dev; @@ -2341,7 +2340,7 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, expected_entries = (uint16_t)ret; struct rte_eth_xstat xstats[expected_entries]; dev = &rte_eth_devices[port_id]; - basic_count = get_xstats_basic_count(dev); + basic_count = rte_eth_basic_stats_count(dev); /* Return max number of stats if no ids given */ if (!ids) { @@ -2355,7 +2354,7 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, return -EINVAL; if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) { - unsigned int basic_count = get_xstats_basic_count(dev); + unsigned int basic_count = rte_eth_basic_stats_count(dev); uint64_t ids_copy[size]; for (i = 0; i < size; i++) { diff --git a/lib/librte_ethdev/rte_ethdev_driver.h b/lib/librte_ethdev/rte_ethdev_driver.h index 936ff8c98651..489889a72203 100644 --- a/lib/librte_ethdev/rte_ethdev_driver.h +++ b/lib/librte_ethdev/rte_ethdev_driver.h @@ -208,6 +208,71 @@ rte_eth_linkstatus_get(const struct rte_eth_dev *dev, #endif } +/** + * @internal + * Get basic stats part of xstats for an ethernet device. + * + * @param dev + * Pointer to struct rte_eth_dev. + */ +__rte_experimental +int +rte_eth_basic_stats_count(struct rte_eth_dev *dev); + +/** + * @internal + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Retrieve the names for the basic part of extended statistics. + * + * @param dev + * Pointer to struct rte_eth_dev. + * @param xstats_names + * An rte_eth_xstat_name array of at least *size* elements to + * be filled. If set to NULL, the function returns the required number + * of elements. + * @return + * - A positive value lower or equal to size: success. The return value + * is the number of entries filled in the stats table. + * - A positive value higher than size: error, the given statistics table + * is too small. The return value corresponds to the size that should + * be given to succeed. The entries in the table are not valid and + * shall not be used by the caller. + * - A negative value on error (invalid port id). + */ +__rte_experimental +int +rte_eth_basic_stats_get_names(struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names); + +/** + * @internal + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Retrieve the basic part of the extended statistics. + * + * @param dev + * Pointer to struct rte_eth_dev. + * @param xstats + * A pointer to a table of structure of type *rte_eth_xstat* + * to be filled with device statistics ids and values. + * This parameter can be set to NULL if n is 0. + * @param n + * The size of the xstats array (number of elements). + * @return + * - A positive value lower or equal to n: success. The return value + * is the number of entries filled in the stats table. + * - A positive value higher than n: error, the given statistics table + * is too small. The return value corresponds to the size that should + * be given to succeed. The entries in the table are not valid and + * shall not be used by the caller. + * - A negative value on error (invalid port id). + */ +__rte_experimental +int +rte_eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats); + + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map index 6df42a47b89d..f2198b0367d1 100644 --- a/lib/librte_ethdev/rte_ethdev_version.map +++ b/lib/librte_ethdev/rte_ethdev_version.map @@ -240,6 +240,25 @@ EXPERIMENTAL { global: # added in 17.11 + rte_eth_devargs_parse; + rte_eth_dev_create; + rte_eth_dev_destroy; + rte_eth_dev_get_module_eeprom; + rte_eth_dev_get_module_info; + rte_eth_dev_is_removed; + rte_eth_dev_owner_delete; + rte_eth_dev_owner_get; + rte_eth_dev_owner_new; + rte_eth_dev_owner_set; + rte_eth_dev_owner_unset; + rte_eth_dev_rx_intr_ctl_q_get_fd; + rte_eth_find_next_of; + rte_eth_find_next_sibling; + rte_eth_read_clock; + rte_eth_switch_domain_alloc; + rte_eth_switch_domain_free; + rte_flow_conv; + rte_flow_expand_rss; rte_mtr_capabilities_get; rte_mtr_create; rte_mtr_destroy; @@ -283,4 +302,9 @@ EXPERIMENTAL { # added in 19.08 rte_eth_read_clock; + + # added in 19.11 + rte_eth_basic_stats_count; + rte_eth_basic_stats_get; + rte_eth_basic_stats_get_names; }; From patchwork Sun Aug 11 16:06:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 57612 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 59AF04C6C; Sun, 11 Aug 2019 18:06:21 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 4F7AE326D for ; Sun, 11 Aug 2019 18:06:18 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id g2so48538129pfq.0 for ; Sun, 11 Aug 2019 09:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=itcAe7gbH25+PGcARfohNVJsVQ7o9M2JsExjAHdF9Nc=; b=xtbx6gNQHTRzRjOlhN7dzYwqJzyoNquZfJVIbohsvAEDtMkWwthV3stRTcyKDK9jDN JK/B5H50iGq39+4YNTYOM9WuA4K2P0jpF1hI9pVVHGOCLe+NC7L+7ZoAIjgjlqcgcqFa 7KR6n5ueFKev3IWeagHUuh51KKj6ku4y0cPqLaCxZVvAJc+FoTmNAoywGLfxrFrgSSHi xjy/qe9ELjz1uY1YA63YpRjR8oX+1rdIbQniBGbUZfXOEvrJtWK456xAJ/oDJC8055Gn 6Gtz8tjPt31dFkfWxLms956oSLU6L19Gy1/Nj8m3rRb2xZGQVG1GNgtQ32OYOFNujIG3 nAEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=itcAe7gbH25+PGcARfohNVJsVQ7o9M2JsExjAHdF9Nc=; b=iKoNbPbTnxvMiz8HkquBo7tpodWn9oy8WrPm54ttLocxrEq4DaIFIaxbw/DgCz9NHQ 9G1aAqZtIAbRqbKr4uV32lXakxY52p1+6XiS82XCSl6+JakRscEIcuGUM/JzZ8eC8C5m kZWd4lDpb1z4W40/emeDvfx7BgJps79vADry+M35amt7YXafk49iQHvOe2c94JsOAX4Q WvTqL4LrIDewhmQXgSmino3bY81/0OmQvLtQue8ekeZkuQsvqU7hT+8hT5jFc9TOYJ5m cAY/I9eS2y+bUb0oOlo16nZZY9GjewkKEGtyqSH/meOlYVWkTBF0Ys59QtQsxu0qIBYV WfiQ== X-Gm-Message-State: APjAAAXuzxQOCbmoQZitzR6Vf96eMO8s+22x3imhgY1n0/4bkm8JbkQC y85vMamh2TxcCOQlWKYpZxdkxR1sn1U= X-Google-Smtp-Source: APXvYqxuLJ7/aCWx1+FH4uubEx/kHsxet4pZvrdBZJYCVbpiHk3OobcdtyHotSTOFhcG9ZUz2HtIug== X-Received: by 2002:aa7:8189:: with SMTP id g9mr32203858pfi.143.1565539577263; Sun, 11 Aug 2019 09:06:17 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id v13sm116890936pfn.109.2019.08.11.09.06.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 11 Aug 2019 09:06:16 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Gaetan Rivet Date: Sun, 11 Aug 2019 09:06:07 -0700 Message-Id: <20190811160607.16441-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190811160607.16441-1-stephen@networkplumber.org> References: <20190626222135.11368-1-stephen@networkplumber.org> <20190811160607.16441-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/2] net/failsafe: implement xstats 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 support for extended statistics in failsafe driver. Reports basic statistics for the failsafe driver, and detailed statistics for each sub device. Signed-off-by: Stephen Hemminger Acked-by: Gaetan Rivet --- drivers/net/failsafe/failsafe_ops.c | 135 ++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c index 96e05d4dc4b1..711fdf302f4f 100644 --- a/drivers/net/failsafe/failsafe_ops.c +++ b/drivers/net/failsafe/failsafe_ops.c @@ -789,6 +789,138 @@ fs_stats_reset(struct rte_eth_dev *dev) fs_unlock(dev, 0); } +/* + * Count how many xstats in total + * Include basic stats for failsafe device + * plus xstats for each sub-device present. + */ +static int +fs_xstats_count(struct rte_eth_dev *dev) +{ + struct sub_device *sdev; + uint8_t i; + int count; + + count = rte_eth_basic_stats_count(dev); + + fs_lock(dev, 0); + FOREACH_SUBDEV(sdev, i, dev) { + count += rte_eth_xstats_get_names(PORT_ID(sdev), NULL, 0); + } + fs_unlock(dev, 0); + + return count; +} + +static int +fs_xstats_get_names(struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names, + unsigned int limit) +{ + struct sub_device *sdev; + unsigned int count; + char tmp[RTE_ETH_XSTATS_NAME_SIZE]; + uint8_t i; + int r; + + /* Caller only cares about count */ + if (!xstats_names) + return fs_xstats_count(dev); + + r = rte_eth_basic_stats_get_names(dev, xstats_names); + if (r < 0) + return r; + + count = r; + + fs_lock(dev, 0); + FOREACH_SUBDEV(sdev, i, dev) { + struct rte_eth_xstat_name *sub_names = xstats_names + count; + + if (count >= limit) + break; + + r = rte_eth_xstats_get_names(PORT_ID(sdev), sub_names, + limit - count); + if (r < 0) { + fs_unlock(dev, 0); + return r; + } + + /* add sub_ prefix to names */ + for (i = 0; i < r; i++) { + snprintf(tmp, sizeof(tmp), "sub%u_%s", + i, sub_names[i].name); + memcpy(sub_names[i].name, tmp, + RTE_ETH_XSTATS_NAME_SIZE); + } + + count += r; + } + fs_unlock(dev, 0); + + return count; +} + +static int +fs_xstats_get(struct rte_eth_dev *dev, + struct rte_eth_xstat *xstats, + unsigned int n) +{ + unsigned int nstats, j, count, scount; + struct sub_device *sdev; + uint8_t i; + int ret; + + nstats = fs_xstats_count(dev); + if (n < nstats || xstats == NULL) + return nstats; + + ret = rte_eth_basic_stats_get(dev->data->port_id, xstats); + if (ret < 0) + return ret; + + count = ret; + for (j = 0; j < count; j++) + xstats[j].id = j; + + fs_lock(dev, 0); + FOREACH_SUBDEV(sdev, i, dev) { + ret = rte_eth_xstats_get(PORT_ID(sdev), + xstats + count, + n > count ? n - count : 0); + if (ret < 0) { + fs_unlock(dev, 0); + return ret; + } + scount = ret; + + /* add offset to id's from sub-device */ + for (j = 0; j < scount; j++) + xstats[count + j].id += count; + + count += scount; + } + fs_unlock(dev, 0); + + return count; +} + +static void +fs_xstats_reset(struct rte_eth_dev *dev) +{ + struct sub_device *sdev; + uint8_t i; + + rte_eth_stats_reset(dev->data->port_id); + + fs_lock(dev, 0); + FOREACH_SUBDEV(sdev, i, dev) { + rte_eth_xstats_reset(PORT_ID(sdev)); + } + fs_unlock(dev, 0); +} + static void fs_dev_merge_desc_lim(struct rte_eth_desc_lim *to, const struct rte_eth_desc_lim *from) @@ -1233,6 +1365,9 @@ const struct eth_dev_ops failsafe_ops = { .link_update = fs_link_update, .stats_get = fs_stats_get, .stats_reset = fs_stats_reset, + .xstats_get = fs_xstats_get, + .xstats_get_names = fs_xstats_get_names, + .xstats_reset = fs_xstats_reset, .dev_infos_get = fs_dev_infos_get, .dev_supported_ptypes_get = fs_dev_supported_ptypes_get, .mtu_set = fs_mtu_set,