From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrei Vagin Subject: Re: [PATCH net-next] net: core: Expose number of link up/down transitions Date: Wed, 17 Jan 2018 16:23:09 -0800 Message-ID: <20180118002308.GA21605@outlook.office365.com> References: <20180117230704.21949-1-f.fainelli@gmail.com> <20180117234941.GA19561@outlook.office365.com> <20180118000652.GD32299@lunn.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Cc: Florian Fainelli , netdev@vger.kernel.org, edumazet@google.com, cphealy@gmail.com, David Decotigny , "David S. Miller" , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Daniel Borkmann , Nikolay Aleksandrov , Alexei Starovoitov , Roopa Prabhu , Mahesh Bandewar , Vlad Yasevich , Jakub Kicinski , Jonas Bonn , stephen hemminger , Hans Liljestrand , "Reshetova, Elena" , Kiril To: Andrew Lunn Return-path: Content-Disposition: inline In-Reply-To: <20180118000652.GD32299@lunn.ch> Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On Thu, Jan 18, 2018 at 01:06:52AM +0100, Andrew Lunn wrote: > > What is the idea to have two separate counters? Can a delta between them > > be a bigger than 1? > > Yes, it can. > > These counters are incremented in netif_carrier_on() / > netif_carrier_off(). They are not always called in pairs and they can > be called multiple times for the same event. The phylib will call them > when it notices the PHY saying the link is down/up, and the MAC driver > sometimes also calls them. We check the __LINK_STATE_NOCARRIER bit before changing these counters, so if we call netif_carrier_on() twice, the counter will be incrimented only by one, will it not? void netif_carrier_on(struct net_device *dev) if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) { atomic_inc(&dev->carrier_changes); ... void netif_carrier_off(struct net_device *dev) if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) { atomic_inc(&dev->carrier_changes); > > Andrew