]> Git Repo - linux.git/blame - drivers/cpuidle/poll_state.c
Merge tag 'linux-kselftest-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / drivers / cpuidle / poll_state.c
CommitLineData
34c2f65b
RW
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>
a37b969a 9#include <linux/sched/clock.h>
34c2f65b
RW
10#include <linux/sched/idle.h>
11
4dc2375c 12#define POLL_IDLE_RELAX_COUNT 200
a37b969a 13
34c2f65b
RW
14static int __cpuidle poll_idle(struct cpuidle_device *dev,
15 struct cpuidle_driver *drv, int index)
16{
a37b969a
RW
17 u64 time_start = local_clock();
18
5f26bdce
RW
19 dev->poll_time_limit = false;
20
34c2f65b
RW
21 local_irq_enable();
22 if (!current_set_polling_and_test()) {
01bad1c6 23 u64 limit = (u64)drv->states[1].target_residency * NSEC_PER_USEC;
4dc2375c
RW
24 unsigned int loop_count = 0;
25
a37b969a 26 while (!need_resched()) {
34c2f65b 27 cpu_relax();
4dc2375c
RW
28 if (loop_count++ < POLL_IDLE_RELAX_COUNT)
29 continue;
a37b969a 30
4dc2375c 31 loop_count = 0;
01bad1c6 32 if (local_clock() - time_start > limit) {
5f26bdce 33 dev->poll_time_limit = true;
a37b969a 34 break;
5f26bdce 35 }
a37b969a 36 }
34c2f65b
RW
37 }
38 current_clr_polling();
39
40 return index;
41}
42
1b39e3f8 43void cpuidle_poll_state_init(struct cpuidle_driver *drv)
34c2f65b
RW
44{
45 struct cpuidle_state *state = &drv->states[0];
46
47 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
48 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
49 state->exit_latency = 0;
50 state->target_residency = 0;
51 state->power_usage = -1;
52 state->enter = poll_idle;
53 state->disabled = false;
54 state->flags = CPUIDLE_FLAG_POLLING;
55}
1b39e3f8 56EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);
This page took 0.12911 seconds and 4 git commands to generate.