@@ -356,7 +356,7 @@ static bool exclusive_mmio_access(const struct drm_i915_private *i915)
356356 return GRAPHICS_VER (i915 ) == 7 ;
357357}
358358
359- static void engine_sample (struct intel_engine_cs * engine , unsigned int period_ns )
359+ static void gen3_engine_sample (struct intel_engine_cs * engine , unsigned int period_ns )
360360{
361361 struct intel_engine_pmu * pmu = & engine -> pmu ;
362362 bool busy ;
@@ -391,6 +391,31 @@ static void engine_sample(struct intel_engine_cs *engine, unsigned int period_ns
391391 add_sample (& pmu -> sample [I915_SAMPLE_BUSY ], period_ns );
392392}
393393
394+ static void gen2_engine_sample (struct intel_engine_cs * engine , unsigned int period_ns )
395+ {
396+ struct intel_engine_pmu * pmu = & engine -> pmu ;
397+ u32 tail , head , acthd ;
398+
399+ tail = ENGINE_READ_FW (engine , RING_TAIL );
400+ head = ENGINE_READ_FW (engine , RING_HEAD );
401+ acthd = ENGINE_READ_FW (engine , ACTHD );
402+
403+ if (head & HEAD_WAIT_I8XX )
404+ add_sample (& pmu -> sample [I915_SAMPLE_WAIT ], period_ns );
405+
406+ if (head & HEAD_WAIT_I8XX || head != acthd ||
407+ (head & HEAD_ADDR ) != (tail & TAIL_ADDR ))
408+ add_sample (& pmu -> sample [I915_SAMPLE_BUSY ], period_ns );
409+ }
410+
411+ static void engine_sample (struct intel_engine_cs * engine , unsigned int period_ns )
412+ {
413+ if (GRAPHICS_VER (engine -> i915 ) >= 3 )
414+ gen3_engine_sample (engine , period_ns );
415+ else
416+ gen2_engine_sample (engine , period_ns );
417+ }
418+
394419static void
395420engines_sample (struct intel_gt * gt , unsigned int period_ns )
396421{
@@ -834,15 +859,14 @@ static void i915_pmu_event_start(struct perf_event *event, int flags)
834859
835860static void i915_pmu_event_stop (struct perf_event * event , int flags )
836861{
837- struct drm_i915_private * i915 =
838- container_of (event -> pmu , typeof (* i915 ), pmu .base );
839- struct i915_pmu * pmu = & i915 -> pmu ;
862+ struct i915_pmu * pmu = event_to_pmu (event );
840863
841864 if (pmu -> closed )
842865 goto out ;
843866
844867 if (flags & PERF_EF_UPDATE )
845868 i915_pmu_event_read (event );
869+
846870 i915_pmu_disable (event );
847871
848872out :
@@ -1232,17 +1256,6 @@ static void i915_pmu_unregister_cpuhp_state(struct i915_pmu *pmu)
12321256 cpuhp_state_remove_instance (cpuhp_slot , & pmu -> cpuhp .node );
12331257}
12341258
1235- static bool is_igp (struct drm_i915_private * i915 )
1236- {
1237- struct pci_dev * pdev = to_pci_dev (i915 -> drm .dev );
1238-
1239- /* IGP is 0000:00:02.0 */
1240- return pci_domain_nr (pdev -> bus ) == 0 &&
1241- pdev -> bus -> number == 0 &&
1242- PCI_SLOT (pdev -> devfn ) == 2 &&
1243- PCI_FUNC (pdev -> devfn ) == 0 ;
1244- }
1245-
12461259void i915_pmu_register (struct drm_i915_private * i915 )
12471260{
12481261 struct i915_pmu * pmu = & i915 -> pmu ;
@@ -1255,18 +1268,13 @@ void i915_pmu_register(struct drm_i915_private *i915)
12551268
12561269 int ret = - ENOMEM ;
12571270
1258- if (GRAPHICS_VER (i915 ) <= 2 ) {
1259- drm_info (& i915 -> drm , "PMU not supported for this GPU." );
1260- return ;
1261- }
1262-
12631271 spin_lock_init (& pmu -> lock );
12641272 hrtimer_init (& pmu -> timer , CLOCK_MONOTONIC , HRTIMER_MODE_REL );
12651273 pmu -> timer .function = i915_sample ;
12661274 pmu -> cpuhp .cpu = -1 ;
12671275 init_rc6 (pmu );
12681276
1269- if (! is_igp (i915 )) {
1277+ if (IS_DGFX (i915 )) {
12701278 pmu -> name = kasprintf (GFP_KERNEL ,
12711279 "i915_%s" ,
12721280 dev_name (i915 -> drm .dev ));
@@ -1318,7 +1326,7 @@ void i915_pmu_register(struct drm_i915_private *i915)
13181326 pmu -> base .event_init = NULL ;
13191327 free_event_attributes (pmu );
13201328err_name :
1321- if (! is_igp (i915 ))
1329+ if (IS_DGFX (i915 ))
13221330 kfree (pmu -> name );
13231331err :
13241332 drm_notice (& i915 -> drm , "Failed to register PMU!\n" );
@@ -1346,7 +1354,7 @@ void i915_pmu_unregister(struct drm_i915_private *i915)
13461354 perf_pmu_unregister (& pmu -> base );
13471355 pmu -> base .event_init = NULL ;
13481356 kfree (pmu -> base .attr_groups );
1349- if (! is_igp (i915 ))
1357+ if (IS_DGFX (i915 ))
13501358 kfree (pmu -> name );
13511359 free_event_attributes (pmu );
13521360}
0 commit comments