From: Lucas De Marchi <lucas.demarchi@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>,
Raag Jadav <raag.jadav@intel.com>
Subject: [PATCH v2 7/8] drm/xe/gt_throttle: Drop individual show functions
Date: Sun, 26 Oct 2025 22:57:19 -0700 [thread overview]
Message-ID: <20251026-gt-throttle-cri-v2-7-41f8288a71a7@intel.com> (raw)
In-Reply-To: <20251026-gt-throttle-cri-v2-0-41f8288a71a7@intel.com>
They are all doing the same thing with the mask being the param. Just
declare our own attribute to store the mask and provide a single
function.
Another common pattern is to define the show function in the macro,
however on follow up work the mask may be used for returning more
information, so it'd need to be stored in any case.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
drivers/gpu/drm/xe/xe_gt_throttle.c | 254 +++++++++---------------------------
1 file changed, 62 insertions(+), 192 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_gt_throttle.c b/drivers/gpu/drm/xe/xe_gt_throttle.c
index 8647d2c997347..fa7068aac3344 100644
--- a/drivers/gpu/drm/xe/xe_gt_throttle.c
+++ b/drivers/gpu/drm/xe/xe_gt_throttle.c
@@ -54,6 +54,11 @@
* - ``reason_vr_tdc``: VR TDC
*/
+struct throttle_attribute {
+ struct kobj_attribute attr;
+ u32 mask;
+};
+
static struct xe_gt *dev_to_gt(struct device *dev)
{
return kobj_to_gt(dev->kobj.parent);
@@ -64,6 +69,11 @@ static struct xe_gt *throttle_to_gt(struct kobject *kobj)
return dev_to_gt(kobj_to_dev(kobj));
}
+static struct throttle_attribute *kobj_attribute_to_throttle(struct kobj_attribute *attr)
+{
+ return container_of(attr, struct throttle_attribute, attr);
+}
+
u32 xe_gt_throttle_get_limit_reasons(struct xe_gt *gt)
{
struct xe_device *xe = gt_to_xe(gt);
@@ -92,214 +102,74 @@ static bool is_throttled_by(struct xe_gt *gt, u32 mask)
return xe_gt_throttle_get_limit_reasons(gt) & mask;
}
-static ssize_t status_show(struct kobject *kobj,
+static ssize_t reason_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
+ struct throttle_attribute *ta = kobj_attribute_to_throttle(attr);
struct xe_gt *gt = throttle_to_gt(kobj);
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, U32_MAX));
-}
-
-static ssize_t reason_pl1_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, POWER_LIMIT_1_MASK));
-}
-
-static ssize_t reason_pl2_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, POWER_LIMIT_2_MASK));
-}
-
-static ssize_t reason_pl4_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, POWER_LIMIT_4_MASK));
-}
-
-static ssize_t reason_thermal_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, THERMAL_LIMIT_MASK));
-}
-
-static ssize_t reason_soc_thermal_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, SOC_THERMAL_LIMIT_MASK));
-}
-
-static ssize_t reason_prochot_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, PROCHOT_MASK));
-}
-
-static ssize_t reason_ratl_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, RATL_MASK));
-}
-
-static ssize_t reason_vr_thermalert_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, VR_THERMALERT_MASK));
-}
-
-static ssize_t reason_soc_avg_thermal_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, SOC_AVG_THERMAL_MASK));
-}
-
-static ssize_t reason_vr_tdc_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, VR_TDC_MASK));
-}
-
-static ssize_t reason_fastvmode_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, FASTVMODE_MASK));
-}
-
-static ssize_t reason_mem_thermal_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, MEM_THERMAL_MASK));
-}
-
-static ssize_t reason_vr_thermal_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, VR_THERMAL_MASK));
-}
-
-static ssize_t reason_iccmax_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, ICCMAX_MASK));
-}
-
-static ssize_t reason_psys_pl1_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, PSYS_PL1_MASK));
-}
-
-static ssize_t reason_psys_pl2_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, PSYS_PL2_MASK));
-}
-
-static ssize_t reason_p0_freq_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, P0_FREQ_MASK));
+ return sysfs_emit(buff, "%u\n", is_throttled_by(gt, ta->mask));
}
-static ssize_t reason_psys_crit_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- struct xe_gt *gt = throttle_to_gt(kobj);
-
- return sysfs_emit(buff, "%u\n", is_throttled_by(gt, PSYS_CRIT_MASK));
-}
-
-#define THROTTLE_ATTR_RO(name) \
- struct kobj_attribute attr_##name = __ATTR_RO(name)
+#define THROTTLE_ATTR_RO(name, _mask) \
+ struct throttle_attribute attr_##name = { \
+ .attr = __ATTR(name, 0444, reason_show, NULL), \
+ .mask = _mask, \
+ }
-static THROTTLE_ATTR_RO(status);
-static THROTTLE_ATTR_RO(reason_pl1);
-static THROTTLE_ATTR_RO(reason_pl2);
-static THROTTLE_ATTR_RO(reason_pl4);
-static THROTTLE_ATTR_RO(reason_thermal);
-static THROTTLE_ATTR_RO(reason_prochot);
-static THROTTLE_ATTR_RO(reason_ratl);
-static THROTTLE_ATTR_RO(reason_vr_thermalert);
-static THROTTLE_ATTR_RO(reason_vr_tdc);
+static THROTTLE_ATTR_RO(status, U32_MAX);
+static THROTTLE_ATTR_RO(reason_pl1, POWER_LIMIT_1_MASK);
+static THROTTLE_ATTR_RO(reason_pl2, POWER_LIMIT_2_MASK);
+static THROTTLE_ATTR_RO(reason_pl4, POWER_LIMIT_4_MASK);
+static THROTTLE_ATTR_RO(reason_thermal, THERMAL_LIMIT_MASK);
+static THROTTLE_ATTR_RO(reason_prochot, PROCHOT_MASK);
+static THROTTLE_ATTR_RO(reason_ratl, RATL_MASK);
+static THROTTLE_ATTR_RO(reason_vr_thermalert, VR_THERMALERT_MASK);
+static THROTTLE_ATTR_RO(reason_vr_tdc, VR_TDC_MASK);
static struct attribute *throttle_attrs[] = {
- &attr_status.attr,
- &attr_reason_pl1.attr,
- &attr_reason_pl2.attr,
- &attr_reason_pl4.attr,
- &attr_reason_thermal.attr,
- &attr_reason_prochot.attr,
- &attr_reason_ratl.attr,
- &attr_reason_vr_thermalert.attr,
- &attr_reason_vr_tdc.attr,
+ &attr_status.attr.attr,
+ &attr_reason_pl1.attr.attr,
+ &attr_reason_pl2.attr.attr,
+ &attr_reason_pl4.attr.attr,
+ &attr_reason_thermal.attr.attr,
+ &attr_reason_prochot.attr.attr,
+ &attr_reason_ratl.attr.attr,
+ &attr_reason_vr_thermalert.attr.attr,
+ &attr_reason_vr_tdc.attr.attr,
NULL
};
-static THROTTLE_ATTR_RO(reason_vr_thermal);
-static THROTTLE_ATTR_RO(reason_soc_thermal);
-static THROTTLE_ATTR_RO(reason_mem_thermal);
-static THROTTLE_ATTR_RO(reason_iccmax);
-static THROTTLE_ATTR_RO(reason_soc_avg_thermal);
-static THROTTLE_ATTR_RO(reason_fastvmode);
-static THROTTLE_ATTR_RO(reason_psys_pl1);
-static THROTTLE_ATTR_RO(reason_psys_pl2);
-static THROTTLE_ATTR_RO(reason_p0_freq);
-static THROTTLE_ATTR_RO(reason_psys_crit);
+static THROTTLE_ATTR_RO(reason_vr_thermal, VR_THERMAL_MASK);
+static THROTTLE_ATTR_RO(reason_soc_thermal, SOC_THERMAL_LIMIT_MASK);
+static THROTTLE_ATTR_RO(reason_mem_thermal, MEM_THERMAL_MASK);
+static THROTTLE_ATTR_RO(reason_iccmax, ICCMAX_MASK);
+static THROTTLE_ATTR_RO(reason_soc_avg_thermal, SOC_AVG_THERMAL_MASK);
+static THROTTLE_ATTR_RO(reason_fastvmode, FASTVMODE_MASK);
+static THROTTLE_ATTR_RO(reason_psys_pl1, PSYS_PL1_MASK);
+static THROTTLE_ATTR_RO(reason_psys_pl2, PSYS_PL2_MASK);
+static THROTTLE_ATTR_RO(reason_p0_freq, P0_FREQ_MASK);
+static THROTTLE_ATTR_RO(reason_psys_crit, PSYS_CRIT_MASK);
static struct attribute *cri_throttle_attrs[] = {
/* Common */
- &attr_status.attr,
- &attr_reason_pl1.attr,
- &attr_reason_pl2.attr,
- &attr_reason_pl4.attr,
- &attr_reason_prochot.attr,
- &attr_reason_ratl.attr,
+ &attr_status.attr.attr,
+ &attr_reason_pl1.attr.attr,
+ &attr_reason_pl2.attr.attr,
+ &attr_reason_pl4.attr.attr,
+ &attr_reason_prochot.attr.attr,
+ &attr_reason_ratl.attr.attr,
/* CRI */
- &attr_reason_vr_thermal.attr,
- &attr_reason_soc_thermal.attr,
- &attr_reason_mem_thermal.attr,
- &attr_reason_iccmax.attr,
- &attr_reason_soc_avg_thermal.attr,
- &attr_reason_fastvmode.attr,
- &attr_reason_psys_pl1.attr,
- &attr_reason_psys_pl2.attr,
- &attr_reason_p0_freq.attr,
- &attr_reason_psys_crit.attr,
+ &attr_reason_vr_thermal.attr.attr,
+ &attr_reason_soc_thermal.attr.attr,
+ &attr_reason_mem_thermal.attr.attr,
+ &attr_reason_iccmax.attr.attr,
+ &attr_reason_soc_avg_thermal.attr.attr,
+ &attr_reason_fastvmode.attr.attr,
+ &attr_reason_psys_pl1.attr.attr,
+ &attr_reason_psys_pl2.attr.attr,
+ &attr_reason_p0_freq.attr.attr,
+ &attr_reason_psys_crit.attr.attr,
NULL
};
--
2.51.0
next prev parent reply other threads:[~2025-10-27 5:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-27 5:57 [PATCH v2 0/8] drm/xe: CRI support in gt_throttle + refactors Lucas De Marchi
2025-10-27 5:57 ` [PATCH v2 1/8] drm/xe/cri: Add new performance limit reasons bits Lucas De Marchi
2025-10-27 5:57 ` [PATCH v2 2/8] drm/xe/gt_throttle: Tidy up perf reasons reading Lucas De Marchi
2025-10-27 5:57 ` [PATCH v2 3/8] drm/xe/gt_throttle: Always read and mask Lucas De Marchi
2025-10-27 5:57 ` [PATCH v2 4/8] drm/xe/gt_throttle: Add throttle_to_gt() Lucas De Marchi
2025-10-27 5:57 ` [PATCH v2 5/8] drm/xe/gt_throttle: Tidy up attribute definition Lucas De Marchi
2025-10-27 11:38 ` Raag Jadav
2025-10-27 5:57 ` [PATCH v2 6/8] drm/xe: Improve freq and throttle documentation Lucas De Marchi
2025-10-27 11:43 ` Raag Jadav
2025-10-27 5:57 ` Lucas De Marchi [this message]
2025-10-27 12:15 ` [PATCH v2 7/8] drm/xe/gt_throttle: Drop individual show functions Raag Jadav
2025-10-27 5:57 ` [PATCH v2 8/8] drm/xe/gt_throttle: Avoid TOCTOU when monitoring reasons Lucas De Marchi
2025-10-27 11:50 ` Raag Jadav
2025-10-27 13:26 ` Lucas De Marchi
2025-10-28 5:24 ` Raag Jadav
2025-10-28 14:02 ` Rodrigo Vivi
2025-10-28 16:04 ` Lucas De Marchi
2025-10-29 20:24 ` Rodrigo Vivi
2025-10-27 6:04 ` ✗ CI.checkpatch: warning for drm/xe: CRI support in gt_throttle + refactors (rev2) Patchwork
2025-10-27 6:05 ` ✓ CI.KUnit: success " Patchwork
2025-10-27 6:51 ` ✓ Xe.CI.BAT: " Patchwork
2025-10-27 8:25 ` ✗ Xe.CI.Full: failure " Patchwork
2025-10-27 11:38 ` [PATCH v2 0/8] drm/xe: CRI support in gt_throttle + refactors Raag Jadav
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251026-gt-throttle-cri-v2-7-41f8288a71a7@intel.com \
--to=lucas.demarchi@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=raag.jadav@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox