]> git.dujemihanovic.xyz Git - linux.git/commitdiff
drm/xe: Convert mem_access assertion towards the runtime_pm state
authorRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 22 Feb 2024 16:39:25 +0000 (11:39 -0500)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Mon, 26 Feb 2024 14:05:21 +0000 (09:05 -0500)
The mem_access helpers are going away and getting replaced by
direct calls of the xe_pm_runtime_{get,put} functions. However, an
assertion with a warning splat is desired when we hit the worst
case of a memory access with the device really in the 'suspended'
state.

Also, this needs to be the first step. Otherwise, the upcoming
conversion would be really noise with warn splats of missing mem_access
gets.

v2: Minor doc changes as suggested by Matt

Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240222163937.138342-2-rodrigo.vivi@intel.com
drivers/gpu/drm/xe/xe_device.c
drivers/gpu/drm/xe/xe_pm.c
drivers/gpu/drm/xe/xe_pm.h

index ca85e81fdb44383ffdafdb48a98a843cb1884b71..049bbca6ed565fef8d6647ab99e873ed30f495d1 100644 (file)
@@ -620,9 +620,20 @@ bool xe_device_mem_access_ongoing(struct xe_device *xe)
        return atomic_read(&xe->mem_access.ref);
 }
 
+/**
+ * xe_device_assert_mem_access - Inspect the current runtime_pm state.
+ * @xe: xe device instance
+ *
+ * To be used before any kind of memory access. It will splat a debug warning
+ * if the device is currently sleeping. But it doesn't guarantee in any way
+ * that the device is going to remain awake. Xe PM runtime get and put
+ * functions might be added to the outer bound of the memory access, while
+ * this check is intended for inner usage to splat some warning if the worst
+ * case has just happened.
+ */
 void xe_device_assert_mem_access(struct xe_device *xe)
 {
-       XE_WARN_ON(!xe_device_mem_access_ongoing(xe));
+       XE_WARN_ON(xe_pm_runtime_suspended(xe));
 }
 
 bool xe_device_mem_access_get_if_ongoing(struct xe_device *xe)
index ae220f21acb1b3bcc25f436cf7662a4eb95b5b72..5289d8c0c3b13c880881c0d64d063e9cbaf324d2 100644 (file)
@@ -261,6 +261,22 @@ struct task_struct *xe_pm_read_callback_task(struct xe_device *xe)
        return READ_ONCE(xe->pm_callback_task);
 }
 
+/**
+ * xe_pm_runtime_suspended - Check if runtime_pm state is suspended
+ * @xe: xe device instance
+ *
+ * This does not provide any guarantee that the device is going to remain
+ * suspended as it might be racing with the runtime state transitions.
+ * It can be used only as a non-reliable assertion, to ensure that we are not in
+ * the sleep state while trying to access some memory for instance.
+ *
+ * Returns true if PCI device is suspended, false otherwise.
+ */
+bool xe_pm_runtime_suspended(struct xe_device *xe)
+{
+       return pm_runtime_suspended(xe->drm.dev);
+}
+
 /**
  * xe_pm_runtime_suspend - Prepare our device for D3hot/D3Cold
  * @xe: xe device instance
index 64a97c6726a7278aecc193d0ba0c86ddbb80c11a..75919eba17461eb6beb66cdb6f565c49de494ebc 100644 (file)
@@ -23,6 +23,7 @@ int xe_pm_resume(struct xe_device *xe);
 void xe_pm_init_early(struct xe_device *xe);
 void xe_pm_init(struct xe_device *xe);
 void xe_pm_runtime_fini(struct xe_device *xe);
+bool xe_pm_runtime_suspended(struct xe_device *xe);
 int xe_pm_runtime_suspend(struct xe_device *xe);
 int xe_pm_runtime_resume(struct xe_device *xe);
 int xe_pm_runtime_get(struct xe_device *xe);