Skip to content

Commit 7537bae

Browse files
Kuppuswamy Sathyanarayananrafaeljw
authored andcommitted
powercap: intel_rapl: Remove incorrect CPU check in PMU context
The RAPL MSR read path incorrectly validates CPU context when called from the PMU subsystem: if (atomic) { if (unlikely(smp_processor_id() != cpu)) return -EIO; rdmsrq(ra->reg.msr, ra->value); } This check fails for package-scoped MSRs like RAPL energy counters, which are readable from any CPU within the package. The perf tool avoids hitting this check by validating against /sys/bus/event_source/devices/power/cpumask before opening events. However, turbostat does not perform this validation and may attempt reads from non-lead CPUs, causing the check to fail and return zero power values. Since package-scoped MSRs are architecturally accessible from any CPU in the package, remove the CPU matching check. Also rename 'atomic' to 'pmu_ctx' to clarify this indicates PMU context where rdmsrq() can be used directly instead of rdmsrl_safe_on_cpu(). Fixes: 748d6ba ("powercap: intel_rapl: Enable MSR-based RAPL PMU support") 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-2-sathyanarayanan.kuppuswamy@linux.intel.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 9b1b3dc commit 7537bae

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

drivers/powercap/intel_rapl_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static void rapl_init_domains(struct rapl_package *rp);
254254
static int rapl_read_data_raw(struct rapl_domain *rd,
255255
enum rapl_primitives prim,
256256
bool xlate, u64 *data,
257-
bool atomic);
257+
bool pmu_ctx);
258258
static int rapl_write_data_raw(struct rapl_domain *rd,
259259
enum rapl_primitives prim,
260260
unsigned long long value);
@@ -832,7 +832,7 @@ prim_fixups(struct rapl_domain *rd, enum rapl_primitives prim)
832832
*/
833833
static int rapl_read_data_raw(struct rapl_domain *rd,
834834
enum rapl_primitives prim, bool xlate, u64 *data,
835-
bool atomic)
835+
bool pmu_ctx)
836836
{
837837
u64 value;
838838
enum rapl_primitives prim_fixed = prim_fixups(rd, prim);
@@ -854,7 +854,7 @@ static int rapl_read_data_raw(struct rapl_domain *rd,
854854

855855
ra.mask = rpi->mask;
856856

857-
if (rd->rp->priv->read_raw(get_rid(rd->rp), &ra, atomic)) {
857+
if (rd->rp->priv->read_raw(get_rid(rd->rp), &ra, pmu_ctx)) {
858858
pr_debug("failed to read reg 0x%llx for %s:%s\n", ra.reg.val, rd->rp->name, rd->name);
859859
return -EIO;
860860
}

drivers/powercap/intel_rapl_msr.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,14 @@ static int rapl_cpu_down_prep(unsigned int cpu)
110110
return 0;
111111
}
112112

113-
static int rapl_msr_read_raw(int cpu, struct reg_action *ra, bool atomic)
113+
static int rapl_msr_read_raw(int cpu, struct reg_action *ra, bool pmu_ctx)
114114
{
115115
/*
116-
* When called from atomic-context (eg PMU event handler)
117-
* perform MSR read directly using rdmsrq().
116+
* When called from PMU context, perform MSR read directly using
117+
* rdmsrq() without IPI overhead. Package-scoped MSRs are readable
118+
* from any CPU in the package.
118119
*/
119-
if (atomic) {
120-
if (unlikely(smp_processor_id() != cpu))
121-
return -EIO;
122-
120+
if (pmu_ctx) {
123121
rdmsrq(ra->reg.msr, ra->value);
124122
goto out;
125123
}

include/linux/intel_rapl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct rapl_if_priv {
152152
union rapl_reg reg_unit;
153153
union rapl_reg regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
154154
int limits[RAPL_DOMAIN_MAX];
155-
int (*read_raw)(int id, struct reg_action *ra, bool atomic);
155+
int (*read_raw)(int id, struct reg_action *ra, bool pmu_ctx);
156156
int (*write_raw)(int id, struct reg_action *ra);
157157
void *defaults;
158158
void *rpi;

0 commit comments

Comments
 (0)