public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [NET] 64 bit byte counter for 2.6.3
@ 2004-02-18 16:51 Markus Hästbacka
  2004-02-18 18:17 ` Stephen Hemminger
  2004-02-22 17:36 ` Pavel Machek
  0 siblings, 2 replies; 12+ messages in thread
From: Markus Hästbacka @ 2004-02-18 16:51 UTC (permalink / raw)
  To: Kernel Mailinglist

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

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

[-- Attachment #2: rm-ifconfig-reset-2.6.3-rc1 --]
[-- Type: text/plain, Size: 1338 bytes --]

--- linux-2.6.3-rc1/net/core/dev.c	2004-02-08 01:07:55.000000000 +0200
+++ linux-2.6.3-rc1-b/net/core/dev.c	2004-02-07 15:29:32.000000000 +0200
@@ -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	*/
 	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	*/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-18 16:51 [NET] 64 bit byte counter for 2.6.3 Markus Hästbacka
@ 2004-02-18 18:17 ` Stephen Hemminger
  2004-02-18 20:32   ` Richard B. Johnson
  2004-02-19  8:14   ` Meelis Roos
  2004-02-22 17:36 ` Pavel Machek
  1 sibling, 2 replies; 12+ messages in thread
From: Stephen Hemminger @ 2004-02-18 18:17 UTC (permalink / raw)
  To: Markus Hästbacka; +Cc: linux-kernel, netdev

On Wed, 18 Feb 2004 18:51:19 +0200
Markus Hästbacka <midian@ihme.org> 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.
> 
> 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 netdev@oss.sgi.com 
 * 64 bit values are not atomic on 32 bit architectures 
 * wider values in /proc output risks breaking apps like ifconfig and netstat

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-18 18:17 ` Stephen Hemminger
@ 2004-02-18 20:32   ` Richard B. Johnson
  2004-02-18 20:43     ` Markus Hästbacka
  2004-02-19  8:14   ` Meelis Roos
  1 sibling, 1 reply; 12+ messages in thread
From: Richard B. Johnson @ 2004-02-18 20:32 UTC (permalink / raw)
  To: Markus H�stbacka; +Cc: Linux kernel


Markus Hästbacka <midian@ihme.org> wrote:
> 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.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-18 20:32   ` Richard B. Johnson
@ 2004-02-18 20:43     ` Markus Hästbacka
  2004-02-18 22:45       ` Richard B. Johnson
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Hästbacka @ 2004-02-18 20:43 UTC (permalink / raw)
  To: root; +Cc: Kernel Mailinglist, netdev

On Wed, 2004-02-18 at 22:32, Richard B. Johnson wrote:
> 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-18 20:43     ` Markus Hästbacka
@ 2004-02-18 22:45       ` Richard B. Johnson
  2004-02-18 22:57         ` Stephen Hemminger
  0 siblings, 1 reply; 12+ messages in thread
From: Richard B. Johnson @ 2004-02-18 22:45 UTC (permalink / raw)
  To: Markus Hästbacka; +Cc: Kernel Mailinglist, netdev

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset=X-UNKNOWN, Size: 2685 bytes --]

On Wed, 18 Feb 2004, Markus [ISO-8859-1] Hästbacka wrote:

> On Wed, 2004-02-18 at 22:32, Richard B. Johnson wrote:
> > 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.

> 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.

> 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.

>
>         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.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-18 22:45       ` Richard B. Johnson
@ 2004-02-18 22:57         ` Stephen Hemminger
  2004-02-18 23:17           ` Jeff Garzik
  0 siblings, 1 reply; 12+ messages in thread
From: Stephen Hemminger @ 2004-02-18 22:57 UTC (permalink / raw)
  To: root; +Cc: Markus Hästbacka, Kernel Mailinglist, netdev

On Wed, 18 Feb 2004 17:45:16 -0500 (EST)
"Richard B. Johnson" <root@chaos.analogic.com> wrote:

> On Wed, 18 Feb 2004, Markus [ISO-8859-1] Hästbacka wrote:
> 
> > On Wed, 2004-02-18 at 22:32, Richard B. Johnson wrote:
> > > 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.
> 
> > 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.
> 
> > 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.
> 
> >
> >         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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-18 22:57         ` Stephen Hemminger
@ 2004-02-18 23:17           ` Jeff Garzik
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Garzik @ 2004-02-18 23:17 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: root, Markus Hästbacka, Kernel Mailinglist, netdev

Stephen Hemminger wrote:
> 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




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-18 18:17 ` Stephen Hemminger
  2004-02-18 20:32   ` Richard B. Johnson
@ 2004-02-19  8:14   ` Meelis Roos
  2004-02-19 17:27     ` Stephen Hemminger
  1 sibling, 1 reply; 12+ messages in thread
From: Meelis Roos @ 2004-02-19  8:14 UTC (permalink / raw)
  To: linux-kernel, netdev

SH>  * Network changes gets discussed on netdev@oss.sgi.com 
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.

-- 
Meelis Roos

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-19  8:14   ` Meelis Roos
@ 2004-02-19 17:27     ` Stephen Hemminger
  0 siblings, 0 replies; 12+ messages in thread
From: Stephen Hemminger @ 2004-02-19 17:27 UTC (permalink / raw)
  To: netdev; +Cc: mroos, linux-kernel

On Thu, 19 Feb 2004 10:14:55 +0200
Meelis Roos <mroos@linux.ee> wrote:

> SH>  * Network changes gets discussed on netdev@oss.sgi.com 
> 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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-18 16:51 [NET] 64 bit byte counter for 2.6.3 Markus Hästbacka
  2004-02-18 18:17 ` Stephen Hemminger
@ 2004-02-22 17:36 ` Pavel Machek
  2004-02-23 11:34   ` Jeff Sipek
  1 sibling, 1 reply; 12+ messages in thread
From: Pavel Machek @ 2004-02-22 17:36 UTC (permalink / raw)
  To: Markus Hästbacka; +Cc: Kernel Mailinglist

Hi!

> --- linux-2.6.3-rc1/net/core/dev.c	2004-02-08 01:07:55.000000000 +0200
> +++ linux-2.6.3-rc1-b/net/core/dev.c	2004-02-07 15:29:32.000000000 +0200
> @@ -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	*/
>  	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

-- 
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-22 17:36 ` Pavel Machek
@ 2004-02-23 11:34   ` Jeff Sipek
  2004-02-23 12:38     ` Andreas Schwab
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Sipek @ 2004-02-23 11:34 UTC (permalink / raw)
  To: Pavel Machek, Markus Hästbacka; +Cc: Kernel Mailinglist

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

On Sunday 22 February 2004 12:36, Pavel Machek wrote:
> Hi!
>
> > --- linux-2.6.3-rc1/net/core/dev.c	2004-02-08 01:07:55.000000000 +0200
> > +++ linux-2.6.3-rc1-b/net/core/dev.c	2004-02-07 15:29:32.000000000 +0200
> > @@ -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	*/
> >  	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-----


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [NET] 64 bit byte counter for 2.6.3
  2004-02-23 11:34   ` Jeff Sipek
@ 2004-02-23 12:38     ` Andreas Schwab
  0 siblings, 0 replies; 12+ messages in thread
From: Andreas Schwab @ 2004-02-23 12:38 UTC (permalink / raw)
  To: Jeff Sipek; +Cc: Pavel Machek, Markus Hästbacka, Kernel Mailinglist

Jeff Sipek <jeffpc@optonline.net> writes:

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

In C99 it's spelt uint64_t.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
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."

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-02-23 12:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-18 16:51 [NET] 64 bit byte counter for 2.6.3 Markus Hästbacka
2004-02-18 18:17 ` Stephen Hemminger
2004-02-18 20:32   ` Richard B. Johnson
2004-02-18 20:43     ` Markus Hästbacka
2004-02-18 22:45       ` Richard B. Johnson
2004-02-18 22:57         ` Stephen Hemminger
2004-02-18 23:17           ` Jeff Garzik
2004-02-19  8:14   ` Meelis Roos
2004-02-19 17:27     ` Stephen Hemminger
2004-02-22 17:36 ` Pavel Machek
2004-02-23 11:34   ` Jeff Sipek
2004-02-23 12:38     ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox