Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * poll_state.c - Polling idle state
4 */
5
6#include <linux/cpuidle.h>
7#include <linux/sched.h>
8#include <linux/sched/clock.h>
9#include <linux/sched/idle.h>
10
11#define POLL_IDLE_RELAX_COUNT 200
12
13static int __cpuidle poll_idle(struct cpuidle_device *dev,
14 struct cpuidle_driver *drv, int index)
15{
16 u64 time_start;
17
18 time_start = local_clock_noinstr();
19
20 dev->poll_time_limit = false;
21
22 raw_local_irq_enable();
23 if (!current_set_polling_and_test()) {
24 unsigned int loop_count = 0;
25 u64 limit;
26
27 limit = cpuidle_poll_time(drv, dev);
28
29 while (!need_resched()) {
30 cpu_relax();
31 if (loop_count++ < POLL_IDLE_RELAX_COUNT)
32 continue;
33
34 loop_count = 0;
35 if (local_clock_noinstr() - time_start > limit) {
36 dev->poll_time_limit = true;
37 break;
38 }
39 }
40 }
41 raw_local_irq_disable();
42
43 current_clr_polling();
44
45 return index;
46}
47
48void cpuidle_poll_state_init(struct cpuidle_driver *drv)
49{
50 struct cpuidle_state *state = &drv->states[0];
51
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;
61}
62EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);
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
15static 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
39void 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}
52EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);