提交 82467a5a 编写于 作者: D Daniel Lezcano 提交者: Rafael J. Wysocki

cpuidle: simplify multiple driver support

Commit bf4d1b5d (cpuidle: support multiple drivers) introduced support
for using multiple cpuidle drivers at the same time.  It added a
couple of new APIs to register the driver per CPU, but that led to
some unnecessary code complexity related to the kernel config options
deciding whether or not the multiple driver support is enabled.  The
code has to work as it did before when the multiple driver support is
not enabled and the multiple driver support has to be compatible with
the previously existing API.

Remove the new API, not used by any driver in the tree yet (but
needed for the HMP cpuidle drivers that will be submitted soon), and
add a new cpumask pointer to the cpuidle driver structure that will
point to the mask of CPUs handled by the given driver.  That will
allow the cpuidle_[un]register_driver() API to be used for the
multiple driver support along with the cpuidle_[un]register()
functions added recently.

[rjw: Changelog]
Signed-off-by: NDaniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 bd2a337a
...@@ -466,7 +466,7 @@ void cpuidle_unregister(struct cpuidle_driver *drv) ...@@ -466,7 +466,7 @@ void cpuidle_unregister(struct cpuidle_driver *drv)
int cpu; int cpu;
struct cpuidle_device *device; struct cpuidle_device *device;
for_each_possible_cpu(cpu) { for_each_cpu(cpu, drv->cpumask) {
device = &per_cpu(cpuidle_dev, cpu); device = &per_cpu(cpuidle_dev, cpu);
cpuidle_unregister_device(device); cpuidle_unregister_device(device);
} }
...@@ -498,7 +498,7 @@ int cpuidle_register(struct cpuidle_driver *drv, ...@@ -498,7 +498,7 @@ int cpuidle_register(struct cpuidle_driver *drv,
return ret; return ret;
} }
for_each_possible_cpu(cpu) { for_each_cpu(cpu, drv->cpumask) {
device = &per_cpu(cpuidle_dev, cpu); device = &per_cpu(cpuidle_dev, cpu);
device->cpu = cpu; device->cpu = cpu;
......
...@@ -18,167 +18,140 @@ ...@@ -18,167 +18,140 @@
DEFINE_SPINLOCK(cpuidle_driver_lock); DEFINE_SPINLOCK(cpuidle_driver_lock);
static void __cpuidle_set_cpu_driver(struct cpuidle_driver *drv, int cpu); #ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
static struct cpuidle_driver * __cpuidle_get_cpu_driver(int cpu);
static void cpuidle_setup_broadcast_timer(void *arg) static DEFINE_PER_CPU(struct cpuidle_driver *, cpuidle_drivers);
static struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu)
{ {
int cpu = smp_processor_id(); return per_cpu(cpuidle_drivers, cpu);
clockevents_notify((long)(arg), &cpu);
} }
static void __cpuidle_driver_init(struct cpuidle_driver *drv, int cpu) static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
{ {
int i; int cpu;
drv->refcnt = 0;
for (i = drv->state_count - 1; i >= 0 ; i--) { for_each_cpu(cpu, drv->cpumask) {
if (!(drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP)) if (drv != __cpuidle_get_cpu_driver(cpu))
continue; continue;
drv->bctimer = 1; per_cpu(cpuidle_drivers, cpu) = NULL;
on_each_cpu_mask(get_cpu_mask(cpu), cpuidle_setup_broadcast_timer,
(void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
break;
} }
} }
static int __cpuidle_register_driver(struct cpuidle_driver *drv, int cpu) static inline int __cpuidle_set_driver(struct cpuidle_driver *drv)
{ {
if (!drv || !drv->state_count) int cpu;
return -EINVAL;
if (cpuidle_disabled())
return -ENODEV;
if (__cpuidle_get_cpu_driver(cpu)) for_each_cpu(cpu, drv->cpumask) {
return -EBUSY;
__cpuidle_driver_init(drv, cpu); if (__cpuidle_get_cpu_driver(cpu)) {
__cpuidle_unset_driver(drv);
return -EBUSY;
}
__cpuidle_set_cpu_driver(drv, cpu); per_cpu(cpuidle_drivers, cpu) = drv;
}
return 0; return 0;
} }
static void __cpuidle_unregister_driver(struct cpuidle_driver *drv, int cpu) #else
{
if (drv != __cpuidle_get_cpu_driver(cpu))
return;
if (!WARN_ON(drv->refcnt > 0)) static struct cpuidle_driver *cpuidle_curr_driver;
__cpuidle_set_cpu_driver(NULL, cpu);
if (drv->bctimer) { static inline struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu)
drv->bctimer = 0; {
on_each_cpu_mask(get_cpu_mask(cpu), cpuidle_setup_broadcast_timer, return cpuidle_curr_driver;
(void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1);
}
} }
#ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS static inline int __cpuidle_set_driver(struct cpuidle_driver *drv)
{
if (cpuidle_curr_driver)
return -EBUSY;
static DEFINE_PER_CPU(struct cpuidle_driver *, cpuidle_drivers); cpuidle_curr_driver = drv;
static void __cpuidle_set_cpu_driver(struct cpuidle_driver *drv, int cpu) return 0;
{
per_cpu(cpuidle_drivers, cpu) = drv;
} }
static struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu) static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
{ {
return per_cpu(cpuidle_drivers, cpu); if (drv == cpuidle_curr_driver)
cpuidle_curr_driver = NULL;
} }
static void __cpuidle_unregister_all_cpu_driver(struct cpuidle_driver *drv) #endif
static void cpuidle_setup_broadcast_timer(void *arg)
{ {
int cpu; int cpu = smp_processor_id();
for_each_present_cpu(cpu) clockevents_notify((long)(arg), &cpu);
__cpuidle_unregister_driver(drv, cpu);
} }
static int __cpuidle_register_all_cpu_driver(struct cpuidle_driver *drv) static int __cpuidle_driver_init(struct cpuidle_driver *drv)
{ {
int ret = 0; int i;
int i, cpu;
for_each_present_cpu(cpu) { drv->refcnt = 0;
ret = __cpuidle_register_driver(drv, cpu);
if (ret)
break;
}
if (ret) if (!drv->cpumask)
for_each_present_cpu(i) { drv->cpumask = (struct cpumask *)cpu_possible_mask;
if (i == cpu)
break;
__cpuidle_unregister_driver(drv, i);
}
for (i = drv->state_count - 1; i >= 0 ; i--) {
return ret; if (!(drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP))
continue;
drv->bctimer = 1;
break;
}
return 0;
} }
int cpuidle_register_cpu_driver(struct cpuidle_driver *drv, int cpu) static int __cpuidle_register_driver(struct cpuidle_driver *drv)
{ {
int ret; int ret;
spin_lock(&cpuidle_driver_lock); if (!drv || !drv->state_count)
ret = __cpuidle_register_driver(drv, cpu); return -EINVAL;
spin_unlock(&cpuidle_driver_lock);
return ret; if (cpuidle_disabled())
} return -ENODEV;
void cpuidle_unregister_cpu_driver(struct cpuidle_driver *drv, int cpu) ret = __cpuidle_driver_init(drv);
{ if (ret)
spin_lock(&cpuidle_driver_lock); return ret;
__cpuidle_unregister_driver(drv, cpu);
spin_unlock(&cpuidle_driver_lock);
}
/** ret = __cpuidle_set_driver(drv);
* cpuidle_register_driver - registers a driver if (ret)
* @drv: the driver return ret;
*/
int cpuidle_register_driver(struct cpuidle_driver *drv)
{
int ret;
spin_lock(&cpuidle_driver_lock); if (drv->bctimer)
ret = __cpuidle_register_all_cpu_driver(drv); on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
spin_unlock(&cpuidle_driver_lock); (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
return ret; return 0;
} }
EXPORT_SYMBOL_GPL(cpuidle_register_driver);
/** /**
* cpuidle_unregister_driver - unregisters a driver * cpuidle_unregister_driver - unregisters a driver
* @drv: the driver * @drv: the driver
*/ */
void cpuidle_unregister_driver(struct cpuidle_driver *drv) static void __cpuidle_unregister_driver(struct cpuidle_driver *drv)
{ {
spin_lock(&cpuidle_driver_lock); if (WARN_ON(drv->refcnt > 0))
__cpuidle_unregister_all_cpu_driver(drv); return;
spin_unlock(&cpuidle_driver_lock);
}
EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);
#else
static struct cpuidle_driver *cpuidle_curr_driver;
static inline void __cpuidle_set_cpu_driver(struct cpuidle_driver *drv, int cpu) if (drv->bctimer) {
{ drv->bctimer = 0;
cpuidle_curr_driver = drv; on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
} (void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1);
}
static inline struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu) __cpuidle_unset_driver(drv);
{
return cpuidle_curr_driver;
} }
/** /**
...@@ -187,13 +160,11 @@ static inline struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu) ...@@ -187,13 +160,11 @@ static inline struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu)
*/ */
int cpuidle_register_driver(struct cpuidle_driver *drv) int cpuidle_register_driver(struct cpuidle_driver *drv)
{ {
int ret, cpu; int ret;
cpu = get_cpu();
spin_lock(&cpuidle_driver_lock); spin_lock(&cpuidle_driver_lock);
ret = __cpuidle_register_driver(drv, cpu); ret = __cpuidle_register_driver(drv);
spin_unlock(&cpuidle_driver_lock); spin_unlock(&cpuidle_driver_lock);
put_cpu();
return ret; return ret;
} }
...@@ -205,16 +176,11 @@ EXPORT_SYMBOL_GPL(cpuidle_register_driver); ...@@ -205,16 +176,11 @@ EXPORT_SYMBOL_GPL(cpuidle_register_driver);
*/ */
void cpuidle_unregister_driver(struct cpuidle_driver *drv) void cpuidle_unregister_driver(struct cpuidle_driver *drv)
{ {
int cpu;
cpu = get_cpu();
spin_lock(&cpuidle_driver_lock); spin_lock(&cpuidle_driver_lock);
__cpuidle_unregister_driver(drv, cpu); __cpuidle_unregister_driver(drv);
spin_unlock(&cpuidle_driver_lock); spin_unlock(&cpuidle_driver_lock);
put_cpu();
} }
EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);
#endif
/** /**
* cpuidle_get_driver - return the current driver * cpuidle_get_driver - return the current driver
......
...@@ -111,6 +111,9 @@ struct cpuidle_driver { ...@@ -111,6 +111,9 @@ struct cpuidle_driver {
struct cpuidle_state states[CPUIDLE_STATE_MAX]; struct cpuidle_state states[CPUIDLE_STATE_MAX];
int state_count; int state_count;
int safe_state_index; int safe_state_index;
/* the driver handles the cpus in cpumask */
struct cpumask *cpumask;
}; };
#ifdef CONFIG_CPU_IDLE #ifdef CONFIG_CPU_IDLE
...@@ -135,9 +138,6 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev); ...@@ -135,9 +138,6 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev);
extern int cpuidle_play_dead(void); extern int cpuidle_play_dead(void);
extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev); extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
extern int cpuidle_register_cpu_driver(struct cpuidle_driver *drv, int cpu);
extern void cpuidle_unregister_cpu_driver(struct cpuidle_driver *drv, int cpu);
#else #else
static inline void disable_cpuidle(void) { } static inline void disable_cpuidle(void) { }
static inline int cpuidle_idle_call(void) { return -ENODEV; } static inline int cpuidle_idle_call(void) { return -ENODEV; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册