Skip to content

Commit 748d6ba

Browse files
Kuppuswamy Sathyanarayananrafaeljw
authored andcommitted
powercap: intel_rapl: Enable MSR-based RAPL PMU support
Currently, RAPL PMU support requires adding CPU model entries to arch/x86/events/rapl.c for each new generation. However, RAPL MSRs are not architectural and require platform-specific customization, making arch/x86 an inappropriate location for this functionality. The powercap subsystem already handles RAPL functionality and is the natural place to consolidate all RAPL features. The powercap RAPL driver already includes PMU support for TPMI-based RAPL interfaces, making it straightforward to extend this support to MSR-based RAPL interfaces as well. This consolidation eliminates the need to maintain RAPL support in multiple subsystems and provides a unified approach for both TPMI and MSR-based RAPL implementations. The MSR-based PMU support includes the following updates: 1. Register MSR-based PMU support for the supported platforms and unregister it when no online CPUs remain in the package. 2. Remove existing checks that restrict RAPL PMU support to TPMI-based interfaces and extend the logic to allow MSR-based RAPL interfaces. 3. Define a CPU model list to determine which processors should register RAPL PMU interface through the powercap driver for MSR-based RAPL, excluding those that support TPMI interface. This list prevents conflicts with existing arch/x86 PMU code that already registers RAPL PMU for some processors. Add Panther Lake & Wildcat Lake to the CPU models list. Signed-off-by: Kuppuswamy Sathyanarayanan <[email protected]> Reviewed-by: Srinivas Pandruvada <[email protected]> [ rjw: Changelog edits ] Link: https://patch.msgid.link/20251121000539.386069-3-sathyanarayanan.kuppuswamy@linux.intel.com Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 1d6c915 commit 748d6ba

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

drivers/powercap/intel_rapl_common.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,11 +1597,11 @@ static int get_pmu_cpu(struct rapl_package *rp)
15971597
if (!rp->has_pmu)
15981598
return nr_cpu_ids;
15991599

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

1604-
/* TPMI RAPL uses any CPU in the package for PMU */
1604+
/* 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)
16071607
return cpu;
@@ -1614,11 +1614,11 @@ static bool is_rp_pmu_cpu(struct rapl_package *rp, int cpu)
16141614
if (!rp->has_pmu)
16151615
return false;
16161616

1617-
/* Only TPMI RAPL is supported for now */
1618-
if (rp->priv->type != RAPL_IF_TPMI)
1617+
/* Only TPMI & MSR RAPL are supported for now */
1618+
if (rp->priv->type != RAPL_IF_TPMI && rp->priv->type != RAPL_IF_MSR)
16191619
return false;
16201620

1621-
/* TPMI RAPL uses any CPU in the package for PMU */
1621+
/* TPMI/MSR RAPL uses any CPU in the package for PMU */
16221622
return topology_physical_package_id(cpu) == rp->id;
16231623
}
16241624

drivers/powercap/intel_rapl_msr.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
/* private data for RAPL MSR Interface */
3434
static struct rapl_if_priv *rapl_msr_priv;
3535

36+
static bool rapl_msr_pmu __ro_after_init;
37+
3638
static struct rapl_if_priv rapl_msr_priv_intel = {
3739
.type = RAPL_IF_MSR,
3840
.reg_unit.msr = MSR_RAPL_POWER_UNIT,
@@ -79,6 +81,8 @@ static int rapl_cpu_online(unsigned int cpu)
7981
rp = rapl_add_package_cpuslocked(cpu, rapl_msr_priv, true);
8082
if (IS_ERR(rp))
8183
return PTR_ERR(rp);
84+
if (rapl_msr_pmu)
85+
rapl_package_add_pmu(rp);
8286
}
8387
cpumask_set_cpu(cpu, &rp->cpumask);
8488
return 0;
@@ -95,10 +99,14 @@ static int rapl_cpu_down_prep(unsigned int cpu)
9599

96100
cpumask_clear_cpu(cpu, &rp->cpumask);
97101
lead_cpu = cpumask_first(&rp->cpumask);
98-
if (lead_cpu >= nr_cpu_ids)
102+
if (lead_cpu >= nr_cpu_ids) {
103+
if (rapl_msr_pmu)
104+
rapl_package_remove_pmu(rp);
99105
rapl_remove_package_cpuslocked(rp);
100-
else if (rp->lead_cpu == cpu)
106+
} else if (rp->lead_cpu == cpu) {
101107
rp->lead_cpu = lead_cpu;
108+
}
109+
102110
return 0;
103111
}
104112

@@ -171,6 +179,13 @@ static const struct x86_cpu_id pl4_support_ids[] = {
171179
{}
172180
};
173181

182+
/* List of MSR-based RAPL PMU support CPUs */
183+
static const struct x86_cpu_id pmu_support_ids[] = {
184+
X86_MATCH_VFM(INTEL_PANTHERLAKE_L, NULL),
185+
X86_MATCH_VFM(INTEL_WILDCATLAKE_L, NULL),
186+
{}
187+
};
188+
174189
static int rapl_msr_probe(struct platform_device *pdev)
175190
{
176191
const struct x86_cpu_id *id = x86_match_cpu(pl4_support_ids);
@@ -198,6 +213,11 @@ static int rapl_msr_probe(struct platform_device *pdev)
198213
pr_info("PL4 support detected.\n");
199214
}
200215

216+
if (x86_match_cpu(pmu_support_ids)) {
217+
rapl_msr_pmu = true;
218+
pr_info("MSR-based RAPL PMU support enabled\n");
219+
}
220+
201221
rapl_msr_priv->control_type = powercap_register_control_type(NULL, "intel-rapl", NULL);
202222
if (IS_ERR(rapl_msr_priv->control_type)) {
203223
pr_debug("failed to register powercap control_type.\n");

0 commit comments

Comments
 (0)