* [PATCH net-next-2.6] slip: fix get_stats() method
@ 2010-08-18 13:13 Eric Dumazet
2010-08-19 7:17 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2010-08-18 13:13 UTC (permalink / raw)
To: David Miller; +Cc: netdev
Use integrated net_device_stats instead of a static one, and make sure
no transient values are feeded. ndo_get_stats() can be called by
concurrent cpus.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
drivers/net/slip.c | 50 +++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/drivers/net/slip.c b/drivers/net/slip.c
index fa434fb..d5a36f5 100644
--- a/drivers/net/slip.c
+++ b/drivers/net/slip.c
@@ -561,36 +561,36 @@ static int sl_change_mtu(struct net_device *dev, int new_mtu)
static struct net_device_stats *
sl_get_stats(struct net_device *dev)
{
- static struct net_device_stats stats;
+ struct net_device_stats *stats = &dev->stats;
struct slip *sl = netdev_priv(dev);
+ unsigned long c_rx_dropped = 0;
#ifdef SL_INCLUDE_CSLIP
- struct slcompress *comp;
-#endif
+ unsigned long c_rx_fifo_errors = 0;
+ unsigned long c_tx_fifo_errors = 0;
+ unsigned long c_collisions = 0;
+ struct slcompress *comp = sl->slcomp;
- memset(&stats, 0, sizeof(struct net_device_stats));
-
- stats.rx_packets = sl->rx_packets;
- stats.tx_packets = sl->tx_packets;
- stats.rx_bytes = sl->rx_bytes;
- stats.tx_bytes = sl->tx_bytes;
- stats.rx_dropped = sl->rx_dropped;
- stats.tx_dropped = sl->tx_dropped;
- stats.tx_errors = sl->tx_errors;
- stats.rx_errors = sl->rx_errors;
- stats.rx_over_errors = sl->rx_over_errors;
-#ifdef SL_INCLUDE_CSLIP
- stats.rx_fifo_errors = sl->rx_compressed;
- stats.tx_fifo_errors = sl->tx_compressed;
- stats.collisions = sl->tx_misses;
- comp = sl->slcomp;
if (comp) {
- stats.rx_fifo_errors += comp->sls_i_compressed;
- stats.rx_dropped += comp->sls_i_tossed;
- stats.tx_fifo_errors += comp->sls_o_compressed;
- stats.collisions += comp->sls_o_misses;
+ c_rx_fifo_errors = comp->sls_i_compressed;
+ c_rx_dropped = comp->sls_i_tossed;
+ c_tx_fifo_errors = comp->sls_o_compressed;
+ c_collisions = comp->sls_o_misses;
}
-#endif /* CONFIG_INET */
- return (&stats);
+ stats->rx_fifo_errors = sl->rx_compressed + c_rx_fifo_errors;
+ stats->tx_fifo_errors = sl->tx_compressed + c_tx_fifo_errors;
+ stats->collisions = sl->tx_misses + c_collisions;
+#endif
+
+ stats->rx_packets = sl->rx_packets;
+ stats->tx_packets = sl->tx_packets;
+ stats->rx_bytes = sl->rx_bytes;
+ stats->tx_bytes = sl->tx_bytes;
+ stats->rx_dropped = sl->rx_dropped + c_rx_dropped;
+ stats->tx_dropped = sl->tx_dropped;
+ stats->tx_errors = sl->tx_errors;
+ stats->rx_errors = sl->rx_errors;
+ stats->rx_over_errors = sl->rx_over_errors;
+ return stats;
}
/* Netdevice register callback */
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next-2.6] slip: fix get_stats() method
2010-08-18 13:13 [PATCH net-next-2.6] slip: fix get_stats() method Eric Dumazet
@ 2010-08-19 7:17 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2010-08-19 7:17 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Wed, 18 Aug 2010 15:13:08 +0200
> Use integrated net_device_stats instead of a static one, and make sure
> no transient values are feeded. ndo_get_stats() can be called by
> concurrent cpus.
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Applied, thanks Eric.
It's pretty freaky how, even to this day, we keep finding these static
function local variables in code which potentially runs multithreaded.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-08-19 7:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-18 13:13 [PATCH net-next-2.6] slip: fix get_stats() method Eric Dumazet
2010-08-19 7:17 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).