Skip to content

Commit 0548574

Browse files
kimphillamdIngo Molnar
authored andcommitted
perf/amd/uncore: Allow the driver to be built as a module
Add support to build the AMD uncore driver as a module. This is in order to facilitate development without having to reboot the kernel in most cases. Signed-off-by: Kim Phillips <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9164d94 commit 0548574

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

arch/x86/events/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@ config PERF_EVENTS_AMD_POWER
3434
(CPUID Fn8000_0007_EDX[12]) interface to calculate the
3535
average power consumption on Family 15h processors.
3636

37+
config PERF_EVENTS_AMD_UNCORE
38+
tristate "AMD Uncore performance events"
39+
depends on PERF_EVENTS && CPU_SUP_AMD
40+
default y
41+
help
42+
Include support for AMD uncore performance events for use with
43+
e.g., perf stat -e amd_l3/.../,amd_df/.../.
44+
45+
To compile this driver as a module, choose M here: the
46+
module will be called 'amd-uncore'.
3747
endmenu

arch/x86/events/amd/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
obj-$(CONFIG_CPU_SUP_AMD) += core.o uncore.o
2+
obj-$(CONFIG_CPU_SUP_AMD) += core.o
33
obj-$(CONFIG_PERF_EVENTS_AMD_POWER) += power.o
44
obj-$(CONFIG_X86_LOCAL_APIC) += ibs.o
5+
obj-$(CONFIG_PERF_EVENTS_AMD_UNCORE) += amd-uncore.o
6+
amd-uncore-objs := uncore.o
57
ifdef CONFIG_AMD_IOMMU
68
obj-$(CONFIG_CPU_SUP_AMD) += iommu.o
79
endif
8-

arch/x86/events/amd/uncore.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ static struct pmu amd_nb_pmu = {
347347
.stop = amd_uncore_stop,
348348
.read = amd_uncore_read,
349349
.capabilities = PERF_PMU_CAP_NO_EXCLUDE | PERF_PMU_CAP_NO_INTERRUPT,
350+
.module = THIS_MODULE,
350351
};
351352

352353
static struct pmu amd_llc_pmu = {
@@ -360,6 +361,7 @@ static struct pmu amd_llc_pmu = {
360361
.stop = amd_uncore_stop,
361362
.read = amd_uncore_read,
362363
.capabilities = PERF_PMU_CAP_NO_EXCLUDE | PERF_PMU_CAP_NO_INTERRUPT,
364+
.module = THIS_MODULE,
363365
};
364366

365367
static struct amd_uncore *amd_uncore_alloc(unsigned int cpu)
@@ -665,4 +667,28 @@ static int __init amd_uncore_init(void)
665667

666668
return ret;
667669
}
668-
device_initcall(amd_uncore_init);
670+
671+
static void __exit amd_uncore_exit(void)
672+
{
673+
cpuhp_remove_state(CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE);
674+
cpuhp_remove_state(CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING);
675+
cpuhp_remove_state(CPUHP_PERF_X86_AMD_UNCORE_PREP);
676+
677+
if (boot_cpu_has(X86_FEATURE_PERFCTR_LLC)) {
678+
perf_pmu_unregister(&amd_llc_pmu);
679+
free_percpu(amd_uncore_llc);
680+
amd_uncore_llc = NULL;
681+
}
682+
683+
if (boot_cpu_has(X86_FEATURE_PERFCTR_NB)) {
684+
perf_pmu_unregister(&amd_nb_pmu);
685+
free_percpu(amd_uncore_nb);
686+
amd_uncore_nb = NULL;
687+
}
688+
}
689+
690+
module_init(amd_uncore_init);
691+
module_exit(amd_uncore_exit);
692+
693+
MODULE_DESCRIPTION("AMD Uncore Driver");
694+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)