Skip to contentSkip to conversation

drm/panthor: dummy read to discard the stale first GPU_TIMESTAMP read

PATCH Superseded [email protected] 2 participants 4 messages Sep 21 – Oct 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/panthor: dummy read to discard the stale first GPU_TIMESTAMP read

From: Ryan Zhang <[email protected]>

The first read of GPU_TIMESTAMP after the GPU has been idle can return a value that lags the real counter, while a read issued immediately after is accurate.

Userspace correlates this timestamp with the host clock, so a stale value shows up as skew between the device and host time domains and makes dEQP-VK.pipeline.monolithic.timestamp.calibrated.calibration_test fail whenever a query happens to hit a large first-read error.

---
 drivers/gpu/drm/panthor/panthor_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +5 -0
index 720bf889096d..956a147dc282 100644
@@ -2,6 +2,7 @@
 /* Copyright 2018 Marty E. Plummer <[email protected]> */
 /* Copyright 2019 Linaro, Ltd., Rob Herring <[email protected]> */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifdef CONFIG_ARM_ARCH_TIMER
 #include <asm/arch_timer.h>
@@ -772,6 +773,10 @@ static int panthor_query_timestamp_info(struct panthor_device *ptdev,
 #else
 	arg->timestamp_frequency = 0;
 #endif
+
+	/* Dummy read to avoid stale values. */
+	gpu_read64_counter(ptdev, GPU_TIMESTAMP);
+
 	arg->current_timestamp = gpu_read64_counter(ptdev, GPU_TIMESTAMP);
 	arg->timestamp_offset = gpu_read64(ptdev, GPU_TIMESTAMP_OFFSET);
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Mon, Sep 21, 2026 at 06:29:57PM +0800, [email protected] wrote:

From: Ryan Zhang <[email protected]>

The first read of GPU_TIMESTAMP after the GPU has been idle can return a value that lags the real counter, while a read issued immediately after is accurate.

Quoted 6 lines

Userspace correlates this timestamp with the host clock, so a stale value shows up as skew between the device and host time domains and makes dEQP-VK.pipeline.monolithic.timestamp.calibrated.calibration_test fail whenever a query happens to hit a large first-read error.

Best regards,
Liviu

Quoted 30 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +5 -0
index 720bf889096d..956a147dc282 100644
@@ -2,6 +2,7 @@
 /* Copyright 2018 Marty E. Plummer <[email protected]> */
 /* Copyright 2019 Linaro, Ltd., Rob Herring <[email protected]> */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifdef CONFIG_ARM_ARCH_TIMER
 #include <asm/arch_timer.h>
@@ -772,6 +773,10 @@ static int panthor_query_timestamp_info(struct panthor_device *ptdev,
 #else
 	arg->timestamp_frequency = 0;
 #endif
+
+	/* Dummy read to avoid stale values. */
+	gpu_read64_counter(ptdev, GPU_TIMESTAMP);
+
 	arg->current_timestamp = gpu_read64_counter(ptdev, GPU_TIMESTAMP);
 	arg->timestamp_offset = gpu_read64(ptdev, GPU_TIMESTAMP_OFFSET);
 
Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
#2 lore raw

PATCH v2 1/1 drm/panthor: dummy read to discard the stale first GPU_TIMESTAMP read

In reply to [email protected]

From: Ryan Zhang <[email protected]>

The first read of GPU_TIMESTAMP after the GPU has been idle can return a value that lags the real counter, while a read issued immediately after is accurate.

Userspace correlates this timestamp with the host clock, so a stale value shows up as skew between the device and host time domains and makes dEQP-VK.pipeline.monolithic.timestamp.calibrated.calibration_test fail whenever a query happens to hit a large first-read error.

---
v2:
- Added the r-b in commit msg.
- Rebased on drm-misc-next to resolve conflict.
- Moved the dummy read into panthor_gpu_get_timestamp() to align with the refactored timestamp query code on drm-misc-next.
Note: The original v1 patch was based on v6.18 and applied cleanly there. Could we also port v1 into 6.18?

 drivers/gpu/drm/panthor/panthor_gpu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/panthor/panthor_gpu.c +4 -0
index a383b04f101e..b8df5663f04e 100644
@@ -2,6 +2,7 @@
 /* Copyright 2018 Marty E. Plummer <[email protected]> */
 /* Copyright 2019 Linaro, Ltd., Rob Herring <[email protected]> */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/bitfield.h>
 #include <linux/bitmap.h>
@@ -470,6 +471,9 @@ void panthor_gpu_resume(struct panthor_device *ptdev)
 
 u64 panthor_gpu_get_timestamp(struct panthor_device *ptdev)
 {
+	/* Dummy read to avoid stale values. */
+	gpu_read64_counter(ptdev->gpu->iomem, GPU_TIMESTAMP);
+
 	return gpu_read64_counter(ptdev->gpu->iomem, GPU_TIMESTAMP);
 }
 
Signature · 1 line
2.43.0
maintainer Applied
#3 lore raw
Quoted 6 lines · On Wed, Sep 23, 2026 at 06:24:48PM +0800, [email protected] wrote:

From: Ryan Zhang <[email protected]>

The first read of GPU_TIMESTAMP after the GPU has been idle can return a value that lags the real counter, while a read issued immediately after is accurate.

Quoted 7 lines

Userspace correlates this timestamp with the host clock, so a stale value shows up as skew between the device and host time domains and makes dEQP-VK.pipeline.monolithic.timestamp.calibrated.calibration_test fail whenever a query happens to hit a large first-read error.

Pushed to drm-misc-next.

Best regards,
Liviu

Quoted 37 lines

---
v2:
- Added the r-b in commit msg.
- Rebased on drm-misc-next to resolve conflict.
- Moved the dummy read into panthor_gpu_get_timestamp() to align with the refactored timestamp query code on drm-misc-next.
Note: The original v1 patch was based on v6.18 and applied cleanly there. Could we also port v1 into 6.18?

 drivers/gpu/drm/panthor/panthor_gpu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/panthor/panthor_gpu.c +4 -0
index a383b04f101e..b8df5663f04e 100644
@@ -2,6 +2,7 @@
 /* Copyright 2018 Marty E. Plummer <[email protected]> */
 /* Copyright 2019 Linaro, Ltd., Rob Herring <[email protected]> */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/bitfield.h>
 #include <linux/bitmap.h>
@@ -470,6 +471,9 @@ void panthor_gpu_resume(struct panthor_device *ptdev)
 
 u64 panthor_gpu_get_timestamp(struct panthor_device *ptdev)
 {
+	/* Dummy read to avoid stale values. */
+	gpu_read64_counter(ptdev->gpu->iomem, GPU_TIMESTAMP);
+
 	return gpu_read64_counter(ptdev->gpu->iomem, GPU_TIMESTAMP);
 }
 
Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯