Skip to content

Commit d7c7f10

Browse files
vireshkrafaeljw
authored andcommitted
cpuidle: don't call poll_idle_init() for every cpu
poll_idle_init() just initializes drv->states[0] and so that is required to be done only once for each driver. Currently, it is called from cpuidle_enable_device() which is called for every CPU that the driver supports. That is not required, so move it to a better place and call it from __cpuidle_register_driver() so that the initialization is carried out only once. Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 1f6b9f7 commit d7c7f10

2 files changed

Lines changed: 42 additions & 41 deletions

File tree

‎drivers/cpuidle/cpuidle.c‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -226,45 +226,6 @@ void cpuidle_resume(void)
226226
mutex_unlock(&cpuidle_lock);
227227
}
228228

229-
#ifdef CONFIG_ARCH_HAS_CPU_RELAX
230-
static int poll_idle(struct cpuidle_device *dev,
231-
struct cpuidle_driver *drv, int index)
232-
{
233-
ktime_t t1, t2;
234-
s64 diff;
235-
236-
t1 = ktime_get();
237-
local_irq_enable();
238-
while (!need_resched())
239-
cpu_relax();
240-
241-
t2 = ktime_get();
242-
diff = ktime_to_us(ktime_sub(t2, t1));
243-
if (diff > INT_MAX)
244-
diff = INT_MAX;
245-
246-
dev->last_residency = (int) diff;
247-
248-
return index;
249-
}
250-
251-
static void poll_idle_init(struct cpuidle_driver *drv)
252-
{
253-
struct cpuidle_state *state = &drv->states[0];
254-
255-
snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
256-
snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
257-
state->exit_latency = 0;
258-
state->target_residency = 0;
259-
state->power_usage = -1;
260-
state->flags = 0;
261-
state->enter = poll_idle;
262-
state->disabled = false;
263-
}
264-
#else
265-
static void poll_idle_init(struct cpuidle_driver *drv) {}
266-
#endif /* CONFIG_ARCH_HAS_CPU_RELAX */
267-
268229
/**
269230
* cpuidle_enable_device - enables idle PM for a CPU
270231
* @dev: the CPU
@@ -294,8 +255,6 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
294255
if (!dev->state_count)
295256
dev->state_count = drv->state_count;
296257

297-
poll_idle_init(drv);
298-
299258
ret = cpuidle_add_device_sysfs(dev);
300259
if (ret)
301260
return ret;

‎drivers/cpuidle/driver.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/mutex.h>
1212
#include <linux/module.h>
13+
#include <linux/sched.h>
1314
#include <linux/cpuidle.h>
1415
#include <linux/cpumask.h>
1516
#include <linux/clockchips.h>
@@ -177,6 +178,45 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv)
177178
}
178179
}
179180

181+
#ifdef CONFIG_ARCH_HAS_CPU_RELAX
182+
static int poll_idle(struct cpuidle_device *dev,
183+
struct cpuidle_driver *drv, int index)
184+
{
185+
ktime_t t1, t2;
186+
s64 diff;
187+
188+
t1 = ktime_get();
189+
local_irq_enable();
190+
while (!need_resched())
191+
cpu_relax();
192+
193+
t2 = ktime_get();
194+
diff = ktime_to_us(ktime_sub(t2, t1));
195+
if (diff > INT_MAX)
196+
diff = INT_MAX;
197+
198+
dev->last_residency = (int) diff;
199+
200+
return index;
201+
}
202+
203+
static void poll_idle_init(struct cpuidle_driver *drv)
204+
{
205+
struct cpuidle_state *state = &drv->states[0];
206+
207+
snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
208+
snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
209+
state->exit_latency = 0;
210+
state->target_residency = 0;
211+
state->power_usage = -1;
212+
state->flags = 0;
213+
state->enter = poll_idle;
214+
state->disabled = false;
215+
}
216+
#else
217+
static void poll_idle_init(struct cpuidle_driver *drv) {}
218+
#endif /* !CONFIG_ARCH_HAS_CPU_RELAX */
219+
180220
/**
181221
* __cpuidle_register_driver: register the driver
182222
* @drv: a valid pointer to a struct cpuidle_driver
@@ -210,6 +250,8 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv)
210250
on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
211251
(void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
212252

253+
poll_idle_init(drv);
254+
213255
return 0;
214256
}
215257

0 commit comments

Comments
 (0)