From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, nogahf@mellanox.com, idosch@mellanox.com,
eladr@mellanox.com, yotamg@mellanox.com, ogerlitz@mellanox.com,
roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com,
linville@tuxdriver.com, tgraf@suug.ch, gospo@cumulusnetworks.com,
sfeldma@gmail.com, sd@queasysnail.net, eranbe@mellanox.com,
ast@plumgrid.com, edumazet@google.com,
hannes@stressinduktion.org, f.fainelli@gmail.com,
dsa@cumulusnetworks.com
Subject: [patch net-next v6 1/3] netdevice: add SW statistics ndo
Date: Tue, 9 Aug 2016 23:25:10 +0200 [thread overview]
Message-ID: <1470777912-2227-2-git-send-email-jiri@resnulli.us> (raw)
In-Reply-To: <1470777912-2227-1-git-send-email-jiri@resnulli.us>
From: Nogah Frankel <nogahf@mellanox.com>
Stats should return the number of packets that went though a port by SW
or HW. But when one has offloaded traffic, one might want to know how
many packets went via slow path.
So this ndo return SW statistics for packets that went via CPU,
(opposed to HW counter that count all the packets, slow path or not).
Add a new ndo declaration to get SW statistics.
Add a function that gets SW statistics if a compatible ndo exist.
Signed-off-by: Nogah Frankel <nogahf@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
include/linux/netdevice.h | 14 ++++++++++++++
net/core/dev.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 076df53..4f5c0875 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -922,6 +922,15 @@ struct netdev_xdp {
* field is written atomically.
* 3. Update dev->stats asynchronously and atomically, and define
* neither operation.
+ * If there are both SW and HW stats, driver should return combined
+ * stats.
+ *
+ * struct rtnl_link_stats64* (*ndo_get_sw_stats64)(struct net_device *dev,
+ * struct rtnl_link_stats64 *storage);
+ * Similar to rtnl_link_stats64 but used to get SW statistics,
+ * if it is possible to get HW and SW statistics separately.
+ * If this option isn't valid - driver doesn't need to define
+ * this function.
*
* int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16 vid);
* If device supports VLAN filtering this function is called when a
@@ -1154,6 +1163,9 @@ struct net_device_ops {
struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
struct rtnl_link_stats64 *storage);
+ struct rtnl_link_stats64* (*ndo_get_sw_stats64)(struct net_device *dev,
+ struct rtnl_link_stats64 *storage);
+
struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
int (*ndo_vlan_rx_add_vid)(struct net_device *dev,
@@ -3798,6 +3810,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
struct rtnl_link_stats64 *storage);
void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
const struct net_device_stats *netdev_stats);
+int dev_get_sw_stats(struct net_device *dev, struct rtnl_link_stats64 *storage);
+bool dev_have_sw_stats(const struct net_device *dev);
extern int netdev_max_backlog;
extern int netdev_tstamp_prequeue;
diff --git a/net/core/dev.c b/net/core/dev.c
index 4ce07dc..e5b8cbf 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7494,6 +7494,8 @@ EXPORT_SYMBOL(netdev_stats_to_stats64);
* The device driver may provide its own method by setting
* dev->netdev_ops->get_stats64 or dev->netdev_ops->get_stats;
* otherwise the internal statistics structure is used.
+ * If device supports both HW & SW statistics - this function should
+ * return the combined statistics.
*/
struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
struct rtnl_link_stats64 *storage)
@@ -7515,6 +7517,35 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
}
EXPORT_SYMBOL(dev_get_stats);
+/* dev_get_sw_stats - get network device SW statistics
+ * (if it is possible to get HW & SW statistics separately)
+ * @dev: device to get statistics from
+ * @storage: place to store stats
+ *
+ * if exist a function to query the netdev SW statistics get it to storage
+ * return 0 if did, or -EINVAL if this function doesn't exist
+ */
+int dev_get_sw_stats(struct net_device *dev,
+ struct rtnl_link_stats64 *storage)
+{
+ const struct net_device_ops *ops = dev->netdev_ops;
+
+ if (ops->ndo_get_sw_stats64) {
+ memset(storage, 0, sizeof(*storage));
+ ops->ndo_get_sw_stats64(dev, storage);
+ } else {
+ return -EINVAL;
+ }
+ return 0;
+}
+EXPORT_SYMBOL(dev_get_sw_stats);
+
+bool dev_have_sw_stats(const struct net_device *dev)
+{
+ return dev->netdev_ops->ndo_get_sw_stats64 != NULL;
+}
+EXPORT_SYMBOL(dev_have_sw_stats);
+
struct netdev_queue *dev_ingress_queue_create(struct net_device *dev)
{
struct netdev_queue *queue = dev_ingress_queue(dev);
--
2.5.5
next prev parent reply other threads:[~2016-08-09 21:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-09 21:25 [patch net-next v6 0/3] return offloaded stats as default and expose original sw stats Jiri Pirko
2016-08-09 21:25 ` Jiri Pirko [this message]
2016-08-09 21:25 ` [patch net-next v6 2/3] net: core: add SW stats to if_stats_msg Jiri Pirko
2016-08-10 6:08 ` Roopa Prabhu
2016-08-16 12:47 ` Nogah Frankel
2016-08-09 21:25 ` [patch net-next v6 3/3] mlxsw: spectrum: Implement SW stats ndo and expose HW stats by default Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470777912-2227-2-git-send-email-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=dsa@cumulusnetworks.com \
--cc=edumazet@google.com \
--cc=eladr@mellanox.com \
--cc=eranbe@mellanox.com \
--cc=f.fainelli@gmail.com \
--cc=gospo@cumulusnetworks.com \
--cc=hannes@stressinduktion.org \
--cc=idosch@mellanox.com \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.org \
--cc=nikolay@cumulusnetworks.com \
--cc=nogahf@mellanox.com \
--cc=ogerlitz@mellanox.com \
--cc=roopa@cumulusnetworks.com \
--cc=sd@queasysnail.net \
--cc=sfeldma@gmail.com \
--cc=tgraf@suug.ch \
--cc=yotamg@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).