netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes
       [not found] <cover.1396111568.git.decot@googlers.com>
@ 2014-03-29 16:48 ` David Decotigny
  2014-03-30  1:36   ` Stephen Hemminger
  2014-03-31 20:25   ` David Miller
  0 siblings, 2 replies; 6+ messages in thread
From: David Decotigny @ 2014-03-29 16:48 UTC (permalink / raw)
  To: David S. Miller, Jamal Hadi Salim, netdev, linux-kernel
  Cc: Greg Kroah-Hartman, Eric Dumazet, Eric W. Biederman, Weilong Chen,
	Jiri Pirko, Amir Vadai, Michael Dalton, David Decotigny, Al Viro,
	Tejun Heo

This allows to monitor carrier on/off transitions and detect link
flapping issues:
 - new /sys/class/net/X/carrier_changes
 - new rtnetlink IFLA_CARRIER_CHANGES (getlink)

Tested:
  - grep . /sys/class/net/*/carrier_changes
    + ip link set dev X down/up
    + plug/unplug cable
  - updated iproute2: prints IFLA_CARRIER_CHANGES
  - iproute2 20121211-2 (debian): unchanged behavior

Signed-off-by: David Decotigny <decot@googlers.com>
---
 include/linux/netdevice.h    |  3 +++
 include/uapi/linux/if_link.h |  1 +
 net/core/net-sysfs.c         | 11 +++++++++++
 net/core/rtnetlink.c         |  6 +++++-
 net/sched/sch_generic.c      |  2 ++
 5 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 159c7e7..feb60c0 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1316,6 +1316,9 @@ struct net_device {
 	atomic_long_t		rx_dropped;
 	atomic_long_t		tx_dropped;
 
+	/* Stats to monitor carrier on<->off transitions */
+	atomic_t		carrier_changes;
+
 #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/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 16410b6..9a7f7ac 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -144,6 +144,7 @@ enum {
 	IFLA_NUM_RX_QUEUES,
 	IFLA_CARRIER,
 	IFLA_PHYS_PORT_ID,
+	IFLA_CARRIER_CHANGES,
 	__IFLA_MAX
 };
 
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index daed9a6..4623962 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -253,6 +253,16 @@ static ssize_t operstate_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(operstate);
 
+static ssize_t carrier_changes_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->carrier_changes));
+}
+static DEVICE_ATTR_RO(carrier_changes);
+
 /* read-write attributes */
 
 static int change_mtu(struct net_device *net, unsigned long new_mtu)
@@ -386,6 +396,7 @@ static struct attribute *net_class_attrs[] = {
 	&dev_attr_duplex.attr,
 	&dev_attr_dormant.attr,
 	&dev_attr_operstate.attr,
+	&dev_attr_carrier_changes.attr,
 	&dev_attr_ifalias.attr,
 	&dev_attr_carrier.attr,
 	&dev_attr_mtu.attr,
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index e7c6006..d4ff417 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -822,6 +822,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + nla_total_size(4) /* IFLA_NUM_RX_QUEUES */
 	       + nla_total_size(1) /* IFLA_OPERSTATE */
 	       + nla_total_size(1) /* IFLA_LINKMODE */
+	       + nla_total_size(4) /* IFLA_CARRIER_CHANGES */
 	       + nla_total_size(ext_filter_mask
 			        & RTEXT_FILTER_VF ? 4 : 0) /* IFLA_NUM_VF */
 	       + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
@@ -970,7 +971,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 	    (dev->qdisc &&
 	     nla_put_string(skb, IFLA_QDISC, dev->qdisc->ops->id)) ||
 	    (dev->ifalias &&
-	     nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)))
+	     nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
+	    nla_put_u32(skb, IFLA_CARRIER_CHANGES,
+			atomic_read(&dev->carrier_changes)))
 		goto nla_put_failure;
 
 	if (1) {
@@ -1147,6 +1150,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
 	[IFLA_NUM_TX_QUEUES]	= { .type = NLA_U32 },
 	[IFLA_NUM_RX_QUEUES]	= { .type = NLA_U32 },
 	[IFLA_PHYS_PORT_ID]	= { .type = NLA_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
+	[IFLA_CARRIER_CHANGES]	= { .type = NLA_U32 },  /* ignored */
 };
 
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index e82e43b..e1543b0 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->carrier_changes);
 		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->carrier_changes);
 		linkwatch_fire_event(dev);
 	}
 }
-- 
1.9.1.423.g4596e3a

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes
  2014-03-29 16:48 ` [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes David Decotigny
@ 2014-03-30  1:36   ` Stephen Hemminger
  2014-03-30  1:50     ` Eric Dumazet
  2014-03-31 20:25   ` David Miller
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2014-03-30  1:36 UTC (permalink / raw)
  To: David Decotigny
  Cc: David S. Miller, Jamal Hadi Salim, netdev, linux-kernel,
	Greg Kroah-Hartman, Eric Dumazet, Eric W. Biederman, Weilong Chen,
	Jiri Pirko, Amir Vadai, Michael Dalton, Al Viro, Tejun Heo

On Sat, 29 Mar 2014 09:48:35 -0700
David Decotigny <decot@googlers.com> wrote:

> This allows to monitor carrier on/off transitions and detect link
> flapping issues:
>  - new /sys/class/net/X/carrier_changes
>  - new rtnetlink IFLA_CARRIER_CHANGES (getlink)
> 
> Tested:
>   - grep . /sys/class/net/*/carrier_changes
>     + ip link set dev X down/up
>     + plug/unplug cable
>   - updated iproute2: prints IFLA_CARRIER_CHANGES
>   - iproute2 20121211-2 (debian): unchanged behavior
> 
> Signed-off-by: David Decotigny <decot@googlers.com>

Is there a related SNMP MIB variable? should there be?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes
  2014-03-30  1:36   ` Stephen Hemminger
@ 2014-03-30  1:50     ` Eric Dumazet
  2014-03-30 15:18       ` David Decotigny
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2014-03-30  1:50 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: David Decotigny, David S. Miller, Jamal Hadi Salim, netdev,
	linux-kernel, Greg Kroah-Hartman, Eric Dumazet, Eric W. Biederman,
	Weilong Chen, Jiri Pirko, Amir Vadai, Michael Dalton, Al Viro,
	Tejun Heo

On Sat, 2014-03-29 at 18:36 -0700, Stephen Hemminger wrote:
> On Sat, 29 Mar 2014 09:48:35 -0700
> David Decotigny <decot@googlers.com> wrote:
> 
> > This allows to monitor carrier on/off transitions and detect link
> > flapping issues:
> >  - new /sys/class/net/X/carrier_changes
> >  - new rtnetlink IFLA_CARRIER_CHANGES (getlink)
> > 
> > Tested:
> >   - grep . /sys/class/net/*/carrier_changes
> >     + ip link set dev X down/up
> >     + plug/unplug cable
> >   - updated iproute2: prints IFLA_CARRIER_CHANGES
> >   - iproute2 20121211-2 (debian): unchanged behavior
> > 
> > Signed-off-by: David Decotigny <decot@googlers.com>
> 
> Is there a related SNMP MIB variable? should there be?

I don't think we have any SNMP MIB variable for devices ?

It seems "ip link" is the facto standard.

(BTW we put BusyPollRxPackets in TcpExt group, this was an error IMHO)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes
  2014-03-30  1:50     ` Eric Dumazet
@ 2014-03-30 15:18       ` David Decotigny
  2014-03-31 16:49         ` Florian Fainelli
  0 siblings, 1 reply; 6+ messages in thread
From: David Decotigny @ 2014-03-30 15:18 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: David S. Miller, Jamal Hadi Salim, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Greg Kroah-Hartman, Eric Dumazet,
	Eric W. Biederman, Weilong Chen, Jiri Pirko, Amir Vadai,
	Michael Dalton, Al Viro, Tejun Heo, Florian Fainelli,
	Eric Dumazet

Hi all,

As Eric mentioned, this is a per-link counter. I am not sure an
aggregate stat would be as useful.

As suggested by Florian, I'm planning to add a doc. As far as I can
tell, I think it goes beyond just documenting this new counter: I
believe sysfs-class-net needs to be added as a whole.

Stephen: I have a patch for iproute2, I was planning to send it after
we're done with this one, unless you want it now. Also, should I
document this IFLA thing, where would be best?

On Sat, Mar 29, 2014 at 6:50 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Sat, 2014-03-29 at 18:36 -0700, Stephen Hemminger wrote:
>> On Sat, 29 Mar 2014 09:48:35 -0700
>> David Decotigny <decot@googlers.com> wrote:
>>
>> > This allows to monitor carrier on/off transitions and detect link
>> > flapping issues:
>> >  - new /sys/class/net/X/carrier_changes
>> >  - new rtnetlink IFLA_CARRIER_CHANGES (getlink)
>> >
>> > Tested:
>> >   - grep . /sys/class/net/*/carrier_changes
>> >     + ip link set dev X down/up
>> >     + plug/unplug cable
>> >   - updated iproute2: prints IFLA_CARRIER_CHANGES
>> >   - iproute2 20121211-2 (debian): unchanged behavior
>> >
>> > Signed-off-by: David Decotigny <decot@googlers.com>
>>
>> Is there a related SNMP MIB variable? should there be?
>
> I don't think we have any SNMP MIB variable for devices ?
>
> It seems "ip link" is the facto standard.
>
> (BTW we put BusyPollRxPackets in TcpExt group, this was an error IMHO)
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes
  2014-03-30 15:18       ` David Decotigny
@ 2014-03-31 16:49         ` Florian Fainelli
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2014-03-31 16:49 UTC (permalink / raw)
  To: David Decotigny
  Cc: Stephen Hemminger, David S. Miller, Jamal Hadi Salim,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman, Eric Dumazet, Eric W. Biederman, Weilong Chen,
	Jiri Pirko, Amir Vadai, Michael Dalton, Al Viro, Tejun Heo,
	Eric Dumazet

Hi David,

2014-03-30 8:18 GMT-07:00 David Decotigny <decot@googlers.com>:
> Hi all,
>
> As Eric mentioned, this is a per-link counter. I am not sure an
> aggregate stat would be as useful.
>
> As suggested by Florian, I'm planning to add a doc. As far as I can
> tell, I think it goes beyond just documenting this new counter: I
> believe sysfs-class-net needs to be added as a whole.

Right, I sort of started to do that here:
http://patchwork.ozlabs.org/patch/334888/
Once this gets accepted, I plan on documenting the other sysfs
attributes in statistics/ and queues/ in particular

>
> Stephen: I have a patch for iproute2, I was planning to send it after
> we're done with this one, unless you want it now. Also, should I
> document this IFLA thing, where would be best?
>
> On Sat, Mar 29, 2014 at 6:50 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>> On Sat, 2014-03-29 at 18:36 -0700, Stephen Hemminger wrote:
>>> On Sat, 29 Mar 2014 09:48:35 -0700
>>> David Decotigny <decot@googlers.com> wrote:
>>>
>>> > This allows to monitor carrier on/off transitions and detect link
>>> > flapping issues:
>>> >  - new /sys/class/net/X/carrier_changes
>>> >  - new rtnetlink IFLA_CARRIER_CHANGES (getlink)
>>> >
>>> > Tested:
>>> >   - grep . /sys/class/net/*/carrier_changes
>>> >     + ip link set dev X down/up
>>> >     + plug/unplug cable
>>> >   - updated iproute2: prints IFLA_CARRIER_CHANGES
>>> >   - iproute2 20121211-2 (debian): unchanged behavior
>>> >
>>> > Signed-off-by: David Decotigny <decot@googlers.com>
>>>
>>> Is there a related SNMP MIB variable? should there be?
>>
>> I don't think we have any SNMP MIB variable for devices ?
>>
>> It seems "ip link" is the facto standard.
>>
>> (BTW we put BusyPollRxPackets in TcpExt group, this was an error IMHO)
>>
>>



-- 
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes
  2014-03-29 16:48 ` [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes David Decotigny
  2014-03-30  1:36   ` Stephen Hemminger
@ 2014-03-31 20:25   ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2014-03-31 20:25 UTC (permalink / raw)
  To: decot
  Cc: jhs, netdev, linux-kernel, gregkh, edumazet, ebiederm,
	chenweilong, jiri, amirv, mwdalton, viro, tj

From: David Decotigny <decot@googlers.com>
Date: Sat, 29 Mar 2014 09:48:35 -0700

> This allows to monitor carrier on/off transitions and detect link
> flapping issues:
>  - new /sys/class/net/X/carrier_changes
>  - new rtnetlink IFLA_CARRIER_CHANGES (getlink)
> 
> Tested:
>   - grep . /sys/class/net/*/carrier_changes
>     + ip link set dev X down/up
>     + plug/unplug cable
>   - updated iproute2: prints IFLA_CARRIER_CHANGES
>   - iproute2 20121211-2 (debian): unchanged behavior
> 
> Signed-off-by: David Decotigny <decot@googlers.com>

Looks good, applied, thanks David.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-03-31 20:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1396111568.git.decot@googlers.com>
2014-03-29 16:48 ` [PATCH net-next v2] net-sysfs: expose number of carrier on/off changes David Decotigny
2014-03-30  1:36   ` Stephen Hemminger
2014-03-30  1:50     ` Eric Dumazet
2014-03-30 15:18       ` David Decotigny
2014-03-31 16:49         ` Florian Fainelli
2014-03-31 20:25   ` David Miller

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).