Skip to contentSkip to conversation

drm/panthor: add gpu_load debugfs node

PATCH In review Guangliu Ding 3 participants 9 messages Jul 8 – Jul 29

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

PATCH 1/1 drm/panthor: add gpu_load debugfs node

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window (~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms).
The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/panthor/panthor_devfreq.h |  6 +++
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +80 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 
@@ -43,6 +47,22 @@ struct panthor_devfreq {
 	 * and panthor_devfreq_record_{busy,idle}().
 	 */
 	spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+	/**
+	 * @last_busy_ns: Busy time in nanoseconds of the last completed devfreq window.
+	 * Updated by panthor_devfreq_get_dev_status() before resetting the counters.
+	 * Protected by @lock.
+	 */
+	u64 last_busy_ns;
+
+	/**
+	 * @last_total_ns: Total time in nanoseconds of the last completed devfreq window.
+	 * Updated by panthor_devfreq_get_dev_status() before resetting the counters.
+	 * Protected by @lock.
+	 */
+	u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct panthor_devfreq *pdevfreq)
@@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,
 
 	status->busy_time = ktime_to_ns(pdevfreq->busy_time);
 
+#ifdef CONFIG_DEBUG_FS
+	pdevfreq->last_busy_ns = status->busy_time;
+	pdevfreq->last_total_ns = status->total_time;
+#endif
+
 	panthor_devfreq_reset(pdevfreq);
 
 	spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
@@ -283,6 +308,17 @@ void panthor_devfreq_suspend(struct panthor_device *ptdev)
 		return;
 
 	drm_WARN_ON(&ptdev->base, devfreq_suspend_device(pdevfreq->devfreq));
+
+#ifdef CONFIG_DEBUG_FS
+	{
+		unsigned long irqflags;
+
+		spin_lock_irqsave(&pdevfreq->lock, irqflags);
+		pdevfreq->last_busy_ns = 0;
+		pdevfreq->last_total_ns = 0;
+		spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+	}
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device *ptdev)
@@ -332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)
 
 	return freq;
 }
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file *m, void *unused)
+{
+	struct panthor_device *ptdev = m->private;
+	struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+	unsigned long irqflags;
+	unsigned int gpu_load;
+	u64 total_ns;
+	u64 busy_ns;
+
+	if (!pdevfreq->devfreq) {
+		seq_puts(m, "devfreq not initialized\n");
+		return 0;
+	}
+
+	spin_lock_irqsave(&pdevfreq->lock, irqflags);
+	busy_ns = pdevfreq->last_busy_ns;
+	total_ns = pdevfreq->last_total_ns;
+	spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+	busy_ns = min(busy_ns, total_ns);
+	gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns * 100ULL, total_ns) : 0;
+
+	seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu  gpu_load: %u%%\n",
+		   busy_ns, total_ns - busy_ns, gpu_load);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq debugfs entries
+ * @minor: DRM minor.
+ */
+void panthor_devfreq_debugfs_init(struct drm_minor *minor)
+{
+	struct panthor_device *ptdev = container_of(minor->dev,
+						    struct panthor_device, base);
+
+	debugfs_create_file("gpu_load", 0444, minor->debugfs_root, ptdev,
+			    &panthor_devfreq_gpu_load_fops);
+}
+#endif /* CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +6 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__
 #define __PANTHOR_DEVFREQ_H__
@@ -20,4 +21,9 @@ void panthor_devfreq_record_idle(struct panthor_device *ptdev);
 
 unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev);
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor);
+#endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */
drivers/gpu/drm/panthor/panthor_drv.c +2 -0
index e8dc4096c1d2..4093a6d21337 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>
@@ -1761,6 +1762,7 @@ static void panthor_debugfs_init(struct drm_minor *minor)
 {
 	panthor_mmu_debugfs_init(minor);
 	panthor_gem_debugfs_init(minor);
+	panthor_devfreq_debugfs_init(minor);
 }
 #endif
 

---
base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Best regards,

Signature · 1 line
Guangliu Ding <[email protected]>
maintainer
#1 lore raw
Quoted 11 lines · Guangliu Ding

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window (~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

Hi Guangliu,

I'm puzzled exactly what you're trying to achieve with this. I can see that getting the GPU load might be useful, we do already have the 'fdinfo' mechanism to do this in a per-client manner but nothing good for "whole GPU" measurements.

But stashing it in debugfs and formatting it as a string seems odd. Do you have a tool which uses this file, or is just for 'cat'ing to see the instantaneous load?

Ideally we'd have something that would provide this information in a format that all drivers could implement, and not rely on debugfs files.

Thanks,
Steve

Quoted 184 lines

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms).
The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/panthor/panthor_devfreq.h |  6 +++
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +80 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 
@@ -43,6 +47,22 @@ struct panthor_devfreq {
 	 * and panthor_devfreq_record_{busy,idle}().
 	 */
 	spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+	/**
+	 * @last_busy_ns: Busy time in nanoseconds of the last completed devfreq window.
+	 * Updated by panthor_devfreq_get_dev_status() before resetting the counters.
+	 * Protected by @lock.
+	 */
+	u64 last_busy_ns;
+
+	/**
+	 * @last_total_ns: Total time in nanoseconds of the last completed devfreq window.
+	 * Updated by panthor_devfreq_get_dev_status() before resetting the counters.
+	 * Protected by @lock.
+	 */
+	u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct panthor_devfreq *pdevfreq)
@@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,
 
 	status->busy_time = ktime_to_ns(pdevfreq->busy_time);
 
+#ifdef CONFIG_DEBUG_FS
+	pdevfreq->last_busy_ns = status->busy_time;
+	pdevfreq->last_total_ns = status->total_time;
+#endif
+
 	panthor_devfreq_reset(pdevfreq);
 
 	spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
@@ -283,6 +308,17 @@ void panthor_devfreq_suspend(struct panthor_device *ptdev)
 		return;
 
 	drm_WARN_ON(&ptdev->base, devfreq_suspend_device(pdevfreq->devfreq));
+
+#ifdef CONFIG_DEBUG_FS
+	{
+		unsigned long irqflags;
+
+		spin_lock_irqsave(&pdevfreq->lock, irqflags);
+		pdevfreq->last_busy_ns = 0;
+		pdevfreq->last_total_ns = 0;
+		spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+	}
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device *ptdev)
@@ -332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)
 
 	return freq;
 }
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file *m, void *unused)
+{
+	struct panthor_device *ptdev = m->private;
+	struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+	unsigned long irqflags;
+	unsigned int gpu_load;
+	u64 total_ns;
+	u64 busy_ns;
+
+	if (!pdevfreq->devfreq) {
+		seq_puts(m, "devfreq not initialized\n");
+		return 0;
+	}
+
+	spin_lock_irqsave(&pdevfreq->lock, irqflags);
+	busy_ns = pdevfreq->last_busy_ns;
+	total_ns = pdevfreq->last_total_ns;
+	spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+	busy_ns = min(busy_ns, total_ns);
+	gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns * 100ULL, total_ns) : 0;
+
+	seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu  gpu_load: %u%%\n",
+		   busy_ns, total_ns - busy_ns, gpu_load);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq debugfs entries
+ * @minor: DRM minor.
+ */
+void panthor_devfreq_debugfs_init(struct drm_minor *minor)
+{
+	struct panthor_device *ptdev = container_of(minor->dev,
+						    struct panthor_device, base);
+
+	debugfs_create_file("gpu_load", 0444, minor->debugfs_root, ptdev,
+			    &panthor_devfreq_gpu_load_fops);
+}
+#endif /* CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +6 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__
 #define __PANTHOR_DEVFREQ_H__
@@ -20,4 +21,9 @@ void panthor_devfreq_record_idle(struct panthor_device *ptdev);
 
 unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev);
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor);
+#endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */
drivers/gpu/drm/panthor/panthor_drv.c +2 -1
index e8dc4096c1d2..4093a6d21337 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>
@@ -1761,6 +1762,7 @@ static void panthor_debugfs_init(struct drm_minor *minor)
 {
 	panthor_mmu_debugfs_init(minor);
 	panthor_gem_debugfs_init(minor);
+	panthor_devfreq_debugfs_init(minor);
 }
 #endif
 
 
---

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Best regards,

Signature · 1 line
Guangliu Ding <[email protected]>
#2 lore raw
Quoted 20 lines · Guangliu Ding
Quoted 11 lines

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window (~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

Hi Guangliu,

I'm puzzled exactly what you're trying to achieve with this. I can see that getting the GPU load might be useful, we do already have the 'fdinfo' mechanism to do this in a per-client manner but nothing good for "whole GPU" measurements.

Quoted 9 lines

But stashing it in debugfs and formatting it as a string seems odd. Do you have a tool which uses this file, or is just for 'cat'ing to see the instantaneous load?

Ideally we'd have something that would provide this information in a format that all drivers could implement, and not rely on debugfs files.

Thanks,
Steve

Hi Steve

Panthor currently exposes very limited runtime telemetry. The intent is to expose utilization in this patch, together with other device-wide GPU runtime metrics (frequency, shader activity, draw-call counts, memory usage, etc.) to a userspace tool for monitoring and workload-optimization purposes.

fdinfo is primarily a per-client interface. Since it requires an open DRM fd and reports information associated with that client, it does not map particularly well to the global metrics exported by this patch.

If a generic cross-driver interface for this kind of GPU telemetry emerges, I'm happy to switch to it. However, no such interface currently exists for devfreq-based device utilization, so debugfs seemed like the most appropriate existing option. Suggestions for a better interface are welcome.

Best Regards,
Guangliu

Quoted 197 lines
Quoted 9 lines

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms).
The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80

+++++++++++++++++++++++++++++++

drivers/gpu/drm/panthor/panthor_devfreq.h | 6 +++

Quoted 26 lines
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 53

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
@@ -43,6 +47,22 @@ struct panthor_devfreq {
       * and panthor_devfreq_record_{busy,idle}().
       */
      spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+     /**
+      * @last_busy_ns: Busy time in nanoseconds of the last completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 54

Quoted 1 line
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+      * Updated by panthor_devfreq_get_dev_status() before resetting the

counters.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq {

Quoted 6 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +6 -0
+      * Protected by @lock.
+      */
+     u64 last_busy_ns;
+
+     /**
+      * @last_total_ns: Total time in nanoseconds of the last completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 61

Quoted 1 line
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+      * Updated by panthor_devfreq_get_dev_status() before resetting the

counters.

Quoted 59 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
+      * Protected by @lock.
+      */
+     u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct panthor_devfreq

*pdevfreq) @@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,

      status->busy_time = ktime_to_ns(pdevfreq->busy_time);
drivers/gpu/drm/panthor/panthor_devfreq.c +5 -0
+#ifdef CONFIG_DEBUG_FS
+     pdevfreq->last_busy_ns = status->busy_time;
+     pdevfreq->last_total_ns = status->total_time; #endif
+
      panthor_devfreq_reset(pdevfreq);
 
      spin_unlock_irqrestore(&pdevfreq->lock, irqflags); @@ -283,6
+308,17 @@ void panthor_devfreq_suspend(struct panthor_device *ptdev)
              return;
 
      drm_WARN_ON(&ptdev->base,

devfreq_suspend_device(pdevfreq->devfreq));

drivers/gpu/drm/panthor/panthor_devfreq.c +11 -1
+
+#ifdef CONFIG_DEBUG_FS
+     {
+             unsigned long irqflags;
+
+             spin_lock_irqsave(&pdevfreq->lock, irqflags);
+             pdevfreq->last_busy_ns = 0;
+             pdevfreq->last_total_ns = 0;
+             spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+     }
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device *ptdev) @@
-332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct

panthor_device *ptdev)

      return freq;

}

drivers/gpu/drm/panthor/panthor_devfreq.c +16 -0
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file *m, void
+*unused) {
+     struct panthor_device *ptdev = m->private;
+     struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+     unsigned long irqflags;
+     unsigned int gpu_load;
+     u64 total_ns;
+     u64 busy_ns;
+
+     if (!pdevfreq->devfreq) {
+             seq_puts(m, "devfreq not initialized\n");
+             return 0;
+     }
+

drivers/gpu/drm/panthor/panthor_devfreq.c unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+     spin_lock_irqsave(&pdevfreq->lock, irqflags);
+     busy_ns = pdevfreq->last_busy_ns;
+     total_ns = pdevfreq->last_total_ns;
+     spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+     busy_ns = min(busy_ns, total_ns);
+     gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns * 100ULL,
+ total_ns) : 0;
+
+     seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu

gpu_load: %u%%\n",

Quoted 8 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +8 -0
+                busy_ns, total_ns - busy_ns, gpu_load);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq debugfs

drivers/gpu/drm/panthor/panthor_devfreq.c unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+entries
+ * @minor: DRM minor.
+ */
+void panthor_devfreq_debugfs_init(struct drm_minor *minor) {
+     struct panthor_device *ptdev = container_of(minor->dev,
+                                                 struct
+panthor_device, base);
+
+     debugfs_create_file("gpu_load", 0444, minor->debugfs_root, ptdev,
+                         &panthor_devfreq_gpu_load_fops); } #endif

/*

Quoted 53 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +5 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__
 #define __PANTHOR_DEVFREQ_H__
@@ -20,4 +21,9 @@ void panthor_devfreq_record_idle(struct
 panthor_device *ptdev);
 
 unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev);
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor); #endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */
drivers/gpu/drm/panthor/panthor_drv.c +2 -1
index e8dc4096c1d2..4093a6d21337 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>
@@ -1761,6 +1762,7 @@ static void panthor_debugfs_init(struct
 drm_minor *minor)  {
      panthor_mmu_debugfs_init(minor);
      panthor_gem_debugfs_init(minor);
+     panthor_devfreq_debugfs_init(minor);
 }
 #endif
 
 
---

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Best regards,
--
Guangliu Ding <[email protected]>

maintainer
#3 lore raw
Quoted 36 lines · Guangliu Ding
Quoted 20 lines · Guangliu Ding
Quoted 11 lines

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window (~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

Hi Guangliu,

I'm puzzled exactly what you're trying to achieve with this. I can see that getting the GPU load might be useful, we do already have the 'fdinfo' mechanism to do this in a per-client manner but nothing good for "whole GPU" measurements.

Quoted 9 lines

But stashing it in debugfs and formatting it as a string seems odd. Do you have a tool which uses this file, or is just for 'cat'ing to see the instantaneous load?

Ideally we'd have something that would provide this information in a format that all drivers could implement, and not rely on debugfs files.

Thanks,
Steve

Hi Steve

Panthor currently exposes very limited runtime telemetry. The intent is to expose utilization in this patch, together with other device-wide GPU runtime metrics (frequency, shader activity, draw-call counts, memory usage, etc.) to a userspace tool for monitoring and workload-optimization purposes.

Quoted 8 lines

fdinfo is primarily a per-client interface. Since it requires an open DRM fd and reports information associated with that client, it does not map particularly well to the global metrics exported by this patch.

If a generic cross-driver interface for this kind of GPU telemetry emerges, I'm happy to switch to it. However, no such interface currently exists for devfreq-based device utilization, so debugfs seemed like the most appropriate existing option. Suggestions for a better interface are welcome.

So my point really is someone should ideally implement a better interface that multiple drivers can use. Having a point hack for one driver doesn't really help the situation.

Indeed you can get the load information with ftrace already:

cd /sys/kernel/tracing
echo 0 > tracing_on
echo > trace
echo 'dev_name == "fb000000.gpu"' > events/devfreq/devfreq_monitor/filter echo 1 > events/devfreq/devfreq_monitor/enable
echo 1 > tracing_on
cat trace_pipe

And you'll get a stream of messages when the GPU is in use which includes a "load=xx" value at the end.

If this is going to be extended to other properties for a user space tool then we should probably be putting this in sysfs and trying to come up with a design that other drivers can copy.

Thanks,
Steve

Quoted 201 lines

Best Regards,
Guangliu

Quoted 197 lines
Quoted 9 lines

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms).
The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80

+++++++++++++++++++++++++++++++

drivers/gpu/drm/panthor/panthor_devfreq.h | 6 +++

Quoted 26 lines
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 53

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
@@ -43,6 +47,22 @@ struct panthor_devfreq {
       * and panthor_devfreq_record_{busy,idle}().
       */
      spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+     /**
+      * @last_busy_ns: Busy time in nanoseconds of the last completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 54

Quoted 1 line
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+      * Updated by panthor_devfreq_get_dev_status() before resetting the

counters.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq {

Quoted 6 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +6 -0
+      * Protected by @lock.
+      */
+     u64 last_busy_ns;
+
+     /**
+      * @last_total_ns: Total time in nanoseconds of the last completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 61

Quoted 1 line
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+      * Updated by panthor_devfreq_get_dev_status() before resetting the

counters.

Quoted 59 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
+      * Protected by @lock.
+      */
+     u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct panthor_devfreq

*pdevfreq) @@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,

      status->busy_time = ktime_to_ns(pdevfreq->busy_time);
drivers/gpu/drm/panthor/panthor_devfreq.c +5 -0
+#ifdef CONFIG_DEBUG_FS
+     pdevfreq->last_busy_ns = status->busy_time;
+     pdevfreq->last_total_ns = status->total_time; #endif
+
      panthor_devfreq_reset(pdevfreq);
 
      spin_unlock_irqrestore(&pdevfreq->lock, irqflags); @@ -283,6
+308,17 @@ void panthor_devfreq_suspend(struct panthor_device *ptdev)
              return;
 
      drm_WARN_ON(&ptdev->base,

devfreq_suspend_device(pdevfreq->devfreq));

drivers/gpu/drm/panthor/panthor_devfreq.c +11 -1
+
+#ifdef CONFIG_DEBUG_FS
+     {
+             unsigned long irqflags;
+
+             spin_lock_irqsave(&pdevfreq->lock, irqflags);
+             pdevfreq->last_busy_ns = 0;
+             pdevfreq->last_total_ns = 0;
+             spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+     }
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device *ptdev) @@
-332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct

panthor_device *ptdev)

      return freq;

}

drivers/gpu/drm/panthor/panthor_devfreq.c +16 -0
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file *m, void
+*unused) {
+     struct panthor_device *ptdev = m->private;
+     struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+     unsigned long irqflags;
+     unsigned int gpu_load;
+     u64 total_ns;
+     u64 busy_ns;
+
+     if (!pdevfreq->devfreq) {
+             seq_puts(m, "devfreq not initialized\n");
+             return 0;
+     }
+

drivers/gpu/drm/panthor/panthor_devfreq.c unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+     spin_lock_irqsave(&pdevfreq->lock, irqflags);
+     busy_ns = pdevfreq->last_busy_ns;
+     total_ns = pdevfreq->last_total_ns;
+     spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+     busy_ns = min(busy_ns, total_ns);
+     gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns * 100ULL,
+ total_ns) : 0;
+
+     seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu

gpu_load: %u%%\n",

Quoted 8 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +8 -0
+                busy_ns, total_ns - busy_ns, gpu_load);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq debugfs

drivers/gpu/drm/panthor/panthor_devfreq.c unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+entries
+ * @minor: DRM minor.
+ */
+void panthor_devfreq_debugfs_init(struct drm_minor *minor) {
+     struct panthor_device *ptdev = container_of(minor->dev,
+                                                 struct
+panthor_device, base);
+
+     debugfs_create_file("gpu_load", 0444, minor->debugfs_root, ptdev,
+                         &panthor_devfreq_gpu_load_fops); } #endif

/*

Quoted 53 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +5 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__
 #define __PANTHOR_DEVFREQ_H__
@@ -20,4 +21,9 @@ void panthor_devfreq_record_idle(struct
 panthor_device *ptdev);
 
 unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev);
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor); #endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */
drivers/gpu/drm/panthor/panthor_drv.c +2 -1
index e8dc4096c1d2..4093a6d21337 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>
@@ -1761,6 +1762,7 @@ static void panthor_debugfs_init(struct
 drm_minor *minor)  {
      panthor_mmu_debugfs_init(minor);
      panthor_gem_debugfs_init(minor);
+     panthor_devfreq_debugfs_init(minor);
 }
 #endif
 
 
---

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Best regards,
--
Guangliu Ding <[email protected]>

#4 lore raw
Quoted 68 lines · Guangliu Ding
Quoted 11 lines
Quoted 11 lines · Guangliu Ding
Quoted 10 lines

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window (~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

Hi Guangliu,

I'm puzzled exactly what you're trying to achieve with this. I can see that getting the GPU load might be useful, we do already have the 'fdinfo' mechanism to do this in a per-client manner but nothing good for

"whole GPU"

Quoted 4 lines
Quoted 4 lines

measurements.

But stashing it in debugfs and formatting it as a string seems odd. Do you have a tool which uses this file, or is just for 'cat'ing to see the

instantaneous load?

Quoted 8 lines
Quoted 7 lines

Ideally we'd have something that would provide this information in a format that all drivers could implement, and not rely on debugfs files.

Thanks,
Steve

Quoted 5 lines

Hi Steve

Panthor currently exposes very limited runtime telemetry. The intent is to expose utilization in this patch, together with other device-wide GPU runtime metrics (frequency, shader activity, draw-call counts,

memory usage, etc.) to a userspace tool for monitoring and workload-optimization purposes.

Quoted 9 lines

fdinfo is primarily a per-client interface. Since it requires an open DRM fd and reports information associated with that client, it does not map particularly well to the global metrics exported by this patch.

If a generic cross-driver interface for this kind of GPU telemetry emerges, I'm happy to switch to it. However, no such interface currently exists for devfreq-based device utilization, so debugfs seemed like the most appropriate existing option. Suggestions for a better

interface are welcome.

So my point really is someone should ideally implement a better interface that multiple drivers can use. Having a point hack for one driver doesn't really help the situation.

Indeed you can get the load information with ftrace already:

cd /sys/kernel/tracing
echo 0 > tracing_on
echo > trace
echo 'dev_name == "fb000000.gpu"' > events/devfreq/devfreq_monitor/filter echo 1 > events/devfreq/devfreq_monitor/enable
echo 1 > tracing_on
cat trace_pipe

And you'll get a stream of messages when the GPU is in use which includes a "load=xx" value at the end.

Quoted 7 lines

If this is going to be extended to other properties for a user space tool then we should probably be putting this in sysfs and trying to come up with a design that other drivers can copy.

Thanks,
Steve

Hi Steve,

Thanks for the feedback and sharing.
I agree that a generic interface shared by multiple drivers would be preferable in the long term.

For our use case, we need to provide customers with a simple way to quickly observe GPU performance metrics from a userspace tuning tool. Even though the devfreq_monitor tracepoint already exposes the load information, ftrace is typically not enabled or supported in our deployed products, making it unsuitable as a user-facing interface for the tool.

As far as I know, there is currently no generic DRM/devfreq interface for querying device-wide GPU utilization on demand. Given that gap, exporting the information through debugfs seemed like the most practical option for Panthor today.

Thanks,
Guangliu

Quoted 210 lines
Quoted 145 lines

Best Regards,
Guangliu

Quoted 142 lines
Quoted 9 lines

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms).
The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80

+++++++++++++++++++++++++++++++

drivers/gpu/drm/panthor/panthor_devfreq.h | 6 +++

Quoted 26 lines
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 54

Quoted 8 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +5 -0
@@ -43,6 +47,22 @@ struct panthor_devfreq {
       * and panthor_devfreq_record_{busy,idle}().
       */
      spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+     /**
+      * @last_busy_ns: Busy time in nanoseconds of the last
+completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 56

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq {

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +7 -0
+      * Protected by @lock.
+      */
+     u64 last_busy_ns;
+
+     /**
+      * @last_total_ns: Total time in nanoseconds of the last
+ completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 65

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

Quoted 62 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
+      * Protected by @lock.
+      */
+     u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct

panthor_devfreq
*pdevfreq) @@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,

      status->busy_time = ktime_to_ns(pdevfreq->busy_time);
drivers/gpu/drm/panthor/panthor_devfreq.c +6 -0
+#ifdef CONFIG_DEBUG_FS
+     pdevfreq->last_busy_ns = status->busy_time;
+     pdevfreq->last_total_ns = status->total_time; #endif
+
      panthor_devfreq_reset(pdevfreq);
 
      spin_unlock_irqrestore(&pdevfreq->lock, irqflags); @@ -283,6
+308,17 @@ void panthor_devfreq_suspend(struct panthor_device
+*ptdev)
              return;
 
      drm_WARN_ON(&ptdev->base,

devfreq_suspend_device(pdevfreq->devfreq));

drivers/gpu/drm/panthor/panthor_devfreq.c +11 -1
+
+#ifdef CONFIG_DEBUG_FS
+     {
+             unsigned long irqflags;
+
+             spin_lock_irqsave(&pdevfreq->lock, irqflags);
+             pdevfreq->last_busy_ns = 0;
+             pdevfreq->last_total_ns = 0;
+             spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+     }
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device *ptdev) @@
-332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct

panthor_device *ptdev)

      return freq;

}

drivers/gpu/drm/panthor/panthor_devfreq.c +17 -0
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file *m, void
+*unused) {
+     struct panthor_device *ptdev = m->private;
+     struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+     unsigned long irqflags;
+     unsigned int gpu_load;
+     u64 total_ns;
+     u64 busy_ns;
+
+     if (!pdevfreq->devfreq) {
+             seq_puts(m, "devfreq not initialized\n");
+             return 0;
+     }
+
+     spin_lock_irqsave(&pdevfreq->lock, irqflags);

drivers/gpu/drm/panthor/panthor_devfreq.c unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+     busy_ns = pdevfreq->last_busy_ns;
+     total_ns = pdevfreq->last_total_ns;
+     spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+     busy_ns = min(busy_ns, total_ns);
+     gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns *
+ 100ULL,
+ total_ns) : 0;
+
+     seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu

gpu_load: %u%%\n",

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+                busy_ns, total_ns - busy_ns, gpu_load);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq debugfs
+entries
+ * @minor: DRM minor.
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/panthor/panthor_devfreq.c

Quoted 8 lines

+ */

drivers/gpu/drm/panthor/panthor_devfreq.c +7 -0
+void panthor_devfreq_debugfs_init(struct drm_minor *minor) {
+     struct panthor_device *ptdev = container_of(minor->dev,
+                                                 struct
+panthor_device, base);
+
+     debugfs_create_file("gpu_load", 0444, minor->debugfs_root, ptdev,
+                         &panthor_devfreq_gpu_load_fops); }

#endif

Quoted 56 lines
Quoted 55 lines

/*

Quoted 54 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +5 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__
 #define __PANTHOR_DEVFREQ_H__
@@ -20,4 +21,9 @@ void panthor_devfreq_record_idle(struct
 panthor_device *ptdev);
 
 unsigned long panthor_devfreq_get_freq(struct panthor_device
 *ptdev);
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor); #endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */
drivers/gpu/drm/panthor/panthor_drv.c +2 -1
index e8dc4096c1d2..4093a6d21337 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>
@@ -1761,6 +1762,7 @@ static void panthor_debugfs_init(struct
 drm_minor *minor)  {
      panthor_mmu_debugfs_init(minor);
      panthor_gem_debugfs_init(minor);
+     panthor_devfreq_debugfs_init(minor);
 }
 #endif
 
 
---

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Best regards,
--
Guangliu Ding <[email protected]>

maintainer
#5 lore raw
Quoted 78 lines · Guangliu Ding
Quoted 68 lines · Guangliu Ding
Quoted 11 lines
Quoted 11 lines · Guangliu Ding
Quoted 10 lines

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window (~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

Hi Guangliu,

I'm puzzled exactly what you're trying to achieve with this. I can see that getting the GPU load might be useful, we do already have the 'fdinfo' mechanism to do this in a per-client manner but nothing good for

"whole GPU"

Quoted 4 lines
Quoted 4 lines

measurements.

But stashing it in debugfs and formatting it as a string seems odd. Do you have a tool which uses this file, or is just for 'cat'ing to see the

instantaneous load?

Quoted 8 lines
Quoted 7 lines

Ideally we'd have something that would provide this information in a format that all drivers could implement, and not rely on debugfs files.

Thanks,
Steve

Quoted 5 lines

Hi Steve

Panthor currently exposes very limited runtime telemetry. The intent is to expose utilization in this patch, together with other device-wide GPU runtime metrics (frequency, shader activity, draw-call counts,

memory usage, etc.) to a userspace tool for monitoring and workload-optimization purposes.

Quoted 9 lines

fdinfo is primarily a per-client interface. Since it requires an open DRM fd and reports information associated with that client, it does not map particularly well to the global metrics exported by this patch.

If a generic cross-driver interface for this kind of GPU telemetry emerges, I'm happy to switch to it. However, no such interface currently exists for devfreq-based device utilization, so debugfs seemed like the most appropriate existing option. Suggestions for a better

interface are welcome.

So my point really is someone should ideally implement a better interface that multiple drivers can use. Having a point hack for one driver doesn't really help the situation.

Indeed you can get the load information with ftrace already:

cd /sys/kernel/tracing
echo 0 > tracing_on
echo > trace
echo 'dev_name == "fb000000.gpu"' > events/devfreq/devfreq_monitor/filter echo 1 > events/devfreq/devfreq_monitor/enable
echo 1 > tracing_on
cat trace_pipe

And you'll get a stream of messages when the GPU is in use which includes a "load=xx" value at the end.

Quoted 7 lines

If this is going to be extended to other properties for a user space tool then we should probably be putting this in sysfs and trying to come up with a design that other drivers can copy.

Thanks,
Steve

Hi Steve,

Quoted 7 lines

Thanks for the feedback and sharing.
I agree that a generic interface shared by multiple drivers would be preferable in the long term.

For our use case, we need to provide customers with a simple way to quickly observe GPU performance metrics from a userspace tuning tool. Even though the devfreq_monitor tracepoint already exposes the load information, ftrace is typically not enabled or supported in our deployed products, making it unsuitable as a user-facing interface for the tool.

You are enabling debugfs but not ftrace? Seems like an odd choice if you want to monitor and tune your system.

We are working on adding performance counters support to Panthor that will expose performance metrics in a more meaningful way.

Quoted 4 lines

As far as I know, there is currently no generic DRM/devfreq interface for querying device-wide GPU utilization on demand. Given that gap, exporting the information through debugfs seemed like the most practical option for Panthor today.

Knowing that the GPU was 80% busy without knowing exactly who was submitting jobs is not a particularly useful information, in my opinion. I would like to understand better what you are trying to do with the information and why implementing a devfreq governor for your usecase would not be useful here.

Best regards,
Liviu

Quoted 215 lines

Thanks,
Guangliu

Quoted 210 lines
Quoted 145 lines

Best Regards,
Guangliu

Quoted 142 lines
Quoted 9 lines

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms).
The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80

+++++++++++++++++++++++++++++++

drivers/gpu/drm/panthor/panthor_devfreq.h | 6 +++

Quoted 26 lines
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 54

Quoted 8 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +5 -0
@@ -43,6 +47,22 @@ struct panthor_devfreq {
       * and panthor_devfreq_record_{busy,idle}().
       */
      spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+     /**
+      * @last_busy_ns: Busy time in nanoseconds of the last
+completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 56

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq {

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +7 -0
+      * Protected by @lock.
+      */
+     u64 last_busy_ns;
+
+     /**
+      * @last_total_ns: Total time in nanoseconds of the last
+ completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 65

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

Quoted 62 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
+      * Protected by @lock.
+      */
+     u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct

panthor_devfreq
*pdevfreq) @@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,

      status->busy_time = ktime_to_ns(pdevfreq->busy_time);
drivers/gpu/drm/panthor/panthor_devfreq.c +6 -0
+#ifdef CONFIG_DEBUG_FS
+     pdevfreq->last_busy_ns = status->busy_time;
+     pdevfreq->last_total_ns = status->total_time; #endif
+
      panthor_devfreq_reset(pdevfreq);
 
      spin_unlock_irqrestore(&pdevfreq->lock, irqflags); @@ -283,6
+308,17 @@ void panthor_devfreq_suspend(struct panthor_device
+*ptdev)
              return;
 
      drm_WARN_ON(&ptdev->base,

devfreq_suspend_device(pdevfreq->devfreq));

drivers/gpu/drm/panthor/panthor_devfreq.c +11 -1
+
+#ifdef CONFIG_DEBUG_FS
+     {
+             unsigned long irqflags;
+
+             spin_lock_irqsave(&pdevfreq->lock, irqflags);
+             pdevfreq->last_busy_ns = 0;
+             pdevfreq->last_total_ns = 0;
+             spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+     }
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device *ptdev) @@
-332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct

panthor_device *ptdev)

      return freq;

}

drivers/gpu/drm/panthor/panthor_devfreq.c +17 -0
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file *m, void
+*unused) {
+     struct panthor_device *ptdev = m->private;
+     struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+     unsigned long irqflags;
+     unsigned int gpu_load;
+     u64 total_ns;
+     u64 busy_ns;
+
+     if (!pdevfreq->devfreq) {
+             seq_puts(m, "devfreq not initialized\n");
+             return 0;
+     }
+
+     spin_lock_irqsave(&pdevfreq->lock, irqflags);

drivers/gpu/drm/panthor/panthor_devfreq.c unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+     busy_ns = pdevfreq->last_busy_ns;
+     total_ns = pdevfreq->last_total_ns;
+     spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+     busy_ns = min(busy_ns, total_ns);
+     gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns *
+ 100ULL,
+ total_ns) : 0;
+
+     seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu

gpu_load: %u%%\n",

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+                busy_ns, total_ns - busy_ns, gpu_load);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq debugfs
+entries
+ * @minor: DRM minor.
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/panthor/panthor_devfreq.c

Quoted 8 lines

+ */

drivers/gpu/drm/panthor/panthor_devfreq.c +7 -0
+void panthor_devfreq_debugfs_init(struct drm_minor *minor) {
+     struct panthor_device *ptdev = container_of(minor->dev,
+                                                 struct
+panthor_device, base);
+
+     debugfs_create_file("gpu_load", 0444, minor->debugfs_root, ptdev,
+                         &panthor_devfreq_gpu_load_fops); }

#endif

Quoted 56 lines
Quoted 55 lines

/*

Quoted 54 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +5 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__
 #define __PANTHOR_DEVFREQ_H__
@@ -20,4 +21,9 @@ void panthor_devfreq_record_idle(struct
 panthor_device *ptdev);
 
 unsigned long panthor_devfreq_get_freq(struct panthor_device
 *ptdev);
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor); #endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */
drivers/gpu/drm/panthor/panthor_drv.c +2 -1
index e8dc4096c1d2..4093a6d21337 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>
@@ -1761,6 +1762,7 @@ static void panthor_debugfs_init(struct
 drm_minor *minor)  {
      panthor_mmu_debugfs_init(minor);
      panthor_gem_debugfs_init(minor);
+     panthor_devfreq_debugfs_init(minor);
 }
 #endif
 
 
---

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Best regards,
--
Guangliu Ding <[email protected]>

Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
#6 lore raw
Quoted 109 lines · Guangliu Ding
Quoted 24 lines
Quoted 24 lines · Guangliu Ding
Quoted 12 lines
Quoted 12 lines · Guangliu Ding
Quoted 11 lines

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window
(~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Hi Guangliu,

I'm puzzled exactly what you're trying to achieve with this. I can see that getting the GPU load might be useful, we do already have the 'fdinfo' mechanism to do this in a per-client manner but nothing good for

"whole GPU"

Quoted 2 lines
Quoted 2 lines

measurements.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

But stashing it in debugfs and formatting it as a string seems odd. Do you have a tool which uses this file, or is just for 'cat'ing to see the

instantaneous load?

Quoted 3 lines
Quoted 3 lines

Ideally we'd have something that would provide this information in a format that all drivers could implement, and not rely on debugfs

files.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

Thanks,
Steve

Hi Steve

Panthor currently exposes very limited runtime telemetry. The intent is to expose utilization in this patch, together with other device-wide GPU runtime metrics (frequency, shader activity, draw-call counts,

Quoted 6 lines
Quoted 6 lines

memory usage, etc.) to a userspace tool for monitoring and workload-optimization purposes.

Quoted 4 lines

fdinfo is primarily a per-client interface. Since it requires an open DRM fd and reports information associated with that client, it does not map particularly well to the global metrics exported by this

patch.

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

If a generic cross-driver interface for this kind of GPU telemetry emerges, I'm happy to switch to it. However, no such interface currently exists for devfreq-based device utilization, so debugfs seemed like the most appropriate existing option. Suggestions for a better

interface are welcome.

So my point really is someone should ideally implement a better interface that multiple drivers can use. Having a point hack for one driver doesn't really help the situation.

Quoted 6 lines
Quoted 6 lines

Indeed you can get the load information with ftrace already:

cd /sys/kernel/tracing
echo 0 > tracing_on
echo > trace
echo 'dev_name == "fb000000.gpu"' >

events/devfreq/devfreq_monitor/filter

Quoted 11 lines
Quoted 11 lines

echo 1 > events/devfreq/devfreq_monitor/enable
echo 1 > tracing_on
cat trace_pipe

And you'll get a stream of messages when the GPU is in use which includes a "load=xx" value at the end.

If this is going to be extended to other properties for a user space tool then we should probably be putting this in sysfs and trying to come up with a design that other drivers can copy.

Quoted 8 lines
Quoted 3 lines

Thanks,
Steve

Hi Steve,

Thanks for the feedback and sharing.
I agree that a generic interface shared by multiple drivers would be

preferable in the long term.

Quoted 5 lines

For our use case, we need to provide customers with a simple way to quickly observe GPU performance metrics from a userspace tuning tool. Even though the devfreq_monitor tracepoint already exposes the load information, ftrace is typically not enabled or supported in our deployed

products, making it unsuitable as a user-facing interface for the tool.

You are enabling debugfs but not ftrace? Seems like an odd choice if you want to monitor and tune your system.

We are working on adding performance counters support to Panthor that will expose performance metrics in a more meaningful way.

Quoted 4 lines

As far as I know, there is currently no generic DRM/devfreq interface for querying device-wide GPU utilization on demand. Given that gap, exporting the information through debugfs seemed like the most practical

option for Panthor today.

Quoted 9 lines

Knowing that the GPU was 80% busy without knowing exactly who was submitting jobs is not a particularly useful information, in my opinion. I would like to understand better what you are trying to do with the information and why implementing a devfreq governor for your usecase would not be useful here.

Best regards,
Liviu

Hi Liviu

Happy to hear that performance counters will be supported to Panthor. Are there any plans to expose detailed utilization statistics of gpu device/ fragment shader/non-fragment shader/tiler to panthor debugfs?
If yes, do you have a rough timeline for this?

The userspace tuning tool is developed to gather both overall gpu statistics (frequency, utilization, etc.) and gpu per-process information (memory usage, etc.) from debugfs and expose to user for reference.
The original idea of this patch is that performance counters are not available yet, so obtaining overall gpu utilization from DVFS appears to be the most practical approach for now.

The tool is also intended to work without ftrace, since ftrace is usually disabled by default. As a result, debugfs is currently our preferred interface for collecting such information.

Thanks,
Guangliu

Quoted 230 lines
Quoted 150 lines

Thanks,
Guangliu

Quoted 146 lines
Quoted 146 lines

Best Regards,
Guangliu

Quoted 143 lines
Quoted 9 lines

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms).
The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80

+++++++++++++++++++++++++++++++

drivers/gpu/drm/panthor/panthor_devfreq.h | 6 +++

Quoted 25 lines
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>  #include <linux/pm_opp.h>
 
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 54

Quoted 8 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +5 -0
@@ -43,6 +47,22 @@ struct panthor_devfreq {
       * and panthor_devfreq_record_{busy,idle}().
       */
      spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+     /**
+      * @last_busy_ns: Busy time in nanoseconds of the last
+completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 56

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq {

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +7 -0
+      * Protected by @lock.
+      */
+     u64 last_busy_ns;
+
+     /**
+      * @last_total_ns: Total time in nanoseconds of the last
+ completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 65

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

Quoted 65 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
+      * Protected by @lock.
+      */
+     u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct

panthor_devfreq
*pdevfreq) @@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,

      status->busy_time = ktime_to_ns(pdevfreq->busy_time);
drivers/gpu/drm/panthor/panthor_devfreq.c +6 -1
+#ifdef CONFIG_DEBUG_FS
+     pdevfreq->last_busy_ns = status->busy_time;
+     pdevfreq->last_total_ns = status->total_time; #endif
+
      panthor_devfreq_reset(pdevfreq);
 
      spin_unlock_irqrestore(&pdevfreq->lock, irqflags); @@
-283,6
+308,17 @@ void panthor_devfreq_suspend(struct panthor_device
+*ptdev)
              return;
 
      drm_WARN_ON(&ptdev->base,

devfreq_suspend_device(pdevfreq->devfreq));

drivers/gpu/drm/panthor/panthor_devfreq.c +11 -0
+
+#ifdef CONFIG_DEBUG_FS
+     {
+             unsigned long irqflags;
+
+             spin_lock_irqsave(&pdevfreq->lock, irqflags);
+             pdevfreq->last_busy_ns = 0;
+             pdevfreq->last_total_ns = 0;
+             spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+     }
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device *ptdev)

@@
-332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

      return freq;

}

drivers/gpu/drm/panthor/panthor_devfreq.c +18 -0
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file *m,
+void
+*unused) {
+     struct panthor_device *ptdev = m->private;
+     struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+     unsigned long irqflags;
+     unsigned int gpu_load;
+     u64 total_ns;
+     u64 busy_ns;
+
+     if (!pdevfreq->devfreq) {
+             seq_puts(m, "devfreq not initialized\n");
+             return 0;
+     }
+
+     spin_lock_irqsave(&pdevfreq->lock, irqflags);

drivers/gpu/drm/panthor/panthor_devfreq.c unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+     busy_ns = pdevfreq->last_busy_ns;
+     total_ns = pdevfreq->last_total_ns;
+     spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+     busy_ns = min(busy_ns, total_ns);
+     gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns *
+ 100ULL,
+ total_ns) : 0;
+
+     seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu

gpu_load: %u%%\n",

Quoted 9 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +9 -0
+                busy_ns, total_ns - busy_ns, gpu_load);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq debugfs
+entries
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/panthor/panthor_devfreq.c

Quoted 8 lines

+ * @minor: DRM minor.
+ */

drivers/gpu/drm/panthor/panthor_devfreq.c +6 -0
+void panthor_devfreq_debugfs_init(struct drm_minor *minor) {
+     struct panthor_device *ptdev = container_of(minor->dev,
+                                                 struct
+panthor_device, base);
+
+     debugfs_create_file("gpu_load", 0444, minor->debugfs_root,

ptdev,

Quoted 55 lines
Quoted 55 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ &panthor_devfreq_gpu_load_fops); }

#endif

Quoted 53 lines
Quoted 53 lines

/*

Quoted 52 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +6 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__
 #define __PANTHOR_DEVFREQ_H__
@@ -20,4 +21,9 @@ void panthor_devfreq_record_idle(struct
 panthor_device *ptdev);
 
 unsigned long panthor_devfreq_get_freq(struct panthor_device
 *ptdev);
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor);
+#endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */ diff --git

a/drivers/gpu/drm/panthor/panthor_drv.c
b/drivers/gpu/drm/panthor/panthor_drv.c
index e8dc4096c1d2..4093a6d21337 100644

drivers/gpu/drm/panthor/panthor_drv.c +1 -0
@@ -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>

drivers/gpu/drm/panthor/panthor_drv.c +1 -1
@@ -1761,6 +1762,7 @@ static void panthor_debugfs_init(struct
 drm_minor *minor)  {
      panthor_mmu_debugfs_init(minor);
      panthor_gem_debugfs_init(minor);
+     panthor_devfreq_debugfs_init(minor);
 }
 #endif
 
 
---

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

Best regards,
--
Guangliu Ding <[email protected]>

--
====================

| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
maintainer
#7 lore raw
Quoted 115 lines · Guangliu Ding
Quoted 115 lines · Guangliu Ding
Quoted 24 lines
Quoted 24 lines · Guangliu Ding
Quoted 12 lines
Quoted 12 lines · Guangliu Ding
Quoted 11 lines

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window
(~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Hi Guangliu,

I'm puzzled exactly what you're trying to achieve with this. I can see that getting the GPU load might be useful, we do already have the 'fdinfo' mechanism to do this in a per-client manner but nothing good for

"whole GPU"

Quoted 2 lines
Quoted 2 lines

measurements.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

But stashing it in debugfs and formatting it as a string seems odd. Do you have a tool which uses this file, or is just for 'cat'ing to see the

instantaneous load?

Quoted 3 lines
Quoted 3 lines

Ideally we'd have something that would provide this information in a format that all drivers could implement, and not rely on debugfs

files.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

Thanks,
Steve

Hi Steve

Panthor currently exposes very limited runtime telemetry. The intent is to expose utilization in this patch, together with other device-wide GPU runtime metrics (frequency, shader activity, draw-call counts,

Quoted 6 lines
Quoted 6 lines

memory usage, etc.) to a userspace tool for monitoring and workload-optimization purposes.

Quoted 4 lines

fdinfo is primarily a per-client interface. Since it requires an open DRM fd and reports information associated with that client, it does not map particularly well to the global metrics exported by this

patch.

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

If a generic cross-driver interface for this kind of GPU telemetry emerges, I'm happy to switch to it. However, no such interface currently exists for devfreq-based device utilization, so debugfs seemed like the most appropriate existing option. Suggestions for a better

interface are welcome.

So my point really is someone should ideally implement a better interface that multiple drivers can use. Having a point hack for one driver doesn't really help the situation.

Quoted 6 lines
Quoted 6 lines

Indeed you can get the load information with ftrace already:

cd /sys/kernel/tracing
echo 0 > tracing_on
echo > trace
echo 'dev_name == "fb000000.gpu"' >

events/devfreq/devfreq_monitor/filter

Quoted 11 lines
Quoted 11 lines

echo 1 > events/devfreq/devfreq_monitor/enable
echo 1 > tracing_on
cat trace_pipe

And you'll get a stream of messages when the GPU is in use which includes a "load=xx" value at the end.

If this is going to be extended to other properties for a user space tool then we should probably be putting this in sysfs and trying to come up with a design that other drivers can copy.

Quoted 8 lines
Quoted 3 lines

Thanks,
Steve

Hi Steve,

Thanks for the feedback and sharing.
I agree that a generic interface shared by multiple drivers would be

preferable in the long term.

Quoted 5 lines

For our use case, we need to provide customers with a simple way to quickly observe GPU performance metrics from a userspace tuning tool. Even though the devfreq_monitor tracepoint already exposes the load information, ftrace is typically not enabled or supported in our deployed

products, making it unsuitable as a user-facing interface for the tool.

You are enabling debugfs but not ftrace? Seems like an odd choice if you want to monitor and tune your system.

We are working on adding performance counters support to Panthor that will expose performance metrics in a more meaningful way.

Quoted 4 lines

As far as I know, there is currently no generic DRM/devfreq interface for querying device-wide GPU utilization on demand. Given that gap, exporting the information through debugfs seemed like the most practical

option for Panthor today.

Knowing that the GPU was 80% busy without knowing exactly who was submitting jobs is not a particularly useful information, in my opinion. I would like to understand better what you are trying to do with the information and why implementing a devfreq governor for your usecase would not be useful here.

Quoted 4 lines
Quoted 3 lines

Best regards,
Liviu

Hi Liviu

Hi Guangliu,

Sorry for the delay in response, I was on holiday for a week.

Quoted 5 lines

Happy to hear that performance counters will be supported to Panthor. Are there any plans to expose detailed utilization statistics of gpu device/ fragment shader/non-fragment shader/tiler to panthor debugfs?
If yes, do you have a rough timeline for this?

The way we're going to expose counters will be per-app and with checks for permission to view the counters, so not a debugfs interface.

Quoted 11 lines

The userspace tuning tool is developed to gather both overall gpu statistics (frequency, utilization, etc.) and gpu per-process information (memory usage, etc.) from debugfs and expose to user for reference.
The original idea of this patch is that performance counters are not available yet, so obtaining overall gpu utilization from DVFS appears to be the most practical approach for now.

The tool is also intended to work without ftrace, since ftrace is usually disabled by default. As a result, debugfs is currently our preferred interface for collecting such information.

Our plan is to support Perfetto for getting the statistics out of the GPU as that is more of a standard tool for app developers. Did you had a look it and are you sure it doesn't meet your requirements?

Best regards,
Liviu

Quoted 234 lines

Thanks,
Guangliu

Quoted 230 lines
Quoted 150 lines

Thanks,
Guangliu

Quoted 146 lines
Quoted 146 lines

Best Regards,
Guangliu

Quoted 143 lines
Quoted 9 lines

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms).
The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80

+++++++++++++++++++++++++++++++

drivers/gpu/drm/panthor/panthor_devfreq.h | 6 +++

Quoted 25 lines
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>  #include <linux/pm_opp.h>
 
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 54

Quoted 8 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +5 -0
@@ -43,6 +47,22 @@ struct panthor_devfreq {
       * and panthor_devfreq_record_{busy,idle}().
       */
      spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+     /**
+      * @last_busy_ns: Busy time in nanoseconds of the last
+completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 56

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 63

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +7 -0
+      * Protected by @lock.
+      */
+     u64 last_busy_ns;
+
+     /**
+      * @last_total_ns: Total time in nanoseconds of the last
+ completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 65

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

Quoted 65 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
+      * Protected by @lock.
+      */
+     u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct

panthor_devfreq
*pdevfreq) @@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,

      status->busy_time = ktime_to_ns(pdevfreq->busy_time);
drivers/gpu/drm/panthor/panthor_devfreq.c +6 -1
+#ifdef CONFIG_DEBUG_FS
+     pdevfreq->last_busy_ns = status->busy_time;
+     pdevfreq->last_total_ns = status->total_time; #endif
+
      panthor_devfreq_reset(pdevfreq);
 
      spin_unlock_irqrestore(&pdevfreq->lock, irqflags); @@
-283,6
+308,17 @@ void panthor_devfreq_suspend(struct panthor_device
+*ptdev)
              return;
 
      drm_WARN_ON(&ptdev->base,

devfreq_suspend_device(pdevfreq->devfreq));

drivers/gpu/drm/panthor/panthor_devfreq.c +11 -0
+
+#ifdef CONFIG_DEBUG_FS
+     {
+             unsigned long irqflags;
+
+             spin_lock_irqsave(&pdevfreq->lock, irqflags);
+             pdevfreq->last_busy_ns = 0;
+             pdevfreq->last_total_ns = 0;
+             spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+     }
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device *ptdev)

@@
-332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

      return freq;

}

drivers/gpu/drm/panthor/panthor_devfreq.c +18 -0
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file *m,
+void
+*unused) {
+     struct panthor_device *ptdev = m->private;
+     struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+     unsigned long irqflags;
+     unsigned int gpu_load;
+     u64 total_ns;
+     u64 busy_ns;
+
+     if (!pdevfreq->devfreq) {
+             seq_puts(m, "devfreq not initialized\n");
+             return 0;
+     }
+
+     spin_lock_irqsave(&pdevfreq->lock, irqflags);

drivers/gpu/drm/panthor/panthor_devfreq.c

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+     busy_ns = pdevfreq->last_busy_ns;
+     total_ns = pdevfreq->last_total_ns;
+     spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+     busy_ns = min(busy_ns, total_ns);
+     gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns *
+ 100ULL,
+ total_ns) : 0;
+
+     seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu

gpu_load: %u%%\n",

Quoted 9 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +9 -0
+                busy_ns, total_ns - busy_ns, gpu_load);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq debugfs
+entries
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/panthor/panthor_devfreq.c

Quoted 8 lines

+ * @minor: DRM minor.
+ */

drivers/gpu/drm/panthor/panthor_devfreq.c +6 -0
+void panthor_devfreq_debugfs_init(struct drm_minor *minor) {
+     struct panthor_device *ptdev = container_of(minor->dev,
+                                                 struct
+panthor_device, base);
+
+     debugfs_create_file("gpu_load", 0444, minor->debugfs_root,

ptdev,

Quoted 55 lines
Quoted 55 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ &panthor_devfreq_gpu_load_fops); }

#endif

Quoted 53 lines
Quoted 53 lines

/*

Quoted 52 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +6 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__
 #define __PANTHOR_DEVFREQ_H__
@@ -20,4 +21,9 @@ void panthor_devfreq_record_idle(struct
 panthor_device *ptdev);
 
 unsigned long panthor_devfreq_get_freq(struct panthor_device
 *ptdev);
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor);
+#endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */ diff --git

a/drivers/gpu/drm/panthor/panthor_drv.c
b/drivers/gpu/drm/panthor/panthor_drv.c
index e8dc4096c1d2..4093a6d21337 100644

drivers/gpu/drm/panthor/panthor_drv.c +1 -0
@@ -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>

drivers/gpu/drm/panthor/panthor_drv.c +1 -1
@@ -1761,6 +1762,7 @@ static void panthor_debugfs_init(struct
 drm_minor *minor)  {
      panthor_mmu_debugfs_init(minor);
      panthor_gem_debugfs_init(minor);
+     panthor_devfreq_debugfs_init(minor);
 }
 #endif
 
 
---

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

Best regards,
--
Guangliu Ding <[email protected]>

--
====================

| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
#8 lore raw
Quoted 131 lines · Guangliu Ding
Quoted 120 lines
Quoted 120 lines · Guangliu Ding
Quoted 24 lines
Quoted 24 lines · Guangliu Ding
Quoted 12 lines
Quoted 12 lines · Guangliu Ding
Quoted 11 lines

Expose GPU utilization via /sys/kernel/debug/dri/<N>/gpu_load. The file reports busy_time_ns, idle_time_ns and gpu_load %.

Values are snapshotted at the end of each devfreq sampling window
(~50 ms) rather than read from live accumulators, avoiding load swings over short observation intervals.

The snapshot is cleared on suspend to avoid stale data when the GPU is powered off.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Hi Guangliu,

I'm puzzled exactly what you're trying to achieve with this. I can see that getting the GPU load might be useful, we do already have the 'fdinfo' mechanism to do this in a per-client manner but nothing good for

"whole GPU"

Quoted 2 lines
Quoted 2 lines

measurements.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

But stashing it in debugfs and formatting it as a string seems odd. Do you have a tool which uses this file, or is just for 'cat'ing to see the

instantaneous load?

Quoted 4 lines
Quoted 4 lines

Ideally we'd have something that would provide this information in a format that all drivers could implement, and not rely on debugfs

files.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

Thanks,
Steve

Hi Steve

Panthor currently exposes very limited runtime telemetry. The intent is to expose utilization in this patch, together with other device-wide GPU runtime metrics (frequency, shader activity, draw-call counts,

Quoted 7 lines
Quoted 7 lines

memory usage, etc.) to a userspace tool for monitoring and workload-optimization purposes.

Quoted 5 lines

fdinfo is primarily a per-client interface. Since it requires an open DRM fd and reports information associated with that client, it does not map particularly well to the global metrics exported by this

patch.

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

If a generic cross-driver interface for this kind of GPU telemetry emerges, I'm happy to switch to it. However, no such interface currently exists for devfreq-based device utilization, so debugfs seemed like the most appropriate existing option. Suggestions for a better

interface are welcome.

So my point really is someone should ideally implement a better interface that multiple drivers can use. Having a point hack for one driver doesn't really help the situation.

Quoted 6 lines
Quoted 6 lines

Indeed you can get the load information with ftrace already:

cd /sys/kernel/tracing
echo 0 > tracing_on
echo > trace
echo 'dev_name == "fb000000.gpu"' >

events/devfreq/devfreq_monitor/filter

Quoted 15 lines
Quoted 7 lines

echo 1 > events/devfreq/devfreq_monitor/enable
echo 1 > tracing_on
cat trace_pipe

And you'll get a stream of messages when the GPU is in use which includes a "load=xx" value at the end.

Quoted 7 lines

If this is going to be extended to other properties for a user space tool then we should probably be putting this in sysfs and trying to come up with a design that other drivers can copy.

Thanks,
Steve

Quoted 5 lines

Hi Steve,

Thanks for the feedback and sharing.
I agree that a generic interface shared by multiple drivers would be

preferable in the long term.

Quoted 6 lines

For our use case, we need to provide customers with a simple way to quickly observe GPU performance metrics from a userspace tuning tool. Even though the devfreq_monitor tracepoint already exposes the load information, ftrace is typically not enabled or supported in our deployed

products, making it unsuitable as a user-facing interface for the tool.

You are enabling debugfs but not ftrace? Seems like an odd choice if you want to monitor and tune your system.

We are working on adding performance counters support to Panthor that will expose performance metrics in a more meaningful way.

Quoted 5 lines

As far as I know, there is currently no generic DRM/devfreq interface for querying device-wide GPU utilization on demand. Given that gap, exporting the information through debugfs seemed like the most practical

option for Panthor today.

Knowing that the GPU was 80% busy without knowing exactly who was submitting jobs is not a particularly useful information, in my opinion. I would like to understand better what you are trying to do with the information and why implementing a devfreq governor for your usecase would not be useful here.

Quoted 4 lines
Quoted 3 lines

Best regards,
Liviu

Hi Liviu

Hi Guangliu,

Sorry for the delay in response, I was on holiday for a week.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

Happy to hear that performance counters will be supported to Panthor. Are there any plans to expose detailed utilization statistics of gpu device/ fragment shader/non-fragment shader/tiler to panthor debugfs? If yes, do you have a rough timeline for this?

The way we're going to expose counters will be per-app and with checks for permission to view the counters, so not a debugfs interface.

Got it. It seems the GPU tuning data in Panthor driver almost to be per-process based, not overall GPU, even though additional performance counter is supported.
I will raise a ticket to ARM support for more details and timeline for performance counter support in the future Panthor driver.

Quoted 8 lines
Quoted 8 lines

The userspace tuning tool is developed to gather both overall gpu statistics (frequency, utilization, etc.) and gpu per-process information (memory usage,
etc.) from debugfs and expose to user for reference.
The original idea of this patch is that performance counters are not available yet, so obtaining overall gpu utilization from DVFS appears to be the most practical approach for now.

Quoted 7 lines
Quoted 3 lines

The tool is also intended to work without ftrace, since ftrace is usually disabled by default. As a result, debugfs is currently our preferred interface for collecting such information.

Our plan is to support Perfetto for getting the statistics out of the GPU as that is more of a standard tool for app developers. Did you had a look it and are you sure it doesn't meet your requirements?

Thanks for your suggestion. I will have a look at Perfetto and confirm if it can be A replacement.

Thanks,
Guangliu

Quoted 251 lines

Best regards,
Liviu

Quoted 166 lines

Thanks,
Guangliu

Quoted 162 lines
Quoted 152 lines

Thanks,
Guangliu

Quoted 148 lines
Quoted 148 lines

Best Regards,
Guangliu

Quoted 145 lines
Quoted 9 lines

---
Add /sys/kernel/debug/dri/<N>/gpu_load to expose GPU utilisation from the last devfreq sampling window (~50 ms). The file reports busy_time_ns, idle_time_ns and load percentage.

Tested on NXP i.MX95 EVK (Mali-G310 V2).

---
 drivers/gpu/drm/panthor/panthor_devfreq.c | 80

+++++++++++++++++++++++++++++++

drivers/gpu/drm/panthor/panthor_devfreq.h | 6 +++

Quoted 25 lines
 drivers/gpu/drm/panthor/panthor_drv.c     |  2 +
 3 files changed, 88 insertions(+)
drivers/gpu/drm/panthor/panthor_devfreq.c +3 -0
index 2249b41ca4af..1b3f58ddfbd3 100644
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0 or MIT
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #include <linux/clk.h>
+#include <linux/debugfs.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq_cooling.h>
+#include <linux/math64.h>
 #include <linux/platform_device.h>  #include

<linux/pm_opp.h>

drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+#include <drm/drm_file.h>
 #include <drm/drm_managed.h>  #include <drm/drm_print.h>

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 54

Quoted 8 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +5 -0
@@ -43,6 +47,22 @@ struct panthor_devfreq {
       * and panthor_devfreq_record_{busy,idle}().
       */
      spinlock_t lock;
+
+#ifdef CONFIG_DEBUG_FS
+     /**
+      * @last_busy_ns: Busy time in nanoseconds of the last
+completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 56

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 63

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +7 -0
+      * Protected by @lock.
+      */
+     u64 last_busy_ns;
+
+     /**
+      * @last_total_ns: Total time in nanoseconds of the
+ last completed

devfreq window.

drivers/gpu/drm/panthor/panthor_devfreq.c struct panthor_devfreq { · line 65

Quoted 2 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +2 -0
+      * Updated by panthor_devfreq_get_dev_status() before
+ resetting the

counters.

Quoted 66 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +4 -0
+      * Protected by @lock.
+      */
+     u64 last_total_ns;
+#endif
 };
 
 static void panthor_devfreq_update_utilization(struct

panthor_devfreq
*pdevfreq) @@ -101,6 +121,11 @@ static int panthor_devfreq_get_dev_status(struct device *dev,

      status->busy_time = ktime_to_ns(pdevfreq->busy_time);
drivers/gpu/drm/panthor/panthor_devfreq.c +7 -1
+#ifdef CONFIG_DEBUG_FS
+     pdevfreq->last_busy_ns = status->busy_time;
+     pdevfreq->last_total_ns = status->total_time; #endif
+
      panthor_devfreq_reset(pdevfreq);
 
      spin_unlock_irqrestore(&pdevfreq->lock, irqflags); @@
-283,6
+308,17 @@ void panthor_devfreq_suspend(struct
+panthor_device
+*ptdev)
              return;
 
      drm_WARN_ON(&ptdev->base,

devfreq_suspend_device(pdevfreq->devfreq));

drivers/gpu/drm/panthor/panthor_devfreq.c +11 -0
+
+#ifdef CONFIG_DEBUG_FS
+     {
+             unsigned long irqflags;
+
+             spin_lock_irqsave(&pdevfreq->lock, irqflags);
+             pdevfreq->last_busy_ns = 0;
+             pdevfreq->last_total_ns = 0;
+             spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+     }
+#endif
 }
 
 void panthor_devfreq_record_busy(struct panthor_device

*ptdev) @@
-332,3 +368,47 @@ unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)

      return freq;

}

drivers/gpu/drm/panthor/panthor_devfreq.c +18 -0
+
+#ifdef CONFIG_DEBUG_FS
+static int panthor_devfreq_gpu_load_show(struct seq_file
+*m, void
+*unused) {
+     struct panthor_device *ptdev = m->private;
+     struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+     unsigned long irqflags;
+     unsigned int gpu_load;
+     u64 total_ns;
+     u64 busy_ns;
+
+     if (!pdevfreq->devfreq) {
+             seq_puts(m, "devfreq not initialized\n");
+             return 0;
+     }
+
+     spin_lock_irqsave(&pdevfreq->lock, irqflags);

drivers/gpu/drm/panthor/panthor_devfreq.c

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+     busy_ns = pdevfreq->last_busy_ns;
+     total_ns = pdevfreq->last_total_ns;
+     spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
+
+     busy_ns = min(busy_ns, total_ns);
+     gpu_load = total_ns ? (unsigned int)div64_u64(busy_ns
+ * 100ULL,
+ total_ns) : 0;
+
+     seq_printf(m, "busy_time_ns: %llu  idle_time_ns: %llu

gpu_load: %u%%\n",

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +10 -0
+                busy_ns, total_ns - busy_ns, gpu_load);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(panthor_devfreq_gpu_load);
+
+/**
+ * panthor_devfreq_debugfs_init() - Initialize devfreq
+debugfs entries
+ * @minor: DRM minor.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/panthor/panthor_devfreq.c

Quoted 8 lines

+ */

drivers/gpu/drm/panthor/panthor_devfreq.c +7 -0
+void panthor_devfreq_debugfs_init(struct drm_minor *minor) {
+     struct panthor_device *ptdev = container_of(minor->dev,
+                                                 struct
+panthor_device, base);
+
+     debugfs_create_file("gpu_load", 0444,
+ minor->debugfs_root,

ptdev,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

&panthor_devfreq_gpu_load_fops); }

Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines

#endif

Quoted 39 lines
Quoted 39 lines

/*

Quoted 38 lines
drivers/gpu/drm/panthor/panthor_devfreq.c +1 -0
+CONFIG_DEBUG_FS */
drivers/gpu/drm/panthor/panthor_devfreq.h +1 -0
index f8e29e02f66c..4552569abfe4 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 or MIT */
 /* Copyright 2019 Collabora ltd. */
+/* Copyright 2026 NXP */
 
 #ifndef __PANTHOR_DEVFREQ_H__  #define

__PANTHOR_DEVFREQ_H__ @@ -20,4 +21,9 @@ void
panthor_devfreq_record_idle(struct
panthor_device *ptdev);

unsigned long panthor_devfreq_get_freq(struct
panthor_device *ptdev);

drivers/gpu/drm/panthor/panthor_devfreq.h +5 -0
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void panthor_devfreq_debugfs_init(struct drm_minor *minor);
+#endif
+
 #endif /* __PANTHOR_DEVFREQ_H__ */ diff --git

a/drivers/gpu/drm/panthor/panthor_drv.c
b/drivers/gpu/drm/panthor/panthor_drv.c
index e8dc4096c1d2..4093a6d21337 100644

drivers/gpu/drm/panthor/panthor_drv.c +0 -0
@@ -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 */

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

#ifdef CONFIG_ARM_ARCH_TIMER #include

<asm/arch_timer.h>

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/panthor/panthor_drv.c +1 -1
@@ -1761,6 +1762,7 @@ static void
 panthor_debugfs_init(struct drm_minor *minor)  {
      panthor_mmu_debugfs_init(minor);
      panthor_gem_debugfs_init(minor);
+     panthor_devfreq_debugfs_init(minor);
 }
 #endif
 
 
---

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260706-master-bd0eef99ca8e

Best regards,
--
Guangliu Ding <[email protected]>

Quoted 9 lines
Quoted 9 lines

--
====================

| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

--
====================

| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯