Efficient 64/128-bit event counters (was: 498+ days uptime)

Jamie Lokier (lkd@tantalophile.demon.co.uk)
Thu, 27 Aug 1998 18:00:05 +0100


As an API, I've proposed a macro `increment_counter (counter, amount)',
which increments a 64-bit (or larger) counter using inline assembly.
Some type `counter_t' should be defined to keep the API sane.

Probably printk should have another format added that specifically works
on `counter_t' types.

The amount to increment is a 32-bit quantity on 32-bit platforms (or
larger if supplied, the macro can work out the details). I know this
would be quite efficient on i386, and of course 64-bit cpus. I don't
know about other architectures.

I've suggested the macro expands to code `addl amount,counter; adcl
$0,counter+4' on i386, avoiding GCC's problems generating good 64 bit
code. It should do the appropriate thing with other archs too.

But now, I've come up with something that is probably faster. And it
can also be extended to 128 bits etc. without slowdown:

addl amount,counter
jc 0f
.section .text.counter,"ax"
0: addl $1,counter+4
adcl $0,counter+8
adcl $0,counter+12
jmp 1f
.previous
1:

This one only works when `amount' is a 32 bit type or less, which will
be the usual case. I propose the `increment_counter' macro look at the
sizeof its arguments to decide which code to emit.

-- 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.altern.org/andrebalsa/doc/lkml-faq.html