diff mbox series

drm/i915/selftest: Synchronise with the GPU timestamp

Message ID 20210205000437.16079-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series drm/i915/selftest: Synchronise with the GPU timestamp | expand

Commit Message

Chris Wilson Feb. 5, 2021, 12:04 a.m. UTC
Wait for the GPU to wake up from the semaphore before measuring the
time, so that we coordinate the sampling on both the CPU and GPU for
more accurate comparisons.

Reported-by: Bruce Chang <yu.bruce.chang@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: CQ Tang <cq.tang@intel.com>
---
 drivers/gpu/drm/i915/gt/selftest_engine_pm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Chang, Yu bruce Feb. 5, 2021, 12:35 a.m. UTC | #1
> Wait for the GPU to wake up from the semaphore before measuring the
>time, so that we coordinate the sampling on both the CPU and GPU for
> more accurate comparisons.
>
>Reported-by: Bruce Chang <yu.bruce.chang@intel.com>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: CQ Tang <cq.tang@intel.com>
> ---
>  drivers/gpu/drm/i915/gt/selftest_engine_pm.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_pm.c b/drivers/gpu/drm/i915/gt/selftest_engine_pm.c
>index 3ce8cb3329f3..007a7c790778 100644
> --- a/drivers/gpu/drm/i915/gt/selftest_engine_pm.c
> +++ b/drivers/gpu/drm/i915/gt/selftest_engine_pm.c
> @@ -111,8 +111,10 @@ static int __measure_timestamps(struct intel_context *ce,
>
>         /* Run the request for a 100us, sampling timestamps before/after */
>          preempt_disable();
> -       *dt = local_clock();
>         write_semaphore(&sema[2], 0);
> +       while (READ_ONCE(sema[1]) == 0) /* wait for the gpu to catch up */
> +               cpu_relax();
> +       *dt = local_clock();
>          udelay(100);
>         *dt = local_clock() - *dt;
>          write_semaphore(&sema[2], 1);
> --
>2.20.1
>

This trick should work!
Thanks!

Reviewed-by: Bruce Chang <yu.bruce.chang@intel.com>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_pm.c b/drivers/gpu/drm/i915/gt/selftest_engine_pm.c
index 3ce8cb3329f3..007a7c790778 100644
--- a/drivers/gpu/drm/i915/gt/selftest_engine_pm.c
+++ b/drivers/gpu/drm/i915/gt/selftest_engine_pm.c
@@ -111,8 +111,10 @@  static int __measure_timestamps(struct intel_context *ce,
 
 	/* Run the request for a 100us, sampling timestamps before/after */
 	preempt_disable();
-	*dt = local_clock();
 	write_semaphore(&sema[2], 0);
+	while (READ_ONCE(sema[1]) == 0) /* wait for the gpu to catch up */
+		cpu_relax();
+	*dt = local_clock();
 	udelay(100);
 	*dt = local_clock() - *dt;
 	write_semaphore(&sema[2], 1);