Skip to contentSkip to conversation

Support perf stat with i915 PMU

RFC New Dmitry Rogozhkin 1 participant 6 messages Sep 2, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover Support perf stat with i915 PMU

These patches depend on the RFC patches enabling i915 PMU from Tvrtko:
https://patchwork.freedesktop.org/series/27488/
Thus, CI failure to build them is expected. I think that my patches should be squeashed in Tvrtko's one actually.

The first patch simply reorders functions and does nothing comparing to Tvrtko's patches. Next patches add fixes according to PMU API comments and clarifications from PMU aware engineers.

v1: Make busy_stats refcounted instead of the whole pmu.

v2: Expose cpumask for the i915 pmu to prevent creation of multiple events
of the same type. Remove perf-driver level sampling.

v3: Add CPUs online/offline tracking to form cpumask.

v4: Add i915_pmu_enable_info debugfs entry. Introduce refcounting of event
subscriptions.

Cc Tvrtko Ursulin <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Peter Zijlstra <[email protected]>

Dmitry Rogozhkin (5):
drm/i915/pmu: reorder function to suite next patch drm/i915/pmu: serve global events and support perf stat drm/i915/pmu: introduce i915_pmu_enable_info debugfs entry drm/i915/pmu: introduce refcounting of event subscriptions drm/i915/pmu: deny perf driver level sampling of i915 PMU

 drivers/gpu/drm/i915/i915_debugfs.c     |   9 +
 drivers/gpu/drm/i915/i915_drv.h         |  20 +-
 drivers/gpu/drm/i915/i915_pmu.c         | 404 +++++++++++++++++---------------
 drivers/gpu/drm/i915/intel_ringbuffer.h |   5 +-
 include/uapi/drm/i915_drm.h             |  28 ++-
 5 files changed, 262 insertions(+), 204 deletions(-)
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

RFC v4 1/5 drm/i915/pmu: reorder function to suite next patch

This patch is doing nover except reordering functions to highlight changes in the next patch.

Change-Id I0cd298780503ae8f6f8035b86c59fc8b5191356b
Cc Tvrtko Ursulin <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 drivers/gpu/drm/i915/i915_pmu.c | 180 ++++++++++++++++++++--------------------
 1 file changed, 90 insertions(+), 90 deletions(-)
drivers/gpu/drm/i915/i915_pmu.c +90 -90
index 3272ec0..bcdf2bc 100644
@@ -363,6 +363,88 @@ static bool engine_needs_busy_stats(struct intel_engine_cs *engine)
 	       (engine->pmu.enable & BIT(I915_SAMPLE_BUSY));
 }
 
+static u64 count_interrupts(struct drm_i915_private *i915)
+{
+	/* open-coded kstat_irqs() */
+	struct irq_desc *desc = irq_to_desc(i915->drm.pdev->irq);
+	u64 sum = 0;
+	int cpu;
+
+	if (!desc || !desc->kstat_irqs)
+		return 0;
+
+	for_each_possible_cpu(cpu)
+		sum += *per_cpu_ptr(desc->kstat_irqs, cpu);
+
+	return sum;
+}
+
+static void i915_pmu_event_read(struct perf_event *event)
+{
+	struct drm_i915_private *i915 =
+		container_of(event->pmu, typeof(*i915), pmu.base);
+	u64 val = 0;
+
+	if (is_engine_event(event)) {
+		u8 sample = engine_event_sample(event);
+		struct intel_engine_cs *engine;
+
+		engine = intel_engine_lookup_user(i915,
+						  engine_event_class(event),
+						  engine_event_instance(event));
+
+		if (WARN_ON_ONCE(!engine)) {
+			/* Do nothing */
+		} else if (sample == I915_SAMPLE_BUSY &&
+			   engine->pmu.busy_stats) {
+			val = ktime_to_ns(intel_engine_get_busy_time(engine));
+		} else {
+			val = engine->pmu.sample[sample];
+		}
+	} else switch (event->attr.config) {
+	case I915_PMU_ACTUAL_FREQUENCY:
+		val = i915->pmu.sample[__I915_SAMPLE_FREQ_ACT];
+		break;
+	case I915_PMU_REQUESTED_FREQUENCY:
+		val = i915->pmu.sample[__I915_SAMPLE_FREQ_REQ];
+		break;
+	case I915_PMU_ENERGY:
+		val = intel_energy_uJ(i915);
+		break;
+	case I915_PMU_INTERRUPTS:
+		val = count_interrupts(i915);
+		break;
+
+	case I915_PMU_RC6_RESIDENCY:
+		if (!i915->gt.awake)
+			return;
+
+		val = intel_rc6_residency_ns(i915,
+					     IS_VALLEYVIEW(i915) ?
+					     VLV_GT_RENDER_RC6 :
+					     GEN6_GT_GFX_RC6);
+		break;
+
+	case I915_PMU_RC6p_RESIDENCY:
+		if (!i915->gt.awake)
+			return;
+
+		if (!IS_VALLEYVIEW(i915))
+			val = intel_rc6_residency_ns(i915, GEN6_GT_GFX_RC6p);
+		break;
+
+	case I915_PMU_RC6pp_RESIDENCY:
+		if (!i915->gt.awake)
+			return;
+
+		if (!IS_VALLEYVIEW(i915))
+			val = intel_rc6_residency_ns(i915, GEN6_GT_GFX_RC6pp);
+		break;
+	}
+
+	local64_set(&event->count, val);
+}
+
 static void i915_pmu_enable(struct perf_event *event)
 {
 	struct drm_i915_private *i915 =
@@ -440,23 +522,6 @@ static void i915_pmu_disable(struct perf_event *event)
 	i915_pmu_timer_cancel(event);
 }
 
-static int i915_pmu_event_add(struct perf_event *event, int flags)
-{
-	struct hw_perf_event *hwc = &event->hw;
-
-	if (flags & PERF_EF_START)
-		i915_pmu_enable(event);
-
-	hwc->state = !(flags & PERF_EF_START);
-
-	return 0;
-}
-
-static void i915_pmu_event_del(struct perf_event *event, int flags)
-{
-	i915_pmu_disable(event);
-}
-
 static void i915_pmu_event_start(struct perf_event *event, int flags)
 {
 	i915_pmu_enable(event);
@@ -467,86 +532,21 @@ static void i915_pmu_event_stop(struct perf_event *event, int flags)
 	i915_pmu_disable(event);
 }
 
-static u64 count_interrupts(struct drm_i915_private *i915)
+static int i915_pmu_event_add(struct perf_event *event, int flags)
 {
-	/* open-coded kstat_irqs() */
-	struct irq_desc *desc = irq_to_desc(i915->drm.pdev->irq);
-	u64 sum = 0;
-	int cpu;
+	struct hw_perf_event *hwc = &event->hw;
 
-	if (!desc || !desc->kstat_irqs)
-		return 0;
+	if (flags & PERF_EF_START)
+		i915_pmu_enable(event);
 
-	for_each_possible_cpu(cpu)
-		sum += *per_cpu_ptr(desc->kstat_irqs, cpu);
+	hwc->state = !(flags & PERF_EF_START);
 
-	return sum;
+	return 0;
 }
 
-static void i915_pmu_event_read(struct perf_event *event)
+static void i915_pmu_event_del(struct perf_event *event, int flags)
 {
-	struct drm_i915_private *i915 =
-		container_of(event->pmu, typeof(*i915), pmu.base);
-	u64 val = 0;
-
-	if (is_engine_event(event)) {
-		u8 sample = engine_event_sample(event);
-		struct intel_engine_cs *engine;
-
-		engine = intel_engine_lookup_user(i915,
-						  engine_event_class(event),
-						  engine_event_instance(event));
-
-		if (WARN_ON_ONCE(!engine)) {
-			/* Do nothing */
-		} else if (sample == I915_SAMPLE_BUSY &&
-			   engine->pmu.busy_stats) {
-			val = ktime_to_ns(intel_engine_get_busy_time(engine));
-		} else {
-			val = engine->pmu.sample[sample];
-		}
-	} else switch (event->attr.config) {
-	case I915_PMU_ACTUAL_FREQUENCY:
-		val = i915->pmu.sample[__I915_SAMPLE_FREQ_ACT];
-		break;
-	case I915_PMU_REQUESTED_FREQUENCY:
-		val = i915->pmu.sample[__I915_SAMPLE_FREQ_REQ];
-		break;
-	case I915_PMU_ENERGY:
-		val = intel_energy_uJ(i915);
-		break;
-	case I915_PMU_INTERRUPTS:
-		val = count_interrupts(i915);
-		break;
-
-	case I915_PMU_RC6_RESIDENCY:
-		if (!i915->gt.awake)
-			return;
-
-		val = intel_rc6_residency_ns(i915,
-					     IS_VALLEYVIEW(i915) ?
-					     VLV_GT_RENDER_RC6 :
-					     GEN6_GT_GFX_RC6);
-		break;
-
-	case I915_PMU_RC6p_RESIDENCY:
-		if (!i915->gt.awake)
-			return;
-
-		if (!IS_VALLEYVIEW(i915))
-			val = intel_rc6_residency_ns(i915, GEN6_GT_GFX_RC6p);
-		break;
-
-	case I915_PMU_RC6pp_RESIDENCY:
-		if (!i915->gt.awake)
-			return;
-
-		if (!IS_VALLEYVIEW(i915))
-			val = intel_rc6_residency_ns(i915, GEN6_GT_GFX_RC6pp);
-		break;
-	}
-
-	local64_set(&event->count, val);
+	i915_pmu_disable(event);
 }
 
 static int i915_pmu_event_event_idx(struct perf_event *event)
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

RFC v4 2/5 drm/i915/pmu: serve global events and support perf stat

In reply to Dmitry Rogozhkin

This patch should probably be squashed with Tvrtko's PMU enabling patch...

Making perf-stat workable with i915 PMU. The major point is that current implementation of i915 PMU exposes global counter rather thatn per-task counters. Thus, required changes are:
* Register PMU with .task_ctx_nr=perf_invalid_context
* Expose cpumask for the PMU with the single CPU in the mask
* Properly support pmu->stop(): it should call pmu->read()
* Properly support pmu->del(): it should call stop(event, PERF_EF_UPDATE)

Examples:
perf stat -e i915/rcs0-busy/ workload.sh
This should error out with "failed to read counter" because the
requested counter can't be queried in per-task mode (which is the case).

perf stat -e i915/rcs0-busy/ -a workload.sh
perf stat -e i915/rcs0-busy/ -a -C0 workload.sh
These 2 commands should give the same result with the correct counter
values. Counter value will be queried once in the end of the wrokload. The example output would be:

Performance counter stats for 'system wide':

       649,547,987      i915/rcs0-busy/

       1.895530680 seconds time elapsed

perf stat -e i915/rcs0-busy/ -a -I 100 workload.sh
This will query counter perdiodically (each 100ms) and dump output:

     0.100108369          4,137,438      i915/rcs0-busy/
i915/rcs0-busy/: 37037414 100149071 100149071
     0.200249024         37,037,414      i915/rcs0-busy/
i915/rcs0-busy/: 36935429 100145077 100145077
     0.300391916         36,935,429      i915/rcs0-busy/
i915/rcs0-busy/: 34262017 100126136 100126136
     0.400518037         34,262,017      i915/rcs0-busy/

i915/rcs0-busy/: 34539960 100126217 100126217

v1: Make pmu.busy_stats a refcounter to avoid busy stats going away
with some deleted event.

v2: Expose cpumask for i915 PMU to avoid multiple events creation of
the same type followed by counter aggregation by perf-stat.

v3: Track CPUs getting online/offline to migrate perf context. If (likely)
cpumask will initially set CPU0, CONFIG_BOOTPARAM_HOTPLUG_CPU0 will be needed to see effect of CPU status tracking.

Change-Id I7d1abe747a4399196e72253f7b66441a6528dbee
Cc Tvrtko Ursulin <[email protected]>
Cc Peter Zijlstra <[email protected]>

cpumask

Change-Id I145f59240b75f2b703e0531ec81af6cd05aae95c
---
 drivers/gpu/drm/i915/i915_drv.h         |  19 +++---
 drivers/gpu/drm/i915/i915_pmu.c         | 115 +++++++++++++++++++++++++++-----
 drivers/gpu/drm/i915/intel_ringbuffer.h |   2 +-
 3 files changed, 110 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +11 -8
index b59da2c..e629e5e 100644
@@ -2153,6 +2153,16 @@ enum {
 	__I915_NUM_PMU_SAMPLERS
 };
 
+struct i915_pmu {
+	struct hlist_node node;
+	struct pmu base;
+	spinlock_t lock;
+	struct hrtimer timer;
+	bool timer_enabled;
+	u64 enable;
+	u64 sample[__I915_NUM_PMU_SAMPLERS];
+};
+
 struct drm_i915_private {
 	struct drm_device drm;
 
@@ -2660,14 +2670,7 @@ struct drm_i915_private {
 		int	irq;
 	} lpe_audio;
 
-	struct {
-		struct pmu base;
-		spinlock_t lock;
-		struct hrtimer timer;
-		bool timer_enabled;
-		u64 enable;
-		u64 sample[__I915_NUM_PMU_SAMPLERS];
-	} pmu;
+	struct i915_pmu pmu;
 
 	/*
 	 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
drivers/gpu/drm/i915/i915_pmu.c +98 -17

195 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +1 -1
index fd5d838..0530e4e 100644
@@ -248,7 +248,7 @@ struct intel_engine_cs {
 	struct {
 		u32 enable;
 		u64 sample[4];
-		bool busy_stats;
+		unsigned int busy_stats;
 		struct work_struct enable_busy_stats;
 		struct delayed_work disable_busy_stats;
 	} pmu;
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

RFC v4 3/5 drm/i915/pmu: introduce i915_pmu_enable_info debugfs entry

In reply to Dmitry Rogozhkin

With the exposure of i915 PMU event enabling mask we will be able to implement IGT tests to see whether we properly handle events enabling/disabling on multiple parallel consumers.

Change-Id I3561e48cd27bc2a19424cf7b6949fadb2a77ab20
Cc Tvrtko Ursulin <[email protected]>
---
 drivers/gpu/drm/i915/i915_debugfs.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/i915/i915_debugfs.c +9 -0
index a2587c1..684607e 100644
@@ -2315,6 +2315,14 @@ static int i915_rps_boost_info(struct seq_file *m, void *data)
 	return 0;
 }
 
+static int i915_pmu_enable_info(struct seq_file *m, void *data)
+{
+	struct drm_i915_private *dev_priv = node_to_i915(m->private);
+
+	seq_printf(m, "0x%llx\n", dev_priv->pmu.enable);
+	return 0;
+}
+
 static int i915_llc(struct seq_file *m, void *data)
 {
 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
@@ -4898,6 +4906,7 @@ static ssize_t i915_engine_stats_read(struct file *file, char __user *ubuf,
 	{"i915_sseu_status", i915_sseu_status, 0},
 	{"i915_drrs_status", i915_drrs_status, 0},
 	{"i915_rps_boost_info", i915_rps_boost_info, 0},
+	{"i915_pmu_enable_info", i915_pmu_enable_info, 0}
 };
 #define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
 
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

RFC v4 4/5 drm/i915/pmu: introduce refcounting of event subscriptions

In reply to Dmitry Rogozhkin

As 'enable' i915 PMU IGT test will show, current PMU implementation does not properly handle multiple parallel consumers. This patch introduces refcounting of event subscriptions meaning that even if one consumer will disable its event PMU event mask will not fly away if there are other subscribers for this event.

Change-Id I0d787f5feab988ad3c8af6d7ad70fb26d5839263
Cc Tvrtko Ursulin <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.h         |  1 +
 drivers/gpu/drm/i915/i915_pmu.c         | 38 ++++++++++++++++++++++++++++++---
 drivers/gpu/drm/i915/intel_ringbuffer.h |  3 ++-
 include/uapi/drm/i915_drm.h             | 28 +++++++++++++++++-------
 4 files changed, 58 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index e629e5e..8bb967a 100644
@@ -2160,6 +2160,7 @@ struct i915_pmu {
 	struct hrtimer timer;
 	bool timer_enabled;
 	u64 enable;
+	unsigned int enable_count[I915_SAMPLE_MAX];
 	u64 sample[__I915_NUM_PMU_SAMPLERS];
 };
 
drivers/gpu/drm/i915/i915_pmu.c +35 -3
index 7bfedb7..5f32356 100644
@@ -17,6 +17,16 @@
 
 static cpumask_t i915_pmu_cpumask = CPU_MASK_NONE;
 
+static u8 i915_config_sample(u64 config)
+{
+	return config - __I915_PMU_OTHER(0);
+}
+
+static u8 i915_event_sample(struct perf_event *event)
+{
+	return i915_config_sample(event->attr.config);
+}
+
 static u8 engine_config_sample(u64 config)
 {
 	return config & I915_PMU_SAMPLE_MASK;
@@ -56,6 +66,11 @@ static bool is_engine_event(struct perf_event *event)
 	return is_engine_config(event->attr.config);
 }
 
+static bool is_event_sample_busy(struct perf_event *event)
+{
+	return is_engine_event(event) && BIT(engine_event_sample(event));
+}
+
 static u64 event_enabled_mask(struct perf_event *event)
 {
 	return config_enabled_mask(event->attr.config);
@@ -470,7 +485,10 @@ static void i915_pmu_enable(struct perf_event *event)
 						  engine_event_class(event),
 						  engine_event_instance(event));
 		GEM_BUG_ON(!engine);
+		++engine->pmu.enable_count[engine_event_sample(event)];
 		engine->pmu.enable |= BIT(engine_event_sample(event));
+	} else {
+		++i915->pmu.enable_count[i915_event_sample(event)];
 	}
 
 	i915->pmu.enable |= event_enabled_mask(event);
@@ -480,7 +498,8 @@ static void i915_pmu_enable(struct perf_event *event)
 				       ns_to_ktime(PERIOD), 0,
 				       HRTIMER_MODE_REL_PINNED);
 		i915->pmu.timer_enabled = true;
-	} else if (is_engine_event(event) && engine_needs_busy_stats(engine)) {
+	}
+	if (is_event_sample_busy(event) && supports_busy_stats()) {
 		/* Enable busy stats for the first event demanding it, next
 		 * events just reference counter. So, if some events will go
 		 * away, we will still have busy stats enabled till remaining
@@ -514,7 +533,13 @@ static void i915_pmu_disable(struct perf_event *event)
 						engine_event_class(event),
 						engine_event_instance(event));
 		GEM_BUG_ON(!engine);
-		engine->pmu.enable &= ~BIT(engine_event_sample(event));
+
+		GEM_BUG_ON(engine->pmu.enable_count[engine_event_sample(event)] == 0);
+
+		if (engine->pmu.enable_count[engine_event_sample(event)] &&
+			--engine->pmu.enable_count[engine_event_sample(event)] == 0) {
+			engine->pmu.enable &= ~BIT(engine_event_sample(event));
+		}
 		if (!engine_needs_busy_stats(engine)) {
 			if (engine->pmu.busy_stats && --engine->pmu.busy_stats == 0) {
 				queue_delayed_work(i915->wq,
@@ -527,7 +552,14 @@ static void i915_pmu_disable(struct perf_event *event)
 			mask |= engine->pmu.enable;
 		mask = (~mask) & ENGINE_SAMPLE_MASK;
 	} else {
-		mask = event_enabled_mask(event);
+		mask = i915->pmu.enable;
+		GEM_BUG_ON(i915->pmu.enable_count[i915_event_sample(event)]);
+
+		if (i915->pmu.enable_count[i915_event_sample(event)] &&
+			--i915->pmu.enable_count[i915_event_sample(event)] == 0) {
+			mask &= ~event_enabled_mask(event);
+		}
+		mask = ~mask;
 	}
 
 	i915->pmu.enable &= ~mask;
drivers/gpu/drm/i915/intel_ringbuffer.h +2 -1
index 0530e4e..1841155 100644
@@ -247,7 +247,8 @@ struct intel_engine_cs {
 
 	struct {
 		u32 enable;
-		u64 sample[4];
+		u32 enable_count[I915_ENGINE_SAMPLE_MAX];
+		u64 sample[I915_ENGINE_SAMPLE_MAX];
 		unsigned int busy_stats;
 		struct work_struct enable_busy_stats;
 		struct delayed_work disable_busy_stats;
include/uapi/drm/i915_drm.h +20 -8
index 28bff96..7fa22aa 100644
@@ -104,7 +104,19 @@ enum drm_i915_pmu_engine_sample {
 	I915_SAMPLE_QUEUED = 0,
 	I915_SAMPLE_BUSY = 1,
 	I915_SAMPLE_WAIT = 2,
-	I915_SAMPLE_SEMA = 3
+	I915_SAMPLE_SEMA = 3,
+	I915_ENGINE_SAMPLE_MAX /* non-ABI*/
+};
+
+enum drm_i915_pmu_sample {
+	I915_SAMPLE_ACTUAL_FREQUENCY = 0,
+	I915_SAMPLE_REQUESTED_FREQUENCY = 1,
+	I915_SAMPLE_ENERGY = 2,
+	I915_SAMPLE_INTERRUPTS = 3,
+	I915_SAMPLE_RC6_RESIDENCY = 4,
+	I915_SAMPLE_RC6p_RESIDENCY = 5,
+	I915_SAMPLE_RC6pp_RESIDENCY = 6,
+	I915_SAMPLE_MAX /* non-ABI*/
 };
 
 #define I915_PMU_SAMPLE_BITS (4)
@@ -132,14 +144,14 @@ enum drm_i915_pmu_engine_sample {
 
 #define __I915_PMU_OTHER(x) (__I915_PMU_ENGINE(0xff, 0xff, 0xf) + 1 + (x))
 
-#define I915_PMU_ACTUAL_FREQUENCY 	__I915_PMU_OTHER(0)
-#define I915_PMU_REQUESTED_FREQUENCY	__I915_PMU_OTHER(1)
-#define I915_PMU_ENERGY			__I915_PMU_OTHER(2)
-#define I915_PMU_INTERRUPTS		__I915_PMU_OTHER(3)
+#define I915_PMU_ACTUAL_FREQUENCY 	__I915_PMU_OTHER(I915_SAMPLE_ACTUAL_FREQUENCY)
+#define I915_PMU_REQUESTED_FREQUENCY	__I915_PMU_OTHER(I915_SAMPLE_REQUESTED_FREQUENCY)
+#define I915_PMU_ENERGY			__I915_PMU_OTHER(I915_SAMPLE_ENERGY)
+#define I915_PMU_INTERRUPTS		__I915_PMU_OTHER(I915_SAMPLE_INTERRUPTS)
 
-#define I915_PMU_RC6_RESIDENCY		__I915_PMU_OTHER(4)
-#define I915_PMU_RC6p_RESIDENCY		__I915_PMU_OTHER(5)
-#define I915_PMU_RC6pp_RESIDENCY	__I915_PMU_OTHER(6)
+#define I915_PMU_RC6_RESIDENCY		__I915_PMU_OTHER(I915_SAMPLE_RC6_RESIDENCY)
+#define I915_PMU_RC6p_RESIDENCY		__I915_PMU_OTHER(I915_SAMPLE_RC6p_RESIDENCY)
+#define I915_PMU_RC6pp_RESIDENCY	__I915_PMU_OTHER(I915_SAMPLE_RC6pp_RESIDENCY)
 
 /* Each region is a minimum of 16k, and there are at most 255 of them.
  */
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

RFC v4 5/5 drm/i915/pmu: deny perf driver level sampling of i915 PMU

In reply to Dmitry Rogozhkin

This patch should probably be squashed with Tvrtko's PMU enabling patch...

As per discussion with Peter, i915 PMU is an example of uncore PMU which are prohibited to support perf driver level sampling. This patch removes hrtimer which we expose to perf core and denies events creation with non-zero event->attr.sampling_period.

Mind that this patch does _not_ remove i915 PMU _internal_ sampling timer. So, sampling metrics are still gathered, but can be accessed only by explicit request to get metric counter, i.e. by sys_read().

Change-Id I33f345f679f0a5a8ecc9867f9e7c1bfb357e708d
Cc Tvrtko Ursulin <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 drivers/gpu/drm/i915/i915_pmu.c | 89 ++---------------------------------------
 1 file changed, 4 insertions(+), 85 deletions(-)
drivers/gpu/drm/i915/i915_pmu.c +4 -85
index 5f32356..b1327ac 100644
@@ -254,50 +254,6 @@ static int engine_event_init(struct perf_event *event)
 	return 0;
 }
 
-static DEFINE_PER_CPU(struct pt_regs, i915_pmu_pt_regs);
-
-static enum hrtimer_restart hrtimer_sample(struct hrtimer *hrtimer)
-{
-	struct pt_regs *regs = this_cpu_ptr(&i915_pmu_pt_regs);
-	struct perf_sample_data data;
-	struct perf_event *event;
-	u64 period;
-
-	event = container_of(hrtimer, struct perf_event, hw.hrtimer);
-	if (event->state != PERF_EVENT_STATE_ACTIVE)
-		return HRTIMER_NORESTART;
-
-	event->pmu->read(event);
-
-	perf_sample_data_init(&data, 0, event->hw.last_period);
-	perf_event_overflow(event, &data, regs);
-
-	period = max_t(u64, 10000, event->hw.sample_period);
-	hrtimer_forward_now(hrtimer, ns_to_ktime(period));
-	return HRTIMER_RESTART;
-}
-
-static void init_hrtimer(struct perf_event *event)
-{
-	struct hw_perf_event *hwc = &event->hw;
-
-	if (!is_sampling_event(event))
-		return;
-
-	hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-	hwc->hrtimer.function = hrtimer_sample;
-
-	if (event->attr.freq) {
-		long freq = event->attr.sample_freq;
-
-		event->attr.sample_period = NSEC_PER_SEC / freq;
-		hwc->sample_period = event->attr.sample_period;
-		local64_set(&hwc->period_left, hwc->sample_period);
-		hwc->last_period = hwc->sample_period;
-		event->attr.freq = 0;
-	}
-}
-
 static int i915_pmu_event_init(struct perf_event *event)
 {
 	struct drm_i915_private *i915 =
@@ -308,6 +264,10 @@ static int i915_pmu_event_init(struct perf_event *event)
 	if (event->attr.type != event->pmu->type)
 		return -ENOENT;
 
+	/* unsupported modes and filters */
+	if (event->attr.sample_period) /* no sampling */
+		return -EINVAL;
+
 	if (has_branch_stack(event))
 		return -EOPNOTSUPP;
 
@@ -343,46 +303,9 @@ static int i915_pmu_event_init(struct perf_event *event)
 	if (!event->parent)
 		event->destroy = i915_pmu_event_destroy;
 
-	init_hrtimer(event);
-
 	return 0;
 }
 
-static void i915_pmu_timer_start(struct perf_event *event)
-{
-	struct hw_perf_event *hwc = &event->hw;
-	s64 period;
-
-	if (!is_sampling_event(event))
-		return;
-
-	period = local64_read(&hwc->period_left);
-	if (period) {
-		if (period < 0)
-			period = 10000;
-
-		local64_set(&hwc->period_left, 0);
-	} else {
-		period = max_t(u64, 10000, hwc->sample_period);
-	}
-
-	hrtimer_start_range_ns(&hwc->hrtimer,
-			       ns_to_ktime(period), 0,
-			       HRTIMER_MODE_REL_PINNED);
-}
-
-static void i915_pmu_timer_cancel(struct perf_event *event)
-{
-	struct hw_perf_event *hwc = &event->hw;
-
-	if (!is_sampling_event(event))
-		return;
-
-	local64_set(&hwc->period_left,
-		    ktime_to_ns(hrtimer_get_remaining(&hwc->hrtimer)));
-	hrtimer_cancel(&hwc->hrtimer);
-}
-
 static bool engine_needs_busy_stats(struct intel_engine_cs *engine)
 {
 	return supports_busy_stats() &&
@@ -512,8 +435,6 @@ static void i915_pmu_enable(struct perf_event *event)
 	}
 
 	spin_unlock_irqrestore(&i915->pmu.lock, flags);
-
-	i915_pmu_timer_start(event);
 }
 
 static void i915_pmu_disable(struct perf_event *event)
@@ -566,8 +487,6 @@ static void i915_pmu_disable(struct perf_event *event)
 	i915->pmu.timer_enabled &= pmu_needs_timer(i915, true);
 
 	spin_unlock_irqrestore(&i915->pmu.lock, flags);
-
-	i915_pmu_timer_cancel(event);
 }
 
 static void i915_pmu_event_start(struct perf_event *event, int flags)
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx