Skip to content

Commit 34c2f65

Browse files
committed
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 <[email protected]> Tested-by: Sudeep Holla <[email protected]> Acked-by: Daniel Lezcano <[email protected]>
1 parent dc2251b commit 34c2f65

File tree

4 files changed

+43
-31
lines changed

4 files changed

+43
-31
lines changed

drivers/cpuidle/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
obj-y += cpuidle.o driver.o governor.o sysfs.o governors/
66
obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o
77
obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o
8+
obj-$(CONFIG_ARCH_HAS_CPU_RELAX) += poll_state.o
89

910
##################################################################################
1011
# ARM SoC drivers

drivers/cpuidle/driver.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -179,37 +179,6 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv)
179179
}
180180
}
181181

182-
#ifdef CONFIG_ARCH_HAS_CPU_RELAX
183-
static 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-
196-
static 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
210-
static void poll_idle_init(struct cpuidle_driver *drv) {}
211-
#endif /* !CONFIG_ARCH_HAS_CPU_RELAX */
212-
213182
/**
214183
* __cpuidle_register_driver: register the driver
215184
* @drv: a valid pointer to a struct cpuidle_driver

drivers/cpuidle/poll_state.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
11+
static 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+
24+
void 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+
}

include/linux/cpuidle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev,
225225
}
226226
#endif
227227

228+
#ifdef CONFIG_ARCH_HAS_CPU_RELAX
229+
void poll_idle_init(struct cpuidle_driver *drv);
230+
#else
231+
static void poll_idle_init(struct cpuidle_driver *drv) {}
232+
#endif
233+
228234
/******************************
229235
* CPUIDLE GOVERNOR INTERFACE *
230236
******************************/

0 commit comments

Comments
 (0)