Skip to content

Commit

Permalink
cpuidle: stop depending on pm_idle
Browse files Browse the repository at this point in the history
cpuidle users should call cpuidle_call_idle() directly
rather than via (pm_idle)() function pointer.

Architecture may choose to continue using (pm_idle)(),
but cpuidle need not depend on it:

  my_arch_cpu_idle()
	...
	if(cpuidle_call_idle())
		pm_idle();

cc: Kevin Hilman <[email protected]>
cc: Paul Mundt <[email protected]>
cc: [email protected]
Acked-by: H. Peter Anvin <[email protected]>
Signed-off-by: Len Brown <[email protected]>
  • Loading branch information
lenb committed Aug 3, 2011
1 parent 4bfc828 commit a0bfa13
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
4 changes: 3 additions & 1 deletion arch/arm/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <linux/uaccess.h>
#include <linux/random.h>
#include <linux/hw_breakpoint.h>
#include <linux/cpuidle.h>

#include <asm/cacheflush.h>
#include <asm/leds.h>
Expand Down Expand Up @@ -196,7 +197,8 @@ void cpu_idle(void)
cpu_relax();
} else {
stop_critical_timings();
pm_idle();
if (cpuidle_call_idle())
pm_idle();
start_critical_timings();
/*
* This will eventually be removed - pm_idle
Expand Down
6 changes: 4 additions & 2 deletions arch/sh/kernel/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
#include <linux/thread_info.h>
#include <linux/irqflags.h>
#include <linux/smp.h>
#include <linux/cpuidle.h>
#include <asm/pgalloc.h>
#include <asm/system.h>
#include <asm/atomic.h>
#include <asm/smp.h>

void (*pm_idle)(void) = NULL;
static void (*pm_idle)(void);

static int hlt_counter;

Expand Down Expand Up @@ -100,7 +101,8 @@ void cpu_idle(void)
local_irq_disable();
/* Don't trace irqs off for idle */
stop_critical_timings();
pm_idle();
if (cpuidle_call_idle())
pm_idle();
/*
* Sanity check to ensure that pm_idle() returns
* with IRQs enabled
Expand Down
4 changes: 3 additions & 1 deletion arch/x86/kernel/process_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <linux/uaccess.h>
#include <linux/io.h>
#include <linux/kdebug.h>
#include <linux/cpuidle.h>

#include <asm/pgtable.h>
#include <asm/system.h>
Expand Down Expand Up @@ -109,7 +110,8 @@ void cpu_idle(void)
local_irq_disable();
/* Don't trace irqs off for idle */
stop_critical_timings();
pm_idle();
if (cpuidle_idle_call())
pm_idle();
start_critical_timings();
}
tick_nohz_restart_sched_tick();
Expand Down
4 changes: 3 additions & 1 deletion arch/x86/kernel/process_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <linux/uaccess.h>
#include <linux/io.h>
#include <linux/ftrace.h>
#include <linux/cpuidle.h>

#include <asm/pgtable.h>
#include <asm/system.h>
Expand Down Expand Up @@ -136,7 +137,8 @@ void cpu_idle(void)
enter_idle();
/* Don't trace irqs off for idle */
stop_critical_timings();
pm_idle();
if (cpuidle_idle_call())
pm_idle();
start_critical_timings();

/* In many cases the interrupt that ended idle
Expand Down
38 changes: 18 additions & 20 deletions drivers/cpuidle/cpuidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ DEFINE_PER_CPU(struct cpuidle_device *, cpuidle_devices);

DEFINE_MUTEX(cpuidle_lock);
LIST_HEAD(cpuidle_detected_devices);
static void (*pm_idle_old)(void);

static int enabled_devices;
static int off __read_mostly;
static int initialized __read_mostly;

int cpuidle_disabled(void)
{
Expand Down Expand Up @@ -56,25 +56,23 @@ static int __cpuidle_register_device(struct cpuidle_device *dev);
* cpuidle_idle_call - the main idle loop
*
* NOTE: no locks or semaphores should be used here
* return non-zero on failure
*/
static void cpuidle_idle_call(void)
int cpuidle_idle_call(void)
{
struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
struct cpuidle_state *target_state;
int next_state;

if (off)
return -ENODEV;

if (!initialized)
return -ENODEV;

/* check if the device is ready */
if (!dev || !dev->enabled) {
if (pm_idle_old)
pm_idle_old();
else
#if defined(CONFIG_ARCH_HAS_DEFAULT_IDLE)
default_idle();
#else
local_irq_enable();
#endif
return;
}
if (!dev || !dev->enabled)
return -EBUSY;

#if 0
/* shows regressions, re-enable for 2.6.29 */
Expand All @@ -99,7 +97,7 @@ static void cpuidle_idle_call(void)
next_state = cpuidle_curr_governor->select(dev);
if (need_resched()) {
local_irq_enable();
return;
return 0;
}

target_state = &dev->states[next_state];
Expand All @@ -124,17 +122,19 @@ static void cpuidle_idle_call(void)
/* give the governor an opportunity to reflect on the outcome */
if (cpuidle_curr_governor->reflect)
cpuidle_curr_governor->reflect(dev);

return 0;
}

/**
* cpuidle_install_idle_handler - installs the cpuidle idle loop handler
*/
void cpuidle_install_idle_handler(void)
{
if (enabled_devices && (pm_idle != cpuidle_idle_call)) {
if (enabled_devices) {
/* Make sure all changes finished before we switch to new idle */
smp_wmb();
pm_idle = cpuidle_idle_call;
initialized = 1;
}
}

Expand All @@ -143,8 +143,8 @@ void cpuidle_install_idle_handler(void)
*/
void cpuidle_uninstall_idle_handler(void)
{
if (enabled_devices && pm_idle_old && (pm_idle != pm_idle_old)) {
pm_idle = pm_idle_old;
if (enabled_devices) {
initialized = 0;
cpuidle_kick_cpus();
}
}
Expand Down Expand Up @@ -440,8 +440,6 @@ static int __init cpuidle_init(void)
if (cpuidle_disabled())
return -ENODEV;

pm_idle_old = pm_idle;

ret = cpuidle_add_class_sysfs(&cpu_sysdev_class);
if (ret)
return ret;
Expand Down
2 changes: 2 additions & 0 deletions include/linux/cpuidle.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ struct cpuidle_driver {

#ifdef CONFIG_CPU_IDLE
extern void disable_cpuidle(void);
extern int cpuidle_idle_call(void);

extern int cpuidle_register_driver(struct cpuidle_driver *drv);
struct cpuidle_driver *cpuidle_get_driver(void);
Expand All @@ -137,6 +138,7 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev);

#else
static inline void disable_cpuidle(void) { }
static inline int cpuidle_idle_call(void) { return -ENODEV; }

static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
{return -ENODEV; }
Expand Down

0 comments on commit a0bfa13

Please sign in to comment.