From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,80cdc103b18508a6 X-Google-Attributes: gidfee84,public From: grunwald@foobar.cs.colorado.edu (Dirk Grunwald) Subject: Re: Alpha hw cycle counter Date: 1996/06/05 Message-ID: X-Deja-AN: 158699552 references: organization: University of Colorado reply-to: grunwald@foobar.cs.colorado.edu newsgroups: comp.unix.osf.osf1 nntp-posting-user: grunwald Alternatively, the following routines will return the time in microseconds without a kernel call. Sample usage: unsigned long start = fixed_rpcc(); ....do stuff..... unsigned long stop = fixed_rpcc(); double delta = rpcc_delta(start, stop); where the resulting 'delta' is in microseconds, scaling the value of the timer for your processor clock rate. The notion of "fixing" the RPCC value is basically what's mentioned in the Alpha manual about the RPCC format (top 32 bits per-process adjustment, bottom 32 bits free-spinning). #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'Makefile' <<'END_OF_FILE' XCFLAGS = -O XASFLAGS = -O2 XOBJS = rpcc-delta.o rpcc-modified.o X Xlibrpcc.a: $(OBJS) X ar rc librpcc.a $(OBJS) X Xinstall: librpcc.a X install -c librpcc.a /srl/ATOM/lib X install -c librpcc.h /srl/ATOM/include X ranlib /srl/ATOM/lib/librpcc.a X Xclean: X rm -f *.o END_OF_FILE if test 254 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'librpcc.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'librpcc.h'\" else echo shar: Extracting \"'librpcc.h'\" \(435 characters\) sed "s/^X//" >'librpcc.h' <<'END_OF_FILE' X#ifndef _librpcc_h_ X#define _librpcc_h_ X X/* X * Read the actual rpcc and 'fix' the value X */ Xunsigned long fixed_rpcc(); X X X/* X * Fix an rpcc retrieved from elsewhere (e.g., from ATOM) X */ Xextern unsigned long fix_rpcc(unsigned long rpcc); X X/* X * Return the time difference, in microseconds between X * two rpcc's. This is scaled for the processor cycle time. X */ Xdouble rpcc_delta(unsigned long ul_start, unsigned long ul_stop); X X#endif END_OF_FILE if test 435 -ne `wc -c <'librpcc.h'`; then echo shar: \"'librpcc.h'\" unpacked with wrong size! fi # end of 'librpcc.h' fi if test -f 'rpcc-delta.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'rpcc-delta.c'\" else echo shar: Extracting \"'rpcc-delta.c'\" \(905 characters\) sed "s/^X//" >'rpcc-delta.c' <<'END_OF_FILE' X#include X#include X#include X Xstatic double scale = -1; X Xunsigned long Xfix_rpcc(unsigned long rpcc) X{ X unsigned long offset = (rpcc >> 32) & 0xffffffff; X unsigned long cycles = (rpcc & 0xffffffff); X return offset + cycles; X} X Xdouble Xrpcc_delta(unsigned long ul_start, unsigned long ul_stop) X{ X X if ( scale == -1 ) { X int err; X double freq; X struct rpb rpbbuf; X X err = getsysinfo(GSI_GET_HWRPB, &rpbbuf, sizeof(rpbbuf)); X if (err < 0) { X freq = 233; X } else { X freq = rpbbuf.rpb_counter; X } X /* X * Scale is the 1 over the clock frequency, in microseconds X */ X scale = (1000.0 * 1000.0)/(double) freq; X } X X if (ul_stop < ul_start ) { X unsigned long delta; X delta = 0xffffffff - ul_start; X delta += ul_stop; X ul_start = 0; X ul_stop = delta; X } X X return (ul_stop - ul_start) * scale; X} END_OF_FILE if test 905 -ne `wc -c <'rpcc-delta.c'`; then echo shar: \"'rpcc-delta.c'\" unpacked with wrong size! fi # end of 'rpcc-delta.c' fi if test -f 'rpcc-modified.s' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'rpcc-modified.s'\" else echo shar: Extracting \"'rpcc-modified.s'\" \(680 characters\) sed "s/^X//" >'rpcc-modified.s' <<'END_OF_FILE' X .ugen X .verstamp 3 11 X .text X .align 4 X .file 2 "rpcc.c" X .globl fixed_rpcc X .loc 2 12 X # 12 { X .ent fixed_rpcc 2 Xfixed_rpcc: X .option O2 X # ldgp $gp, 0($27) X .frame $sp, 0, $26, 0 X .prologue 1 X .loc 2 12 X X .loc 2 13 X # 13 unsigned long rpcc = r; X .loc 2 14 X # 14 unsigned long offset = (rpcc >> 32) & 0xffffffff; X .loc 2 15 X # 15 unsigned long cycles = (rpcc & 0xffffffff); X .loc 2 16 X # 16 return offset + cycles; X # X # Register 16 is $a0. Load the rpcc into this register (i.e., it was X # not passed to us) X # X rpcc $16 X extll $16, 4, $1 X and $16, 4294967295, $2 X addq $1, $2, $0 X .livereg 0xFC7F0002,0x3FC00000 X ret $31, ($26), 1 X .end fixed_rpcc END_OF_FILE if test 680 -ne `wc -c <'rpcc-modified.s'`; then echo shar: \"'rpcc-modified.s'\" unpacked with wrong size! fi # end of 'rpcc-modified.s' fi echo shar: End of shell archive. exit 0