mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Richard B. Johnson" <root@chaos.analogic.com>
To: "Markus Hästbacka" <midian@ihme.org>
Cc: Kernel Mailinglist <linux-kernel@vger.kernel.org>, netdev@oss.sgi.com
Subject: Re: [NET] 64 bit byte counter for 2.6.3
Date: Wed, 18 Feb 2004 17:45:16 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.53.0402181645220.27707@chaos> (raw)
In-Reply-To: <1077137014.18843.10.camel@midux>

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



  reply	other threads:[~2004-02-18 22:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-18 16:51 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.53.0402181645220.27707@chaos \
    --to=root@chaos.analogic.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=midian@ihme.org \
    --cc=netdev@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®