Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@linux.intel.com>
To: intel-gfx <intel-gfx@lists.freedesktop.org>,
	dri-devel <dri-devel@lists.freedesktop.org>
Cc: Chris Wilson <chris.p.wilson@linux.intel.com>,
	Andi Shyti <andi.shyti@linux.intel.com>
Subject: [RFC PATCH v2 11/11] drm/i915/gt: Allow the user to change the CCS mode through sysfs
Date: Sat, 17 Aug 2024 23:00:26 +0200	[thread overview]
Message-ID: <20240817210026.310645-12-andi.shyti@linux.intel.com> (raw)
In-Reply-To: <20240817210026.310645-1-andi.shyti@linux.intel.com>

Create the 'ccs_mode' file under

/sys/class/drm/cardX/gt/gt0/ccs_mode

This file allows the user to read and set the current CCS mode.

 - Reading: The user can read the current CCS mode, which can be
   1, 2, or 4. This value is derived from the current engine
   mask.

 - Writing: The user can set the CCS mode to 1, 2, or 4,
   depending on the desired number of exposed engines and the
   required load balancing.

The interface will return -EBUSY if other clients are connected
to i915, or -EINVAL if an invalid value is set.

Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
---
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 74 +++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c
index b1c3c9d9bb4f..30393009bc43 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c
+++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c
@@ -5,6 +5,7 @@
 
 #include "i915_drv.h"
 #include "intel_gt_ccs_mode.h"
+#include "intel_gt_pm.h"
 #include "intel_gt_print.h"
 #include "intel_gt_regs.h"
 #include "intel_gt_sysfs.h"
@@ -206,6 +207,68 @@ static ssize_t num_cslices_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(num_cslices);
 
+static ssize_t ccs_mode_show(struct device *dev,
+			     struct device_attribute *attr, char *buff)
+{
+	struct intel_gt *gt = kobj_to_gt(&dev->kobj);
+	u32 ccs_mode;
+
+	ccs_mode = hweight32(gt->ccs.ccs_mask);
+
+	return sysfs_emit(buff, "%u\n", ccs_mode);
+}
+
+static ssize_t ccs_mode_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buff, size_t count)
+{
+	struct intel_gt *gt = kobj_to_gt(&dev->kobj);
+	int num_cslices = hweight32(CCS_MASK(gt));
+	int ccs_mode = hweight32(gt->ccs.ccs_mask);
+	ssize_t ret;
+	u32 val;
+
+	ret = kstrtou32(buff, 0, &val);
+	if (ret)
+		return ret;
+
+	/*
+	 * As of now possible values to be set are 1, 2, 4,
+	 * up to the maximum number of available slices
+	 */
+	if ((!val) || (val > num_cslices) || (num_cslices % val))
+		return -EINVAL;
+
+	/*
+	 * We don't want to change the CCS
+	 * mode while someone is using the GT
+	 */
+	if (intel_gt_pm_is_awake(gt))
+		return -EBUSY;
+
+	mutex_lock(&gt->wakeref.mutex);
+	mutex_lock(&gt->ccs.mutex);
+
+	/*
+	 * Nothing to do if the requested setting
+	 * is the same as the current one
+	 */
+	if (val == ccs_mode)
+		return count;
+	else if (val > ccs_mode)
+		add_uabi_ccs_engines(gt, val);
+	else
+		remove_uabi_ccs_engines(gt, val);
+
+	intel_gt_apply_ccs_mode(gt, val);
+
+	mutex_unlock(&gt->ccs.mutex);
+	mutex_unlock(&gt->wakeref.mutex);
+
+	return count;
+}
+static DEVICE_ATTR_RW(ccs_mode);
+
 void intel_gt_sysfs_ccs_init(struct intel_gt *gt)
 {
 	int err;
@@ -213,4 +276,15 @@ void intel_gt_sysfs_ccs_init(struct intel_gt *gt)
 	err = sysfs_create_file(&gt->sysfs_gt, &dev_attr_num_cslices.attr);
 	if (err)
 		gt_dbg(gt, "failed to create sysfs num_cslices files\n");
+
+	/*
+	 * Do not create the ccs_mode file for non DG2 platforms
+	 * because they don't need it as they have only one CCS engine
+	 */
+	if (!IS_DG2(gt->i915))
+		return;
+
+	err = sysfs_create_file(&gt->sysfs_gt, &dev_attr_ccs_mode.attr);
+	if (err)
+		gt_dbg(gt, "failed to create sysfs ccs_mode files\n");
 }
-- 
2.45.2


  parent reply	other threads:[~2024-08-17 21:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-17 21:00 [RFC PATCH v2 00/11] CCS static load balance Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 01/11] drm/i915/gt: Move the CCS mode variable to a global position Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 02/11] drm/i915/gt: Allow the creation of multi-mode CCS masks Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 03/11] drm/i915/gt: Refactor uabi engine class/instance list creation Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 04/11] drm/i915/gt: Manage CCS engine creation within UABI exposure Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 05/11] drm/i915/gt: Remove cslices mask value from the CCS structure Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 06/11] drm/i915/gt: Expose the number of total CCS slices Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 07/11] drm/i915/gt: Store engine-related sysfs kobjects Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 08/11] drm/i915/gt: Store active CCS mask Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 09/11] drm/i915/gt: Isolate single sysfs engine file creation Andi Shyti
2024-08-17 21:00 ` [RFC PATCH v2 10/11] drm/i915/gt: Implement creation and removal routines for CCS engines Andi Shyti
2024-08-17 21:00 ` Andi Shyti [this message]
2024-08-17 22:35 ` ✗ Fi.CI.CHECKPATCH: warning for CCS static load balance (rev2) Patchwork
2024-08-17 22:35 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-08-17 22:41 ` ✗ Fi.CI.BAT: failure " Patchwork

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=20240817210026.310645-12-andi.shyti@linux.intel.com \
    --to=andi.shyti@linux.intel.com \
    --cc=chris.p.wilson@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /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