Skip to content

Commit ef98988

Browse files
committed
Merge tag 'pm-extra-4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull more power management updates from Rafael Wysocki: "This includes a couple of fixes for cpufreq regressions introduced in 4.8, a rework of the intel_pstate algorithm used on Atom processors (that took some time to test) plus a fix and a couple of cleanups in that driver, a CPPC cpufreq driver fix, and a some devfreq fixes and cleanups (core and exynos-nocp). Specifics: - Fix two cpufreq regressions causing undesirable changes in behavior to appear (one in the core and one in the conservative governor) introduced during the 4.8 cycle (Aaro Koskinen, Rafael Wysocki). - Fix the way the intel_pstate driver accesses MSRs related to the hardware-managed P-states (HWP) feature during the initialization which currently is unsafe and may cause the processor to generate a general protection fault (Srinivas Pandruvada). - Rework the intel_pstate's P-state selection algorithm used on Atom processors to avoid known problems with the current one and to make the computation more straightforward, which also happens to improve performance in multiple benchmarks a bit (Rafael Wysocki). - Improve two comments in the intel_pstate driver (Rafael Wysocki). - Fix the desired performance computation in the CPPC cpufreq driver (Hoan Tran). - Fix the devfreq core to avoid printing misleading error messages in some cases (Tobias Jakobi). - Fix the error code path in devfreq_add_device() to use proper locking around list modifications (Axel Lin). - Fix a build failure and remove a couple of redundant updates of variables in the exynos-nocp devfreq driver (Axel Lin)" * tag 'pm-extra-4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: cpufreq: CPPC: Correct desired_perf calculation cpufreq: conservative: Fix next frequency selection cpufreq: skip invalid entries when searching the frequency cpufreq: intel_pstate: Fix struct pstate_adjust_policy kerneldoc cpufreq: intel_pstate: Proportional algorithm for Atom PM / devfreq: Skip status update on uninitialized previous_freq PM / devfreq: Add proper locking around list_del() PM / devfreq: exynos-nocp: Remove redundant code PM / devfreq: exynos-nocp: Select REGMAP_MMIO cpufreq: intel_pstate: Clarify comment in get_target_pstate_use_performance() cpufreq: intel_pstate: Fix unsafe HWP MSR access
2 parents f34d360 + 383731d commit ef98988

7 files changed

Lines changed: 115 additions & 71 deletions

File tree

‎drivers/cpufreq/cppc_cpufreq.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
8080
{
8181
struct cppc_cpudata *cpu;
8282
struct cpufreq_freqs freqs;
83+
u32 desired_perf;
8384
int ret = 0;
8485

8586
cpu = all_cpu_data[policy->cpu];
8687

87-
cpu->perf_ctrls.desired_perf = (u64)target_freq * policy->max / cppc_dmi_max_khz;
88+
desired_perf = (u64)target_freq * cpu->perf_caps.highest_perf / cppc_dmi_max_khz;
89+
/* Return if it is exactly the same perf */
90+
if (desired_perf == cpu->perf_ctrls.desired_perf)
91+
return ret;
92+
93+
cpu->perf_ctrls.desired_perf = desired_perf;
8894
freqs.old = policy->cur;
8995
freqs.new = target_freq;
9096

‎drivers/cpufreq/cpufreq_conservative.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
struct cs_policy_dbs_info {
1818
struct policy_dbs_info policy_dbs;
1919
unsigned int down_skip;
20+
unsigned int requested_freq;
2021
};
2122

2223
static inline struct cs_policy_dbs_info *to_dbs_info(struct policy_dbs_info *policy_dbs)
@@ -61,6 +62,7 @@ static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
6162
{
6263
struct policy_dbs_info *policy_dbs = policy->governor_data;
6364
struct cs_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs);
65+
unsigned int requested_freq = dbs_info->requested_freq;
6466
struct dbs_data *dbs_data = policy_dbs->dbs_data;
6567
struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
6668
unsigned int load = dbs_update(policy);
@@ -72,19 +74,28 @@ static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
7274
if (cs_tuners->freq_step == 0)
7375
goto out;
7476

77+
/*
78+
* If requested_freq is out of range, it is likely that the limits
79+
* changed in the meantime, so fall back to current frequency in that
80+
* case.
81+
*/
82+
if (requested_freq > policy->max || requested_freq < policy->min)
83+
requested_freq = policy->cur;
84+
7585
/* Check for frequency increase */
7686
if (load > dbs_data->up_threshold) {
77-
unsigned int requested_freq = policy->cur;
78-
7987
dbs_info->down_skip = 0;
8088

8189
/* if we are already at full speed then break out early */
8290
if (requested_freq == policy->max)
8391
goto out;
8492

8593
requested_freq += get_freq_target(cs_tuners, policy);
94+
if (requested_freq > policy->max)
95+
requested_freq = policy->max;
8696

8797
__cpufreq_driver_target(policy, requested_freq, CPUFREQ_RELATION_H);
98+
dbs_info->requested_freq = requested_freq;
8899
goto out;
89100
}
90101

@@ -95,7 +106,7 @@ static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
95106

96107
/* Check for frequency decrease */
97108
if (load < cs_tuners->down_threshold) {
98-
unsigned int freq_target, requested_freq = policy->cur;
109+
unsigned int freq_target;
99110
/*
100111
* if we cannot reduce the frequency anymore, break out early
101112
*/
@@ -109,6 +120,7 @@ static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
109120
requested_freq = policy->min;
110121

111122
__cpufreq_driver_target(policy, requested_freq, CPUFREQ_RELATION_L);
123+
dbs_info->requested_freq = requested_freq;
112124
}
113125

114126
out:
@@ -287,6 +299,7 @@ static void cs_start(struct cpufreq_policy *policy)
287299
struct cs_policy_dbs_info *dbs_info = to_dbs_info(policy->governor_data);
288300

289301
dbs_info->down_skip = 0;
302+
dbs_info->requested_freq = policy->cur;
290303
}
291304

292305
static struct dbs_governor cs_governor = {

‎drivers/cpufreq/intel_pstate.c‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ struct cpudata {
225225
static struct cpudata **all_cpu_data;
226226

227227
/**
228-
* struct pid_adjust_policy - Stores static PID configuration data
228+
* struct pstate_adjust_policy - Stores static PID configuration data
229229
* @sample_rate_ms: PID calculation sample rate in ms
230230
* @sample_rate_ns: Sample rate calculation in ns
231231
* @deadband: PID deadband
@@ -562,12 +562,12 @@ static void intel_pstate_hwp_set(const struct cpumask *cpumask)
562562
int min, hw_min, max, hw_max, cpu, range, adj_range;
563563
u64 value, cap;
564564

565-
rdmsrl(MSR_HWP_CAPABILITIES, cap);
566-
hw_min = HWP_LOWEST_PERF(cap);
567-
hw_max = HWP_HIGHEST_PERF(cap);
568-
range = hw_max - hw_min;
569-
570565
for_each_cpu(cpu, cpumask) {
566+
rdmsrl_on_cpu(cpu, MSR_HWP_CAPABILITIES, &cap);
567+
hw_min = HWP_LOWEST_PERF(cap);
568+
hw_max = HWP_HIGHEST_PERF(cap);
569+
range = hw_max - hw_min;
570+
571571
rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value);
572572
adj_range = limits->min_perf_pct * range / 100;
573573
min = hw_min + adj_range;
@@ -1232,6 +1232,7 @@ static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
12321232
{
12331233
struct sample *sample = &cpu->sample;
12341234
int32_t busy_frac, boost;
1235+
int target, avg_pstate;
12351236

12361237
busy_frac = div_fp(sample->mperf, sample->tsc);
12371238

@@ -1242,7 +1243,26 @@ static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
12421243
busy_frac = boost;
12431244

12441245
sample->busy_scaled = busy_frac * 100;
1245-
return get_avg_pstate(cpu) - pid_calc(&cpu->pid, sample->busy_scaled);
1246+
1247+
target = limits->no_turbo || limits->turbo_disabled ?
1248+
cpu->pstate.max_pstate : cpu->pstate.turbo_pstate;
1249+
target += target >> 2;
1250+
target = mul_fp(target, busy_frac);
1251+
if (target < cpu->pstate.min_pstate)
1252+
target = cpu->pstate.min_pstate;
1253+
1254+
/*
1255+
* If the average P-state during the previous cycle was higher than the
1256+
* current target, add 50% of the difference to the target to reduce
1257+
* possible performance oscillations and offset possible performance
1258+
* loss related to moving the workload from one CPU to another within
1259+
* a package/module.
1260+
*/
1261+
avg_pstate = get_avg_pstate(cpu);
1262+
if (avg_pstate > target)
1263+
target += (avg_pstate - target) >> 1;
1264+
1265+
return target;
12461266
}
12471267

12481268
static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
@@ -1251,10 +1271,11 @@ static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
12511271
u64 duration_ns;
12521272

12531273
/*
1254-
* perf_scaled is the average performance during the last sampling
1255-
* period scaled by the ratio of the maximum P-state to the P-state
1256-
* requested last time (in percent). That measures the system's
1257-
* response to the previous P-state selection.
1274+
* perf_scaled is the ratio of the average P-state during the last
1275+
* sampling period to the P-state requested last time (in percent).
1276+
*
1277+
* That measures the system's response to the previous P-state
1278+
* selection.
12581279
*/
12591280
max_pstate = cpu->pstate.max_pstate_physical;
12601281
current_pstate = cpu->pstate.current_pstate;

‎drivers/devfreq/devfreq.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ static int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
137137

138138
cur_time = jiffies;
139139

140+
/* Immediately exit if previous_freq is not initialized yet. */
141+
if (!devfreq->previous_freq)
142+
goto out;
143+
140144
prev_lev = devfreq_get_freq_level(devfreq, devfreq->previous_freq);
141145
if (prev_lev < 0) {
142146
ret = prev_lev;
@@ -594,17 +598,19 @@ struct devfreq *devfreq_add_device(struct device *dev,
594598
if (devfreq->governor)
595599
err = devfreq->governor->event_handler(devfreq,
596600
DEVFREQ_GOV_START, NULL);
597-
mutex_unlock(&devfreq_list_lock);
598601
if (err) {
599602
dev_err(dev, "%s: Unable to start governor for the device\n",
600603
__func__);
601604
goto err_init;
602605
}
606+
mutex_unlock(&devfreq_list_lock);
603607

604608
return devfreq;
605609

606610
err_init:
607611
list_del(&devfreq->node);
612+
mutex_unlock(&devfreq_list_lock);
613+
608614
device_unregister(&devfreq->dev);
609615
err_out:
610616
return ERR_PTR(err);

‎drivers/devfreq/event/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config DEVFREQ_EVENT_EXYNOS_NOCP
1717
tristate "EXYNOS NoC (Network On Chip) Probe DEVFREQ event Driver"
1818
depends on ARCH_EXYNOS || COMPILE_TEST
1919
select PM_OPP
20+
select REGMAP_MMIO
2021
help
2122
This add the devfreq-event driver for Exynos SoC. It provides NoC
2223
(Network on Chip) Probe counters to measure the bandwidth of AXI bus.

‎drivers/devfreq/event/exynos-nocp.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ static int exynos_nocp_get_event(struct devfreq_event_dev *edev,
176176
return 0;
177177

178178
out:
179-
edata->load_count = 0;
180-
edata->total_count = 0;
181-
182179
dev_err(nocp->dev, "Failed to read the counter of NoC probe device\n");
183180

184181
return ret;

0 commit comments

Comments
 (0)