Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] drm/xe/pmu: Add GT frequency events
@ 2025-03-24 23:24 Vinay Belgaumkar
  2025-03-25  0:18 ` Dixit, Ashutosh
                   ` (8 more replies)
  0 siblings, 9 replies; 23+ messages in thread
From: Vinay Belgaumkar @ 2025-03-24 23:24 UTC (permalink / raw)
  To: intel-xe; +Cc: Vinay Belgaumkar, Riana Tauro, Lucas De Marchi, Rodrigo Vivi

Define PMU events for GT frequency (actual and requested). The
instantaneous values for these frequencies will be displayed.

Following PMU events are being added:
  xe_0000_00_02.0/gt-actual-frequency/              [Kernel PMU event]
  xe_0000_00_02.0/gt-requested-frequency/           [Kernel PMU event]

Standard perf commands can be used to monitor GT frequency:
  $ perf stat -e xe_0000_00_02.0/gt-requested-frequency,gt=0/ -I1000

  1.001229762       1483 Mhz  xe_0000_00_02.0/gt-requested-frequency,gt=0/
  2.006175406       1483 Mhz  xe_0000_00_02.0/gt-requested-frequency,gt=0/

v2: Use locks while storing/reading samples, keep track of multiple
clients (Lucas) and other general cleanup.
v3: Review comments (Lucas) and use event counts instead of mask for
active events.
v4: Add freq events to event_param_valid method (Riana)
v5: Use instantaneous values instead of aggregating (Lucas)

Cc: Riana Tauro <riana.tauro@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
---
 drivers/gpu/drm/xe/xe_pmu.c | 40 +++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
index 4f62a6e515d6..4e2e891e7655 100644
--- a/drivers/gpu/drm/xe/xe_pmu.c
+++ b/drivers/gpu/drm/xe/xe_pmu.c
@@ -10,6 +10,7 @@
 #include "xe_force_wake.h"
 #include "xe_gt_idle.h"
 #include "xe_guc_engine_activity.h"
+#include "xe_guc_pc.h"
 #include "xe_hw_engine.h"
 #include "xe_pm.h"
 #include "xe_pmu.h"
@@ -76,6 +77,8 @@ static unsigned int config_to_gt_id(u64 config)
 #define XE_PMU_EVENT_GT_C6_RESIDENCY		0x01
 #define XE_PMU_EVENT_ENGINE_ACTIVE_TICKS	0x02
 #define XE_PMU_EVENT_ENGINE_TOTAL_TICKS		0x03
+#define XE_PMU_EVENT_GT_ACTUAL_FREQUENCY	0x04
+#define XE_PMU_EVENT_GT_REQUESTED_FREQUENCY	0x05
 
 static struct xe_gt *event_to_gt(struct perf_event *event)
 {
@@ -163,6 +166,8 @@ static bool event_param_valid(struct perf_event *event)
 	engine_instance = config_to_engine_instance(config);
 
 	switch (config_to_event_id(config)) {
+	case XE_PMU_EVENT_GT_ACTUAL_FREQUENCY:
+	case XE_PMU_EVENT_GT_REQUESTED_FREQUENCY:
 	case XE_PMU_EVENT_GT_C6_RESIDENCY:
 		if (engine_class || engine_instance)
 			return false;
@@ -172,6 +177,8 @@ static bool event_param_valid(struct perf_event *event)
 		if (!event_to_hwe(event))
 			return false;
 		break;
+	default:
+		return false;
 	}
 
 	return true;
@@ -256,6 +263,7 @@ static u64 read_engine_events(struct xe_gt *gt, struct perf_event *event)
 static u64 __xe_pmu_event_read(struct perf_event *event)
 {
 	struct xe_gt *gt = event_to_gt(event);
+	u32 cur_gt_freq;
 
 	if (!gt)
 		return 0;
@@ -266,11 +274,24 @@ static u64 __xe_pmu_event_read(struct perf_event *event)
 	case XE_PMU_EVENT_ENGINE_ACTIVE_TICKS:
 	case XE_PMU_EVENT_ENGINE_TOTAL_TICKS:
 		return read_engine_events(gt, event);
+	case XE_PMU_EVENT_GT_ACTUAL_FREQUENCY:
+		return xe_guc_pc_get_act_freq(&gt->uc.guc.pc);
+	case XE_PMU_EVENT_GT_REQUESTED_FREQUENCY:
+		if (!xe_guc_pc_get_cur_freq(&gt->uc.guc.pc, &cur_gt_freq))
+			return cur_gt_freq;
 	}
 
 	return 0;
 }
 
+static bool is_gt_frequency_event(struct perf_event *event)
+{
+	uint32_t id = config_to_event_id(event->attr.config);
+
+	return (id == XE_PMU_EVENT_GT_ACTUAL_FREQUENCY) ||
+	       (id == XE_PMU_EVENT_GT_REQUESTED_FREQUENCY);
+}
+
 static void xe_pmu_event_update(struct perf_event *event)
 {
 	struct hw_perf_event *hwc = &event->hw;
@@ -281,7 +302,13 @@ static void xe_pmu_event_update(struct perf_event *event)
 		new = __xe_pmu_event_read(event);
 	} while (!local64_try_cmpxchg(&hwc->prev_count, &prev, new));
 
-	local64_add(new - prev, &event->count);
+	/* GT frequency is not a monotonically increasing counter, so record the
+	 * instantaneous value instead.
+	 */
+	if (is_gt_frequency_event(event))
+		local64_add(new, &event->count);
+	else
+		local64_add(new - prev, &event->count);
 }
 
 static void xe_pmu_event_read(struct perf_event *event)
@@ -419,6 +446,10 @@ static ssize_t event_attr_show(struct device *dev,
 XE_EVENT_ATTR_SIMPLE(gt-c6-residency, gt_c6_residency, XE_PMU_EVENT_GT_C6_RESIDENCY, "ms");
 XE_EVENT_ATTR_NOUNIT(engine-active-ticks, engine_active_ticks, XE_PMU_EVENT_ENGINE_ACTIVE_TICKS);
 XE_EVENT_ATTR_NOUNIT(engine-total-ticks, engine_total_ticks, XE_PMU_EVENT_ENGINE_TOTAL_TICKS);
+XE_EVENT_ATTR_SIMPLE(gt-actual-frequency, gt_actual_frequency,
+		     XE_PMU_EVENT_GT_ACTUAL_FREQUENCY, "Mhz");
+XE_EVENT_ATTR_SIMPLE(gt-requested-frequency, gt_requested_frequency,
+		     XE_PMU_EVENT_GT_REQUESTED_FREQUENCY, "Mhz");
 
 static struct attribute *pmu_empty_event_attrs[] = {
 	/* Empty - all events are added as groups with .attr_update() */
@@ -434,6 +465,8 @@ static const struct attribute_group *pmu_events_attr_update[] = {
 	&pmu_group_gt_c6_residency,
 	&pmu_group_engine_active_ticks,
 	&pmu_group_engine_total_ticks,
+	&pmu_group_gt_actual_frequency,
+	&pmu_group_gt_requested_frequency,
 	NULL,
 };
 
@@ -442,8 +475,11 @@ static void set_supported_events(struct xe_pmu *pmu)
 	struct xe_device *xe = container_of(pmu, typeof(*xe), pmu);
 	struct xe_gt *gt = xe_device_get_gt(xe, 0);
 
-	if (!xe->info.skip_guc_pc)
+	if (!xe->info.skip_guc_pc) {
 		pmu->supported_events |= BIT_ULL(XE_PMU_EVENT_GT_C6_RESIDENCY);
+		pmu->supported_events |= BIT_ULL(XE_PMU_EVENT_GT_ACTUAL_FREQUENCY);
+		pmu->supported_events |= BIT_ULL(XE_PMU_EVENT_GT_REQUESTED_FREQUENCY);
+	}
 
 	if (xe_guc_engine_activity_supported(&gt->uc.guc)) {
 		pmu->supported_events |= BIT_ULL(XE_PMU_EVENT_ENGINE_ACTIVE_TICKS);
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2025-03-26 22:38 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-24 23:24 [PATCH v4] drm/xe/pmu: Add GT frequency events Vinay Belgaumkar
2025-03-25  0:18 ` Dixit, Ashutosh
2025-03-25  2:37   ` Belgaumkar, Vinay
2025-03-25 17:15     ` Dixit, Ashutosh
2025-03-25 20:33       ` Belgaumkar, Vinay
2025-03-25 21:53         ` Dixit, Ashutosh
2025-03-25 22:01           ` Belgaumkar, Vinay
2025-03-25 22:45             ` Dixit, Ashutosh
2025-03-25 23:02               ` Belgaumkar, Vinay
2025-03-26  4:09               ` Lucas De Marchi
2025-03-26  4:14                 ` Lucas De Marchi
2025-03-26 15:02                   ` Dixit, Ashutosh
2025-03-26 15:34                     ` Lucas De Marchi
2025-03-26 22:02                   ` Belgaumkar, Vinay
2025-03-26 22:38                     ` Dixit, Ashutosh
2025-03-25  0:29 ` ✓ CI.Patch_applied: success for drm/xe/pmu: Add GT frequency events (rev6) Patchwork
2025-03-25  0:29 ` ✗ CI.checkpatch: warning " Patchwork
2025-03-25  0:30 ` ✓ CI.KUnit: success " Patchwork
2025-03-25  0:47 ` ✓ CI.Build: " Patchwork
2025-03-25  0:49 ` ✓ CI.Hooks: " Patchwork
2025-03-25  0:50 ` ✓ CI.checksparse: " Patchwork
2025-03-25  1:11 ` ✓ Xe.CI.BAT: " Patchwork
2025-03-25  6:04 ` ✗ Xe.CI.Full: failure " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox