1 // SPDX-License-Identifier: GPL-2.0-only
3 * poll_state.c - Polling idle state
6 #include <linux/cpuidle.h>
7 #include <linux/sched.h>
8 #include <linux/sched/clock.h>
9 #include <linux/sched/idle.h>
11 #define POLL_IDLE_RELAX_COUNT 200
13 static int __cpuidle
poll_idle(struct cpuidle_device
*dev
,
14 struct cpuidle_driver
*drv
, int index
)
18 time_start
= local_clock_noinstr();
20 dev
->poll_time_limit
= false;
22 raw_local_irq_enable();
23 if (!current_set_polling_and_test()) {
24 unsigned int loop_count
= 0;
27 limit
= cpuidle_poll_time(drv
, dev
);
29 while (!need_resched()) {
31 if (loop_count
++ < POLL_IDLE_RELAX_COUNT
)
35 if (local_clock_noinstr() - time_start
> limit
) {
36 dev
->poll_time_limit
= true;
41 raw_local_irq_disable();
43 current_clr_polling();
48 void cpuidle_poll_state_init(struct cpuidle_driver
*drv
)
50 struct cpuidle_state
*state
= &drv
->states
[0];
52 snprintf(state
->name
, CPUIDLE_NAME_LEN
, "POLL");
53 snprintf(state
->desc
, CPUIDLE_DESC_LEN
, "CPUIDLE CORE POLL IDLE");
54 state
->exit_latency
= 0;
55 state
->target_residency
= 0;
56 state
->exit_latency_ns
= 0;
57 state
->target_residency_ns
= 0;
58 state
->power_usage
= -1;
59 state
->enter
= poll_idle
;
60 state
->flags
= CPUIDLE_FLAG_POLLING
;
62 EXPORT_SYMBOL_GPL(cpuidle_poll_state_init
);