2 * poll_state.c - Polling idle state
4 * This file is released under the GPLv2.
7 #include <linux/cpuidle.h>
8 #include <linux/sched.h>
9 #include <linux/sched/clock.h>
10 #include <linux/sched/idle.h>
12 #define POLL_IDLE_RELAX_COUNT 200
14 static int __cpuidle
poll_idle(struct cpuidle_device
*dev
,
15 struct cpuidle_driver
*drv
, int index
)
17 u64 time_start
= local_clock();
19 dev
->poll_time_limit
= false;
22 if (!current_set_polling_and_test()) {
23 unsigned int loop_count
= 0;
24 u64 limit
= TICK_NSEC
;
27 for (i
= 1; i
< drv
->state_count
; i
++) {
28 if (drv
->states
[i
].disabled
|| dev
->states_usage
[i
].disable
)
31 limit
= (u64
)drv
->states
[i
].target_residency
* NSEC_PER_USEC
;
35 while (!need_resched()) {
37 if (loop_count
++ < POLL_IDLE_RELAX_COUNT
)
41 if (local_clock() - time_start
> limit
) {
42 dev
->poll_time_limit
= true;
47 current_clr_polling();
52 void cpuidle_poll_state_init(struct cpuidle_driver
*drv
)
54 struct cpuidle_state
*state
= &drv
->states
[0];
56 snprintf(state
->name
, CPUIDLE_NAME_LEN
, "POLL");
57 snprintf(state
->desc
, CPUIDLE_DESC_LEN
, "CPUIDLE CORE POLL IDLE");
58 state
->exit_latency
= 0;
59 state
->target_residency
= 0;
60 state
->power_usage
= -1;
61 state
->enter
= poll_idle
;
62 state
->disabled
= false;
63 state
->flags
= CPUIDLE_FLAG_POLLING
;
65 EXPORT_SYMBOL_GPL(cpuidle_poll_state_init
);