Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* ALPHA Chipset Register
@ 1995-07-07  4:00 Alan Curtis x4749
  1995-07-08  4:00 ` John L. Henning
  1995-07-17  4:00 ` Robin Fairbairns
  0 siblings, 2 replies; 3+ messages in thread
From: Alan Curtis x4749 @ 1995-07-07  4:00 UTC (permalink / raw)


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...

alan "I just gotta get the manual soon" curtis



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

* Re: ALPHA Chipset Register
  1995-07-07  4:00 ALPHA Chipset Register Alan Curtis x4749
@ 1995-07-08  4:00 ` John L. Henning
  1995-07-17  4:00 ` Robin Fairbairns
  1 sibling, 0 replies; 3+ messages in thread
From: John L. Henning @ 1995-07-08  4:00 UTC (permalink / raw)



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
-----------------------------------------------------------------------------




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

* Re: ALPHA Chipset Register
  1995-07-07  4:00 ALPHA Chipset Register Alan Curtis x4749
  1995-07-08  4:00 ` John L. Henning
@ 1995-07-17  4:00 ` Robin Fairbairns
  1 sibling, 0 replies; 3+ messages in thread
From: Robin Fairbairns @ 1995-07-17  4:00 UTC (permalink / raw)


In article <DBD3I8.8s3@nntpa.cb.att.com>,
Alan Curtis x4749 <alan@cbncp5.cb.att.com> wrote:
>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 ????

It counts processor cycles.

>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 PALcode (or all PALcode I've looked at) sets the counter offset
when going into a process's context so that the instructions quoted in
Sites' architecture manual give you something that's pretty much
monotonic increasing and related to the number of cycles your process
has executed.  There are going to be problems when the processor speed
increases to the extent that a typical timeslice occupies >2**32
cycles <g>

This PALcode will obviate the effects arising from multiple processors
in the same system; I can imagine much excitement if there were
processors with different speeds on the same bus, though.

>alan "I just gotta get the manual soon" curtis

Do. It's a laugh a minute.

The code in Sites' manual is

	rpcc	r0
	sll	r0, #32, r1
	addq	r0, r1, r0
	srl	r0, #32, r0

which leaves you with a 32-bit unsigned number in r0
--
Robin (Campaign for Real Radio 3) Fairbairns     rf@cl.cam.ac.uk
U of Cambridge Computer Lab, Pembroke St, Cambridge  CB2 3QG, UK
<a href="http://www.cl.cam.ac.uk/users/rf/robin.html">Private page</a>



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

end of thread, other threads:[~1995-07-17  4:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-07-07  4:00 ALPHA Chipset Register Alan Curtis x4749
1995-07-08  4:00 ` John L. Henning
1995-07-17  4:00 ` Robin Fairbairns

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