gallium/os: Cleanup up os_time_get/os_time_get_nano.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 5 Dec 2012 08:59:21 +0000 (08:59 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 6 Dec 2012 17:12:31 +0000 (17:12 +0000)
- Re-implement os_time_get in terms of os_time_get_nano() for consistency
- Use CLOCK_MONOTONIC as recommended
- Only use clock_gettime on Linux for now.

Reviewed-by: Brian Paul <brianp@vmware.com>
scons/gallium.py
src/gallium/auxiliary/os/os_time.c
src/gallium/auxiliary/os/os_time.h

index 66ccaea7359d4734756569774f60b2544138f7cc..98671f75d2f0f6a4e05f0c619b8ff3bb8d2dc740 100755 (executable)
@@ -500,7 +500,7 @@ def generate(env):
     libs = []
     if env['platform'] in ('darwin', 'freebsd', 'linux', 'posix', 'sunos'):
         libs += ['m', 'pthread', 'dl']
-    if env['platform'] in 'linux':
+    if env['platform'] in ('linux',):
         libs += ['rt']
     env.Append(LIBS = libs)
 
index f943e0f3162f3b1c6380cb8505ad9f1ec7a21dc7..3612eba26808c2ea36c999500f2ab7f95428b7f2 100644 (file)
 
 
 int64_t
-os_time_get(void)
+os_time_get_nano(void)
 {
-#if defined(PIPE_OS_UNIX)
+#if defined(PIPE_OS_LINUX)
+
+   struct timespec tv;
+   clock_gettime(CLOCK_MONOTONIC, &tv);
+   return tv.tv_nsec + tv.tv_sec*INT64_C(1000000000);
+
+#elif defined(PIPE_OS_UNIX)
 
    struct timeval tv;
    gettimeofday(&tv, NULL);
-   return tv.tv_usec + tv.tv_sec*1000000LL;
+   return tv.tv_usec*INT64_C(1000) + tv.tv_sec*INT64_C(1000000000);
 
 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
 
@@ -63,22 +69,12 @@ os_time_get(void)
    if(!frequency.QuadPart)
       QueryPerformanceFrequency(&frequency);
    QueryPerformanceCounter(&counter);
-   return counter.QuadPart*INT64_C(1000000)/frequency.QuadPart;
-
-#endif
-}
+   return counter.QuadPart*INT64_C(1000000000)/frequency.QuadPart;
 
+#else
 
-uint64_t
-os_time_get_nano(void)
-{
-#if defined(PIPE_OS_UNIX)
-   struct timespec tv;
-   clock_gettime(CLOCK_REALTIME, &tv);
-   return tv.tv_nsec + tv.tv_sec * 1000000000LL;
+#error Unsupported OS
 
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-   return os_time_get() * 1000;
 #endif
 }
 
index 54101a1f546619ec41fa8db3d04b785b613196c9..517de9b04746c1d6ed8b03f7d4fe0f4eb91f4fe3 100644 (file)
@@ -51,17 +51,19 @@ extern "C" {
 
 
 /*
- * Get the current time in microseconds from an unknown base.
+ * Get the current time in nanoseconds from an unknown base.
  */
 int64_t
-os_time_get(void);
+os_time_get_nano(void);
 
 
 /*
- * Get the current time in nanoseconds from an unknown base.
+ * Get the current time in microseconds from an unknown base.
  */
-uint64_t
-os_time_get_nano(void);
+static INLINE int64_t
+os_time_get(void) {
+    return os_time_get_nano() * 1000;
+}
 
 
 /*