Merge tag 'gvt-fixes-2018-09-04' of https://github.com/intel/gvt-linux into drm-intel...
[linux-2.6-microblaze.git] / drivers / cpuidle / poll_state.c
1 /*
2  * poll_state.c - Polling idle state
3  *
4  * This file is released under the GPLv2.
5  */
6
7 #include <linux/cpuidle.h>
8 #include <linux/sched.h>
9 #include <linux/sched/clock.h>
10 #include <linux/sched/idle.h>
11
12 #define POLL_IDLE_TIME_LIMIT    (TICK_NSEC / 16)
13 #define POLL_IDLE_RELAX_COUNT   200
14
15 static int __cpuidle poll_idle(struct cpuidle_device *dev,
16                                struct cpuidle_driver *drv, int index)
17 {
18         u64 time_start = local_clock();
19
20         local_irq_enable();
21         if (!current_set_polling_and_test()) {
22                 unsigned int loop_count = 0;
23
24                 while (!need_resched()) {
25                         cpu_relax();
26                         if (loop_count++ < POLL_IDLE_RELAX_COUNT)
27                                 continue;
28
29                         loop_count = 0;
30                         if (local_clock() - time_start > POLL_IDLE_TIME_LIMIT)
31                                 break;
32                 }
33         }
34         current_clr_polling();
35
36         return index;
37 }
38
39 void cpuidle_poll_state_init(struct cpuidle_driver *drv)
40 {
41         struct cpuidle_state *state = &drv->states[0];
42
43         snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
44         snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
45         state->exit_latency = 0;
46         state->target_residency = 0;
47         state->power_usage = -1;
48         state->enter = poll_idle;
49         state->disabled = false;
50         state->flags = CPUIDLE_FLAG_POLLING;
51 }
52 EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);