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 D5F09A046B for ; Thu, 27 Jun 2019 01:34:13 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E93694C8E; Thu, 27 Jun 2019 01:34:01 +0200 (CEST) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by dpdk.org (Postfix) with ESMTP id 8BD0337A2 for ; Thu, 27 Jun 2019 01:33:57 +0200 (CEST) Received: by mail-pg1-f196.google.com with SMTP id y72so94618pgd.8 for ; Wed, 26 Jun 2019 16:33: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 :mime-version:content-transfer-encoding; bh=mVzH7MS9jU9XHiZID3idJoyKVkuPXMlmxGHOoZgv70I=; b=JPf3NIc9VObRVaiM0vy4LzxJsk9XJDNEzOznyEM+eL0QV0ooA5GPnqEW5XJesb8eGP Sqc+mNCGZKaQ2J2sDjUPflBMQCmpHaqQqxEilWc16QCTDEaM6DVsF8MLEEpEGkn9CXNK YiyM5UoUdMIDWH0xhR36WxHJFqnRsXTw5ALuDmOo4UhGBie8fJLHmpL7I0u6IFnA5H2D uolHnIl6XQoajLZC9GlgzoUGfz1k3L6rVfaRxB3IFR0xgd5sOD1wCKXkPvz1TTbFZHDR 8/vNh6lEapaSPAXyknmHMR4AcyHJCCXdhxT9bm2pZs4InsDy6AWutMZx0XiMdN2IskyY qXBw== 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=mVzH7MS9jU9XHiZID3idJoyKVkuPXMlmxGHOoZgv70I=; b=jYZxo3a97hYwM5t8X6GKj6VA8C69/i/qbARiWuHkFsgdx0gjPbysgIRqOCBHRoeY2p cxM4GpJOIF7yZh5+xOQhpHOO5UHzDRlkbeWVQg6jmoKvRsRWntU5WQkkkupyqtEdfqnC kepK6XC2JAe4wODVKlu6ZWPnBxwPipxGRkSMhhaXGHKzmwW/xmCWPa9Fogcw/RS0xwh6 OCOWd9i6ApGFDKH8NCWw1BcZmRtsbPal7P1746coog/UJu0euucRCUKV6fS9rV4GnY84 +ho8WvpECnWv7wBKXcZC/TqSpu/EfbC6eN6iEnWJTz6KOxn4l3u3KCkp9dO03xe0cxOL zMGg== X-Gm-Message-State: APjAAAX0aXF4Y8tEpMzZiPFAvuNSN/8yRSjjA5hWGqiXfXC9fA5dGH2p T0tviwfeMyyzNRKCH39Ywu92yg== X-Google-Smtp-Source: APXvYqzhs1Rfo1ZM9dDYIrGC5f0QBXAKDF6Listo6ekPBAepKgYlgMYUQSSf+QhFOU21peBCDtWbuQ== X-Received: by 2002:a17:90a:fa07:: with SMTP id cm7mr1994943pjb.138.1561592036779; Wed, 26 Jun 2019 16:33:56 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id g2sm357028pfb.95.2019.06.26.16.33.55 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 26 Jun 2019 16:33:55 -0700 (PDT) From: Stephen Hemminger To: gaetan.rivet@6wind.com Cc: dev@dpdk.org, Stephen Hemminger , Stephen Hemminger Date: Wed, 26 Jun 2019 16:33:46 -0700 Message-Id: <20190626233346.4719-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190626233346.4719-1-stephen@networkplumber.org> References: <20190626222135.11368-1-stephen@networkplumber.org> <20190626233346.4719-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 2/2] 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 --- drivers/net/failsafe/failsafe_ops.c | 130 ++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c index 96e05d4dc4b1..a250c0528965 100644 --- a/drivers/net/failsafe/failsafe_ops.c +++ b/drivers/net/failsafe/failsafe_ops.c @@ -789,6 +789,133 @@ fs_stats_reset(struct rte_eth_dev *dev) fs_unlock(dev, 0); } +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; + + 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), + xstats_names + count, + 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 +1360,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.20.1