Commit | Line | Data |
---|---|---|
55716d26 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
34c2f65b RW |
2 | /* |
3 | * poll_state.c - Polling idle state | |
34c2f65b RW |
4 | */ |
5 | ||
6 | #include <linux/cpuidle.h> | |
7 | #include <linux/sched.h> | |
a37b969a | 8 | #include <linux/sched/clock.h> |
34c2f65b RW |
9 | #include <linux/sched/idle.h> |
10 | ||
4dc2375c | 11 | #define POLL_IDLE_RELAX_COUNT 200 |
a37b969a | 12 | |
34c2f65b RW |
13 | static int __cpuidle poll_idle(struct cpuidle_device *dev, |
14 | struct cpuidle_driver *drv, int index) | |
15 | { | |
a37b969a RW |
16 | u64 time_start = local_clock(); |
17 | ||
5f26bdce RW |
18 | dev->poll_time_limit = false; |
19 | ||
34c2f65b RW |
20 | local_irq_enable(); |
21 | if (!current_set_polling_and_test()) { | |
4dc2375c | 22 | unsigned int loop_count = 0; |
259231a0 | 23 | u64 limit; |
800fb34a | 24 | |
259231a0 | 25 | limit = cpuidle_poll_time(drv, dev); |
4dc2375c | 26 | |
a37b969a | 27 | while (!need_resched()) { |
34c2f65b | 28 | cpu_relax(); |
4dc2375c RW |
29 | if (loop_count++ < POLL_IDLE_RELAX_COUNT) |
30 | continue; | |
a37b969a | 31 | |
4dc2375c | 32 | loop_count = 0; |
01bad1c6 | 33 | if (local_clock() - time_start > limit) { |
5f26bdce | 34 | dev->poll_time_limit = true; |
a37b969a | 35 | break; |
5f26bdce | 36 | } |
a37b969a | 37 | } |
34c2f65b RW |
38 | } |
39 | current_clr_polling(); | |
40 | ||
41 | return index; | |
42 | } | |
43 | ||
1b39e3f8 | 44 | void cpuidle_poll_state_init(struct cpuidle_driver *drv) |
34c2f65b RW |
45 | { |
46 | struct cpuidle_state *state = &drv->states[0]; | |
47 | ||
48 | snprintf(state->name, CPUIDLE_NAME_LEN, "POLL"); | |
49 | snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE"); | |
50 | state->exit_latency = 0; | |
51 | state->target_residency = 0; | |
52 | state->power_usage = -1; | |
53 | state->enter = poll_idle; | |
54 | state->disabled = false; | |
55 | state->flags = CPUIDLE_FLAG_POLLING; | |
56 | } | |
1b39e3f8 | 57 | EXPORT_SYMBOL_GPL(cpuidle_poll_state_init); |