policy = cpufreq_cpu_get_raw(cpu); if (unlikely(!policy)) return 0;
data = policy->driver_data; if (unlikely(!data || !policy->freq_table)) return 0;
cached_freq = policy->freq_table[to_perf_data(data)->state].frequency;
freq = extract_freq(policy, get_cur_val(cpumask_of(cpu), data)); if (freq != cached_freq) { /* * The dreaded BIOS frequency change behind our back. * Force set the frequency on next target call.
*/
data->resume = 1;
}
for (i = 0; i < 100; i++) {
cur_freq = extract_freq(policy, get_cur_val(mask, data)); if (cur_freq == freq) return 1;
udelay(10);
} return 0;
}
staticint acpi_cpufreq_target(struct cpufreq_policy *policy, unsignedint index)
{ struct acpi_cpufreq_data *data = policy->driver_data; struct acpi_processor_performance *perf; conststruct cpumask *mask; unsignedint next_perf_state = 0; /* Index into perf table */ int result = 0;
if (unlikely(!data)) { return -ENODEV;
}
perf = to_perf_data(data);
next_perf_state = policy->freq_table[index].driver_data; if (perf->state == next_perf_state) { if (unlikely(data->resume)) {
pr_debug("Called after resume, resetting to P%d\n",
next_perf_state);
data->resume = 0;
} else {
pr_debug("Already at target state (P%d)\n",
next_perf_state); return 0;
}
}
/* * The core won't allow CPUs to go away until the governor has been * stopped, so we can rely on the stability of policy->cpus.
*/
mask = policy->shared_type == CPUFREQ_SHARED_TYPE_ANY ?
cpumask_of(policy->cpu) : policy->cpus;
/* * Find the closest frequency above target_freq.
*/ if (policy->cached_target_freq == target_freq)
index = policy->cached_resolved_idx; else
index = cpufreq_table_find_index_dl(policy, target_freq, false);
/* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */
for_each_possible_cpu(i)
free_cpumask_var(per_cpu_ptr(acpi_perf_data, i)
->shared_cpu_map);
free_percpu(acpi_perf_data);
}
staticint cpufreq_boost_down_prep(unsignedint cpu)
{ /* * Clear the boost-disable bit on the CPU_DOWN path so that * this cpu cannot block the remaining ones from boosting.
*/ return boost_set_msr(1);
}
/* * acpi_cpufreq_early_init - initialize ACPI P-States library * * Initialize the ACPI P-States library (drivers/acpi/processor_perflib.c) * in order to determine correct frequency and voltage pairings. We can * do _PDC and _PSD and find out the processor dependency for the * actual init that will happen later...
*/ staticint __init acpi_cpufreq_early_init(void)
{ unsignedint i;
pr_debug("%s\n", __func__);
acpi_perf_data = alloc_percpu(struct acpi_processor_performance); if (!acpi_perf_data) {
pr_debug("Memory allocation error for acpi_perf_data.\n"); return -ENOMEM;
}
for_each_possible_cpu(i) { if (!zalloc_cpumask_var_node(
&per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map,
GFP_KERNEL, cpu_to_node(i))) {
/* Freeing a NULL pointer is OK: alloc_percpu zeroes. */
free_acpi_perf_data(); return -ENOMEM;
}
}
/* Do initialization in ACPI core */
acpi_processor_preregister_performance(acpi_perf_data); return 0;
}
#ifdef CONFIG_SMP /* * Some BIOSes do SW_ANY coordination internally, either set it up in hw * or do it in BIOS firmware and won't inform about it to OS. If not * detected, this has a side effect of making CPU run at a different speed * than OS intended it to run at. Detect it and handle it cleanly.
*/ staticint bios_with_sw_any_bug;
staticint acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
{ /* Intel Xeon Processor 7100 Series Specification Update * https://www.intel.com/Assets/PDF/specupdate/314554.pdf * AL30: A Machine Check Exception (MCE) Occurring during an * Enhanced Intel SpeedStep Technology Ratio Change May Cause
* Both Processor Cores to Lock Up. */ if (c->x86_vendor == X86_VENDOR_INTEL) { if ((c->x86 == 15) &&
(c->x86_model == 6) &&
(c->x86_stepping == 8)) {
pr_info("Intel(R) Xeon(R) 7100 Errata AL30, processors may lock up on frequency changes: disabling acpi-cpufreq\n"); return -ENODEV;
}
} return 0;
} #endif
#ifdef CONFIG_ACPI_CPPC_LIB /* * get_max_boost_ratio: Computes the max_boost_ratio as the ratio * between the highest_perf and the nominal_perf. * * Returns the max_boost_ratio for @cpu. Returns the CPPC nominal * frequency via @nominal_freq if it is non-NULL pointer.
*/ static u64 get_max_boost_ratio(unsignedint cpu, u64 *nominal_freq)
{ struct cppc_perf_caps perf_caps;
u64 highest_perf, nominal_perf; int ret;
if (acpi_pstate_strict) return 0;
ret = cppc_get_perf_caps(cpu, &perf_caps); if (ret) {
pr_debug("CPU%d: Unable to get performance capabilities (%d)\n",
cpu, ret); return 0;
}
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
ret = amd_get_boost_ratio_numerator(cpu, &highest_perf); if (ret) {
pr_debug("CPU%d: Unable to get boost ratio numerator (%d)\n",
cpu, ret); return 0;
}
} else {
highest_perf = perf_caps.highest_perf;
}
nominal_perf = perf_caps.nominal_perf;
if (nominal_freq)
*nominal_freq = perf_caps.nominal_freq * 1000;
if (!highest_perf || !nominal_perf) {
pr_debug("CPU%d: highest or nominal performance missing\n", cpu); return 0;
}
if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
result = acpi_processor_register_performance(perf, cpu); if (result) goto err_free_mask;
policy->shared_type = perf->shared_type;
/* * Will let policy->cpus know about dependency only when software * coordination is required.
*/ if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
cpumask_copy(policy->cpus, perf->shared_cpu_map);
}
cpumask_copy(data->freqdomain_cpus, perf->shared_cpu_map);
/* capability check */ if (perf->state_count <= 1) {
pr_debug("No P-States\n");
result = -ENODEV; goto err_unreg;
}
if (perf->control_register.space_id != perf->status_register.space_id) {
result = -ENODEV; goto err_unreg;
}
switch (perf->control_register.space_id) { case ACPI_ADR_SPACE_SYSTEM_IO: if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
boot_cpu_data.x86 == 0xf) {
pr_debug("AMD K8 systems must use native drivers.\n");
result = -ENODEV; goto err_unreg;
}
pr_debug("SYSTEM IO addr space\n");
data->cpu_feature = SYSTEM_IO_CAPABLE;
data->cpu_freq_read = cpu_freq_read_io;
data->cpu_freq_write = cpu_freq_write_io; break; case ACPI_ADR_SPACE_FIXED_HARDWARE:
pr_debug("HARDWARE addr space\n"); if (check_est_cpu(cpu)) {
data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE;
data->cpu_freq_read = cpu_freq_read_intel;
data->cpu_freq_write = cpu_freq_write_intel; break;
} if (check_amd_hwpstate_cpu(cpu)) {
data->cpu_feature = SYSTEM_AMD_MSR_CAPABLE;
data->cpu_freq_read = cpu_freq_read_amd;
data->cpu_freq_write = cpu_freq_write_amd; break;
}
result = -ENODEV; goto err_unreg; default:
pr_debug("Unknown addr space %d\n",
(u32) (perf->control_register.space_id));
result = -ENODEV; goto err_unreg;
}
freq_table = kcalloc(perf->state_count + 1, sizeof(*freq_table),
GFP_KERNEL); if (!freq_table) {
result = -ENOMEM; goto err_unreg;
}
/* detect transition latency */
policy->cpuinfo.transition_latency = 0; for (i = 0; i < perf->state_count; i++) { if ((perf->states[i].transition_latency * 1000) >
policy->cpuinfo.transition_latency)
policy->cpuinfo.transition_latency =
perf->states[i].transition_latency * 1000;
}
/* Check for high latency (>20uS) from buggy BIOSes, like on T42 */ if (perf->control_register.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE &&
policy->cpuinfo.transition_latency > 20 * 1000) {
policy->cpuinfo.transition_latency = 20 * 1000;
pr_info_once("P-state transition latency capped at 20 uS\n");
}
/* table init */ for (i = 0; i < perf->state_count; i++) { if (i > 0 && perf->states[i].core_frequency >=
freq_table[valid_states-1].frequency / 1000) continue;
/* * The loop above sorts the freq_table entries in the * descending order. If ACPI CPPC has not advertised * the nominal frequency (this is possible in CPPC * revisions prior to 3), then use the first entry in * the pstate table as a proxy for nominal frequency.
*/ if (!freq)
freq = freq_table[0].frequency;
policy->cpuinfo.max_freq = freq * max_boost_ratio >> SCHED_CAPACITY_SHIFT;
} else { /* * If the maximum "boost" frequency is unknown, ask the arch * scale-invariance code to use the "nominal" performance for * CPU utilization scaling so as to prevent the schedutil * governor from selecting inadequate CPU frequencies.
*/
arch_set_max_freq_ratio(true);
}
policy->freq_table = freq_table;
perf->state = 0;
switch (perf->control_register.space_id) { case ACPI_ADR_SPACE_SYSTEM_IO: /* * The core will not set policy->cur, because * cpufreq_driver->get is NULL, so we need to set it here. * However, we have to guess it, because the current speed is * unknown and not detectable via IO ports.
*/
policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu); break; case ACPI_ADR_SPACE_FIXED_HARDWARE:
acpi_cpufreq_driver.get = get_cur_freq_on_cpu; break; default: break;
}
/* notify BIOS that we exist */
acpi_processor_notify_smm(THIS_MODULE);
pr_debug("CPU%u - ACPI performance management activated.\n", cpu); for (i = 0; i < perf->state_count; i++)
pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n",
(i == perf->state ? '*' : ' '), i,
(u32) perf->states[i].core_frequency,
(u32) perf->states[i].power,
(u32) perf->states[i].transition_latency);
/* * the first call to ->target() should result in us actually * writing something to the appropriate registers.
*/
data->resume = 1;
if (perf->states[0].core_frequency * 1000 != freq_table[0].frequency)
pr_warn(FW_WARN "P-state 0 is not max freq\n");
if (acpi_cpufreq_driver.set_boost) { if (policy->boost_supported) { /* * The firmware may have altered boost state while the * CPU was offline (for example during a suspend-resume * cycle).
*/ if (policy->boost_enabled != boost_state(cpu))
set_boost(policy, policy->boost_enabled);
} else {
policy->boost_supported = true;
}
}
staticvoid __init acpi_cpufreq_boost_init(void)
{ if (!(boot_cpu_has(X86_FEATURE_CPB) || boot_cpu_has(X86_FEATURE_IDA))) {
pr_debug("Boost capabilities not present in the processor\n"); return;
}
staticint __init acpi_cpufreq_probe(struct platform_device *pdev)
{ int ret;
if (acpi_disabled) return -ENODEV;
/* don't keep reloading if cpufreq_driver exists */ if (cpufreq_get_current_driver()) return -ENODEV;
pr_debug("%s\n", __func__);
ret = acpi_cpufreq_early_init(); if (ret) return ret;
#ifdef CONFIG_X86_ACPI_CPUFREQ_CPB /* this is a sysfs file with a strange name and an even stranger * semantic - per CPU instantiation, but system global effect. * Lets enable it only on AMD CPUs for compatibility reasons and * only if configured. This is considered legacy code, which * will probably be removed at some point in the future.
*/ if (!check_amd_hwpstate_cpu(0)) { struct freq_attr **attr;
pr_debug("CPB unsupported, do not expose it\n");
for (attr = acpi_cpufreq_attr; *attr; attr++) if (*attr == &cpb) {
*attr = NULL; break;
}
} #endif
acpi_cpufreq_boost_init();
ret = cpufreq_register_driver(&acpi_cpufreq_driver); if (ret) {
free_acpi_perf_data();
} return ret;
}
module_param(acpi_pstate_strict, uint, 0644);
MODULE_PARM_DESC(acpi_pstate_strict, "value 0 or non-zero. non-zero -> strict ACPI checks are " "performed during frequency changes.");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.