Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sk Anirban <sk.anirban@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: anshuman.gupta@intel.com, badal.nilawar@intel.com,
	riana.tauro@intel.com, karthik.poosa@intel.com,
	raag.jadav@intel.com, soham.purkait@intel.com,
	mallesh.koujalagi@intel.com, vinay.belgaumkar@intel.com,
	Sk Anirban <sk.anirban@intel.com>
Subject: [PATCH] drm/xe/guc_pc: Add ignore efficient frequency support
Date: Tue, 16 Sep 2025 12:28:11 +0530	[thread overview]
Message-ID: <20250916065810.2810689-2-sk.anirban@intel.com> (raw)

When setting minimum frequency, GuC automatically elevates it to
efficient levels, potentially overriding user requests.
This patch adds slpc_ignore_eff_freq sysfs interface to disable
this behavior, allowing users to enforce their exact minimum
frequency settings.

Signed-off-by: Sk Anirban <sk.anirban@intel.com>
---
 drivers/gpu/drm/xe/xe_gt_freq.c      | 36 ++++++++++++++++++++
 drivers/gpu/drm/xe/xe_guc_pc.c       | 49 ++++++++++++++++++++++++++--
 drivers/gpu/drm/xe/xe_guc_pc.h       |  1 +
 drivers/gpu/drm/xe/xe_guc_pc_types.h |  2 ++
 4 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_gt_freq.c b/drivers/gpu/drm/xe/xe_gt_freq.c
index 60d9354e7dbf..55d55fbcd4bd 100644
--- a/drivers/gpu/drm/xe/xe_gt_freq.c
+++ b/drivers/gpu/drm/xe/xe_gt_freq.c
@@ -227,6 +227,41 @@ static ssize_t max_freq_store(struct kobject *kobj,
 }
 static struct kobj_attribute attr_max_freq = __ATTR_RW(max_freq);
 
+static ssize_t slpc_ignore_eff_freq_show(struct kobject *kobj,
+					 struct kobj_attribute *attr, char *buf)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct xe_guc_pc *pc = dev_to_pc(dev);
+
+	return sysfs_emit(buf, "%u\n", pc->ignore_eff_freq);
+}
+
+static ssize_t slpc_ignore_eff_freq_store(struct kobject *kobj,
+					  struct kobj_attribute *attr,
+					  const char *buff, size_t count)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct xe_guc_pc *pc = dev_to_pc(dev);
+	u32 val;
+	ssize_t ret;
+
+	ret = kstrtou32(buff, 0, &val);
+	if (ret)
+		return ret;
+
+	if (val > 1)
+		return -EINVAL;
+
+	xe_pm_runtime_get(dev_to_xe(dev));
+	ret = xe_guc_pc_set_ignore_eff_freq(pc, val);
+	xe_pm_runtime_put(dev_to_xe(dev));
+	if (ret)
+		return ret;
+
+	return count;
+}
+static struct kobj_attribute attr_slpc_ignore_eff_freq = __ATTR_RW(slpc_ignore_eff_freq);
+
 static const struct attribute *freq_attrs[] = {
 	&attr_act_freq.attr,
 	&attr_cur_freq.attr,
@@ -236,6 +271,7 @@ static const struct attribute *freq_attrs[] = {
 	&attr_rpn_freq.attr,
 	&attr_min_freq.attr,
 	&attr_max_freq.attr,
+	&attr_slpc_ignore_eff_freq.attr,
 	NULL
 };
 
diff --git a/drivers/gpu/drm/xe/xe_guc_pc.c b/drivers/gpu/drm/xe/xe_guc_pc.c
index 68b192fe3b32..4c5b5d33d9e3 100644
--- a/drivers/gpu/drm/xe/xe_guc_pc.c
+++ b/drivers/gpu/drm/xe/xe_guc_pc.c
@@ -331,6 +331,8 @@ static void pc_set_cur_freq(struct xe_guc_pc *pc, u32 freq)
 
 static int pc_set_min_freq(struct xe_guc_pc *pc, u32 freq)
 {
+	int ret;
+
 	/*
 	 * Let's only check for the rpn-rp0 range. If max < min,
 	 * min becomes a fixed request.
@@ -342,8 +344,10 @@ static int pc_set_min_freq(struct xe_guc_pc *pc, u32 freq)
 	 * GuC policy is to elevate minimum frequency to the efficient levels
 	 * Our goal is to have the admin choices respected.
 	 */
-	pc_action_set_param(pc, SLPC_PARAM_IGNORE_EFFICIENT_FREQUENCY,
-			    freq < pc->rpe_freq);
+	ret = pc_action_set_param(pc, SLPC_PARAM_IGNORE_EFFICIENT_FREQUENCY,
+				  freq < pc->rpe_freq || pc->ignore_eff_freq);
+	if (ret)
+		xe_gt_err(pc_to_gt(pc), "Failed to set efficient freq\n");
 
 	return pc_action_set_param(pc,
 				   SLPC_PARAM_GLOBAL_MIN_GT_UNSLICE_FREQ_MHZ,
@@ -732,6 +736,45 @@ int xe_guc_pc_set_max_freq(struct xe_guc_pc *pc, u32 freq)
 	return xe_guc_pc_set_max_freq_locked(pc, freq);
 }
 
+int xe_guc_pc_set_ignore_eff_freq(struct xe_guc_pc *pc, bool val)
+{
+	int ret;
+	u32 min_freq;
+
+	guard(mutex)(&pc->freq_lock);
+
+	if (!pc->freq_ready)
+		return -EAGAIN;
+
+	if (val) {
+		ret = xe_guc_pc_get_min_freq_locked(pc, &min_freq);
+		if (ret)
+			return ret;
+	}
+
+	ret = pc_action_set_param(pc, SLPC_PARAM_IGNORE_EFFICIENT_FREQUENCY, val);
+	if (ret) {
+		xe_gt_err(pc_to_gt(pc), "Failed to set ignore efficient freq(%d): %pe\n",
+			  val, ERR_PTR(ret));
+		return ret;
+	}
+
+	pc->ignore_eff_freq = val;
+
+	if (val) {
+		ret = pc_action_set_param(pc,
+					  SLPC_PARAM_GLOBAL_MIN_GT_UNSLICE_FREQ_MHZ,
+					  min_freq);
+		if (ret) {
+			xe_gt_err(pc_to_gt(pc), "Failed to set min freq to %u: %pe\n",
+				  min_freq, ERR_PTR(ret));
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 /**
  * xe_guc_pc_c_status - get the current GT C state
  * @pc: XE_GuC_PC instance
@@ -1328,6 +1371,8 @@ int xe_guc_pc_init(struct xe_guc_pc *pc)
 	if (err)
 		return err;
 
+	pc->ignore_eff_freq = false;
+
 	bo = xe_managed_bo_create_pin_map(xe, tile, size,
 					  XE_BO_FLAG_VRAM_IF_DGFX(tile) |
 					  XE_BO_FLAG_GGTT |
diff --git a/drivers/gpu/drm/xe/xe_guc_pc.h b/drivers/gpu/drm/xe/xe_guc_pc.h
index 52ecdd5ddbff..8a49daad8d11 100644
--- a/drivers/gpu/drm/xe/xe_guc_pc.h
+++ b/drivers/gpu/drm/xe/xe_guc_pc.h
@@ -31,6 +31,7 @@ int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq);
 int xe_guc_pc_set_min_freq(struct xe_guc_pc *pc, u32 freq);
 int xe_guc_pc_get_max_freq(struct xe_guc_pc *pc, u32 *freq);
 int xe_guc_pc_set_max_freq(struct xe_guc_pc *pc, u32 freq);
+int xe_guc_pc_set_ignore_eff_freq(struct xe_guc_pc *pc, bool val);
 
 enum xe_gt_idle_state xe_guc_pc_c_status(struct xe_guc_pc *pc);
 u64 xe_guc_pc_rc6_residency(struct xe_guc_pc *pc);
diff --git a/drivers/gpu/drm/xe/xe_guc_pc_types.h b/drivers/gpu/drm/xe/xe_guc_pc_types.h
index c02053948a57..17e10809011e 100644
--- a/drivers/gpu/drm/xe/xe_guc_pc_types.h
+++ b/drivers/gpu/drm/xe/xe_guc_pc_types.h
@@ -37,6 +37,8 @@ struct xe_guc_pc {
 	struct mutex freq_lock;
 	/** @freq_ready: Only handle freq changes, if they are really ready */
 	bool freq_ready;
+	/** @ignore_eff_freq: Ignore efficient frequency */
+	bool ignore_eff_freq;
 };
 
 #endif	/* _XE_GUC_PC_TYPES_H_ */
-- 
2.43.0


             reply	other threads:[~2025-09-16  6:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-16  6:58 Sk Anirban [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-09-16 14:05 [PATCH] drm/xe/guc_pc: Add ignore efficient frequency support Sk Anirban
2025-09-17  5:29 ` Nilawar, Badal
2025-09-17  5:52   ` Anirban, Sk
2025-09-19  0:24     ` Belgaumkar, Vinay

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=20250916065810.2810689-2-sk.anirban@intel.com \
    --to=sk.anirban@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=karthik.poosa@intel.com \
    --cc=mallesh.koujalagi@intel.com \
    --cc=raag.jadav@intel.com \
    --cc=riana.tauro@intel.com \
    --cc=soham.purkait@intel.com \
    --cc=vinay.belgaumkar@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