Skip to content

Commit eeca4c6

Browse files
dhananjay-AMDPeter Zijlstra
authored andcommitted
perf/x86/rapl: Add arguments to the init and cleanup functions
Prepare for the addition of RAPL core energy counter support. Add arguments to the init and cleanup functions, which will help in initialization and cleaning up of two separate PMUs. No functional change. Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: "Gautham R. Shenoy" <gautham.shenoy@amd.com> Reviewed-by: Zhang Rui <rui.zhang@intel.com> Tested-by: Zhang Rui <rui.zhang@intel.com> Link: https://lore.kernel.org/r/20241115060805.447565-7-Dhananjay.Ugwekar@amd.com
1 parent cd29d83 commit eeca4c6

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

arch/x86/events/rapl.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ static void __init rapl_advertise(void)
603603
}
604604
}
605605

606-
static void cleanup_rapl_pmus(void)
606+
static void cleanup_rapl_pmus(struct rapl_pmus *rapl_pmus)
607607
{
608608
int i;
609609

@@ -621,7 +621,7 @@ static const struct attribute_group *rapl_attr_update[] = {
621621
NULL,
622622
};
623623

624-
static int __init init_rapl_pmu(void)
624+
static int __init init_rapl_pmu(struct rapl_pmus *rapl_pmus)
625625
{
626626
struct rapl_pmu *rapl_pmu;
627627
int idx;
@@ -647,20 +647,20 @@ static int __init init_rapl_pmu(void)
647647
return -ENOMEM;
648648
}
649649

650-
static int __init init_rapl_pmus(void)
650+
static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_scope)
651651
{
652652
int nr_rapl_pmu = topology_max_packages();
653-
int rapl_pmu_scope = PERF_PMU_SCOPE_PKG;
653+
struct rapl_pmus *rapl_pmus;
654654

655-
if (!rapl_pmu_is_pkg_scope()) {
656-
nr_rapl_pmu *= topology_max_dies_per_package();
657-
rapl_pmu_scope = PERF_PMU_SCOPE_DIE;
658-
}
655+
if (rapl_pmu_scope == PERF_PMU_SCOPE_DIE)
656+
nr_rapl_pmu *= topology_max_dies_per_package();
659657

660658
rapl_pmus = kzalloc(struct_size(rapl_pmus, rapl_pmu, nr_rapl_pmu), GFP_KERNEL);
661659
if (!rapl_pmus)
662660
return -ENOMEM;
663661

662+
*rapl_pmus_ptr = rapl_pmus;
663+
664664
rapl_pmus->nr_rapl_pmu = nr_rapl_pmu;
665665
rapl_pmus->pmu.attr_groups = rapl_attr_groups;
666666
rapl_pmus->pmu.attr_update = rapl_attr_update;
@@ -675,7 +675,7 @@ static int __init init_rapl_pmus(void)
675675
rapl_pmus->pmu.module = THIS_MODULE;
676676
rapl_pmus->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE;
677677

678-
return init_rapl_pmu();
678+
return init_rapl_pmu(rapl_pmus);
679679
}
680680

681681
static struct rapl_model model_snb = {
@@ -799,8 +799,12 @@ MODULE_DEVICE_TABLE(x86cpu, rapl_model_match);
799799
static int __init rapl_pmu_init(void)
800800
{
801801
const struct x86_cpu_id *id;
802+
int rapl_pmu_scope = PERF_PMU_SCOPE_DIE;
802803
int ret;
803804

805+
if (rapl_pmu_is_pkg_scope())
806+
rapl_pmu_scope = PERF_PMU_SCOPE_PKG;
807+
804808
id = x86_match_cpu(rapl_model_match);
805809
if (!id)
806810
return -ENODEV;
@@ -816,7 +820,7 @@ static int __init rapl_pmu_init(void)
816820
if (ret)
817821
return ret;
818822

819-
ret = init_rapl_pmus();
823+
ret = init_rapl_pmus(&rapl_pmus, rapl_pmu_scope);
820824
if (ret)
821825
return ret;
822826

@@ -829,14 +833,14 @@ static int __init rapl_pmu_init(void)
829833

830834
out:
831835
pr_warn("Initialization failed (%d), disabled\n", ret);
832-
cleanup_rapl_pmus();
836+
cleanup_rapl_pmus(rapl_pmus);
833837
return ret;
834838
}
835839
module_init(rapl_pmu_init);
836840

837841
static void __exit intel_rapl_exit(void)
838842
{
839843
perf_pmu_unregister(&rapl_pmus->pmu);
840-
cleanup_rapl_pmus();
844+
cleanup_rapl_pmus(rapl_pmus);
841845
}
842846
module_exit(intel_rapl_exit);

0 commit comments

Comments
 (0)