From owner-freebsd-bugs Wed Nov 13 00:00:06 1996 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id AAA01176 for bugs-outgoing; Wed, 13 Nov 1996 00:00:06 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id AAA01151; Wed, 13 Nov 1996 00:00:03 -0800 (PST) Resent-Date: Wed, 13 Nov 1996 00:00:03 -0800 (PST) Resent-Message-Id: <199611130800.AAA01151@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, Received:"from noc.belwue.de (root@noc.BelWue.DE [129.143.2.1]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id XAA00956 for" ; Tue, 12 Nov 1996 23:57:04.-0800 (PST) Received: from rubin.noc.dfn.de (rubin.noc.dfn.de [193.174.247.201]) by noc.belwue.de with SMTP id IAA10238 (8.6.13/IDA-1.6 for ); Wed, 13 Nov 1996 08:56:53 +0100 Received: from diamant.noc.dfn.de by rubin.noc.dfn.de (4.1/BelWue-2.0SUN) id AA02189; Wed, 13 Nov 96 08:56:53 +0100 Received: by diamant.noc.dfn.de (SMI-8.6/SVR4/BelWue-1.0.3) id IAA05900; Wed, 13 Nov 1996 08:56:10 +0100 Message-Id: <199611130756.IAA05900@diamant.noc.dfn.de> Date: Wed, 13 Nov 1996 08:56:09 +0100 (MET) From: Schweikhardt@RUS.Uni-Stuttgart.DE (Jens Schweikhardt) To: FreeBSD-gnats-submit@freebsd.org Cc: schweikh@diamant.noc.dfn.de (Jens Schweikhardt) Subject: misc/1998: clock() wraps after only 548775 ticks Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >Number: 1998 >Category: misc >Synopsis: clock() wraps after only 548775 ticks >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Nov 13 00:00:00 PST 1996 >Last-Modified: >Originator: schweikh@noc.dfn.de >Organization: DFN Network Operation Center >Release: FreeBSD 2.1-STABLE i386 >Environment: i486 DX2/66 >Description: The value returned by clock() wraps after about 548775 ticks (4288 CPU seconds = 1 hour and then some). This is the behaviour I would expect if CLOCKS_PER_SEC were 1000000, but it's only 128 according to . So FreeBSD needlessly wastes a great potential of accurate resource usage measurement. This surely seems realted to the kernel's inability to measure resource usages of more than this amount of user and system time (with getrusage()). If this is the intended behaviour and will not be changed then please add a note in the clock(3) and getrusage(2) man pages about the premature wrap... (yuck, FreeBSD :-) >How-To-Repeat: Compile and run this: #include #include #include #include #include static time_t start; static struct rusage rus; static void alarm_handler (int); static void alarm_handler (int sig) { (void) getrusage (RUSAGE_SELF, &rus); (void) printf ("%lu %lu %6.0f\n", (unsigned long) (time (NULL) - start), (unsigned long) clock (), (double) (rus.ru_utime.tv_sec + rus.ru_stime.tv_sec + (rus.ru_utime.tv_usec + rus.ru_stime.tv_usec)/1.0E6)); (void) fflush (NULL); } int main (void) { struct sigaction sa = { 0 }; struct itimerval alarm_time = {{1, 0}, {1, 0}}; sa.sa_handler = alarm_handler; (void) sigemptyset (&sa.sa_mask); (void) sigaddset (&sa.sa_mask, SIGVTALRM); if (sigaction (SIGVTALRM, &sa, NULL) == -1) { perror ("sigaction"); return EXIT_FAILURE; } if (setitimer (ITIMER_VIRTUAL, &alarm_time, NULL) == -1) { perror ("setitimer"); return EXIT_FAILURE; } start = time (NULL); for (;;) ; return EXIT_SUCCESS; } Run it for 4300 (CPU) seconds. The output will look like this: 1 133 1 3 260 2 4 384 3 5 511 4 6 635 5 7 751 6 8 869 7 ... 4487 548007 4281 4488 548127 4282 4490 548254 4283 4491 548375 4284 4492 548494 4285 4493 548618 4286 4494 121 1 4496 248 2 4497 379 3 4498 504 4 4499 630 5 4500 756 6 >Fix: >Audit-Trail: >Unformatted: To: FreeBSD-gnats-submit@freebsd.org Subject: clock() wraps after only 548775 ticks From: schweikh@noc.dfn.de Reply-To: schweikh@noc.dfn.de X-send-pr-version: 3.2