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 380E5A2EFC for ; Thu, 19 Sep 2019 14:57:09 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E727F1EFEB; Thu, 19 Sep 2019 14:56:59 +0200 (CEST) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by dpdk.org (Postfix) with ESMTP id 81EE51EFDF for ; Thu, 19 Sep 2019 14:56:57 +0200 (CEST) Received: by mail-wr1-f66.google.com with SMTP id r5so2944446wrm.12 for ; Thu, 19 Sep 2019 05:56:57 -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; bh=5e+KNvphZQf/O34q0pjNdu4cp7DnIhHMPoCcSIn/f18=; b=nzzBaF8adXUUKkcl2zpuOY3LiFwp+BNXibWu/9BdfiuKdnrlEYTE4cdmZdznm3Dpea 6o4IDMsUUS2EL44ifBmfatFz6EvBuD9j9jbMOam0uuLHeVs3y0yh50X+igCFHw3WuU3y 91Cu/uhAjJUcwKxh++VDmKqUATZFc5ua89ANBGuM6NN54InpXwyBftRyoh5Um6D92s24 XsvJKycXaTwLaglqZeuND3J577xGkSxglFR6uOd9xJyg9lT9GnauQfYxcMh92gC6l/j2 7pdMLl5eFxpLRmEFmp/bZg49GCXMw/i8h2KL5om6a36Tu2cd/pnARHU/VWdmmVup87Zl ZdxA== 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; bh=5e+KNvphZQf/O34q0pjNdu4cp7DnIhHMPoCcSIn/f18=; b=C6kbH7VPgCFF441jsCoRWuWoj2R0c4t2Ql75ghNnJF+hc7ln41R2t8SbXsC8TARP0b pmgzaQR6d5myNjFXIsRZ0swIgyuMc3WdZws9Zo+mn3GfsI3V/+Bj5Yy+bIDYyYmiiofb g0/bGJMFuzBxf9KY7wXzB++Wfj9pQ6TPryNCoj5uk8I5NDjDZtpp8R9KrokSv6+cTtqc QDymFfmIvmb/9ggATVeTRyzYgOD+9TVev2QtCbQiqGl8z+GApVdE5pNnUx3g+bcyrD22 COzjDeNaHUu+x0d5Aotz1p5KtvM8yOqesTa9EQduLoMaAH8v9lxvUpRAacLFni5prC8h WMgQ== X-Gm-Message-State: APjAAAXKqPKWwmqBaBbBFyshJ/xyyP0bC0k3pqwqIYL48ctn72Sx4gFu TVhYnUXWlE8OO0YInErmG/pN29P6nAEyww== X-Google-Smtp-Source: APXvYqzJFwTpzZtU4OcFDIwLfvAnFHCd0mF0+rlLts6rRebMLaZf5sNYBPGSXsm2pOI/O4yrL3efDA== X-Received: by 2002:adf:ec09:: with SMTP id x9mr7031842wrn.308.1568897816760; Thu, 19 Sep 2019 05:56:56 -0700 (PDT) Received: from localhost.localdomain (lmontsouris-657-1-167-187.w82-127.abo.wanadoo.fr. [82.127.205.187]) by smtp.gmail.com with ESMTPSA id f186sm8030519wmg.21.2019.09.19.05.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 05:56:55 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 19 Sep 2019 14:56:50 +0200 Message-Id: <20190919125650.27262-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190919125650.27262-1-stephen@networkplumber.org> References: <20190811160607.16441-1-stephen@networkplumber.org> <20190919125650.27262-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 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, -- 2.17.1