Date: Thu, 1 Jun 1995 15:39:51 -0500 From: Jim Lowe <james@miller.cs.uwm.edu> To: freebsd-hackers@FreeBSD.ORG Subject: Interval timer/System clock Message-ID: <199506012039.PAA20210@miller.cs.uwm.edu>
next in thread | raw e-mail | index | archive | help
I have a question about the system interval timer.  I am not sure why it
is behaving the way it is.
Shouldn't the interval timer in the system have a resolution of HZ rather
than HZ/2?  
I ran the attached test program on various systems and compiled the following
results:
OS type		Processor	Min possible interval timer (seconds)
-------------	---------	------------------
OSF 3.0		Alpha		0.005
Solaris 2.4	Sun 4 		0.01
Ultrix 4.4	Mips 		0.004
FreeBSD 2.0.5	Pentium		0.02
NetBSD 1.0a	386		0.01
Note that FreeBSD returns 0.02 rather than 0.01 which I would expect for a
100 Hz clock.
Also, it would be nice to have a faster interval timer (0.005 secs) for
various Multimedia/Real Time applications.  I assume I can just add the line
``OPTIONS "HZ=512"'' to my configuration file, but if I do -- will
I break anything obvious?
Thanks for any help or suggestions.
	-Jim
-----snip here for itest.c---
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#define ITIMER_REAL 0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF 2
#include <signal.h>
static unsigned int num_ints;
#define	NUM_MS		1
void
timer_int()
{
	num_ints++;
	return;
}
int
main()
{
struct timeval tv, tvo;
struct itimerval it;
struct sigaction action;
double u,v;
	action.sa_handler = timer_int;
	sigaction(SIGALRM, &action, NULL);
	num_ints = 0;
	u = 0;
	it.it_interval.tv_sec = 0;
	it.it_interval.tv_usec = NUM_MS;
	it.it_value.tv_sec = 0;
	it.it_value.tv_usec = NUM_MS;
	setitimer(ITIMER_REAL, &it, NULL);
	gettimeofday(&tvo, NULL);
	while(1) {
		pause();
		gettimeofday(&tv, NULL);
		v = (tv.tv_sec - tvo.tv_sec) + 1e-6 * (tv.tv_sec - tvo.tv_sec);
		if(v - u > 1.0) {
			printf("%d %8.8f %8.8f %8.8f secs\r", num_ints, v,
						(double)num_ints/v,
						v/(double)num_ints);
			fflush(stdout);
			u = v;
		}
	}
}	
--PAA20140.802039138/miller.cs.uwm.edu--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199506012039.PAA20210>
