Bug in Posix clock_getres.c
Joel Sherrill
joel.sherrill at OARcorp.com
Wed Oct 10 18:32:14 UTC 2001
David Polock wrote:
>
> Hi,
>
> I've just started to take a look at rtems, version 4.5.0. I think I've found
> a bug in rtems-4.5.0/c/src/exec/posix/src/clockgetres.c. If the mailing list
> is not the right place for bug reports, please point me to the correct address.
It is the right place. :) Here is the patch that was checked into the
development
branch a while back. This patch will be included in 4.5.1.
diff -u -r1.2 -r1.3
--- clockgetres.c 2000/08/30 17:12:42 1.2
+++ clockgetres.c 2001/01/22 14:19:05 1.3
@@ -1,5 +1,5 @@
/*
- * $Id: clockgetres.c,v 1.2 2000/08/30 17:12:42 joel Exp $
+ * $Id: clockgetres.c,v 1.3 2001/01/22 14:19:05 joel Exp $
*/
#include <assert.h>
@@ -36,8 +36,11 @@
case CLOCK_REALTIME:
case CLOCK_PROCESS_CPUTIME:
case CLOCK_THREAD_CPUTIME:
- if ( res )
- _POSIX_Interval_to_timespec( _TOD_Microseconds_per_tick, res );
+ if ( res ) {
+ res->tv_sec = _TOD_Microseconds_per_tick / 1000000;
+ res->tv_nsec = _TOD_Microseconds_per_tick * 1000;
+ /* _POSIX_Interval_to_timespec( _TOD_Microseconds_per_tick, res ); */
+ }
break;
default:
> ------------------
> Bug description:
>
> The function clock_getres should calculate the resolution of a time unit. The
> result is stored in a timespec structure. The operating system stores the timer
> resolution in _TOD_Microseconds_per_tick.
>
> clockgetres.c:40 reads:
> >> _POSIX_Interval_to_timespec( _TOD_Microseconds_per_tick, res );
>
> The function _POSIX_Interval_to_timespec expects "ticks" and calculates the
> corresponding time in microsecons with the line
> >> usecs = ticks * _TOD_Microseconds_per_tick;
>
> So the abstract effect of these calls is:
> >> res = _TOD_Microseconds_per_tick * _TOD_Microseconds_per_tick
>
> So the returned clock resolution is the squared value of the real clock resolution.
>
> ------------------
> Bug fix:
>
> Change line 40 in clockgetres.c to:
> >> _POSIX_Interval_to_timespec( 1, res );
>
> Best regards,
>
> David Polock
--
Joel Sherrill, Ph.D. Director of Research & Development
joel at OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
More information about the users
mailing list