Skip to contentSkip to conversation

64 bit byte counter for 2.6.3

NET Markus Hästbacka 8 participants 12 messages Feb 18, 2004 – Feb 23, 2004

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

Ok, Here's a patch for 64 bit byte counters for 2.6.3. For any intrested users to try.

That means in english that the limit for RX bytes and TX bytes (in ifconfig for example) is much higher than the old 4GB limit on 32 bit systems.

Orginal patch by Miika Pekkarinen, ported forward from 2.5 by me.

Patch says 2.6.3-rc1, but patches cleanly on 2.6.3.

Markus

net/core/dev.c +2 -2
@@ -2042,8 +2042,8 @@
 	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:%14llu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
+				"%14llu %7lu %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,
include/linux/netdevice.h +2 -2
@@ -103,8 +103,8 @@
 {
 	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_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	*/
#1 lore raw
Quoted 7 lines · On Wed, 18 Feb 2004 18:51:19 +0200 Markus Hästbacka <[email protected]> wrote:

Ok, Here's a patch for 64 bit byte counters for 2.6.3. For any intrested users to try.

That means in english that the limit for RX bytes and TX bytes (in ifconfig for example) is much higher than the old 4GB limit on 32 bit systems.

Quoted 5 lines

Orginal patch by Miika Pekkarinen, ported forward from 2.5 by me.

Patch says 2.6.3-rc1, but patches cleanly on 2.6.3.

Markus

Some quick comments:
* Network changes gets discussed on [email protected]
* 64 bit values are not atomic on 32 bit architectures
* wider values in /proc output risks breaking apps like ifconfig and netstat

#2 lore raw
Quoted 2 lines · Markus Hästbacka

Ok, Here's a patch for 64 bit byte counters for 2.6.3. For any intrested users to try.

Manipulation of a 'long long' is not atomic in 32 bit architectures. Please explain how we don't care, if we shouldn't care. Also some /proc entries might get read incorrectly with existing tools.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an Pentium III machine (1797.90 BogoMips).
Note 96.31% of all statistics are fiction.

#3 lore raw
Quoted 3 lines · Richard B. Johnson

Manipulation of a 'long long' is not atomic in 32 bit architectures. Please explain how we don't care, if we shouldn't care. Also some /proc entries might get read incorrectly with existing tools.

Please, tell me all the tools, I'll test them. ifconfig and netstat works correctly atleast.

And about the caring, is rx/tx bytes so important that they can't use long long? I would care to see more than 4GB, and maybe some error in the counter at some point (Have you _ever_ seen that happen?) than only 4GB.

And no, I didn't post this to be merged into the mainline kernel, just to let users know that there maybe is an option for seeing maximum 4GB.

This has been working for me since, umm.. let's say 2.4.20. All the tools I've needed have worked.

Markus

#4 lore raw
Quoted 7 lines · On Wed, 18 Feb 2004, Markus [ISO-8859-1] H�stbacka wrote:
Quoted 3 lines · Richard B. Johnson

Manipulation of a 'long long' is not atomic in 32 bit architectures. Please explain how we don't care, if we shouldn't care. Also some /proc entries might get read incorrectly with existing tools.

Please, tell me all the tools, I'll test them. ifconfig and netstat works correctly atleast.

Hum, they will work when they see 2^64 written in ASCII in /proc/net/dev ? I doubt that. Have you ever even seen 64-bit ASCII?

The largest unsigned long long will be 18446744073709551615. If it's read with 32-bit tools (sscanf), it will read 4294967295.

Quoted 5 lines

And about the caring, is rx/tx bytes so important that they can't use long long? I would care to see more than 4GB, and maybe some error in the counter at some point (Have you _ever_ seen that happen?) than only 4GB.

The 32-bit wrap is a serious problem. It can't be ignored. The writing of any multiple-part variable in the kernel can be interrupted at any time. Interrupting half-written variables can have dire consequences. Let's pretend that gcc knows how to write a long-long with minimum overhead..... high word is in edx and the low word is in eax. The memory variable is addressed by ebx....

		addl	%eax, (%ebx)		# Sum low word
		adcl	%edx, 0x04(%ebx)	# Sum CY and high

Now, get interrupted...

		addl	%eax, (%ebx)		# Sum low word
		->>> interrupt <<<--

                Do some code that adds more stuff to
		the variable....

		Return to the interrupted code.

		adcl	%edx, 0x04(%ebx)	# Sum CY and high

The memory variable is now wrong. If it's an event counter, maybe it doesn't make any difference. That's what needs to be addressed. You can't just dismiss it. Any time you write code that knowingly results in the wrong results, its impact needs to be fully understood.

Changing a bunch of variables in a 32-bit machine to 64-bit ones is a major change, regardless of how trivial it may seem.

You need to make a spin-locked thingy for every variable you want to manipulate if the result needs to be correct.

Quoted 5 lines

And no, I didn't post this to be merged into the mainline kernel, just to let users know that there maybe is an option for seeing maximum 4GB.

This has been working for me since, umm.. let's say 2.4.20. All the tools I've needed have worked.

Just wait until your packet count is 4294967296. It will likely read 0. When 4294967297, may read 1. That's off by quite a bit.

Quoted 3 lines

Markus

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an Intel Pentium III machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.

#5 lore raw
Quoted 65 lines · On Wed, 18 Feb 2004 17:45:16 -0500 (EST) "Richard B. Johnson"…
Quoted 7 lines · On Wed, 18 Feb 2004, Markus [ISO-8859-1] Hästbacka wrote:
Quoted 3 lines · Richard B. Johnson

Manipulation of a 'long long' is not atomic in 32 bit architectures. Please explain how we don't care, if we shouldn't care. Also some /proc entries might get read incorrectly with existing tools.

Please, tell me all the tools, I'll test them. ifconfig and netstat works correctly atleast.

Hum, they will work when they see 2^64 written in ASCII in /proc/net/dev ? I doubt that. Have you ever even seen 64-bit ASCII?

The largest unsigned long long will be 18446744073709551615. If it's read with 32-bit tools (sscanf), it will read 4294967295.

Quoted 5 lines

And about the caring, is rx/tx bytes so important that they can't use long long? I would care to see more than 4GB, and maybe some error in the counter at some point (Have you _ever_ seen that happen?) than only 4GB.

The 32-bit wrap is a serious problem. It can't be ignored. The writing of any multiple-part variable in the kernel can be interrupted at any time. Interrupting half-written variables can have dire consequences. Let's pretend that gcc knows how to write a long-long with minimum overhead..... high word is in edx and the low word is in eax. The memory variable is addressed by ebx....

		addl	%eax, (%ebx)		# Sum low word
		adcl	%edx, 0x04(%ebx)	# Sum CY and high

Now, get interrupted...

		addl	%eax, (%ebx)		# Sum low word
		->>> interrupt <<<--

                Do some code that adds more stuff to
		the variable....

		Return to the interrupted code.

		adcl	%edx, 0x04(%ebx)	# Sum CY and high

The memory variable is now wrong. If it's an event counter, maybe it doesn't make any difference. That's what needs to be addressed. You can't just dismiss it. Any time you write code that knowingly results in the wrong results, its impact needs to be fully understood.

Changing a bunch of variables in a 32-bit machine to 64-bit ones is a major change, regardless of how trivial it may seem.

You need to make a spin-locked thingy for every variable you want to manipulate if the result needs to be correct.

Quoted 5 lines

And no, I didn't post this to be merged into the mainline kernel, just to let users know that there maybe is an option for seeing maximum 4GB.

This has been working for me since, umm.. let's say 2.4.20. All the tools I've needed have worked.

Just wait until your packet count is 4294967296. It will likely read 0. When 4294967297, may read 1. That's off by quite a bit.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Markus

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an Intel Pentium III machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.

Do it right:
* use per-cpu long long for both bytes and packet counts
and change each driver ...
* expose both a new 64 bit and legacy 32 bit /proc interface
* no tools use /sys yet, so that needs to show long long
* have both a get_stats and get_stats64 hook in netdevice so not all drivers have to be converted at once.

#6 lore raw
Quoted 7 lines · Stephen Hemminger

Do it right:
* use per-cpu long long for both bytes and packet counts
and change each driver ...
* expose both a new 64 bit and legacy 32 bit /proc interface
* no tools use /sys yet, so that needs to show long long
* have both a get_stats and get_stats64 hook in netdevice so not all drivers have to be converted at once.

Yep.

Jeff

#7 lore raw
In reply to Stephen Hemminger

SH> * Network changes gets discussed on [email protected] SH> * 64 bit values are not atomic on 32 bit architectures

Agree.

SH> * wider values in /proc output risks breaking apps like ifconfig and netstat

This is probably not a problem here, ifconfig etc have been working fine with non-wrapping numbers on sparc64 and other 64-bit machines.

Signature · 1 line
Meelis Roos
#8 lore raw
Quoted 9 lines · On Thu, 19 Feb 2004 10:14:55 +0200 Meelis Roos <[email protected]> wrote:

SH> * Network changes gets discussed on [email protected] SH> * 64 bit values are not atomic on 32 bit architectures

Agree.

SH> * wider values in /proc output risks breaking apps like ifconfig and netstat

This is probably not a problem here, ifconfig etc have been working fine with non-wrapping numbers on sparc64 and other 64-bit machines.

Looking at current net-tools source, they are doing sscanf into a long-long-unsigned value already.

#9 lore raw
In reply to Markus Hästbacka

Hi!

Quoted 16 lines
net/core/dev.c +2 -2
@@ -2042,8 +2042,8 @@
 	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:%14llu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
+				"%14llu %7lu %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,

include/linux/netdevice.h line 107

Quoted 7 lines
include/linux/netdevice.h +2 -2
@@ -103,8 +103,8 @@
 {
 	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_bytes;		/* total bytes received 	*/
+	unsigned long long tx_bytes;		/* total bytes transmitted	*/

Perhaps this should be u64? I'm not sure if long long is not 128-bits on x86-64.
Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#10 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 21 lines · Pavel Machek

Hi!

Quoted 19 lines
net/core/dev.c +2 -3
@@ -2042,8 +2042,8 @@
 	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:%14llu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
+				"%14llu %7lu %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,
--- linux-2.6.3-rc1/include/linux/netdevice.h	2004-02-08

01:05:47.000000000 +0200 +++
linux-2.6.3-rc1-b/include/linux/netdevice.h 2004-02-07 15:21:26.000000000
+0200 @@ -103,8 +103,8 @@
{
unsigned long rx_packets; /* total packets received */

Quoted 8 lines

net/core/dev.c

Quoted 5 lines
net/core/dev.c +2 -2
 	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_bytes;		/* total bytes received 	*/
+	unsigned long long tx_bytes;		/* total bytes transmitted	*/

Perhaps this should be u64? I'm not sure if long long is not 128-bits on x86-64.

Hmm...I've been told that u_int64_t is the C99 (IIRC) standard, and that it should be used in favor of u64. Is that so?

I'll announce my version of 64-bit net stats fairly soon.

Jeff.

- --
We have joy, we have fun, we have Linux on a Sun... -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAOeVHwFP0+seVj/4RAv1gAKCFZZEHOi78wcrX2dWquQ4Qcth4AQCgicO0 L+vkeXdghp0YPWzgLInBpU8=
=F5rS
-----END PGP SIGNATURE-----

#11 lore raw
Quoted 1 line · Jeff Sipek

Hmm...I've been told that u_int64_t is the C99 (IIRC) standard

In C99 it's spelt uint64_t.

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."