diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2009-11-15 22:36:51 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-11-18 02:51:52 -0500 |
commit | d83345adf96bc13a5e360f4649a2e68ef968dec0 (patch) | |
tree | 015fe31fde6b5ea6abc6ebb75aa446fa63fcbb79 /net | |
parent | b038b0401f9697ee1d7df40021b96e7de0564938 (diff) |
net: add dev_txq_stats_fold() helper
Some drivers ndo_get_stats() method need to perform txqueue stats folding.
Move folding from dev_get_stats() to a new dev_txq_stats_fold() function
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/core/dev.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index d867522290b9..c3e0578d29d1 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -5169,6 +5169,32 @@ void netdev_run_todo(void) | |||
5169 | } | 5169 | } |
5170 | 5170 | ||
5171 | /** | 5171 | /** |
5172 | * dev_txq_stats_fold - fold tx_queues stats | ||
5173 | * @dev: device to get statistics from | ||
5174 | * @stats: struct net_device_stats to hold results | ||
5175 | */ | ||
5176 | void dev_txq_stats_fold(const struct net_device *dev, | ||
5177 | struct net_device_stats *stats) | ||
5178 | { | ||
5179 | unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0; | ||
5180 | unsigned int i; | ||
5181 | struct netdev_queue *txq; | ||
5182 | |||
5183 | for (i = 0; i < dev->num_tx_queues; i++) { | ||
5184 | txq = netdev_get_tx_queue(dev, i); | ||
5185 | tx_bytes += txq->tx_bytes; | ||
5186 | tx_packets += txq->tx_packets; | ||
5187 | tx_dropped += txq->tx_dropped; | ||
5188 | } | ||
5189 | if (tx_bytes || tx_packets || tx_dropped) { | ||
5190 | stats->tx_bytes = tx_bytes; | ||
5191 | stats->tx_packets = tx_packets; | ||
5192 | stats->tx_dropped = tx_dropped; | ||
5193 | } | ||
5194 | } | ||
5195 | EXPORT_SYMBOL(dev_txq_stats_fold); | ||
5196 | |||
5197 | /** | ||
5172 | * dev_get_stats - get network device statistics | 5198 | * dev_get_stats - get network device statistics |
5173 | * @dev: device to get statistics from | 5199 | * @dev: device to get statistics from |
5174 | * | 5200 | * |
@@ -5182,25 +5208,9 @@ const struct net_device_stats *dev_get_stats(struct net_device *dev) | |||
5182 | 5208 | ||
5183 | if (ops->ndo_get_stats) | 5209 | if (ops->ndo_get_stats) |
5184 | return ops->ndo_get_stats(dev); | 5210 | return ops->ndo_get_stats(dev); |
5185 | else { | 5211 | |
5186 | unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0; | 5212 | dev_txq_stats_fold(dev, &dev->stats); |
5187 | struct net_device_stats *stats = &dev->stats; | 5213 | return &dev->stats; |
5188 | unsigned int i; | ||
5189 | struct netdev_queue *txq; | ||
5190 | |||
5191 | for (i = 0; i < dev->num_tx_queues; i++) { | ||
5192 | txq = netdev_get_tx_queue(dev, i); | ||
5193 | tx_bytes += txq->tx_bytes; | ||
5194 | tx_packets += txq->tx_packets; | ||
5195 | tx_dropped += txq->tx_dropped; | ||
5196 | } | ||
5197 | if (tx_bytes || tx_packets || tx_dropped) { | ||
5198 | stats->tx_bytes = tx_bytes; | ||
5199 | stats->tx_packets = tx_packets; | ||
5200 | stats->tx_dropped = tx_dropped; | ||
5201 | } | ||
5202 | return stats; | ||
5203 | } | ||
5204 | } | 5214 | } |
5205 | EXPORT_SYMBOL(dev_get_stats); | 5215 | EXPORT_SYMBOL(dev_get_stats); |
5206 | 5216 | ||