summaryrefslogtreecommitdiff
path: root/lib/igt_aux.h
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2018-01-25 21:17:47 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2018-01-26 21:26:57 +0000
commit2649a091a0a67e6d4106024fb6d74cf7119f350f (patch)
tree9ad06ab4ed62a02b38adf93a59ebc8dd4f49e011 /lib/igt_aux.h
parent5d63473d5264d3384fc9ec8a328d5046a6bf868c (diff)
lib: Refactor igt_wait() to use library timers
Use the timer routines for computing elapsed time from igt_core for smaller code. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Antonio Argenziano <antonio.argenziano@intel.com>
Diffstat (limited to 'lib/igt_aux.h')
-rw-r--r--lib/igt_aux.h33
1 files changed, 16 insertions, 17 deletions
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 02e70126..f9c75992 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -29,6 +29,7 @@
#define IGT_AUX_H
#include <intel_bufmgr.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/time.h>
@@ -251,30 +252,28 @@ void igt_unlock_mem(void);
* True of COND evaluated to true, false otherwise.
*/
#define igt_wait(COND, timeout_ms, interval_ms) ({ \
- struct timeval start_, end_, diff_; \
- int elapsed_ms_; \
- bool ret_ = false; \
+ const unsigned long interval_us__ = 1000 * (interval_ms); \
+ const unsigned long timeout_ms__ = (timeout_ms); \
+ struct timespec tv__ = {}; \
+ bool ret__; \
\
- igt_assert(gettimeofday(&start_, NULL) == 0); \
do { \
+ uint64_t elapsed__ = igt_nsec_elapsed(&tv__) >> 20; \
+ \
if (COND) { \
- ret_ = true; \
+ igt_debug("%s took %"PRIu64"ms\n", #COND, elapsed__); \
+ ret__ = true; \
+ break; \
+ } \
+ if (elapsed__ > timeout_ms__) { \
+ ret__ = false; \
break; \
} \
\
- usleep(interval_ms * 1000); \
- \
- igt_assert(gettimeofday(&end_, NULL) == 0); \
- timersub(&end_, &start_, &diff_); \
- \
- elapsed_ms_ = diff_.tv_sec * 1000 + \
- diff_.tv_usec / 1000; \
- } while (elapsed_ms_ < timeout_ms); \
- \
- if (!ret_ && (COND)) \
- ret_ = true; \
+ usleep(interval_us__); \
+ } while (1); \
\
- ret_; \
+ ret__; \
})
struct igt_mean;