Skip to contentSkip to conversation

overflows in /proc/net/dev

PATCH Sebastian Claßen 5 participants 5 messages Aug 18, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi all...

in struct net_device_stats all members are defined as unsgined long. In time of gigabit ethernet this takes not long to overflow. Are there any plans to change these coutners to unsigned long long? I saw in ifconfig source code the byte and packet counters are already defined as unsigned long long.

I've tried the attached little patch which seems to work well. Are there any good reasons against this changes?

Signature · 10 lines
Mit freundlichen Grüßen / Yours sincerely

Sebastian Claßen, Postmaster
freenet.de AG, Willstätterstraße 13, D-40549 Düsseldorf
Phone: +49 (0) 211 / 53087-522
----------------------------------------------------------------------
Vorsitzender des Aufsichtsrates: Prof. Dr. Helmut Thoma
Vorstand: Eckhard Spoerr (Vors.), Axel Krieger,
          Stephan Esch, Eric Berger
Amtsgericht Hamburg HRB 74048
linux/netdevice.h renamed from linux/netdevice.h.orig +4 -4
@@ -107,10 +107,10 @@ struct netpoll;
  
 struct net_device_stats
 {
-	unsigned long rx_packets;		/* total packets received	*/
-	unsigned long tx_packets;		/* total packets transmitted	*/
-	unsigned long rx_bytes;		/* total bytes received 	*/
-	unsigned long tx_bytes;		/* total bytes transmitted	*/
+	unsigned long long rx_packets;		/* total packets received	*/
+	unsigned long long tx_packets;		/* total packets transmitted	*/
+	unsigned long long rx_bytes;		/* total bytes received 	*/
+	unsigned long long tx_bytes;		/* total bytes transmitted	*/
 	unsigned long rx_errors;		/* bad packets received		*/
 	unsigned long tx_errors;		/* packet transmit problems	*/
 	unsigned long rx_dropped;		/* no space in linux buffers	*/
core/dev.c renamed from core/dev.c.orig +2 -2
@@ -1984,8 +1984,8 @@ static void dev_seq_printf_stats(struct 
 	if (dev->get_stats) {
 		struct net_device_stats *stats = dev->get_stats(dev);
 
-		seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
-				"%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
+		seq_printf(seq, "%6s:%8llu %7llu %4lu %4lu %4lu %5lu %10lu %9lu "
+				"%8llu %7llu %4lu %4lu %4lu %5lu %7lu %10lu\n",
 			   dev->name, stats->rx_bytes, stats->rx_packets,
 			   stats->rx_errors,
 			   stats->rx_dropped + stats->rx_missed_errors,
#1 lore raw
Quoted 2 lines · Sebastian Cla?en

in struct net_device_stats all members are defined as unsgined long. In time of gigabit ethernet this takes not long to overflow.

It should still take an appreciable amount of time surely? We can detect those wraps in userspace and deal with it as needed.

Quoted 1 line

Are there any plans to change these coutners to unsigned long long?

It comes up from time to time (see below).

Quoted 2 lines

I saw in ifconfig source code the byte and packet counters are already defined as unsigned long long.

ifconfig is userspace.

[...]

linux/netdevice.h struct netpoll; · line 113

Quoted 10 lines

struct net_device_stats
{

linux/netdevice.h renamed from linux/netdevice.h.orig +4 -4
-	unsigned long rx_packets;		/* total packets received	*/
-	unsigned long tx_packets;		/* total packets transmitted	*/
-	unsigned long rx_bytes;		/* total bytes received 	*/
-	unsigned long tx_bytes;		/* total bytes transmitted	*/
+	unsigned long long rx_packets;		/* total packets received	*/
+	unsigned long long tx_packets;		/* total packets transmitted	*/
+	unsigned long long rx_bytes;		/* total bytes received 	*/
+	unsigned long long tx_bytes;		/* total bytes transmitted	*/

I thought the concensurs here was that because doing reliable atomic updates of 64-bit values isn't possible on some (most?) 32-bit architectures so we need additional locking to make this work which is undesirable? (It might even be a FAQ by now as this comes up fairly often).

#2 lore raw
Quoted 4 lines · Chris Wedgwood
Quoted 2 lines · Sebastian Cla?en

in struct net_device_stats all members are defined as unsgined long. In time of gigabit ethernet this takes not long to overflow.

It should still take an appreciable amount of time surely? We can

With 100MBit it took about 5 minutes to overflow the 32bit byte counters (too less for typical mrtg and Nyquist-Shannon sampling theorem in mind), with 1GBit it takes about 30 seconds.
If you consider this appreciable... well :)

Quoted 1 line

detect those wraps in userspace and deal with it as needed.

Of course, it's usually enough time for a typical userspace application to get scheduled at least twice.

regards
Mario

Signature · 1 line
User sind wie ideale Gase - sie verteilen sich gleichmaessig ueber alle Platten
maintainer
#3 lore raw
In reply to Chris Wedgwood

From: Chris Wedgwood <[email protected]>
Date: Thu, 18 Aug 2005 09:33:58 -0700

Quoted 5 lines

I thought the concensurs here was that because doing reliable atomic updates of 64-bit values isn't possible on some (most?) 32-bit architectures so we need additional locking to make this work which is undesirable? (It might even be a FAQ by now as this comes up fairly often).

That's correct.

#4 lore raw
Quoted 10 lines · On Thu, 18 Aug 2005 14:32:48 -0700 (PDT) "David S. Miller"…

From: Chris Wedgwood <[email protected]>
Date: Thu, 18 Aug 2005 09:33:58 -0700

Quoted 5 lines

I thought the concensurs here was that because doing reliable atomic updates of 64-bit values isn't possible on some (most?) 32-bit architectures so we need additional locking to make this work which is undesirable? (It might even be a FAQ by now as this comes up fairly often).

That's correct.

Also width of fields in /proc/net/dev can't change without potentially breaking ABI of applications.