From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>,
peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, irogers@google.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/7] perf/x86/rapl: Move the pmu allocation out of CPU hotplug
Date: Mon, 9 Sep 2024 09:02:56 -0400 [thread overview]
Message-ID: <b9893f4f-c91e-4c83-b785-ad78dc2f67f5@linux.intel.com> (raw)
In-Reply-To: <88fa2064-c054-4833-872c-0cf5ff1e3609@amd.com>
Hi Dhananjay,
On 2024-09-09 5:26 a.m., Dhananjay Ugwekar wrote:
> Hello Kan,
>
> On 8/2/2024 8:46 PM, kan.liang@linux.intel.com wrote:
>> From: Kan Liang <kan.liang@linux.intel.com>
>>
>> The rapl pmu just needs to be allocated once. It doesn't matter to be
>> allocated at each CPU hotplug, or the global init_rapl_pmus().
>>
>> Move the pmu allocation to the init_rapl_pmus(). So the generic hotplug
>> supports can be applied.
>>
>> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
>> Cc: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
>> ---
>> arch/x86/events/rapl.c | 43 +++++++++++++++++++++++++++++-------------
>> 1 file changed, 30 insertions(+), 13 deletions(-)
>>
>> diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
>> index b985ca79cf97..f8b6d504d03f 100644
>> --- a/arch/x86/events/rapl.c
>> +++ b/arch/x86/events/rapl.c
>> @@ -568,19 +568,8 @@ static int rapl_cpu_online(unsigned int cpu)
>> struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
>> int target;
>>
>> - if (!pmu) {
>> - pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu));
>> - if (!pmu)
>> - return -ENOMEM;
>> -
>> - raw_spin_lock_init(&pmu->lock);
>> - INIT_LIST_HEAD(&pmu->active_list);
>> - pmu->pmu = &rapl_pmus->pmu;
>> - pmu->timer_interval = ms_to_ktime(rapl_timer_ms);
>> - rapl_hrtimer_init(pmu);
>> -
>> - rapl_pmus->pmus[topology_logical_die_id(cpu)] = pmu;
>> - }
>> + if (!pmu)
>> + return -ENOMEM;
>>
>> /*
>> * Check if there is an online cpu in the package which collects rapl
>> @@ -673,6 +662,32 @@ static const struct attribute_group *rapl_attr_update[] = {
>> NULL,
>> };
>>
>> +static void __init init_rapl_pmu(void)
>> +{
>> + struct rapl_pmu *pmu;
>> + int cpu;
>> +
>> + cpus_read_lock();
>> +
>> + for_each_cpu(cpu, cpu_online_mask) {
>> + pmu = cpu_to_rapl_pmu(cpu);
>> + if (pmu)
>> + continue;
>> + pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu));
>> + if (!pmu)
>> + continue;
>> + raw_spin_lock_init(&pmu->lock);
>> + INIT_LIST_HEAD(&pmu->active_list);
>> + pmu->pmu = &rapl_pmus->pmu;
>> + pmu->timer_interval = ms_to_ktime(rapl_timer_ms);
>> + rapl_hrtimer_init(pmu);
>> +
>> + rapl_pmus->pmus[topology_logical_die_id(cpu)] = pmu;
>> + }
>> +
>> + cpus_read_unlock();
>> +}
>> +
>> static int __init init_rapl_pmus(void)
>> {
>> int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package();
>> @@ -681,6 +696,8 @@ static int __init init_rapl_pmus(void)
>> if (!rapl_pmus)
>> return -ENOMEM;
>>
>> + init_rapl_pmu();
>> +
>> rapl_pmus->nr_rapl_pmu = nr_rapl_pmu;
>
> I feel there is one potential bug here, first we are calling init_rapl_pmu() --> cpu_to_rapl_pmu(cpu) --> "return rapl_pmu_idx < rapl_pmus->nr_rapl_pmu ? rapl_pmus->pmus[rapl_pmu_idx] : NULL;"
> Then we are updating "rapl_pmus->nr_rapl_pmu = nr_rapl_pmu;". This makes the return check in cpu_to_rapl_pmu() ineffective as the rapl_pmus->nr_rapl_pmu value would be falsely zero.
>
Ah, right. A pmu will be allocated for each CPU rather than each socket.
A user wouldn't see a difference, but it wastes memory and may cause
memory leak.
I think we should move the init_rapl_pmu(); to the end of the function.
The patch set has been merged into Peter's perf/core branch. Do you want
to post a fix patch to address the issue?
Thanks,
Kan
> Please let me know if I'm missing something.
>
> Thanks,
> Dhananjay
>
>> rapl_pmus->pmu.attr_groups = rapl_attr_groups;
>> rapl_pmus->pmu.attr_update = rapl_attr_update;
>
next prev parent reply other threads:[~2024-09-09 13:02 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 15:16 [PATCH 0/7] Generic hotplug support for a PMU with a scope kan.liang
2024-08-02 15:16 ` [PATCH 1/7] perf: " kan.liang
2024-09-10 9:59 ` [tip: perf/core] " tip-bot2 for Kan Liang
2024-09-12 10:12 ` Steven Price
2024-09-12 14:53 ` Liang, Kan
2024-09-19 15:43 ` [PATCH 1/7] " Guenter Roeck
2024-09-19 16:28 ` Liang, Kan
2024-10-23 17:09 ` Matthieu Baerts
2024-10-23 17:46 ` Liang, Kan
2024-10-23 18:19 ` Peter Zijlstra
2024-08-02 15:16 ` [PATCH 2/7] perf: Add PERF_EV_CAP_READ_SCOPE kan.liang
2024-09-06 15:11 ` Peter Zijlstra
2024-09-06 15:26 ` Liang, Kan
2024-09-10 9:59 ` [tip: perf/core] " tip-bot2 for Kan Liang
2024-08-02 15:16 ` [PATCH 3/7] perf/x86/intel/cstate: Clean up cpumask and hotplug kan.liang
2024-09-10 9:59 ` [tip: perf/core] " tip-bot2 for Kan Liang
2024-08-02 15:16 ` [PATCH 4/7] iommu/vt-d: Clean up cpumask and hotplug for perfmon kan.liang
2024-09-10 9:59 ` [tip: perf/core] " tip-bot2 for Kan Liang
2024-08-02 15:16 ` [PATCH 5/7] dmaengine: idxd: " kan.liang
2024-08-05 15:40 ` Dave Jiang
2024-08-05 17:46 ` Fenghua Yu
2024-09-10 9:59 ` [tip: perf/core] " tip-bot2 for Kan Liang
2024-08-02 15:16 ` [PATCH 6/7] perf/x86/rapl: Move the pmu allocation out of CPU hotplug kan.liang
2024-09-09 9:26 ` Dhananjay Ugwekar
2024-09-09 13:02 ` Liang, Kan [this message]
2024-09-09 13:24 ` Peter Zijlstra
2024-09-09 17:11 ` Liang, Kan
2024-09-10 9:59 ` [tip: perf/core] " tip-bot2 for Kan Liang
2024-08-02 15:16 ` [PATCH 7/7] perf/x86/rapl: Clean up cpumask and hotplug kan.liang
2024-09-10 9:59 ` [tip: perf/core] " tip-bot2 for Kan Liang
2024-09-04 12:44 ` [PATCH 0/7] Generic hotplug support for a PMU with a scope Liang, Kan
2024-09-06 15:17 ` Peter Zijlstra
2024-09-06 15:30 ` Liang, Kan
2024-09-06 15:12 ` Peter Zijlstra
2024-09-06 15:30 ` Liang, Kan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b9893f4f-c91e-4c83-b785-ad78dc2f67f5@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=Dhananjay.Ugwekar@amd.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox