cpuidle: don't call poll_idle_init() for every cpu
[firefly-linux-kernel-4.4.55.git] / drivers / cpuidle / driver.c
index 2458a741ad4566eebfa19bb22ceb667c4e7419c9..06dbe7c86199808aefdf3d9e6b447c0e0b697b1c 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <linux/mutex.h>
 #include <linux/module.h>
+#include <linux/sched.h>
 #include <linux/cpuidle.h>
 #include <linux/cpumask.h>
 #include <linux/clockchips.h>
@@ -177,6 +178,45 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv)
        }
 }
 
+#ifdef CONFIG_ARCH_HAS_CPU_RELAX
+static int poll_idle(struct cpuidle_device *dev,
+               struct cpuidle_driver *drv, int index)
+{
+       ktime_t t1, t2;
+       s64 diff;
+
+       t1 = ktime_get();
+       local_irq_enable();
+       while (!need_resched())
+               cpu_relax();
+
+       t2 = ktime_get();
+       diff = ktime_to_us(ktime_sub(t2, t1));
+       if (diff > INT_MAX)
+               diff = INT_MAX;
+
+       dev->last_residency = (int) diff;
+
+       return index;
+}
+
+static void poll_idle_init(struct cpuidle_driver *drv)
+{
+       struct cpuidle_state *state = &drv->states[0];
+
+       snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
+       snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
+       state->exit_latency = 0;
+       state->target_residency = 0;
+       state->power_usage = -1;
+       state->flags = 0;
+       state->enter = poll_idle;
+       state->disabled = false;
+}
+#else
+static void poll_idle_init(struct cpuidle_driver *drv) {}
+#endif /* !CONFIG_ARCH_HAS_CPU_RELAX */
+
 /**
  * __cpuidle_register_driver: register the driver
  * @drv: a valid pointer to a struct cpuidle_driver
@@ -210,6 +250,8 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv)
                on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
                                 (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
 
+       poll_idle_init(drv);
+
        return 0;
 }