Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Re: Alpha hw cycle counter
  1996-06-05  4:00 Alpha hw cycle counter Steve Thompson
@ 1996-06-05  4:00 ` Dirk Grunwald
  1996-06-06  4:00 ` Jeffrey Mogul
  1 sibling, 0 replies; 3+ messages in thread
From: Dirk Grunwald @ 1996-06-05  4:00 UTC (permalink / raw)




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 <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile librpcc.h rpcc-delta.c rpcc-modified.s
# Wrapped by grunwald@foobar.cs.colorado.edu on Wed Jun  5 20:20:42 1996
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(254 characters\)
sed "s/^X//" >'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 <sys/sysinfo.h>
X#include <machine/hal_sysinfo.h>
X#include <machine/rpb.h>
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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Alpha hw cycle counter
@ 1996-06-05  4:00 Steve Thompson
  1996-06-05  4:00 ` Dirk Grunwald
  1996-06-06  4:00 ` Jeffrey Mogul
  0 siblings, 2 replies; 3+ messages in thread
From: Steve Thompson @ 1996-06-05  4:00 UTC (permalink / raw)



I'm looking for a method to read the hw cycle counter under DEC Unix; C
preferred but assembler OK. Alternatively, some way to read the current
time to a resolution of at least a microsecond. I'd appreciate a pointer
to either of these; TIA.

-Steve
-------------------------------------------------------------------------
Steve Thompson
@ Lockheed Martin Federal Systems			phone: (607) 751 4943   
M/D 0220, 1801 State Route 17C, Owego, NY 13827-3994	fax:   (607) 751 2800
 "186,000 miles per second: it's not just a good idea; it's the law"
-------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Alpha hw cycle counter
  1996-06-05  4:00 Alpha hw cycle counter Steve Thompson
  1996-06-05  4:00 ` Dirk Grunwald
@ 1996-06-06  4:00 ` Jeffrey Mogul
  1 sibling, 0 replies; 3+ messages in thread
From: Jeffrey Mogul @ 1996-06-06  4:00 UTC (permalink / raw)



In article <Pine.A32.3.93.960605112455.39137A-100000@spain.endicott.ibm.com> Steve Thompson <v2pen01@spain.endicott.ibm.com> writes:
>I'm looking for a method to read the hw cycle counter under DEC Unix; C
>preferred but assembler OK. Alternatively, some way to read the current
>time to a resolution of at least a microsecond. I'd appreciate a pointer
>to either of these; TIA.

Create rpcc.s with this in it:
        .globl  ReadPCC
        .ent    ReadPCC,0
ReadPCC:;
        .frame  $30,0,$26
        rpcc    $0
        ret     $31,($26)
        .end    ReadPCC


Call it from C like so:

        unsigned int p;
	unsigned int ReadPCC();

        p = ReadPCC();

works for me, anyway.

-Jeff

P.S.: Digital UNIX V4.0 will return microsecond resolution
from gettimeofday(), *if* you rebuild the kernel using the
MICROTIME configuration option.  (Sorry, I haven't tried this
myself so I can't provide full instructions yet.)



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-06-06  4:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-06-05  4:00 Alpha hw cycle counter Steve Thompson
1996-06-05  4:00 ` Dirk Grunwald
1996-06-06  4:00 ` Jeffrey Mogul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox