[PATCH v2 8/8] RFC drm/xe/guc: Handle runtime suspend issues for engine busyness
Riana Tauro
riana.tauro at intel.com
Thu Dec 7 12:58:02 UTC 2023
1) During runtime suspend, when card enters D3hot, values read
from the shared memory maintained by GuC returns 0xFF.
Waking up for every perf read when
device is runtime suspended causes power penality.
Store the last read busy ticks and total active ticks and return
these values when suspended
2) When the device is runtime resumed, guc is loaded again. If pmu
interface was opened to collect busyness events, the guc stats
have to be re-enabled to resume collection after suspend.
Disable/enable guc stats if pmu is opened and is already collecting
busyness events and device gets runtime suspended/resumed.
Signed-off-by: Riana Tauro <riana.tauro at intel.com>
---
drivers/gpu/drm/xe/xe_gt.c | 2 +
drivers/gpu/drm/xe/xe_guc_engine_busyness.c | 52 ++++++++++++++++++++-
drivers/gpu/drm/xe/xe_guc_engine_busyness.h | 3 +-
drivers/gpu/drm/xe/xe_guc_types.h | 5 ++
drivers/gpu/drm/xe/xe_pmu.c | 6 +++
drivers/gpu/drm/xe/xe_pmu.h | 2 +
6 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
index 07a94d315715..f7e81f66995d 100644
--- a/drivers/gpu/drm/xe/xe_gt.c
+++ b/drivers/gpu/drm/xe/xe_gt.c
@@ -731,6 +731,8 @@ int xe_gt_resume(struct xe_gt *gt)
if (err)
goto err_force_wake;
+ xe_pmu_resume(gt);
+
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
xe_device_mem_access_put(gt_to_xe(gt));
xe_gt_info(gt, "resumed\n");
diff --git a/drivers/gpu/drm/xe/xe_guc_engine_busyness.c b/drivers/gpu/drm/xe/xe_guc_engine_busyness.c
index e31fb131dfb9..91dcb84650ce 100644
--- a/drivers/gpu/drm/xe/xe_guc_engine_busyness.c
+++ b/drivers/gpu/drm/xe/xe_guc_engine_busyness.c
@@ -110,11 +110,15 @@ static void guc_engine_busyness_get_usage(struct xe_guc *guc,
#undef read_engine_usage
#undef read_global_field
- if (_ticks_engine)
+ if (hwe && _ticks_engine) {
*_ticks_engine = ticks_engine;
+ guc->busy.prev_busy_ticks[hwe->class][hwe->logical_instance] = ticks_engine;
+ }
- if (_ticks_gt)
+ if (_ticks_gt) {
*_ticks_gt = ticks_gt;
+ guc->busy.prev_gt_ticks = ticks_gt;
+ }
}
static void guc_engine_busyness_action_usage_stats(struct xe_guc *guc, bool enable)
@@ -229,6 +233,36 @@ void xe_guc_engine_busyness_unpin(struct xe_guc *guc, bool pmu_locked)
guc_engine_busyness_toggle_stats(guc);
}
+/*
+ * xe_guc_engine_busyness_resume - Helper to resume engine busyness
+ * @guc: The GuC object
+ *
+ * Enable engine busyness if there were outstanding pmu events before
+ * suspend and the collection has to be resumed. This is necessary
+ * as there is a common path for both Runtime suspend and system suspend
+ * and it reloads GuC on resume.
+ */
+void xe_guc_engine_busyness_resume(struct xe_guc *guc)
+{
+ if (guc->busy.pmu_ref)
+ guc_engine_busyness_toggle_stats(guc);
+}
+
+/*
+ * xe_guc_engine_busyness_suspend - Helper to suspend engine busyness
+ * @guc: The GuC object
+ *
+ * Disable engine busyness if there are any outstanding pmu events
+ * and if its suspended. This is necessary as there is a common
+ * path for both Runtime suspend and system suspend
+ * and it reloads GuC on resume.
+ */
+void xe_guc_engine_busyness_suspend(struct xe_guc *guc)
+{
+ if (guc->busy.pmu_ref)
+ guc->busy.enabled = false;
+}
+
/*
* xe_guc_engine_busyness_active_ticks - Gets the total active ticks
* @guc: The GuC object
@@ -237,13 +271,20 @@ void xe_guc_engine_busyness_unpin(struct xe_guc *guc, bool pmu_locked)
*/
u64 xe_guc_engine_busyness_active_ticks(struct xe_guc *guc)
{
+ struct xe_device *xe = guc_to_xe(guc);
+ bool device_awake;
u64 ticks_gt;
/* Engine busyness supported only on GuC >= 70.11.1 */
if (!guc_engine_busyness_supported(guc))
return 0;
+ device_awake = xe_device_mem_access_get_if_ongoing(xe);
+ if (!device_awake)
+ return guc->busy.prev_gt_ticks;
+
guc_engine_busyness_get_usage(guc, NULL, NULL, &ticks_gt);
+ xe_device_mem_access_put(xe);
return ticks_gt;
}
@@ -258,13 +299,20 @@ u64 xe_guc_engine_busyness_active_ticks(struct xe_guc *guc)
*/
u64 xe_guc_engine_busyness_ticks(struct xe_guc *guc, struct xe_hw_engine *hwe)
{
+ struct xe_device *xe = guc_to_xe(guc);
+ bool device_awake;
u64 ticks_engine;
/* Engine busyness supported only on GuC >= 70.11.1 */
if (!guc_engine_busyness_supported(guc))
return 0;
+ device_awake = xe_device_mem_access_get_if_ongoing(xe);
+ if (!device_awake)
+ return guc->busy.prev_busy_ticks[hwe->class][hwe->logical_instance];
+
guc_engine_busyness_get_usage(guc, hwe, &ticks_engine, NULL);
+ xe_device_mem_access_put(xe);
return ticks_engine;
}
diff --git a/drivers/gpu/drm/xe/xe_guc_engine_busyness.h b/drivers/gpu/drm/xe/xe_guc_engine_busyness.h
index 7fde63db8a1d..f59994024059 100644
--- a/drivers/gpu/drm/xe/xe_guc_engine_busyness.h
+++ b/drivers/gpu/drm/xe/xe_guc_engine_busyness.h
@@ -16,5 +16,6 @@ u64 xe_guc_engine_busyness_active_ticks(struct xe_guc *guc);
u64 xe_guc_engine_busyness_ticks(struct xe_guc *guc, struct xe_hw_engine *hwe);
void xe_guc_engine_busyness_pin(struct xe_guc *guc, bool pmu_locked);
void xe_guc_engine_busyness_unpin(struct xe_guc *guc, bool pmu_locked);
-
+void xe_guc_engine_busyness_suspend(struct xe_guc *guc);
+void xe_guc_engine_busyness_resume(struct xe_guc *guc);
#endif
diff --git a/drivers/gpu/drm/xe/xe_guc_types.h b/drivers/gpu/drm/xe/xe_guc_types.h
index cf87fe75490b..4596a341f09a 100644
--- a/drivers/gpu/drm/xe/xe_guc_types.h
+++ b/drivers/gpu/drm/xe/xe_guc_types.h
@@ -15,6 +15,7 @@
#include "xe_guc_fwif.h"
#include "xe_guc_log_types.h"
#include "xe_guc_pc_types.h"
+#include "xe_hw_engine.h"
#include "xe_uc_fw_types.h"
/**
@@ -88,6 +89,10 @@ struct xe_guc {
* been requested, locked by PMU spinlock
*/
int pmu_ref;
+ /** @prev_busy_ticks: array containing last stored busy ticks */
+ u64 prev_busy_ticks[XE_ENGINE_CLASS_MAX][XE_HW_ENGINE_MAX_INSTANCE];
+ /** @prev_gt_ticks: last stored gt ticks */
+ u64 prev_gt_ticks;
} busy;
/**
diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
index 3b532798610e..436b97cfdcac 100644
--- a/drivers/gpu/drm/xe/xe_pmu.c
+++ b/drivers/gpu/drm/xe/xe_pmu.c
@@ -703,9 +703,15 @@ static void xe_pmu_unregister_cpuhp_state(struct xe_pmu *pmu)
void xe_pmu_suspend(struct xe_gt *gt)
{
+ xe_guc_engine_busyness_suspend(>->uc.guc);
engine_group_busyness_store(gt);
}
+void xe_pmu_resume(struct xe_gt *gt)
+{
+ xe_guc_engine_busyness_resume(>->uc.guc);
+}
+
static void xe_pmu_unregister(struct drm_device *device, void *arg)
{
struct xe_pmu *pmu = arg;
diff --git a/drivers/gpu/drm/xe/xe_pmu.h b/drivers/gpu/drm/xe/xe_pmu.h
index a99d4ddd023e..568bcf250934 100644
--- a/drivers/gpu/drm/xe/xe_pmu.h
+++ b/drivers/gpu/drm/xe/xe_pmu.h
@@ -14,11 +14,13 @@ int xe_pmu_init(void);
void xe_pmu_exit(void);
void xe_pmu_register(struct xe_pmu *pmu);
void xe_pmu_suspend(struct xe_gt *gt);
+void xe_pmu_resume(struct xe_gt *gt);
#else
static inline int xe_pmu_init(void) { return 0; }
static inline void xe_pmu_exit(void) {}
static inline void xe_pmu_register(struct xe_pmu *pmu) {}
static inline void xe_pmu_suspend(struct xe_gt *gt) {}
+static inline void xe_pmu_resume(struct xe_gt *gt) {}
#endif
#endif
--
2.40.0
More information about the Intel-xe
mailing list