• Petr Machata's avatar
    net: dev: Add hardware stats support · 9309f97a
    Petr Machata authored
    Offloading switch device drivers may be able to collect statistics of the
    traffic taking place in the HW datapath that pertains to a certain soft
    netdevice, such as VLAN. Add the necessary infrastructure to allow exposing
    these statistics to the offloaded netdevice in question. The API was shaped
    by the following considerations:
    
    - Collection of HW statistics is not free: there may be a finite number of
      counters, and the act of counting may have a performance impact. It is
      therefore necessary to allow toggling whether HW counting should be done
      for any particular SW netdevice.
    
    - As the drivers are loaded and removed, a particular device may get
      offloaded and unoffloaded again. At the same time, the statistics values
      need to stay monotonic (modulo the eventual 64-bit wraparound),
      increasing only to reflect traffic measured in the device.
    
      To that end, the netdevice keeps around a lazily-allocated copy of struct
      rtnl_link_stats64. Device drivers then contribute to the values kept
      therein at various points. Even as the driver goes away, the struct stays
      around to maintain the statistics values.
    
    - Different HW devices may be able to count different things. The
      motivation behind this patch in particular is exposure of HW counters on
      Nvidia Spectrum switches, where the only practical approach to counting
      traffic on offloaded soft netdevices currently is to use router interface
      counters, and count L3 traffic. Correspondingly that is the statistics
      suite added in this patch.
    
      Other devices may be able to measure different kinds of traffic, and for
      that reason, the APIs are built to allow uniform access to different
      statistics suites.
    
    - Because soft netdevices and offloading drivers are only loosely bound, a
      netdevice uses a notifier chain to communicate with the drivers. Several
      new notifiers, NETDEV_OFFLOAD_XSTATS_*, have been added to carry messages
      to the offloading drivers.
    
    - Devices can have various conditions for when a particular counter is
      available. As the device is configured and reconfigured, the device
      offload may become or cease being suitable for counter binding. A
      netdevice can use a notifier type NETDEV_OFFLOAD_XSTATS_REPORT_USED to
      ping offloading drivers and determine whether anyone currently implements
      a given statistics suite. This information can then be propagated to user
      space.
    
      When the driver decides to unoffload a netdevice, it can use a
      newly-added function, netdev_offload_xstats_report_delta(), to record
      outstanding collected statistics, before destroying the HW counter.
    
    This patch adds a helper, call_netdevice_notifiers_info_robust(), for
    dispatching a notifier with the possibility of unwind when one of the
    consumers bails. Given the wish to eventually get rid of the global
    notifier block altogether, this helper only invokes the per-netns notifier
    block.
    Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
    Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    9309f97a
dev.c 282 KB