• Qiao Ma's avatar
    net: hinic: fix bug that ethtool get wrong stats · 67dffd3d
    Qiao Ma authored
    Function hinic_get_stats64() will do two operations:
    1. reads stats from every hinic_rxq/txq and accumulates them
    2. calls hinic_rxq/txq_clean_stats() to clean every rxq/txq's stats
    
    For hinic_get_stats64(), it could get right data, because it sums all
    data to nic_dev->rx_stats/tx_stats.
    But it is wrong for get_drv_queue_stats(), this function will read
    hinic_rxq's stats, which have been cleared to zero by hinic_get_stats64().
    
    I have observed hinic's cleanup operation by using such command:
    > watch -n 1 "cat ethtool -S eth4 | tail -40"
    
    Result before:
         ...
         rxq7_pkts: 1
         rxq7_bytes: 90
         rxq7_errors: 0
         rxq7_csum_errors: 0
         rxq7_other_errors: 0
         ...
         rxq9_pkts: 11
         rxq9_bytes: 726
         rxq9_errors: 0
         rxq9_csum_errors: 0
         rxq9_other_errors: 0
         ...
         rxq11_pkts: 0
         rxq11_bytes: 0
         rxq11_errors: 0
         rxq11_csum_errors: 0
         rxq11_other_errors: 0
    
    Result after a few seconds:
         ...
         rxq7_pkts: 0
         rxq7_bytes: 0
         rxq7_errors: 0
         rxq7_csum_errors: 0
         rxq7_other_errors: 0
         ...
         rxq9_pkts: 2
         rxq9_bytes: 132
         rxq9_errors: 0
         rxq9_csum_errors: 0
         rxq9_other_errors: 0
         ...
         rxq11_pkts: 1
         rxq11_bytes: 170
         rxq11_errors: 0
         rxq11_csum_errors: 0
         rxq11_other_errors: 0
    
    To solve this problem, we just keep every queue's total stats in their own
    queue (aka hinic_{rxq|txq}), and simply sum all per-queue stats every time
    calling hinic_get_stats64().
    With that solution, there is no need to clean per-queue stats now,
    and there is no need to maintain global hinic_dev.{tx|rx}_stats, too.
    
    Fixes: edd384f6 ("net-next/hinic: Add ethtool and stats")
    Signed-off-by: default avatarQiao Ma <mqaio@linux.alibaba.com>
    Reported-by: default avatarkernel test robot <lkp@intel.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    67dffd3d
hinic_dev.h 2.66 KB