From patchwork Mon Aug 29 18:28:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 1110022 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7TIV6f5013033 for ; Mon, 29 Aug 2011 18:40:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754730Ab1H2S3A (ORCPT ); Mon, 29 Aug 2011 14:29:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64902 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754386Ab1H2S3A (ORCPT ); Mon, 29 Aug 2011 14:29:00 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7TISbCk017194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 29 Aug 2011 14:28:37 -0400 Received: from cavan.codon.org.uk (ovpn-113-30.phx2.redhat.com [10.3.113.30]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p7TISZb6001290 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Mon, 29 Aug 2011 14:28:37 -0400 Received: from [2001:470:1f07:1371:a288:b4ff:fe2c:e1a8] (helo=localhost.localdomain) by cavan.codon.org.uk with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1Qy6ZU-0002JX-Ok; Mon, 29 Aug 2011 19:28:33 +0100 From: Matthew Garrett To: linux-acpi@vger.kernel.org Cc: lenb@kernel.org, rui.zhang@intel.com, jboyer@redhat.com, Matthew Garrett Subject: [PATCH] ACPI: Ensure thermal limits match CPU frequencies Date: Mon, 29 Aug 2011 14:28:27 -0400 Message-Id: <1314642507-32491-1-git-send-email-mjg@redhat.com> X-SA-Do-Not-Run: Yes X-SA-Exim-Connect-IP: 2001:470:1f07:1371:a288:b4ff:fe2c:e1a8 X-SA-Exim-Mail-From: mjg@redhat.com X-SA-Exim-Scanned: No (on cavan.codon.org.uk); SAEximRunCond expanded to false X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 29 Aug 2011 18:40:26 +0000 (UTC) The ACPI thermal management code supports slowing down a CPU when it's overheating. Right now that's done by choosing to run it at 100%, 75%, 50% or 25% of full speed. However, most CPUs do not allow an arbitrary frequency to be set and so will run at the first frequency below that value. This doesn't match the intent of the specification, which is to drop the frequency state by state until the temperature stabalises. Fix this up so it uses actual frequencies rather than percentages. Reported by: Gene Snider Signed-off-by: Matthew Garrett --- drivers/acpi/processor_thermal.c | 45 +++++++++++++++++++++---------------- 1 files changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c index 870550d..1c4eb60 100644 --- a/drivers/acpi/processor_thermal.c +++ b/drivers/acpi/processor_thermal.c @@ -52,10 +52,8 @@ ACPI_MODULE_NAME("processor_thermal"); * _any_ cpufreq driver and not only the acpi-cpufreq driver. */ -#define CPUFREQ_THERMAL_MIN_STEP 0 -#define CPUFREQ_THERMAL_MAX_STEP 3 -static DEFINE_PER_CPU(unsigned int, cpufreq_thermal_reduction_pctg); +static DEFINE_PER_CPU(unsigned int, cpufreq_thermal_limit_state); static unsigned int acpi_thermal_cpufreq_is_init = 0; static int cpu_has_cpufreq(unsigned int cpu) @@ -70,19 +68,19 @@ static int acpi_thermal_cpufreq_notifier(struct notifier_block *nb, unsigned long event, void *data) { struct cpufreq_policy *policy = data; - unsigned long max_freq = 0; + int state = per_cpu(cpufreq_thermal_limit_state, policy->cpu); + struct cpufreq_frequency_table *table; if (event != CPUFREQ_ADJUST) - goto out; + return 0; + + table = cpufreq_frequency_get_table(policy->cpu); - max_freq = ( - policy->cpuinfo.max_freq * - (100 - per_cpu(cpufreq_thermal_reduction_pctg, policy->cpu) * 20) - ) / 100; + if (!table) + return 0; - cpufreq_verify_within_limits(policy, 0, max_freq); + cpufreq_verify_within_limits(policy, 0, table[state].frequency); - out: return 0; } @@ -92,10 +90,21 @@ static struct notifier_block acpi_thermal_cpufreq_notifier_block = { static int cpufreq_get_max_state(unsigned int cpu) { + int count = 0; + struct cpufreq_frequency_table *table; + if (!cpu_has_cpufreq(cpu)) return 0; - return CPUFREQ_THERMAL_MAX_STEP; + table = cpufreq_frequency_get_table(cpu); + + if (!table) + return 0; + + while (table[count].frequency != CPUFREQ_TABLE_END) + count++; + + return count; } static int cpufreq_get_cur_state(unsigned int cpu) @@ -103,7 +112,7 @@ static int cpufreq_get_cur_state(unsigned int cpu) if (!cpu_has_cpufreq(cpu)) return 0; - return per_cpu(cpufreq_thermal_reduction_pctg, cpu); + return per_cpu(cpufreq_thermal_limit_state, cpu); } static int cpufreq_set_cur_state(unsigned int cpu, int state) @@ -111,7 +120,7 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state) if (!cpu_has_cpufreq(cpu)) return 0; - per_cpu(cpufreq_thermal_reduction_pctg, cpu) = state; + per_cpu(cpufreq_thermal_limit_state, cpu) = state; cpufreq_update_policy(cpu); return 0; } @@ -122,7 +131,7 @@ void acpi_thermal_cpufreq_init(void) for (i = 0; i < nr_cpu_ids; i++) if (cpu_present(i)) - per_cpu(cpufreq_thermal_reduction_pctg, i) = 0; + per_cpu(cpufreq_thermal_limit_state, i) = 0; i = cpufreq_register_notifier(&acpi_thermal_cpufreq_notifier_block, CPUFREQ_POLICY_NOTIFIER); @@ -170,15 +179,11 @@ int acpi_processor_get_limit_info(struct acpi_processor *pr) return 0; } -/* thermal coolign device callbacks */ +/* thermal cooling device callbacks */ static int acpi_processor_max_state(struct acpi_processor *pr) { int max_state = 0; - /* - * There exists four states according to - * cpufreq_thermal_reduction_ptg. 0, 1, 2, 3 - */ max_state += cpufreq_get_max_state(pr->id); if (pr->flags.throttling) max_state += (pr->throttling.state_count -1);