Skip to content

Commit 2db4edf

Browse files
committed
perf/x86/rapl: Move the pmu allocation out of CPU hotplug
JIRA: https://issues.redhat.com/browse/RHEL-77935 upstream ======== commit 9b99d65 Author: Kan Liang <kan.liang@linux.intel.com> Date: Thu Oct 10 07:26:03 2024 -0700 description =========== There are extra codes in the CPU hotplug function to allocate rapl pmus. The generic PMU hotplug support is hard to be applied. As long as the rapl pmus can be allocated upfront for each die/socket, the code doesn't need to be implemented in the CPU hotplug function. Move the code to the init_rapl_pmus(), and allocate a PMU for each possible die/socket. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Oliver Sang <oliver.sang@intel.com> Link: https://lore.kernel.org/r/20241010142604.770192-1-kan.liang@linux.intel.com Signed-off-by: Michael Petlan <mpetlan@redhat.com>
1 parent 3772451 commit 2db4edf

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

arch/x86/events/rapl.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -602,19 +602,8 @@ static int rapl_cpu_online(unsigned int cpu)
602602
struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
603603
int target;
604604

605-
if (!pmu) {
606-
pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu));
607-
if (!pmu)
608-
return -ENOMEM;
609-
610-
raw_spin_lock_init(&pmu->lock);
611-
INIT_LIST_HEAD(&pmu->active_list);
612-
pmu->pmu = &rapl_pmus->pmu;
613-
pmu->timer_interval = ms_to_ktime(rapl_timer_ms);
614-
rapl_hrtimer_init(pmu);
615-
616-
rapl_pmus->pmus[rapl_pmu_idx] = pmu;
617-
}
605+
if (!pmu)
606+
return -ENOMEM;
618607

619608
/*
620609
* Check if there is an online cpu in the package which collects rapl
@@ -707,6 +696,32 @@ static const struct attribute_group *rapl_attr_update[] = {
707696
NULL,
708697
};
709698

699+
static int __init init_rapl_pmu(void)
700+
{
701+
struct rapl_pmu *pmu;
702+
int idx;
703+
704+
for (idx = 0; idx < rapl_pmus->nr_rapl_pmu; idx++) {
705+
pmu = kzalloc(sizeof(*pmu), GFP_KERNEL);
706+
if (!pmu)
707+
goto free;
708+
709+
raw_spin_lock_init(&pmu->lock);
710+
INIT_LIST_HEAD(&pmu->active_list);
711+
pmu->pmu = &rapl_pmus->pmu;
712+
pmu->timer_interval = ms_to_ktime(rapl_timer_ms);
713+
rapl_hrtimer_init(pmu);
714+
715+
rapl_pmus->pmus[idx] = pmu;
716+
}
717+
718+
return 0;
719+
free:
720+
for (; idx > 0; idx--)
721+
kfree(rapl_pmus->pmus[idx - 1]);
722+
return -ENOMEM;
723+
}
724+
710725
static int __init init_rapl_pmus(void)
711726
{
712727
int nr_rapl_pmu = topology_max_packages();
@@ -730,7 +745,8 @@ static int __init init_rapl_pmus(void)
730745
rapl_pmus->pmu.read = rapl_pmu_event_read;
731746
rapl_pmus->pmu.module = THIS_MODULE;
732747
rapl_pmus->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE;
733-
return 0;
748+
749+
return init_rapl_pmu();
734750
}
735751

736752
static struct rapl_model model_snb = {

0 commit comments

Comments
 (0)