From davids@tock.gpsclock.com  Fri Jan 21 00:07:48 2000
Return-Path: <davids@tock.gpsclock.com>
Received: from tock.gpsclock.com (tock.gpsclock.com [209.133.29.20])
	by hub.freebsd.org (Postfix) with ESMTP id B1B2714C43
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 21 Jan 2000 00:07:46 -0800 (PST)
	(envelope-from davids@tock.gpsclock.com)
Received: (from davids@localhost)
	by tock.gpsclock.com (8.9.3/8.9.3) id AAA14016;
	Fri, 21 Jan 2000 00:07:45 -0800 (PST)
	(envelope-from davids)
Message-Id: <200001210807.AAA14016@tock.gpsclock.com>
Date: Fri, 21 Jan 2000 00:07:45 -0800 (PST)
From: davids@webmaster.com
Sender: davids@tock.gpsclock.com
Reply-To: davids@webmaster.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: libc_r bug in poll, timeout math suspicious
X-Send-Pr-Version: 3.2

>Number:         16245
>Category:       misc
>Synopsis:       poll misconverts milliseconds to nanoseconds
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 21 00:10:01 PST 2000
>Closed-Date:    Sat Jan 22 01:09:41 PST 2000
>Last-Modified:  Sat Jan 22 01:15:27 PST 2000
>Originator:     David Schwartz
>Release:        FreeBSD 3.3-STABLE i386
>Organization:
Webmaster, Incorporated
>Environment:

	FreeBSD 3.3-STALE system. Using libc_r with loops based heavily
around poll with timeouts.

>Description:

	Threaded code that uses libc_r and is based around 'poll' uses much
more system CPU time than it should. Problem is tracked to a math error in
the 'poll' routine.

>How-To-Repeat:

	Run any program that calls poll in a tight loop, relying on the
timeout in 'poll' to prevent a spin.

>Fix:
	
	In libc_r/uthread/uthread_poll.c, we find the following suspicious
math:

       } else if (timeout > 0) {
                /* Convert the timeout in msec to a timespec: */

                ts.tv_sec = timeout / 1000;
                ts.tv_nsec = (timeout % 1000) * 1000;

                /* Set the wake up time: */
                _thread_kern_set_timeout(&ts);
        } else if (timeout < 0) {

	This conversion from milliseconds to nanoseconds is incorrect. There
are a million milliseconds in a nanosecond.

---
Actually, there are a million nanoseconds in a millisecond, but I get the
point. =)

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jasone 
State-Changed-When: Sat Jan 22 01:09:41 PST 2000 
State-Changed-Why:  
Fixed. 
>Unformatted:
