Skip to content

Commit

Permalink
Merge branch 'pm-cpuidle'
Browse files Browse the repository at this point in the history
* pm-cpuidle:
  ARM: EXYNOS: Remove incorrect __init annotation from cpuidle driver
  ARM: EXYNOS: Use dev_err() instead of printk() for cpuidle driver
  intel_idle: use CPU_TASKS_FROZEN instead of a numeric constant
  cpuidle: remove cpuidle_unregister_governor()
  cpuidle: don't call poll_idle_init() for every cpu
  cpuidle: use drv instead of cpuidle_driver in show_current_driver()
  cpuidle: call cpuidle_get_driver() from after taking cpuidle_driver_lock
  cpuidle: replace multiline statements with single line in cpuidle_idle_call()
  cpuidle: reduce code duplication inside cpuidle_idle_call()
  cpuidle: merge two if() statements for checking error cases
  cpuidle: rearrange __cpuidle_register_device() to keep minimal exit points
  cpuidle: rearrange code in __cpuidle_driver_init()
  cpuidle: make __cpuidle_driver_init() return void
  cpuidle: make __cpuidle_device_init() return void
  cpuidle: Fix comments in cpuidle core
  cpuidle: fix indentation of cpumask
  • Loading branch information
Rafael J. Wysocki committed Nov 7, 2013
2 parents 230b4b3 + f612a4f commit adf9684
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 138 deletions.
1 change: 0 additions & 1 deletion Documentation/cpuidle/governor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ kernel configuration and platform will be selected by cpuidle.

Interfaces:
extern int cpuidle_register_governor(struct cpuidle_governor *gov);
extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
struct cpuidle_governor
6 changes: 3 additions & 3 deletions arch/arm/mach-exynos/cpuidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static void __init exynos5_core_down_clk(void)
__raw_writel(tmp, EXYNOS5_PWR_CTRL2);
}

static int __init exynos_cpuidle_probe(struct platform_device *pdev)
static int exynos_cpuidle_probe(struct platform_device *pdev)
{
int cpu_id, ret;
struct cpuidle_device *device;
Expand All @@ -206,7 +206,7 @@ static int __init exynos_cpuidle_probe(struct platform_device *pdev)

ret = cpuidle_register_driver(&exynos4_idle_driver);
if (ret) {
printk(KERN_ERR "CPUidle failed to register driver\n");
dev_err(&pdev->dev, "failed to register cpuidle driver\n");
return ret;
}

Expand All @@ -220,7 +220,7 @@ static int __init exynos_cpuidle_probe(struct platform_device *pdev)

ret = cpuidle_register_device(device);
if (ret) {
printk(KERN_ERR "CPUidle register device failed\n");
dev_err(&pdev->dev, "failed to register cpuidle device\n");
return ret;
}
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/cpuidle/coupled.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static cpumask_t cpuidle_coupled_poked;
* has returned from this function, the barrier is immediately available for
* reuse.
*
* The atomic variable a must be initialized to 0 before any cpu calls
* The atomic variable must be initialized to 0 before any cpu calls
* this function, will be reset to 0 before any cpu returns from this function.
*
* Must only be called from within a coupled idle state handler
Expand Down
78 changes: 15 additions & 63 deletions drivers/cpuidle/cpuidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ int cpuidle_idle_call(void)
struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
struct cpuidle_driver *drv;
int next_state, entered_state;
bool broadcast;

if (off)
return -ENODEV;

if (!initialized)
if (off || !initialized)
return -ENODEV;

/* check if the device is ready */
Expand All @@ -144,19 +142,19 @@ int cpuidle_idle_call(void)

trace_cpu_idle_rcuidle(next_state, dev->cpu);

if (drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP)
clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
&dev->cpu);
broadcast = !!(drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP);

if (broadcast)
clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);

if (cpuidle_state_is_coupled(dev, drv, next_state))
entered_state = cpuidle_enter_state_coupled(dev, drv,
next_state);
else
entered_state = cpuidle_enter_state(dev, drv, next_state);

if (drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP)
clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
&dev->cpu);
if (broadcast)
clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);

trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);

Expand Down Expand Up @@ -228,45 +226,6 @@ void cpuidle_resume(void)
mutex_unlock(&cpuidle_lock);
}

#ifdef CONFIG_ARCH_HAS_CPU_RELAX
static int poll_idle(struct cpuidle_device *dev,
struct cpuidle_driver *drv, int index)
{
ktime_t t1, t2;
s64 diff;

t1 = ktime_get();
local_irq_enable();
while (!need_resched())
cpu_relax();

t2 = ktime_get();
diff = ktime_to_us(ktime_sub(t2, t1));
if (diff > INT_MAX)
diff = INT_MAX;

dev->last_residency = (int) diff;

return index;
}

static void poll_idle_init(struct cpuidle_driver *drv)
{
struct cpuidle_state *state = &drv->states[0];

snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
state->exit_latency = 0;
state->target_residency = 0;
state->power_usage = -1;
state->flags = 0;
state->enter = poll_idle;
state->disabled = false;
}
#else
static void poll_idle_init(struct cpuidle_driver *drv) {}
#endif /* CONFIG_ARCH_HAS_CPU_RELAX */

/**
* cpuidle_enable_device - enables idle PM for a CPU
* @dev: the CPU
Expand Down Expand Up @@ -296,8 +255,6 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
if (!dev->state_count)
dev->state_count = drv->state_count;

poll_idle_init(drv);

ret = cpuidle_add_device_sysfs(dev);
if (ret)
return ret;
Expand Down Expand Up @@ -358,12 +315,10 @@ static void __cpuidle_unregister_device(struct cpuidle_device *dev)
module_put(drv->owner);
}

static int __cpuidle_device_init(struct cpuidle_device *dev)
static void __cpuidle_device_init(struct cpuidle_device *dev)
{
memset(dev->states_usage, 0, sizeof(dev->states_usage));
dev->last_residency = 0;

return 0;
}

/**
Expand All @@ -385,13 +340,12 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
list_add(&dev->device_list, &cpuidle_detected_devices);

ret = cpuidle_coupled_register_device(dev);
if (ret) {
if (ret)
__cpuidle_unregister_device(dev);
return ret;
}
else
dev->registered = 1;

dev->registered = 1;
return 0;
return ret;
}

/**
Expand All @@ -410,9 +364,7 @@ int cpuidle_register_device(struct cpuidle_device *dev)
if (dev->registered)
goto out_unlock;

ret = __cpuidle_device_init(dev);
if (ret)
goto out_unlock;
__cpuidle_device_init(dev);

ret = __cpuidle_register_device(dev);
if (ret)
Expand Down Expand Up @@ -516,7 +468,7 @@ int cpuidle_register(struct cpuidle_driver *drv,

#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
/*
* On multiplatform for ARM, the coupled idle states could
* On multiplatform for ARM, the coupled idle states could be
* enabled in the kernel even if the cpuidle driver does not
* use it. Note, coupled_cpus is a struct copy.
*/
Expand Down
67 changes: 51 additions & 16 deletions drivers/cpuidle/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <linux/mutex.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/cpuidle.h>
#include <linux/cpumask.h>
#include <linux/clockchips.h>
Expand Down Expand Up @@ -56,7 +57,7 @@ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
}

/**
* __cpuidle_set_driver - set per CPU driver variables the the given driver.
* __cpuidle_set_driver - set per CPU driver variables for the given driver.
* @drv: a valid pointer to a struct cpuidle_driver
*
* For each CPU in the driver's cpumask, unset the registered driver per CPU
Expand Down Expand Up @@ -132,7 +133,7 @@ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
* cpuidle_setup_broadcast_timer - enable/disable the broadcast timer
* @arg: a void pointer used to match the SMP cross call API
*
* @arg is used as a value of type 'long' with on of the two values:
* @arg is used as a value of type 'long' with one of the two values:
* - CLOCK_EVT_NOTIFY_BROADCAST_ON
* - CLOCK_EVT_NOTIFY_BROADCAST_OFF
*
Expand All @@ -149,10 +150,8 @@ static void cpuidle_setup_broadcast_timer(void *arg)
/**
* __cpuidle_driver_init - initialize the driver's internal data
* @drv: a valid pointer to a struct cpuidle_driver
*
* Returns 0 on success, a negative error code otherwise.
*/
static int __cpuidle_driver_init(struct cpuidle_driver *drv)
static void __cpuidle_driver_init(struct cpuidle_driver *drv)
{
int i;

Expand All @@ -169,20 +168,55 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv)
/*
* Look for the timer stop flag in the different states, so that we know
* if the broadcast timer has to be set up. The loop is in the reverse
* order, because usually on of the the deeper states has this flag set.
* order, because usually one of the deeper states have this flag set.
*/
for (i = drv->state_count - 1; i >= 0 ; i--) {
if (drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP) {
drv->bctimer = 1;
break;
}
}
}

if (!(drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP))
continue;
#ifdef CONFIG_ARCH_HAS_CPU_RELAX
static int poll_idle(struct cpuidle_device *dev,
struct cpuidle_driver *drv, int index)
{
ktime_t t1, t2;
s64 diff;

drv->bctimer = 1;
break;
}
t1 = ktime_get();
local_irq_enable();
while (!need_resched())
cpu_relax();

return 0;
t2 = ktime_get();
diff = ktime_to_us(ktime_sub(t2, t1));
if (diff > INT_MAX)
diff = INT_MAX;

dev->last_residency = (int) diff;

return index;
}

static void poll_idle_init(struct cpuidle_driver *drv)
{
struct cpuidle_state *state = &drv->states[0];

snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
state->exit_latency = 0;
state->target_residency = 0;
state->power_usage = -1;
state->flags = 0;
state->enter = poll_idle;
state->disabled = false;
}
#else
static void poll_idle_init(struct cpuidle_driver *drv) {}
#endif /* !CONFIG_ARCH_HAS_CPU_RELAX */

/**
* __cpuidle_register_driver: register the driver
* @drv: a valid pointer to a struct cpuidle_driver
Expand All @@ -206,9 +240,7 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv)
if (cpuidle_disabled())
return -ENODEV;

ret = __cpuidle_driver_init(drv);
if (ret)
return ret;
__cpuidle_driver_init(drv);

ret = __cpuidle_set_driver(drv);
if (ret)
Expand All @@ -218,6 +250,8 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv)
on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
(void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);

poll_idle_init(drv);

return 0;
}

Expand Down Expand Up @@ -346,10 +380,11 @@ struct cpuidle_driver *cpuidle_driver_ref(void)
*/
void cpuidle_driver_unref(void)
{
struct cpuidle_driver *drv = cpuidle_get_driver();
struct cpuidle_driver *drv;

spin_lock(&cpuidle_driver_lock);

drv = cpuidle_get_driver();
if (drv && !WARN_ON(drv->refcnt <= 0))
drv->refcnt--;

Expand Down
43 changes: 0 additions & 43 deletions drivers/cpuidle/governor.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,46 +96,3 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)

return ret;
}

/**
* cpuidle_replace_governor - find a replacement governor
* @exclude_rating: the rating that will be skipped while looking for
* new governor.
*/
static struct cpuidle_governor *cpuidle_replace_governor(int exclude_rating)
{
struct cpuidle_governor *gov;
struct cpuidle_governor *ret_gov = NULL;
unsigned int max_rating = 0;

list_for_each_entry(gov, &cpuidle_governors, governor_list) {
if (gov->rating == exclude_rating)
continue;
if (gov->rating > max_rating) {
max_rating = gov->rating;
ret_gov = gov;
}
}

return ret_gov;
}

/**
* cpuidle_unregister_governor - unregisters a governor
* @gov: the governor
*/
void cpuidle_unregister_governor(struct cpuidle_governor *gov)
{
if (!gov)
return;

mutex_lock(&cpuidle_lock);
if (gov == cpuidle_curr_governor) {
struct cpuidle_governor *new_gov;
new_gov = cpuidle_replace_governor(gov->rating);
cpuidle_switch_governor(new_gov);
}
list_del(&gov->governor_list);
mutex_unlock(&cpuidle_lock);
}

7 changes: 4 additions & 3 deletions drivers/cpuidle/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ static ssize_t show_current_driver(struct device *dev,
char *buf)
{
ssize_t ret;
struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();
struct cpuidle_driver *drv;

spin_lock(&cpuidle_driver_lock);
if (cpuidle_driver)
ret = sprintf(buf, "%s\n", cpuidle_driver->name);
drv = cpuidle_get_driver();
if (drv)
ret = sprintf(buf, "%s\n", drv->name);
else
ret = sprintf(buf, "none\n");
spin_unlock(&cpuidle_driver_lock);
Expand Down
2 changes: 1 addition & 1 deletion drivers/idle/intel_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static int cpu_hotplug_notify(struct notifier_block *n,
int hotcpu = (unsigned long)hcpu;
struct cpuidle_device *dev;

switch (action & 0xf) {
switch (action & ~CPU_TASKS_FROZEN) {
case CPU_ONLINE:

if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
Expand Down
Loading

0 comments on commit adf9684

Please sign in to comment.