fast 64 bit "atomic" x86 counters

Jamie Lokier (ln@tantalophile.demon.co.uk)
Wed, 15 Sep 1999 04:57:09 +0200


Alan Cox wrote:
> 64bit atomic increments are expensive. You can collect the same data via
> ipchains if you wish to take the hit, or sample very 15 minutes

Which reminds me.
Let me know if this "cheap 63bit atomic increment" works...

Increment:

lock
addl $1,counter
jo 0f
jc 0f
.section .fixup,"ax"
0: incl counter+4
jmp 1f
.previous
1:

Read:

movl counter+4,%edx
lock
addl $0,(%esp)
movl counter,%eax
cmpl $0x80000000,%eax
adcl $0,%edx
shrl $1,%edx

Based on the observation that carry events are rare.
We can safely assume two never happen during the processor race windows.

enjoy,
-- Jamie

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/