From owner-freebsd-hackers Thu Jun 1 13:40:05 1995 Return-Path: hackers-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id NAA24716 for hackers-outgoing; Thu, 1 Jun 1995 13:40:05 -0700 Received: from miller.cs.uwm.edu (miller.cs.uwm.edu [129.89.35.13]) by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id NAA24671 for ; Thu, 1 Jun 1995 13:39:54 -0700 Received: (from james@localhost) by miller.cs.uwm.edu (8.6.10/8.6.10) id PAA20210 for freebsd-hackers@freebsd.org; Thu, 1 Jun 1995 15:39:51 -0500 Date: Thu, 1 Jun 1995 15:39:51 -0500 From: Jim Lowe Message-Id: <199506012039.PAA20210@miller.cs.uwm.edu> To: freebsd-hackers@FreeBSD.ORG Subject: Interval timer/System clock Sender: hackers-owner@FreeBSD.ORG Precedence: bulk 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 #include #include #define ITIMER_REAL 0 #define ITIMER_VIRTUAL 1 #define ITIMER_PROF 2 #include 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--