* [PATCH RFC 1/2] drm/xe/pmu: Release forcewake across system suspend
2026-12-02 20:51 [PATCH RFC 0/2] drm/xe/pmu: Don't let open PMU events block S0ix and GT C6 Michal Hlavac
@ 2026-12-02 20:51 ` Michal Hlavac
2026-12-02 20:51 ` [PATCH RFC 2/2] drm/xe/pmu: Don't hold forcewake while events are open Michal Hlavac
2026-12-03 14:02 ` ✗ LGCI.VerificationFailed: failure for drm/xe/pmu: Don't let open PMU events block S0ix and GT C6 Patchwork
2 siblings, 0 replies; 5+ messages in thread
From: Michal Hlavac @ 2026-12-02 20:51 UTC (permalink / raw)
To: Matthew Brost, Thomas Hellström, Rodrigo Vivi
Cc: intel-xe, Riana Tauro, Vinay Belgaumkar, Umesh Nerlige Ramappa,
Lucas De Marchi, Michal Hlavac
Engine activity and GT frequency events take GT forcewake when they are
created and hold it until they are destroyed, because it can't be taken
from the read callback. Nothing drops these references on system
suspend, so a monitoring tool that keeps such events open (for example
ksystemstats in KDE Plasma 6.8) leaves the GT awake for the whole
suspend. On suspend-to-idle the package then never leaves C0 and the
platform never enters S0ix.
On a Dell XPS 14 DA14260 (Panther Lake) with ksystemstats holding
engine and frequency events open, a 45 s s2idle cycle ends with
/sys/power/suspend_stats/last_hw_sleep = 0 and intel_pmc_core reports
"CPU did not enter Package C10". With this change the same cycle
reaches 44 s of hardware sleep.
Let all events on a GT share one forcewake reference instead of taking
one each, drop it at the end of xe_pm_suspend() and take it again in
xe_pm_resume().
Open events still keep the GT out of C6 while the system is running.
Fixes: c7f2b8bfca78 ("drm/xe/xe_pmu: Acquire forcewake on event init for engine events")
Fixes: 89f306dc6dfd ("drm/xe/pmu: Add GT frequency events")
Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/9633
Link: https://bugs.kde.org/show_bug.cgi?id=527160
Signed-off-by: Michal Hlavac <miso@hlavki.eu>
---
drivers/gpu/drm/xe/xe_pm.c | 13 +++--
drivers/gpu/drm/xe/xe_pmu.c | 117 ++++++++++++++++++++++++++++++--------
drivers/gpu/drm/xe/xe_pmu.h | 4 ++
drivers/gpu/drm/xe/xe_pmu_types.h | 17 +++++-
4 files changed, 121 insertions(+), 30 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index f73f68bd4..a0e912e49 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -24,6 +24,7 @@
#include "xe_irq.h"
#include "xe_late_bind_fw.h"
#include "xe_pcode.h"
+#include "xe_pmu.h"
#include "xe_printk.h"
#include "xe_pxp.h"
#include "xe_sriov_vf_ccs.h"
@@ -194,10 +195,12 @@ int xe_pm_suspend(struct xe_device *xe, bool hibernate)
trace_xe_pm_suspend(xe, __builtin_return_address(0));
err = xe_device_suspend(xe, hibernate, false);
- if (err)
+ if (err) {
drm_dbg(&xe->drm, "Device suspend failed %d\n", err);
- else
+ } else {
+ xe_pmu_suspend(&xe->pmu);
drm_dbg(&xe->drm, "Device suspended\n");
+ }
xe_pm_block_end_signalling();
return err;
@@ -218,10 +221,12 @@ int xe_pm_resume(struct xe_device *xe)
trace_xe_pm_resume(xe, __builtin_return_address(0));
err = xe_device_resume(xe, false);
- if (err)
+ if (err) {
drm_dbg(&xe->drm, "Device resume failed %d\n", err);
- else
+ } else {
+ xe_pmu_resume(&xe->pmu);
drm_dbg(&xe->drm, "Device resumed\n");
+ }
xe_pm_block_end_signalling();
return err;
diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
index ce1b110f7..f1f3f4068 100644
--- a/drivers/gpu/drm/xe/xe_pmu.c
+++ b/drivers/gpu/drm/xe/xe_pmu.c
@@ -130,33 +130,59 @@ static bool is_gt_frequency_event(struct perf_event *event)
id == XE_PMU_EVENT_GT_REQUESTED_FREQUENCY;
}
-static bool event_gt_forcewake(struct perf_event *event)
+static bool event_needs_forcewake(struct perf_event *event)
+{
+ return is_engine_event(event->attr.config) || is_gt_frequency_event(event);
+}
+
+/*
+ * Forcewake can't be taken in the read callback, which runs under a raw
+ * spinlock, so it is held for as long as an event that needs it exists. All
+ * such events on a GT share one reference, which xe_pmu_suspend() drops and
+ * xe_pmu_resume() takes again.
+ */
+static bool event_gt_forcewake_get(struct perf_event *event)
{
struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
- u64 config = event->attr.config;
- struct xe_gt *gt;
- unsigned int *fw_ref;
+ struct xe_gt *gt = event_to_gt(event);
+ struct xe_pmu *pmu = &xe->pmu;
+ u8 id = gt->info.id;
- if (!is_engine_event(config) && !is_gt_frequency_event(event))
+ if (!event_needs_forcewake(event))
return true;
- gt = xe_device_get_gt(xe, config_to_gt_id(config));
-
- fw_ref = kzalloc_obj(*fw_ref);
- if (!fw_ref)
- return false;
+ guard(mutex)(&pmu->fw_lock);
- *fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
- if (!*fw_ref) {
- kfree(fw_ref);
- return false;
+ if (!pmu->fw_ref[id]) {
+ pmu->fw_ref[id] = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
+ if (!pmu->fw_ref[id])
+ return false;
}
- event->pmu_private = fw_ref;
+ pmu->fw_count[id]++;
return true;
}
+static void event_gt_forcewake_put(struct perf_event *event)
+{
+ struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
+ struct xe_gt *gt = event_to_gt(event);
+ struct xe_pmu *pmu = &xe->pmu;
+ u8 id = gt->info.id;
+
+ if (!event_needs_forcewake(event))
+ return;
+
+ guard(mutex)(&pmu->fw_lock);
+
+ if (--pmu->fw_count[id])
+ return;
+
+ xe_force_wake_put(gt_to_fw(gt), pmu->fw_ref[id]);
+ pmu->fw_ref[id] = 0;
+}
+
static bool event_supported(struct xe_pmu *pmu, unsigned int gt_id,
unsigned int id)
{
@@ -214,15 +240,8 @@ static bool event_param_valid(struct perf_event *event)
static void xe_pmu_event_destroy(struct perf_event *event)
{
struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
- struct xe_gt *gt;
- unsigned int *fw_ref = event->pmu_private;
- if (fw_ref) {
- gt = xe_device_get_gt(xe, config_to_gt_id(event->attr.config));
- xe_force_wake_put(gt_to_fw(gt), *fw_ref);
- kfree(fw_ref);
- event->pmu_private = NULL;
- }
+ event_gt_forcewake_put(event);
drm_WARN_ON(&xe->drm, event->parent);
xe_pm_runtime_put(xe);
@@ -262,7 +281,7 @@ static int xe_pmu_event_init(struct perf_event *event)
if (!event->parent) {
drm_dev_get(&xe->drm);
xe_pm_runtime_get(xe);
- if (!event_gt_forcewake(event)) {
+ if (!event_gt_forcewake_get(event)) {
xe_pm_runtime_put(xe);
drm_dev_put(&xe->drm);
return -EINVAL;
@@ -520,6 +539,52 @@ static void set_supported_events(struct xe_pmu *pmu)
}
}
+/**
+ * xe_pmu_suspend() - Drop the forcewake held for PMU events
+ * @pmu: the PMU object
+ *
+ * Called on system suspend, so that events left open by userspace do not keep
+ * the GTs awake while the system sleeps.
+ */
+void xe_pmu_suspend(struct xe_pmu *pmu)
+{
+ struct xe_device *xe = container_of(pmu, typeof(*xe), pmu);
+ struct xe_gt *gt;
+ u8 id;
+
+ if (!pmu->registered)
+ return;
+
+ guard(mutex)(&pmu->fw_lock);
+
+ for_each_gt(gt, xe, id) {
+ xe_force_wake_put(gt_to_fw(gt), pmu->fw_ref[id]);
+ pmu->fw_ref[id] = 0;
+ }
+}
+
+/**
+ * xe_pmu_resume() - Take the forcewake needed by PMU events again
+ * @pmu: the PMU object
+ *
+ * Called on system resume, once the GTs are back up.
+ */
+void xe_pmu_resume(struct xe_pmu *pmu)
+{
+ struct xe_device *xe = container_of(pmu, typeof(*xe), pmu);
+ struct xe_gt *gt;
+ u8 id;
+
+ if (!pmu->registered)
+ return;
+
+ guard(mutex)(&pmu->fw_lock);
+
+ for_each_gt(gt, xe, id)
+ if (pmu->fw_count[id])
+ pmu->fw_ref[id] = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
+}
+
/**
* xe_pmu_unregister() - Remove/cleanup PMU registration
* @arg: Ptr to pmu
@@ -555,11 +620,13 @@ int xe_pmu_register(struct xe_pmu *pmu)
int ret = -ENOMEM;
char *name;
- BUILD_BUG_ON(XE_MAX_GT_PER_TILE != XE_PMU_MAX_GT);
+ BUILD_BUG_ON(XE_MAX_TILES_PER_DEVICE * XE_MAX_GT_PER_TILE != XE_PMU_MAX_GT);
if (IS_SRIOV_VF(xe))
return 0;
+ mutex_init(&pmu->fw_lock);
+
name = kasprintf(GFP_KERNEL, "xe_%s",
dev_name(xe->drm.dev));
if (!name)
diff --git a/drivers/gpu/drm/xe/xe_pmu.h b/drivers/gpu/drm/xe/xe_pmu.h
index 60c37126f..912e033c1 100644
--- a/drivers/gpu/drm/xe/xe_pmu.h
+++ b/drivers/gpu/drm/xe/xe_pmu.h
@@ -10,8 +10,12 @@
#if IS_ENABLED(CONFIG_PERF_EVENTS)
int xe_pmu_register(struct xe_pmu *pmu);
+void xe_pmu_suspend(struct xe_pmu *pmu);
+void xe_pmu_resume(struct xe_pmu *pmu);
#else
static inline int xe_pmu_register(struct xe_pmu *pmu) { return 0; }
+static inline void xe_pmu_suspend(struct xe_pmu *pmu) {}
+static inline void xe_pmu_resume(struct xe_pmu *pmu) {}
#endif
#endif
diff --git a/drivers/gpu/drm/xe/xe_pmu_types.h b/drivers/gpu/drm/xe/xe_pmu_types.h
index f5ba4d566..5a38cdf3c 100644
--- a/drivers/gpu/drm/xe/xe_pmu_types.h
+++ b/drivers/gpu/drm/xe/xe_pmu_types.h
@@ -6,10 +6,12 @@
#ifndef _XE_PMU_TYPES_H_
#define _XE_PMU_TYPES_H_
+#include <linux/mutex_types.h>
#include <linux/perf_event.h>
#include <linux/spinlock_types.h>
-#define XE_PMU_MAX_GT 2
+/* XE_MAX_TILES_PER_DEVICE * XE_MAX_GT_PER_TILE */
+#define XE_PMU_MAX_GT 4
/**
* struct xe_pmu - PMU related data per Xe device
@@ -34,6 +36,19 @@ struct xe_pmu {
* @supported_events: Bitmap of supported events, indexed by event id
*/
u64 supported_events;
+ /**
+ * @fw_lock: Protects @fw_count and @fw_ref.
+ */
+ struct mutex fw_lock;
+ /**
+ * @fw_count: Number of events that need forcewake, per GT.
+ */
+ unsigned int fw_count[XE_PMU_MAX_GT];
+ /**
+ * @fw_ref: Forcewake reference shared by those events, per GT. Zero
+ * while the device is suspended.
+ */
+ unsigned int fw_ref[XE_PMU_MAX_GT];
};
#endif
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH RFC 2/2] drm/xe/pmu: Don't hold forcewake while events are open
2026-12-02 20:51 [PATCH RFC 0/2] drm/xe/pmu: Don't let open PMU events block S0ix and GT C6 Michal Hlavac
2026-12-02 20:51 ` [PATCH RFC 1/2] drm/xe/pmu: Release forcewake across system suspend Michal Hlavac
@ 2026-12-02 20:51 ` Michal Hlavac
2026-12-03 13:45 ` sashiko-bot
2026-12-03 14:02 ` ✗ LGCI.VerificationFailed: failure for drm/xe/pmu: Don't let open PMU events block S0ix and GT C6 Patchwork
2 siblings, 1 reply; 5+ messages in thread
From: Michal Hlavac @ 2026-12-02 20:51 UTC (permalink / raw)
To: Matthew Brost, Thomas Hellström, Rodrigo Vivi
Cc: intel-xe, Riana Tauro, Vinay Belgaumkar, Umesh Nerlige Ramappa,
Lucas De Marchi, Michal Hlavac
Engine activity and GT frequency events hold GT forcewake for as long
as they are open. A monitoring tool that keeps such events open (for
example ksystemstats in KDE Plasma 6.8) therefore keeps the GT out of
C6 for as long as it runs, and the forcewake has to be dropped and
taken again around system suspend.
The forcewake is there for three register reads in the read callback,
which can't take it itself. None of them needs the GT to be forced
awake:
- The engine activity counters read the GPM timestamp only while GuC
reports the engine as running, and then the GT is normally awake.
The engine can go idle and the GT enter C6 at any time though, so
only use the timestamp if the GT is in C0 before and after the
read, and keep the previous value otherwise.
- The actual frequency is documented to read as 0 in C6 and is
already read without forcewake by the act_freq sysfs attribute.
- The requested frequency can be read the same way as the timestamp.
Report 0 if the GT is not in C0.
With that, drop the forcewake handling from the PMU, including the
suspend and resume hooks. The runtime PM reference held by open events
stays as it is.
This changes what gt-requested-frequency reports: it used to always
return a request, because the event itself kept the GT awake. It now
reads as 0 while the GT is in C6, like gt-actual-frequency does, and
like both frequencies do in i915 while the GT is parked.
Tested on a Dell XPS 14 DA14260 (Panther Lake) with ksystemstats
holding engine and frequency events open. The gt-c6 residency of both
GTs now advances by about 9.7 s per 10 s on an idle desktop, where it
did not advance at all. A 45 s s2idle cycle still reaches 44 s of
hardware sleep. The reported engine utilization is 1-2 % when idle and
about 60 % with glxgears running, before and after a suspend cycle, and
gt-requested-frequency follows gt-actual-frequency under load.
Fixes: c7f2b8bfca78 ("drm/xe/xe_pmu: Acquire forcewake on event init for engine events")
Fixes: 89f306dc6dfd ("drm/xe/pmu: Add GT frequency events")
Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/9633
Link: https://bugs.kde.org/show_bug.cgi?id=527160
Signed-off-by: Michal Hlavac <miso@hlavki.eu>
---
drivers/gpu/drm/xe/xe_guc_engine_activity.c | 34 ++++++--
drivers/gpu/drm/xe/xe_guc_pc.c | 22 +++++
drivers/gpu/drm/xe/xe_guc_pc.h | 1 +
drivers/gpu/drm/xe/xe_pm.c | 13 +--
drivers/gpu/drm/xe/xe_pmu.c | 124 ++--------------------------
drivers/gpu/drm/xe/xe_pmu.h | 4 -
drivers/gpu/drm/xe/xe_pmu_types.h | 17 +---
7 files changed, 58 insertions(+), 157 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_guc_engine_activity.c b/drivers/gpu/drm/xe/xe_guc_engine_activity.c
index 729ce8ac1..bb978c141 100644
--- a/drivers/gpu/drm/xe/xe_guc_engine_activity.c
+++ b/drivers/gpu/drm/xe/xe_guc_engine_activity.c
@@ -14,6 +14,7 @@
#include "xe_guc.h"
#include "xe_guc_engine_activity.h"
#include "xe_guc_ct.h"
+#include "xe_guc_pc.h"
#include "xe_hw_engine.h"
#include "xe_map.h"
#include "xe_mmio.h"
@@ -170,18 +171,36 @@ static u64 cpu_ns_to_guc_tsc_tick(ktime_t ns, u32 freq)
#define read_metadata_record(xe_, map_, field_) \
xe_map_rd_field(xe_, map_, 0, struct guc_engine_activity_metadata, field_)
+/*
+ * The PMU reads the engine activity without forcewake, and the GPM timestamp
+ * can only be read while the GT is awake. The GT is normally awake while an
+ * engine is running, but the engine can go idle and let the GT enter C6 at any
+ * time. Only trust the timestamp if the GT was in C0 before and after reading
+ * it.
+ */
+static bool read_gpm_timestamp(struct xe_guc *guc, u32 *gpm_ts)
+{
+ struct xe_gt *gt = guc_to_gt(guc);
+
+ if (xe_guc_pc_c_status(&guc->pc) != GT_IDLE_C0)
+ return false;
+
+ *gpm_ts = lower_32_bits(xe_mmio_read64_2x32(>->mmio, MISC_STATUS_0) >>
+ guc->engine_activity.gpm_timestamp_shift);
+
+ return xe_guc_pc_c_status(&guc->pc) == GT_IDLE_C0;
+}
+
static u64 get_engine_active_ticks(struct xe_guc *guc, struct xe_hw_engine *hwe,
unsigned int index)
{
struct engine_activity *ea = hw_engine_to_engine_activity(hwe, index);
struct guc_engine_activity *cached_activity = &ea->activity;
struct guc_engine_activity_metadata *cached_metadata = &ea->metadata;
- struct xe_guc_engine_activity *engine_activity = &guc->engine_activity;
struct iosys_map activity_map, metadata_map;
struct xe_device *xe = guc_to_xe(guc);
- struct xe_gt *gt = guc_to_gt(guc);
- u32 last_update_tick, global_change_num;
- u64 active_ticks, gpm_ts;
+ u32 last_update_tick, global_change_num, gpm_ts;
+ u64 active_ticks;
u16 change_num;
activity_map = engine_activity_map(guc, hwe, index);
@@ -216,11 +235,8 @@ static u64 get_engine_active_ticks(struct xe_guc *guc, struct xe_hw_engine *hwe,
cached_activity->active_ticks = active_ticks;
update:
- if (ea->running) {
- gpm_ts = xe_mmio_read64_2x32(>->mmio, MISC_STATUS_0) >>
- engine_activity->gpm_timestamp_shift;
- ea->active = lower_32_bits(gpm_ts) - cached_activity->last_update_tick;
- }
+ if (ea->running && read_gpm_timestamp(guc, &gpm_ts))
+ ea->active = gpm_ts - cached_activity->last_update_tick;
trace_xe_guc_engine_activity(xe, ea, hwe->name, hwe->instance);
diff --git a/drivers/gpu/drm/xe/xe_guc_pc.c b/drivers/gpu/drm/xe/xe_guc_pc.c
index 9558d7196..8e37ce22c 100644
--- a/drivers/gpu/drm/xe/xe_guc_pc.c
+++ b/drivers/gpu/drm/xe/xe_guc_pc.c
@@ -515,6 +515,28 @@ u32 xe_guc_pc_get_cur_freq_fw(struct xe_guc_pc *pc)
return get_cur_freq(gt);
}
+/**
+ * xe_guc_pc_get_cur_freq_if_awake - Get requested frequency without waking the GT
+ * @pc: The GuC PC
+ *
+ * For callers that can't take forcewake. The request register can only be
+ * read while the GT is awake, so only trust it if the GT was in C0 before and
+ * after the read.
+ *
+ * Returns: the requested frequency, or 0 if the GT is not in C0.
+ */
+u32 xe_guc_pc_get_cur_freq_if_awake(struct xe_guc_pc *pc)
+{
+ u32 freq;
+
+ if (xe_guc_pc_c_status(pc) != GT_IDLE_C0)
+ return 0;
+
+ freq = get_cur_freq(pc_to_gt(pc));
+
+ return xe_guc_pc_c_status(pc) == GT_IDLE_C0 ? freq : 0;
+}
+
/**
* xe_guc_pc_get_cur_freq - Get Current requested frequency
* @pc: The GuC PC
diff --git a/drivers/gpu/drm/xe/xe_guc_pc.h b/drivers/gpu/drm/xe/xe_guc_pc.h
index 1025a2b15..9c4496a1d 100644
--- a/drivers/gpu/drm/xe/xe_guc_pc.h
+++ b/drivers/gpu/drm/xe/xe_guc_pc.h
@@ -21,6 +21,7 @@ int xe_guc_pc_action_unset_param(struct xe_guc_pc *pc, u8 id);
u32 xe_guc_pc_get_act_freq(struct xe_guc_pc *pc);
int xe_guc_pc_get_cur_freq(struct xe_guc_pc *pc, u32 *freq);
u32 xe_guc_pc_get_cur_freq_fw(struct xe_guc_pc *pc);
+u32 xe_guc_pc_get_cur_freq_if_awake(struct xe_guc_pc *pc);
u32 xe_guc_pc_get_rp0_freq(struct xe_guc_pc *pc);
u32 xe_guc_pc_get_rpa_freq(struct xe_guc_pc *pc);
u32 xe_guc_pc_get_rpe_freq(struct xe_guc_pc *pc);
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index a0e912e49..f73f68bd4 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -24,7 +24,6 @@
#include "xe_irq.h"
#include "xe_late_bind_fw.h"
#include "xe_pcode.h"
-#include "xe_pmu.h"
#include "xe_printk.h"
#include "xe_pxp.h"
#include "xe_sriov_vf_ccs.h"
@@ -195,12 +194,10 @@ int xe_pm_suspend(struct xe_device *xe, bool hibernate)
trace_xe_pm_suspend(xe, __builtin_return_address(0));
err = xe_device_suspend(xe, hibernate, false);
- if (err) {
+ if (err)
drm_dbg(&xe->drm, "Device suspend failed %d\n", err);
- } else {
- xe_pmu_suspend(&xe->pmu);
+ else
drm_dbg(&xe->drm, "Device suspended\n");
- }
xe_pm_block_end_signalling();
return err;
@@ -221,12 +218,10 @@ int xe_pm_resume(struct xe_device *xe)
trace_xe_pm_resume(xe, __builtin_return_address(0));
err = xe_device_resume(xe, false);
- if (err) {
+ if (err)
drm_dbg(&xe->drm, "Device resume failed %d\n", err);
- } else {
- xe_pmu_resume(&xe->pmu);
+ else
drm_dbg(&xe->drm, "Device resumed\n");
- }
xe_pm_block_end_signalling();
return err;
diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
index f1f3f4068..44ae0db64 100644
--- a/drivers/gpu/drm/xe/xe_pmu.c
+++ b/drivers/gpu/drm/xe/xe_pmu.c
@@ -7,7 +7,6 @@
#include <linux/device.h>
#include "xe_device.h"
-#include "xe_force_wake.h"
#include "xe_gt_idle.h"
#include "xe_guc_engine_activity.h"
#include "xe_guc_pc.h"
@@ -41,6 +40,9 @@
*
* For gt specific events (gt-*) gt parameter must be passed. All other parameters will be 0.
*
+ * Open events don't keep the GT awake. The frequency events (gt-actual-frequency and
+ * gt-requested-frequency) read as 0 while the GT is in C6.
+ *
* The standard perf tool can be used to grep for a certain event as well.
* Example:
*
@@ -114,14 +116,6 @@ static struct xe_hw_engine *event_to_hwe(struct perf_event *event)
return hwe;
}
-static bool is_engine_event(u64 config)
-{
- unsigned int event_id = config_to_event_id(config);
-
- return (event_id == XE_PMU_EVENT_ENGINE_TOTAL_TICKS ||
- event_id == XE_PMU_EVENT_ENGINE_ACTIVE_TICKS);
-}
-
static bool is_gt_frequency_event(struct perf_event *event)
{
u32 id = config_to_event_id(event->attr.config);
@@ -130,59 +124,6 @@ static bool is_gt_frequency_event(struct perf_event *event)
id == XE_PMU_EVENT_GT_REQUESTED_FREQUENCY;
}
-static bool event_needs_forcewake(struct perf_event *event)
-{
- return is_engine_event(event->attr.config) || is_gt_frequency_event(event);
-}
-
-/*
- * Forcewake can't be taken in the read callback, which runs under a raw
- * spinlock, so it is held for as long as an event that needs it exists. All
- * such events on a GT share one reference, which xe_pmu_suspend() drops and
- * xe_pmu_resume() takes again.
- */
-static bool event_gt_forcewake_get(struct perf_event *event)
-{
- struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
- struct xe_gt *gt = event_to_gt(event);
- struct xe_pmu *pmu = &xe->pmu;
- u8 id = gt->info.id;
-
- if (!event_needs_forcewake(event))
- return true;
-
- guard(mutex)(&pmu->fw_lock);
-
- if (!pmu->fw_ref[id]) {
- pmu->fw_ref[id] = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
- if (!pmu->fw_ref[id])
- return false;
- }
-
- pmu->fw_count[id]++;
-
- return true;
-}
-
-static void event_gt_forcewake_put(struct perf_event *event)
-{
- struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
- struct xe_gt *gt = event_to_gt(event);
- struct xe_pmu *pmu = &xe->pmu;
- u8 id = gt->info.id;
-
- if (!event_needs_forcewake(event))
- return;
-
- guard(mutex)(&pmu->fw_lock);
-
- if (--pmu->fw_count[id])
- return;
-
- xe_force_wake_put(gt_to_fw(gt), pmu->fw_ref[id]);
- pmu->fw_ref[id] = 0;
-}
-
static bool event_supported(struct xe_pmu *pmu, unsigned int gt_id,
unsigned int id)
{
@@ -241,8 +182,6 @@ static void xe_pmu_event_destroy(struct perf_event *event)
{
struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
- event_gt_forcewake_put(event);
-
drm_WARN_ON(&xe->drm, event->parent);
xe_pm_runtime_put(xe);
drm_dev_put(&xe->drm);
@@ -281,11 +220,6 @@ static int xe_pmu_event_init(struct perf_event *event)
if (!event->parent) {
drm_dev_get(&xe->drm);
xe_pm_runtime_get(xe);
- if (!event_gt_forcewake_get(event)) {
- xe_pm_runtime_put(xe);
- drm_dev_put(&xe->drm);
- return -EINVAL;
- }
event->destroy = xe_pmu_event_destroy;
}
@@ -326,7 +260,7 @@ static u64 __xe_pmu_event_read(struct perf_event *event)
case XE_PMU_EVENT_GT_ACTUAL_FREQUENCY:
return xe_guc_pc_get_act_freq(>->uc.guc.pc);
case XE_PMU_EVENT_GT_REQUESTED_FREQUENCY:
- return xe_guc_pc_get_cur_freq_fw(>->uc.guc.pc);
+ return xe_guc_pc_get_cur_freq_if_awake(>->uc.guc.pc);
}
return 0;
@@ -539,52 +473,6 @@ static void set_supported_events(struct xe_pmu *pmu)
}
}
-/**
- * xe_pmu_suspend() - Drop the forcewake held for PMU events
- * @pmu: the PMU object
- *
- * Called on system suspend, so that events left open by userspace do not keep
- * the GTs awake while the system sleeps.
- */
-void xe_pmu_suspend(struct xe_pmu *pmu)
-{
- struct xe_device *xe = container_of(pmu, typeof(*xe), pmu);
- struct xe_gt *gt;
- u8 id;
-
- if (!pmu->registered)
- return;
-
- guard(mutex)(&pmu->fw_lock);
-
- for_each_gt(gt, xe, id) {
- xe_force_wake_put(gt_to_fw(gt), pmu->fw_ref[id]);
- pmu->fw_ref[id] = 0;
- }
-}
-
-/**
- * xe_pmu_resume() - Take the forcewake needed by PMU events again
- * @pmu: the PMU object
- *
- * Called on system resume, once the GTs are back up.
- */
-void xe_pmu_resume(struct xe_pmu *pmu)
-{
- struct xe_device *xe = container_of(pmu, typeof(*xe), pmu);
- struct xe_gt *gt;
- u8 id;
-
- if (!pmu->registered)
- return;
-
- guard(mutex)(&pmu->fw_lock);
-
- for_each_gt(gt, xe, id)
- if (pmu->fw_count[id])
- pmu->fw_ref[id] = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
-}
-
/**
* xe_pmu_unregister() - Remove/cleanup PMU registration
* @arg: Ptr to pmu
@@ -620,13 +508,11 @@ int xe_pmu_register(struct xe_pmu *pmu)
int ret = -ENOMEM;
char *name;
- BUILD_BUG_ON(XE_MAX_TILES_PER_DEVICE * XE_MAX_GT_PER_TILE != XE_PMU_MAX_GT);
+ BUILD_BUG_ON(XE_MAX_GT_PER_TILE != XE_PMU_MAX_GT);
if (IS_SRIOV_VF(xe))
return 0;
- mutex_init(&pmu->fw_lock);
-
name = kasprintf(GFP_KERNEL, "xe_%s",
dev_name(xe->drm.dev));
if (!name)
diff --git a/drivers/gpu/drm/xe/xe_pmu.h b/drivers/gpu/drm/xe/xe_pmu.h
index 912e033c1..60c37126f 100644
--- a/drivers/gpu/drm/xe/xe_pmu.h
+++ b/drivers/gpu/drm/xe/xe_pmu.h
@@ -10,12 +10,8 @@
#if IS_ENABLED(CONFIG_PERF_EVENTS)
int xe_pmu_register(struct xe_pmu *pmu);
-void xe_pmu_suspend(struct xe_pmu *pmu);
-void xe_pmu_resume(struct xe_pmu *pmu);
#else
static inline int xe_pmu_register(struct xe_pmu *pmu) { return 0; }
-static inline void xe_pmu_suspend(struct xe_pmu *pmu) {}
-static inline void xe_pmu_resume(struct xe_pmu *pmu) {}
#endif
#endif
diff --git a/drivers/gpu/drm/xe/xe_pmu_types.h b/drivers/gpu/drm/xe/xe_pmu_types.h
index 5a38cdf3c..f5ba4d566 100644
--- a/drivers/gpu/drm/xe/xe_pmu_types.h
+++ b/drivers/gpu/drm/xe/xe_pmu_types.h
@@ -6,12 +6,10 @@
#ifndef _XE_PMU_TYPES_H_
#define _XE_PMU_TYPES_H_
-#include <linux/mutex_types.h>
#include <linux/perf_event.h>
#include <linux/spinlock_types.h>
-/* XE_MAX_TILES_PER_DEVICE * XE_MAX_GT_PER_TILE */
-#define XE_PMU_MAX_GT 4
+#define XE_PMU_MAX_GT 2
/**
* struct xe_pmu - PMU related data per Xe device
@@ -36,19 +34,6 @@ struct xe_pmu {
* @supported_events: Bitmap of supported events, indexed by event id
*/
u64 supported_events;
- /**
- * @fw_lock: Protects @fw_count and @fw_ref.
- */
- struct mutex fw_lock;
- /**
- * @fw_count: Number of events that need forcewake, per GT.
- */
- unsigned int fw_count[XE_PMU_MAX_GT];
- /**
- * @fw_ref: Forcewake reference shared by those events, per GT. Zero
- * while the device is suspended.
- */
- unsigned int fw_ref[XE_PMU_MAX_GT];
};
#endif
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread