bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

glibc POSIX.1b timer implementation drifts [WITH POSSIBLE SOLUTION]


From: Eric F. Sorton
Subject: glibc POSIX.1b timer implementation drifts [WITH POSSIBLE SOLUTION]
Date: Mon, 25 Mar 2002 11:11:15 -0500
User-agent: Mutt/1.2.5i

Hi All,

During use of the POSIX.1b timer implementation within glibc, my collegues and
I noticed that the timer drifts rather significantly.  For example, if you
establish a timer at a rate of 10 Hz and let it run for 100 seconds, you would
expect to see the timer fire 1000 times.  This behavior is not realized.  The
timer fires less than 1000 times.  As the rate of the timer increases, the
drift becomes more pronounced.

Examining the code, the problem appears to be in the function
sysdeps/pthread/timer_routines.c, lines 415-419 of linuxthreads version 2.2.5.
On line 416, the next expiration time is caculated as:

        timespec_add (&timer->expirytime, &now, &timer->value.it_interval);

If you continually calculate the next expiration time based upon now, the
latency of when the timer actually fires compounds and drift occours.  I
believe the line should read:

        timespec_add (&timer->expirytime, &timer->expirytime, 
&timer->value.it_interval);

If the next expiration time is always based upon the previous expiration time,
then drift should (in theory) be eliminated.

In addition to the above change, it is also necessary to check to see if the
calculated next expiration time is less than "now" (i.e. the expiration point 
has
already passed), and continue to increment the next expiration time until a
time greater than "now" is found.  This can occour if the timer overruns.  This
would also allow the implementation of timer_getoverrun().

I am interested in opinions on if this is a valid BUG within the glibc code.

I will produce a patch which implements the above changes if there is interest.

Eric

-- 
+--=--=- Eric F. Sorton <address@hidden> =--=--=--=--=--=--=--=--=--=-+ 
| Command and Control Technologies Corporation (http://www.cctcorp.com) |
|            Phone: (321) 264-1193   Fax: (321) 383-5096                |
+--=--=--=--=--=--=--=--=--=--=--=-+-=--=--=--=--=--=--=--=--=--=--=--=-+ 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]