Skip to contentSkip to conversation

Add throttle reasosn sysfs

PATCH In review Sujaritha Sundaresan 4 participants 9 messages Sep 26, 2023 – Sep 27, 2023

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

v3 cover Add throttle reasosn sysfs

Add throttle reasons sysfs under device/tile<n>/gt<n>

Sujaritha Sundaresan (1):
drm/xe: Add throttle reasons sysfs attributes

 drivers/gpu/drm/xe/Makefile               |   1 +
 drivers/gpu/drm/xe/regs/xe_gt_regs.h      |  12 +
 drivers/gpu/drm/xe/xe_gt_sysfs.c          |   3 +
 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c | 257 ++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h |  16 ++
 5 files changed, 289 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c
 create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/1 drm/xe: Add throttle reasons sysfs attributes

Add throttle reasons sysfs interface under device/../gt#/ Currently there is one overall status and eight reasons attributes.

The new sysfs structure will have the below layout

device/tile<n>/gt<n>

               ├── gt0
               │   └── throttle
               │       ├── <throttle_reasons>
               │
               │
               ├── gtN
               │   └── throttle
               │       ├── <throttle_reasons>

v2: Fix review comments (Riana)
Move init call (Matt)

v3: Remove xe_gt_throttle (Riana)
Make functions static (Rodrigo)

---
 drivers/gpu/drm/xe/Makefile               |   1 +
 drivers/gpu/drm/xe/regs/xe_gt_regs.h      |  12 +
 drivers/gpu/drm/xe/xe_gt_sysfs.c          |   3 +
 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c | 257 ++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h |  16 ++
 5 files changed, 289 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c
 create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h
drivers/gpu/drm/xe/Makefile +1 -0
index b1681d1416eb..9aa61e416a24 100644
@@ -64,6 +64,7 @@ xe-y += xe_bb.o \
 	xe_gt_mcr.o \
 	xe_gt_pagefault.o \
 	xe_gt_sysfs.o \
+	xe_gt_throttle_sysfs.o \
 	xe_gt_tlb_invalidation.o \
 	xe_gt_topology.o \
 	xe_guc.o \
drivers/gpu/drm/xe/regs/xe_gt_regs.h +12 -0
index 3a4c9bcf793f..374238dd8a06 100644
@@ -411,4 +411,16 @@
 #define XEHPC_BCS5_BCS6_INTR_MASK		XE_REG(0x190118)
 #define XEHPC_BCS7_BCS8_INTR_MASK		XE_REG(0x19011c)
 
+#define GT0_PERF_LIMIT_REASONS			XE_REG(0x1381a8)
+#define   GT0_PERF_LIMIT_REASONS_MASK		0xde3
+#define   PROCHOT_MASK				REG_BIT(0)
+#define   THERMAL_LIMIT_MASK			REG_BIT(1)
+#define   RATL_MASK				REG_BIT(5)
+#define   VR_THERMALERT_MASK			REG_BIT(6)
+#define   VR_TDC_MASK				REG_BIT(7)
+#define   POWER_LIMIT_4_MASK			REG_BIT(8)
+#define   POWER_LIMIT_1_MASK			REG_BIT(10)
+#define   POWER_LIMIT_2_MASK			REG_BIT(11)
+#define MTL_MEDIA_PERF_LIMIT_REASONS		XE_REG(0x138030)
+
 #endif
drivers/gpu/drm/xe/xe_gt_sysfs.c +3 -0
index c69d2e8a0fe1..dc3f841b49d0 100644
@@ -11,6 +11,7 @@
 #include <drm/drm_managed.h>
 
 #include "xe_gt.h"
+#include "xe_gt_throttle_sysfs.h"
 
 static void xe_gt_sysfs_kobj_release(struct kobject *kobj)
 {
@@ -52,6 +53,8 @@ void xe_gt_sysfs_init(struct xe_gt *gt)
 
 	gt->sysfs = &kg->base;
 
+	xe_gt_throttle_sysfs_init(gt);
+
 	err = drmm_add_action_or_reset(&xe->drm, gt_sysfs_fini, gt);
 	if (err) {
 		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +257 -0

257 lines not on this page · raw message

+}

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +16 -0
new file mode 100644
index 000000000000..c318d98215a0
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef _XE_GT_THROTTLE_SYSFS_H_
+#define _XE_GT_THROTTLE_SYSFS_H_
+
+#include <drm/drm_managed.h>
+
+#include "xe_device.h"
+#include "xe_gt.h"
+
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt);
+
+#endif /* _XE_GT_THROTTLE_SYSFS_H_ */
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [Intel-xe] [PATCH v3 1/1] drm/xe: Add throttle reasons sysfs attributes

Quoted 114 lines · Sujaritha Sundaresan

Add throttle reasons sysfs interface under device/../gt#/ Currently there is one overall status and eight reasons attributes.

The new sysfs structure will have the below layout

device/tile<n>/gt<n>

               ├── gt0
               │   └── throttle
               │       ├── <throttle_reasons>
               │
               │
               ├── gtN
               │   └── throttle
               │       ├── <throttle_reasons>

v2: Fix review comments (Riana)
Move init call (Matt)

v3: Remove xe_gt_throttle (Riana)
Make functions static (Rodrigo)

---
 drivers/gpu/drm/xe/Makefile               |   1 +
 drivers/gpu/drm/xe/regs/xe_gt_regs.h      |  12 +
 drivers/gpu/drm/xe/xe_gt_sysfs.c          |   3 +
 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c | 257 ++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h |  16 ++
 5 files changed, 289 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c
 create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h
drivers/gpu/drm/xe/Makefile +1 -0
index b1681d1416eb..9aa61e416a24 100644
@@ -64,6 +64,7 @@ xe-y += xe_bb.o \
 	xe_gt_mcr.o \
 	xe_gt_pagefault.o \
 	xe_gt_sysfs.o \
+	xe_gt_throttle_sysfs.o \
 	xe_gt_tlb_invalidation.o \
 	xe_gt_topology.o \
 	xe_guc.o \
drivers/gpu/drm/xe/regs/xe_gt_regs.h +12 -0
index 3a4c9bcf793f..374238dd8a06 100644
@@ -411,4 +411,16 @@
 #define XEHPC_BCS5_BCS6_INTR_MASK		XE_REG(0x190118)
 #define XEHPC_BCS7_BCS8_INTR_MASK		XE_REG(0x19011c)
 
+#define GT0_PERF_LIMIT_REASONS			XE_REG(0x1381a8)
+#define   GT0_PERF_LIMIT_REASONS_MASK		0xde3
+#define   PROCHOT_MASK				REG_BIT(0)
+#define   THERMAL_LIMIT_MASK			REG_BIT(1)
+#define   RATL_MASK				REG_BIT(5)
+#define   VR_THERMALERT_MASK			REG_BIT(6)
+#define   VR_TDC_MASK				REG_BIT(7)
+#define   POWER_LIMIT_4_MASK			REG_BIT(8)
+#define   POWER_LIMIT_1_MASK			REG_BIT(10)
+#define   POWER_LIMIT_2_MASK			REG_BIT(11)
+#define MTL_MEDIA_PERF_LIMIT_REASONS		XE_REG(0x138030)
+
 #endif
drivers/gpu/drm/xe/xe_gt_sysfs.c +3 -0
index c69d2e8a0fe1..dc3f841b49d0 100644
@@ -11,6 +11,7 @@
 #include <drm/drm_managed.h>
 
 #include "xe_gt.h"
+#include "xe_gt_throttle_sysfs.h"
 
 static void xe_gt_sysfs_kobj_release(struct kobject *kobj)
 {
@@ -52,6 +53,8 @@ void xe_gt_sysfs_init(struct xe_gt *gt)
 
 	gt->sysfs = &kg->base;
 
+	xe_gt_throttle_sysfs_init(gt);
+
 	err = drmm_add_action_or_reset(&xe->drm, gt_sysfs_fini, gt);
 	if (err) {
 		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +21 -0
new file mode 100644
index 000000000000..12facebd8989
@@ -0,0 +1,257 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#include <drm/drm_managed.h>
+
+#include <regs/xe_gt_regs.h>
+#include "xe_device.h"
+#include "xe_gt.h"
+#include "xe_gt_sysfs.h"
+#include "xe_gt_throttle_sysfs.h"
+#include "xe_mmio.h"
+
+/**
+ * DOC: Xe GT Throttle
+ *
+ * Provides sysfs entries for frequency throttle reasons in GT
+ *
+ * device/gt#/throttle/status - Overall status
+ * device/gt#/throttle/reason_pl1 - Frequency throttle due to PL1

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c line 31

Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +10 -0
+ * device/gt#/throttle/reason_pl2 - Frequency throttle due to PL2
+ * device/gt#/throttle/reason_pl4 - Frequency throttle due to PL4, Iccmax etc.
+ * device/gt#/throttle/reason_thermal - Frequency throttle due to thermal
+ * device/gt#/throttle/reason_prochot - Frequency throttle due to prochot
+ * device/gt#/throttle/reason_ratl - Frequency throttle due to RATL
+ * device/gt#/throttle/reason_vr_thermalert - Frequency throttle due to VR THERMALERT
+ * device/gt#/throttle/reason_vr_tdc -  Frequency throttle due to VR TDC
+ */
+
+u32 read_perf_limit_reasons(struct xe_gt *gt)

I'm afraid that you forgot to make this static...

Quoted 194 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +194 -0
+{
+	u32 reg;
+
+	if (xe_gt_is_media_type(gt))
+		reg = xe_mmio_read32(gt, MTL_MEDIA_PERF_LIMIT_REASONS);
+	else
+		reg = xe_mmio_read32(gt, GT0_PERF_LIMIT_REASONS);
+
+	return reg;
+}
+
+static u32 read_status(struct xe_gt *gt)
+{
+	u32 status = read_perf_limit_reasons(gt) & GT0_PERF_LIMIT_REASONS_MASK;
+
+	return status;
+}
+
+static u32 read_reason_pl1(struct xe_gt *gt)
+{
+	u32 pl1 = read_perf_limit_reasons(gt) & POWER_LIMIT_1_MASK;
+
+	return pl1;
+}
+
+static u32 read_reason_pl2(struct xe_gt *gt)
+{
+	u32 pl2 = read_perf_limit_reasons(gt) & POWER_LIMIT_2_MASK;
+
+	return pl2;
+}
+
+static u32 read_reason_pl4(struct xe_gt *gt)
+{
+	u32 pl4 = read_perf_limit_reasons(gt) & POWER_LIMIT_4_MASK;
+
+	return pl4;
+}
+
+static u32 read_reason_thermal(struct xe_gt *gt)
+{
+	u32 thermal = read_perf_limit_reasons(gt) & THERMAL_LIMIT_MASK;
+
+	return thermal;
+}
+
+static u32 read_reason_prochot(struct xe_gt *gt)
+{
+	u32 prochot = read_perf_limit_reasons(gt) & PROCHOT_MASK;
+
+	return prochot;
+}
+
+static u32 read_reason_ratl(struct xe_gt *gt)
+{
+	u32 ratl = read_perf_limit_reasons(gt) & RATL_MASK;
+
+	return ratl;
+}
+
+static u32 read_reason_vr_thermalert(struct xe_gt *gt)
+{
+	u32 thermalert = read_perf_limit_reasons(gt) & VR_THERMALERT_MASK;
+
+	return thermalert;
+}
+
+static u32 read_reason_vr_tdc(struct xe_gt *gt)
+{
+	u32 tdc = read_perf_limit_reasons(gt) & VR_TDC_MASK;
+
+	return tdc;
+}
+
+static ssize_t status_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool status = !!read_status(gt);
+
+	return sysfs_emit(buff, "%u\n", status);
+}
+static DEVICE_ATTR_RO(status);
+
+static ssize_t reason_pl1_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl1 = !!read_reason_pl1(gt);
+
+	return sysfs_emit(buff, "%u\n", pl1);
+}
+static DEVICE_ATTR_RO(reason_pl1);
+
+static ssize_t reason_pl2_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl2 = !!read_reason_pl2(gt);
+
+	return sysfs_emit(buff, "%u\n", pl2);
+}
+static DEVICE_ATTR_RO(reason_pl2);
+
+static ssize_t reason_pl4_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl4 = !!read_reason_pl4(gt);
+
+	return sysfs_emit(buff, "%u\n", pl4);
+}
+static DEVICE_ATTR_RO(reason_pl4);
+
+static ssize_t reason_thermal_show(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool thermal = !!read_reason_thermal(gt);
+
+	return sysfs_emit(buff, "%u\n", thermal);
+}
+static DEVICE_ATTR_RO(reason_thermal);
+
+static ssize_t reason_prochot_show(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool prochot = !!read_reason_prochot(gt);
+
+	return sysfs_emit(buff, "%u\n", prochot);
+}
+static DEVICE_ATTR_RO(reason_prochot);
+
+static ssize_t reason_ratl_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool ratl = !!read_reason_ratl(gt);
+
+	return sysfs_emit(buff, "%u\n", ratl);
+}
+static DEVICE_ATTR_RO(reason_ratl);
+
+static ssize_t reason_vr_thermalert_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool thermalert = !!read_reason_vr_thermalert(gt);
+
+	return sysfs_emit(buff, "%u\n", thermalert);
+}
+static DEVICE_ATTR_RO(reason_vr_thermalert);
+
+static ssize_t reason_vr_tdc_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool tdc = !!read_reason_vr_tdc(gt);
+
+	return sysfs_emit(buff, "%u\n", tdc);
+}
+static DEVICE_ATTR_RO(reason_vr_tdc);
+
+static const struct attribute *throttle_attrs[] = {
+	&dev_attr_status.attr,
+	&dev_attr_reason_pl1.attr,
+	&dev_attr_reason_pl2.attr,
+	&dev_attr_reason_pl4.attr,
+	&dev_attr_reason_thermal.attr,
+	&dev_attr_reason_prochot.attr,
+	&dev_attr_reason_ratl.attr,
+	&dev_attr_reason_vr_thermalert.attr,
+	&dev_attr_reason_vr_tdc.attr,
+	NULL
+};

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c line 235

Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +10 -0
+
+static void gt_throttle_sysfs_fini(struct drm_device *drm, void *arg)
+{
+	struct kobject *kobj = arg;
+
+	sysfs_remove_files(kobj, throttle_attrs);
+	kobject_put(kobj);
+}
+
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt)

... and to add a kernel doc to the non-static one

Quoted 31 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +23 -0
+{
+	struct xe_device *xe = gt_to_xe(gt);
+	struct kobject *kobj;
+	int err;
+
+	kobj = kobject_create_and_add("throttle", gt->sysfs);
+	if (!kobj) {
+		drm_warn(&xe->drm, "%s failed, err: %d\n", __func__, -ENOMEM);
+		return;
+	}
+
+	err = sysfs_create_files(kobj, throttle_attrs);
+	if (err) {
+		kobject_put(kobj);
+		drm_warn(&xe->drm, "failed to register throttle sysfs, err: %d\n", err);
+		return;
+	}
+
+	err = drmm_add_action_or_reset(&xe->drm, gt_throttle_sysfs_fini, kobj);
+	if (err)
+		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
+			 __func__, err);
+}
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +2 -0
new file mode 100644
index 000000000000..c318d98215a0
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: MIT */
+/*

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h line 12

Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +10 -0
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef _XE_GT_THROTTLE_SYSFS_H_
+#define _XE_GT_THROTTLE_SYSFS_H_
+
+#include <drm/drm_managed.h>
+
+#include "xe_device.h"
+#include "xe_gt.h"

do not include .h inside a .h

struct xe_gt;

should be enough here
and the rest of includes if needed they should be in the .c

Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +4 -0
+
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt);
+
+#endif /* _XE_GT_THROTTLE_SYSFS_H_ */
Signature · 1 line
2.25.1
#3 lore raw

Re: [Intel-xe] [PATCH v3 1/1] drm/xe: Add throttle reasons sysfs attributes

Quoted 118 lines · Rodrigo Vivi
Quoted 117 lines · Sujaritha Sundaresan

Add throttle reasons sysfs interface under device/../gt#/ Currently there is one overall status and eight reasons attributes.

The new sysfs structure will have the below layout

device/tile<n>/gt<n>

                ├── gt0
                │   └── throttle
                │       ├── <throttle_reasons>
                │
                │
                ├── gtN
                │   └── throttle
                │       ├── <throttle_reasons>

v2: Fix review comments (Riana)
Move init call (Matt)

v3: Remove xe_gt_throttle (Riana)
Make functions static (Rodrigo)

---
  drivers/gpu/drm/xe/Makefile               |   1 +
  drivers/gpu/drm/xe/regs/xe_gt_regs.h      |  12 +
  drivers/gpu/drm/xe/xe_gt_sysfs.c          |   3 +
  drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c | 257 ++++++++++++++++++++++
  drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h |  16 ++
  5 files changed, 289 insertions(+)

create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h

drivers/gpu/drm/xe/Makefile +1 -0
index b1681d1416eb..9aa61e416a24 100644
@@ -64,6 +64,7 @@ xe-y += xe_bb.o \
  	xe_gt_mcr.o \
  	xe_gt_pagefault.o \
  	xe_gt_sysfs.o \
+	xe_gt_throttle_sysfs.o \
  	xe_gt_tlb_invalidation.o \
  	xe_gt_topology.o \
  	xe_guc.o \
drivers/gpu/drm/xe/regs/xe_gt_regs.h +12 -0
index 3a4c9bcf793f..374238dd8a06 100644
@@ -411,4 +411,16 @@
  #define XEHPC_BCS5_BCS6_INTR_MASK		XE_REG(0x190118)
  #define XEHPC_BCS7_BCS8_INTR_MASK		XE_REG(0x19011c)
 
+#define GT0_PERF_LIMIT_REASONS			XE_REG(0x1381a8)
+#define   GT0_PERF_LIMIT_REASONS_MASK		0xde3
+#define   PROCHOT_MASK				REG_BIT(0)
+#define   THERMAL_LIMIT_MASK			REG_BIT(1)
+#define   RATL_MASK				REG_BIT(5)
+#define   VR_THERMALERT_MASK			REG_BIT(6)
+#define   VR_TDC_MASK				REG_BIT(7)
+#define   POWER_LIMIT_4_MASK			REG_BIT(8)
+#define   POWER_LIMIT_1_MASK			REG_BIT(10)
+#define   POWER_LIMIT_2_MASK			REG_BIT(11)
+#define MTL_MEDIA_PERF_LIMIT_REASONS		XE_REG(0x138030)
+
  #endif
drivers/gpu/drm/xe/xe_gt_sysfs.c +3 -0
index c69d2e8a0fe1..dc3f841b49d0 100644
@@ -11,6 +11,7 @@
  #include <drm/drm_managed.h>
 
  #include "xe_gt.h"
+#include "xe_gt_throttle_sysfs.h"
 
  static void xe_gt_sysfs_kobj_release(struct kobject *kobj)
  {
@@ -52,6 +53,8 @@ void xe_gt_sysfs_init(struct xe_gt *gt)
 
  	gt->sysfs = &kg->base;
 
+	xe_gt_throttle_sysfs_init(gt);
+
  	err = drmm_add_action_or_reset(&xe->drm, gt_sysfs_fini, gt);
  	if (err) {
  		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +24 -0
new file mode 100644
index 000000000000..12facebd8989
@@ -0,0 +1,257 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#include <drm/drm_managed.h>
+
+#include <regs/xe_gt_regs.h>
+#include "xe_device.h"
+#include "xe_gt.h"
+#include "xe_gt_sysfs.h"
+#include "xe_gt_throttle_sysfs.h"
+#include "xe_mmio.h"
+
+/**
+ * DOC: Xe GT Throttle
+ *
+ * Provides sysfs entries for frequency throttle reasons in GT
+ *
+ * device/gt#/throttle/status - Overall status
+ * device/gt#/throttle/reason_pl1 - Frequency throttle due to PL1
+ * device/gt#/throttle/reason_pl2 - Frequency throttle due to PL2
+ * device/gt#/throttle/reason_pl4 - Frequency throttle due to PL4, Iccmax etc.
+ * device/gt#/throttle/reason_thermal - Frequency throttle due to thermal
Quoted 8 lines

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c line 31

Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +7 -0
+ * device/gt#/throttle/reason_prochot - Frequency throttle due to prochot
+ * device/gt#/throttle/reason_ratl - Frequency throttle due to RATL
+ * device/gt#/throttle/reason_vr_thermalert - Frequency throttle due to VR THERMALERT
+ * device/gt#/throttle/reason_vr_tdc -  Frequency throttle due to VR TDC
+ */
+
+u32 read_perf_limit_reasons(struct xe_gt *gt)

I'm afraid that you forgot to make this static...

This was miss will fix.

Quoted 198 lines
Quoted 198 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +197 -0
+{
+	u32 reg;
+
+	if (xe_gt_is_media_type(gt))
+		reg = xe_mmio_read32(gt, MTL_MEDIA_PERF_LIMIT_REASONS);
+	else
+		reg = xe_mmio_read32(gt, GT0_PERF_LIMIT_REASONS);
+
+	return reg;
+}
+
+static u32 read_status(struct xe_gt *gt)
+{
+	u32 status = read_perf_limit_reasons(gt) & GT0_PERF_LIMIT_REASONS_MASK;
+
+	return status;
+}
+
+static u32 read_reason_pl1(struct xe_gt *gt)
+{
+	u32 pl1 = read_perf_limit_reasons(gt) & POWER_LIMIT_1_MASK;
+
+	return pl1;
+}
+
+static u32 read_reason_pl2(struct xe_gt *gt)
+{
+	u32 pl2 = read_perf_limit_reasons(gt) & POWER_LIMIT_2_MASK;
+
+	return pl2;
+}
+
+static u32 read_reason_pl4(struct xe_gt *gt)
+{
+	u32 pl4 = read_perf_limit_reasons(gt) & POWER_LIMIT_4_MASK;
+
+	return pl4;
+}
+
+static u32 read_reason_thermal(struct xe_gt *gt)
+{
+	u32 thermal = read_perf_limit_reasons(gt) & THERMAL_LIMIT_MASK;
+
+	return thermal;
+}
+
+static u32 read_reason_prochot(struct xe_gt *gt)
+{
+	u32 prochot = read_perf_limit_reasons(gt) & PROCHOT_MASK;
+
+	return prochot;
+}
+
+static u32 read_reason_ratl(struct xe_gt *gt)
+{
+	u32 ratl = read_perf_limit_reasons(gt) & RATL_MASK;
+
+	return ratl;
+}
+
+static u32 read_reason_vr_thermalert(struct xe_gt *gt)
+{
+	u32 thermalert = read_perf_limit_reasons(gt) & VR_THERMALERT_MASK;
+
+	return thermalert;
+}
+
+static u32 read_reason_vr_tdc(struct xe_gt *gt)
+{
+	u32 tdc = read_perf_limit_reasons(gt) & VR_TDC_MASK;
+
+	return tdc;
+}
+
+static ssize_t status_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool status = !!read_status(gt);
+
+	return sysfs_emit(buff, "%u\n", status);
+}
+static DEVICE_ATTR_RO(status);
+
+static ssize_t reason_pl1_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl1 = !!read_reason_pl1(gt);
+
+	return sysfs_emit(buff, "%u\n", pl1);
+}
+static DEVICE_ATTR_RO(reason_pl1);
+
+static ssize_t reason_pl2_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl2 = !!read_reason_pl2(gt);
+
+	return sysfs_emit(buff, "%u\n", pl2);
+}
+static DEVICE_ATTR_RO(reason_pl2);
+
+static ssize_t reason_pl4_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl4 = !!read_reason_pl4(gt);
+
+	return sysfs_emit(buff, "%u\n", pl4);
+}
+static DEVICE_ATTR_RO(reason_pl4);
+
+static ssize_t reason_thermal_show(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool thermal = !!read_reason_thermal(gt);
+
+	return sysfs_emit(buff, "%u\n", thermal);
+}
+static DEVICE_ATTR_RO(reason_thermal);
+
+static ssize_t reason_prochot_show(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool prochot = !!read_reason_prochot(gt);
+
+	return sysfs_emit(buff, "%u\n", prochot);
+}
+static DEVICE_ATTR_RO(reason_prochot);
+
+static ssize_t reason_ratl_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool ratl = !!read_reason_ratl(gt);
+
+	return sysfs_emit(buff, "%u\n", ratl);
+}
+static DEVICE_ATTR_RO(reason_ratl);
+
+static ssize_t reason_vr_thermalert_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool thermalert = !!read_reason_vr_thermalert(gt);
+
+	return sysfs_emit(buff, "%u\n", thermalert);
+}
+static DEVICE_ATTR_RO(reason_vr_thermalert);
+
+static ssize_t reason_vr_tdc_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool tdc = !!read_reason_vr_tdc(gt);
+
+	return sysfs_emit(buff, "%u\n", tdc);
+}
+static DEVICE_ATTR_RO(reason_vr_tdc);
+
+static const struct attribute *throttle_attrs[] = {
+	&dev_attr_status.attr,
+	&dev_attr_reason_pl1.attr,
+	&dev_attr_reason_pl2.attr,
+	&dev_attr_reason_pl4.attr,
+	&dev_attr_reason_thermal.attr,
+	&dev_attr_reason_prochot.attr,
+	&dev_attr_reason_ratl.attr,
+	&dev_attr_reason_vr_thermalert.attr,
+	&dev_attr_reason_vr_tdc.attr,
+	NULL
+};
+
+static void gt_throttle_sysfs_fini(struct drm_device *drm, void *arg)
+{
Quoted 8 lines

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c line 235

Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +7 -0
+	struct kobject *kobj = arg;
+
+	sysfs_remove_files(kobj, throttle_attrs);
+	kobject_put(kobj);
+}
+
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt)

... and to add a kernel doc to the non-static one

Will do

Quoted 44 lines
Quoted 32 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +23 -0
+{
+	struct xe_device *xe = gt_to_xe(gt);
+	struct kobject *kobj;
+	int err;
+
+	kobj = kobject_create_and_add("throttle", gt->sysfs);
+	if (!kobj) {
+		drm_warn(&xe->drm, "%s failed, err: %d\n", __func__, -ENOMEM);
+		return;
+	}
+
+	err = sysfs_create_files(kobj, throttle_attrs);
+	if (err) {
+		kobject_put(kobj);
+		drm_warn(&xe->drm, "failed to register throttle sysfs, err: %d\n", err);
+		return;
+	}
+
+	err = drmm_add_action_or_reset(&xe->drm, gt_throttle_sysfs_fini, kobj);
+	if (err)
+		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
+			 __func__, err);
+}
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +2 -0
new file mode 100644
index 000000000000..c318d98215a0
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: MIT */
+/*

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h line 12

Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +10 -0
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef _XE_GT_THROTTLE_SYSFS_H_
+#define _XE_GT_THROTTLE_SYSFS_H_
+
+#include <drm/drm_managed.h>
+
+#include "xe_device.h"
+#include "xe_gt.h"

do not include .h inside a .h

Quoted 4 lines

struct xe_gt;

should be enough here
and the rest of includes if needed they should be in the .c

Sure will remove.

Thanks,

Suja

Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +4 -0
+
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt);
+
+#endif /* _XE_GT_THROTTLE_SYSFS_H_ */
Signature · 1 line
2.25.1
#4 lore raw

Re: [Intel-xe] [PATCH v3 1/1] drm/xe: Add throttle reasons sysfs attributes

In reply to Sujaritha Sundaresan

Hi Suja

Quoted 117 lines · Sujaritha Sundaresan

Add throttle reasons sysfs interface under device/../gt#/ Currently there is one overall status and eight reasons attributes.

The new sysfs structure will have the below layout

device/tile<n>/gt<n>

                ├── gt0
                │   └── throttle
                │       ├── <throttle_reasons>
                │
                │
                ├── gtN
                │   └── throttle
                │       ├── <throttle_reasons>

v2: Fix review comments (Riana)
Move init call (Matt)

v3: Remove xe_gt_throttle (Riana)
Make functions static (Rodrigo)

---
  drivers/gpu/drm/xe/Makefile               |   1 +
  drivers/gpu/drm/xe/regs/xe_gt_regs.h      |  12 +
  drivers/gpu/drm/xe/xe_gt_sysfs.c          |   3 +
  drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c | 257 ++++++++++++++++++++++
  drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h |  16 ++
  5 files changed, 289 insertions(+)

create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h

drivers/gpu/drm/xe/Makefile +1 -0
index b1681d1416eb..9aa61e416a24 100644
@@ -64,6 +64,7 @@ xe-y += xe_bb.o \
  	xe_gt_mcr.o \
  	xe_gt_pagefault.o \
  	xe_gt_sysfs.o \
+	xe_gt_throttle_sysfs.o \
  	xe_gt_tlb_invalidation.o \
  	xe_gt_topology.o \
  	xe_guc.o \
drivers/gpu/drm/xe/regs/xe_gt_regs.h +12 -0
index 3a4c9bcf793f..374238dd8a06 100644
@@ -411,4 +411,16 @@
  #define XEHPC_BCS5_BCS6_INTR_MASK		XE_REG(0x190118)
  #define XEHPC_BCS7_BCS8_INTR_MASK		XE_REG(0x19011c)
 
+#define GT0_PERF_LIMIT_REASONS			XE_REG(0x1381a8)
+#define   GT0_PERF_LIMIT_REASONS_MASK		0xde3
+#define   PROCHOT_MASK				REG_BIT(0)
+#define   THERMAL_LIMIT_MASK			REG_BIT(1)
+#define   RATL_MASK				REG_BIT(5)
+#define   VR_THERMALERT_MASK			REG_BIT(6)
+#define   VR_TDC_MASK				REG_BIT(7)
+#define   POWER_LIMIT_4_MASK			REG_BIT(8)
+#define   POWER_LIMIT_1_MASK			REG_BIT(10)
+#define   POWER_LIMIT_2_MASK			REG_BIT(11)
+#define MTL_MEDIA_PERF_LIMIT_REASONS		XE_REG(0x138030)
+
  #endif
drivers/gpu/drm/xe/xe_gt_sysfs.c +3 -0
index c69d2e8a0fe1..dc3f841b49d0 100644
@@ -11,6 +11,7 @@
  #include <drm/drm_managed.h>
 
  #include "xe_gt.h"
+#include "xe_gt_throttle_sysfs.h"
 
  static void xe_gt_sysfs_kobj_release(struct kobject *kobj)
  {
@@ -52,6 +53,8 @@ void xe_gt_sysfs_init(struct xe_gt *gt)
 
  	gt->sysfs = &kg->base;
 
+	xe_gt_throttle_sysfs_init(gt);
+
  	err = drmm_add_action_or_reset(&xe->drm, gt_sysfs_fini, gt);
  	if (err) {
  		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +24 -0
new file mode 100644
index 000000000000..12facebd8989
@@ -0,0 +1,257 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#include <drm/drm_managed.h>
+
+#include <regs/xe_gt_regs.h>
+#include "xe_device.h"
+#include "xe_gt.h"
+#include "xe_gt_sysfs.h"
+#include "xe_gt_throttle_sysfs.h"
+#include "xe_mmio.h"
+
+/**
+ * DOC: Xe GT Throttle
+ *
+ * Provides sysfs entries for frequency throttle reasons in GT
+ *
+ * device/gt#/throttle/status - Overall status
+ * device/gt#/throttle/reason_pl1 - Frequency throttle due to PL1
+ * device/gt#/throttle/reason_pl2 - Frequency throttle due to PL2
+ * device/gt#/throttle/reason_pl4 - Frequency throttle due to PL4, Iccmax etc.
+ * device/gt#/throttle/reason_thermal - Frequency throttle due to thermal

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c line 34

Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +10 -0
+ * device/gt#/throttle/reason_prochot - Frequency throttle due to prochot
+ * device/gt#/throttle/reason_ratl - Frequency throttle due to RATL
+ * device/gt#/throttle/reason_vr_thermalert - Frequency throttle due to VR THERMALERT
+ * device/gt#/throttle/reason_vr_tdc -  Frequency throttle due to VR TDC
+ */
+
+u32 read_perf_limit_reasons(struct xe_gt *gt)
+{
+	u32 reg;
+

xe_device_mem_access_get here?

Quoted 61 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +61 -0
+	if (xe_gt_is_media_type(gt))
+		reg = xe_mmio_read32(gt, MTL_MEDIA_PERF_LIMIT_REASONS);
+	else
+		reg = xe_mmio_read32(gt, GT0_PERF_LIMIT_REASONS);
+
+	return reg;
+}
+
+static u32 read_status(struct xe_gt *gt)
+{
+	u32 status = read_perf_limit_reasons(gt) & GT0_PERF_LIMIT_REASONS_MASK;
+
+	return status;
+}
+
+static u32 read_reason_pl1(struct xe_gt *gt)
+{
+	u32 pl1 = read_perf_limit_reasons(gt) & POWER_LIMIT_1_MASK;
+
+	return pl1;
+}
+
+static u32 read_reason_pl2(struct xe_gt *gt)
+{
+	u32 pl2 = read_perf_limit_reasons(gt) & POWER_LIMIT_2_MASK;
+
+	return pl2;
+}
+
+static u32 read_reason_pl4(struct xe_gt *gt)
+{
+	u32 pl4 = read_perf_limit_reasons(gt) & POWER_LIMIT_4_MASK;
+
+	return pl4;
+}
+
+static u32 read_reason_thermal(struct xe_gt *gt)
+{
+	u32 thermal = read_perf_limit_reasons(gt) & THERMAL_LIMIT_MASK;
+
+	return thermal;
+}
+
+static u32 read_reason_prochot(struct xe_gt *gt)
+{
+	u32 prochot = read_perf_limit_reasons(gt) & PROCHOT_MASK;
+
+	return prochot;
+}
+
+static u32 read_reason_ratl(struct xe_gt *gt)
+{
+	u32 ratl = read_perf_limit_reasons(gt) & RATL_MASK;
+
+	return ratl;
+}
+
+static u32 read_reason_vr_thermalert(struct xe_gt *gt)
+{
+	u32 thermalert = read_perf_limit_reasons(gt) & VR_THERMALERT_MASK;
+

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c line 105

Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +10 -0
+	return thermalert;
+}
+
+static u32 read_reason_vr_tdc(struct xe_gt *gt)
+{
+	u32 tdc = read_perf_limit_reasons(gt) & VR_TDC_MASK;
+
+	return tdc;
+}
+

Since the same function in called multiple times above. Can it be a single function with the mask sent from the show?

Quoted 162 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +153 -0
+static ssize_t status_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool status = !!read_status(gt);
+
+	return sysfs_emit(buff, "%u\n", status);
+}
+static DEVICE_ATTR_RO(status);
+
+static ssize_t reason_pl1_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl1 = !!read_reason_pl1(gt);
+
+	return sysfs_emit(buff, "%u\n", pl1);
+}
+static DEVICE_ATTR_RO(reason_pl1);
+
+static ssize_t reason_pl2_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl2 = !!read_reason_pl2(gt);
+
+	return sysfs_emit(buff, "%u\n", pl2);
+}
+static DEVICE_ATTR_RO(reason_pl2);
+
+static ssize_t reason_pl4_show(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool pl4 = !!read_reason_pl4(gt);
+
+	return sysfs_emit(buff, "%u\n", pl4);
+}
+static DEVICE_ATTR_RO(reason_pl4);
+
+static ssize_t reason_thermal_show(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool thermal = !!read_reason_thermal(gt);
+
+	return sysfs_emit(buff, "%u\n", thermal);
+}
+static DEVICE_ATTR_RO(reason_thermal);
+
+static ssize_t reason_prochot_show(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool prochot = !!read_reason_prochot(gt);
+
+	return sysfs_emit(buff, "%u\n", prochot);
+}
+static DEVICE_ATTR_RO(reason_prochot);
+
+static ssize_t reason_ratl_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool ratl = !!read_reason_ratl(gt);
+
+	return sysfs_emit(buff, "%u\n", ratl);
+}
+static DEVICE_ATTR_RO(reason_ratl);
+
+static ssize_t reason_vr_thermalert_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool thermalert = !!read_reason_vr_thermalert(gt);
+
+	return sysfs_emit(buff, "%u\n", thermalert);
+}
+static DEVICE_ATTR_RO(reason_vr_thermalert);
+
+static ssize_t reason_vr_tdc_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buff)
+{
+	struct kobject *kobj = &dev->kobj;
+	struct xe_gt *gt = kobj_to_gt(kobj);
+	bool tdc = !!read_reason_vr_tdc(gt);
+
+	return sysfs_emit(buff, "%u\n", tdc);
+}
+static DEVICE_ATTR_RO(reason_vr_tdc);
+
+static const struct attribute *throttle_attrs[] = {
+	&dev_attr_status.attr,
+	&dev_attr_reason_pl1.attr,
+	&dev_attr_reason_pl2.attr,
+	&dev_attr_reason_pl4.attr,
+	&dev_attr_reason_thermal.attr,
+	&dev_attr_reason_prochot.attr,
+	&dev_attr_reason_ratl.attr,
+	&dev_attr_reason_vr_thermalert.attr,
+	&dev_attr_reason_vr_tdc.attr,
+	NULL
+};
+
+static void gt_throttle_sysfs_fini(struct drm_device *drm, void *arg)
+{
+	struct kobject *kobj = arg;
+
+	sysfs_remove_files(kobj, throttle_attrs);
+	kobject_put(kobj);
+}
+
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt)
+{
+	struct xe_device *xe = gt_to_xe(gt);
+	struct kobject *kobj;
+	int err;
+
+	kobj = kobject_create_and_add("throttle", gt->sysfs);
+	if (!kobj) {
+		drm_warn(&xe->drm, "%s failed, err: %d\n", __func__, -ENOMEM);
+		return;
+	}
+
+	err = sysfs_create_files(kobj, throttle_attrs);
+	if (err) {
+		kobject_put(kobj);
+		drm_warn(&xe->drm, "failed to register throttle sysfs, err: %d\n", err);
+		return;
+	}
+
+	err = drmm_add_action_or_reset(&xe->drm, gt_throttle_sysfs_fini, kobj);
+	if (err)
+		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
+			 __func__, err);
+}
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +3 -0
new file mode 100644
index 000000000000..c318d98215a0
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h line 13

Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +10 -0
+ */
+
+#ifndef _XE_GT_THROTTLE_SYSFS_H_
+#define _XE_GT_THROTTLE_SYSFS_H_
+
+#include <drm/drm_managed.h>
+
+#include "xe_device.h"
+#include "xe_gt.h"
+

Above headers are not used.
Can use forward declaration for xe_gt

Thanks
Riana

Quoted 3 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +3 -0
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt);
+
+#endif /* _XE_GT_THROTTLE_SYSFS_H_ */
#5 lore raw

Re: [Intel-xe] [PATCH v3 1/1] drm/xe: Add throttle reasons sysfs attributes

Quoted 198 lines · Riana Tauro

Hi Suja

Quoted 122 lines · Sujaritha Sundaresan

Add throttle reasons sysfs interface under device/../gt#/ Currently there is one overall status and eight reasons attributes.

The new sysfs structure will have the below layout

device/tile<n>/gt<n>

                ├── gt0
                │   └── throttle
                │       ├── <throttle_reasons>
                │
                │
                ├── gtN
                │   └── throttle
                │       ├── <throttle_reasons>

v2: Fix review comments (Riana)
     Move init call (Matt)

v3: Remove xe_gt_throttle (Riana)
     Make functions static (Rodrigo)

---
  drivers/gpu/drm/xe/Makefile               |   1 + drivers/gpu/drm/xe/regs/xe_gt_regs.h      |  12 + drivers/gpu/drm/xe/xe_gt_sysfs.c          |   3 + drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c | 257 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h |  16 ++

  5 files changed, 289 insertions(+)

  create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c create mode 100644 drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h

drivers/gpu/drm/xe/Makefile +1 -0
index b1681d1416eb..9aa61e416a24 100644
@@ -64,6 +64,7 @@ xe-y += xe_bb.o \
       xe_gt_mcr.o \
       xe_gt_pagefault.o \
       xe_gt_sysfs.o \
+    xe_gt_throttle_sysfs.o \
       xe_gt_tlb_invalidation.o \
       xe_gt_topology.o \
       xe_guc.o \
drivers/gpu/drm/xe/regs/xe_gt_regs.h +11 -0
index 3a4c9bcf793f..374238dd8a06 100644
@@ -411,4 +411,16 @@
   #define XEHPC_BCS5_BCS6_INTR_MASK        XE_REG(0x190118)
   #define XEHPC_BCS7_BCS8_INTR_MASK        XE_REG(0x19011c)
   +#define GT0_PERF_LIMIT_REASONS            XE_REG(0x1381a8)
+#define   GT0_PERF_LIMIT_REASONS_MASK        0xde3
+#define   PROCHOT_MASK                REG_BIT(0)
+#define   THERMAL_LIMIT_MASK            REG_BIT(1)
+#define   RATL_MASK                REG_BIT(5)
+#define   VR_THERMALERT_MASK            REG_BIT(6)
+#define   VR_TDC_MASK                REG_BIT(7)
+#define   POWER_LIMIT_4_MASK            REG_BIT(8)
+#define   POWER_LIMIT_1_MASK            REG_BIT(10)
+#define   POWER_LIMIT_2_MASK            REG_BIT(11)
+#define MTL_MEDIA_PERF_LIMIT_REASONS        XE_REG(0x138030)
+
   #endif
drivers/gpu/drm/xe/xe_gt_sysfs.c +2 -0
index c69d2e8a0fe1..dc3f841b49d0 100644
@@ -11,6 +11,7 @@
   #include <drm/drm_managed.h>
     #include "xe_gt.h"
+#include "xe_gt_throttle_sysfs.h"
     static void xe_gt_sysfs_kobj_release(struct kobject *kobj)
   {
@@ -52,6 +53,8 @@ void xe_gt_sysfs_init(struct xe_gt *gt)
         gt->sysfs = &kg->base;
   +    xe_gt_throttle_sysfs_init(gt);
+
       err = drmm_add_action_or_reset(&xe->drm, gt_sysfs_fini, gt);
       if (err) {
           drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +23 -0
new file mode 100644
index 000000000000..12facebd8989
@@ -0,0 +1,257 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#include <drm/drm_managed.h>
+
+#include <regs/xe_gt_regs.h>
+#include "xe_device.h"
+#include "xe_gt.h"
+#include "xe_gt_sysfs.h"
+#include "xe_gt_throttle_sysfs.h"
+#include "xe_mmio.h"
+
+/**
+ * DOC: Xe GT Throttle
+ *
+ * Provides sysfs entries for frequency throttle reasons in GT
+ *
+ * device/gt#/throttle/status - Overall status
+ * device/gt#/throttle/reason_pl1 - Frequency throttle due to PL1
+ * device/gt#/throttle/reason_pl2 - Frequency throttle due to PL2
+ * device/gt#/throttle/reason_pl4 - Frequency throttle due to PL4, 

Iccmax etc.
+ * device/gt#/throttle/reason_thermal - Frequency throttle due to thermal
+ * device/gt#/throttle/reason_prochot - Frequency throttle due to prochot
+ * device/gt#/throttle/reason_ratl - Frequency throttle due to RATL
+ * device/gt#/throttle/reason_vr_thermalert - Frequency throttle due to VR THERMALERT
+ * device/gt#/throttle/reason_vr_tdc -  Frequency throttle due to VR TDC
+ */

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c line 34

Quoted 5 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +5 -0
+
+u32 read_perf_limit_reasons(struct xe_gt *gt)
+{
+    u32 reg;
+

xe_device_mem_access_get here?

Quoted 66 lines

+    if (xe_gt_is_media_type(gt))
+        reg = xe_mmio_read32(gt, MTL_MEDIA_PERF_LIMIT_REASONS); +    else
+        reg = xe_mmio_read32(gt, GT0_PERF_LIMIT_REASONS);

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +7 -0
+
+    return reg;
+}
+
+static u32 read_status(struct xe_gt *gt)
+{
+    u32 status = read_perf_limit_reasons(gt) & 

GT0_PERF_LIMIT_REASONS_MASK;

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +54 -0
+
+    return status;
+}
+
+static u32 read_reason_pl1(struct xe_gt *gt)
+{
+    u32 pl1 = read_perf_limit_reasons(gt) & POWER_LIMIT_1_MASK;
+
+    return pl1;
+}
+
+static u32 read_reason_pl2(struct xe_gt *gt)
+{
+    u32 pl2 = read_perf_limit_reasons(gt) & POWER_LIMIT_2_MASK;
+
+    return pl2;
+}
+
+static u32 read_reason_pl4(struct xe_gt *gt)
+{
+    u32 pl4 = read_perf_limit_reasons(gt) & POWER_LIMIT_4_MASK;
+
+    return pl4;
+}
+
+static u32 read_reason_thermal(struct xe_gt *gt)
+{
+    u32 thermal = read_perf_limit_reasons(gt) & THERMAL_LIMIT_MASK;
+
+    return thermal;
+}
+
+static u32 read_reason_prochot(struct xe_gt *gt)
+{
+    u32 prochot = read_perf_limit_reasons(gt) & PROCHOT_MASK;
+
+    return prochot;
+}
+
+static u32 read_reason_ratl(struct xe_gt *gt)
+{
+    u32 ratl = read_perf_limit_reasons(gt) & RATL_MASK;
+
+    return ratl;
+}
+
+static u32 read_reason_vr_thermalert(struct xe_gt *gt)
+{
+    u32 thermalert = read_perf_limit_reasons(gt) & VR_THERMALERT_MASK;
+
+    return thermalert;
+}
+
+static u32 read_reason_vr_tdc(struct xe_gt *gt)
Quoted 8 lines

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c line 105

Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +6 -0
+{
+    u32 tdc = read_perf_limit_reasons(gt) & VR_TDC_MASK;
+
+    return tdc;
+}
+

Since the same function in called multiple times above. Can it be a single function with the mask sent from the show?

I'll try it out.

Quoted 178 lines
Quoted 165 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +145 -0
+static ssize_t status_show(struct device *dev,
+               struct device_attribute *attr,
+               char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool status = !!read_status(gt);
+
+    return sysfs_emit(buff, "%u\n", status);
+}
+static DEVICE_ATTR_RO(status);
+
+static ssize_t reason_pl1_show(struct device *dev,
+                   struct device_attribute *attr,
+                   char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool pl1 = !!read_reason_pl1(gt);
+
+    return sysfs_emit(buff, "%u\n", pl1);
+}
+static DEVICE_ATTR_RO(reason_pl1);
+
+static ssize_t reason_pl2_show(struct device *dev,
+                   struct device_attribute *attr,
+                   char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool pl2 = !!read_reason_pl2(gt);
+
+    return sysfs_emit(buff, "%u\n", pl2);
+}
+static DEVICE_ATTR_RO(reason_pl2);
+
+static ssize_t reason_pl4_show(struct device *dev,
+                   struct device_attribute *attr,
+                   char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool pl4 = !!read_reason_pl4(gt);
+
+    return sysfs_emit(buff, "%u\n", pl4);
+}
+static DEVICE_ATTR_RO(reason_pl4);
+
+static ssize_t reason_thermal_show(struct device *dev,
+                   struct device_attribute *attr,
+                   char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool thermal = !!read_reason_thermal(gt);
+
+    return sysfs_emit(buff, "%u\n", thermal);
+}
+static DEVICE_ATTR_RO(reason_thermal);
+
+static ssize_t reason_prochot_show(struct device *dev,
+                   struct device_attribute *attr,
+                   char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool prochot = !!read_reason_prochot(gt);
+
+    return sysfs_emit(buff, "%u\n", prochot);
+}
+static DEVICE_ATTR_RO(reason_prochot);
+
+static ssize_t reason_ratl_show(struct device *dev,
+                struct device_attribute *attr,
+                char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool ratl = !!read_reason_ratl(gt);
+
+    return sysfs_emit(buff, "%u\n", ratl);
+}
+static DEVICE_ATTR_RO(reason_ratl);
+
+static ssize_t reason_vr_thermalert_show(struct device *dev,
+                     struct device_attribute *attr,
+                     char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool thermalert = !!read_reason_vr_thermalert(gt);
+
+    return sysfs_emit(buff, "%u\n", thermalert);
+}
+static DEVICE_ATTR_RO(reason_vr_thermalert);
+
+static ssize_t reason_vr_tdc_show(struct device *dev,
+                  struct device_attribute *attr,
+                  char *buff)
+{
+    struct kobject *kobj = &dev->kobj;
+    struct xe_gt *gt = kobj_to_gt(kobj);
+    bool tdc = !!read_reason_vr_tdc(gt);
+
+    return sysfs_emit(buff, "%u\n", tdc);
+}
+static DEVICE_ATTR_RO(reason_vr_tdc);
+
+static const struct attribute *throttle_attrs[] = {
+    &dev_attr_status.attr,
+    &dev_attr_reason_pl1.attr,
+    &dev_attr_reason_pl2.attr,
+    &dev_attr_reason_pl4.attr,
+    &dev_attr_reason_thermal.attr,
+    &dev_attr_reason_prochot.attr,
+    &dev_attr_reason_ratl.attr,
+    &dev_attr_reason_vr_thermalert.attr,
+    &dev_attr_reason_vr_tdc.attr,
+    NULL
+};
+
+static void gt_throttle_sysfs_fini(struct drm_device *drm, void *arg)
+{
+    struct kobject *kobj = arg;
+
+    sysfs_remove_files(kobj, throttle_attrs);
+    kobject_put(kobj);
+}
+
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt)
+{
+    struct xe_device *xe = gt_to_xe(gt);
+    struct kobject *kobj;
+    int err;
+
+    kobj = kobject_create_and_add("throttle", gt->sysfs);
+    if (!kobj) {
+        drm_warn(&xe->drm, "%s failed, err: %d\n", __func__, -ENOMEM);
+        return;
+    }
+
+    err = sysfs_create_files(kobj, throttle_attrs);
+    if (err) {
+        kobject_put(kobj);
+        drm_warn(&xe->drm, "failed to register throttle sysfs, err: 

%d\n", err);
+        return;
+    }
+
+    err = drmm_add_action_or_reset(&xe->drm, gt_throttle_sysfs_fini, kobj);
+    if (err)
+        drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed,
err: %d\n",
+             __func__, err);

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c new file +1 -0
+}
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +3 -0
new file mode 100644
index 000000000000..c318d98215a0
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation

drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h line 13

Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +10 -0
+ */
+
+#ifndef _XE_GT_THROTTLE_SYSFS_H_
+#define _XE_GT_THROTTLE_SYSFS_H_
+
+#include <drm/drm_managed.h>
+
+#include "xe_device.h"
+#include "xe_gt.h"
+

Above headers are not used.
Can use forward declaration for xe_gt

Quoted 2 lines

Thanks
Riana

Sure.

Thanks,

Suja

Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/xe/xe_gt_throttle_sysfs.h new file +3 -0
+void xe_gt_throttle_sysfs_init(struct xe_gt *gt);
+
+#endif /* _XE_GT_THROTTLE_SYSFS_H_ */
#6 lore raw

[Intel-xe] ✓ CI.Patch_applied: success for Add throttle reasosn sysfs

In reply to Sujaritha Sundaresan
== Series Details ==

== Series Details ==

Series: Add throttle reasosn sysfs
URL : https://patchwork.freedesktop.org/series/124278/
State : success

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: fc8ec3c56 drm/xe: Add Wa_18028616096
=== git am output follows ===
Applying: drm/xe: Add throttle reasons sysfs attributes

#7 lore raw

[Intel-xe] ✗ CI.checkpatch: warning for Add throttle reasosn sysfs

In reply to Sujaritha Sundaresan
== Series Details ==

== Series Details ==

Series: Add throttle reasosn sysfs
URL : https://patchwork.freedesktop.org/series/124278/
State : warning

== Summary ==

+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 63c2b6b160bca2df6efc7bc4cea6f442097d7854
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 0d5f041309116a88b06bd840793dc3ee8ec643b4

Author: Sujaritha Sundaresan <[email protected]>
Date:   Tue Sep 26 20:09:16 2023 +0530

drm/xe: Add throttle reasons sysfs attributes

Add throttle reasons sysfs interface under device/../gt#/ Currently there is one overall status and eight reasons attributes.

The new sysfs structure will have the below layout

device/tile<n>/gt<n>
├── gt0
│ └── throttle
│ ├── <throttle_reasons>
│
│
├── gtN
│ └── throttle
│ ├── <throttle_reasons>

v2: Fix review comments (Riana)
Move init call (Matt)

v3: Remove xe_gt_throttle (Riana)
Make functions static (Rodrigo)

+ /mt/dim checkpatch fc8ec3c56efa5c15b630ddc17c89100440fe03ef drm-intel
0d5f04130 drm/xe: Add throttle reasons sysfs attributes
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:88: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #88:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 311 lines checked

#8 lore raw

[Intel-xe] ✗ CI.KUnit: failure for Add throttle reasosn sysfs

In reply to Sujaritha Sundaresan
== Series Details ==

== Series Details ==

Series: Add throttle reasosn sysfs
URL : https://patchwork.freedesktop.org/series/124278/
State : failure

== Summary ==

+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:../drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c: In function ‘xe_gt_throttle_sysfs_init’:
../drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c:256:3: error: expected declaration or statement at end of input

  256 |   drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
      |   ^~~~~~~~

make[7]: *** [../scripts/Makefile.build:243: drivers/gpu/drm/xe/xe_gt_throttle_sysfs.o] Error 1 make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:480: drivers/gpu/drm/xe] Error 2 make[6]: *** Waiting for unfinished jobs....
make[5]: *** [../scripts/Makefile.build:480: drivers/gpu/drm] Error 2
make[4]: *** [../scripts/Makefile.build:480: drivers/gpu] Error 2
make[3]: *** [../scripts/Makefile.build:480: drivers] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [/kernel/Makefile:2032: .] Error 2
make[1]: *** [/kernel/Makefile:234: __sub-make] Error 2
make: *** [Makefile:234: __sub-make] Error 2

[15:16:19] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[15:16:23] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make ARCH=um O=.kunit --jobs=48
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel