Skip to content

Commit 35ed8fa

Browse files
committed
Merge back earlier cpufreq material for 7.1
2 parents 6dcf9d0 + 2e00c2d commit 35ed8fa

10 files changed

Lines changed: 72 additions & 73 deletions

File tree

drivers/acpi/cppc_acpi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private)
19441944
}
19451945

19461946
/* Look up the max frequency in DMI */
1947-
static u64 cppc_get_dmi_max_khz(void)
1947+
u64 cppc_get_dmi_max_khz(void)
19481948
{
19491949
u16 mhz = 0;
19501950

@@ -1958,6 +1958,7 @@ static u64 cppc_get_dmi_max_khz(void)
19581958

19591959
return KHZ_PER_MHZ * mhz;
19601960
}
1961+
EXPORT_SYMBOL_GPL(cppc_get_dmi_max_khz);
19611962

19621963
/*
19631964
* If CPPC lowest_freq and nominal_freq registers are exposed then we can

drivers/cpufreq/Kconfig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ config CPU_FREQ_GOV_ONDEMAND
163163

164164
config CPU_FREQ_GOV_CONSERVATIVE
165165
tristate "'conservative' cpufreq governor"
166-
depends on CPU_FREQ
167166
select CPU_FREQ_GOV_COMMON
168167
help
169168
'conservative' - this driver is rather similar to the 'ondemand'
@@ -188,7 +187,7 @@ config CPU_FREQ_GOV_CONSERVATIVE
188187

189188
config CPU_FREQ_GOV_SCHEDUTIL
190189
bool "'schedutil' cpufreq policy governor"
191-
depends on CPU_FREQ && SMP
190+
depends on SMP
192191
select CPU_FREQ_GOV_ATTR_SET
193192
select IRQ_WORK
194193
help
@@ -365,6 +364,6 @@ config ACPI_CPPC_CPUFREQ_FIE
365364

366365
If in doubt, say N.
367366

368-
endif
367+
endif # CPU_FREQ
369368

370369
endmenu

drivers/cpufreq/acpi-cpufreq.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,29 @@ static inline u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq)
675675
}
676676
#endif
677677

678+
static void acpi_cpufreq_resolve_max_freq(struct cpufreq_policy *policy,
679+
unsigned int pss_max_freq)
680+
{
681+
#ifdef CONFIG_ACPI_CPPC_LIB
682+
u64 max_speed = cppc_get_dmi_max_khz();
683+
/*
684+
* Use DMI "Max Speed" if it looks plausible: must be
685+
* above _PSS P0 frequency and within 2x of it.
686+
*/
687+
if (max_speed > pss_max_freq && max_speed < pss_max_freq * 2) {
688+
policy->cpuinfo.max_freq = max_speed;
689+
return;
690+
}
691+
#endif
692+
/*
693+
* If the maximum "boost" frequency is unknown, ask the arch
694+
* scale-invariance code to use the "nominal" performance for
695+
* CPU utilization scaling so as to prevent the schedutil
696+
* governor from selecting inadequate CPU frequencies.
697+
*/
698+
arch_set_max_freq_ratio(true);
699+
}
700+
678701
static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
679702
{
680703
struct cpufreq_frequency_table *freq_table;
@@ -849,13 +872,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
849872

850873
policy->cpuinfo.max_freq = freq * max_boost_ratio >> SCHED_CAPACITY_SHIFT;
851874
} else {
852-
/*
853-
* If the maximum "boost" frequency is unknown, ask the arch
854-
* scale-invariance code to use the "nominal" performance for
855-
* CPU utilization scaling so as to prevent the schedutil
856-
* governor from selecting inadequate CPU frequencies.
857-
*/
858-
arch_set_max_freq_ratio(true);
875+
acpi_cpufreq_resolve_max_freq(policy, freq_table[0].frequency);
859876
}
860877

861878
policy->freq_table = freq_table;

drivers/cpufreq/amd-pstate.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,6 @@ static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on)
769769
else if (policy->cpuinfo.max_freq > nominal_freq)
770770
policy->cpuinfo.max_freq = nominal_freq;
771771

772-
policy->max = policy->cpuinfo.max_freq;
773-
774772
if (cppc_state == AMD_PSTATE_PASSIVE) {
775773
ret = freq_qos_update_request(&cpudata->req[1], policy->cpuinfo.max_freq);
776774
if (ret < 0)

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -807,17 +807,11 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)
807807
{
808808
struct cppc_cpudata *cpu_data = policy->driver_data;
809809
struct cppc_perf_caps *caps = &cpu_data->perf_caps;
810-
int ret;
811810

812811
if (state)
813-
policy->max = cppc_perf_to_khz(caps, caps->highest_perf);
812+
policy->cpuinfo.max_freq = cppc_perf_to_khz(caps, caps->highest_perf);
814813
else
815-
policy->max = cppc_perf_to_khz(caps, caps->nominal_perf);
816-
policy->cpuinfo.max_freq = policy->max;
817-
818-
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
819-
if (ret < 0)
820-
return ret;
814+
policy->cpuinfo.max_freq = cppc_perf_to_khz(caps, caps->nominal_perf);
821815

822816
return 0;
823817
}

drivers/cpufreq/cpufreq.c

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,19 @@ static int policy_set_boost(struct cpufreq_policy *policy, bool enable)
609609
policy->boost_enabled = enable;
610610

611611
ret = cpufreq_driver->set_boost(policy, enable);
612-
if (ret)
612+
if (ret) {
613613
policy->boost_enabled = !policy->boost_enabled;
614+
return ret;
615+
}
614616

615-
return ret;
617+
ret = freq_qos_update_request(&policy->boost_freq_req, policy->cpuinfo.max_freq);
618+
if (ret < 0) {
619+
policy->boost_enabled = !policy->boost_enabled;
620+
cpufreq_driver->set_boost(policy, policy->boost_enabled);
621+
return ret;
622+
}
623+
624+
return 0;
616625
}
617626

618627
static ssize_t store_local_boost(struct cpufreq_policy *policy,
@@ -760,7 +769,7 @@ static ssize_t store_##file_name \
760769
if (ret) \
761770
return ret; \
762771
\
763-
ret = freq_qos_update_request(policy->object##_freq_req, val);\
772+
ret = freq_qos_update_request(&policy->object##_freq_req, val); \
764773
return ret >= 0 ? count : ret; \
765774
}
766775

@@ -1365,19 +1374,21 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
13651374
/* Cancel any pending policy->update work before freeing the policy. */
13661375
cancel_work_sync(&policy->update);
13671376

1368-
if (policy->max_freq_req) {
1377+
if (freq_qos_request_active(&policy->max_freq_req)) {
13691378
/*
13701379
* Remove max_freq_req after sending CPUFREQ_REMOVE_POLICY
13711380
* notification, since CPUFREQ_CREATE_POLICY notification was
13721381
* sent after adding max_freq_req earlier.
13731382
*/
13741383
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
13751384
CPUFREQ_REMOVE_POLICY, policy);
1376-
freq_qos_remove_request(policy->max_freq_req);
1385+
freq_qos_remove_request(&policy->max_freq_req);
13771386
}
13781387

1379-
freq_qos_remove_request(policy->min_freq_req);
1380-
kfree(policy->min_freq_req);
1388+
if (freq_qos_request_active(&policy->min_freq_req))
1389+
freq_qos_remove_request(&policy->min_freq_req);
1390+
if (freq_qos_request_active(&policy->boost_freq_req))
1391+
freq_qos_remove_request(&policy->boost_freq_req);
13811392

13821393
cpufreq_policy_put_kobj(policy);
13831394
free_cpumask_var(policy->real_cpus);
@@ -1447,47 +1458,29 @@ static int cpufreq_policy_online(struct cpufreq_policy *policy,
14471458
add_cpu_dev_symlink(policy, j, get_cpu_device(j));
14481459
}
14491460

1450-
policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req),
1451-
GFP_KERNEL);
1452-
if (!policy->min_freq_req) {
1453-
ret = -ENOMEM;
1454-
goto out_destroy_policy;
1461+
if (policy->boost_supported) {
1462+
ret = freq_qos_add_request(&policy->constraints,
1463+
&policy->boost_freq_req,
1464+
FREQ_QOS_MAX,
1465+
policy->cpuinfo.max_freq);
1466+
if (ret < 0)
1467+
goto out_destroy_policy;
14551468
}
14561469

14571470
ret = freq_qos_add_request(&policy->constraints,
1458-
policy->min_freq_req, FREQ_QOS_MIN,
1471+
&policy->min_freq_req, FREQ_QOS_MIN,
14591472
FREQ_QOS_MIN_DEFAULT_VALUE);
1460-
if (ret < 0) {
1461-
/*
1462-
* So we don't call freq_qos_remove_request() for an
1463-
* uninitialized request.
1464-
*/
1465-
kfree(policy->min_freq_req);
1466-
policy->min_freq_req = NULL;
1473+
if (ret < 0)
14671474
goto out_destroy_policy;
1468-
}
1469-
1470-
/*
1471-
* This must be initialized right here to avoid calling
1472-
* freq_qos_remove_request() on uninitialized request in case
1473-
* of errors.
1474-
*/
1475-
policy->max_freq_req = policy->min_freq_req + 1;
14761475

14771476
ret = freq_qos_add_request(&policy->constraints,
1478-
policy->max_freq_req, FREQ_QOS_MAX,
1477+
&policy->max_freq_req, FREQ_QOS_MAX,
14791478
FREQ_QOS_MAX_DEFAULT_VALUE);
1480-
if (ret < 0) {
1481-
policy->max_freq_req = NULL;
1479+
if (ret < 0)
14821480
goto out_destroy_policy;
1483-
}
14841481

14851482
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
14861483
CPUFREQ_CREATE_POLICY, policy);
1487-
} else {
1488-
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
1489-
if (ret < 0)
1490-
goto out_destroy_policy;
14911484
}
14921485

14931486
if (cpufreq_driver->get && has_target()) {
@@ -2364,8 +2357,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
23642357
target_freq = __resolve_freq(policy, target_freq, policy->min,
23652358
policy->max, relation);
23662359

2367-
pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
2368-
policy->cpu, target_freq, relation, old_target_freq);
2360+
pr_debug("CPU %u: cur %u kHz -> target %u kHz (req %u kHz, rel %u)\n",
2361+
policy->cpu, policy->cur, target_freq, old_target_freq, relation);
23692362

23702363
/*
23712364
* This might look like a redundant call as we are checking it again
@@ -2789,16 +2782,10 @@ int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)
27892782
return -ENXIO;
27902783

27912784
ret = cpufreq_frequency_table_cpuinfo(policy);
2792-
if (ret) {
2785+
if (ret)
27932786
pr_err("%s: Policy frequency update failed\n", __func__);
2794-
return ret;
2795-
}
2796-
2797-
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
2798-
if (ret < 0)
2799-
return ret;
28002787

2801-
return 0;
2788+
return ret;
28022789
}
28032790
EXPORT_SYMBOL_GPL(cpufreq_boost_set_sw);
28042791

drivers/cpufreq/cpufreq_governor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/kernel_stat.h>
2222
#include <linux/module.h>
2323
#include <linux/mutex.h>
24+
#include <linux/sysfs.h>
2425

2526
/* Ondemand Sampling types */
2627
enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE};
@@ -57,15 +58,15 @@ static ssize_t file_name##_show \
5758
{ \
5859
struct dbs_data *dbs_data = to_dbs_data(attr_set); \
5960
struct _gov##_dbs_tuners *tuners = dbs_data->tuners; \
60-
return sprintf(buf, "%u\n", tuners->file_name); \
61+
return sysfs_emit(buf, "%u\n", tuners->file_name); \
6162
}
6263

6364
#define gov_show_one_common(file_name) \
6465
static ssize_t file_name##_show \
6566
(struct gov_attr_set *attr_set, char *buf) \
6667
{ \
6768
struct dbs_data *dbs_data = to_dbs_data(attr_set); \
68-
return sprintf(buf, "%u\n", dbs_data->file_name); \
69+
return sysfs_emit(buf, "%u\n", dbs_data->file_name); \
6970
}
7071

7172
#define gov_attr_ro(_name) \

drivers/cpufreq/intel_pstate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3472,7 +3472,7 @@ static int intel_pstate_update_status(const char *buf, size_t size)
34723472
{
34733473
if (size == 3 && !strncmp(buf, "off", size)) {
34743474
if (!intel_pstate_driver)
3475-
return -EINVAL;
3475+
return 0;
34763476

34773477
if (hwp_active)
34783478
return -EBUSY;

include/acpi/cppc_acpi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ extern int cppc_set_enable(int cpu, bool enable);
156156
extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps);
157157
extern bool cppc_perf_ctrs_in_pcc_cpu(unsigned int cpu);
158158
extern bool cppc_perf_ctrs_in_pcc(void);
159+
extern u64 cppc_get_dmi_max_khz(void);
159160
extern unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf);
160161
extern unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int freq);
161162
extern bool acpi_cpc_valid(void);

include/linux/cpufreq.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ struct cpufreq_policy {
7979
* called, but you're in IRQ context */
8080

8181
struct freq_constraints constraints;
82-
struct freq_qos_request *min_freq_req;
83-
struct freq_qos_request *max_freq_req;
82+
struct freq_qos_request min_freq_req;
83+
struct freq_qos_request max_freq_req;
84+
struct freq_qos_request boost_freq_req;
8485

8586
struct cpufreq_frequency_table *freq_table;
8687
enum cpufreq_table_sorting freq_table_sorted;
@@ -232,7 +233,7 @@ static inline bool policy_is_inactive(struct cpufreq_policy *policy)
232233

233234
static inline bool policy_is_shared(struct cpufreq_policy *policy)
234235
{
235-
return cpumask_weight(policy->cpus) > 1;
236+
return cpumask_nth(1, policy->cpus) < nr_cpumask_bits;
236237
}
237238

238239
#ifdef CONFIG_CPU_FREQ

0 commit comments

Comments
 (0)