aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle/cpuidle.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/cpuidle/cpuidle.c')
-rw-r--r--drivers/cpuidle/cpuidle.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 2a98d99cbd46..2c4b2d47973e 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -15,6 +15,7 @@
15#include <linux/pm_qos_params.h> 15#include <linux/pm_qos_params.h>
16#include <linux/cpu.h> 16#include <linux/cpu.h>
17#include <linux/cpuidle.h> 17#include <linux/cpuidle.h>
18#include <linux/ktime.h>
18 19
19#include "cpuidle.h" 20#include "cpuidle.h"
20 21
@@ -180,6 +181,44 @@ void cpuidle_disable_device(struct cpuidle_device *dev)
180 181
181EXPORT_SYMBOL_GPL(cpuidle_disable_device); 182EXPORT_SYMBOL_GPL(cpuidle_disable_device);
182 183
184#ifdef CONFIG_ARCH_HAS_CPU_RELAX
185static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st)
186{
187 ktime_t t1, t2;
188 s64 diff;
189 int ret;
190
191 t1 = ktime_get();
192 local_irq_enable();
193 while (!need_resched())
194 cpu_relax();
195
196 t2 = ktime_get();
197 diff = ktime_to_us(ktime_sub(t2, t1));
198 if (diff > INT_MAX)
199 diff = INT_MAX;
200
201 ret = (int) diff;
202 return ret;
203}
204
205static void poll_idle_init(struct cpuidle_device *dev)
206{
207 struct cpuidle_state *state = &dev->states[0];
208
209 cpuidle_set_statedata(state, NULL);
210
211 snprintf(state->name, CPUIDLE_NAME_LEN, "C0 (poll idle)");
212 state->exit_latency = 0;
213 state->target_residency = 0;
214 state->power_usage = -1;
215 state->flags = CPUIDLE_FLAG_POLL | CPUIDLE_FLAG_TIME_VALID;
216 state->enter = poll_idle;
217}
218#else
219static void poll_idle_init(struct cpuidle_device *dev) {}
220#endif /* CONFIG_ARCH_HAS_CPU_RELAX */
221
183/** 222/**
184 * cpuidle_register_device - registers a CPU's idle PM feature 223 * cpuidle_register_device - registers a CPU's idle PM feature
185 * @dev: the cpu 224 * @dev: the cpu
@@ -198,6 +237,8 @@ int cpuidle_register_device(struct cpuidle_device *dev)
198 237
199 mutex_lock(&cpuidle_lock); 238 mutex_lock(&cpuidle_lock);
200 239
240 poll_idle_init(dev);
241
201 per_cpu(cpuidle_devices, dev->cpu) = dev; 242 per_cpu(cpuidle_devices, dev->cpu) = dev;
202 list_add(&dev->device_list, &cpuidle_detected_devices); 243 list_add(&dev->device_list, &cpuidle_detected_devices);
203 if ((ret = cpuidle_add_sysfs(sys_dev))) { 244 if ((ret = cpuidle_add_sysfs(sys_dev))) {