Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
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 3/8] drm/xe/gt_throttle: Always read and mask
Date: Sun, 26 Oct 2025 22:57:15 -0700	[thread overview]
Message-ID: <20251026-gt-throttle-cri-v2-3-41f8288a71a7@intel.com> (raw)
In-Reply-To: <20251026-gt-throttle-cri-v2-0-41f8288a71a7@intel.com>

Use a single function to read and mask the value the callers will be
interested in. This reduces the risk of a caller using a plain call to
xe_gt_throttle_get_limit_reasons() without applying any mask, which can
return unexpected bits for future platforms.

Select which reg and mask it's going to be used according to the
platform and gt type and always use that one function.

There was an odd xe_gt_dbg() when reading the status, which is not done
for any other throttle/* sysfs file, so just make the status be as
special as everybody else.

Reviewed-by: Raag Jadav <raag.jadav@intel.com>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
 drivers/gpu/drm/xe/xe_gt_throttle.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_gt_throttle.c b/drivers/gpu/drm/xe/xe_gt_throttle.c
index c69710f2dbeb5..f743444f641a8 100644
--- a/drivers/gpu/drm/xe/xe_gt_throttle.c
+++ b/drivers/gpu/drm/xe/xe_gt_throttle.c
@@ -8,7 +8,6 @@
 #include <regs/xe_gt_regs.h>
 #include "xe_device.h"
 #include "xe_gt.h"
-#include "xe_gt_printk.h"
 #include "xe_gt_sysfs.h"
 #include "xe_gt_throttle.h"
 #include "xe_mmio.h"
@@ -57,32 +56,25 @@ dev_to_gt(struct device *dev)
 
 u32 xe_gt_throttle_get_limit_reasons(struct xe_gt *gt)
 {
-	u32 reg;
+	struct xe_device *xe = gt_to_xe(gt);
+	struct xe_reg reg;
+	u32 val, mask;
 
-	xe_pm_runtime_get(gt_to_xe(gt));
 	if (xe_gt_is_media_type(gt))
-		reg = xe_mmio_read32(&gt->mmio, MTL_MEDIA_PERF_LIMIT_REASONS);
+		reg = MTL_MEDIA_PERF_LIMIT_REASONS;
 	else
-		reg = xe_mmio_read32(&gt->mmio, GT0_PERF_LIMIT_REASONS);
-	xe_pm_runtime_put(gt_to_xe(gt));
-
-	return reg;
-}
-
-static u32 read_status(struct xe_gt *gt)
-{
-	struct xe_device *xe = gt_to_xe(gt);
-	u32 status, mask;
+		reg = GT0_PERF_LIMIT_REASONS;
 
 	if (xe->info.platform == XE_CRESCENTISLAND)
 		mask = CRI_PERF_LIMIT_REASONS_MASK;
 	else
 		mask = GT0_PERF_LIMIT_REASONS_MASK;
 
-	status = xe_gt_throttle_get_limit_reasons(gt) & mask;
-	xe_gt_dbg(gt, "throttle reasons: 0x%08x\n", status);
+	xe_pm_runtime_get(xe);
+	val = xe_mmio_read32(&gt->mmio, reg) & mask;
+	xe_pm_runtime_put(xe);
 
-	return status;
+	return val;
 }
 
 static bool is_throttled_by(struct xe_gt *gt, u32 mask)
@@ -96,7 +88,7 @@ static ssize_t status_show(struct kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct xe_gt *gt = dev_to_gt(dev);
 
-	return sysfs_emit(buff, "%u\n", !!read_status(gt));
+	return sysfs_emit(buff, "%u\n", is_throttled_by(gt, U32_MAX));
 }
 static struct kobj_attribute attr_status = __ATTR_RO(status);
 

-- 
2.51.0


  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 ` Lucas De Marchi [this message]
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 ` [PATCH v2 7/8] drm/xe/gt_throttle: Drop individual show functions Lucas De Marchi
2025-10-27 12:15   ` 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-3-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