Subject: Re: processor speed on O2
To: None <port-sgimips@NetBSD.org>
From: Stephen M. Rumble <stephen.rumble@utoronto.ca>
List: port-sgimips
Date: 04/01/2007 19:19:07
This message is in MIME format.
--=_4birf8ewpbeo
Content-Type: text/plain;
charset=ISO-8859-1;
DelSp="Yes";
format="flowed"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Quoting "Stephen M. Rumble" <stephen.rumble@utoronto.ca>:
> Here's userland example (attached).
Sorry, it was broken on MIPS. The attached version appears to give
reasonable output under gxemul running NetBSD/pmax.
I hope you find it useful,
Steve
--=_4birf8ewpbeo
Content-Type: text/x-csrc;
charset=UTF-8;
name="mhz.c"
Content-Disposition: attachment;
filename="mhz.c"
Content-Transfer-Encoding: quoted-printable
/*=09$Id: mhz.c,v 1.4 2007/04/01 23:06:37 rumble Exp $=09*/
/*
* PUBLIC DOMAIN
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#define X86
//#define MIPS
#define SLEEPTIME=09500000=09/* microseconds */
#ifdef MIPS
#define MAXCYCLES =09(0xffffffffUL)
uint64_t
read_cycle_counter()
{
=09uint32_t a;
=09__asm __volatile ("mfc0 %0, $9; nop" : "=3Dr" (a));
=09return ((uint64_t)a);
}
#endif
#ifdef X86
#define MAXCYCLES=09(0xffffffffffffffffULL)
uint64_t
read_cycle_counter()
{
=09uint32_t hi, lo;
=09__asm__ __volatile ("rdtsc" : "=3Da" (lo), "=3Dd" (hi));
=09return ((uint64_t)hi << 32 | lo);
}
#endif
uint32_t
tvdiff(struct timeval *tv1, struct timeval *tv2)
{
=09uint64_t before, after;
=09before =3D (uint64_t)tv1->tv_sec * 1000000 + tv1->tv_usec;
=09after =3D (uint64_t)tv2->tv_sec * 1000000 + tv2->tv_usec;
=09return (after - before);
}
int
main()
{
=09struct timeval tv1, tv2;
=09uint64_t cc1, cc2;
=09gettimeofday(&tv1, NULL);
=09cc1 =3D read_cycle_counter();
#if SLEEPTIME > 1000000
=09sleep(SLEEPTIME / 1000000);
#else
=09usleep(SLEEPTIME);
#endif
=09cc2 =3D read_cycle_counter();
=09gettimeofday(&tv2, NULL);
=09if (cc1 < cc2)
=09=09cc1 =3D cc2 - cc1;
=09else
=09=09cc1 =3D cc2 + (MAXCYCLES - cc1);
=09printf("%.02f MHz\n", (float)cc1 / tvdiff(&tv1, &tv2));
=09return (0);
}
--=_4birf8ewpbeo--