From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,9a9611620e98241 X-Google-Attributes: gid1164f8,public From: grunwald@cons.cs.colorado.edu (Dirk Grunwald) Subject: Re: Help needed with timers on DEC 4000/710 Date: 1995/06/05 Message-ID: #1/1 X-Deja-AN: 103745520 distribution: world references: <3qtjd0INN463@chicago.cis.ohio-state.edu> organization: University of Colorado at Boulder reply-to: grunwald@foobar.cs.colorado.edu newsgroups: comp.sys.dec [ 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 #include #include 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 -----------------------------------------------------------------------------