Skip to content

Commit

Permalink
thermal: intel: powerclamp: Fix cur_state for multi package system
Browse files Browse the repository at this point in the history
commit 8e47363 upstream.

The powerclamp cooling device cur_state shows actual idle observed by
package C-state idle counters. But the implementation is not sufficient
for multi package or multi die system. The cur_state value is incorrect.
On these systems, these counters must be read from each package/die and
somehow aggregate them. But there is no good method for aggregation.

It was not a problem when explicit CPU model addition was required to
enable intel powerclamp. In this way certain CPU models could have
been avoided. But with the removal of CPU model check with the
availability of Package C-state counters, the driver is loaded on most
of the recent systems.

For multi package/die systems, just show the actual target idle state,
the system is trying to achieve. In powerclamp this is the user set
state minus one.

Also there is no use of starting a worker thread for polling package
C-state counters and applying any compensation for multiple package
or multiple die systems.

Fixes: b721ca0 ("thermal/powerclamp: remove cpu whitelist")
Signed-off-by: Srinivas Pandruvada <[email protected]>
Cc: 4.14+ <[email protected]> # 4.14+
Signed-off-by: Rafael J. Wysocki <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
spandruvada authored and gregkh committed Mar 10, 2023
1 parent 6f2bce8 commit b57ba4e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions drivers/thermal/intel/intel_powerclamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

static unsigned int target_mwait;
static struct dentry *debug_dir;
static bool poll_pkg_cstate_enable;

/* user selected target */
static unsigned int set_target_ratio;
Expand Down Expand Up @@ -261,6 +262,9 @@ static unsigned int get_compensation(int ratio)
{
unsigned int comp = 0;

if (!poll_pkg_cstate_enable)
return 0;

/* we only use compensation if all adjacent ones are good */
if (ratio == 1 &&
cal_data[ratio].confidence >= CONFIDENCE_OK &&
Expand Down Expand Up @@ -519,7 +523,8 @@ static int start_power_clamp(void)
control_cpu = cpumask_first(cpu_online_mask);

clamping = true;
schedule_delayed_work(&poll_pkg_cstate_work, 0);
if (poll_pkg_cstate_enable)
schedule_delayed_work(&poll_pkg_cstate_work, 0);

/* start one kthread worker per online cpu */
for_each_online_cpu(cpu) {
Expand Down Expand Up @@ -585,11 +590,15 @@ static int powerclamp_get_max_state(struct thermal_cooling_device *cdev,
static int powerclamp_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
if (true == clamping)
*state = pkg_cstate_ratio_cur;
else
if (clamping) {
if (poll_pkg_cstate_enable)
*state = pkg_cstate_ratio_cur;
else
*state = set_target_ratio;
} else {
/* to save power, do not poll idle ratio while not clamping */
*state = -1; /* indicates invalid state */
}

return 0;
}
Expand Down Expand Up @@ -712,6 +721,9 @@ static int __init powerclamp_init(void)
goto exit_unregister;
}

if (topology_max_packages() == 1 && topology_max_die_per_package() == 1)
poll_pkg_cstate_enable = true;

cooling_dev = thermal_cooling_device_register("intel_powerclamp", NULL,
&powerclamp_cooling_ops);
if (IS_ERR(cooling_dev)) {
Expand Down

0 comments on commit b57ba4e

Please sign in to comment.