Skip to content

Commit 9642092

Browse files
zhang-ruirafaeljw
authored andcommitted
powercap: intel_rapl: Do not change CLAMPING bit if ENABLE bit cannot be changed
PL1 cannot be disabled on some platforms. The ENABLE bit is still set after software clears it. This behavior leads to a scenario where, upon user request to disable the Power Limit through the powercap sysfs, the ENABLE bit remains set while the CLAMPING bit is inadvertently cleared. According to the Intel Software Developer's Manual, the CLAMPING bit, "When set, allows the processor to go below the OS requested P states in order to maintain the power below specified Platform Power Limit value." Thus this means the system may operate at higher power levels than intended on such platforms. Enhance the code to check ENABLE bit after writing to it, and stop further processing if ENABLE bit cannot be changed. Reported-by: Srinivas Pandruvada <[email protected]> Fixes: 2d281d8 ("PowerCap: Introduce Intel RAPL power capping driver") Cc: All applicable <[email protected]> Signed-off-by: Zhang Rui <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Use str_enabled_disabled() instead of open-coded equivalent ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent d0b3b7b commit 9642092

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

drivers/powercap/intel_rapl_common.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,28 @@ static int set_domain_enable(struct powercap_zone *power_zone, bool mode)
341341
{
342342
struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone);
343343
struct rapl_defaults *defaults = get_defaults(rd->rp);
344+
u64 val;
344345
int ret;
345346

346347
cpus_read_lock();
347348
ret = rapl_write_pl_data(rd, POWER_LIMIT1, PL_ENABLE, mode);
348-
if (!ret && defaults->set_floor_freq)
349+
if (ret)
350+
goto end;
351+
352+
ret = rapl_read_pl_data(rd, POWER_LIMIT1, PL_ENABLE, false, &val);
353+
if (ret)
354+
goto end;
355+
356+
if (mode != val) {
357+
pr_debug("%s cannot be %s\n", power_zone->name,
358+
str_enabled_disabled(mode));
359+
goto end;
360+
}
361+
362+
if (defaults->set_floor_freq)
349363
defaults->set_floor_freq(rd, mode);
364+
365+
end:
350366
cpus_read_unlock();
351367

352368
return ret;

0 commit comments

Comments
 (0)