* Measuring VERY short durations
@ 2002-12-13 10:36 JF Larvoire
2002-12-13 11:59 ` Falk Hueffner
0 siblings, 1 reply; 5+ messages in thread
From: JF Larvoire @ 2002-12-13 10:36 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 174 bytes --]
Hello,
we'd like to measure the duration of very short code pieces.
Is there a way to get access to processor clock counters on the Alpha?
How?
Thanks,
Jean-Fran�ois
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Measuring VERY short durations
2002-12-13 10:36 Measuring VERY short durations JF Larvoire
@ 2002-12-13 11:59 ` Falk Hueffner
2002-12-13 13:44 ` JF Larvoire
0 siblings, 1 reply; 5+ messages in thread
From: Falk Hueffner @ 2002-12-13 11:59 UTC (permalink / raw)
"JF Larvoire" <jean-francois.larvoire@remove_this.free.fr> writes:
> we'd like to measure the duration of very short code pieces. Is
> there a way to get access to processor clock counters on the Alpha?
Yes. Try this code:
#ifdef __GNUC__
static inline unsigned realcc(void) {
unsigned long cc;
asm volatile("rpcc %0" : "=r"(cc));
return cc;
}
#else /* DEC C */
#include <c_asm.h>
static inline unsigned realcc(void) {
return asm("rpcc %v0");
}
#endif
This will get the lower 32 bits of the cycle counter (the upper 32
bits contain a process-specific counter that you can use to calculate
user time for a specific process). Note that it wraps around every few
seconds, and context switches might disturb the result, so you should
do some sanity checks.
If you need *extremely* short measurements (like 20 cycles), and have
an EV6, you should pass a second argument to rpcc, which will avoid it
being executed too early by the out-of-order mechanism. See the Alpha
Architecture Reference Manual (4th edition) for details.
--
Falk
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Measuring VERY short durations
2002-12-13 11:59 ` Falk Hueffner
@ 2002-12-13 13:44 ` JF Larvoire
2002-12-13 13:56 ` Andrew Duane USG
0 siblings, 1 reply; 5+ messages in thread
From: JF Larvoire @ 2002-12-13 13:44 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 654 bytes --]
Hello,
I tried it, but it does not seem to work:
It compiles OK, but when I test it with in the trivial attached program, I
get this result:
Sum 1 done in 9 cycles.
Sum 2 done in 6 cycles.
It's obviously wrong, as there should be more cycles, and also the second
loop should take 2.5 longer to execute.
Any clue?
Jean-Fran�ois
void main(int argc, char *argv[])
{
unsigned u0, u1, u2;
int i;
int n;
u0 = realcc();
for (i=0, n=0; i<10; i++) n += i*i;
u1 = realcc();
for (i=0, n=0; i<25; i++) n += i*i;
u2 = realcc();
printf("Sum 1 done in %u cycles.\n", u1-u0);
printf("Sum 2 done in %u cycles.\n", u2-u1);
return;
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Measuring VERY short durations
2002-12-13 13:44 ` JF Larvoire
@ 2002-12-13 13:56 ` Andrew Duane USG
2002-12-18 10:03 ` JF Larvoire
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Duane USG @ 2002-12-13 13:56 UTC (permalink / raw)
In article <3df9e50d$0$18245$626a54ce@news.free.fr> "JF Larvoire" <jean-francois.larvoire@remove_this.free.fr> writes:
>Hello,
>
>I tried it, but it does not seem to work:
>It compiles OK, but when I test it with in the trivial attached program, I
>get this result:
> Sum 1 done in 9 cycles.
> Sum 2 done in 6 cycles.
I ran this on my EV5-based 4100 station.
I think the problem is our too-smart-for-its-own-good compiler.
Did you compile this optimized (-O2)? When I did that, the loops
were optimized out and the RPCC instructions were inlined almost
next to each other, giving me 3 and 1 cycles.
With -g instead of -O2, I got 128 and 300 cycles.
--
Andrew L. Duane (JOT-7) duane@zk3.dec.com
HP/Compaq Corporation Andrew.Duane@compaq.com
110 Spit Brook Road Andrew.Duane@hp.com
M/S ZKO3-3/U14
Nashua, NH 03062-2698 (603)-884-1294
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-12-18 10:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-13 10:36 Measuring VERY short durations JF Larvoire
2002-12-13 11:59 ` Falk Hueffner
2002-12-13 13:44 ` JF Larvoire
2002-12-13 13:56 ` Andrew Duane USG
2002-12-18 10:03 ` JF Larvoire
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox