CCS static load balance
Subsystems (4)
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 7, no functional changes occur except for the addition of the num_cslices interface. The significant changes happen in patch 8, which is the core part of the CCS mode setting, utilizing the groundwork laid in the earlier patches.
The i915 driver is not designed to support dynamic removal and addition of engines, so this process requires careful attention as it can fail in various ways.
One aspect still missing is client management. We need to prevent users from connecting to i915 until all engines are recreated. There may be a need for a global protection mechanism, or perhaps I am overlooking something. I welcome any suggestions on this matter.
I would greatly appreciate further input from all reviewers who have already assisted with the previous work. Additionally, I would be grateful if Chris Wilson could join the discussion and provide his insights, as we have previously had valuable exchanges on this topic.
Although this series is not yet fully ready, I am submitting it to gather feedback early on. My goal is to have this series included in version 6.12.
IGT tests have also been developed, but I haven't sent them yet.
Thanks,
Andi
Andi Shyti (9):
drm/i915/gt: Refactor uabi engine class/instance list creation drm/i915/gt: Rename "cslises" with "cslice_mask" drm/i915/gt: Move CCS mode mask creation to intel_ccs_mode.c drm/i915/gt: Expose the number of total CCS slices drm/i915/gt: Move the CCS mode variable to a global position drm/i915/gt: Add sysfs cleanup function for engines drm/i915/gt: Allow the creation of multi-mode CCS masks drm/i915/gt: Allow the user to change the CCS mode through sysfs drm/i915/gt: Document CCS mode load balancing
Documentation/gpu/i915.rst | 3 + drivers/gpu/drm/i915/gt/intel_engine_cs.c | 52 +-- drivers/gpu/drm/i915/gt/intel_engine_types.h | 3 + drivers/gpu/drm/i915/gt/intel_engine_user.c | 29 +- drivers/gpu/drm/i915/gt/intel_gt.c | 3 + drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 319 +++++++++++++++++-- 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 | 14 +- drivers/gpu/drm/i915/gt/intel_workarounds.c | 7 +- drivers/gpu/drm/i915/gt/sysfs_engines.c | 18 ++ drivers/gpu/drm/i915/gt/sysfs_engines.h | 1 + drivers/gpu/drm/i915/i915_drv.h | 1 + 13 files changed, 372 insertions(+), 86 deletions(-)
Signature · 1 line
2.45.2
RFC PATCH 1/9 drm/i915/gt: Refactor uabi engine class/instance list creation
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
@@ -203,7 +203,7 @@ static void engine_rename(struct intel_engine_cs *engine, const char *name, u16void 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
RFC PATCH 2/9 drm/i915/gt: Rename "cslises" with "cslice_mask"
In reply to Andi Shytidrm/i915/gt: Rename "cslises" variable to clarify its purpose
The "cslises" variable stores the mask of the CCS engines after calculating the fused ones and before setting the CCS mode.
Since it represents a mask and not the number of CCS slices, rename it to reflect its actual purpose to avoid confusion.
No functional changes intended.
--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 2 +- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 2 +- drivers/gpu/drm/i915/gt/intel_gt_types.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1 -1
@@ -889,7 +889,7 @@ static intel_engine_mask_t init_engine_mask(struct intel_gt *gt)* Store the number of active cslices before * changing the CCS engine configuration */ - gt->ccs.cslices =CCS_MASK (gt); + gt->ccs.cslice_mask =CCS_MASK (gt);/* Mask off all the CCS engine */ info->engine_mask &= ~GENMASK (CCS3 ,CCS0 );
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +1 -1
@@ -19,7 +19,7 @@ unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt)/* Build the value for the fixed CCS load balancing */ for (cslice =0 ; cslice <I915_MAX_CCS ; cslice++) { -if (gt->ccs.cslices &BIT (cslice)) +if (gt->ccs.cslice_mask &BIT (cslice))/* * If available, assign the cslice * to the first available engine...
drivers/gpu/drm/i915/gt/intel_gt_types.h +1 -1
@@ -212,7 +212,7 @@ struct intel_gt {* Mask of the non fused CCS slices * to be used for the load balancing */ -intel_engine_mask_t cslices; +intel_engine_mask_t cslice_mask; } ccs;/*
Signature · 1 line
2.45.2
RFC PATCH 3/9 drm/i915/gt: Move CCS mode mask creation to intel_ccs_mode.c
In reply to Andi ShytiIn anticipation of upcoming patches, it is more convenient to move the CCS mode mask creation to the intel_ccs_mode.c file, which serves as a placeholder for all CCS engine settings.
No functional changes intended.
--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 50 --------------------- drivers/gpu/drm/i915/gt/intel_gt.c | 3 ++ drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 46 +++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h | 1 + 4 files changed, 50 insertions(+), 50 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +0 -50
@@ -812,32 +812,6 @@ static void engine_mask_apply_media_fuses(struct intel_gt *gt)GEM_BUG_ON (vebox_mask !=VEBOX_MASK (gt)); } -static void engine_mask_apply_compute_fuses (struct intel_gt *gt) -{ -struct drm_i915_private *i915 = gt->i915; -struct intel_gt_info *info = >->info; -int ss_per_ccs = info->sseu.max_subslices /I915_MAX_CCS ; -unsigned long ccs_mask; -unsigned int i; - -if (GRAPHICS_VER (i915) <11 ) -return ; - -if (hweight32 (CCS_MASK (gt)) <=1 ) -return ; - - ccs_mask =intel_slicemask_from_xehp_dssmask (info->sseu.compute_subslice_mask, - ss_per_ccs); -/* -* If all DSS in a quadrant are fused off, the corresponding CCS -* engine is not available for use. -*/ -for_each_clear_bit (i, &ccs_mask,I915_MAX_CCS ) { - info->engine_mask &= ~BIT (_CCS (i)); -gt_dbg (gt,"ccs%u fused off\n" , i); - } -} -/* * Determine which engines are fused off in our particular hardware. * Note that we have a catch-22 situation where we need to be able to access
@@ -855,7 +829,6 @@ static intel_engine_mask_t init_engine_mask(struct intel_gt *gt)GEM_BUG_ON (!info->engine_mask);engine_mask_apply_media_fuses (gt); -engine_mask_apply_compute_fuses (gt);/* * The only use of the GSC CS is to load and communicate with the GSC
@@ -874,29 +847,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.cslice_mask =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_gt.c +3 -0
@@ -17,6 +17,7 @@#include "intel_engine_regs.h" #include "intel_ggtt_gmch.h" #include "intel_gt.h" +#include "intel_gt_ccs_mode.h" #include "intel_gt_buffer_pool.h" #include "intel_gt_clock_utils.h" #include "intel_gt_debugfs.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 +46 -0
54 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h +1 -0
@@ -9,5 +9,6 @@struct intel_gt ;unsigned int 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__ */
Signature · 1 line
2.45.2
RFC PATCH 4/9 drm/i915/gt: Expose the number of total CCS slices
In reply to Andi ShytiImplement 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 | 23 +++++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h | 1 + drivers/gpu/drm/i915/gt/intel_gt_sysfs.c | 2 ++ 3 files changed, 26 insertions(+)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +23 -0
@@ -8,6 +8,7 @@#include "intel_gt_ccs_mode.h" #include "intel_gt_print.h" #include "intel_gt_regs.h" +#include "intel_gt_sysfs.h" void intel_gt_ccs_mode_init (struct intel_gt *gt) {
@@ -83,3 +84,25 @@ unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt)return mode; } + +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 (gt->ccs.cslice_mask); + +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 (>->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
@@ -9,6 +9,7 @@struct intel_gt ;unsigned int intel_gt_apply_ccs_mode (struct intel_gt *gt); +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
@@ -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, >->sysfs_gt); +intel_gt_sysfs_ccs_init (gt);return ;
Signature · 1 line
2.45.2
RFC PATCH 5/9 drm/i915/gt: Move the CCS mode variable to a global position
In reply to Andi ShytiStore 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_ccs_mode.c | 10 +++++++--- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h | 2 +- drivers/gpu/drm/i915/gt/intel_gt_types.h | 12 ++++++++++++ drivers/gpu/drm/i915/gt/intel_workarounds.c | 7 ++++--- 4 files changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +7 -3
@@ -18,6 +18,8 @@ void intel_gt_ccs_mode_init(struct intel_gt *gt)unsigned int i;u8 first_ccs; +mutex_init (>->ccs.mutex); +/* Calculate the slices considering the fused engines */ ss_per_ccs = info->sseu.max_subslices /I915_MAX_CCS ; fused_mask = intel_slicemask_from_xehp_dssmask(info->sseu.compute_subslice_mask,
@@ -55,14 +57,16 @@ void intel_gt_ccs_mode_init(struct intel_gt *gt) info->engine_mask |=BIT (_CCS (first_ccs)); } -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 (>->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++) {
@@ -82,7 +86,7 @@ unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt) XEHP_CCS_MODE_CSLICE_MASK); } -return mode; + gt->ccs.mode_reg_val = mode; } static ssize_t num_cslices_show(struct device *dev,
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h +1 -1
@@ -8,7 +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_sysfs_ccs_init (struct intel_gt *gt);void intel_gt_ccs_mode_init (struct intel_gt *gt);
drivers/gpu/drm/i915/gt/intel_gt_types.h +12 -0
@@ -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 */ +struct mutex mutex;intel_engine_mask_t cslice_mask; +u32 mode_reg_val; } ccs;/*
drivers/gpu/drm/i915/gt/intel_workarounds.c +4 -3
@@ -2713,7 +2713,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 ;
@@ -2730,8 +2729,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 (>->ccs.mutex); +intel_gt_apply_ccs_mode (gt); +wa_masked_en (wal,XEHP_CCS_MODE , gt->ccs.mode_reg_val); +mutex_unlock (>->ccs.mutex); }/*
Signature · 1 line
2.45.2
RFC PATCH 6/9 drm/i915/gt: Add sysfs cleanup function for engines
In reply to Andi ShytiEngines and their properties are exposed in:
/sys/class/drm/cardX/engine/<engine_name>
These files are cleaned up when the driver is removed. However, when the presence of engines starts changing dynamically, we need a function to clean up the existing ones.
Store the engine-related objects (kobj and kobj_defaults) in the 'intel_engine_cs' structure, and store the main directory's object (sysfs_engines) in the 'drm_i915_private' structure.
No functional changes intended at this point, as this function does not have users yet.
--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 2 ++ drivers/gpu/drm/i915/gt/intel_engine_types.h | 3 +++ drivers/gpu/drm/i915/gt/sysfs_engines.c | 18 ++++++++++++++++++ drivers/gpu/drm/i915/gt/sysfs_engines.h | 1 + drivers/gpu/drm/i915/i915_drv.h | 1 + 5 files changed, 25 insertions(+)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +2 -0
@@ -716,6 +716,8 @@ void intel_engines_free(struct intel_gt *gt)kfree (engine); gt->engine[id] =NULL ; } + +memset (gt->engine_class,0 ,sizeof (gt->engine_class)); } static
drivers/gpu/drm/i915/gt/intel_engine_types.h +3 -0
@@ -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 +18 -0
@@ -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);
@@ -536,3 +542,15 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915) } } } + +void intel_engines_remove_sysfs (struct drm_i915_private *i915) +{ +struct intel_engine_cs *engine; + +for_each_uabi_engine (engine, i915) { +kobject_put (engine->kobj_defaults); +kobject_put (engine->kobj); + } + +kobject_put (i915->sysfs_engine); +}
drivers/gpu/drm/i915/gt/sysfs_engines.h +1 -0
@@ -9,5 +9,6 @@struct drm_i915_private ;void intel_engines_add_sysfs (struct drm_i915_private *i915); +void intel_engines_remove_sysfs (struct drm_i915_private *i915);#endif /* INTEL_ENGINE_SYSFS_H */
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -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
RFC PATCH 7/9 drm/i915/gt: Allow the creation of multi-mode CCS masks
In reply to Andi ShytiUntil 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
@@ -4,7 +4,6 @@*/ #include "i915_drv.h" -#include "intel_gt.h" #include "intel_gt_ccs_mode.h" #include "intel_gt_print.h" #include "intel_gt_regs.h"
@@ -57,33 +56,80 @@ void intel_gt_ccs_mode_init(struct intel_gt *gt) info->engine_mask |=BIT (_CCS (first_ccs)); } -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.cslice_mask; +u32 mode_val =0 ; +int ccs_id;int cslice; -u32 mode =0 ; -int first_ccs =__ffs (CCS_MASK (gt)); +u32 m = mode;lockdep_assert_held (>->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.cslice_mask &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
@@ -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_sysfs_ccs_init (struct intel_gt *gt);void intel_gt_ccs_mode_init (struct intel_gt *gt);
drivers/gpu/drm/i915/gt/intel_workarounds.c +1 -1
@@ -2730,7 +2730,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 (>->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 (>->ccs.mutex); }
Signature · 1 line
2.45.2
kernel test robot
build botRe: [RFC PATCH 7/9] drm/i915/gt: Allow the creation of multi-mode CCS masks
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 linus/master v6.10 next-20240723] [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-Refactor-uabi-engine-class-instance-list-creation/20240723-192341 base: git://anongit.freedesktop.org/drm-intel for-linux-next patch link: https://lore.kernel.org/r/20240723112046.123938-8-andi.shyti%40linux.intel.com patch subject: [RFC PATCH 7/9] drm/i915/gt: Allow the creation of multi-mode CCS masks config: i386-randconfig-001-20240724 (https://download.01.org/0day-ci/archive/20240724/[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/20240724/[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/intel_gt_ccs_mode.c:62:6: warning: variable 'mode_val' set but not used [-Wunused-but-set-variable]
62 | u32 mode_val = 0;
| ^1 warning generated.
vim +/mode_val +62 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c
58
59 void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode)
60 {
61 unsigned long cslices_mask = gt->ccs.cslice_mask;
> 62 u32 mode_val = 0;
63 int ccs_id;
64 int cslice;
65 u32 m = mode;
66
67 lockdep_assert_held(>->ccs.mutex);
68
69 if (!IS_DG2(gt->i915))
70 return;
71
72 /*
73 * The mode has two bit dedicated for each engine
74 * that will be used for the CCS balancing algorithm:
75 *
76 * BIT | CCS slice
77 * ------------------
78 * 0 | CCS slice
79 * 1 | 0
80 * ------------------
81 * 2 | CCS slice
82 * 3 | 1
83 * ------------------
84 * 4 | CCS slice
85 * 5 | 2
86 * ------------------
87 * 6 | CCS slice
88 * 7 | 3
89 * ------------------
90 *
91 * When a CCS slice is not available, then we will write 0x7,
92 * oterwise we will write the user engine id which load will
93 * be forwarded to that slice.
94 *
95 * The possible configurations are:
96 *
97 * 1 engine (ccs0):
98 * slice 0, 1, 2, 3: ccs0
99 *
100 * 2 engines (ccs0, ccs1):
101 * slice 0, 2: ccs0
102 * slice 1, 3: ccs1
103 *
104 * 4 engines (ccs0, ccs1, ccs2, ccs3):
105 * slice 0: ccs0
106 * slice 1: ccs1
107 * slice 2: ccs2
108 * slice 3: ccs3 109 */
110 ccs_id = __ffs(cslices_mask);
111
112 for (cslice = 0; cslice < I915_MAX_CCS; cslice++) {
113 if (!(cslices_mask & BIT(cslice))) {
114 /*
115 * If not available, mark the slice as unavailable
116 * and no task will be dispatched here.
117 */
118 mode_val |= XEHP_CCS_MODE_CSLICE(cslice,
119 XEHP_CCS_MODE_CSLICE_MASK);
120 continue;
121 }
122
123 mode_val |= XEHP_CCS_MODE_CSLICE(cslice, ccs_id);
124
125 if (!m) {
126 m = mode;
127 ccs_id = __ffs(cslices_mask);
128 continue;
129 }
130
131 m--;
132 ccs_id = find_next_bit(&cslices_mask, I915_MAX_CCS, ccs_id + 1);
133 }
134
135 gt->ccs.mode_reg_val = mode;
136 }
137
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC PATCH 8/9 drm/i915/gt: Allow the user to change the CCS mode through sysfs
In reply to Andi ShytiCreate 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 | 108 ++++++++++++++++++++ 1 file changed, 108 insertions(+)
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +108 -0
@@ -4,10 +4,27 @@*/ #include "i915_drv.h" +#include "intel_engine_user.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" +#include "i915_perf.h" +#include "sysfs_engines.h" + +static void engine_update_mask (struct intel_gt *gt,u32 ccs_mode) +{ +unsigned long ccs_mask = gt->ccs.cslice_mask; +struct intel_gt_info *info = >->info; +int i; + +/* Mask off all the CCS engines */ + info->engine_mask &= ~GENMASK (CCS3 ,CCS0 ); + +for_each_set_bit (i, &ccs_mask,I915_MAX_CCS ) + info->engine_mask |=BIT (_CCS (i)); +}void intel_gt_ccs_mode_init (struct intel_gt *gt) {
@@ -148,6 +165,86 @@ 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 (CCS_MASK (gt)); + +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 (gt->ccs.cslice_mask); +struct intel_engine_cs *engine; +enum intel_engine_id id; +intel_wakeref_t wakeref; +ssize_t ret; +u32 val; + +/* +* We don't want to change the CCS +* mode while someone is using the GT +*/ +if (intel_gt_pm_is_awake (gt)) +return -EBUSY ; + + 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 ; + +/* +* Nothing to do if the requested setting +* is the same as the current one +*/ +if (val ==hweight32 (CCS_MASK (gt))) +return count; + +/* Recreate engine exposure */ +intel_engines_remove_sysfs (gt->i915); + +mutex_lock (>->ccs.mutex); +intel_gt_apply_ccs_mode (gt, val -1 ); +mutex_unlock (>->ccs.mutex); + + wakeref =intel_runtime_pm_get (gt->uncore->rpm); + +i915_perf_fini (gt->i915); +intel_engines_release (gt); +intel_engines_free (gt); + +mutex_lock (>->ccs.mutex); +engine_update_mask (gt, val); +mutex_unlock (>->ccs.mutex); + +intel_engines_init_mmio (gt); +i915_perf_init (gt->i915); +intel_engines_init (gt); + + gt->i915->uabi_engines =RB_ROOT ; +intel_engines_driver_register (gt->i915); + +intel_runtime_pm_put (gt->uncore->rpm, wakeref); + +intel_engines_add_sysfs (gt->i915); + +return count; +} +static DEVICE_ATTR_RW (ccs_mode); +void intel_gt_sysfs_ccs_init (struct intel_gt *gt) {int err;
@@ -155,4 +252,15 @@ void intel_gt_sysfs_ccs_init(struct intel_gt *gt) err =sysfs_create_file (>->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 (>->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
kernel test robot
build botRe: [RFC PATCH 8/9] drm/i915/gt: Allow the user to change the CCS mode through sysfs
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 linus/master v6.10 next-20240723] [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-Refactor-uabi-engine-class-instance-list-creation/20240723-192341 base: git://anongit.freedesktop.org/drm-intel for-linux-next patch link: https://lore.kernel.org/r/20240723112046.123938-9-andi.shyti%40linux.intel.com patch subject: [RFC PATCH 8/9] drm/i915/gt: Allow the user to change the CCS mode through sysfs config: i386-randconfig-001-20240724 (https://download.01.org/0day-ci/archive/20240724/[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/20240724/[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/intel_gt_ccs_mode.c:79:6: warning: variable 'mode_val' set but not used [-Wunused-but-set-variable]
79 | u32 mode_val = 0;
| ^
>> drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c:185:26: warning: unused variable 'engine' [-Wunused-variable]
185 | struct intel_engine_cs *engine;
| ^~~~~~
>> drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c:186:23: warning: unused variable 'id' [-Wunused-variable]
186 | enum intel_engine_id id;
| ^~3 warnings generated.
vim +/engine +185 drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c
75
76 void intel_gt_apply_ccs_mode(struct intel_gt *gt, u32 mode)
77 {
78 unsigned long cslices_mask = gt->ccs.cslice_mask;
> 79 u32 mode_val = 0;
80 int ccs_id;
81 int cslice;
82 u32 m = mode;
83
84 lockdep_assert_held(>->ccs.mutex);
85
86 if (!IS_DG2(gt->i915))
87 return;
88
89 /*
90 * The mode has two bit dedicated for each engine
91 * that will be used for the CCS balancing algorithm:
92 *
93 * BIT | CCS slice
94 * ------------------
95 * 0 | CCS slice
96 * 1 | 0
97 * ------------------
98 * 2 | CCS slice
99 * 3 | 1
100 * ------------------
101 * 4 | CCS slice
102 * 5 | 2
103 * ------------------
104 * 6 | CCS slice
105 * 7 | 3
106 * ------------------
107 *
108 * When a CCS slice is not available, then we will write 0x7,
109 * oterwise we will write the user engine id which load will
110 * be forwarded to that slice.
111 *
112 * The possible configurations are:
113 *
114 * 1 engine (ccs0):
115 * slice 0, 1, 2, 3: ccs0
116 *
117 * 2 engines (ccs0, ccs1):
118 * slice 0, 2: ccs0
119 * slice 1, 3: ccs1
120 *
121 * 4 engines (ccs0, ccs1, ccs2, ccs3):
122 * slice 0: ccs0
123 * slice 1: ccs1
124 * slice 2: ccs2
125 * slice 3: ccs3
126 */
127 ccs_id = __ffs(cslices_mask);
128
129 for (cslice = 0; cslice < I915_MAX_CCS; cslice++) {
130 if (!(cslices_mask & BIT(cslice))) {
131 /*
132 * If not available, mark the slice as unavailable
133 * and no task will be dispatched here.
134 */
135 mode_val |= XEHP_CCS_MODE_CSLICE(cslice,
136 XEHP_CCS_MODE_CSLICE_MASK);
137 continue;
138 }
139
140 mode_val |= XEHP_CCS_MODE_CSLICE(cslice, ccs_id);
141
142 if (!m) {
143 m = mode;
144 ccs_id = __ffs(cslices_mask);
145 continue;
146 }
147
148 m--;
149 ccs_id = find_next_bit(&cslices_mask, I915_MAX_CCS, ccs_id + 1);
150 }
151
152 gt->ccs.mode_reg_val = mode;
153 }
154
155 static ssize_t num_cslices_show(struct device *dev,
156 struct device_attribute *attr,
157 char *buff)
158 {
159 struct intel_gt *gt = kobj_to_gt(&dev->kobj);
160 u32 num_slices;
161
162 num_slices = hweight32(gt->ccs.cslice_mask);
163
164 return sysfs_emit(buff, "%u\n", num_slices);
165 }
166 static DEVICE_ATTR_RO(num_cslices);
167
168 static ssize_t ccs_mode_show(struct device *dev,
169 struct device_attribute *attr, char *buff)
170 {
171 struct intel_gt *gt = kobj_to_gt(&dev->kobj);
172 u32 ccs_mode;
173
174 ccs_mode = hweight32(CCS_MASK(gt));
175
176 return sysfs_emit(buff, "%u\n", ccs_mode);
177 }
178
179 static ssize_t ccs_mode_store(struct device *dev,
180 struct device_attribute *attr,
181 const char *buff, size_t count)
182 {
183 struct intel_gt *gt = kobj_to_gt(&dev->kobj);
184 int num_cslices = hweight32(gt->ccs.cslice_mask);
> 185 struct intel_engine_cs *engine;
> 186 enum intel_engine_id id; 187 intel_wakeref_t wakeref;
188 ssize_t ret;
189 u32 val;
190
191 /*
192 * We don't want to change the CCS
193 * mode while someone is using the GT
194 */
195 if (intel_gt_pm_is_awake(gt))
196 return -EBUSY;
197
198 ret = kstrtou32(buff, 0, &val);
199 if (ret)
200 return ret;
201
202 /*
203 * As of now possible values to be set are 1, 2, 4,
204 * up to the maximum number of available slices
205 */
206 if ((!val) || (val > num_cslices) || (num_cslices % val))
207 return -EINVAL;
208
209 /*
210 * Nothing to do if the requested setting
211 * is the same as the current one
212 */
213 if (val == hweight32(CCS_MASK(gt)))
214 return count;
215
216 /* Recreate engine exposure */
217 intel_engines_remove_sysfs(gt->i915);
218
219 mutex_lock(>->ccs.mutex);
220 intel_gt_apply_ccs_mode(gt, val - 1);
221 mutex_unlock(>->ccs.mutex);
222
223 wakeref = intel_runtime_pm_get(gt->uncore->rpm);
224
225 i915_perf_fini(gt->i915);
226 intel_engines_release(gt);
227 intel_engines_free(gt);
228
229 mutex_lock(>->ccs.mutex);
230 engine_update_mask(gt, val);
231 mutex_unlock(>->ccs.mutex);
232
233 intel_engines_init_mmio(gt);
234 i915_perf_init(gt->i915);
235 intel_engines_init(gt);
236
237 gt->i915->uabi_engines = RB_ROOT;
238 intel_engines_driver_register(gt->i915);
239
240 intel_runtime_pm_put(gt->uncore->rpm, wakeref);
241
242 intel_engines_add_sysfs(gt->i915);
243
244 return count;
245 }
246 static DEVICE_ATTR_RW(ccs_mode);
247
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC PATCH 9/9 drm/i915/gt: Document CCS mode load balancing
In reply to Andi ShytiAdd documentation for how to set the static CCS load balancing.
--- Documentation/gpu/i915.rst | 3 ++ drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 56 +++++++++++++++++++++ 2 files changed, 59 insertions(+)
Documentation/gpu/i915.rst +3 -0
@@ -341,6 +341,9 @@ for execution also include a list of all locations within buffers that refer to GPU-addresses so that the kernel can edit the buffer correctly. This process is dubbed relocation. +.. kernel-doc:: drivers/gpu/drm/i915/gt/intel_gt_sysfs.c + :doc: CCS load balancing + Locking Guidelines ------------------
drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.45.2
Patchwork
CI✗ Fi.CI.BUILD: failure for CCS static load balance
In reply to Andi Shyti== Series Details ==
== Series Details ==
Series: CCS static load balance
URL : https://patchwork.freedesktop.org/series/136381/
State : failure
== Summary ==
Error: make failed
CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC [M] drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.odrivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c: In function ‘ccs_mode_store’:drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c:242:23: error: unused variable ‘id’ [-Werror=unused-variable]
242 | enum intel_engine_id id;
| ^~drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c:241:26: error: unused variable ‘engine’ [-Werror=unused-variable]
241 | struct intel_engine_cs *engine;
| ^~~~~~
cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:244: drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.o] Error 1 make[5]: *** [scripts/Makefile.build:485: drivers/gpu/drm/i915] Error 2
make[4]: *** [scripts/Makefile.build:485: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:485: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:485: drivers] Error 2
make[1]: *** [/home/kbuild2/kernel/Makefile:1934: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
Build failed, no error log produced