[1/2] lib: Refactor igt_wait() to use library timers

Submitted by Chris Wilson on Jan. 25, 2018, 9:28 p.m.

Details

Message ID 20180125212849.2261-1-chris@chris-wilson.co.uk
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in IGT (deprecated)

Not browsing as part of any series.

Commit Message

Chris Wilson Jan. 25, 2018, 9:28 p.m.
Use the timer routines for computing elapsed time from igt_core for
smaller code.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_aux.h | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

Patch hide | download patch | download mbox

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;		\
+									\
 		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_;								\
 })

Comments

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@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@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_;								\
>   })
>
Quoting Antonio Argenziano (2018-01-26 16:50:15)
> 
> 
> 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@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@intel.com>

Corrected and pushed, thanks!
-Chris