Re: [PATCH v3 02/10] perf/x86/rapl: Fix the energy-pkg event for AMD CPUs

From: Dhananjay Ugwekar
Date: Tue Jul 02 2024 - 05:40:04 EST


Hello Peter,

On 7/1/2024 6:29 PM, Peter Zijlstra wrote:
> On Mon, Jun 24, 2024 at 05:58:59AM +0000, Dhananjay Ugwekar wrote:
>
>> diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
>> index b985ca79cf97..73be25e1f4b4 100644
>> --- a/arch/x86/events/rapl.c
>> +++ b/arch/x86/events/rapl.c
>> @@ -103,6 +103,10 @@ static struct perf_pmu_events_attr event_attr_##v = { \
>> .event_str = str, \
>> };
>>
>> +#define rapl_pmu_is_pkg_scope() \
>> + (boot_cpu_data.x86_vendor == X86_VENDOR_AMD || \
>> + boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)
>> +
>> struct rapl_pmu {
>> raw_spinlock_t lock;
>> int n_active;
>> @@ -140,9 +144,21 @@ static unsigned int rapl_cntr_mask;
>> static u64 rapl_timer_ms;
>> static struct perf_msr *rapl_msrs;
>>
>> +static inline unsigned int get_rapl_pmu_idx(int cpu)
>> +{
>> + return rapl_pmu_is_pkg_scope() ? topology_logical_package_id(cpu) :
>> + topology_logical_die_id(cpu);
>> +}
>> +
>> +static inline const struct cpumask *get_rapl_pmu_cpumask(int cpu)
>> +{
>> + return rapl_pmu_is_pkg_scope() ? topology_core_cpumask(cpu) :
>> + topology_die_cpumask(cpu);
>> +}
>
> This wants a comment. The next time someone looks at this we're going to
> be confused.

Yes, will add a comment.

>
>> @@ -677,6 +696,9 @@ static int __init init_rapl_pmus(void)
>> {
>> int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package();
>>
>> + if (rapl_pmu_is_pkg_scope())
>> + nr_rapl_pmu = topology_max_packages();
>> +
>
> How about:
>
> int nr_rapl_pmu = topology_max_packages();
> if (!rapl_pmu_is_pkg_scope())
> nr_rapl_pmu *= topology_max_dies_per_package();
>
> hmm?

Sure, I'm okay with this as well, will modify in next version.

Thanks,
Dhananjay