Skip to contentSkip to conversation

CCS static load balance

RFC PATCH Superseded Andi Shyti 3 participants 16 messages Aug 17, 2024 – Aug 18, 2024

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Andi Shyti

author
#0 lore raw

v2 cover CCS static load balance

Hi,

This patch series introduces static load balancing for GPUs with multiple compute engines. It's a lengthy series, and some challenging aspects still need to be resolved.

I have tried to split the work as much as possible to facilitate the review process.

To summarize, in patches 1 to 10, no functional changes occur except for the addition of the num_cslices interface. The significant changes happen in patch 11, which is the core part of the CCS mode setting, utilizing the groundwork laid in the earlier patches.

Compared to the first version I've taken a completely different approach to adding and removing engines. in v1 physical engines were directly added and removed, along with the memory allocated to them, each time the user changed the CCS mode.

In this updated approach, the focus is now on managing the UABI engine list, which controls the engines exposed to userspace. Instead of manipulating phuscal engines and their memory, we now handle engine exposure through this list.

I would greatly appreciate further input from all reviewers who have already assisted with the previous work.

IGT tests have also been developed, but I haven't sent them yet.

Thank you Chris for the offline reviews.

Thanks,
Andi

Changelog
=========
v1 -> v2:
- Changed engine dynamic creation and removal as described above.

Andi Shyti (11):
drm/i915/gt: Move the CCS mode variable to a global position drm/i915/gt: Allow the creation of multi-mode CCS masks drm/i915/gt: Refactor uabi engine class/instance list creation drm/i915/gt: Manage CCS engine creation within UABI exposure drm/i915/gt: Remove cslices mask value from the CCS structure drm/i915/gt: Expose the number of total CCS slices drm/i915/gt: Store engine-related sysfs kobjects drm/i915/gt: Store active CCS mask
drm/i915/gt: Isolate single sysfs engine file creation drm/i915/gt: Implement creation and removal routines for CCS engines drm/i915/gt: Allow the user to change the CCS mode through sysfs

 drivers/gpu/drm/i915/gt/intel_engine_cs.c    |  23 --
 drivers/gpu/drm/i915/gt/intel_engine_types.h |   3 +
 drivers/gpu/drm/i915/gt/intel_engine_user.c  |  49 +++-
 drivers/gpu/drm/i915/gt/intel_gt.c           |   3 +
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c  | 287 +++++++++++++++++--
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h  |   6 +-
 drivers/gpu/drm/i915/gt/intel_gt_sysfs.c     |   2 +
 drivers/gpu/drm/i915/gt/intel_gt_types.h     |  18 +-
 drivers/gpu/drm/i915/gt/intel_workarounds.c  |   7 +-
 drivers/gpu/drm/i915/gt/sysfs_engines.c      |  75 +++--
 drivers/gpu/drm/i915/gt/sysfs_engines.h      |   2 +
 drivers/gpu/drm/i915/i915_drv.h              |   1 +
 12 files changed, 385 insertions(+), 91 deletions(-)
Signature · 1 line
2.45.2
author
#1 lore raw

RFC PATCH v2 1/11 drm/i915/gt: Move the CCS mode variable to a global position

Store the CCS mode value in the intel_gt->ccs structure to make it available for future instances that may need to change its value.

Name it mode_reg_val because it holds the value that will be written into the CCS_MODE register, determining the CCS balancing and, consequently, the number of engines generated.

Create a mutex to control access to the mode_reg_val variable.

No functional changes intended.

---
 drivers/gpu/drm/i915/gt/intel_gt.c          |  3 +++
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 13 ++++++++++---
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h |  3 ++-
 drivers/gpu/drm/i915/gt/intel_gt_types.h    | 12 ++++++++++++
 drivers/gpu/drm/i915/gt/intel_workarounds.c |  7 ++++---
 5 files changed, 31 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt.c +3 -0
index a6c69a706fd7..5af0527d822d 100644
@@ -18,6 +18,7 @@
 #include "intel_ggtt_gmch.h"
 #include "intel_gt.h"
 #include "intel_gt_buffer_pool.h"
+#include "intel_gt_ccs_mode.h"
 #include "intel_gt_clock_utils.h"
 #include "intel_gt_debugfs.h"
 #include "intel_gt_mcr.h"
@@ -136,6 +137,8 @@ int intel_gt_init_mmio(struct intel_gt *gt)
 	intel_sseu_info_init(gt);
 	intel_gt_mcr_init(gt);
 
+	intel_gt_ccs_mode_init(gt);
+
 	return intel_engines_init_mmio(gt);
 }
 
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +10 -3
index 3c62a44e9106..19e0bc359861 100644
@@ -8,14 +8,16 @@
 #include "intel_gt_ccs_mode.h"
 #include "intel_gt_regs.h"
 
-unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt)
+void intel_gt_apply_ccs_mode(struct intel_gt *gt)
 {
 	int cslice;
 	u32 mode = 0;
 	int first_ccs = __ffs(CCS_MASK(gt));
 
+	lockdep_assert_held(&gt->ccs.mutex);
+
 	if (!IS_DG2(gt->i915))
-		return 0;
+		return;
 
 	/* Build the value for the fixed CCS load balancing */
 	for (cslice = 0; cslice < I915_MAX_CCS; cslice++) {
@@ -35,5 +37,10 @@ unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt)
 						     XEHP_CCS_MODE_CSLICE_MASK);
 	}
 
-	return mode;
+	gt->ccs.mode_reg_val = mode;
+}
+
+void intel_gt_ccs_mode_init(struct intel_gt *gt)
+{
+	mutex_init(&gt->ccs.mutex);
 }
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h +2 -1
index 55547f2ff426..e646ab595ded 100644
@@ -8,6 +8,7 @@
 
 struct intel_gt;
 
-unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt);
+void intel_gt_apply_ccs_mode(struct intel_gt *gt);
+void intel_gt_ccs_mode_init(struct intel_gt *gt);
 
 #endif /* __INTEL_GT_CCS_MODE_H__ */
drivers/gpu/drm/i915/gt/intel_gt_types.h +12 -0
index bcee084b1f27..8df8fac066c0 100644
@@ -207,12 +207,24 @@ struct intel_gt {
 					    [MAX_ENGINE_INSTANCE + 1];
 	enum intel_submission_method submission_method;
 
+	/*
+	 * Track fixed mapping between CCS engines and compute slices.
+	 *
+	 * In order to w/a HW that has the inability to dynamically load
+	 * balance between CCS engines and EU in the compute slices, we have to
+	 * reconfigure a static mapping on the fly.
+	 *
+	 * The mode variable is set by the user and sets the balancing mode,
+	 * i.e. how the CCS streams are distributed amongs the slices.
+	 */
 	struct {
 		/*
 		 * Mask of the non fused CCS slices
 		 * to be used for the load balancing
 		 */
 		intel_engine_mask_t cslices;
+		struct mutex mutex;
+		u32 mode_reg_val;
 	} ccs;
 
 	/*
drivers/gpu/drm/i915/gt/intel_workarounds.c +4 -3
index bfe6d8fc820f..daa11e11d68f 100644
@@ -2727,7 +2727,6 @@ add_render_compute_tuning_settings(struct intel_gt *gt,
 static void ccs_engine_wa_mode(struct intel_engine_cs *engine, struct i915_wa_list *wal)
 {
 	struct intel_gt *gt = engine->gt;
-	u32 mode;
 
 	if (!IS_DG2(gt->i915))
 		return;
@@ -2744,8 +2743,10 @@ static void ccs_engine_wa_mode(struct intel_engine_cs *engine, struct i915_wa_li
 	 * After having disabled automatic load balancing we need to
 	 * assign all slices to a single CCS. We will call it CCS mode 1
 	 */
-	mode = intel_gt_apply_ccs_mode(gt);
-	wa_masked_en(wal, XEHP_CCS_MODE, mode);
+	mutex_lock(&gt->ccs.mutex);
+	intel_gt_apply_ccs_mode(gt);
+	wa_masked_en(wal, XEHP_CCS_MODE, gt->ccs.mode_reg_val);
+	mutex_unlock(&gt->ccs.mutex);
 }
 
 /*
Signature · 1 line
2.45.2
author
#2 lore raw

RFC PATCH v2 2/11 drm/i915/gt: Allow the creation of multi-mode CCS masks

In reply to Andi Shyti

Until now, we have only set CCS mode balancing to 1, which means that only one compute engine is exposed to the user. The stream of compute commands submitted to that engine is then shared among all the dedicated execution units.

This is done by calling the 'intel_gt_apply_ccs_mode(); function.

With this change, the aforementioned function takes an additional parameter called 'mode' that specifies the desired mode to be set for the CCS engines balancing. The mode parameter can have the following values:

- mode = 0: CCS load balancing mode 1 (1 CCS engine exposed)
- mode = 1: CCS load balancing mode 2 (2 CCS engines exposed)
- mode = 3: CCS load balancing mode 4 (4 CCS engines exposed)

This allows us to generate the appropriate register value to be written to CCS_MODE, configuring how the exposed engine streams will be submitted to the execution units.

No functional changes are intended yet, as no mode higher than '0' is currently being set.

---
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 78 ++++++++++++++++-----
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h |  4 +-
 drivers/gpu/drm/i915/gt/intel_workarounds.c |  2 +-
 3 files changed, 65 insertions(+), 19 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +62 -16
index 19e0bc359861..6afd44ffc358 100644
@@ -4,37 +4,83 @@
  */
 
 #include "i915_drv.h"
-#include "intel_gt.h"
 #include "intel_gt_ccs_mode.h"
 #include "intel_gt_regs.h"
 
-void intel_gt_apply_ccs_mode(struct intel_gt *gt)
+void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode)
 {
+	unsigned long cslices_mask = gt->ccs.cslices;
+	u32 mode_val = 0;
+	u32 m = mode;
+	int ccs_id;
 	int cslice;
-	u32 mode = 0;
-	int first_ccs = __ffs(CCS_MASK(gt));
 
 	lockdep_assert_held(&gt->ccs.mutex);
 
 	if (!IS_DG2(gt->i915))
 		return;
 
-	/* Build the value for the fixed CCS load balancing */
-	for (cslice = 0; cslice < I915_MAX_CCS; cslice++) {
-		if (gt->ccs.cslices & BIT(cslice))
-			/*
-			 * If available, assign the cslice
-			 * to the first available engine...
-			 */
-			mode |= XEHP_CCS_MODE_CSLICE(cslice, first_ccs);
+	/*
+	 * The mode has two bit dedicated for each engine
+	 * that will be used for the CCS balancing algorithm:
+	 *
+	 *    BIT | CCS slice
+	 *   ------------------
+	 *     0  | CCS slice
+	 *     1  |     0
+	 *   ------------------
+	 *     2  | CCS slice
+	 *     3  |     1
+	 *   ------------------
+	 *     4  | CCS slice
+	 *     5  |     2
+	 *   ------------------
+	 *     6  | CCS slice
+	 *     7  |     3
+	 *   ------------------
+	 *
+	 * When a CCS slice is not available, then we will write 0x7,
+	 * oterwise we will write the user engine id which load will
+	 * be forwarded to that slice.
+	 *
+	 * The possible configurations are:
+	 *
+	 * 1 engine (ccs0):
+	 *   slice 0, 1, 2, 3: ccs0
+	 *
+	 * 2 engines (ccs0, ccs1):
+	 *   slice 0, 2: ccs0
+	 *   slice 1, 3: ccs1
+	 *
+	 * 4 engines (ccs0, ccs1, ccs2, ccs3):
+	 *   slice 0: ccs0
+	 *   slice 1: ccs1
+	 *   slice 2: ccs2
+	 *   slice 3: ccs3
+	 */
+	ccs_id = __ffs(cslices_mask);
 
-		else
+	for (cslice = 0; cslice < I915_MAX_CCS; cslice++) {
+		if (!(cslices_mask & BIT(cslice))) {
 			/*
-			 * ... otherwise, mark the cslice as
-			 * unavailable if no CCS dispatches here
+			 * If not available, mark the slice as unavailable
+			 * and no task will be dispatched here.
 			 */
-			mode |= XEHP_CCS_MODE_CSLICE(cslice,
+			mode_val |= XEHP_CCS_MODE_CSLICE(cslice,
 						     XEHP_CCS_MODE_CSLICE_MASK);
+			continue;
+		}
+
+		mode_val |= XEHP_CCS_MODE_CSLICE(cslice, ccs_id);
+
+		if (!m) {
+			m = mode;
+			ccs_id = __ffs(cslices_mask);
+			continue;
+		}
+
+		m--;
+		ccs_id = find_next_bit(&cslices_mask, I915_MAX_CCS, ccs_id + 1);
 	}
 
 	gt->ccs.mode_reg_val = mode;
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h +2 -2
index e646ab595ded..0e1c43ea1d54 100644
@@ -6,9 +6,9 @@
 #ifndef __INTEL_GT_CCS_MODE_H__
 #define __INTEL_GT_CCS_MODE_H__
 
-struct intel_gt;
+#include "intel_gt.h"
 
-void intel_gt_apply_ccs_mode(struct intel_gt *gt);
+void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode);
 void intel_gt_ccs_mode_init(struct intel_gt *gt);
 
 #endif /* __INTEL_GT_CCS_MODE_H__ */
drivers/gpu/drm/i915/gt/intel_workarounds.c +1 -1
index daa11e11d68f..203f2bb00e30 100644
@@ -2744,7 +2744,7 @@ static void ccs_engine_wa_mode(struct intel_engine_cs *engine, struct i915_wa_li
 	 * assign all slices to a single CCS. We will call it CCS mode 1
 	 */
 	mutex_lock(&gt->ccs.mutex);
-	intel_gt_apply_ccs_mode(gt);
+	intel_gt_apply_ccs_mode(gt, 0);
 	wa_masked_en(wal, XEHP_CCS_MODE, gt->ccs.mode_reg_val);
 	mutex_unlock(&gt->ccs.mutex);
 }
Signature · 1 line
2.45.2
author
#3 lore raw

RFC PATCH v2 3/11 drm/i915/gt: Refactor uabi engine class/instance list creation

In reply to Andi Shyti

For the upcoming changes we need a cleaner way to build the list of uabi engines.

---
 drivers/gpu/drm/i915/gt/intel_engine_user.c | 29 ++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_user.c +17 -12
index 833987015b8b..11cc06c0c785 100644
@@ -203,7 +203,7 @@ static void engine_rename(struct intel_engine_cs *engine, const char *name, u16
 
 void intel_engines_driver_register(struct drm_i915_private *i915)
 {
-	u16 name_instance, other_instance = 0;
+	u16 class_instance[I915_LAST_UABI_ENGINE_CLASS + 2] = { };
 	struct legacy_ring ring = {};
 	struct list_head *it, *next;
 	struct rb_node **p, *prev;
@@ -214,6 +214,8 @@ void intel_engines_driver_register(struct drm_i915_private *i915)
 	prev = NULL;
 	p = &i915->uabi_engines.rb_node;
 	list_for_each_safe(it, next, &engines) {
+		u16 uabi_class;
+
 		struct intel_engine_cs *engine =
 			container_of(it, typeof(*engine), uabi_list);
 
@@ -222,15 +224,14 @@ void intel_engines_driver_register(struct drm_i915_private *i915)
 
 		GEM_BUG_ON(engine->class >= ARRAY_SIZE(uabi_classes));
 		engine->uabi_class = uabi_classes[engine->class];
-		if (engine->uabi_class == I915_NO_UABI_CLASS) {
-			name_instance = other_instance++;
-		} else {
-			GEM_BUG_ON(engine->uabi_class >=
-				   ARRAY_SIZE(i915->engine_uabi_class_count));
-			name_instance =
-				i915->engine_uabi_class_count[engine->uabi_class]++;
-		}
-		engine->uabi_instance = name_instance;
+
+		if (engine->uabi_class == I915_NO_UABI_CLASS)
+			uabi_class = I915_LAST_UABI_ENGINE_CLASS + 1;
+		else
+			uabi_class = engine->uabi_class;
+
+		GEM_BUG_ON(uabi_class >= ARRAY_SIZE(class_instance));
+		engine->uabi_instance = class_instance[uabi_class]++;
 
 		/*
 		 * Replace the internal name with the final user and log facing
@@ -238,11 +239,15 @@ void intel_engines_driver_register(struct drm_i915_private *i915)
 		 */
 		engine_rename(engine,
 			      intel_engine_class_repr(engine->class),
-			      name_instance);
+			      engine->uabi_instance);
 
-		if (engine->uabi_class == I915_NO_UABI_CLASS)
+		if (uabi_class > I915_LAST_UABI_ENGINE_CLASS)
 			continue;
 
+		GEM_BUG_ON(uabi_class >=
+			   ARRAY_SIZE(i915->engine_uabi_class_count));
+		i915->engine_uabi_class_count[uabi_class]++;
+
 		rb_link_node(&engine->uabi_node, prev, p);
 		rb_insert_color(&engine->uabi_node, &i915->uabi_engines);
 
Signature · 1 line
2.45.2
author
#4 lore raw

RFC PATCH v2 4/11 drm/i915/gt: Manage CCS engine creation within UABI exposure

In reply to Andi Shyti

In commit ea315f98e5d6 ("drm/i915/gt: Do not generate the command streamer for all the CCS"), we restricted the creation of physical CCS engines to only one stream. This allowed the user to submit a single compute workload, with all CCS slices sharing the workload from that stream.

This patch removes that limitation but still exposes only one stream to the user. The physical memory for each engine remains allocated but unused, however the user will only see one engine exposed.

Do this by adding only one engine to the UABI list, ensuring that only one engine is visible to the user.

---
 drivers/gpu/drm/i915/gt/intel_engine_cs.c   | 23 ---------------------
 drivers/gpu/drm/i915/gt/intel_engine_user.c | 20 +++++++++++++++---
 2 files changed, 17 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +0 -23
index 4d30a86016f2..def255ee0b96 100644
@@ -876,29 +876,6 @@ static intel_engine_mask_t init_engine_mask(struct intel_gt *gt)
 		info->engine_mask &= ~BIT(GSC0);
 	}
 
-	/*
-	 * Do not create the command streamer for CCS slices beyond the first.
-	 * All the workload submitted to the first engine will be shared among
-	 * all the slices.
-	 *
-	 * Once the user will be allowed to customize the CCS mode, then this
-	 * check needs to be removed.
-	 */
-	if (IS_DG2(gt->i915)) {
-		u8 first_ccs = __ffs(CCS_MASK(gt));
-
-		/*
-		 * Store the number of active cslices before
-		 * changing the CCS engine configuration
-		 */
-		gt->ccs.cslices = CCS_MASK(gt);
-
-		/* Mask off all the CCS engine */
-		info->engine_mask &= ~GENMASK(CCS3, CCS0);
-		/* Put back in the first CCS engine */
-		info->engine_mask |= BIT(_CCS(first_ccs));
-	}
-
 	return info->engine_mask;
 }
 
drivers/gpu/drm/i915/gt/intel_engine_user.c +17 -3
index 11cc06c0c785..c5ccb677ed15 100644
@@ -207,6 +207,7 @@ void intel_engines_driver_register(struct drm_i915_private *i915)
 	struct legacy_ring ring = {};
 	struct list_head *it, *next;
 	struct rb_node **p, *prev;
+	u8 uabi_ccs_instance = 0;
 	LIST_HEAD(engines);
 
 	sort_engines(i915, &engines);
@@ -246,6 +247,22 @@ void intel_engines_driver_register(struct drm_i915_private *i915)
 
 		GEM_BUG_ON(uabi_class >=
 			   ARRAY_SIZE(i915->engine_uabi_class_count));
+
+		/* Fix up the mapping to match default execbuf::user_map[] */
+		add_legacy_ring(&ring, engine);
+
+		/*
+		 * Do not create the command streamer for CCS slices beyond the
+		 * first. All the workload submitted to the first engine will be
+		 * shared among all the slices.
+		 */
+		if (IS_DG2(i915) && uabi_class == I915_ENGINE_CLASS_COMPUTE) {
+			uabi_ccs_instance++;
+
+			if (uabi_ccs_instance > 1)
+				continue;
+		}
+
 		i915->engine_uabi_class_count[uabi_class]++;
 
 		rb_link_node(&engine->uabi_node, prev, p);
@@ -255,9 +272,6 @@ void intel_engines_driver_register(struct drm_i915_private *i915)
 						    engine->uabi_class,
 						    engine->uabi_instance) != engine);
 
-		/* Fix up the mapping to match default execbuf::user_map[] */
-		add_legacy_ring(&ring, engine);
-
 		prev = &engine->uabi_node;
 		p = &prev->rb_right;
 	}
Signature · 1 line
2.45.2
author
#5 lore raw

RFC PATCH v2 5/11 drm/i915/gt: Remove cslices mask value from the CCS structure

In reply to Andi Shyti

Following the decision to manage CCS engine creation within UABI engines, the "cslices" variable in the "ccs" structure in the "gt" is no longer needed. Remove it is now redundant.

---
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 2 +-
 drivers/gpu/drm/i915/gt/intel_gt_types.h    | 5 -----
 2 files changed, 1 insertion(+), 6 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +1 -1
index 6afd44ffc358..2b6d4ee7445d 100644
@@ -9,7 +9,7 @@
 
 void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode)
 {
-	unsigned long cslices_mask = gt->ccs.cslices;
+	unsigned long cslices_mask = CCS_MASK(gt);
 	u32 mode_val = 0;
 	u32 m = mode;
 	int ccs_id;
drivers/gpu/drm/i915/gt/intel_gt_types.h +0 -5
index 8df8fac066c0..a833b395237b 100644
@@ -218,11 +218,6 @@ struct intel_gt {
 	 * i.e. how the CCS streams are distributed amongs the slices.
 	 */
 	struct {
-		/*
-		 * Mask of the non fused CCS slices
-		 * to be used for the load balancing
-		 */
-		intel_engine_mask_t cslices;
 		struct mutex mutex;
 		u32 mode_reg_val;
 	} ccs;
Signature · 1 line
2.45.2
author
#6 lore raw

RFC PATCH v2 6/11 drm/i915/gt: Expose the number of total CCS slices

In reply to Andi Shyti

Implement a sysfs interface to show the number of available CCS slices. The displayed number does not take into account the CCS balancing mode.

---
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 24 +++++++++++++++++++++
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h |  1 +
 drivers/gpu/drm/i915/gt/intel_gt_sysfs.c    |  2 ++
 3 files changed, 27 insertions(+)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +24 -0
index 2b6d4ee7445d..49493928f714 100644
@@ -5,7 +5,9 @@
 
 #include "i915_drv.h"
 #include "intel_gt_ccs_mode.h"
+#include "intel_gt_print.h"
 #include "intel_gt_regs.h"
+#include "intel_gt_sysfs.h"
 
 void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode)
 {
@@ -90,3 +92,25 @@ void intel_gt_ccs_mode_init(struct intel_gt *gt)
 {
 	mutex_init(&gt->ccs.mutex);
 }
+
+static ssize_t num_cslices_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buff)
+{
+	struct intel_gt *gt = kobj_to_gt(&dev->kobj);
+	u32 num_slices;
+
+	num_slices = hweight32(CCS_MASK(gt));
+
+	return sysfs_emit(buff, "%u\n", num_slices);
+}
+static DEVICE_ATTR_RO(num_cslices);
+
+void intel_gt_sysfs_ccs_init(struct intel_gt *gt)
+{
+	int err;
+
+	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");
+}
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h +1 -0
index 0e1c43ea1d54..c60bfdb54e37 100644
@@ -9,6 +9,7 @@
 #include "intel_gt.h"
 
 void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode);
+void intel_gt_sysfs_ccs_init(struct intel_gt *gt);
 void intel_gt_ccs_mode_init(struct intel_gt *gt);
 
 #endif /* __INTEL_GT_CCS_MODE_H__ */
drivers/gpu/drm/i915/gt/intel_gt_sysfs.c +2 -0
index 33cba406b569..895eedc402ae 100644
@@ -12,6 +12,7 @@
 #include "i915_drv.h"
 #include "i915_sysfs.h"
 #include "intel_gt.h"
+#include "intel_gt_ccs_mode.h"
 #include "intel_gt_print.h"
 #include "intel_gt_sysfs.h"
 #include "intel_gt_sysfs_pm.h"
@@ -101,6 +102,7 @@ void intel_gt_sysfs_register(struct intel_gt *gt)
 		goto exit_fail;
 
 	intel_gt_sysfs_pm_init(gt, &gt->sysfs_gt);
+	intel_gt_sysfs_ccs_init(gt);
 
 	return;
 
Signature · 1 line
2.45.2
author
#7 lore raw

RFC PATCH v2 7/11 drm/i915/gt: Store engine-related sysfs kobjects

In reply to Andi Shyti

Upcoming commits will need to access engine-related kobjects to enable the creation and destruction of sysfs interfaces at runtime.

For this, store the "engine" directory (i915->sysfs_engine), the engine files (gt->kobj), and the default data (gt->kobj_defaults).

---
 drivers/gpu/drm/i915/gt/intel_engine_types.h | 3 +++
 drivers/gpu/drm/i915/gt/sysfs_engines.c      | 6 ++++++
 drivers/gpu/drm/i915/i915_drv.h              | 1 +
 3 files changed, 10 insertions(+)
drivers/gpu/drm/i915/gt/intel_engine_types.h +3 -0
index ba55c059063d..a0f2f5c08388 100644
@@ -388,6 +388,9 @@ struct intel_engine_cs {
 	u32 context_size;
 	u32 mmio_base;
 
+	struct kobject *kobj;
+	struct kobject *kobj_defaults;
+
 	struct intel_engine_tlb_inv tlb_inv;
 
 	/*
drivers/gpu/drm/i915/gt/sysfs_engines.c +6 -0
index 021f51d9b456..d0bb2aa561ed 100644
@@ -479,6 +479,8 @@ static void add_defaults(struct kobj_engine *parent)
 	if (intel_engine_has_preempt_reset(ke->engine) &&
 	    sysfs_create_file(&ke->base, &preempt_timeout_def.attr))
 		return;
+
+	parent->engine->kobj_defaults = &ke->base;
 }
 
 void intel_engines_add_sysfs(struct drm_i915_private *i915)
@@ -506,6 +508,8 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915)
 	if (!dir)
 		return;
 
+	i915->sysfs_engine = dir;
+
 	for_each_uabi_engine(engine, i915) {
 		struct kobject *kobj;
 
@@ -526,6 +530,8 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915)
 
 		add_defaults(container_of(kobj, struct kobj_engine, base));
 
+		engine->kobj = kobj;
+
 		if (0) {
 err_object:
 			kobject_put(kobj);
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 94f7f6cc444c..3a8a757f5bd5 100644
@@ -320,6 +320,7 @@ struct drm_i915_private {
 	struct intel_gt *gt[I915_MAX_GT];
 
 	struct kobject *sysfs_gt;
+	struct kobject *sysfs_engine;
 
 	/* Quick lookup of media GT (current platforms only have one) */
 	struct intel_gt *media_gt;
Signature · 1 line
2.45.2
author
#8 lore raw

RFC PATCH v2 8/11 drm/i915/gt: Store active CCS mask

In reply to Andi Shyti

To support upcoming patches, we need to store the current mask for active CCS engines.

Active engines refer to those exposed to userspace via the UABI engine list.

---
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 20 ++++++++++++++++++++
 drivers/gpu/drm/i915/gt/intel_gt_types.h    |  1 +
 2 files changed, 21 insertions(+)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +20 -0
index 49493928f714..01ce719cf475 100644
@@ -9,6 +9,23 @@
 #include "intel_gt_regs.h"
 #include "intel_gt_sysfs.h"
 
+static void update_ccs_mask(struct intel_gt *gt, u32 ccs_mode)
+{
+	unsigned long cslices_mask = CCS_MASK(gt);
+	int i;
+
+	/* Mask off all the CCS engines */
+	gt->ccs.ccs_mask = 0;
+
+	for_each_set_bit(i, &cslices_mask, I915_MAX_CCS) {
+		gt->ccs.ccs_mask |= BIT(i);
+
+		ccs_mode--;
+		if (!ccs_mode)
+			break;
+	}
+}
+
 void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode)
 {
 	unsigned long cslices_mask = CCS_MASK(gt);
@@ -91,6 +108,9 @@ void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode)
 void intel_gt_ccs_mode_init(struct intel_gt *gt)
 {
 	mutex_init(&gt->ccs.mutex);
+
+	/* Set CCS balance mode 1 in the ccs_mask */
+	update_ccs_mask(gt, 1);
 }
 
 static ssize_t num_cslices_show(struct device *dev,
drivers/gpu/drm/i915/gt/intel_gt_types.h +1 -0
index a833b395237b..235b4b81eecd 100644
@@ -220,6 +220,7 @@ struct intel_gt {
 	struct {
 		struct mutex mutex;
 		u32 mode_reg_val;
+		intel_engine_mask_t ccs_mask;
 	} ccs;
 
 	/*
Signature · 1 line
2.45.2
author
#9 lore raw

RFC PATCH v2 9/11 drm/i915/gt: Isolate single sysfs engine file creation

In reply to Andi Shyti

In preparation for upcoming patches, we need the ability to create and remove individual sysfs files. To facilitate this, extract from the intel_engines_add_sysfs() function the creation of individual files.

---
 drivers/gpu/drm/i915/gt/sysfs_engines.c | 75 ++++++++++++++++---------
 drivers/gpu/drm/i915/gt/sysfs_engines.h |  2 +
 2 files changed, 49 insertions(+), 28 deletions(-)
drivers/gpu/drm/i915/gt/sysfs_engines.c +47 -28
index d0bb2aa561ed..3356fadce327 100644
@@ -9,6 +9,7 @@
 #include "i915_drv.h"
 #include "intel_engine.h"
 #include "intel_engine_heartbeat.h"
+#include "intel_gt_print.h"
 #include "sysfs_engines.h"
 
 struct kobj_engine {
@@ -483,7 +484,7 @@ static void add_defaults(struct kobj_engine *parent)
 	parent->engine->kobj_defaults = &ke->base;
 }
 
-void intel_engines_add_sysfs(struct drm_i915_private *i915)
+int intel_engine_add_single_sysfs(struct intel_engine_cs *engine)
 {
 	static const struct attribute * const files[] = {
 		&name_attr.attr,
@@ -499,46 +500,64 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915)
 #endif
 		NULL
 	};
+	struct kobject *dir = engine->i915->sysfs_engine;
+	struct kobject *kobj = engine->kobj;
+	int err;
 
-	struct device *kdev = i915->drm.primary->kdev;
-	struct intel_engine_cs *engine;
-	struct kobject *dir;
-
-	dir = kobject_create_and_add("engine", &kdev->kobj);
-	if (!dir)
-		return;
-
-	i915->sysfs_engine = dir;
-
-	for_each_uabi_engine(engine, i915) {
-		struct kobject *kobj;
-
+	if (!kobj) {
 		kobj = kobj_engine(dir, engine);
 		if (!kobj)
 			goto err_engine;
+	}
 
-		if (sysfs_create_files(kobj, files))
+	err = sysfs_create_files(kobj, files);
+	if (err)
+		goto err_object;
+
+	if (intel_engine_has_timeslices(engine)) {
+		err = sysfs_create_file(kobj, &timeslice_duration_attr.attr);
+		if (err)
 			goto err_object;
+	}
 
-		if (intel_engine_has_timeslices(engine) &&
-		    sysfs_create_file(kobj, &timeslice_duration_attr.attr))
-			goto err_engine;
+	if (intel_engine_has_preempt_reset(engine)) {
+		err = sysfs_create_file(kobj, &preempt_timeout_attr.attr);
+		if (err)
+			goto err_object;
+	}
 
-		if (intel_engine_has_preempt_reset(engine) &&
-		    sysfs_create_file(kobj, &preempt_timeout_attr.attr))
-			goto err_engine;
+	add_defaults(container_of(kobj, struct kobj_engine, base));
 
-		add_defaults(container_of(kobj, struct kobj_engine, base));
+	engine->kobj = kobj;
 
-		engine->kobj = kobj;
+	return 0;
 
-		if (0) {
 err_object:
-			kobject_put(kobj);
+	kobject_put(kobj);
 err_engine:
-			dev_err(kdev, "Failed to add sysfs engine '%s'\n",
-				engine->name);
+	gt_err(engine->gt, "Failed to add sysfs engine '%s'\n",
+		engine->name);
+
+	return err;
+}
+
+void intel_engines_add_sysfs(struct drm_i915_private *i915)
+{
+	struct device *kdev = i915->drm.primary->kdev;
+	struct intel_engine_cs *engine;
+	struct kobject *dir;
+
+	dir = kobject_create_and_add("engine", &kdev->kobj);
+	if (!dir)
+		return;
+
+	i915->sysfs_engine = dir;
+
+	for_each_uabi_engine(engine, i915) {
+		int err;
+
+		err = intel_engine_add_single_sysfs(engine);
+		if (err)
 			break;
-		}
 	}
 }
drivers/gpu/drm/i915/gt/sysfs_engines.h +2 -0
index 9546fffe03a7..2e3ec2df14a9 100644
@@ -7,7 +7,9 @@
 #define INTEL_ENGINE_SYSFS_H
 
 struct drm_i915_private;
+struct intel_engine_cs;
 
 void intel_engines_add_sysfs(struct drm_i915_private *i915);
+int intel_engine_add_single_sysfs(struct intel_engine_cs *engine);
 
 #endif /* INTEL_ENGINE_SYSFS_H */
Signature · 1 line
2.45.2
#10 lore raw

Re: [RFC PATCH v2 09/11] drm/i915/gt: Isolate single sysfs engine file creation

kernel test robot noticed the following build warnings:

Hi Andi,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-intel/for-linux-next-fixes drm-tip/drm-tip drm/drm-next drm-exynos/exynos-drm-next drm-misc/drm-misc-next linus/master v6.11-rc3 next-20240816] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andi-Shyti/drm-i915-gt-Move-the-CCS-mode-variable-to-a-global-position/20240818-050310
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
patch link:    https://lore.kernel.org/r/20240817210026.310645-10-andi.shyti%40linux.intel.com
patch subject: [RFC PATCH v2 09/11] drm/i915/gt: Isolate single sysfs engine file creation
config: i386-buildonly-randconfig-004-20240818 (https://download.01.org/0day-ci/archive/20240818/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240818/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/gt/sysfs_engines.c:509:7: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     509 |                 if (!kobj)
         |                     ^~~~~
   drivers/gpu/drm/i915/gt/sysfs_engines.c:541:9: note: uninitialized use occurs here
     541 |         return err;
         |                ^~~
   drivers/gpu/drm/i915/gt/sysfs_engines.c:509:3: note: remove the 'if' if its condition is always false
     509 |                 if (!kobj)
         |                 ^~~~~~~~~~
     510 |                         goto err_engine;
         |                         ~~~~~~~~~~~~~~~
   drivers/gpu/drm/i915/gt/sysfs_engines.c:505:9: note: initialize the variable 'err' to silence this warning
     505 |         int err;
         |                ^
         |                 = 0

1 warning generated.

vim +509 drivers/gpu/drm/i915/gt/sysfs_engines.c

7a0ba6b43bc0b00 Chris Wilson 2020-05-14  486  
54b2887ff521b0c Andi Shyti   2024-08-17  487  int intel_engine_add_single_sysfs(struct intel_engine_cs *engine)
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  488  {
d2a9692ad4295e2 Jani Nikula  2023-03-09  489  	static const struct attribute * const files[] = {
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  490  		&name_attr.attr,
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  491  		&class_attr.attr,
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  492  		&inst_attr.attr,
6e57cc39420c1d1 Chris Wilson 2020-02-28  493  		&mmio_attr.attr,
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  494  		&caps_attr.attr,
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  495  		&all_caps_attr.attr,
062444bbc6859db Chris Wilson 2020-02-28  496  		&max_spin_attr.attr,
72338a1f5ef8a48 Chris Wilson 2020-02-28  497  		&stop_timeout_attr.attr,
9a40bddd47ca4aa Chris Wilson 2020-02-28  498  #if CONFIG_DRM_I915_HEARTBEAT_INTERVAL
9a40bddd47ca4aa Chris Wilson 2020-02-28  499  		&heartbeat_interval_attr.attr,
9a40bddd47ca4aa Chris Wilson 2020-02-28  500  #endif
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  501  		NULL
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  502  	};
54b2887ff521b0c Andi Shyti   2024-08-17  503  	struct kobject *dir = engine->i915->sysfs_engine;
54b2887ff521b0c Andi Shyti   2024-08-17  504  	struct kobject *kobj = engine->kobj;
54b2887ff521b0c Andi Shyti   2024-08-17  505  	int err;
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  506  
54b2887ff521b0c Andi Shyti   2024-08-17  507  	if (!kobj) {
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  508  		kobj = kobj_engine(dir, engine);
4ec76dbeb62b5f8 Chris Wilson 2020-02-28 @509  		if (!kobj)
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  510  			goto err_engine;
54b2887ff521b0c Andi Shyti   2024-08-17  511  	}
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  512  
54b2887ff521b0c Andi Shyti   2024-08-17  513  	err = sysfs_create_files(kobj, files);
54b2887ff521b0c Andi Shyti   2024-08-17  514  	if (err)
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  515  		goto err_object;
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  516  
54b2887ff521b0c Andi Shyti   2024-08-17  517  	if (intel_engine_has_timeslices(engine)) {
54b2887ff521b0c Andi Shyti   2024-08-17  518  		err = sysfs_create_file(kobj, &timeslice_duration_attr.attr);
54b2887ff521b0c Andi Shyti   2024-08-17  519  		if (err)
54b2887ff521b0c Andi Shyti   2024-08-17  520  			goto err_object;
54b2887ff521b0c Andi Shyti   2024-08-17  521  	}
1a2695a7465971f Chris Wilson 2020-02-28  522  
54b2887ff521b0c Andi Shyti   2024-08-17  523  	if (intel_engine_has_preempt_reset(engine)) {
54b2887ff521b0c Andi Shyti   2024-08-17  524  		err = sysfs_create_file(kobj, &preempt_timeout_attr.attr);
54b2887ff521b0c Andi Shyti   2024-08-17  525  		if (err)
54b2887ff521b0c Andi Shyti   2024-08-17  526  			goto err_object;
54b2887ff521b0c Andi Shyti   2024-08-17  527  	}
db3d8338bacbfc7 Chris Wilson 2020-02-28  528  
7a0ba6b43bc0b00 Chris Wilson 2020-05-14  529  	add_defaults(container_of(kobj, struct kobj_engine, base));
7a0ba6b43bc0b00 Chris Wilson 2020-05-14  530  
99884adbcf06963 Andi Shyti   2024-08-17  531  	engine->kobj = kobj;
99884adbcf06963 Andi Shyti   2024-08-17  532  
54b2887ff521b0c Andi Shyti   2024-08-17  533  	return 0;
54b2887ff521b0c Andi Shyti   2024-08-17  534  
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  535  err_object:
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  536  	kobject_put(kobj);
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  537  err_engine:
54b2887ff521b0c Andi Shyti   2024-08-17  538  	gt_err(engine->gt, "Failed to add sysfs engine '%s'\n",
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  539  		engine->name);
54b2887ff521b0c Andi Shyti   2024-08-17  540  
54b2887ff521b0c Andi Shyti   2024-08-17  541  	return err;
4ec76dbeb62b5f8 Chris Wilson 2020-02-28  542  }
54b2887ff521b0c Andi Shyti   2024-08-17  543  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#11 lore raw

RFC PATCH v2 10/11 drm/i915/gt: Implement creation and removal routines for CCS engines

In reply to Andi Shyti

In preparation for upcoming patches, we need routines to dynamically create and destroy CCS engines based on the CCS mode that the user wants to set.

The process begins by calculating the engine mask for the engines that need to be added or removed. We then update the UABI list of exposed engines and create or destroy the corresponding sysfs interfaces accordingly.

These functions are not yet in use, so no functional changes are intended at this stage.

---
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 80 +++++++++++++++++++++
 1 file changed, 80 insertions(+)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +80 -0
index 01ce719cf475..b1c3c9d9bb4f 100644
@@ -8,6 +8,7 @@
 #include "intel_gt_print.h"
 #include "intel_gt_regs.h"
 #include "intel_gt_sysfs.h"
+#include "sysfs_engines.h"
 
 static void update_ccs_mask(struct intel_gt *gt, u32 ccs_mode)
 {
@@ -113,6 +114,85 @@ void intel_gt_ccs_mode_init(struct intel_gt *gt)
 	update_ccs_mask(gt, 1);
 }
 
+static void add_uabi_ccs_engines(struct intel_gt *gt, u32 ccs_mode)
+{
+	struct drm_i915_private *i915 = gt->i915;
+	intel_engine_mask_t new_ccs_mask, tmp;
+	struct intel_engine_cs *engine;
+	struct rb_node **p, *prev;
+
+	/* Store the current ccs mask */
+	new_ccs_mask = gt->ccs.ccs_mask;
+	update_ccs_mask(gt, ccs_mode);
+
+	/*
+	 * Store only the mask of the CCS engines that need to be added by
+	 * removing from the new mask the engines that are already active
+	 */
+	new_ccs_mask = gt->ccs.ccs_mask & ~new_ccs_mask;
+	new_ccs_mask <<= CCS0;
+
+	/*
+	 * UABI are stored only on the right branch of the rb tree, making it
+	 * de facto a double linked list. Get to the bottom of the list and
+	 * insert there the new engines.
+	 */
+	prev = NULL;
+	p = &i915->uabi_engines.rb_node;
+	for_each_uabi_engine(engine, i915) {
+		prev = &engine->uabi_node;
+		p = &prev->rb_right;
+	}
+
+	for_each_engine_masked(engine, gt, new_ccs_mask, tmp) {
+		int err;
+
+		i915->engine_uabi_class_count[I915_ENGINE_CLASS_COMPUTE]++;
+
+		rb_link_node(&engine->uabi_node, prev, p);
+		rb_insert_color(&engine->uabi_node, &i915->uabi_engines);
+
+		rb_link_node(&engine->uabi_node, prev, p);
+		rb_insert_color(&engine->uabi_node, &i915->uabi_engines);
+
+		prev = &engine->uabi_node;
+		p = &prev->rb_right;
+
+		err = intel_engine_add_single_sysfs(engine);
+		if (err)
+			gt_warn(gt,
+				"Unable to create sysfs entries for %s engine",
+				engine->name);
+	}
+}
+
+static void remove_uabi_ccs_engines(struct intel_gt *gt, u8 ccs_mode)
+{
+	struct drm_i915_private *i915 = gt->i915;
+	intel_engine_mask_t new_ccs_mask, tmp;
+	struct intel_engine_cs *engine;
+
+	/* Store the current ccs mask */
+	new_ccs_mask = gt->ccs.ccs_mask;
+	update_ccs_mask(gt, ccs_mode);
+
+	/*
+	 * Store only the mask of the CCS engines that need to be removed by
+	 * unmasking them from the new mask the engines that are already active
+	 */
+	new_ccs_mask = new_ccs_mask & ~gt->ccs.ccs_mask;
+	new_ccs_mask <<= CCS0;
+
+	for_each_engine_masked(engine, gt, new_ccs_mask, tmp) {
+		i915->engine_uabi_class_count[I915_ENGINE_CLASS_COMPUTE]--;
+
+		rb_erase(&engine->uabi_node, &i915->uabi_engines);
+		/* Remove sysfs entries */
+		kobject_put(engine->kobj_defaults);
+		kobject_put(engine->kobj);
+	}
+}
+
 static ssize_t num_cslices_show(struct device *dev,
 				struct device_attribute *attr,
 				char *buff)
Signature · 1 line
2.45.2
author
#12 lore raw

RFC PATCH v2 11/11 drm/i915/gt: Allow the user to change the CCS mode through sysfs

In reply to Andi Shyti

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.

---
 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 74 +++++++++++++++++++++
 1 file changed, 74 insertions(+)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +74 -0
index b1c3c9d9bb4f..30393009bc43 100644
@@ -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");
 }
Signature · 1 line
2.45.2
#13 lore raw

✗ Fi.CI.CHECKPATCH: warning for CCS static load balance (rev2)

In reply to Andi Shyti
== Series Details ==

== Series Details ==

Series: CCS static load balance (rev2)
URL : https://patchwork.freedesktop.org/series/136381/
State : warning

== Summary ==

Error: dim checkpatch failed
84e876cb3a32 drm/i915/gt: Move the CCS mode variable to a global position -:113: CHECK:UNCOMMENTED_DEFINITION: struct mutex definition without comment #113: FILE: drivers/gpu/drm/i915/gt/intel_gt_types.h:226:
+ struct mutex mutex;

total: 0 errors, 0 warnings, 1 checks, 95 lines checked
3b0bf8998852 drm/i915/gt: Allow the creation of multi-mode CCS masks
0076ce951e97 drm/i915/gt: Refactor uabi engine class/instance list creation
-:54: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #54: FILE: drivers/gpu/drm/i915/gt/intel_engine_user.c:233:
+ GEM_BUG_ON(uabi_class >= ARRAY_SIZE(class_instance));

-:70: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #70: FILE: drivers/gpu/drm/i915/gt/intel_engine_user.c:247:
+ GEM_BUG_ON(uabi_class >=

total: 0 errors, 2 warnings, 0 checks, 56 lines checked 96ff57617c4a drm/i915/gt: Manage CCS engine creation within UABI exposure 4743af1f0f34 drm/i915/gt: Remove cslices mask value from the CCS structure 12d784cbbf89 drm/i915/gt: Expose the number of total CCS slices 09c8acafca2a drm/i915/gt: Store engine-related sysfs kobjects e2ea1fbf7f3b drm/i915/gt: Store active CCS mask
9d3afeca2efa drm/i915/gt: Isolate single sysfs engine file creation -:100: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #100: FILE: drivers/gpu/drm/i915/gt/sysfs_engines.c:539:
+ gt_err(engine->gt, "Failed to add sysfs engine '%s'\n",
+ engine->name);

total: 0 errors, 0 warnings, 1 checks, 115 lines checked 54a64c3795dd drm/i915/gt: Implement creation and removal routines for CCS engines be957e86b979 drm/i915/gt: Allow the user to change the CCS mode through sysfs -:71: CHECK:UNNECESSARY_PARENTHESES: Unnecessary parentheses around '!val' #71: FILE: drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c:239:
+ if ((!val) || (val > num_cslices) || (num_cslices % val))

-:71: CHECK:UNNECESSARY_PARENTHESES: Unnecessary parentheses around 'val > num_cslices' #71: FILE: drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c:239:
+ if ((!val) || (val > num_cslices) || (num_cslices % val))

total: 0 errors, 0 warnings, 2 checks, 90 lines checked

#15 lore raw

✗ Fi.CI.BAT: failure for CCS static load balance (rev2)

In reply to Andi Shyti
== Series Details ==

== Series Details ==

Series: CCS static load balance (rev2)
URL : https://patchwork.freedesktop.org/series/136381/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_15252 -> Patchwork_136381v2
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_136381v2 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes
introduced in Patchwork_136381v2, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/index.html

Participating hosts (40 -> 41)
------------------------------

Additional (2): fi-tgl-1115g4 fi-cfl-8109u
Missing (1): fi-kbl-8809g

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_136381v2:

### IGT changes ###

#### Possible regressions ####

* igt@i915_selftest@live@hangcheck:
- bat-atsm-1: [PASS][1] -> [DMESG-FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/bat-atsm-1/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/bat-atsm-1/igt@i915_selftest@[email protected]
- bat-dg2-9: [PASS][3] -> [DMESG-FAIL][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/bat-dg2-9/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/bat-dg2-9/igt@i915_selftest@[email protected]
- bat-dg2-8: [PASS][5] -> [DMESG-FAIL][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/bat-dg2-8/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/bat-dg2-8/igt@i915_selftest@[email protected]
- bat-dg2-14: [PASS][7] -> [DMESG-FAIL][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/bat-dg2-14/igt@i915_selftest@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/bat-dg2-14/igt@i915_selftest@[email protected]

Known issues
------------

Here are the changes found in Patchwork_136381v2 that come from known issues:

### CI changes ###

#### Possible fixes ####

* boot:
- {bat-arlh-3}: [FAIL][9] -> [PASS][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/bat-arlh-3/boot.html
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/bat-arlh-3/boot.html

### IGT changes ###

#### Issues hit ####

* igt@debugfs_test@basic-hwmon:
- fi-tgl-1115g4: NOTRUN -> [SKIP][11] ([i915#9318])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

* igt@gem_huc_copy@huc-copy:
- fi-cfl-8109u: NOTRUN -> [SKIP][12] ([i915#2190])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-cfl-8109u/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [SKIP][13] ([i915#2190])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

* igt@gem_lmem_swapping@parallel-random-engines:
- fi-tgl-1115g4: NOTRUN -> [SKIP][14] ([i915#4613]) +3 other tests skip
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

* igt@gem_lmem_swapping@verify-random:
- fi-cfl-8109u: NOTRUN -> [SKIP][15] ([i915#4613]) +3 other tests skip
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-cfl-8109u/igt@[email protected]

* igt@i915_pm_rpm@module-reload:
- fi-kbl-7567u: [PASS][16] -> [DMESG-WARN][17] ([i915#11888] / [i915#1982])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/fi-kbl-7567u/igt@[email protected]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-kbl-7567u/igt@[email protected]

* igt@i915_selftest@live@gt_heartbeat:
- fi-kbl-7567u: [PASS][18] -> [DMESG-WARN][19] ([i915#11621]) +31 other tests dmesg-warn
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/fi-kbl-7567u/igt@i915_selftest@live@gt_heartbeat.html
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-kbl-7567u/igt@i915_selftest@live@gt_heartbeat.html

* igt@i915_selftest@live@hangcheck:
- bat-arls-2: [PASS][20] -> [DMESG-WARN][21] ([i915#11349] / [i915#11378])
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/bat-arls-2/igt@i915_selftest@[email protected]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/bat-arls-2/igt@i915_selftest@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
- fi-tgl-1115g4: NOTRUN -> [SKIP][22] ([i915#4103]) +1 other test skip
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

* igt@kms_dsc@dsc-basic:
- fi-tgl-1115g4: NOTRUN -> [SKIP][23] ([i915#3555] / [i915#3840])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

* igt@kms_force_connector_basic@force-load-detect:
- fi-tgl-1115g4: NOTRUN -> [SKIP][24]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

* igt@kms_pm_backlight@basic-brightness:
- fi-cfl-8109u: NOTRUN -> [SKIP][25] +11 other tests skip
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-cfl-8109u/igt@[email protected]
- fi-tgl-1115g4: NOTRUN -> [SKIP][26] ([i915#9812])
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

* igt@kms_pm_rpm@basic-pci-d3-state:
- fi-kbl-7567u: [PASS][27] -> [DMESG-WARN][28] ([i915#11888]) +38 other tests dmesg-warn
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_15252/fi-kbl-7567u/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-kbl-7567u/igt@[email protected]

* igt@kms_psr@psr-sprite-plane-onoff:
- fi-tgl-1115g4: NOTRUN -> [SKIP][29] ([i915#9732]) +3 other tests skip
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

* igt@kms_setmode@basic-clone-single-crtc:
- fi-tgl-1115g4: NOTRUN -> [SKIP][30] ([i915#3555])
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/fi-tgl-1115g4/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[i915#10196]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/10196
[i915#11343]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11343
[i915#11346]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11346
[i915#11349]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11349
[i915#11378]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11378
[i915#11621]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11621
[i915#11666]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11666
[i915#11671]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11671
[i915#11681]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11681
[i915#11723]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11723
[i915#11724]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11724
[i915#11725]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11725
[i915#11726]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11726
[i915#11888]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11888
[i915#1982]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/1982
[i915#2190]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/2190
[i915#3555]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3555
[i915#3840]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3840
[i915#4103]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4103
[i915#4613]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4613
[i915#8809]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/8809
[i915#9318]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9318
[i915#9732]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9732
[i915#9812]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9812
[i915#9886]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9886

Build changes
-------------

* Linux: CI_DRM_15252 -> Patchwork_136381v2

CI-20190529: 20190529
CI_DRM_15252: 867f8f978dc40659fb770105a4e075efc224e121 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7975: 7975
Patchwork_136381v2: 867f8f978dc40659fb770105a4e075efc224e121 @ git://anongit.freedesktop.org/gfx-ci/linux

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_136381v2/index.html