From karl@habitat.procplace.com  Tue Sep 17 09:13:38 2002
Return-Path: <karl@habitat.procplace.com>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B9C9937B404
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 Sep 2002 09:13:38 -0700 (PDT)
Received: from habitat.procplace.com (habitat.procplace.com [65.208.17.199])
	by mx1.FreeBSD.org (Postfix) with SMTP id 3ABF843E42
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 Sep 2002 09:13:38 -0700 (PDT)
	(envelope-from karl@habitat.procplace.com)
Received: (qmail 20869 invoked by uid 1000); 17 Sep 2002 16:13:34 -0000
Message-Id: <20020917161334.20862.qmail@habitat.procplace.com>
Date: 17 Sep 2002 16:13:34 -0000
From: Karl Lehenbauer <karl@habitat.procplace.com>
Reply-To: Karl Lehenbauer <karl@habitat.procplace.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: gettimeofday super rarely returns an impossible tv_usec value
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         42875
>Category:       kern
>Synopsis:       gettimeofday super rarely returns an impossible tv_usec value
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    maxim
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 17 09:20:01 PDT 2002
>Closed-Date:    Thu Oct 17 06:22:11 PDT 2002
>Last-Modified:  Thu Oct 17 06:22:11 PDT 2002
>Originator:     Karl Lehenbauer
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
Procplace.com, Inc.
>Environment:
System: FreeBSD habitat.procplace.com 4.6-STABLE FreeBSD 4.6-STABLE #3: Mon Aug 5 22:36:39 CDT 2002 dbaker@habitat.procplace.com:/usr/local/dbakerspawn/builds/obj/RELENG_4/usr/local/dbakerspawn/RELENG/4/src/sys/2UIAHPROCPLACE i386


	
>Description:
	Maybe one in thirty million times, gettimeofday will return
	an invalid tv_usec value (microseconds).  It should ALWAYS
	be between 0 and 999999, but it is occasionally a very large
	negative number.

>How-To-Repeat:
	Compile this program and let it run for a super long time.
	Preferably use a machine that is actually doing stuff.
	
/* detect freebsd gettimeofday bug */

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>

check()
{
    struct timeval tv;

    if (gettimeofday(&tv, NULL) == -1) {
	perror("gettimeofday");
	return;
    }

    if (tv.tv_usec < 0 || tv.tv_usec >= 1000000) {
	 printf("cazart!  gettimeofday returned impossible tv_usec value of %d\n", tv.tv_usec);
    }
}

main()
{
    int i;

    for (i = 0; i < 1000000; i++) {
	int j;
	for (j = 0; i < 100; j++) {
	    check();
	}
	usleep((i % 8) + 1);
    }
}

Example of output from the program over several hours of run time:
 cazart!  gettimeofday returned impossible tv_usec value of -694164958
 cazart!  gettimeofday returned impossible tv_usec value of -693709994
 cazart!  gettimeofday returned impossible tv_usec value of -694051644


>Fix:

	Locate and repair bug in kernel that allows invalid tv_usec
	calls to be returned.


>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: Karl Lehenbauer <karl@habitat.procplace.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/42875: gettimeofday super rarely returns an impossible
 tv_usec value
Date: Wed, 18 Sep 2002 05:46:34 +1000 (EST)

 On 17 Sep 2002, Karl Lehenbauer wrote:
 
 > >Release:        FreeBSD 4.6-STABLE i386
 >
 > >Description:
 > 	Maybe one in thirty million times, gettimeofday will return
 > 	an invalid tv_usec value (microseconds).  It should ALWAYS
 > 	be between 0 and 999999, but it is occasionally a very large
 > 	negative number.
 
 Does this really happen in 4.6R?  It should have been fixed between
 4.5R and 4.6R by:
 
 % RCS file: /home/ncvs/src/sys/kern/kern_clock.c,v
 % Working file: kern_clock.c
 % head: 1.141
 % ...
 % ----------------------------
 % revision 1.105.2.7
 % date: 2002/02/05 18:50:07;  author: phk;  state: Exp;  lines: +3 -3
 % MFC:  make timecounters more rubust for large deltas from hardware.
 % ----------------------------
 
 Bruce
 

From: Maxim Konovalov <maxim@FreeBSD.org>
To: Bruce Evans <bde@zeta.org.au>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/42875: gettimeofday super rarely returns an impossible
 tv_usec value
Date: Wed, 18 Sep 2002 09:10:37 +0400 (MSD)

 [...]
 >  On 17 Sep 2002, Karl Lehenbauer wrote:
 >
 >  > >Release:        FreeBSD 4.6-STABLE i386
 >  >
 >  > >Description:
 >  > 	Maybe one in thirty million times, gettimeofday will return
 >  > 	an invalid tv_usec value (microseconds).  It should ALWAYS
 >  > 	be between 0 and 999999, but it is occasionally a very large
 >  > 	negative number.
 >
 >  Does this really happen in 4.6R?  It should have been fixed between
 >  4.5R and 4.6R by:
 
 It happens on 4.6.2-RELEaSE at least. See "named crash" thread on
 -bugs for details:
 
 http://docs.freebsd.org/cgi/getmsg.cgi?fetch=186250+0+current/freebsd-bugs
 
 >  % RCS file: /home/ncvs/src/sys/kern/kern_clock.c,v
 >  % Working file: kern_clock.c
 >  % head: 1.141
 >  % ...
 >  % ----------------------------
 >  % revision 1.105.2.7
 >  % date: 2002/02/05 18:50:07;  author: phk;  state: Exp;  lines: +3 -3
 >  % MFC:  make timecounters more rubust for large deltas from hardware.
 >  % ----------------------------
 
 RELENG_4_6_2_RELEASE has this code. There is another bug somewhere.
 
 -- 
 Maxim Konovalov, maxim@FreeBSD.org
 
 
State-Changed-From-To: open->closed 
State-Changed-By: maxim 
State-Changed-When: Thu Oct 17 06:20:07 PDT 2002 
State-Changed-Why:  
Fixed in 4.7-STABLE in rev. 1.105.2.10 src/sys/kern/kern_clock.c. 


Responsible-Changed-From-To: freebsd-bugs->maxim 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Thu Oct 17 06:20:07 PDT 2002 
Responsible-Changed-Why:  
Feedbacks belong to me. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=42875 
>Unformatted:
