[PATCH v3 05/10] [DO NOT REVIEW] drm/xe/xe_pmu: add fixes for base PMU

Riana Tauro riana.tauro at intel.com
Mon Jan 6 07:55:54 UTC 2025


DO NOT REVIEW. Patch added for compilation

use pmu format attr and rename pm event.
fix lockdep splat

Signed-off-by: Riana Tauro <riana.tauro at intel.com>
---
 drivers/gpu/drm/xe/xe_pmu.c       | 44 +++++++------------------------
 drivers/gpu/drm/xe/xe_pmu_types.h | 16 +++++------
 2 files changed, 18 insertions(+), 42 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
index 7e2b9d74a6f3..bae8eb38fddd 100644
--- a/drivers/gpu/drm/xe/xe_pmu.c
+++ b/drivers/gpu/drm/xe/xe_pmu.c
@@ -260,19 +260,13 @@ static u64 get_c6(struct xe_gt *gt)
 	struct xe_device *xe = gt_to_xe(gt);
 	const unsigned int gt_id = gt->info.id;
 	struct xe_pmu *pmu = &xe->pmu;
-	bool device_awake;
 	unsigned long flags;
 	u64 val;
 
-	device_awake = xe_pm_runtime_get_if_active(xe);
-	if (device_awake) {
-		val = xe_gt_idle_residency_msec(&gt->gtidle);
-		xe_pm_runtime_put(xe);
-	}
-
 	raw_spin_lock_irqsave(&pmu->lock, flags);
 
-	if (device_awake) {
+	if (!xe_pm_runtime_suspended(xe)) {
+		val = xe_gt_idle_residency_msec(&gt->gtidle);
 		store_sample(pmu, gt_id, __XE_SAMPLE_C6, val);
 	} else {
 		/*
@@ -376,7 +370,6 @@ frequency_sample(struct xe_gt *gt, unsigned int period_ns)
 	struct xe_device *xe = gt_to_xe(gt);
 	const unsigned int gt_id = gt->info.id;
 	struct xe_pmu *pmu = &xe->pmu;
-	bool device_awake;
 	int ret;
 	u32 cur_freq;
 
@@ -384,8 +377,7 @@ frequency_sample(struct xe_gt *gt, unsigned int period_ns)
 		return;
 
 	/* Report 0/0 (actual/requested) frequency while GT is suspended. */
-	device_awake = xe_pm_runtime_get_if_active(xe);
-	if (!device_awake)
+	if (xe_pm_runtime_suspended(xe))
 		return;
 
 	if (pmu->enable & config_mask(__XE_PMU_ACTUAL_FREQUENCY(gt_id))) {
@@ -495,14 +487,11 @@ static void xe_pmu_enable(struct perf_event *event)
 	struct xe_gt *gt;
 	const unsigned int bit = event_bit(event);
 	unsigned long flags;
-	bool device_awake;
 	unsigned int i;
 
 	if (bit == -1)
 		goto update;
 
-	device_awake = xe_pm_runtime_get_if_active(xe);
-
 	raw_spin_lock_irqsave(&pmu->lock, flags);
 
 	/*
@@ -522,10 +511,9 @@ static void xe_pmu_enable(struct perf_event *event)
 	__xe_pmu_maybe_start_timer(pmu);
 
 	/* Set active GTs in case system is not currently suspended */
-	if (device_awake) {
+	if (!xe_pm_runtime_suspended(xe)) {
 		for_each_gt(gt, xe, i)
 			pmu->active_gts |= BIT(gt->info.id);
-		xe_pm_runtime_put(xe);
 	}
 
 	raw_spin_unlock_irqrestore(&pmu->lock, flags);
@@ -626,24 +614,12 @@ struct xe_str_attribute {
 	const char *str;
 };
 
-static ssize_t xe_pmu_format_show(struct device *dev,
-				  struct device_attribute *attr, char *buf)
-{
-	struct xe_str_attribute *eattr;
-
-	eattr = container_of(attr, struct xe_str_attribute, attr);
-	return sprintf(buf, "%s\n", eattr->str);
-}
-
-#define XE_PMU_FORMAT_ATTR(_name, _config) \
-	(&((struct xe_str_attribute[]) { \
-		{ .attr = __ATTR(_name, 0444, xe_pmu_format_show, NULL), \
-		.str = _config, } \
-	})[0].attr.attr)
+PMU_FORMAT_ATTR(event,          "config:0-11");
+PMU_FORMAT_ATTR(gt_id,          "config:60-63");
 
 static struct attribute *xe_pmu_format_attrs[] = {
-	XE_PMU_FORMAT_ATTR(event_id, "config:0-20"),
-	XE_PMU_FORMAT_ATTR(gt_id, "config:60-63"),
+	&format_attr_event.attr,
+	&format_attr_gt_id.attr,
 	NULL,
 };
 
@@ -737,7 +713,7 @@ create_event_attributes(struct xe_pmu *pmu)
 
 	/* Count how many counters we will be exposing. */
 	for (i = 0; i < ARRAY_SIZE(events); i++) {
-		u64 config = __XE_PMU_PM(events[i].counter);
+		u64 config = __XE_PMU_EVENT(events[i].counter);
 
 		if (!config_status(xe, config))
 			count++;
@@ -762,7 +738,7 @@ create_event_attributes(struct xe_pmu *pmu)
 	attr_iter = attr;
 
 	for (i = 0; i < ARRAY_SIZE(events); i++) {
-		u64 config = __XE_PMU_PM(events[i].counter);
+		u64 config = __XE_PMU_EVENT(events[i].counter);
 		char *str;
 
 		if (config_status(xe, config))
diff --git a/drivers/gpu/drm/xe/xe_pmu_types.h b/drivers/gpu/drm/xe/xe_pmu_types.h
index 5d873bae4a0d..0109bb11937b 100644
--- a/drivers/gpu/drm/xe/xe_pmu_types.h
+++ b/drivers/gpu/drm/xe/xe_pmu_types.h
@@ -24,17 +24,17 @@ enum {
  */
 #define __XE_PMU_GT_SHIFT (60)
 
-#define ___XE_PMU_PM(gt, x) \
+#define ___XE_PMU_EVENT(gt, x) \
 	(((__u64)(x)) | ((__u64)(gt) << __XE_PMU_GT_SHIFT))
 
-#define __XE_PMU_PM(x) ___XE_PMU_PM(0, x)
+#define __XE_PMU_EVENT(x) ___XE_PMU_EVENT(0, x)
 
-#define XE_PMU_C6_RESIDENCY                    __XE_PMU_PM(0)
-#define XE_PMU_ACTUAL_FREQUENCY			__XE_PMU_PM(1)
-#define XE_PMU_REQUESTED_FREQUENCY		__XE_PMU_PM(2)
-#define __XE_PMU_C6_RESIDENCY(gt)              ___XE_PMU_PM(gt, 0)
-#define __XE_PMU_ACTUAL_FREQUENCY(gt)		___XE_PMU_PM(gt, 1)
-#define __XE_PMU_REQUESTED_FREQUENCY(gt)	___XE_PMU_PM(gt, 2)
+#define XE_PMU_C6_RESIDENCY                    __XE_PMU_EVENT(0)
+#define XE_PMU_ACTUAL_FREQUENCY			__XE_PMU_EVENT(1)
+#define XE_PMU_REQUESTED_FREQUENCY		__XE_PMU_EVENT(2)
+#define __XE_PMU_C6_RESIDENCY(gt)              ___XE_PMU_EVENT(gt, 0)
+#define __XE_PMU_ACTUAL_FREQUENCY(gt)		___XE_PMU_EVENT(gt, 1)
+#define __XE_PMU_REQUESTED_FREQUENCY(gt)	___XE_PMU_EVENT(gt, 2)
 
 /*
  * Non-engine events that we need to track enabled-disabled transition and
-- 
2.47.1



More information about the Intel-xe mailing list