[PATCH v1 2/3] drm/xe/xe_debugfs: Exposure of G-State residency counter through debugfs

Soham Purkait soham.purkait at intel.com
Thu May 22 20:49:36 UTC 2025


Add a debugfs node named dgfx_pkg_residencies under gtidle/
in order to obtain the G-State residency counter values
for G2, G6, G8, G10 & ModS.

v1 : Add a debugfs node named dgfx_pkg_residencies under gtidle/
     through which residency counter values for G2, G6, G8, G10
     & ModS is being exposed.                        (Anshuman)
     Included helper function, runtime_get/put, and error handling
     for xe_pmt_telem_read.                          (Riana)

Signed-off-by: Soham Purkait <soham.purkait at intel.com>
---
 drivers/gpu/drm/xe/xe_debugfs.c | 64 +++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_debugfs.c b/drivers/gpu/drm/xe/xe_debugfs.c
index d0503959a8ed..e3419279ab6d 100644
--- a/drivers/gpu/drm/xe/xe_debugfs.c
+++ b/drivers/gpu/drm/xe/xe_debugfs.c
@@ -11,16 +11,19 @@
 
 #include <drm/drm_debugfs.h>
 
+#include "regs/xe_pmt.h"
 #include "xe_bo.h"
 #include "xe_device.h"
 #include "xe_force_wake.h"
 #include "xe_gt_debugfs.h"
 #include "xe_gt_printk.h"
 #include "xe_guc_ads.h"
+#include "xe_mmio.h"
 #include "xe_pm.h"
 #include "xe_pxp_debugfs.h"
 #include "xe_sriov.h"
 #include "xe_step.h"
+#include "xe_vsec.h"
 
 #ifdef CONFIG_DRM_XE_DEBUG
 #include "xe_bo_evict.h"
@@ -185,17 +188,73 @@ static ssize_t wedged_mode_set(struct file *f, const char __user *ubuf,
 	return size;
 }
 
+static int read_residency_counter(struct xe_device *xe, struct xe_mmio *mmio,
+                                  u64 *dst, u32 offset, char *name)
+{	
+	int ret = xe_pmt_telem_read(to_pci_dev(xe->drm.dev),
+				xe_mmio_read32(mmio, PUNIT_TELEMETRY_GUID),
+				dst, offset, sizeof(u64));
+	if (ret != sizeof(u64)) {
+		drm_warn(&xe->drm, "%s residency counter failed to read, ret %d\n", name, ret);
+	}
+	return 0;
+}
+
+
+static ssize_t dgfx_pkg_residencies_show(struct file *f, char __user *ubuf,
+				 size_t size, loff_t *pos)
+{
+	u64 g_states;
+	char buf[256];
+	int len = 0;
+	struct xe_device *xe;
+	struct xe_mmio *mmio;
+
+	xe = file_inode(f)->i_private;
+	xe_pm_runtime_get(xe);
+	mmio = xe_root_tile_mmio(xe);	
+
+	g_states = 0;
+	read_residency_counter(xe, mmio, &g_states, BMG_G2_RESIDENCY_OFFSET, "G2");
+	len = scnprintf(buf, sizeof(buf), "Package G2: %llu\n", g_states);
+
+	g_states = 0;
+	read_residency_counter(xe, mmio, &g_states, BMG_G6_RESIDENCY_OFFSET, "G6");
+	len += scnprintf(buf + len, sizeof(buf) - len, "Package G6: %llu\n", g_states);
+
+	g_states = 0;
+	read_residency_counter(xe, mmio, &g_states, BMG_G8_RESIDENCY_OFFSET, "G8");
+	len += scnprintf(buf + len, sizeof(buf) - len, "Package G8: %llu\n", g_states);
+
+	g_states = 0;
+	read_residency_counter(xe, mmio, &g_states, BMG_G10_RESIDENCY_OFFSET, "G10");
+	len += scnprintf(buf + len, sizeof(buf) - len, "Package G10: %llu\n", g_states);
+
+	g_states = 0;
+	read_residency_counter(xe, mmio, &g_states, BMG_MODS_RESIDENCY_OFFSET, "ModS");
+	len += scnprintf(buf + len, sizeof(buf) - len, "Package ModS: %llu\n", g_states);
+
+	xe_pm_runtime_put(xe);
+	return simple_read_from_buffer(ubuf, size, pos, buf, len);
+}
+
 static const struct file_operations wedged_mode_fops = {
 	.owner = THIS_MODULE,
 	.read = wedged_mode_show,
 	.write = wedged_mode_set,
 };
 
+static const struct file_operations dgfx_pkg_residencies_fops = {
+	.owner = THIS_MODULE,
+	.read = dgfx_pkg_residencies_show,
+};
+
 void xe_debugfs_register(struct xe_device *xe)
 {
 	struct ttm_device *bdev = &xe->ttm;
 	struct drm_minor *minor = xe->drm.primary;
 	struct dentry *root = minor->debugfs_root;
+	struct dentry *gtidle_d;
 	struct ttm_resource_manager *man;
 	struct xe_gt *gt;
 	u32 mem_type;
@@ -211,6 +270,11 @@ void xe_debugfs_register(struct xe_device *xe)
 	debugfs_create_file("wedged_mode", 0600, root, xe,
 			    &wedged_mode_fops);
 
+	gtidle_d = debugfs_create_dir("gtidle", root);
+
+	debugfs_create_file("dgfx_pkg_residencies", 0444, gtidle_d, xe,
+			    &dgfx_pkg_residencies_fops);
+    
 	for (mem_type = XE_PL_VRAM0; mem_type <= XE_PL_VRAM1; ++mem_type) {
 		man = ttm_manager_type(bdev, mem_type);
 
-- 
2.34.1



More information about the Intel-xe mailing list