CLOCK_MONOTONIC substitution for uclibc?

Peter Kjellerstedt peter.kjellerstedt at axis.com
Sat Sep 27 11:01:08 UTC 2008


> -----Original Message-----
> From: Steven Woody [mailto:narkewoody at gmail.com]
> Sent: den 27 september 2008 03:40
> To: Peter Kjellerstedt
> Subject: Re: CLOCK_MONOTONIC substitution for uclibc?
>
> On Fri, Sep 26, 2008 at 3:37 PM, Peter Kjellerstedt
> <peter.kjellerstedt at axis.com> wrote:
> >> -----Original Message-----
> >> From: uclibc-bounces at uclibc.org [mailto:uclibc-bounces at uclibc.org]
> On
> >> Behalf Of Joakim Tjernlund
> >> Sent: den 26 september 2008 09:14
> >> To: Steven Woody
> >> Cc: uclibc at uclibc.org
> >> Subject: Re: CLOCK_MONOTONIC substitution for uclibc?
> >>
> >> On Fri, 2008-09-26 at 13:30 +0800, Steven Woody wrote:
> >> > Hi,
> >> >
> >> > I see even though uclibc implemented clock_gettime(clock_id, tp),
> it
> >> > does not support clock type of CLOCK_MONOTONIC.  So if I want some
> >> > kind of monotonic time which should not changed by user process (
> >> > such as setting of date), what should I do?
> >>
> >> Use "ticks = times(NULL)", NULL can only be used on Linux.
> >>
> >>  Jocke
> >
> > We use CLOCK_MONOTONIC with uClibc without any problem...
> > What version of uClibc are you using, and what architecture?
>
> Here is 0.9.29, are you sure you are using it without problem? Below
> is from 0.9.29's code
> (uClibc-0.9.29/libc/sysdeps/linux/common/clock_gettime.c):
>
> int clock_gettime(clockid_t clock_id, struct timespec* tp)
> {
>     struct timeval tv;
>     int retval = -1;
>     switch (clock_id) {
>         case CLOCK_REALTIME:
>             retval = gettimeofday(&tv, NULL);
>             if (retval == 0) {
>                 TIMEVAL_TO_TIMESPEC(&tv, tp);
>             }
>             break;
>         default:
>             errno = EINVAL;
>             break;
>     }
>     return retval;
> }
>
>
> What version are you using?  Thanks.
>
> -
> narke

You missed the following three lines above that code:

#ifdef __NR_clock_gettime
_syscall2(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp);
#else

Thus, the use of CLOCK_MONOTONIC with uClibc relies on clock_gettime()
being available as a system call from the kernel (which it obviously
is in the 2.6 kernel we use).

//Peter




More information about the uClibc mailing list