Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Dec 2001 00:13:38 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Michal Mertl <mime@traveller.cz>
Cc:        Alfred Perlstein <bright@mu.org>, Mike Smith <msmith@FreeBSD.ORG>, John Hanley <jh_@yahoo.com>, <arch@FreeBSD.ORG>
Subject:   Re: 64 bit counters
Message-ID:  <200112270813.fBR8Dc150215@apollo.backplane.com>
References:   <Pine.BSF.4.41.0112262252210.33404-100000@prg.traveller.cz>

next in thread | previous in thread | raw e-mail | index | archive | help
:Why do I think it never becomes wrong? Generally I'm adding rather small
:value (<1e6 or so) to 64 bit counter. When one addition overflows less
:significant 32 bits, several next additions don't overflow.
:
:u_int64_t+=u_long is:
:addl %eax,(u_int64_t) ; this is atomic, right?
:adcl $0,4(u_int64_t)
:
:If interrupt occurs in between these two instructions, then the less
:significant halt is right and more significant will be fixed after the
:execution returns to second instruction. Even if the interrupt modified
:the value, we can expect (read - be sure) it didn't modify the more
:significant half.

    You are absolutely right.  The carry will only be set on the addl
    which overflows the 32 bit counter and will not be set on any of
    the other addl's that might be occuring just before, inbetween the
    two instructions, or just after.  So only one of those will cause the
    msb to increment.

    For UP the addl instruction is atomic.  For SMP we still have to lock the
    bus cycle.  Something like this:

	lock; addl %eax,(u_int64_t)
	lock; adcl $0,4(u_int64_t)

    Or this:

	lock; addl %eax,(u_int64_t)
	jnc 1f
	lock; incl 4(u_int64_t)
	1:

:So I see here two problems: how to read the value and how to assure we
:won't use the same principle on counters which grow much faster.
:
:If you thing this is really unacceptable, I don't blame you. It really

    I think putting sophistication in the code reading the value of
    the counters (by checking against a previously read value and making
    appropriate assumptions if the new value appears to be too small or
    too large), in order to avoid having to make the increment operation
    complex, is a good idea.

					    -Matt

:Still willing to work on making FreeBSD even better :-).
:
:-- 
:Michal Mertl
:mime@traveller.cz

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200112270813.fBR8Dc150215>