aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-08-23 17:21:07 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-08-29 21:06:27 -0400
commit34c2f65b718d44ea7d7b3cc10777f410677455ce (patch)
tree70a9a541937ff04eb67c1bda48f81da664231df6
parentdc2251bf98c66db3f4e055b751968f0871037ae4 (diff)
cpuidle: Move polling state initialization code to separate file
Move the polling state initialization code to a separate file built conditionally on CONFIG_ARCH_HAS_CPU_RELAX to get rid of the #ifdef in driver.c. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: Sudeep Holla <sudeep.holla@arm.com> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--drivers/cpuidle/Makefile1
-rw-r--r--drivers/cpuidle/driver.c31
-rw-r--r--drivers/cpuidle/poll_state.c36
-rw-r--r--include/linux/cpuidle.h6
4 files changed, 43 insertions, 31 deletions
diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile
index 3ba81b1dffad..0b67a05a7aae 100644
--- a/drivers/cpuidle/Makefile
+++ b/drivers/cpuidle/Makefile
@@ -5,6 +5,7 @@
5obj-y += cpuidle.o driver.o governor.o sysfs.o governors/ 5obj-y += cpuidle.o driver.o governor.o sysfs.o governors/
6obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o 6obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o
7obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o 7obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o
8obj-$(CONFIG_ARCH_HAS_CPU_RELAX) += poll_state.o
8 9
9################################################################################## 10##################################################################################
10# ARM SoC drivers 11# ARM SoC drivers
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index e942f8ef4309..6f694c86f3fa 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -179,37 +179,6 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv)
179 } 179 }
180} 180}
181 181
182#ifdef CONFIG_ARCH_HAS_CPU_RELAX
183static int __cpuidle poll_idle(struct cpuidle_device *dev,
184 struct cpuidle_driver *drv, int index)
185{
186 local_irq_enable();
187 if (!current_set_polling_and_test()) {
188 while (!need_resched())
189 cpu_relax();
190 }
191 current_clr_polling();
192
193 return index;
194}
195
196static void poll_idle_init(struct cpuidle_driver *drv)
197{
198 struct cpuidle_state *state = &drv->states[0];
199
200 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
201 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
202 state->exit_latency = 0;
203 state->target_residency = 0;
204 state->power_usage = -1;
205 state->enter = poll_idle;
206 state->disabled = false;
207 state->flags = CPUIDLE_FLAG_POLLING;
208}
209#else
210static void poll_idle_init(struct cpuidle_driver *drv) {}
211#endif /* !CONFIG_ARCH_HAS_CPU_RELAX */
212
213/** 182/**
214 * __cpuidle_register_driver: register the driver 183 * __cpuidle_register_driver: register the driver
215 * @drv: a valid pointer to a struct cpuidle_driver 184 * @drv: a valid pointer to a struct cpuidle_driver
diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c
new file mode 100644
index 000000000000..0db4f7273952
--- /dev/null
+++ b/drivers/cpuidle/poll_state.c
@@ -0,0 +1,36 @@
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/idle.h>
10
11static int __cpuidle poll_idle(struct cpuidle_device *dev,
12 struct cpuidle_driver *drv, int index)
13{
14 local_irq_enable();
15 if (!current_set_polling_and_test()) {
16 while (!need_resched())
17 cpu_relax();
18 }
19 current_clr_polling();
20
21 return index;
22}
23
24void poll_idle_init(struct cpuidle_driver *drv)
25{
26 struct cpuidle_state *state = &drv->states[0];
27
28 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
29 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
30 state->exit_latency = 0;
31 state->target_residency = 0;
32 state->power_usage = -1;
33 state->enter = poll_idle;
34 state->disabled = false;
35 state->flags = CPUIDLE_FLAG_POLLING;
36}
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
index b58d952a00e2..561bc5365067 100644
--- a/include/linux/cpuidle.h
+++ b/include/linux/cpuidle.h
@@ -225,6 +225,12 @@ static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev,
225} 225}
226#endif 226#endif
227 227
228#ifdef CONFIG_ARCH_HAS_CPU_RELAX
229void poll_idle_init(struct cpuidle_driver *drv);
230#else
231static void poll_idle_init(struct cpuidle_driver *drv) {}
232#endif
233
228/****************************** 234/******************************
229 * CPUIDLE GOVERNOR INTERFACE * 235 * CPUIDLE GOVERNOR INTERFACE *
230 ******************************/ 236 ******************************/