Mesa (master): gallium/os: Cleanup up os_time_get/os_time_get_nano.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Thu Dec 6 17:13:21 UTC 2012


Module: Mesa
Branch: master
Commit: d296326e065ed9685bd27d62a3ba20d8a8996e6f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d296326e065ed9685bd27d62a3ba20d8a8996e6f

Author: José Fonseca <jfonseca at vmware.com>
Date:   Wed Dec  5 08:59:21 2012 +0000

gallium/os: Cleanup up os_time_get/os_time_get_nano.

- 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 at vmware.com>

---

 scons/gallium.py                   |    2 +-
 src/gallium/auxiliary/os/os_time.c |   28 ++++++++++++----------------
 src/gallium/auxiliary/os/os_time.h |   12 +++++++-----
 3 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/scons/gallium.py b/scons/gallium.py
index 66ccaea..98671f7 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -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)
 
diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c
index f943e0f..3612eba 100644
--- a/src/gallium/auxiliary/os/os_time.c
+++ b/src/gallium/auxiliary/os/os_time.c
@@ -48,13 +48,19 @@
 
 
 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
 }
 
diff --git a/src/gallium/auxiliary/os/os_time.h b/src/gallium/auxiliary/os/os_time.h
index 54101a1..517de9b 100644
--- a/src/gallium/auxiliary/os/os_time.h
+++ b/src/gallium/auxiliary/os/os_time.h
@@ -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;
+}
 
 
 /*




More information about the mesa-commit mailing list