[Mesa-dev] [PATCH] gallium/os: fixup os_time_get and os_time_get_nano
Jose Fonseca
jfonseca at vmware.com
Tue Dec 4 05:29:58 PST 2012
Maybe we should be inclusive, i.e., only set HAVE_CLOCK_GETTIME on platforms we know it exists like linux. This is what apitrace has currently: https://github.com/apitrace/apitrace/blob/master/common/os_time.hpp#L64 .
Either way,
Reviewed-by: Jose Fonseca <jfonseca at vmware.com>
Jose
----- Original Message -----
> So it appears MacOSX doesn't have clock_gettime, so workaround
> that, and switch to using a consistent clock everywhere,
> (CLOCK_MONOTONIC in case of non-MacOSX UNIX).
>
> I'm sure there are more surprised lying in wait.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
> src/gallium/auxiliary/os/os_time.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/src/gallium/auxiliary/os/os_time.c
> b/src/gallium/auxiliary/os/os_time.c
> index 4055125..d3fc805 100644
> --- a/src/gallium/auxiliary/os/os_time.c
> +++ b/src/gallium/auxiliary/os/os_time.c
> @@ -46,11 +46,22 @@
>
> #include "os_time.h"
>
> +#if defined(PIPE_OS_UNIX) && !defined(PIPE_OS_APPLE)
> +/* MacOSX doesn't have clock_gettime, not sure about other UNIX/HURD
> */
> +#define HAVE_CLOCK_GETTIME 1
> +#endif
>
> +/*
> + * when we have clock_gettime use get nano to define time get,
> + * when we don't have it work vice-versa, should avoid extra
> + * conversions.
> + */
> int64_t
> os_time_get(void)
> {
> -#if defined(PIPE_OS_UNIX)
> +#if defined(HAVE_CLOCK_GETTIME)
> + return os_time_get_nano() / 1000;
> +#elif defined(PIPE_UNIX)
>
> struct timeval tv;
> gettimeofday(&tv, NULL);
> @@ -72,12 +83,11 @@ os_time_get(void)
> uint64_t
> os_time_get_nano(void)
> {
> -#if defined(PIPE_OS_UNIX)
> +#if defined(HAVE_CLOCK_GETTIME)
> struct timespec tv;
> - clock_gettime(CLOCK_REALTIME, &tv);
> + clock_gettime(CLOCK_MONOTONIC, &tv);
> return tv.tv_nsec + tv.tv_sec * 1000000000LL;
> -
> -#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
> +#else
> return os_time_get() * 1000;
> #endif
> }
> --
> 1.7.11.7
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list