Xorg vs gettimeofday() and clock_gettime()

Jung-uk Kim jkim at FreeBSD.org
Thu Feb 28 21:07:43 UTC 2008


On Wednesday 27 February 2008 04:32 am, Thomas Mueller wrote:
> On Mon, 25 Feb 2008 13:56:40 -0700, John Hein wrote:
> > Xin LI wrote at 12:11 -0800 on Feb 25, 2008:
> >  > Shall we make some source-level change to Xorg (either
> >  > upstream under ifdef FreeBSD or our own port, _FAST clocks are
> >  > not available on some other operating systems) so that we can
> >  > override the gettimeofday() direct calls and X_GETTIMEOFDAY's
> >  > to use clock_gettime with a faster clock?
> >
> > Sounds good to me.
> > I vote for putting in a patch in the x11-servers/xorg-server port
> > so it gets some quick exposure and then feeding it back upstream
> > where it can be added on their schedule.
>
> FWIW, xorg already has support for clock_gettime(CLOCK_MONOTONIC)
> in xorg-server-1.4/os/utils.c:
>
>  _X_EXPORT CARD32
>  GetTimeInMillis(void)
>  {
>     struct timeval tv;
>
>  #ifdef MONOTONIC_CLOCK
>     struct timespec tp;
>     if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
>         return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
>  #endif
>
>     X_GETTIMEOFDAY(&tv);
>     return(tv.tv_sec * 1000) + (tv.tv_usec / 1000);
>  }
>
> Apparently the autoconf check for presence of CLOCK_MONOTONIC fails
> on FreeBSD:
>
>  #define _POSIX_C_SOURCE 199309L
>  #include <time.h>
>
>  int main(int argc, char *argv[]) {
>     struct timespec tp;
>
>     if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
>         return 0;
>     else
>         return 1;
>  }
>
> /usr/include/time.h:
>  #if !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112
>  #define CLOCK_REALTIME  0
>  [...]
>  #define CLOCK_MONOTONIC 4
>
> Was CLOCK_MONOTONIC already defined for _POSIX_C_SOURCE 199309?

So this test was introduced in the following commit:

http://lists.freedesktop.org/archives/xorg-commit/2006-November/009390.html

Google found me this:

http://www.opengroup.org/austin/mailarchives/ag-review/msg00489.html

'The recently-approved 1003.1j-2000 adds CLOCK_MONOTONIC to the list.'

I think 1003.1b-1993 added clock_gettime(2) and configure.ac tests 
bogus spec.

Jung-uk Kim


More information about the freebsd-x11 mailing list