From: Jiri Pirko <jiri@resnulli.us>
To: David Decotigny <decot@googlers.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Jamal Hadi Salim <jhs@mojatatu.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Eric Dumazet <edumazet@google.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Weilong Chen <chenweilong@huawei.com>,
Amir Vadai <amirv@mellanox.com>,
Michael Dalton <mwdalton@google.com>,
Al Viro <viro@ZenIV.linux.org.uk>, Tejun Heo <tj@kernel.org>
Subject: Re: [PATCH v1] net-sysfs: expose number of link up/down transitions
Date: Fri, 28 Mar 2014 07:25:37 +0100 [thread overview]
Message-ID: <20140328062537.GA2805@minipsycho.orion> (raw)
In-Reply-To: <cc4b88e880d31d8d71a5c8872a64c9d665cd097e.1395980768.git.decot@googlers.com>
Fri, Mar 28, 2014 at 05:35:00AM CET, decot@googlers.com wrote:
>Tested:
> grep . /sys/class/net/*/count_link_*
> + ip link set dev X down/up
>
>Signed-off-by: David Decotigny <decot@googlers.com>
>---
> include/linux/netdevice.h | 4 ++++
> net/core/net-sysfs.c | 18 ++++++++++++++++++
> net/sched/sch_generic.c | 2 ++
> 3 files changed, 24 insertions(+)
>
>diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>index 4b6d12c..cf52869 100644
>--- a/include/linux/netdevice.h
>+++ b/include/linux/netdevice.h
>@@ -1315,6 +1315,10 @@ struct net_device {
> * Do not use this in drivers.
> */
>
>+ /* Stats to monitor link on/off, flapping */
>+ atomic_t count_link_up;
>+ atomic_t count_link_down;
>+
> #ifdef CONFIG_WIRELESS_EXT
> /* List of functions to handle Wireless Extensions (instead of ioctl).
> * See <net/iw_handler.h> for details. Jean II */
>diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
>index daed9a6..a65ac54 100644
>--- a/net/core/net-sysfs.c
>+++ b/net/core/net-sysfs.c
>@@ -253,6 +253,22 @@ static ssize_t operstate_show(struct device *dev,
> }
> static DEVICE_ATTR_RO(operstate);
>
>+static ssize_t count_link_up_show(struct device *dev,
>+ struct device_attribute *attr, char *buf)
>+{
>+ struct net_device *netdev = to_net_dev(dev);
>+ return sprintf(buf, fmt_dec, atomic_read(&netdev->count_link_up));
>+}
>+
>+static ssize_t count_link_down_show(struct device *dev,
>+ struct device_attribute *attr, char *buf)
>+{
>+ struct net_device *netdev = to_net_dev(dev);
>+ return sprintf(buf, fmt_dec, atomic_read(&netdev->count_link_down));
>+}
>+static DEVICE_ATTR_RO(count_link_up);
>+static DEVICE_ATTR_RO(count_link_down);
>+
If this is exposed in sysfs, this needs to be exposed via RT netlink as
well.
> /* read-write attributes */
>
> static int change_mtu(struct net_device *net, unsigned long new_mtu)
>@@ -386,6 +402,8 @@ static struct attribute *net_class_attrs[] = {
> &dev_attr_duplex.attr,
> &dev_attr_dormant.attr,
> &dev_attr_operstate.attr,
>+ &dev_attr_count_link_up.attr,
>+ &dev_attr_count_link_down.attr,
> &dev_attr_ifalias.attr,
> &dev_attr_carrier.attr,
> &dev_attr_mtu.attr,
>diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
>index e82e43b..2d06943 100644
>--- a/net/sched/sch_generic.c
>+++ b/net/sched/sch_generic.c
>@@ -310,6 +310,7 @@ void netif_carrier_on(struct net_device *dev)
> if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
> if (dev->reg_state == NETREG_UNINITIALIZED)
> return;
>+ atomic_inc(&dev->count_link_up);
> linkwatch_fire_event(dev);
> if (netif_running(dev))
> __netdev_watchdog_up(dev);
>@@ -328,6 +329,7 @@ void netif_carrier_off(struct net_device *dev)
> if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
> if (dev->reg_state == NETREG_UNINITIALIZED)
> return;
>+ atomic_inc(&dev->count_link_down);
> linkwatch_fire_event(dev);
> }
> }
>--
>1.9.1.423.g4596e3a
>
next prev parent reply other threads:[~2014-03-28 6:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1395980768.git.decot@googlers.com>
2014-03-28 4:35 ` [PATCH v1] net-sysfs: expose number of link up/down transitions David Decotigny
2014-03-28 5:17 ` Stephen Rothwell
2014-03-28 5:56 ` Florian Fainelli
2014-03-28 6:25 ` Jiri Pirko [this message]
2014-03-28 16:51 ` Florian Fainelli
2014-03-28 17:46 ` Eric Dumazet
2014-03-28 17:59 ` Florian Fainelli
2014-03-28 18:08 ` Eric Dumazet
2014-03-28 18:19 ` David Decotigny
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=20140328062537.GA2805@minipsycho.orion \
--to=jiri@resnulli.us \
--cc=amirv@mellanox.com \
--cc=chenweilong@huawei.com \
--cc=davem@davemloft.net \
--cc=decot@googlers.com \
--cc=ebiederm@xmission.com \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jhs@mojatatu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mwdalton@google.com \
--cc=netdev@vger.kernel.org \
--cc=tj@kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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).