From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org
Cc: hpa@zytor.com, trenn@suse.de, kay.sievers@vrf.org,
Andi Kleen <ak@linux.intel.com>,
lenb@kernel.org
Subject: [PATCH 3/8] intel-idle: convert to x86_cpu_id auto probing
Date: Mon, 19 Dec 2011 15:46:29 -0800 [thread overview]
Message-ID: <1324338394-4670-4-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1324338394-4670-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
With this it should be automatically loaded on suitable systems by
udev.
The old switch () is replaced with a table based approach, this
also cleans up the code.
Cc: lenb@kernel.org
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
drivers/idle/intel_idle.c | 116 +++++++++++++++++++++++++-------------------
1 files changed, 66 insertions(+), 50 deletions(-)
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 5d2f8e1..0920cc5 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -62,6 +62,7 @@
#include <linux/notifier.h>
#include <linux/cpu.h>
#include <linux/module.h>
+#include <asm/cpu_device_id.h>
#include <asm/mwait.h>
#include <asm/msr.h>
@@ -81,6 +82,17 @@ static unsigned int mwait_substates;
/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
+struct idle_cpu {
+ struct cpuidle_state *state_table;
+
+ /*
+ * Hardware C-state auto-demotion may not always be optimal.
+ * Indicate which enable bits to clear here.
+ */
+ unsigned long auto_demotion_disable_flags;
+};
+
+static const struct idle_cpu *icpu;
static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
static int intel_idle(struct cpuidle_device *dev,
struct cpuidle_driver *drv, int index);
@@ -88,12 +100,6 @@ static int intel_idle(struct cpuidle_device *dev,
static struct cpuidle_state *cpuidle_state_table;
/*
- * Hardware C-state auto-demotion may not always be optimal.
- * Indicate which enable bits to clear here.
- */
-static unsigned long long auto_demotion_disable_flags;
-
-/*
* Set this flag for states where the HW flushes the TLB for us
* and so we don't need cross-calls to keep it consistent.
* If this flag is set, SW flushes the TLB, so even if the
@@ -320,27 +326,72 @@ static void auto_demotion_disable(void *dummy)
unsigned long long msr_bits;
rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
- msr_bits &= ~auto_demotion_disable_flags;
+ msr_bits &= ~(icpu->auto_demotion_disable_flags);
wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
}
+static const struct idle_cpu idle_cpu_nehalem = {
+ .state_table = nehalem_cstates,
+};
+
+static const struct idle_cpu idle_cpu_westmere = {
+ .state_table = nehalem_cstates,
+ .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
+};
+
+static const struct idle_cpu idle_cpu_atom = {
+ .state_table = atom_cstates,
+};
+
+static const struct idle_cpu idle_cpu_lincroft = {
+ .state_table = atom_cstates,
+ .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
+};
+
+static const struct idle_cpu idle_cpu_snb = {
+ .state_table = snb_cstates,
+};
+
+#define ICPU(model, cpu) \
+ { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
+
+static const struct x86_cpu_id intel_idle_ids[] = {
+ ICPU(0x1a, idle_cpu_nehalem),
+ ICPU(0x1e, idle_cpu_nehalem),
+ ICPU(0x1f, idle_cpu_nehalem),
+ ICPU(0x25, idle_cpu_westmere),
+ ICPU(0x2c, idle_cpu_westmere),
+ ICPU(0x2f, idle_cpu_westmere),
+ ICPU(0x1c, idle_cpu_atom),
+ ICPU(0x26, idle_cpu_lincroft),
+ ICPU(0x2f, idle_cpu_westmere),
+ ICPU(0x2a, idle_cpu_snb),
+ ICPU(0x2d, idle_cpu_snb),
+ {}
+};
+MODULE_DEVICE_TABLE(x86cpu, intel_idle_ids);
+
/*
* intel_idle_probe()
*/
static int intel_idle_probe(void)
{
unsigned int eax, ebx, ecx;
+ const struct x86_cpu_id *id;
if (max_cstate == 0) {
pr_debug(PREFIX "disabled\n");
return -EPERM;
}
- if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
- return -ENODEV;
-
- if (!boot_cpu_has(X86_FEATURE_MWAIT))
+ id = x86_match_cpu(intel_idle_ids);
+ if (!id) {
+ if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
+ boot_cpu_data.x86 == 6)
+ pr_debug(PREFIX "does not run on family %d model %d\n",
+ boot_cpu_data.x86, boot_cpu_data.x86_model);
return -ENODEV;
+ }
if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
return -ENODEV;
@@ -353,44 +404,9 @@ static int intel_idle_probe(void)
pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
-
- if (boot_cpu_data.x86 != 6) /* family 6 */
- return -ENODEV;
-
- switch (boot_cpu_data.x86_model) {
-
- case 0x1A: /* Core i7, Xeon 5500 series */
- case 0x1E: /* Core i7 and i5 Processor - Lynnfield Jasper Forest */
- case 0x1F: /* Core i7 and i5 Processor - Nehalem */
- case 0x2E: /* Nehalem-EX Xeon */
- case 0x2F: /* Westmere-EX Xeon */
- case 0x25: /* Westmere */
- case 0x2C: /* Westmere */
- cpuidle_state_table = nehalem_cstates;
- auto_demotion_disable_flags =
- (NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE);
- break;
-
- case 0x1C: /* 28 - Atom Processor */
- cpuidle_state_table = atom_cstates;
- break;
-
- case 0x26: /* 38 - Lincroft Atom Processor */
- cpuidle_state_table = atom_cstates;
- auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE;
- break;
-
- case 0x2A: /* SNB */
- case 0x2D: /* SNB Xeon */
- cpuidle_state_table = snb_cstates;
- break;
-
- default:
- pr_debug(PREFIX "does not run on family %d model %d\n",
- boot_cpu_data.x86, boot_cpu_data.x86_model);
- return -ENODEV;
- }
-
+ icpu = (const struct idle_cpu *)id->driver_data;
+ cpuidle_state_table = icpu->state_table;
+
if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
else {
@@ -470,7 +486,7 @@ static int intel_idle_cpuidle_driver_init(void)
drv->state_count += 1;
}
- if (auto_demotion_disable_flags)
+ if (icpu->auto_demotion_disable_flags)
smp_call_function(auto_demotion_disable, NULL, 1);
return 0;
--
1.7.7.4
next prev parent reply other threads:[~2011-12-19 23:46 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-19 23:46 CPUID based driver autoloading v3 Andi Kleen
2011-12-19 23:46 ` [PATCH 1/8] Add driver auto probing for x86 features v2 Andi Kleen
2011-12-20 1:25 ` [tip:x86/autoprobe] x86: Add driver auto probing for x86 features tip-bot for Andi Kleen
2011-12-23 13:16 ` [PATCH 1/8] Add driver auto probing for x86 features v2 Thomas Renninger
2011-12-19 23:46 ` [PATCH 2/8] crypto: Add support for x86 cpuid auto loading for x86 crypto drivers Andi Kleen
2011-12-20 1:26 ` [tip:x86/autoprobe] x86, " tip-bot for Andi Kleen
2011-12-19 23:46 ` Andi Kleen [this message]
2011-12-20 1:27 ` [tip:x86/autoprobe] x86, intel-idle: convert to x86_cpu_id auto probing tip-bot for Andi Kleen
2011-12-19 23:46 ` [PATCH 4/8] ACPI: Load acpi-cpufreq from processor driver automatically Andi Kleen
2011-12-20 1:28 ` [tip:x86/autoprobe] x86, acpi: " tip-bot for Andi Kleen
2011-12-19 23:46 ` [PATCH 5/8] HWMON: Convert via-cputemp to x86 cpuid autoprobing Andi Kleen
2011-12-20 1:28 ` [tip:x86/autoprobe] x86, hwmon: " tip-bot for Andi Kleen
2011-12-19 23:46 ` [PATCH 6/8] HWMON: Convert coretemp " Andi Kleen
2011-12-20 1:29 ` [tip:x86/autoprobe] x86, hwmon: " tip-bot for Andi Kleen
2011-12-19 23:46 ` [PATCH 7/8] cpufreq: Add support for x86 cpuinfo auto loading v3 Andi Kleen
2011-12-20 1:30 ` [tip:x86/autoprobe] x86, cpufreq: Add support for x86 cpuinfo auto loading tip-bot for Andi Kleen
2011-12-20 10:12 ` Ingo Molnar
2011-12-20 18:18 ` Andi Kleen
2011-12-21 11:03 ` [PATCH 7/8] cpufreq: Add support for x86 cpuinfo auto loading v3 Thomas Renninger
2011-12-21 20:12 ` Andi Kleen
2011-12-21 20:14 ` H. Peter Anvin
2011-12-21 21:30 ` Dave Jones
2011-12-22 0:01 ` Andi Kleen
2011-12-22 0:08 ` H. Peter Anvin
2011-12-22 0:14 ` Andi Kleen
2011-12-22 15:29 ` Thomas Renninger
2011-12-22 20:49 ` Andi Kleen
2011-12-22 17:55 ` [PATCH] X86: Introduce HW-Pstate scattered cpuid feature Thomas Renninger
2011-12-19 23:46 ` [PATCH 8/8] x86: autoload microcode driver on Intel and AMD systems Andi Kleen
2011-12-20 1:31 ` [tip:x86/autoprobe] x86: Autoload " tip-bot for Andi Kleen
2011-12-21 15:02 ` [PATCH 9/8] CPU: Introduce ARCH_HAS_CPU_AUTOPROBE and X86 parts Thomas Renninger
2011-12-21 15:32 ` Kay Sievers
2011-12-21 23:29 ` Greg KH
2011-12-21 23:36 ` H. Peter Anvin
2011-12-21 23:46 ` Kay Sievers
2011-12-21 23:50 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1324338394-4670-4-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=ak@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kay.sievers@vrf.org \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=trenn@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).