mm: thp: set the accessed flag for old pages on access fault
[pandora-kernel.git] / drivers / idle / intel_idle.c
index 3aa8d4c..4fa2b11 100644 (file)
@@ -61,6 +61,7 @@
 #include <linux/sched.h>
 #include <linux/notifier.h>
 #include <linux/cpu.h>
+#include <linux/module.h>
 #include <asm/mwait.h>
 #include <asm/msr.h>
 
@@ -81,7 +82,8 @@ static unsigned int mwait_substates;
 static unsigned int lapic_timer_reliable_states = (1 << 1);     /* Default to only C1 */
 
 static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
-static int intel_idle(struct cpuidle_device *dev, int index);
+static int intel_idle(struct cpuidle_device *dev,
+                       struct cpuidle_driver *drv, int index);
 
 static struct cpuidle_state *cpuidle_state_table;
 
@@ -161,6 +163,38 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
                .enter = &intel_idle },
 };
 
+static struct cpuidle_state ivb_cstates[MWAIT_MAX_NUM_CSTATES] = {
+       { /* MWAIT C0 */ },
+       { /* MWAIT C1 */
+               .name = "C1-IVB",
+               .desc = "MWAIT 0x00",
+               .flags = CPUIDLE_FLAG_TIME_VALID,
+               .exit_latency = 1,
+               .target_residency = 1,
+               .enter = &intel_idle },
+       { /* MWAIT C2 */
+               .name = "C3-IVB",
+               .desc = "MWAIT 0x10",
+               .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
+               .exit_latency = 59,
+               .target_residency = 156,
+               .enter = &intel_idle },
+       { /* MWAIT C3 */
+               .name = "C6-IVB",
+               .desc = "MWAIT 0x20",
+               .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
+               .exit_latency = 80,
+               .target_residency = 300,
+               .enter = &intel_idle },
+       { /* MWAIT C4 */
+               .name = "C7-IVB",
+               .desc = "MWAIT 0x30",
+               .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
+               .exit_latency = 87,
+               .target_residency = 300,
+               .enter = &intel_idle },
+};
+
 static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
        { /* MWAIT C0 */ },
        { /* MWAIT C1 */
@@ -227,13 +261,15 @@ static int get_driver_data(int cstate)
 /**
  * intel_idle
  * @dev: cpuidle_device
+ * @drv: cpuidle driver
  * @index: index of cpuidle state
  *
  */
-static int intel_idle(struct cpuidle_device *dev, int index)
+static int intel_idle(struct cpuidle_device *dev,
+               struct cpuidle_driver *drv, int index)
 {
        unsigned long ecx = 1; /* break on interrupt flag */
-       struct cpuidle_state *state = &dev->states[index];
+       struct cpuidle_state *state = &drv->states[index];
        struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
        unsigned long eax = (unsigned long)cpuidle_get_statedata(state_usage);
        unsigned int cstate;
@@ -344,7 +380,8 @@ static int intel_idle_probe(void)
        cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
 
        if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
-               !(ecx & CPUID5_ECX_INTERRUPT_BREAK))
+           !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
+           !mwait_substates)
                        return -ENODEV;
 
        pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
@@ -381,6 +418,11 @@ static int intel_idle_probe(void)
                cpuidle_state_table = snb_cstates;
                break;
 
+       case 0x3A:      /* IVB */
+       case 0x3E:      /* IVB Xeon */
+               cpuidle_state_table = ivb_cstates;
+               break;
+
        default:
                pr_debug(PREFIX "does not run on family %d model %d\n",
                        boot_cpu_data.x86, boot_cpu_data.x86_model);
@@ -389,10 +431,8 @@ static int intel_idle_probe(void)
 
        if (boot_cpu_has(X86_FEATURE_ARAT))     /* Always Reliable APIC Timer */
                lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
-       else {
-               smp_call_function(__setup_broadcast_timer, (void *)true, 1);
-               register_cpu_notifier(&setup_broadcast_notifier);
-       }
+       else
+               on_each_cpu(__setup_broadcast_timer, (void *)true, 1);
 
        pr_debug(PREFIX "v" INTEL_IDLE_VERSION
                " model 0x%X\n", boot_cpu_data.x86_model);
@@ -419,6 +459,60 @@ static void intel_idle_cpuidle_devices_uninit(void)
        free_percpu(intel_idle_cpuidle_devices);
        return;
 }
+/*
+ * intel_idle_cpuidle_driver_init()
+ * allocate, initialize cpuidle_states
+ */
+static int intel_idle_cpuidle_driver_init(void)
+{
+       int cstate;
+       struct cpuidle_driver *drv = &intel_idle_driver;
+
+       drv->state_count = 1;
+
+       for (cstate = 1; cstate < MWAIT_MAX_NUM_CSTATES; ++cstate) {
+               int num_substates;
+
+               if (cstate > max_cstate) {
+                       printk(PREFIX "max_cstate %d reached\n",
+                               max_cstate);
+                       break;
+               }
+
+               /* does the state exist in CPUID.MWAIT? */
+               num_substates = (mwait_substates >> ((cstate) * 4))
+                                       & MWAIT_SUBSTATE_MASK;
+               if (num_substates == 0)
+                       continue;
+               /* is the state not enabled? */
+               if (cpuidle_state_table[cstate].enter == NULL) {
+                       /* does the driver not know about the state? */
+                       if (*cpuidle_state_table[cstate].name == '\0')
+                               pr_debug(PREFIX "unaware of model 0x%x"
+                                       " MWAIT %d please"
+                                       " contact lenb@kernel.org",
+                               boot_cpu_data.x86_model, cstate);
+                       continue;
+               }
+
+               if ((cstate > 2) &&
+                       !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
+                       mark_tsc_unstable("TSC halts in idle"
+                                       " states deeper than C2");
+
+               drv->states[drv->state_count] = /* structure copy */
+                       cpuidle_state_table[cstate];
+
+               drv->state_count += 1;
+       }
+
+       if (auto_demotion_disable_flags)
+               on_each_cpu(auto_demotion_disable, NULL, 1);
+
+       return 0;
+}
+
+
 /*
  * intel_idle_cpuidle_devices_init()
  * allocate, initialize, register cpuidle_devices
@@ -453,23 +547,9 @@ static int intel_idle_cpuidle_devices_init(void)
                                continue;
                        /* is the state not enabled? */
                        if (cpuidle_state_table[cstate].enter == NULL) {
-                               /* does the driver not know about the state? */
-                               if (*cpuidle_state_table[cstate].name == '\0')
-                                       pr_debug(PREFIX "unaware of model 0x%x"
-                                               " MWAIT %d please"
-                                               " contact lenb@kernel.org",
-                                       boot_cpu_data.x86_model, cstate);
                                continue;
                        }
 
-                       if ((cstate > 2) &&
-                               !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
-                               mark_tsc_unstable("TSC halts in idle"
-                                       " states deeper than C2");
-
-                       dev->states[dev->state_count] = /* structure copy */
-                               cpuidle_state_table[cstate];
-
                        dev->states_usage[dev->state_count].driver_data =
                                (void *)get_driver_data(cstate);
 
@@ -484,8 +564,6 @@ static int intel_idle_cpuidle_devices_init(void)
                        return -EIO;
                }
        }
-       if (auto_demotion_disable_flags)
-               smp_call_function(auto_demotion_disable, NULL, 1);
 
        return 0;
 }
@@ -503,6 +581,7 @@ static int __init intel_idle_init(void)
        if (retval)
                return retval;
 
+       intel_idle_cpuidle_driver_init();
        retval = cpuidle_register_driver(&intel_idle_driver);
        if (retval) {
                printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
@@ -516,6 +595,9 @@ static int __init intel_idle_init(void)
                return retval;
        }
 
+       if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
+               register_cpu_notifier(&setup_broadcast_notifier);
+
        return 0;
 }
 
@@ -525,7 +607,7 @@ static void __exit intel_idle_exit(void)
        cpuidle_unregister_driver(&intel_idle_driver);
 
        if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE) {
-               smp_call_function(__setup_broadcast_timer, (void *)false, 1);
+               on_each_cpu(__setup_broadcast_timer, (void *)false, 1);
                unregister_cpu_notifier(&setup_broadcast_notifier);
        }