Skip to contentSkip to conversation

RPM, percnt and other minor fixes for Panfrost

PATCH Superseded Adrián Larumbe 1 participant 5 messages May 25

Subsystems (3)

v1 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Adrián Larumbe

author maintainer
#0 lore raw

cover RPM, percnt and other minor fixes for Panfrost

This patch series comes with some minor fixes for Panfrost. Some of the issues addressed were uncovered by LLM tools, while the one about RPM was traditionally debugged.

I haven't yet added any Fixes or Reported-By tags, because the purpose of the first revision is probing appetite for these changes and eliciting early discussion.

The only proper bug fixes are the ones for perfcnt and RPM, and the others are more about ensuring robustness. perfcnt bug was never observed in the open, because no one had faced a HW reset when a perfcnt session was ongoing. RPM fix addresses a long-standing issue I had been observing for quite some time, but that I had completely misunderstood.

---
Adrián Larumbe (4):
drm/panfrost: Check another bo field for cache option query drm/panfrost: Make reset sequence deal with an active HWPerf session drm/panfrost: Prevent division by 0
drm/panfrost: Fix RPM so device suspends when no jobs are in flight

 drivers/gpu/drm/panfrost/panfrost_devfreq.c |  3 +-
 drivers/gpu/drm/panfrost/panfrost_device.c  |  1 +
 drivers/gpu/drm/panfrost/panfrost_drv.c     | 10 +++--
 drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 58 +++++++++++++++++++----------
 drivers/gpu/drm/panfrost/panfrost_perfcnt.h |  1 +
 5 files changed, 49 insertions(+), 24 deletions(-)

---
base-commit: c1079aebb4de218caa86c44f9a53700d1a582683
change-id: 20260523-claude-fixes-82b03a134a8c

Best regards,

Signature · 1 line
Adrián Larumbe <[email protected]>
author maintainer
#1 lore raw

PATCH 1/4 drm/panfrost: Check another bo field for cache option query

When querying the properties of a BO, whether it was created in Writeback caching mode for userspace mappings, is recorded in a Panfrost BO's wb_mmap field.

---
 drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
index 3d0bdba2a474..cb8e5015847f 100644
@@ -659,7 +659,7 @@ static int panfrost_ioctl_query_bo_info(struct drm_device *dev, void *data,
 		if (bo->is_heap)
 			args->create_flags |= PANFROST_BO_HEAP;
 
-		if (!bo->base.map_wc)
+		if (bo->wb_mmap)
 			args->create_flags |= PANFROST_BO_WB_MMAP;
 	}
 
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH 2/4 drm/panfrost: Make reset sequence deal with an active HWPerf session

In reply to Adrián Larumbe

Right now, if there's a HW reset and an HWPerf session is active, panfrost_mmu_reset() will reset mmu structs for all all open files to have zero users and their HW address space assignment. Then, when disabling hwperf, panfrost_mmu_as_put() will WARN that mmu->as_count is less than zero.

Fix this by introducing a perfcnt HW reset path.

The choice was made to render perfcnt unusable after reset, so that a user might have to reprogram it with a full disable/enable sequence before requesting more perfcnt dumps.

---
 drivers/gpu/drm/panfrost/panfrost_device.c  |  1 +
 drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 58 +++++++++++++++++++----------
 drivers/gpu/drm/panfrost/panfrost_perfcnt.h |  1 +
 3 files changed, 41 insertions(+), 19 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.c +1 -0
index 7fed22d555a5..2a4417bc4065 100644
@@ -421,6 +421,7 @@ void panfrost_device_reset(struct panfrost_device *pfdev, bool enable_job_int)
 {
 	panfrost_gpu_soft_reset(pfdev);
 
+	panfrost_perfcnt_reset(pfdev);
 	panfrost_gpu_power_on(pfdev);
 	panfrost_mmu_reset(pfdev);
 
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +39 -19

103 lines not on this page · raw message

drivers/gpu/drm/panfrost/panfrost_perfcnt.h +1 -0
index 8bbcf5f5fb33..8b9bc704b634 100644
@@ -14,5 +14,6 @@ int panfrost_ioctl_perfcnt_enable(struct drm_device *dev, void *data,
 				  struct drm_file *file_priv);
 int panfrost_ioctl_perfcnt_dump(struct drm_device *dev, void *data,
 				struct drm_file *file_priv);
+void panfrost_perfcnt_reset(struct panfrost_device *pfdev);
 
 #endif
Signature · 1 line
2.53.0
author maintainer
#3 lore raw

PATCH 3/4 drm/panfrost: Prevent division by 0

In reply to Adrián Larumbe

When updating and debug-printing devfreq stats, in the very unlikely offchance that total device time is less than 100 ns, clamp it to 0 to avoid division by 0.

---
 drivers/gpu/drm/panfrost/panfrost_devfreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_devfreq.c +2 -1
index b51c30778811..e34de47bf43b 100644
@@ -78,7 +78,8 @@ static int panfrost_devfreq_get_dev_status(struct device *dev,
 
 	dev_dbg(pfdev->base.dev, "busy %lu total %lu %lu %% freq %lu MHz\n",
 		status->busy_time, status->total_time,
-		status->busy_time / (status->total_time / 100),
+		status->total_time >= 100 ?
+			status->busy_time / (status->total_time / 100) : 0,
 		status->current_frequency / 1000 / 1000);
 
 	return 0;
Signature · 1 line
2.53.0
author maintainer
#4 lore raw

PATCH 4/4 drm/panfrost: Fix RPM so device suspends when no jobs are in flight

In reply to Adrián Larumbe

Right now, because of an apparent bug in the management of runtime PM, the device remains powered on at all times. This was causing three different issues:

- Because MMU interrupts are only enabled when the device resets, the very first job targeting the tiler heap would always time out, as a device reset is only performed during a runtime resume operation.
- Devfreq OPP transition notifications would be printed all the time, even when the device is meant to be idle, which polute the kernel ring buffer.
- PM refcnt would eventually underflow.

---
 drivers/gpu/drm/panfrost/panfrost_drv.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/panfrost/panfrost_drv.c +5 -3
index cb8e5015847f..68b831add0bb 100644
@@ -986,9 +986,8 @@ static int panfrost_probe(struct platform_device *pdev)
 		goto err_out0;
 	}
 
-	pm_runtime_set_active(pfdev->base.dev);
-	pm_runtime_mark_last_busy(pfdev->base.dev);
 	pm_runtime_enable(pfdev->base.dev);
+	pm_runtime_resume_and_get(pfdev->base.dev);
 	pm_runtime_set_autosuspend_delay(pfdev->base.dev, 50); /* ~3 frames */
 	pm_runtime_use_autosuspend(pfdev->base.dev);
 
@@ -1004,6 +1003,8 @@ static int panfrost_probe(struct platform_device *pdev)
 	if (err)
 		goto err_out2;
 
+	pm_runtime_put_sync_suspend(pfdev->base.dev);
+
 	return 0;
 
 err_out2:
@@ -1024,8 +1025,9 @@ static void panfrost_remove(struct platform_device *pdev)
 	panfrost_gem_shrinker_cleanup(&pfdev->base);
 
 	pm_runtime_get_sync(pfdev->base.dev);
-	pm_runtime_disable(pfdev->base.dev);
 	panfrost_device_fini(pfdev);
+	pm_runtime_put_sync(pfdev->base.dev);
+	pm_runtime_disable(pfdev->base.dev);
 	pm_runtime_set_suspended(pfdev->base.dev);
 }
 
Signature · 1 line
2.53.0