Skip to content

Commit 4f95b5b

Browse files
committed
Merge back earlier cpufreq material for 6.17-rc1
2 parents 84bb8c1 + 0ae2044 commit 4f95b5b

6 files changed

Lines changed: 49 additions & 76 deletions

File tree

Documentation/admin-guide/pm/cpufreq.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ policy limits change after that.
398398

399399
This governor does not do anything by itself. Instead, it allows user space
400400
to set the CPU frequency for the policy it is attached to by writing to the
401-
``scaling_setspeed`` attribute of that policy.
401+
``scaling_setspeed`` attribute of that policy. Though the intention may be to
402+
set an exact frequency for the policy, the actual frequency may vary depending
403+
on hardware coordination, thermal and power limits, and other factors.
402404

403405
``schedutil``
404406
-------------

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@
2626

2727
#include <acpi/cppc_acpi.h>
2828

29-
/*
30-
* This list contains information parsed from per CPU ACPI _CPC and _PSD
31-
* structures: e.g. the highest and lowest supported performance, capabilities,
32-
* desired performance, level requested etc. Depending on the share_type, not
33-
* all CPUs will have an entry in the list.
34-
*/
35-
static LIST_HEAD(cpu_data_list);
36-
3729
static struct cpufreq_driver cppc_cpufreq_driver;
3830

3931
#ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE
@@ -352,7 +344,6 @@ static unsigned int cppc_cpufreq_get_transition_delay_us(unsigned int cpu)
352344
#if defined(CONFIG_ARM64) && defined(CONFIG_ENERGY_MODEL)
353345

354346
static DEFINE_PER_CPU(unsigned int, efficiency_class);
355-
static void cppc_cpufreq_register_em(struct cpufreq_policy *policy);
356347

357348
/* Create an artificial performance state every CPPC_EM_CAP_STEP capacity unit. */
358349
#define CPPC_EM_CAP_STEP (20)
@@ -488,7 +479,19 @@ static int cppc_get_cpu_cost(struct device *cpu_dev, unsigned long KHz,
488479
return 0;
489480
}
490481

491-
static int populate_efficiency_class(void)
482+
static void cppc_cpufreq_register_em(struct cpufreq_policy *policy)
483+
{
484+
struct cppc_cpudata *cpu_data;
485+
struct em_data_callback em_cb =
486+
EM_ADV_DATA_CB(cppc_get_cpu_power, cppc_get_cpu_cost);
487+
488+
cpu_data = policy->driver_data;
489+
em_dev_register_perf_domain(get_cpu_device(policy->cpu),
490+
get_perf_level_count(policy), &em_cb,
491+
cpu_data->shared_cpu_map, 0);
492+
}
493+
494+
static void populate_efficiency_class(void)
492495
{
493496
struct acpi_madt_generic_interrupt *gicc;
494497
DECLARE_BITMAP(used_classes, 256) = {};
@@ -503,7 +506,7 @@ static int populate_efficiency_class(void)
503506
if (bitmap_weight(used_classes, 256) <= 1) {
504507
pr_debug("Efficiency classes are all equal (=%d). "
505508
"No EM registered", class);
506-
return -EINVAL;
509+
return;
507510
}
508511

509512
/*
@@ -520,26 +523,11 @@ static int populate_efficiency_class(void)
520523
index++;
521524
}
522525
cppc_cpufreq_driver.register_em = cppc_cpufreq_register_em;
523-
524-
return 0;
525-
}
526-
527-
static void cppc_cpufreq_register_em(struct cpufreq_policy *policy)
528-
{
529-
struct cppc_cpudata *cpu_data;
530-
struct em_data_callback em_cb =
531-
EM_ADV_DATA_CB(cppc_get_cpu_power, cppc_get_cpu_cost);
532-
533-
cpu_data = policy->driver_data;
534-
em_dev_register_perf_domain(get_cpu_device(policy->cpu),
535-
get_perf_level_count(policy), &em_cb,
536-
cpu_data->shared_cpu_map, 0);
537526
}
538527

539528
#else
540-
static int populate_efficiency_class(void)
529+
static void populate_efficiency_class(void)
541530
{
542-
return 0;
543531
}
544532
#endif
545533

@@ -567,8 +555,6 @@ static struct cppc_cpudata *cppc_cpufreq_get_cpu_data(unsigned int cpu)
567555
goto free_mask;
568556
}
569557

570-
list_add(&cpu_data->node, &cpu_data_list);
571-
572558
return cpu_data;
573559

574560
free_mask:
@@ -583,7 +569,6 @@ static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy)
583569
{
584570
struct cppc_cpudata *cpu_data = policy->driver_data;
585571

586-
list_del(&cpu_data->node);
587572
free_cpumask_var(cpu_data->shared_cpu_map);
588573
kfree(cpu_data);
589574
policy->driver_data = NULL;
@@ -954,24 +939,10 @@ static int __init cppc_cpufreq_init(void)
954939
return ret;
955940
}
956941

957-
static inline void free_cpu_data(void)
958-
{
959-
struct cppc_cpudata *iter, *tmp;
960-
961-
list_for_each_entry_safe(iter, tmp, &cpu_data_list, node) {
962-
free_cpumask_var(iter->shared_cpu_map);
963-
list_del(&iter->node);
964-
kfree(iter);
965-
}
966-
967-
}
968-
969942
static void __exit cppc_cpufreq_exit(void)
970943
{
971944
cpufreq_unregister_driver(&cppc_cpufreq_driver);
972945
cppc_freq_invariance_exit();
973-
974-
free_cpu_data();
975946
}
976947

977948
module_exit(cppc_cpufreq_exit);

drivers/cpufreq/cpufreq.c

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ static struct attribute *cpufreq_attrs[] = {
967967
&cpuinfo_min_freq.attr,
968968
&cpuinfo_max_freq.attr,
969969
&cpuinfo_transition_latency.attr,
970+
&scaling_cur_freq.attr,
970971
&scaling_min_freq.attr,
971972
&scaling_max_freq.attr,
972973
&affected_cpus.attr,
@@ -1095,10 +1096,6 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
10951096
return ret;
10961097
}
10971098

1098-
ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
1099-
if (ret)
1100-
return ret;
1101-
11021099
if (cpufreq_driver->bios_limit) {
11031100
ret = sysfs_create_file(&policy->kobj, &bios_limit.attr);
11041101
if (ret)
@@ -1284,6 +1281,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
12841281
goto err_free_real_cpus;
12851282
}
12861283

1284+
init_rwsem(&policy->rwsem);
1285+
12871286
freq_constraints_init(&policy->constraints);
12881287

12891288
policy->nb_min.notifier_call = cpufreq_notifier_min;
@@ -1306,7 +1305,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
13061305
}
13071306

13081307
INIT_LIST_HEAD(&policy->policy_list);
1309-
init_rwsem(&policy->rwsem);
13101308
spin_lock_init(&policy->transition_lock);
13111309
init_waitqueue_head(&policy->transition_wait);
13121310
INIT_WORK(&policy->update, handle_update);
@@ -1694,14 +1692,13 @@ static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy)
16941692
return;
16951693
}
16961694

1697-
if (has_target())
1695+
if (has_target()) {
16981696
strscpy(policy->last_governor, policy->governor->name,
16991697
CPUFREQ_NAME_LEN);
1700-
else
1701-
policy->last_policy = policy->policy;
1702-
1703-
if (has_target())
17041698
cpufreq_exit_governor(policy);
1699+
} else {
1700+
policy->last_policy = policy->policy;
1701+
}
17051702

17061703
/*
17071704
* Perform the ->offline() during light-weight tear-down, as
@@ -1803,6 +1800,9 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b
18031800
{
18041801
unsigned int new_freq;
18051802

1803+
if (!cpufreq_driver->get)
1804+
return 0;
1805+
18061806
new_freq = cpufreq_driver->get(policy->cpu);
18071807
if (!new_freq)
18081808
return 0;
@@ -1925,10 +1925,7 @@ unsigned int cpufreq_get(unsigned int cpu)
19251925

19261926
guard(cpufreq_policy_read)(policy);
19271927

1928-
if (cpufreq_driver->get)
1929-
return __cpufreq_get(policy);
1930-
1931-
return 0;
1928+
return __cpufreq_get(policy);
19321929
}
19331930
EXPORT_SYMBOL(cpufreq_get);
19341931

@@ -2482,8 +2479,7 @@ int cpufreq_start_governor(struct cpufreq_policy *policy)
24822479

24832480
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
24842481

2485-
if (cpufreq_driver->get)
2486-
cpufreq_verify_current_freq(policy, false);
2482+
cpufreq_verify_current_freq(policy, false);
24872483

24882484
if (policy->governor->start) {
24892485
ret = policy->governor->start(policy);
@@ -2715,10 +2711,12 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
27152711
pr_debug("starting governor %s failed\n", policy->governor->name);
27162712
if (old_gov) {
27172713
policy->governor = old_gov;
2718-
if (cpufreq_init_governor(policy))
2714+
if (cpufreq_init_governor(policy)) {
2715+
policy->governor = NULL;
2716+
} else if (cpufreq_start_governor(policy)) {
2717+
cpufreq_exit_governor(policy);
27192718
policy->governor = NULL;
2720-
else
2721-
cpufreq_start_governor(policy);
2719+
}
27222720
}
27232721

27242722
return ret;
@@ -2944,15 +2942,6 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
29442942
cpufreq_driver = driver_data;
29452943
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
29462944

2947-
/*
2948-
* Mark support for the scheduler's frequency invariance engine for
2949-
* drivers that implement target(), target_index() or fast_switch().
2950-
*/
2951-
if (!cpufreq_driver->setpolicy) {
2952-
static_branch_enable_cpuslocked(&cpufreq_freq_invariance);
2953-
pr_debug("supports frequency invariance");
2954-
}
2955-
29562945
if (driver_data->setpolicy)
29572946
driver_data->flags |= CPUFREQ_CONST_LOOPS;
29582947

@@ -2983,6 +2972,15 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
29832972
hp_online = ret;
29842973
ret = 0;
29852974

2975+
/*
2976+
* Mark support for the scheduler's frequency invariance engine for
2977+
* drivers that implement target(), target_index() or fast_switch().
2978+
*/
2979+
if (!cpufreq_driver->setpolicy) {
2980+
static_branch_enable_cpuslocked(&cpufreq_freq_invariance);
2981+
pr_debug("supports frequency invariance");
2982+
}
2983+
29862984
pr_debug("driver %s up and running\n", driver_data->name);
29872985
goto out;
29882986

drivers/cpufreq/cpufreq_userspace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ static struct cpufreq_governor cpufreq_gov_userspace = {
134134
.store_setspeed = cpufreq_set,
135135
.show_setspeed = show_speed,
136136
.owner = THIS_MODULE,
137+
.flags = CPUFREQ_GOV_STRICT_TARGET,
137138
};
138139

139140
MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>, "

drivers/cpufreq/intel_pstate.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,6 +2775,8 @@ static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
27752775
X86_MATCH(INTEL_TIGERLAKE, core_funcs),
27762776
X86_MATCH(INTEL_SAPPHIRERAPIDS_X, core_funcs),
27772777
X86_MATCH(INTEL_EMERALDRAPIDS_X, core_funcs),
2778+
X86_MATCH(INTEL_GRANITERAPIDS_D, core_funcs),
2779+
X86_MATCH(INTEL_GRANITERAPIDS_X, core_funcs),
27782780
{}
27792781
};
27802782
MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids);
@@ -3249,8 +3251,8 @@ static int intel_cpufreq_update_pstate(struct cpufreq_policy *policy,
32493251
int max_pstate = policy->strict_target ?
32503252
target_pstate : cpu->max_perf_ratio;
32513253

3252-
intel_cpufreq_hwp_update(cpu, target_pstate, max_pstate, 0,
3253-
fast_switch);
3254+
intel_cpufreq_hwp_update(cpu, target_pstate, max_pstate,
3255+
target_pstate, fast_switch);
32543256
} else if (target_pstate != old_pstate) {
32553257
intel_cpufreq_perf_ctl_update(cpu, target_pstate, fast_switch);
32563258
}

include/acpi/cppc_acpi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ struct cppc_perf_fb_ctrs {
139139

140140
/* Per CPU container for runtime CPPC management. */
141141
struct cppc_cpudata {
142-
struct list_head node;
143142
struct cppc_perf_caps perf_caps;
144143
struct cppc_perf_ctrls perf_ctrls;
145144
struct cppc_perf_fb_ctrs perf_fb_ctrs;

0 commit comments

Comments
 (0)