Xorg vs gettimeofday() and clock_gettime()
Thomas Mueller
tmueller at sysgo.com
Wed Feb 27 10:01:05 UTC 2008
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?
--
Thomas Mueller
More information about the freebsd-x11
mailing list