util: move os_time.[ch] to src/util
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Sun, 22 Oct 2017 15:38:44 +0000 (17:38 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 9 Nov 2017 10:57:21 +0000 (11:57 +0100)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
59 files changed:
src/gallium/auxiliary/Makefile.sources
src/gallium/auxiliary/gallivm/lp_bld_init.c
src/gallium/auxiliary/hud/hud_cpu.c
src/gallium/auxiliary/hud/hud_cpufreq.c
src/gallium/auxiliary/hud/hud_diskstat.c
src/gallium/auxiliary/hud/hud_driver_query.c
src/gallium/auxiliary/hud/hud_fps.c
src/gallium/auxiliary/hud/hud_nic.c
src/gallium/auxiliary/hud/hud_sensors_temp.c
src/gallium/auxiliary/meson.build
src/gallium/auxiliary/os/os_time.c [deleted file]
src/gallium/auxiliary/os/os_time.h [deleted file]
src/gallium/auxiliary/util/u_time.h
src/gallium/drivers/ddebug/dd_draw.c
src/gallium/drivers/etnaviv/etnaviv_query_sw.c
src/gallium/drivers/etnaviv/etnaviv_screen.c
src/gallium/drivers/freedreno/freedreno_query_sw.c
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/llvmpipe/lp_query.c
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_screen.c
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/llvmpipe/lp_state_setup.c
src/gallium/drivers/nouveau/nouveau_fence.c
src/gallium/drivers/nouveau/nouveau_screen.c
src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_flush.c
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r600/r600_gpu_load.c
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/r600/r600_pipe_common.c
src/gallium/drivers/r600/r600_query.c
src/gallium/drivers/r600/r600_texture.c
src/gallium/drivers/r600/sb/sb_core.cpp
src/gallium/drivers/radeon/r600_gpu_load.c
src/gallium/drivers/radeon/r600_pipe_common.c
src/gallium/drivers/radeon/r600_query.c
src/gallium/drivers/radeon/r600_texture.c
src/gallium/drivers/rbug/rbug_core.c
src/gallium/drivers/softpipe/sp_query.c
src/gallium/drivers/softpipe/sp_screen.c
src/gallium/drivers/svga/svga_context.h
src/gallium/drivers/swr/swr_fence.cpp
src/gallium/drivers/swr/swr_query.cpp
src/gallium/drivers/trace/tr_dump.c
src/gallium/drivers/virgl/virgl_screen.c
src/gallium/state_trackers/wgl/stw_framebuffer.c
src/gallium/tests/unit/pipe_barrier_test.c
src/gallium/winsys/amdgpu/drm/amdgpu_bo.c
src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
src/gallium/winsys/radeon/drm/radeon_drm_bo.c
src/gallium/winsys/radeon/drm/radeon_drm_cs.c
src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c
src/util/Makefile.sources
src/util/meson.build
src/util/os_time.c [new file with mode: 0644]
src/util/os_time.h [new file with mode: 0644]

index 0502a2c44f800b8cd63336e384adffbca5c29d79..4fb7a30613a36ec80f283db85d2a9730bc6c519c 100644 (file)
@@ -83,8 +83,6 @@ C_SOURCES := \
        os/os_process.c \
        os/os_process.h \
        os/os_thread.h \
-       os/os_time.c \
-       os/os_time.h \
        pipebuffer/pb_buffer_fenced.c \
        pipebuffer/pb_buffer_fenced.h \
        pipebuffer/pb_buffer.h \
index c456a97eb627d20e977776817c249d804aa54d8f..6ddc509a813529f86a64428ee73c984c7d992d78 100644 (file)
@@ -32,7 +32,7 @@
 #include "util/u_debug.h"
 #include "util/u_memory.h"
 #include "util/simple_list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "lp_bld.h"
 #include "lp_bld_debug.h"
 #include "lp_bld_misc.h"
index 4caaab6977e1d854458167a9d2fe6365564b2da3..581dad6df049fa2cb0e643ce66555bf85f4c00df 100644 (file)
@@ -29,7 +29,7 @@
  */
 
 #include "hud/hud_private.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "os/os_thread.h"
 #include "util/u_memory.h"
 #include "util/u_queue.h"
index abb930d7e288fce179b1ed041ebcfcbd1769ee2f..2b881a850e3ceb80d2a49bc9d7355b8903cd9a84 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "hud/hud_private.h"
 #include "util/list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "os/os_thread.h"
 #include "util/u_memory.h"
 #include <stdio.h>
index df86abd12d88615bbc0054f71836878404097da6..53b32baef226d663f64b8ad779b481d24a7438fc 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "hud/hud_private.h"
 #include "util/list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "os/os_thread.h"
 #include "util/u_memory.h"
 #include <stdio.h>
index 76104b5b497a46387cd31c709dc9b6fb6578329d..8b1e4e104a7e10e4250f3b4583f5461374be3f90 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "hud/hud_private.h"
 #include "pipe/p_screen.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include <stdio.h>
index 8aa7a665a30fe51fac5e654e1fafc5d6d1ceb70d..aecbaf0f6b48d8ac56b91c14d42b632be77a4fcf 100644 (file)
@@ -29,7 +29,7 @@
  */
 
 #include "hud/hud_private.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "util/u_memory.h"
 
 struct fps_info {
index 835f92e2e04d0540b5ab594667eb11407e37ebe0..bb29a90dbcab9eea14ec960562b7592213e5da6f 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "hud/hud_private.h"
 #include "util/list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "os/os_thread.h"
 #include "util/u_memory.h"
 #include <stdio.h>
index 29ee257ce86e5ce54ddbad42cbd9dd7e16afe337..7ae6f71b55c81216140cbeae79bef1d9a0f035bc 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "hud/hud_private.h"
 #include "util/list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "os/os_thread.h"
 #include "util/u_memory.h"
 #include <stdio.h>
index 948fb86b3b2017637197874b366481fcd1c7cfcc..d8fdd3510f1d6e137548fa961a1090b0dae9860e 100644 (file)
@@ -103,8 +103,6 @@ files_libgallium = files(
   'os/os_process.c',
   'os/os_process.h',
   'os/os_thread.h',
-  'os/os_time.c',
-  'os/os_time.h',
   'pipebuffer/pb_buffer_fenced.c',
   'pipebuffer/pb_buffer_fenced.h',
   'pipebuffer/pb_buffer.h',
diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c
deleted file mode 100644 (file)
index e4a1cae..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008-2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-/**
- * @file
- * OS independent time-manipulation functions.
- * 
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-
-#include "pipe/p_defines.h"
-#include "util/u_atomic.h"
-
-#if defined(PIPE_OS_UNIX)
-#  include <time.h> /* timeval */
-#  include <sys/time.h> /* timeval */
-#  include <sched.h> /* sched_yield */
-#  include <errno.h>
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-#  include <windows.h>
-#else
-#  error Unsupported OS
-#endif
-
-#include "os_time.h"
-
-
-int64_t
-os_time_get_nano(void)
-{
-#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*INT64_C(1000) + tv.tv_sec*INT64_C(1000000000);
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-
-   static LARGE_INTEGER frequency;
-   LARGE_INTEGER counter;
-   int64_t secs, nanosecs;
-   if(!frequency.QuadPart)
-      QueryPerformanceFrequency(&frequency);
-   QueryPerformanceCounter(&counter);
-   /* Compute seconds and nanoseconds parts separately to
-    * reduce severity of precision loss.
-    */
-   secs = counter.QuadPart / frequency.QuadPart;
-   nanosecs = (counter.QuadPart % frequency.QuadPart) * INT64_C(1000000000)
-      / frequency.QuadPart;
-   return secs*INT64_C(1000000000) + nanosecs;
-
-#else
-
-#error Unsupported OS
-
-#endif
-}
-
-
-
-void
-os_time_sleep(int64_t usecs)
-{
-#if defined(PIPE_OS_LINUX)
-   struct timespec time;
-   time.tv_sec = usecs / 1000000;
-   time.tv_nsec = (usecs % 1000000) * 1000;
-   while (clock_nanosleep(CLOCK_MONOTONIC, 0, &time, &time) == EINTR);
-
-#elif defined(PIPE_OS_UNIX)
-   usleep(usecs);
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-   DWORD dwMilliseconds = (DWORD) ((usecs + 999) / 1000);
-   /* Avoid Sleep(O) as that would cause to sleep for an undetermined duration */
-   if (dwMilliseconds) {
-      Sleep(dwMilliseconds);
-   }
-#else
-#  error Unsupported OS
-#endif
-}
-
-
-
-int64_t
-os_time_get_absolute_timeout(uint64_t timeout)
-{
-   int64_t time, abs_timeout;
-
-   /* Also check for the type upper bound. */
-   if (timeout == PIPE_TIMEOUT_INFINITE || timeout > INT64_MAX)
-      return PIPE_TIMEOUT_INFINITE;
-
-   time = os_time_get_nano();
-   abs_timeout = time + (int64_t)timeout;
-
-   /* Check for overflow. */
-   if (abs_timeout < time)
-      return PIPE_TIMEOUT_INFINITE;
-
-   return abs_timeout;
-}
-
-
-bool
-os_wait_until_zero(volatile int *var, uint64_t timeout)
-{
-   if (!p_atomic_read(var))
-      return true;
-
-   if (!timeout)
-      return false;
-
-   if (timeout == PIPE_TIMEOUT_INFINITE) {
-      while (p_atomic_read(var)) {
-#if defined(PIPE_OS_UNIX)
-         sched_yield();
-#endif
-      }
-      return true;
-   }
-   else {
-      int64_t start_time = os_time_get_nano();
-      int64_t end_time = start_time + timeout;
-
-      while (p_atomic_read(var)) {
-         if (os_time_timeout(start_time, end_time, os_time_get_nano()))
-            return false;
-
-#if defined(PIPE_OS_UNIX)
-         sched_yield();
-#endif
-      }
-      return true;
-   }
-}
-
-
-bool
-os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout)
-{
-   if (!p_atomic_read(var))
-      return true;
-
-   if (timeout == PIPE_TIMEOUT_INFINITE)
-      return os_wait_until_zero(var, PIPE_TIMEOUT_INFINITE);
-
-   while (p_atomic_read(var)) {
-      if (os_time_get_nano() >= timeout)
-         return false;
-
-#if defined(PIPE_OS_UNIX)
-      sched_yield();
-#endif
-   }
-   return true;
-}
diff --git a/src/gallium/auxiliary/os/os_time.h b/src/gallium/auxiliary/os/os_time.h
deleted file mode 100644 (file)
index ca0bdd5..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008-2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-/**
- * @file
- * OS independent time-manipulation functions.
- * 
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-#ifndef _OS_TIME_H_
-#define _OS_TIME_H_
-
-
-#include "pipe/p_config.h"
-
-#if defined(PIPE_OS_UNIX)
-#  include <unistd.h> /* usleep */
-#endif
-
-#include "pipe/p_compiler.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*
- * Get the current time in nanoseconds from an unknown base.
- */
-int64_t
-os_time_get_nano(void);
-
-
-/*
- * Get the current time in microseconds from an unknown base.
- */
-static inline int64_t
-os_time_get(void)
-{
-   return os_time_get_nano() / 1000;
-}
-
-
-/*
- * Sleep.
- */
-void
-os_time_sleep(int64_t usecs);
-
-
-/*
- * Helper function for detecting time outs, taking in account overflow.
- *
- * Returns true if the current time has elapsed beyond the specified interval.
- */
-static inline boolean
-os_time_timeout(int64_t start,
-                int64_t end,
-                int64_t curr)
-{
-   if (start <= end)
-      return !(start <= curr && curr < end);
-   else
-      return !((start <= curr) || (curr < end));
-}
-
-
-/**
- * Convert a relative timeout in nanoseconds into an absolute timeout,
- * in other words, it returns current time + timeout.
- * os_time_get_nano() must be monotonic.
- * PIPE_TIMEOUT_INFINITE is passed through unchanged. If the calculation
- * overflows, PIPE_TIMEOUT_INFINITE is returned.
- */
-int64_t
-os_time_get_absolute_timeout(uint64_t timeout);
-
-
-/**
- * Wait until the variable at the given memory location is zero.
- *
- * \param var           variable
- * \param timeout       timeout in ns, can be anything from 0 (no wait) to
- *                      PIPE_TIME_INFINITE (wait forever)
- * \return     true if the variable is zero
- */
-bool
-os_wait_until_zero(volatile int *var, uint64_t timeout);
-
-
-/**
- * Wait until the variable at the given memory location is zero.
- * The timeout is the absolute time when the waiting should stop. If it is
- * less than or equal to the current time, it only returns the status and
- * doesn't wait. PIPE_TIME_INFINITE waits forever. This requires that
- * os_time_get_nano is monotonic.
- *
- * \param var       variable
- * \param timeout   the time in ns when the waiting should stop
- * \return     true if the variable is zero
- */
-bool
-os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _OS_TIME_H_ */
index a5017d6bce218d0ee8c1c4181adbd6770b1f61f0..99fa1400511107e1ab7e13d09a2b8d6101c6a0e9 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "pipe/p_config.h"
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include "pipe/p_compiler.h"
 
index aec9332d903c1badbc50782dd7128276b491a3ac..a15801beb1db65d2d35c20ec50c4f7749712f58d 100644 (file)
@@ -35,7 +35,7 @@
 #include "util/u_memory.h"
 #include "tgsi/tgsi_parse.h"
 #include "tgsi/tgsi_scan.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include <inttypes.h>
 
 
index dd9bac38501f342901a41f99cc19e17194d6cdf5..2e65065b285d5c537694ea070648d962386dcb38 100644 (file)
@@ -25,7 +25,7 @@
  *    Christian Gmeiner <christian.gmeiner@gmail.com>
  */
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "pipe/p_state.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
index b0c4b7ba471060aa23fe9c1511532437eb678b45..30beb412d9d7aef472f7da9e3946f0a794fa3dd9 100644 (file)
@@ -38,7 +38,7 @@
 #include "etnaviv_resource.h"
 #include "etnaviv_translate.h"
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
index dfa898723972fbb5a71b319e69c2a348746f839d..50965161146ea6da83b55e32b840e83b620a7659 100644 (file)
@@ -30,7 +30,7 @@
 #include "util/u_string.h"
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include "freedreno_query_sw.h"
 #include "freedreno_context.h"
index e5504b6b386cfc679d16d9979128018291bd9abb..5bb1e20c7807ee90ae4704fa3159507fd924cec1 100644 (file)
@@ -38,7 +38,7 @@
 #include "util/u_string.h"
 #include "util/u_debug.h"
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include <stdio.h>
 #include <errno.h>
index 7b81903b413f5fdc73859df54d7f12e3169cad4d..ad11d8ca53fe2e092da3ae045e08d83f8e34a72b 100644 (file)
@@ -33,7 +33,7 @@
 #include "draw/draw_context.h"
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "lp_context.h"
 #include "lp_flush.h"
 #include "lp_fence.h"
index 9e2780ca1d72441965c2c4fd71f617694aea8ccf..939944aa791359e36fb0b5ff0e3d1de6d98f81a0 100644 (file)
@@ -34,7 +34,7 @@
 #include "util/u_string.h"
 #include "util/u_thread.h"
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include "lp_scene_queue.h"
 #include "lp_context.h"
index ee377dc61f83055438e5b4caa20857027fbba93c..bd5876994d318e38c481108806bd7bd79cd056ef 100644 (file)
@@ -38,7 +38,7 @@
 #include "gallivm/lp_bld_type.h"
 
 #include "os/os_misc.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "lp_texture.h"
 #include "lp_fence.h"
 #include "lp_jit.h"
index 2be6fc033d1d21e324f2f38e183988cbdd7e2b72..c1573231335c0bafbf7835ea6d1883b7cd763665 100644 (file)
@@ -41,7 +41,7 @@
 #include "util/u_pack_color.h"
 #include "util/u_viewport.h"
 #include "draw/draw_pipe.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "lp_context.h"
 #include "lp_memory.h"
 #include "lp_scene.h"
index 9223ce63e3ac51fb658d0ca1ab2364c670cd5b6b..0daf7aecf6e2bf28f2457ca7cceb18e551922753 100644 (file)
@@ -67,7 +67,7 @@
 #include "util/u_string.h"
 #include "util/simple_list.h"
 #include "util/u_dual_blend.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "pipe/p_shader_tokens.h"
 #include "draw/draw_context.h"
 #include "tgsi/tgsi_dump.h"
index 6b0df21b8adaa777366eca43e9879ad45d70ed92..77c7ac1bbde585e2a4717f2998c5088dbb814b0e 100644 (file)
@@ -29,7 +29,7 @@
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/simple_list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "gallivm/lp_bld_arit.h"
 #include "gallivm/lp_bld_bitarit.h"
 #include "gallivm/lp_bld_const.h"
index 6c299cbc6a5a6c5913ddbdf4c7e32eb8c79fb647..d14c59b2dd15d271a3e2bbd45863f0c14bb84569 100644 (file)
@@ -23,7 +23,7 @@
 #include "nouveau_screen.h"
 #include "nouveau_winsys.h"
 #include "nouveau_fence.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #ifdef PIPE_OS_UNIX
 #include <sched.h>
index ea68809c6e8ed97afe9f6d002fadc6e659c7e384..c144b39b2dd2d1ade24424182cbd19351a7ce7f8 100644 (file)
@@ -8,7 +8,7 @@
 #include "util/u_format_s3tc.h"
 #include "util/u_string.h"
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include <stdio.h>
 #include <errno.h>
index 6f4231d76e31ac81963a5de612e9e135bc35a4a5..b55fb63f000b589bbfc6adda832ffa7924ad029b 100644 (file)
@@ -26,7 +26,7 @@
 #include "util/u_sampler.h"
 #include "util/simple_list.h"
 #include "util/u_upload_mgr.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "vl/vl_decoder.h"
 #include "vl/vl_video_buffer.h"
 
index 54108d1cdfbc70f4c7cf3ce1f000e4ae7540ae85..7fabd13f3d7943b07c141d33967e5c0da72f351a 100644 (file)
@@ -27,7 +27,7 @@
 #include "util/simple_list.h"
 #include "util/u_upload_mgr.h"
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include "r300_context.h"
 #include "r300_cs.h"
index 72ba0ff84e3bf748898a59f4487b58c6d479324e..b9b2d7d8382f021927c804a80f02508e6ce46a6e 100644 (file)
@@ -24,7 +24,7 @@
 #include "util/u_format.h"
 #include "util/u_format_s3tc.h"
 #include "util/u_memory.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "vl/vl_decoder.h"
 #include "vl/vl_video_buffer.h"
 
index c15fb9dfa06f2ed0f80691cb28b1f96cb1b22648..a2de8cc71a4a3bdbf566c3ec3d34127a15e24e5a 100644 (file)
@@ -36,7 +36,7 @@
 
 #include "r600_pipe_common.h"
 #include "r600_query.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 /* For good accuracy at 1000 fps or lower. This will be inaccurate for higher
  * fps (there are too few samples per frame). */
index e639d928830b648771925b277adbd84223dc502e..2381c5b7d00ca278cf52a8875813df7bd1403f06 100644 (file)
@@ -39,7 +39,7 @@
 #include "vl/vl_video_buffer.h"
 #include "radeon_video.h"
 #include "radeon_uvd.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 static const struct debug_named_value r600_debug_options[] = {
        /* features */
index acad670d6faabb42ca9d9f7fbac08c6fb7b257d5..e2d0e32bb2bb5773ac5a2469862164b484ebaf6a 100644 (file)
@@ -32,7 +32,7 @@
 #include "util/u_memory.h"
 #include "util/u_format_s3tc.h"
 #include "util/u_upload_mgr.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "vl/vl_decoder.h"
 #include "vl/vl_video_buffer.h"
 #include "radeon_video.h"
index aa3e36f56f7ce17c6c61b06cd4e5c5cb347d2f6d..9c17c3ba23e1150080319e2413bf725db39f8eec 100644 (file)
@@ -27,7 +27,7 @@
 #include "r600_cs.h"
 #include "util/u_memory.h"
 #include "util/u_upload_mgr.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "tgsi/tgsi_text.h"
 
 #define R600_MAX_STREAMS 4
index b84111449000d1c16478c9c73e956d96acd80586..3515d979d9ef5e25ec1457fea80f5ff39303f60d 100644 (file)
@@ -32,7 +32,7 @@
 #include "util/u_memory.h"
 #include "util/u_pack_color.h"
 #include "util/u_surface.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include <errno.h>
 #include <inttypes.h>
 
index afea8188f1c143f890446d054ad14d1b65ac97d9..cdc2862d36df2fa7cd6ac7523d959034013a594e 100644 (file)
@@ -26,7 +26,7 @@
 
 #define SB_RA_SCHED_CHECK DEBUG
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "r600_pipe.h"
 #include "r600_shader.h"
 
index ccbd1c918644833f606f6e1d05dadb415227e913..411dcfe8724f73d2c23b0c0dfecf96a44ea0efa9 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "r600_pipe_common.h"
 #include "r600_query.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 /* For good accuracy at 1000 fps or lower. This will be inaccurate for higher
  * fps (there are too few samples per frame). */
index c9502182a7ebee497e6da172eac6a6bc82b6eaa4..5d8214118a1312fcf51ce5c51a10b77d7688d210 100644 (file)
@@ -29,7 +29,7 @@
 #include "util/u_memory.h"
 #include "util/u_format_s3tc.h"
 #include "util/u_upload_mgr.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "vl/vl_decoder.h"
 #include "vl/vl_video_buffer.h"
 #include "radeon/radeon_video.h"
index aedf950ff2decbaf8e89cc35d1241a175eb00ae4..0a03061ab9199c0c92a9321337be69907365005c 100644 (file)
@@ -26,7 +26,7 @@
 #include "r600_cs.h"
 #include "util/u_memory.h"
 #include "util/u_upload_mgr.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "tgsi/tgsi_text.h"
 #include "amd/common/sid.h"
 
index 0800c0f1d1c0c6e58659ef1db2db6037e2df3d31..258690cadf5b29450323b71417f62084d99a9b98 100644 (file)
@@ -28,7 +28,7 @@
 #include "util/u_memory.h"
 #include "util/u_pack_color.h"
 #include "util/u_surface.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include <errno.h>
 #include <inttypes.h>
 #include "state_tracker/drm_driver.h"
index 82bcef8d03b2c8fc8f9564d0dd4f1951694a10a4..8eb39c17b14cb6e10eaece7346e5f733f3fb5974 100644 (file)
@@ -33,7 +33,7 @@
 #include "util/u_memory.h"
 #include "util/simple_list.h"
 #include "util/u_network.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include "tgsi/tgsi_parse.h"
 
index 267c99977fe528ac3e8aff8dccfb249aa38884d7..5c9afe6fe47ea0898924630b09836042081ac425 100644 (file)
@@ -30,7 +30,7 @@
  */
 
 #include "draw/draw_context.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
 #include "sp_context.h"
index 356ebf4e83311060e449e6b86f6cb06cc84cd362..08efd14fbe0f22b1e94a24b1bc6f7c32b16407a3 100644 (file)
@@ -31,7 +31,7 @@
 #include "util/u_format_s3tc.h"
 #include "util/u_video.h"
 #include "os/os_misc.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_screen.h"
 #include "draw/draw_context.h"
index 0d695a6492741151314ef48e5dbbd2f5d9cd0ab6..80c59c05e86d956d0d66a52bbe637975cd50e7e5 100644 (file)
@@ -31,7 +31,7 @@
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include "util/u_blitter.h"
 #include "util/list.h"
index abf1d0c69c8701925a37349f5d4d16229c3edc79..3005eb9aaadd61dd82b92f2ea182d9cebae9273a 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "pipe/p_screen.h"
 #include "util/u_memory.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include "swr_context.h"
 #include "swr_screen.h"
index e3697304e0566779a8b0ed77768a569edf0f631b..ea31de630b3075199d9f1a9f4cce8ceddf42c3be 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "swr_context.h"
 #include "swr_fence.h"
 #include "swr_query.h"
index 2003222cc1cf6af7e19c458de1ef6929174e3eeb..49349496ac6cbac3b2ba0b94659c71c1b0da7fe1 100644 (file)
@@ -45,7 +45,7 @@
 
 #include "pipe/p_compiler.h"
 #include "os/os_thread.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "util/u_debug.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
index 56520156891da9886a75162dded6656a1d2f2f1c..1646e7ee025cf92dfa74066127a99d4c03fa40c4 100644 (file)
@@ -24,7 +24,7 @@
 #include "util/u_format.h"
 #include "util/u_format_s3tc.h"
 #include "util/u_video.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_screen.h"
 
index 06b5c8da3c24d008a9a9964bafb3dea67d2554b8..7348ea3ba885713d48454a1b6b6581b6331ce4f8 100644 (file)
@@ -30,7 +30,7 @@
 #include "pipe/p_screen.h"
 #include "util/u_memory.h"
 #include "hud/hud_context.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "state_tracker/st_api.h"
 
 #include "stw_icd.h"
index 6bd46b8d964f8c18fc4bad123e9ff210f7d57fe2..838c9bfd96c6de3e1a87ca4206e85207e0a6d874 100644 (file)
@@ -36,8 +36,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "util/u_atomic.h"
 #include "util/u_thread.h"
 
index d0395a938cefc2d82d2cf3deba817a906d342789..c3e97c2286180b09b0f838fbb2c901a09a69e19a 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "amdgpu_cs.h"
 
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "state_tracker/drm_driver.h"
 #include <amdgpu_drm.h>
 #include <xf86drm.h>
index 0f36cc5ae6307f578331b6ff9a967a3ddfd00847..0a3f0fd6016b134cf96c72a7bba0520a6c4e9089 100644 (file)
@@ -27,7 +27,8 @@
  */
 
 #include "amdgpu_cs.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
+#include <inttypes.h>
 #include <stdio.h>
 
 #include "amd/common/sid.h"
index 15e9d38e33a026f22d8de76428341685eb01196c..b4e501c817fad91b5afd17fbcd63bfcf892e4c65 100644 (file)
@@ -31,7 +31,7 @@
 #include "util/simple_list.h"
 #include "os/os_thread.h"
 #include "os/os_mman.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include "state_tracker/drm_driver.h"
 
index 2b1542fcf484adc59f56777b4b70ef31c684a452..7220f3a0240e50420d8521ee8e655207640e1756 100644 (file)
@@ -56,7 +56,7 @@
 #include "radeon_drm_cs.h"
 
 #include "util/u_memory.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 
 #include <stdio.h>
 #include <stdlib.h>
index 7f542e7f1ff45e780dc5402fb901f6fbc27bc870..71e652ebf31bee58d958ce57f98da86a0209d540 100644 (file)
@@ -28,7 +28,7 @@
 #include <sys/stat.h>
 
 #include "os/os_mman.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "util/u_memory.h"
 #include "util/u_format.h"
 #include "util/u_hash_table.h"
index 404ba58b08dcd38d5d417afb7daa15ba102ebbfa..d76be4d5d32a551825897078f39d6329ae2ce8dd 100644 (file)
@@ -24,7 +24,7 @@
 #include "util/u_memory.h"
 #include "util/u_format.h"
 #include "util/u_inlines.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "state_tracker/sw_winsys.h"
 
 #include "virgl_vtest_winsys.h"
index f8096feb232084d7ec5d66f09c6795cec5d82a9e..104ecae8ed3b3106eb1956547208c9c8d88beef1 100644 (file)
@@ -22,6 +22,8 @@ MESA_UTIL_FILES := \
        macros.h \
        mesa-sha1.c \
        mesa-sha1.h \
+       os_time.c \
+       os_time.h \
        sha1/sha1.c \
        sha1/sha1.h \
        ralloc.c \
index a9ab5bf545c336705c67450681a361f281611d55..ac86c9e111eeb89a0249f4aecacc7c65a2af1327 100644 (file)
@@ -46,6 +46,8 @@ files_mesa_util = files(
   'macros.h',
   'mesa-sha1.c',
   'mesa-sha1.h',
+  'os_time.c',
+  'os_time.h',
   'sha1/sha1.c',
   'sha1/sha1.h',
   'ralloc.c',
diff --git a/src/util/os_time.c b/src/util/os_time.c
new file mode 100644 (file)
index 0000000..8d8291f
--- /dev/null
@@ -0,0 +1,191 @@
+/**************************************************************************
+ *
+ * Copyright 2008-2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * OS independent time-manipulation functions.
+ * 
+ * @author Jose Fonseca <jfonseca@vmware.com>
+ */
+
+#include "os_time.h"
+
+/* TODO: fix this dependency */
+#include "gallium/include/pipe/p_config.h"
+
+#include "util/u_atomic.h"
+
+#if defined(PIPE_OS_UNIX)
+#  include <time.h> /* timeval */
+#  include <sys/time.h> /* timeval */
+#  include <sched.h> /* sched_yield */
+#  include <errno.h>
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+#  include <windows.h>
+#else
+#  error Unsupported OS
+#endif
+
+
+int64_t
+os_time_get_nano(void)
+{
+#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*INT64_C(1000) + tv.tv_sec*INT64_C(1000000000);
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+
+   static LARGE_INTEGER frequency;
+   LARGE_INTEGER counter;
+   int64_t secs, nanosecs;
+   if(!frequency.QuadPart)
+      QueryPerformanceFrequency(&frequency);
+   QueryPerformanceCounter(&counter);
+   /* Compute seconds and nanoseconds parts separately to
+    * reduce severity of precision loss.
+    */
+   secs = counter.QuadPart / frequency.QuadPart;
+   nanosecs = (counter.QuadPart % frequency.QuadPart) * INT64_C(1000000000)
+      / frequency.QuadPart;
+   return secs*INT64_C(1000000000) + nanosecs;
+
+#else
+
+#error Unsupported OS
+
+#endif
+}
+
+
+
+void
+os_time_sleep(int64_t usecs)
+{
+#if defined(PIPE_OS_LINUX)
+   struct timespec time;
+   time.tv_sec = usecs / 1000000;
+   time.tv_nsec = (usecs % 1000000) * 1000;
+   while (clock_nanosleep(CLOCK_MONOTONIC, 0, &time, &time) == EINTR);
+
+#elif defined(PIPE_OS_UNIX)
+   usleep(usecs);
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+   DWORD dwMilliseconds = (DWORD) ((usecs + 999) / 1000);
+   /* Avoid Sleep(O) as that would cause to sleep for an undetermined duration */
+   if (dwMilliseconds) {
+      Sleep(dwMilliseconds);
+   }
+#else
+#  error Unsupported OS
+#endif
+}
+
+
+
+int64_t
+os_time_get_absolute_timeout(uint64_t timeout)
+{
+   int64_t time, abs_timeout;
+
+   /* Also check for the type upper bound. */
+   if (timeout == OS_TIMEOUT_INFINITE || timeout > INT64_MAX)
+      return OS_TIMEOUT_INFINITE;
+
+   time = os_time_get_nano();
+   abs_timeout = time + (int64_t)timeout;
+
+   /* Check for overflow. */
+   if (abs_timeout < time)
+      return OS_TIMEOUT_INFINITE;
+
+   return abs_timeout;
+}
+
+
+bool
+os_wait_until_zero(volatile int *var, uint64_t timeout)
+{
+   if (!p_atomic_read(var))
+      return true;
+
+   if (!timeout)
+      return false;
+
+   if (timeout == OS_TIMEOUT_INFINITE) {
+      while (p_atomic_read(var)) {
+#if defined(PIPE_OS_UNIX)
+         sched_yield();
+#endif
+      }
+      return true;
+   }
+   else {
+      int64_t start_time = os_time_get_nano();
+      int64_t end_time = start_time + timeout;
+
+      while (p_atomic_read(var)) {
+         if (os_time_timeout(start_time, end_time, os_time_get_nano()))
+            return false;
+
+#if defined(PIPE_OS_UNIX)
+         sched_yield();
+#endif
+      }
+      return true;
+   }
+}
+
+
+bool
+os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout)
+{
+   if (!p_atomic_read(var))
+      return true;
+
+   if (timeout == OS_TIMEOUT_INFINITE)
+      return os_wait_until_zero(var, OS_TIMEOUT_INFINITE);
+
+   while (p_atomic_read(var)) {
+      if (os_time_get_nano() >= timeout)
+         return false;
+
+#if defined(PIPE_OS_UNIX)
+      sched_yield();
+#endif
+   }
+   return true;
+}
diff --git a/src/util/os_time.h b/src/util/os_time.h
new file mode 100644 (file)
index 0000000..049ab11
--- /dev/null
@@ -0,0 +1,130 @@
+/**************************************************************************
+ *
+ * Copyright 2008-2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * OS independent time-manipulation functions.
+ * 
+ * @author Jose Fonseca <jfonseca@vmware.com>
+ */
+
+#ifndef _OS_TIME_H_
+#define _OS_TIME_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* must be equal to PIPE_TIMEOUT_INFINITE */
+#define OS_TIMEOUT_INFINITE 0xffffffffffffffffull
+
+/*
+ * Get the current time in nanoseconds from an unknown base.
+ */
+int64_t
+os_time_get_nano(void);
+
+
+/*
+ * Get the current time in microseconds from an unknown base.
+ */
+static inline int64_t
+os_time_get(void)
+{
+   return os_time_get_nano() / 1000;
+}
+
+
+/*
+ * Sleep.
+ */
+void
+os_time_sleep(int64_t usecs);
+
+
+/*
+ * Helper function for detecting time outs, taking in account overflow.
+ *
+ * Returns true if the current time has elapsed beyond the specified interval.
+ */
+static inline bool
+os_time_timeout(int64_t start,
+                int64_t end,
+                int64_t curr)
+{
+   if (start <= end)
+      return !(start <= curr && curr < end);
+   else
+      return !((start <= curr) || (curr < end));
+}
+
+
+/**
+ * Convert a relative timeout in nanoseconds into an absolute timeout,
+ * in other words, it returns current time + timeout.
+ * os_time_get_nano() must be monotonic.
+ * OS_TIMEOUT_INFINITE is passed through unchanged. If the calculation
+ * overflows, OS_TIMEOUT_INFINITE is returned.
+ */
+int64_t
+os_time_get_absolute_timeout(uint64_t timeout);
+
+
+/**
+ * Wait until the variable at the given memory location is zero.
+ *
+ * \param var           variable
+ * \param timeout       timeout in ns, can be anything from 0 (no wait) to
+ *                      OS_TIMEOUT_INFINITE (wait forever)
+ * \return     true if the variable is zero
+ */
+bool
+os_wait_until_zero(volatile int *var, uint64_t timeout);
+
+
+/**
+ * Wait until the variable at the given memory location is zero.
+ * The timeout is the absolute time when the waiting should stop. If it is
+ * less than or equal to the current time, it only returns the status and
+ * doesn't wait. OS_TIMEOUT_INFINITE waits forever. This requires that
+ * os_time_get_nano is monotonic.
+ *
+ * \param var       variable
+ * \param timeout   the time in ns when the waiting should stop
+ * \return     true if the variable is zero
+ */
+bool
+os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _OS_TIME_H_ */