提交 d83345ad 编写于 作者: E Eric Dumazet 提交者: David S. Miller

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: NEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 b038b040
...@@ -1941,6 +1941,7 @@ extern void netdev_features_change(struct net_device *dev); ...@@ -1941,6 +1941,7 @@ extern void netdev_features_change(struct net_device *dev);
extern void dev_load(struct net *net, const char *name); extern void dev_load(struct net *net, const char *name);
extern void dev_mcast_init(void); extern void dev_mcast_init(void);
extern const struct net_device_stats *dev_get_stats(struct net_device *dev); extern const struct net_device_stats *dev_get_stats(struct net_device *dev);
extern void dev_txq_stats_fold(const struct net_device *dev, struct net_device_stats *stats);
extern int netdev_max_backlog; extern int netdev_max_backlog;
extern int weight_p; extern int weight_p;
......
...@@ -5168,6 +5168,32 @@ void netdev_run_todo(void) ...@@ -5168,6 +5168,32 @@ void netdev_run_todo(void)
} }
} }
/**
* dev_txq_stats_fold - fold tx_queues stats
* @dev: device to get statistics from
* @stats: struct net_device_stats to hold results
*/
void dev_txq_stats_fold(const struct net_device *dev,
struct net_device_stats *stats)
{
unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0;
unsigned int i;
struct netdev_queue *txq;
for (i = 0; i < dev->num_tx_queues; i++) {
txq = netdev_get_tx_queue(dev, i);
tx_bytes += txq->tx_bytes;
tx_packets += txq->tx_packets;
tx_dropped += txq->tx_dropped;
}
if (tx_bytes || tx_packets || tx_dropped) {
stats->tx_bytes = tx_bytes;
stats->tx_packets = tx_packets;
stats->tx_dropped = tx_dropped;
}
}
EXPORT_SYMBOL(dev_txq_stats_fold);
/** /**
* dev_get_stats - get network device statistics * dev_get_stats - get network device statistics
* @dev: device to get statistics from * @dev: device to get statistics from
...@@ -5182,25 +5208,9 @@ const struct net_device_stats *dev_get_stats(struct net_device *dev) ...@@ -5182,25 +5208,9 @@ const struct net_device_stats *dev_get_stats(struct net_device *dev)
if (ops->ndo_get_stats) if (ops->ndo_get_stats)
return ops->ndo_get_stats(dev); return ops->ndo_get_stats(dev);
else {
unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0; dev_txq_stats_fold(dev, &dev->stats);
struct net_device_stats *stats = &dev->stats; return &dev->stats;
unsigned int i;
struct netdev_queue *txq;
for (i = 0; i < dev->num_tx_queues; i++) {
txq = netdev_get_tx_queue(dev, i);
tx_bytes += txq->tx_bytes;
tx_packets += txq->tx_packets;
tx_dropped += txq->tx_dropped;
}
if (tx_bytes || tx_packets || tx_dropped) {
stats->tx_bytes = tx_bytes;
stats->tx_packets = tx_packets;
stats->tx_dropped = tx_dropped;
}
return stats;
}
} }
EXPORT_SYMBOL(dev_get_stats); EXPORT_SYMBOL(dev_get_stats);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册