]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe: Cache data about user-visible engines
authorLucas De Marchi <lucas.demarchi@intel.com>
Fri, 17 May 2024 20:43:08 +0000 (13:43 -0700)
committerLucas De Marchi <lucas.demarchi@intel.com>
Tue, 21 May 2024 13:33:40 +0000 (06:33 -0700)
gt->info.engine_mask used to indicate the available engines, but that
is not always true anymore: some engines are reserved to kernel and some
may be exposed as a single engine (e.g. with ccs_mode).

Runtime changes only happen when no clients exist, so it's safe to cache
the list of engines in the gt and update that when it's needed. This
will help implementing per client engine utilization so this (mostly
constant) information doesn't need to be re-calculated on every query.

Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240517204310.88854-7-lucas.demarchi@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_gt.c
drivers/gpu/drm/xe/xe_gt.h
drivers/gpu/drm/xe/xe_gt_ccs_mode.c
drivers/gpu/drm/xe/xe_gt_types.h

index e69a03ddd255f7e8763540a608c085e2db80fba6..5194a3d38e767de7c23a00a534cb7a6949996a4b 100644 (file)
@@ -560,9 +560,32 @@ int xe_gt_init(struct xe_gt *gt)
        if (err)
                return err;
 
+       xe_gt_record_user_engines(gt);
+
        return drmm_add_action_or_reset(&gt_to_xe(gt)->drm, gt_fini, gt);
 }
 
+void xe_gt_record_user_engines(struct xe_gt *gt)
+{
+       struct xe_hw_engine *hwe;
+       enum xe_hw_engine_id id;
+
+       gt->user_engines.mask = 0;
+       memset(gt->user_engines.instances_per_class, 0,
+              sizeof(gt->user_engines.instances_per_class));
+
+       for_each_hw_engine(hwe, gt, id) {
+               if (xe_hw_engine_is_reserved(hwe))
+                       continue;
+
+               gt->user_engines.mask |= BIT_ULL(id);
+               gt->user_engines.instances_per_class[hwe->class]++;
+       }
+
+       xe_gt_assert(gt, (gt->user_engines.mask | gt->info.engine_mask)
+                    == gt->info.engine_mask);
+}
+
 static int do_gt_reset(struct xe_gt *gt)
 {
        int err;
index 8474c50b1b307f6685b6bae88aaa1bb155a13854..1d010bf4a756f56e6e3c8f290ad8c2f114a4fec3 100644 (file)
@@ -38,6 +38,19 @@ int xe_gt_init_hwconfig(struct xe_gt *gt);
 int xe_gt_init_early(struct xe_gt *gt);
 int xe_gt_init(struct xe_gt *gt);
 int xe_gt_record_default_lrcs(struct xe_gt *gt);
+
+/**
+ * xe_gt_record_user_engines - save data related to engines available to
+ * usersapce
+ * @gt: GT structure
+ *
+ * Walk the available HW engines from gt->info.engine_mask and calculate data
+ * related to those engines that may be used by userspace. To be used whenever
+ * available engines change in runtime (e.g. with ccs_mode) or during
+ * initialization
+ */
+void xe_gt_record_user_engines(struct xe_gt *gt);
+
 void xe_gt_suspend_prepare(struct xe_gt *gt);
 int xe_gt_suspend(struct xe_gt *gt);
 int xe_gt_resume(struct xe_gt *gt);
index a34c9a24dafc71b1fbb043532dbeafa7eec3464d..c36218f4f6c8f7420f49eb0a5c1cd0d8565d7dd2 100644 (file)
@@ -134,6 +134,7 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
        if (gt->ccs_mode != num_engines) {
                xe_gt_info(gt, "Setting compute mode to %d\n", num_engines);
                gt->ccs_mode = num_engines;
+               xe_gt_record_user_engines(gt);
                xe_gt_reset_async(gt);
        }
 
index 475fb58882f15e91ee1bf13251c8cefe4bc92da0..10a9a9529377484255d540b2b1f4140c5007e5fc 100644 (file)
@@ -113,7 +113,11 @@ struct xe_gt {
                enum xe_gt_type type;
                /** @info.reference_clock: clock frequency */
                u32 reference_clock;
-               /** @info.engine_mask: mask of engines present on GT */
+               /**
+                * @info.engine_mask: mask of engines present on GT. Some of
+                * them may be reserved in runtime and not available for user.
+                * See @user_engines.mask
+                */
                u64 engine_mask;
                /** @info.gmdid: raw GMD_ID value from hardware */
                u32 gmdid;
@@ -368,6 +372,21 @@ struct xe_gt {
                /** @wa_active.oob: bitmap with active OOB workaroudns */
                unsigned long *oob;
        } wa_active;
+
+       /** @user_engines: engines present in GT and available to userspace */
+       struct {
+               /**
+                * @user_engines.mask: like @info->engine_mask, but take in
+                * consideration only engines available to userspace
+                */
+               u64 mask;
+
+               /**
+                * @user_engines.instances_per_class: aggregate per class the
+                * number of engines available to userspace
+                */
+               u8 instances_per_class[XE_ENGINE_CLASS_MAX];
+       } user_engines;
 };
 
 #endif