diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2009-11-18 02:09:39 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-11-19 16:16:22 -0500 |
commit | 2b1c8b0f925c3f5943cf95d263d72927baae88e7 (patch) | |
tree | 956b46cc040504a0545065184e322ff596ef5d16 /drivers/net/veth.c | |
parent | 56cf54831fd1be105e89a9df899e3b22442da180 (diff) |
veth: Fix veth_get_stats()
veth_get_stats() can be called in parallel on several cpus.
It's better to not reset dev->stats as it could give wrong result on
one cpu. Use temporary variables, then store the final results.
Also, we should loop on every possible cpus, not only online cpus,
or cpu hotplug can suddenly give wrong veth stats.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/veth.c')
-rw-r--r-- | drivers/net/veth.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/drivers/net/veth.c b/drivers/net/veth.c index ade5b344f75d..52af5017c46b 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c | |||
@@ -210,32 +210,29 @@ rx_drop: | |||
210 | static struct net_device_stats *veth_get_stats(struct net_device *dev) | 210 | static struct net_device_stats *veth_get_stats(struct net_device *dev) |
211 | { | 211 | { |
212 | struct veth_priv *priv; | 212 | struct veth_priv *priv; |
213 | struct net_device_stats *dev_stats; | ||
214 | int cpu; | 213 | int cpu; |
215 | struct veth_net_stats *stats; | 214 | struct veth_net_stats *stats, total = {0}; |
216 | 215 | ||
217 | priv = netdev_priv(dev); | 216 | priv = netdev_priv(dev); |
218 | dev_stats = &dev->stats; | ||
219 | |||
220 | dev_stats->rx_packets = 0; | ||
221 | dev_stats->tx_packets = 0; | ||
222 | dev_stats->rx_bytes = 0; | ||
223 | dev_stats->tx_bytes = 0; | ||
224 | dev_stats->tx_dropped = 0; | ||
225 | dev_stats->rx_dropped = 0; | ||
226 | 217 | ||
227 | for_each_online_cpu(cpu) { | 218 | for_each_possible_cpu(cpu) { |
228 | stats = per_cpu_ptr(priv->stats, cpu); | 219 | stats = per_cpu_ptr(priv->stats, cpu); |
229 | 220 | ||
230 | dev_stats->rx_packets += stats->rx_packets; | 221 | total.rx_packets += stats->rx_packets; |
231 | dev_stats->tx_packets += stats->tx_packets; | 222 | total.tx_packets += stats->tx_packets; |
232 | dev_stats->rx_bytes += stats->rx_bytes; | 223 | total.rx_bytes += stats->rx_bytes; |
233 | dev_stats->tx_bytes += stats->tx_bytes; | 224 | total.tx_bytes += stats->tx_bytes; |
234 | dev_stats->tx_dropped += stats->tx_dropped; | 225 | total.tx_dropped += stats->tx_dropped; |
235 | dev_stats->rx_dropped += stats->rx_dropped; | 226 | total.rx_dropped += stats->rx_dropped; |
236 | } | 227 | } |
237 | 228 | dev->stats.rx_packets = total.rx_packets; | |
238 | return dev_stats; | 229 | dev->stats.tx_packets = total.tx_packets; |
230 | dev->stats.rx_bytes = total.rx_bytes; | ||
231 | dev->stats.tx_bytes = total.tx_bytes; | ||
232 | dev->stats.tx_dropped = total.tx_dropped; | ||
233 | dev->stats.rx_dropped = total.rx_dropped; | ||
234 | |||
235 | return &dev->stats; | ||
239 | } | 236 | } |
240 | 237 | ||
241 | static int veth_open(struct net_device *dev) | 238 | static int veth_open(struct net_device *dev) |