[Intel-gfx] [PATCH igt 1/2] lib: Refactor igt_wait() to use library timers
Antonio Argenziano
antonio.argenziano at intel.com
Fri Jan 26 16:50:15 UTC 2018
On 25/01/18 13:28, Chris Wilson wrote:
> Use the timer routines for computing elapsed time from igt_core for
> smaller code.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
> lib/igt_aux.h | 25 +++++++++++--------------
> 1 file changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/lib/igt_aux.h b/lib/igt_aux.h
> index 02e70126c..48ba7970f 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,28 +252,24 @@ 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; \
> + struct timespec tv = {}; \
> + bool ret_; \
> \
> - igt_assert(gettimeofday(&start_, NULL) == 0); \
> do { \
> + uint64_t elapsed = igt_nsec_elapsed(&tv) >> 20; \
Maybe tv_ and elapsed_ just for consistency.
Reviewed-by: Antonio Argenziano <antonio.argenziano at intel.com>
> + \
> if (COND) { \
> + 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; \
> + } while (1); \
> \
> ret_; \
> })
>
More information about the Intel-gfx
mailing list