Skip to contentSkip to conversation

Add debugfs to expose G2, G6, G8, G10 and ModS residency

PATCH In review Soham Purkait 3 participants 6 messages May 29, 2025 – May 30, 2025

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

v2 cover Add debugfs to expose G2, G6, G8, G10 and ModS residency

The changes in the first patch is taken from
https://patchwork.freedesktop.org/series/149026/
Thay are added only for compilation and does not
require review.

This patch exposes G2, G6, G8, G10 and ModS residency counter value through
debugfs.

Soham Purkait (3):
Utility function and macro for telemetry reading drm/xe/xe_debugfs: Exposure of G-State residency counter through
debugfs
drm/xe/regs/xe_pmt: Macros for G-State residency offset

 drivers/gpu/drm/xe/regs/xe_pmt.h | 11 ++++++
 drivers/gpu/drm/xe/xe_debugfs.c  | 61 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vsec.c     |  2 +-
 drivers/gpu/drm/xe/xe_vsec.h     |  5 +++
 4 files changed, 78 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 Utility function and macro for telemetry reading

The changes in this patch is taken from
https://patchwork.freedesktop.org/series/149026/
Thay are added only for compilation and does not
require review.

---
 drivers/gpu/drm/xe/regs/xe_pmt.h | 5 +++++
 drivers/gpu/drm/xe/xe_vsec.c     | 2 +-
 drivers/gpu/drm/xe/xe_vsec.h     | 5 +++++
 3 files changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/regs/xe_pmt.h +5 -0
index f45abcd96ba8..b1d4504e4adc 100644
@@ -10,6 +10,11 @@
 #define BMG_PMT_BASE_OFFSET		0xDB000
 #define BMG_DISCOVERY_OFFSET		(SOC_BASE + BMG_PMT_BASE_OFFSET)
 
+#define PUNIT_TELEMETRY_GUID		XE_REG(BMG_DISCOVERY_OFFSET + 0x4)
+#define BMG_ENERGY_STATUS_PMT_OFFSET	(0x30)
+#define ENERGY_PKG			REG_GENMASK64(31, 0)
+#define ENERGY_CARD			REG_GENMASK64(63, 32)
+
 #define BMG_TELEMETRY_BASE_OFFSET	0xE0000
 #define BMG_TELEMETRY_OFFSET		(SOC_BASE + BMG_TELEMETRY_BASE_OFFSET)
 
drivers/gpu/drm/xe/xe_vsec.c +1 -1
index b378848d3b7b..a46e9580b1f4 100644
@@ -149,7 +149,7 @@ static int xe_guid_decode(u32 guid, int *index, u32 *offset)
 	return 0;
 }
 
-static int xe_pmt_telem_read(struct pci_dev *pdev, u32 guid, u64 *data, loff_t user_offset,
+int xe_pmt_telem_read(struct pci_dev *pdev, u32 guid, u64 *data, loff_t user_offset,
 			     u32 count)
 {
 	struct xe_device *xe = pdev_to_xe_device(pdev);
drivers/gpu/drm/xe/xe_vsec.h +5 -0
index 5777c53faec2..6184b875e4b1 100644
@@ -4,8 +4,13 @@
 #ifndef _XE_VSEC_H_
 #define _XE_VSEC_H_
 
+#include "linux/types.h"
+#include "linux/pci.h"
+
 struct xe_device;
 
 void xe_vsec_init(struct xe_device *xe);
+int xe_pmt_telem_read(struct pci_dev *pdev, u32 guid, u64 *data, loff_t user_offset,
+		      u32 count);
 
 #endif
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/3] Utility function and macro for telemetry reading

Quoted 47 lines · Soham Purkait

The changes in this patch is taken from
https://patchwork.freedesktop.org/series/149026/
Thay are added only for compilation and does not
require review.

---
  drivers/gpu/drm/xe/regs/xe_pmt.h | 5 +++++
  drivers/gpu/drm/xe/xe_vsec.c     | 2 +-
  drivers/gpu/drm/xe/xe_vsec.h     | 5 +++++
  3 files changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/regs/xe_pmt.h +5 -0
index f45abcd96ba8..b1d4504e4adc 100644
@@ -10,6 +10,11 @@
  #define BMG_PMT_BASE_OFFSET		0xDB000
  #define BMG_DISCOVERY_OFFSET		(SOC_BASE + BMG_PMT_BASE_OFFSET)
 
+#define PUNIT_TELEMETRY_GUID		XE_REG(BMG_DISCOVERY_OFFSET + 0x4)
+#define BMG_ENERGY_STATUS_PMT_OFFSET	(0x30)
+#define ENERGY_PKG			REG_GENMASK64(31, 0)
+#define ENERGY_CARD			REG_GENMASK64(63, 32)
+
  #define BMG_TELEMETRY_BASE_OFFSET	0xE0000
  #define BMG_TELEMETRY_OFFSET		(SOC_BASE + BMG_TELEMETRY_BASE_OFFSET)
 
drivers/gpu/drm/xe/xe_vsec.c +1 -1
index b378848d3b7b..a46e9580b1f4 100644
@@ -149,7 +149,7 @@ static int xe_guid_decode(u32 guid, int *index, u32 *offset)
  	return 0;
  }
 
-static int xe_pmt_telem_read(struct pci_dev *pdev, u32 guid, u64 *data, loff_t user_offset,
+int xe_pmt_telem_read(struct pci_dev *pdev, u32 guid, u64 *data, loff_t user_offset,
  			     u32 count)
  {
  	struct xe_device *xe = pdev_to_xe_device(pdev);
drivers/gpu/drm/xe/xe_vsec.h +0 -0
index 5777c53faec2..6184b875e4b1 100644
@@ -4,8 +4,13 @@
  #ifndef _XE_VSEC_H_
  #define _XE_VSEC_H_
 

drivers/gpu/drm/xe/xe_vsec.h line 16

Quoted 10 lines
drivers/gpu/drm/xe/xe_vsec.h +5 -0
+#include "linux/types.h"
+#include "linux/pci.h"
+
  struct xe_device;
 
  void xe_vsec_init(struct xe_device *xe);
+int xe_pmt_telem_read(struct pci_dev *pdev, u32 guid, u64 *data, loff_t user_offset,
+		      u32 count);
 
  #endif

These are merged now https://lore.kernel.org/all/[email protected]/ , you can rebase on top of it.

#3 lore raw

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

In reply to Soham Purkait

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

---
 drivers/gpu/drm/xe/xe_debugfs.c | 61 +++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
drivers/gpu/drm/xe/xe_debugfs.c +61 -0
index d0503959a8ed..98e9f3ab6c5e 100644
@@ -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,12 +188,67 @@ 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;
@@ -211,6 +269,9 @@ void xe_debugfs_register(struct xe_device *xe)
 	debugfs_create_file("wedged_mode", 0600, root, xe,
 			    &wedged_mode_fops);
 
+	debugfs_create_file("dgfx_pkg_residencies", 0444, root, 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);
 
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 3/3 drm/xe/regs/xe_pmt: Macros for G-State residency offset

In reply to Soham Purkait

Add G-State residency offset macros for G2, G6, G8, G10
and ModS.

---
 drivers/gpu/drm/xe/regs/xe_pmt.h | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/xe/regs/xe_pmt.h +6 -0
index b1d4504e4adc..23995835a583 100644
@@ -21,4 +21,10 @@
 #define SG_REMAP_INDEX1			XE_REG(SOC_BASE + 0x08)
 #define   SG_REMAP_BITS			REG_GENMASK(31, 24)
 
+#define BMG_G2_RESIDENCY_OFFSET			(0x530)
+#define BMG_G6_RESIDENCY_OFFSET			(0x538)
+#define BMG_G8_RESIDENCY_OFFSET			(0x540)
+#define BMG_G10_RESIDENCY_OFFSET		(0x548)
+#define BMG_MODS_RESIDENCY_OFFSET		(0x4D0)
+
 #endif
Signature · 1 line
2.34.1
#5 lore raw

✗ CI.Patch_applied: failure for Add debugfs to expose G2, G6, G8, G10 and ModS residency (rev2)

In reply to Soham Purkait
== Series Details ==

== Series Details ==

Series: Add debugfs to expose G2, G6, G8, G10 and ModS residency (rev2)
URL : https://patchwork.freedesktop.org/series/149406/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 901190a06230 drm-tip: 2025y-05m-29d-16h-22m-38s UTC integration manifest === git am output follows ===
.git/rebase-apply/patch:35: trailing whitespace.
{
.git/rebase-apply/patch:57: trailing whitespace.

	mmio = xe_root_tile_mmio(xe);	

.git/rebase-apply/patch:103: trailing whitespace.

error: patch failed: drivers/gpu/drm/xe/xe_debugfs.c:185
error: drivers/gpu/drm/xe/xe_debugfs.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Applying: Utility function and macro for telemetry reading
Applying: drm/xe/xe_debugfs: Exposure of G-State residency counter through debugfs Patch failed at 0002 drm/xe/xe_debugfs: Exposure of G-State residency counter through debugfs When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".