Skip to content

Commit 525e006

Browse files
Kuppuswamy Sathyanarayananrafaeljw
authored andcommitted
powercap: intel_rapl: Expose all package CPUs in PMU cpumask
Currently, the RAPL PMU cpumask only includes one CPU per package (typically the lead_cpu) for both MSR and TPMI interfaces. This forces tools to pin their operations to that specific CPU, even though package-scoped registers are readable from any CPU within the package. Change the cpumask to include all online CPUs in each package. This allows tools like perf and turbostat to read RAPL events from any CPU in the package without requiring special handling to find and use the designated lead_cpu. The change refactors get_pmu_cpu() into set_pmu_cpumask() which populates the cpumask with all CPUs belonging to each RAPL package instead of returning a single CPU. This improves flexibility for userspace tools while maintaining correctness since package-scoped RAPL MSRs are architecturally accessible from any CPU in the package. Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Tested-by: Furquim Ulisses <ulisses.furquim@intel.com> Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Link: https://patch.msgid.link/20260209234310.1440722-3-sathyanarayanan.kuppuswamy@linux.intel.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 7537bae commit 525e006

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

drivers/powercap/intel_rapl_common.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,23 +1590,21 @@ static struct rapl_pmu rapl_pmu;
15901590

15911591
/* PMU helpers */
15921592

1593-
static int get_pmu_cpu(struct rapl_package *rp)
1593+
static void set_pmu_cpumask(struct rapl_package *rp, cpumask_var_t mask)
15941594
{
15951595
int cpu;
15961596

15971597
if (!rp->has_pmu)
1598-
return nr_cpu_ids;
1598+
return;
15991599

16001600
/* Only TPMI & MSR RAPL are supported for now */
16011601
if (rp->priv->type != RAPL_IF_TPMI && rp->priv->type != RAPL_IF_MSR)
1602-
return nr_cpu_ids;
1602+
return;
16031603

16041604
/* TPMI/MSR RAPL uses any CPU in the package for PMU */
16051605
for_each_online_cpu(cpu)
16061606
if (topology_physical_package_id(cpu) == rp->id)
1607-
return cpu;
1608-
1609-
return nr_cpu_ids;
1607+
cpumask_set_cpu(cpu, mask);
16101608
}
16111609

16121610
static bool is_rp_pmu_cpu(struct rapl_package *rp, int cpu)
@@ -1883,7 +1881,6 @@ static ssize_t cpumask_show(struct device *dev,
18831881
{
18841882
struct rapl_package *rp;
18851883
cpumask_var_t cpu_mask;
1886-
int cpu;
18871884
int ret;
18881885

18891886
if (!alloc_cpumask_var(&cpu_mask, GFP_KERNEL))
@@ -1895,9 +1892,7 @@ static ssize_t cpumask_show(struct device *dev,
18951892

18961893
/* Choose a cpu for each RAPL Package */
18971894
list_for_each_entry(rp, &rapl_packages, plist) {
1898-
cpu = get_pmu_cpu(rp);
1899-
if (cpu < nr_cpu_ids)
1900-
cpumask_set_cpu(cpu, cpu_mask);
1895+
set_pmu_cpumask(rp, cpu_mask);
19011896
}
19021897
cpus_read_unlock();
19031898

0 commit comments

Comments
 (0)