[Intel-xe] [RFC v2 2/2] drm/xe: Prevent exec_queues creation on diabled CCS engines

Niranjana Vishwanathapura niranjana.vishwanathapura at intel.com
Wed Nov 1 23:57:49 UTC 2023


Ensure no exec_queues are opened when changing CCS mode.
Allow exec_queue creation only with enabled CCS engines.

Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura at intel.com>
---
 drivers/gpu/drm/xe/xe_device.c       |  1 +
 drivers/gpu/drm/xe/xe_device_types.h |  9 ++++++
 drivers/gpu/drm/xe/xe_exec_queue.c   | 45 ++++++++++++++++++++++++++--
 drivers/gpu/drm/xe/xe_tile_sysfs.c   |  8 +++++
 4 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 8341acf66e5f..a0d2fa7f63ff 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -226,6 +226,7 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	xe->info.force_execlist = force_execlist;
 
 	spin_lock_init(&xe->irq.lock);
+	spin_lock_init(&xe->ccs_mode.lock);
 
 	init_waitqueue_head(&xe->ufence_wq);
 
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index cb537cac1ef9..803cca66a19c 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -297,6 +297,15 @@ struct xe_device {
 		struct ttm_resource_manager sys_mgr;
 	} mem;
 
+	/** @ccs_mode: ccs mode */
+	struct {
+		/** @lock: Ensures no client is active while setting ccs_mode */
+		spinlock_t lock;
+
+		/** @num_exec_queues: number of open exec queues */
+		u64 num_exec_queues;
+	} ccs_mode;
+
 	/** @usm: unified memory state */
 	struct {
 		/** @asid: convert a ASID to VM */
diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_exec_queue.c
index 4fd44a9203e4..beb89d41ef7b 100644
--- a/drivers/gpu/drm/xe/xe_exec_queue.c
+++ b/drivers/gpu/drm/xe/xe_exec_queue.c
@@ -539,6 +539,15 @@ static u32 bind_exec_queue_logical_mask(struct xe_device *xe, struct xe_gt *gt,
 	return logical_mask;
 }
 
+static inline bool ccs_mode_engine_enabled(struct xe_device *xe,
+					   struct drm_xe_engine_class_instance eci)
+{
+	struct xe_gt *gt = xe_device_get_gt(xe, eci.gt_id);
+
+	return !(eci.engine_class == DRM_XE_ENGINE_CLASS_COMPUTE &&
+		 eci.engine_instance >= gt->ccs.num_engines);
+}
+
 static u32 calc_validate_logical_mask(struct xe_device *xe, struct xe_gt *gt,
 				      struct drm_xe_engine_class_instance *eci,
 				      u16 width, u16 num_placements)
@@ -561,6 +570,9 @@ static u32 calc_validate_logical_mask(struct xe_device *xe, struct xe_gt *gt,
 
 			n = j * width + i;
 
+			if (XE_IOCTL_DBG(xe, !ccs_mode_engine_enabled(xe, eci[n])))
+				return 0;
+
 			hwe = find_hw_engine(xe, eci[n]);
 			if (XE_IOCTL_DBG(xe, !hwe))
 				return 0;
@@ -590,8 +602,8 @@ static u32 calc_validate_logical_mask(struct xe_device *xe, struct xe_gt *gt,
 	return return_mask;
 }
 
-int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
-			       struct drm_file *file)
+static int __xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
+					struct drm_file *file)
 {
 	struct xe_device *xe = to_xe_device(dev);
 	struct xe_file *xef = to_xe_file(file);
@@ -747,6 +759,34 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
 	return err;
 }
 
+static void inc_exec_queue_count(struct xe_device *xe)
+{
+	spin_lock(&xe->ccs_mode.lock);
+	xe->ccs_mode.num_exec_queues++;
+	spin_unlock(&xe->ccs_mode.lock);
+}
+
+static void dec_exec_queue_count(struct xe_device *xe)
+{
+	spin_lock(&xe->ccs_mode.lock);
+	xe->ccs_mode.num_exec_queues--;
+	spin_unlock(&xe->ccs_mode.lock);
+}
+
+int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
+			       struct drm_file *file)
+{
+	struct xe_device *xe = to_xe_device(dev);
+	int err;
+
+	inc_exec_queue_count(xe);
+	err = __xe_exec_queue_create_ioctl(dev, data, file);
+	if (err)
+		dec_exec_queue_count(xe);
+
+	return err;
+}
+
 int xe_exec_queue_get_property_ioctl(struct drm_device *dev, void *data,
 				     struct drm_file *file)
 {
@@ -872,6 +912,7 @@ int xe_exec_queue_destroy_ioctl(struct drm_device *dev, void *data,
 	if (XE_IOCTL_DBG(xe, !q))
 		return -ENOENT;
 
+	dec_exec_queue_count(xe);
 	if (!(q->flags & EXEC_QUEUE_FLAG_PERSISTENT))
 		xe_exec_queue_kill(q);
 	else
diff --git a/drivers/gpu/drm/xe/xe_tile_sysfs.c b/drivers/gpu/drm/xe/xe_tile_sysfs.c
index a0162744ce24..88f016f651ba 100644
--- a/drivers/gpu/drm/xe/xe_tile_sysfs.c
+++ b/drivers/gpu/drm/xe/xe_tile_sysfs.c
@@ -72,12 +72,20 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
 		return -EINVAL;
 	}
 
+	spin_lock(&xe->ccs_mode.lock);
+	if (xe->ccs_mode.num_exec_queues) {
+		spin_unlock(&xe->ccs_mode.lock);
+		return -EBUSY;
+	}
+
 	if (gt->ccs.num_engines != num_engines) {
 		drm_info(&xe->drm, "tile-%d: setting compute mode to %d\n", tile->id, num_engines);
 		gt->ccs.num_engines = num_engines;
 		xe_gt_reset_async(gt);
 	}
 
+	spin_unlock(&xe->ccs_mode.lock);
+
 	return count;
 }
 
-- 
2.21.0.rc0.32.g243a4c7e27



More information about the Intel-xe mailing list