Re: [PATCH net-next] net: core: Expose number of link up/down transitions
From: David Ahern
Date: Wed Jan 17 2018 - 19:28:57 EST
On 1/17/18 3:06 PM, Florian Fainelli wrote:
> diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
> index 7bf8b85ade16..9f732c3dc2ce 100644
> --- a/net/core/net-sysfs.c
> +++ b/net/core/net-sysfs.c
> @@ -295,10 +295,29 @@ static ssize_t carrier_changes_show(struct device *dev,
> struct net_device *netdev = to_net_dev(dev);
>
> return sprintf(buf, fmt_dec,
> - atomic_read(&netdev->carrier_changes));
> + atomic_read(&netdev->count_link_up) +
> + atomic_read(&netdev->count_link_down));
> }
> static DEVICE_ATTR_RO(carrier_changes);
>
> +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 DEVICE_ATTR_RO(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_down);
> +
> /* read-write attributes */
>
> static int change_mtu(struct net_device *dev, unsigned long new_mtu)
> @@ -547,6 +566,8 @@ static struct attribute *net_class_attrs[] __ro_after_init = {
> &dev_attr_phys_port_name.attr,
> &dev_attr_phys_switch_id.attr,
> &dev_attr_proto_down.attr,
> + &dev_attr_count_link_up.attr,
> + &dev_attr_count_link_down.attr,
> NULL,
> };
> ATTRIBUTE_GROUPS(net_class);
Personally, I do not like adding any more sysfs files. As discussed in
the past sysfs is a huge contributor to the overhead of netdevs.