Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3928757
  • 博文数量: 93
  • 博客积分: 3189
  • 博客等级: 中校
  • 技术积分: 4229
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-02 13:29
个人简介

出没于杭州和青岛的程序猿一枚,对内核略懂一二

文章分类

全部博文(93)

文章存档

2016年(2)

2015年(3)

2014年(11)

2013年(29)

2012年(16)

2011年(5)

2010年(5)

2009年(22)

分类: LINUX

2014-10-17 13:23:25

版权所有,转载请注明出处http://forever.blog.chinaunix.net.
最近有开发人员反映dstat输出的网卡信息,存在连续几秒(多的达到20秒)带宽为零的情况,但是开发人员反馈可以在目标机器上抓取到发送出去的数据包。
1. dstat带宽输出为0的原因?
    分析dstat的源码,dstat通过读取/proc/net/dev的数据来计算网络带宽。那么带宽为0,说明/proc/net/dev数据没有更新。
2. /proc/net/dev数据更新不及时的原因?
    分析kernel代码,/proc/net/dev数据的更新通过调用驱动中的ndo_get_stats64()方法获取网卡的统计信息。
3. 网卡统计信息更新不及时的原因?
       David S.Miller的解释:
It's a tradeoff between excess DMA traffic updating the statistics,
and having them updated more frequently.
Actually, the thing that matters is when ->get_stats() is called.
So if a driver can trigger a statistics DMA update at ->get_stats()
time, that's probably what it should do. But this could get
expensive and make the "do DMA less often" optimization less useful.
    也就是说网卡统计信息,考虑到不能过度的频繁更新DMA数据。
4. 以Intel网卡igb驱动为例,每两秒更新一次,或者通过ethtool命令强制更新。
    Previously, igb stats were updated :
        - By watchdog timer, every 2 secs
        - Every time an "ethtool -S ethX" was done

    There is no general guarantee netdev stats are immediately available to 
    user.
    ndo_get_stats() is not allowed to sleep, (because of bonding...), so
    drivers can not always provide accurate stats, if they need to make a
    long transaction with hardware.

    Other drivers do the same (provide hardware statistics), with about one
    second resolution.

    So the "resulted in false observations from userspace." is something
    that might upset admins, but is not a hard requirement of netdev stats.
5. 为了解决这个问题,引入了在读取时更新的机制,该机制只是增加了增加了准确性,但仍然不能保证绝对实时。
This patch also increase the accuracy of stats in /proc/net/dev, by
 updating the adapter stats when reading /proc/net/dev.  Previously
 the stats were only updated by the watchdog timer every 2 sec, which
 resulted in false observations from userspace.


点击(此处)折叠或打开

  1. diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c
  2. index 55edcb7..6cec297 100644
  3. --- a/drivers/net/igb/igb_main.c
  4. +++ b/drivers/net/igb/igb_main.c
  5. @@ -4218,11 +4218,17 @@ static void igb_reset_task(struct work_struct *work)
  6.   * @netdev: network interface device structure
  7.   *
  8.   * Returns the address of the device statistics structure.
  9. - * The statistics are actually updated from the timer callback.
  10. + * The statistics are also updated from the timer callback
  11. + * igb_watchdog_task().
  12.   **/
  13.  static struct net_device_stats *igb_get_stats(struct net_device *netdev)
  14.  {
  15. -    /* only return the current stats */
  16. +    struct igb_adapter *adapter = netdev_priv(netdev);
  17. +
  18. +    /* update stats */
  19. +    igb_update_stats(adapter);
  20. +
  21. +    /* return the current stats */
  22.      return &netdev->stats;
  23.  }
  24.  
  25. @@ -4307,7 +4313,7 @@ static int igb_change_mtu(struct net_device *netdev, int new_mtu)
  26.  
  27.  void igb_update_stats(struct igb_adapter *adapter)
  28.  {
  29. -    struct net_device_stats *net_stats = igb_get_stats(adapter->netdev);
  30. +    struct net_device_stats *net_stats = &adapter->netdev->stats;
  31.      struct e1000_hw *hw = &adapter->hw;
  32.      struct pci_dev *pdev = adapter->pdev;
  33.      u32 reg, mpc;


    
阅读(9238) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~