[PATCH 3/3] drm/xe/xe_debugfs: Exposure of pcie link state residency counters through debugfs

Soham Purkait soham.purkait at intel.com
Thu May 29 19:26:20 UTC 2025


    Add a debugfs node named dgfx_link_state_residencys in order to
obtain the pcie link state residency counter values for L0,
L1, L1.2

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

diff --git a/drivers/gpu/drm/xe/xe_debugfs.c b/drivers/gpu/drm/xe/xe_debugfs.c
index d83cd6ed3fa8..41a7302a9286 100644
--- a/drivers/gpu/drm/xe/xe_debugfs.c
+++ b/drivers/gpu/drm/xe/xe_debugfs.c
@@ -185,6 +185,47 @@ 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_link_state_residencys_show(struct file *f, char __user *ubuf,
+				 size_t size, loff_t *pos)
+{
+	u64 link_res;
+	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);	
+
+	link_res = 0;
+	read_residency_counter(xe, mmio, &link_res, PCIE_LINK_L0_RESIDENCY_COUNTER, "PCIE LINK L0");
+	len = scnprintf(buf, sizeof(buf), "PCIE LINK L0 RESIDENCY :  %llu\n", link_res);
+
+	link_res = 0;
+	read_residency_counter(xe, mmio, &link_res, PCIE_LINK_L1_RESIDENCY_COUNTER, "PCIE LINK L1");
+	len += scnprintf(buf + len, sizeof(buf) - len, "PCIE LINK L1 RESIDENCY : %llu\n", link_res);
+
+	link_res = 0;
+	read_residency_counter(xe, mmio, &link_res, PCIE_LINK_L1_2_RESIDENCY_COUNTER, "PCIE LINK L1.2");
+	len += scnprintf(buf + len, sizeof(buf) - len, "PCIE LINK L1.2 RESIDENCY : %llu\n", link_res);
+
+	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,
@@ -226,6 +267,11 @@ static const struct file_operations atomic_svm_timeslice_ms_fops = {
 	.write = atomic_svm_timeslice_ms_set,
 };
 
+static const struct file_operations dgfx_link_state_residencys_fops = {
+	.owner = THIS_MODULE,
+	.read = dgfx_link_state_residencys_show,
+};
+
 void xe_debugfs_register(struct xe_device *xe)
 {
 	struct ttm_device *bdev = &xe->ttm;
@@ -249,6 +295,9 @@ void xe_debugfs_register(struct xe_device *xe)
 	debugfs_create_file("atomic_svm_timeslice_ms", 0600, root, xe,
 			    &atomic_svm_timeslice_ms_fops);
 
+	debugfs_create_file("dgfx_link_state_residencys", 0444, root, xe,
+			    &dgfx_link_state_residencys_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