[Intel-gfx] [CI 16/20] drm/i915: Only query timestamp when measuring elapsed time

Chris Wilson chris at chris-wilson.co.uk
Fri May 20 12:20:35 UTC 2016


On Thu, May 19, 2016 at 04:44:03PM +0100, Tvrtko Ursulin wrote:
> 
> On 19/05/16 12:32, Chris Wilson wrote:
> >Avoid the two calls to ktime_get_raw_ns() (at best it reads the TSC) as
> >we only need to compute the elapsed time for a timed wait.
> >
> >v2: Eliminate the unused local variable reducing the function size by 64
> >bytes (using the storage space on the callers stack rather than adding
> >to our stack frame)
> >
> >Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> >---
> >  drivers/gpu/drm/i915/i915_gem.c | 14 +++++---------
> >  1 file changed, 5 insertions(+), 9 deletions(-)
> >
> >diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> >index b48a3b46e86f..2c254cf49c15 100644
> >--- a/drivers/gpu/drm/i915/i915_gem.c
> >+++ b/drivers/gpu/drm/i915/i915_gem.c
> >@@ -1215,7 +1215,6 @@ int __i915_wait_request(struct drm_i915_gem_request *req,
> >  	int state = interruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;
> >  	struct intel_wait wait;
> >  	unsigned long timeout_remain;
> >-	s64 before = 0; /* Only to silence a compiler warning. */
> >  	int ret = 0;
> >
> >  	might_sleep();
> >@@ -1234,12 +1233,9 @@ int __i915_wait_request(struct drm_i915_gem_request *req,
> >  		if (*timeout == 0)
> >  			return -ETIME;
> >
> >+		/* Record current time in case interrupted, or wedged */
> >  		timeout_remain = nsecs_to_jiffies_timeout(*timeout);
> >-
> >-		/*
> >-		 * Record current time in case interrupted by signal, or wedged.
> >-		 */
> >-		before = ktime_get_raw_ns();
> >+		*timeout += ktime_get_raw_ns();
> >  	}
> >
> >  	trace_i915_gem_request_wait_begin(req);
> >@@ -1296,9 +1292,9 @@ complete:
> >  	trace_i915_gem_request_wait_end(req);
> >
> >  	if (timeout) {
> >-		s64 tres = *timeout - (ktime_get_raw_ns() - before);
> >-
> >-		*timeout = tres < 0 ? 0 : tres;
> >+		*timeout -= ktime_get_raw_ns();
> >+		if (*timeout < 0)
> >+			*timeout = 0;
> >
> >  		/*
> >  		 * Apparently ktime isn't accurate enough and occasionally has a
> >
> 
> I think this is bad, better have a local than play games with
> callers storage.

It's smaller faster code :-)
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the Intel-gfx mailing list