From: henning@i4get.enet.dec.com (John L. Henning)
Subject: Re: ALPHA Chipset Register
Date: 1995/07/08 [thread overview]
Message-ID: <3tm5rn$cru@peavax.eng.pko.dec.com> (raw)
In-Reply-To: DBD3I8.8s3@nntpa.cb.att.com
In article <DBD3I8.8s3@nntpa.cb.att.com>, alan@cbncp5.cb.att.com (Alan Curtis x4749) writes...
>I've come accross the "rpcc" instruction which claims
>to read the "Process Cycle Counter". Does anyone know
>if this is just counting the XXX Mhz clock, or machine cycles,
>or instructions, or ????
>
>I've read it many times and am not convinced I can make heads
>or tails of it on any consistent basis. Yes, one of my big
>problems is that I am on a multi-CPU system, but I think I'm
>working my way out of that hole...
>
The attached is a re-post of an article by Dirk Grunwald. Hope this
helps. In addition to the usual disclaimers, I'll add that I have not
personally tested Dirk's code! But he's a great guy, therefore it can't
have any bugs :-).
/John Henning
CSD Performance Group
Digital Equipment Corporation
henning@zko.dec.com
Speaking for myself, not Digital
Begin re-post:
Article: 20937
From: grunwald@cons.cs.colorado.edu (Dirk Grunwald)
Newsgroups: comp.sys.dec
Subject: Re: Help needed with timers on DEC 4000/710
Date: 05 Jun 1995 01:23:31 GMT
Organization: University of Colorado at Boulder
[ I sent this by mail and then realized others would want it too ]
The alpha has a cycle counter. It's a 32 bit counter, overflows in
2^32 cycles. This is about 15 seconds. If you're timing things with
resolution less than 15 seconds, it'll work fine.
The following code calculates the time (in microseconds) given a value
from the PCC. Given the code segments below, to time code, simply do:
unsigned long start, stop;
start = fixed_rpcc();
do_your_stuff();
stop = fixed_rpcc();
printf("Time was %f microseconds\n", rpcc_delta(start, stop);
-----------------------------------------------------------------------------
#include <sys/sysinfo.h>
#include <machine/hal_sysinfo.h>
#include <machine/rpb.h>
static double scale = -1;
unsigned long
fix_rpcc(unsigned long rpcc)
{
unsigned long offset = (rpcc >> 32) & 0xffffffff;
unsigned long cycles = (rpcc & 0xffffffff);
return offset + cycles;
}
double
rpcc_delta(unsigned long ul_start, unsigned long ul_stop)
{
if ( scale == -1 ) {
int err;
double freq;
struct rpb rpbbuf;
err = getsysinfo(GSI_GET_HWRPB, &rpbbuf, sizeof(rpbbuf));
if (err < 0) {
freq = 233;
} else {
freq = rpbbuf.rpb_counter;
}
/*
* Scale is the 1 over the clock frequency, in microseconds
*/
scale = (1000.0 * 1000.0)/(double) freq;
}
if (ul_stop < ul_start ) {
unsigned long delta;
delta = 0xffffffff - ul_start;
delta += ul_stop;
ul_start = 0;
ul_stop = delta;
}
return (ul_stop - ul_start) * scale;
}
-----------------------------------------------------------------------------
The following (assembly) routine reads the cycle counter
-----------------------------------------------------------------------------
.ugen
.verstamp 3 11
.text
.align 4
.file 2 "rpcc.c"
.globl fixed_rpcc
.loc 2 12
# 12 {
.ent fixed_rpcc 2
fixed_rpcc:
.option O2
# ldgp $gp, 0($27)
.frame $sp, 0, $26, 0
.prologue 1
.loc 2 12
.loc 2 13
# 13 unsigned long rpcc = r;
.loc 2 14
# 14 unsigned long offset = (rpcc >> 32) & 0xffffffff;
.loc 2 15
# 15 unsigned long cycles = (rpcc & 0xffffffff);
.loc 2 16
# 16 return offset + cycles;
#
# Register 16 is $a0. Load the rpcc into this register (i.e., it was
# not passed to us)
#
rpcc $16
extll $16, 4, $1
and $16, 4294967295, $2
addq $1, $2, $0
.livereg 0xFC7F0002,0x3FC00000
ret $31, ($26), 1
.end fixed_rpcc
-----------------------------------------------------------------------------
next prev parent reply other threads:[~1995-07-08 4:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-07-07 4:00 ALPHA Chipset Register Alan Curtis x4749
1995-07-08 4:00 ` John L. Henning [this message]
1995-07-17 4:00 ` Robin Fairbairns
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox