Skip to contentSkip to conversation

drm/i915/pmu: Drop custom hotplug code

PATCH Applied Lucas De Marchi 4 participants 6 messages Jan 31, 2025 – Feb 5, 2025

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

PATCH v2 1/1 drm/i915/pmu: Drop custom hotplug code

Since commit 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope"), there's generic support for system-wide counters and integration with cpu hotplug.

The i915 counters are system-wide, even though the migration code is using the wrong topology mask:

	target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);

So one could think the counter has core scope rather than system scope, which is not the case. That was never caught in tests since they would disable just one cpu at a time. After the removal of hotpluggable CPU0 in commit 5475abbde77f ("x86/smpboot: Remove the CPU0 hotplug kludge") and commit e59e74dc48a3 ("x86/topology: Remove CPU0 hotplug option") this became essentially non-testable for our systems.

Using the generic hotplug code, the same cpu0 is still reported in cpumask - only if it was possible to unplug it, it would migrate to another cpu, so there isn't much a change in behavior.

The one thing that changes is the return code for perf_event_open() if an invalid cpu is used: previously i915 would return -EINVAL, but generic perf code returns -ENODEV. That should be ok for all the users and not cause breakages.

Cc Kan Liang <[email protected]>
Cc Peter Zijlstra (Intel) <[email protected]>
Cc Vinay Belgaumkar <[email protected]>

---

v2: Expand commit message explanation to clarify what was discussed with Kan, Tvrtko and Umesh in
https://patchwork.freedesktop.org/patch/msgid/[email protected]

 drivers/gpu/drm/i915/i915_module.c |   2 -
 drivers/gpu/drm/i915/i915_pmu.c    | 114 +----------------------------
 drivers/gpu/drm/i915/i915_pmu.h    |  11 ---
 3 files changed, 1 insertion(+), 126 deletions(-)
drivers/gpu/drm/i915/i915_module.c +0 -2
index 2f88970cc0a93..5862754c662c4 100644
@@ -71,8 +71,6 @@ static const struct {
 	{ .init = i915_vma_resource_module_init,
 	  .exit = i915_vma_resource_module_exit },
 	{ .init = i915_mock_selftests },
-	{ .init = i915_pmu_init,
-	  .exit = i915_pmu_exit },
 	{ .init = i915_pci_register_driver,
 	  .exit = i915_pci_unregister_driver },
 	{ .init = i915_perf_sysctl_register,
drivers/gpu/drm/i915/i915_pmu.c +1 -113

172 lines not on this page · raw message

drivers/gpu/drm/i915/i915_pmu.h +0 -11
index 0ec78c2b4f203..5826cc81858c4 100644
@@ -56,13 +56,6 @@ struct i915_pmu_sample {
 };
 
 struct i915_pmu {
-	/**
-	 * @cpuhp: Struct used for CPU hotplug handling.
-	 */
-	struct {
-		struct hlist_node node;
-		unsigned int cpu;
-	} cpuhp;
 	/**
 	 * @base: PMU base.
 	 */
@@ -155,15 +148,11 @@ struct i915_pmu {
 };
 
 #ifdef CONFIG_PERF_EVENTS
-int i915_pmu_init(void);
-void i915_pmu_exit(void);
 void i915_pmu_register(struct drm_i915_private *i915);
 void i915_pmu_unregister(struct drm_i915_private *i915);
 void i915_pmu_gt_parked(struct intel_gt *gt);
 void i915_pmu_gt_unparked(struct intel_gt *gt);
 #else
-static inline int i915_pmu_init(void) { return 0; }
-static inline void i915_pmu_exit(void) {}
 static inline void i915_pmu_register(struct drm_i915_private *i915) {}
 static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
 static inline void i915_pmu_gt_parked(struct intel_gt *gt) {}
Signature · 1 line
2.48.0
#1 lore raw

✗ Fi.CI.SPARSE: warning for drm/i915/pmu: Drop custom hotplug code (rev3)

== Series Details ==

== Series Details ==

Series: drm/i915/pmu: Drop custom hotplug code (rev3)
URL : https://patchwork.freedesktop.org/series/143636/
State : warning

== Summary ==

Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.

#2 lore raw

✗ i915.CI.BAT: failure for drm/i915/pmu: Drop custom hotplug code (rev3)

In reply to Lucas De Marchi
== Series Details ==

== Series Details ==

Series: drm/i915/pmu: Drop custom hotplug code (rev3)
URL : https://patchwork.freedesktop.org/series/143636/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_16053 -> Patchwork_143636v3
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_143636v3 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes
introduced in Patchwork_143636v3, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/index.html

Participating hosts (42 -> 42)
------------------------------

Additional (1): bat-adlp-6
Missing (1): fi-snb-2520m

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_143636v3:

### IGT changes ###

#### Possible regressions ####

* igt@kms_cursor_legacy@basic-flip-after-cursor-atomic:
- fi-kbl-7567u: [PASS][1] -> [DMESG-WARN][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/fi-kbl-7567u/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/fi-kbl-7567u/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_143636v3 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@debugfs_test@basic-hwmon:
- bat-adlp-6: NOTRUN -> [SKIP][3] ([i915#9318])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

* igt@gem_lmem_swapping@random-engines:
- bat-adlp-6: NOTRUN -> [SKIP][4] ([i915#4613]) +3 other tests skip
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

* igt@gem_tiled_pread_basic:
- bat-adlp-6: NOTRUN -> [SKIP][5] ([i915#3282])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@gem_tiled_pread_basic.html

* igt@i915_module_load@load:
- fi-pnv-d510: [PASS][6] -> [ABORT][7] ([i915#13203])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/fi-pnv-d510/igt@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/fi-pnv-d510/igt@[email protected]

* igt@i915_pm_rpm@module-reload:
- bat-rpls-4: [PASS][8] -> [FAIL][9] ([i915#13401])
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/bat-rpls-4/igt@[email protected]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-rpls-4/igt@[email protected]
- fi-tgl-1115g4: [PASS][10] -> [FAIL][11] ([i915#13401])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/fi-tgl-1115g4/igt@[email protected]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/fi-tgl-1115g4/igt@[email protected]

* igt@i915_pm_rps@basic-api:
- bat-adlp-6: NOTRUN -> [SKIP][12] ([i915#6621])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

* igt@i915_selftest@live:
- bat-adlp-6: NOTRUN -> [INCOMPLETE][13] ([i915#12435] / [i915#9413])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

* igt@i915_selftest@live@hangcheck:
- bat-adlp-6: NOTRUN -> [INCOMPLETE][14] ([i915#9413])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@i915_selftest@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy:
- bat-adlp-6: NOTRUN -> [SKIP][15] ([i915#4103]) +1 other test skip
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

* igt@kms_dsc@dsc-basic:
- bat-adlp-6: NOTRUN -> [SKIP][16] ([i915#3555] / [i915#3840])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

* igt@kms_force_connector_basic@force-load-detect:
- bat-adlp-6: NOTRUN -> [SKIP][17]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

* igt@kms_pipe_crc_basic@nonblocking-crc-frame-sequence:
- bat-dg2-11: [PASS][18] -> [SKIP][19] ([i915#9197]) +3 other tests skip
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/bat-dg2-11/igt@[email protected]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-dg2-11/igt@[email protected]

* igt@kms_setmode@basic-clone-single-crtc:
- bat-adlp-6: NOTRUN -> [SKIP][20] ([i915#3555])
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

* igt@prime_vgem@basic-write:
- bat-adlp-6: NOTRUN -> [SKIP][21] ([i915#3291] / [i915#3708]) +2 other tests skip
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-adlp-6/igt@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live:
- bat-twl-1: [ABORT][22] ([i915#12919] / [i915#13503]) -> [PASS][23]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/bat-twl-1/igt@[email protected]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-twl-1/igt@[email protected]

* igt@i915_selftest@live@requests:
- bat-twl-1: [ABORT][24] ([i915#12919]) -> [PASS][25]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/bat-twl-1/igt@i915_selftest@[email protected]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-twl-1/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@workarounds:
- bat-arls-5: [DMESG-FAIL][26] ([i915#12061]) -> [PASS][27] +1 other test pass
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/bat-arls-5/igt@i915_selftest@[email protected]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-arls-5/igt@i915_selftest@[email protected]
- bat-mtlp-6: [DMESG-FAIL][28] ([i915#12061]) -> [PASS][29] +1 other test pass
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/bat-mtlp-6/igt@i915_selftest@[email protected]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-mtlp-6/igt@i915_selftest@[email protected]
- {bat-mtlp-9}: [DMESG-FAIL][30] ([i915#12061]) -> [PASS][31]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16053/bat-mtlp-9/igt@i915_selftest@[email protected]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/bat-mtlp-9/igt@i915_selftest@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[i915#12061]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12061
[i915#12435]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12435
[i915#12919]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12919
[i915#13203]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13203
[i915#13401]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13401
[i915#13503]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13503
[i915#3282]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3282
[i915#3291]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3291
[i915#3555]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3555
[i915#3708]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3708
[i915#3840]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3840
[i915#4103]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4103
[i915#4613]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4613
[i915#6621]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/6621
[i915#9197]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9197
[i915#9318]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9318
[i915#9413]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9413

Build changes
-------------

* Linux: CI_DRM_16053 -> Patchwork_143636v3

CI-20190529: 20190529
CI_DRM_16053: 01f54d1da1ffffff78047186f62b5916dfd43939 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_8219: d92c8eadff2a4e5b4d90cf8c8c52936263d29394 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_143636v3: 01f54d1da1ffffff78047186f62b5916dfd43939 @ git://anongit.freedesktop.org/gfx-ci/linux

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_143636v3/index.html

Reviewed-by on v2 1/1
#3 lore raw
In reply to Lucas De Marchi
Quoted 25 lines · Lucas De Marchi

Since commit 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope"), there's generic support for system-wide counters and integration with cpu hotplug.

The i915 counters are system-wide, even though the migration code is using the wrong topology mask:

	target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);

So one could think the counter has core scope rather than system scope, which is not the case. That was never caught in tests since they would disable just one cpu at a time. After the removal of hotpluggable CPU0 in commit 5475abbde77f ("x86/smpboot: Remove the CPU0 hotplug kludge") and commit e59e74dc48a3 ("x86/topology: Remove CPU0 hotplug option") this became essentially non-testable for our systems.

Using the generic hotplug code, the same cpu0 is still reported in cpumask - only if it was possible to unplug it, it would migrate to another cpu, so there isn't much a change in behavior.

The one thing that changes is the return code for perf_event_open() if an invalid cpu is used: previously i915 would return -EINVAL, but generic perf code returns -ENODEV. That should be ok for all the users and not cause breakages.

Quoted 5 lines
Cc Kan Liang <[email protected]>
Cc Peter Zijlstra (Intel) <[email protected]>
Cc Vinay Belgaumkar <[email protected]>

Thanks,
Kan

Quoted 242 lines

---

v2: Expand commit message explanation to clarify what was discussed with Kan, Tvrtko and Umesh in
https://patchwork.freedesktop.org/patch/msgid/[email protected]

 drivers/gpu/drm/i915/i915_module.c |   2 -
 drivers/gpu/drm/i915/i915_pmu.c    | 114 +----------------------------
 drivers/gpu/drm/i915/i915_pmu.h    |  11 ---
 3 files changed, 1 insertion(+), 126 deletions(-)
drivers/gpu/drm/i915/i915_module.c +0 -2
index 2f88970cc0a93..5862754c662c4 100644
@@ -71,8 +71,6 @@ static const struct {
 	{ .init = i915_vma_resource_module_init,
 	  .exit = i915_vma_resource_module_exit },
 	{ .init = i915_mock_selftests },
-	{ .init = i915_pmu_init,
-	  .exit = i915_pmu_exit },
 	{ .init = i915_pci_register_driver,
 	  .exit = i915_pci_unregister_driver },
 	{ .init = i915_perf_sysctl_register,
drivers/gpu/drm/i915/i915_pmu.c +1 -113
index 2eecd42f61ba1..69a109d02116e 100644
@@ -28,9 +28,6 @@
 	 BIT(I915_SAMPLE_WAIT) | \
 	 BIT(I915_SAMPLE_SEMA))
 
-static cpumask_t i915_pmu_cpumask;
-static unsigned int i915_pmu_target_cpu = -1;
-
 static struct i915_pmu *event_to_pmu(struct perf_event *event)
 {
 	return container_of(event->pmu, struct i915_pmu, base);
@@ -642,10 +639,6 @@ static int i915_pmu_event_init(struct perf_event *event)
 	if (event->cpu < 0)
 		return -EINVAL;
 
-	/* only allow running on one cpu at a time */
-	if (!cpumask_test_cpu(event->cpu, &i915_pmu_cpumask))
-		return -EINVAL;
-
 	if (is_engine_event(event))
 		ret = engine_event_init(event);
 	else
@@ -935,23 +928,6 @@ static ssize_t i915_pmu_event_show(struct device *dev,
 	return sprintf(buf, "config=0x%lx\n", eattr->val);
 }
 
-static ssize_t cpumask_show(struct device *dev,
-			    struct device_attribute *attr, char *buf)
-{
-	return cpumap_print_to_pagebuf(true, buf, &i915_pmu_cpumask);
-}
-
-static DEVICE_ATTR_RO(cpumask);
-
-static struct attribute *i915_cpumask_attrs[] = {
-	&dev_attr_cpumask.attr,
-	NULL,
-};
-
-static const struct attribute_group i915_pmu_cpumask_attr_group = {
-	.attrs = i915_cpumask_attrs,
-};
-
 #define __event(__counter, __name, __unit) \
 { \
 	.counter = (__counter), \
@@ -1168,92 +1144,12 @@ static void free_event_attributes(struct i915_pmu *pmu)
 	pmu->pmu_attr = NULL;
 }
 
-static int i915_pmu_cpu_online(unsigned int cpu, struct hlist_node *node)
-{
-	struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), cpuhp.node);
-
-	/* Select the first online CPU as a designated reader. */
-	if (cpumask_empty(&i915_pmu_cpumask))
-		cpumask_set_cpu(cpu, &i915_pmu_cpumask);
-
-	return 0;
-}
-
-static int i915_pmu_cpu_offline(unsigned int cpu, struct hlist_node *node)
-{
-	struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), cpuhp.node);
-	unsigned int target = i915_pmu_target_cpu;
-
-	/*
-	 * Unregistering an instance generates a CPU offline event which we must
-	 * ignore to avoid incorrectly modifying the shared i915_pmu_cpumask.
-	 */
-	if (!pmu->registered)
-		return 0;
-
-	if (cpumask_test_and_clear_cpu(cpu, &i915_pmu_cpumask)) {
-		target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);
-
-		/* Migrate events if there is a valid target */
-		if (target < nr_cpu_ids) {
-			cpumask_set_cpu(target, &i915_pmu_cpumask);
-			i915_pmu_target_cpu = target;
-		}
-	}
-
-	if (target < nr_cpu_ids && target != pmu->cpuhp.cpu) {
-		perf_pmu_migrate_context(&pmu->base, cpu, target);
-		pmu->cpuhp.cpu = target;
-	}
-
-	return 0;
-}
-
-static enum cpuhp_state cpuhp_state = CPUHP_INVALID;
-
-int i915_pmu_init(void)
-{
-	int ret;
-
-	ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
-				      "perf/x86/intel/i915:online",
-				      i915_pmu_cpu_online,
-				      i915_pmu_cpu_offline);
-	if (ret < 0)
-		pr_notice("Failed to setup cpuhp state for i915 PMU! (%d)\n",
-			  ret);
-	else
-		cpuhp_state = ret;
-
-	return 0;
-}
-
-void i915_pmu_exit(void)
-{
-	if (cpuhp_state != CPUHP_INVALID)
-		cpuhp_remove_multi_state(cpuhp_state);
-}
-
-static int i915_pmu_register_cpuhp_state(struct i915_pmu *pmu)
-{
-	if (cpuhp_state == CPUHP_INVALID)
-		return -EINVAL;
-
-	return cpuhp_state_add_instance(cpuhp_state, &pmu->cpuhp.node);
-}
-
-static void i915_pmu_unregister_cpuhp_state(struct i915_pmu *pmu)
-{
-	cpuhp_state_remove_instance(cpuhp_state, &pmu->cpuhp.node);
-}
-
 void i915_pmu_register(struct drm_i915_private *i915)
 {
 	struct i915_pmu *pmu = &i915->pmu;
 	const struct attribute_group *attr_groups[] = {
 		&i915_pmu_format_attr_group,
 		&pmu->events_attr_group,
-		&i915_pmu_cpumask_attr_group,
 		NULL
 	};
 	int ret = -ENOMEM;
@@ -1261,7 +1157,6 @@ void i915_pmu_register(struct drm_i915_private *i915)
 	spin_lock_init(&pmu->lock);
 	hrtimer_init(&pmu->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	pmu->timer.function = i915_sample;
-	pmu->cpuhp.cpu = -1;
 	init_rc6(pmu);
 
 	if (IS_DGFX(i915)) {
@@ -1290,6 +1185,7 @@ void i915_pmu_register(struct drm_i915_private *i915)
 
 	pmu->base.module	= THIS_MODULE;
 	pmu->base.task_ctx_nr	= perf_invalid_context;
+	pmu->base.scope		= PERF_PMU_SCOPE_SYS_WIDE;
 	pmu->base.event_init	= i915_pmu_event_init;
 	pmu->base.add		= i915_pmu_event_add;
 	pmu->base.del		= i915_pmu_event_del;
@@ -1301,16 +1197,10 @@ void i915_pmu_register(struct drm_i915_private *i915)
 	if (ret)
 		goto err_groups;
 
-	ret = i915_pmu_register_cpuhp_state(pmu);
-	if (ret)
-		goto err_unreg;
-
 	pmu->registered = true;
 
 	return;
 
-err_unreg:
-	perf_pmu_unregister(&pmu->base);
 err_groups:
 	kfree(pmu->base.attr_groups);
 err_attr:
@@ -1334,8 +1224,6 @@ void i915_pmu_unregister(struct drm_i915_private *i915)
 
 	hrtimer_cancel(&pmu->timer);
 
-	i915_pmu_unregister_cpuhp_state(pmu);
-
 	perf_pmu_unregister(&pmu->base);
 	kfree(pmu->base.attr_groups);
 	if (IS_DGFX(i915))
drivers/gpu/drm/i915/i915_pmu.h +0 -11
index 0ec78c2b4f203..5826cc81858c4 100644
@@ -56,13 +56,6 @@ struct i915_pmu_sample {
 };
 
 struct i915_pmu {
-	/**
-	 * @cpuhp: Struct used for CPU hotplug handling.
-	 */
-	struct {
-		struct hlist_node node;
-		unsigned int cpu;
-	} cpuhp;
 	/**
 	 * @base: PMU base.
 	 */
@@ -155,15 +148,11 @@ struct i915_pmu {
 };
 
 #ifdef CONFIG_PERF_EVENTS
-int i915_pmu_init(void);
-void i915_pmu_exit(void);
 void i915_pmu_register(struct drm_i915_private *i915);
 void i915_pmu_unregister(struct drm_i915_private *i915);
 void i915_pmu_gt_parked(struct intel_gt *gt);
 void i915_pmu_gt_unparked(struct intel_gt *gt);
 #else
-static inline int i915_pmu_init(void) { return 0; }
-static inline void i915_pmu_exit(void) {}
 static inline void i915_pmu_register(struct drm_i915_private *i915) {}
 static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
 static inline void i915_pmu_gt_parked(struct intel_gt *gt) {}
maintainer Reviewed-by on v2 1/1
#4 lore raw
In reply to Lucas De Marchi
Quoted 30 lines · Lucas De Marchi

Since commit 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope"), there's generic support for system-wide counters and integration with cpu hotplug.

The i915 counters are system-wide, even though the migration code is using the wrong topology mask:

	target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);

So one could think the counter has core scope rather than system scope, which is not the case. That was never caught in tests since they would disable just one cpu at a time. After the removal of hotpluggable CPU0 in commit 5475abbde77f ("x86/smpboot: Remove the CPU0 hotplug kludge") and commit e59e74dc48a3 ("x86/topology: Remove CPU0 hotplug option") this became essentially non-testable for our systems.

Using the generic hotplug code, the same cpu0 is still reported in cpumask - only if it was possible to unplug it, it would migrate to another cpu, so there isn't much a change in behavior.

The one thing that changes is the return code for perf_event_open() if an invalid cpu is used: previously i915 would return -EINVAL, but generic perf code returns -ENODEV. That should be ok for all the users and not cause breakages.

Cc Kan Liang <[email protected]>
Cc Peter Zijlstra (Intel) <[email protected]>
Cc Vinay Belgaumkar <[email protected]>
Quoted 5 lines

---

v2: Expand commit message explanation to clarify what was discussed with Kan, Tvrtko and Umesh in
https://patchwork.freedesktop.org/patch/msgid/[email protected]

I *think* the comment in perf_event_setup_cpumask clarifies my question of whether "evil" userspace could setup a counter group with mixed cpus - that it couldn't. Even though I cannot actually untangle where perf_online_sys_mask gets set.

In any case I don't think it is concern for this patch.

Regards,

Tvrtko

Quoted 236 lines
  drivers/gpu/drm/i915/i915_module.c |   2 -
  drivers/gpu/drm/i915/i915_pmu.c    | 114 +----------------------------
  drivers/gpu/drm/i915/i915_pmu.h    |  11 ---
  3 files changed, 1 insertion(+), 126 deletions(-)
drivers/gpu/drm/i915/i915_module.c +0 -2
index 2f88970cc0a93..5862754c662c4 100644
@@ -71,8 +71,6 @@ static const struct {
  	{ .init = i915_vma_resource_module_init,
  	  .exit = i915_vma_resource_module_exit },
  	{ .init = i915_mock_selftests },
-	{ .init = i915_pmu_init,
-	  .exit = i915_pmu_exit },
  	{ .init = i915_pci_register_driver,
  	  .exit = i915_pci_unregister_driver },
  	{ .init = i915_perf_sysctl_register,
drivers/gpu/drm/i915/i915_pmu.c +1 -113
index 2eecd42f61ba1..69a109d02116e 100644
@@ -28,9 +28,6 @@
  	 BIT(I915_SAMPLE_WAIT) | \
  	 BIT(I915_SAMPLE_SEMA))
 
-static cpumask_t i915_pmu_cpumask;
-static unsigned int i915_pmu_target_cpu = -1;
-
  static struct i915_pmu *event_to_pmu(struct perf_event *event)
  {
  	return container_of(event->pmu, struct i915_pmu, base);
@@ -642,10 +639,6 @@ static int i915_pmu_event_init(struct perf_event *event)
  	if (event->cpu < 0)
  		return -EINVAL;
 
-	/* only allow running on one cpu at a time */
-	if (!cpumask_test_cpu(event->cpu, &i915_pmu_cpumask))
-		return -EINVAL;
-
  	if (is_engine_event(event))
  		ret = engine_event_init(event);
  	else
@@ -935,23 +928,6 @@ static ssize_t i915_pmu_event_show(struct device *dev,
  	return sprintf(buf, "config=0x%lx\n", eattr->val);
  }
 
-static ssize_t cpumask_show(struct device *dev,
-			    struct device_attribute *attr, char *buf)
-{
-	return cpumap_print_to_pagebuf(true, buf, &i915_pmu_cpumask);
-}
-
-static DEVICE_ATTR_RO(cpumask);
-
-static struct attribute *i915_cpumask_attrs[] = {
-	&dev_attr_cpumask.attr,
-	NULL,
-};
-
-static const struct attribute_group i915_pmu_cpumask_attr_group = {
-	.attrs = i915_cpumask_attrs,
-};
-
  #define __event(__counter, __name, __unit) \
  { \
  	.counter = (__counter), \
@@ -1168,92 +1144,12 @@ static void free_event_attributes(struct i915_pmu *pmu)
  	pmu->pmu_attr = NULL;
  }
 
-static int i915_pmu_cpu_online(unsigned int cpu, struct hlist_node *node)
-{
-	struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), cpuhp.node);
-
-	/* Select the first online CPU as a designated reader. */
-	if (cpumask_empty(&i915_pmu_cpumask))
-		cpumask_set_cpu(cpu, &i915_pmu_cpumask);
-
-	return 0;
-}
-
-static int i915_pmu_cpu_offline(unsigned int cpu, struct hlist_node *node)
-{
-	struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), cpuhp.node);
-	unsigned int target = i915_pmu_target_cpu;
-
-	/*
-	 * Unregistering an instance generates a CPU offline event which we must
-	 * ignore to avoid incorrectly modifying the shared i915_pmu_cpumask.
-	 */
-	if (!pmu->registered)
-		return 0;
-
-	if (cpumask_test_and_clear_cpu(cpu, &i915_pmu_cpumask)) {
-		target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);
-
-		/* Migrate events if there is a valid target */
-		if (target < nr_cpu_ids) {
-			cpumask_set_cpu(target, &i915_pmu_cpumask);
-			i915_pmu_target_cpu = target;
-		}
-	}
-
-	if (target < nr_cpu_ids && target != pmu->cpuhp.cpu) {
-		perf_pmu_migrate_context(&pmu->base, cpu, target);
-		pmu->cpuhp.cpu = target;
-	}
-
-	return 0;
-}
-
-static enum cpuhp_state cpuhp_state = CPUHP_INVALID;
-
-int i915_pmu_init(void)
-{
-	int ret;
-
-	ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
-				      "perf/x86/intel/i915:online",
-				      i915_pmu_cpu_online,
-				      i915_pmu_cpu_offline);
-	if (ret < 0)
-		pr_notice("Failed to setup cpuhp state for i915 PMU! (%d)\n",
-			  ret);
-	else
-		cpuhp_state = ret;
-
-	return 0;
-}
-
-void i915_pmu_exit(void)
-{
-	if (cpuhp_state != CPUHP_INVALID)
-		cpuhp_remove_multi_state(cpuhp_state);
-}
-
-static int i915_pmu_register_cpuhp_state(struct i915_pmu *pmu)
-{
-	if (cpuhp_state == CPUHP_INVALID)
-		return -EINVAL;
-
-	return cpuhp_state_add_instance(cpuhp_state, &pmu->cpuhp.node);
-}
-
-static void i915_pmu_unregister_cpuhp_state(struct i915_pmu *pmu)
-{
-	cpuhp_state_remove_instance(cpuhp_state, &pmu->cpuhp.node);
-}
-
  void i915_pmu_register(struct drm_i915_private *i915)
  {
  	struct i915_pmu *pmu = &i915->pmu;
  	const struct attribute_group *attr_groups[] = {
  		&i915_pmu_format_attr_group,
  		&pmu->events_attr_group,
-		&i915_pmu_cpumask_attr_group,
  		NULL
  	};
  	int ret = -ENOMEM;
@@ -1261,7 +1157,6 @@ void i915_pmu_register(struct drm_i915_private *i915)
  	spin_lock_init(&pmu->lock);
  	hrtimer_init(&pmu->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  	pmu->timer.function = i915_sample;
-	pmu->cpuhp.cpu = -1;
  	init_rc6(pmu);
 
  	if (IS_DGFX(i915)) {
@@ -1290,6 +1185,7 @@ void i915_pmu_register(struct drm_i915_private *i915)
 
  	pmu->base.module	= THIS_MODULE;
  	pmu->base.task_ctx_nr	= perf_invalid_context;
+	pmu->base.scope		= PERF_PMU_SCOPE_SYS_WIDE;
  	pmu->base.event_init	= i915_pmu_event_init;
  	pmu->base.add		= i915_pmu_event_add;
  	pmu->base.del		= i915_pmu_event_del;
@@ -1301,16 +1197,10 @@ void i915_pmu_register(struct drm_i915_private *i915)
  	if (ret)
  		goto err_groups;
 
-	ret = i915_pmu_register_cpuhp_state(pmu);
-	if (ret)
-		goto err_unreg;
-
  	pmu->registered = true;
 
  	return;
 
-err_unreg:
-	perf_pmu_unregister(&pmu->base);
  err_groups:
  	kfree(pmu->base.attr_groups);
  err_attr:
@@ -1334,8 +1224,6 @@ void i915_pmu_unregister(struct drm_i915_private *i915)
 
  	hrtimer_cancel(&pmu->timer);
 
-	i915_pmu_unregister_cpuhp_state(pmu);
-
  	perf_pmu_unregister(&pmu->base);
  	kfree(pmu->base.attr_groups);
  	if (IS_DGFX(i915))
drivers/gpu/drm/i915/i915_pmu.h +0 -11
index 0ec78c2b4f203..5826cc81858c4 100644
@@ -56,13 +56,6 @@ struct i915_pmu_sample {
  };
 
  struct i915_pmu {
-	/**
-	 * @cpuhp: Struct used for CPU hotplug handling.
-	 */
-	struct {
-		struct hlist_node node;
-		unsigned int cpu;
-	} cpuhp;
  	/**
  	 * @base: PMU base.
  	 */
@@ -155,15 +148,11 @@ struct i915_pmu {
  };
 
  #ifdef CONFIG_PERF_EVENTS
-int i915_pmu_init(void);
-void i915_pmu_exit(void);
  void i915_pmu_register(struct drm_i915_private *i915);
  void i915_pmu_unregister(struct drm_i915_private *i915);
  void i915_pmu_gt_parked(struct intel_gt *gt);
  void i915_pmu_gt_unparked(struct intel_gt *gt);
  #else
-static inline int i915_pmu_init(void) { return 0; }
-static inline void i915_pmu_exit(void) {}
  static inline void i915_pmu_register(struct drm_i915_private *i915) {}
  static inline void i915_pmu_unregister(struct drm_i915_private *i915) {}
  static inline void i915_pmu_gt_parked(struct intel_gt *gt) {}
author Applied
#5 lore raw
In reply to Lucas De Marchi
Quoted 8 lines · Lucas De Marchi

Since commit 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope"), there's generic support for system-wide counters and integration with cpu hotplug.

The i915 counters are system-wide, even though the migration code is using the wrong topology mask:

[...]

Applied to drm-intel-gt-next. Thanks for the reviews.

[1/1] drm/i915/pmu: Drop custom hotplug code

      commit: 87b593d79864e6e82cb00aa3d837094a1643e272

Best regards,

Signature · 1 line
Lucas De Marchi <[email protected]>