Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 32798
b: refs/heads/master
c: aa95387
h: refs/heads/master
v: v3
  • Loading branch information
Linus Torvalds committed Jul 23, 2006
1 parent eb64114 commit 050dc3a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 48 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2cd7cbdf4bd0d0fe58e4dc903e8b413412595504
refs/heads/master: aa95387774039096c11803c04011f1aa42d85758
6 changes: 0 additions & 6 deletions trunk/include/linux/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ static inline void unregister_cpu_notifier(struct notifier_block *nb)
{
}
#endif
extern int current_in_cpu_hotplug(void);

int cpu_up(unsigned int cpu);

Expand All @@ -61,10 +60,6 @@ static inline int register_cpu_notifier(struct notifier_block *nb)
static inline void unregister_cpu_notifier(struct notifier_block *nb)
{
}
static inline int current_in_cpu_hotplug(void)
{
return 0;
}

#endif /* CONFIG_SMP */
extern struct sysdev_class cpu_sysdev_class;
Expand All @@ -73,7 +68,6 @@ extern struct sysdev_class cpu_sysdev_class;
/* Stop CPUs going up and down. */
extern void lock_cpu_hotplug(void);
extern void unlock_cpu_hotplug(void);
extern int lock_cpu_hotplug_interruptible(void);
#define hotcpu_notifier(fn, pri) { \
static struct notifier_block fn##_nb = \
{ .notifier_call = fn, .priority = pri }; \
Expand Down
75 changes: 34 additions & 41 deletions trunk/kernel/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,48 @@
#include <linux/mutex.h>

/* This protects CPUs going up and down... */
static DEFINE_MUTEX(cpucontrol);
static DEFINE_MUTEX(cpu_add_remove_lock);
static DEFINE_MUTEX(cpu_bitmask_lock);

static __cpuinitdata BLOCKING_NOTIFIER_HEAD(cpu_chain);

#ifdef CONFIG_HOTPLUG_CPU
static struct task_struct *lock_cpu_hotplug_owner;
static int lock_cpu_hotplug_depth;

static int __lock_cpu_hotplug(int interruptible)
{
int ret = 0;

if (lock_cpu_hotplug_owner != current) {
if (interruptible)
ret = mutex_lock_interruptible(&cpucontrol);
else
mutex_lock(&cpucontrol);
}

/*
* Set only if we succeed in locking
*/
if (!ret) {
lock_cpu_hotplug_depth++;
lock_cpu_hotplug_owner = current;
}

return ret;
}
/* Crappy recursive lock-takers in cpufreq! Complain loudly about idiots */
static struct task_struct *recursive;
static int recursive_depth;

void lock_cpu_hotplug(void)
{
__lock_cpu_hotplug(0);
struct task_struct *tsk = current;

if (tsk == recursive) {
static int warnings = 10;
if (warnings) {
printk(KERN_ERR "Lukewarm IQ detected in hotplug locking\n");
WARN_ON(1);
warnings--;
}
recursive_depth++;
return;
}
mutex_lock(&cpu_bitmask_lock);
recursive = tsk;
}
EXPORT_SYMBOL_GPL(lock_cpu_hotplug);

void unlock_cpu_hotplug(void)
{
if (--lock_cpu_hotplug_depth == 0) {
lock_cpu_hotplug_owner = NULL;
mutex_unlock(&cpucontrol);
WARN_ON(recursive != current);
if (recursive_depth) {
recursive_depth--;
return;
}
mutex_unlock(&cpu_bitmask_lock);
recursive = NULL;
}
EXPORT_SYMBOL_GPL(unlock_cpu_hotplug);

int lock_cpu_hotplug_interruptible(void)
{
return __lock_cpu_hotplug(1);
}
EXPORT_SYMBOL_GPL(lock_cpu_hotplug_interruptible);
#endif /* CONFIG_HOTPLUG_CPU */

/* Need to know about CPUs going up/down? */
Expand Down Expand Up @@ -122,9 +114,7 @@ int cpu_down(unsigned int cpu)
struct task_struct *p;
cpumask_t old_allowed, tmp;

if ((err = lock_cpu_hotplug_interruptible()) != 0)
return err;

mutex_lock(&cpu_add_remove_lock);
if (num_online_cpus() == 1) {
err = -EBUSY;
goto out;
Expand All @@ -150,7 +140,10 @@ int cpu_down(unsigned int cpu)
cpu_clear(cpu, tmp);
set_cpus_allowed(current, tmp);

mutex_lock(&cpu_bitmask_lock);
p = __stop_machine_run(take_cpu_down, NULL, cpu);
mutex_unlock(&cpu_bitmask_lock);

if (IS_ERR(p)) {
/* CPU didn't die: tell everyone. Can't complain. */
if (blocking_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED,
Expand Down Expand Up @@ -187,7 +180,7 @@ int cpu_down(unsigned int cpu)
out_allowed:
set_cpus_allowed(current, old_allowed);
out:
unlock_cpu_hotplug();
mutex_unlock(&cpu_add_remove_lock);
return err;
}
#endif /*CONFIG_HOTPLUG_CPU*/
Expand All @@ -197,9 +190,7 @@ int __devinit cpu_up(unsigned int cpu)
int ret;
void *hcpu = (void *)(long)cpu;

if ((ret = lock_cpu_hotplug_interruptible()) != 0)
return ret;

mutex_lock(&cpu_add_remove_lock);
if (cpu_online(cpu) || !cpu_present(cpu)) {
ret = -EINVAL;
goto out;
Expand All @@ -214,7 +205,9 @@ int __devinit cpu_up(unsigned int cpu)
}

/* Arch-specific enabling code. */
mutex_lock(&cpu_bitmask_lock);
ret = __cpu_up(cpu);
mutex_unlock(&cpu_bitmask_lock);
if (ret != 0)
goto out_notify;
BUG_ON(!cpu_online(cpu));
Expand All @@ -227,6 +220,6 @@ int __devinit cpu_up(unsigned int cpu)
blocking_notifier_call_chain(&cpu_chain,
CPU_UP_CANCELED, hcpu);
out:
unlock_cpu_hotplug();
mutex_unlock(&cpu_add_remove_lock);
return ret;
}

0 comments on commit 050dc3a

Please sign in to comment.