Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 302789
b: refs/heads/master
c: 3bb5d2e
h: refs/heads/master
i:
  302787: adc3df5
v: v3
  • Loading branch information
Suresh Siddha authored and Thomas Gleixner committed May 3, 2012
1 parent da04509 commit 912c0ff
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 57 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: 9a1347237492f273f84ec39962b5806c70b2806a
refs/heads/master: 3bb5d2ee396aabaa4e318f17e94d13e2ee0e5a88
9 changes: 6 additions & 3 deletions trunk/kernel/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,18 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
int ret, nr_calls = 0;
void *hcpu = (void *)(long)cpu;
unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
struct task_struct *idle;

if (cpu_online(cpu) || !cpu_present(cpu))
return -EINVAL;

cpu_hotplug_begin();

ret = smpboot_prepare(cpu);
if (ret)
idle = idle_thread_get(cpu);
if (IS_ERR(idle)) {
ret = PTR_ERR(idle);
goto out;
}

ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls);
if (ret) {
Expand All @@ -316,7 +319,7 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
}

/* Arch-specific enabling code. */
ret = __cpu_up(cpu, idle_thread_get(cpu));
ret = __cpu_up(cpu, idle);
if (ret != 0)
goto out_notify;
BUG_ON(!cpu_online(cpu));
Expand Down
4 changes: 4 additions & 0 deletions trunk/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <linux/smp.h>
#include <linux/cpu.h>

#include "smpboot.h"

#ifdef CONFIG_USE_GENERIC_SMP_HELPERS
static struct {
struct list_head queue;
Expand Down Expand Up @@ -669,6 +671,8 @@ void __init smp_init(void)
{
unsigned int cpu;

idle_threads_init();

/* FIXME: This should be done in userspace --RR */
for_each_present_cpu(cpu) {
if (num_online_cpus() >= setup_max_cpus)
Expand Down
72 changes: 19 additions & 53 deletions trunk/kernel/smpboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,42 @@
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/percpu.h>
#include <linux/workqueue.h>

#include "smpboot.h"

#ifdef CONFIG_GENERIC_SMP_IDLE_THREAD
struct create_idle {
struct work_struct work;
struct task_struct *idle;
struct completion done;
unsigned int cpu;
};

static void __cpuinit do_fork_idle(struct work_struct *work)
{
struct create_idle *c = container_of(work, struct create_idle, work);

c->idle = fork_idle(c->cpu);
complete(&c->done);
}

static struct task_struct * __cpuinit idle_thread_create(unsigned int cpu)
{
struct create_idle c_idle = {
.cpu = cpu,
.done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
};

INIT_WORK_ONSTACK(&c_idle.work, do_fork_idle);
schedule_work(&c_idle.work);
wait_for_completion(&c_idle.done);
destroy_work_on_stack(&c_idle.work);
return c_idle.idle;
}

/*
* For the hotplug case we keep the task structs around and reuse
* them.
*/
static DEFINE_PER_CPU(struct task_struct *, idle_threads);

static inline struct task_struct *get_idle_for_cpu(unsigned int cpu)
struct task_struct * __cpuinit idle_thread_get(unsigned int cpu)
{
struct task_struct *tsk = per_cpu(idle_threads, cpu);

if (!tsk)
return idle_thread_create(cpu);
return ERR_PTR(-ENOMEM);
init_idle(tsk, cpu);
return tsk;
}

struct task_struct * __cpuinit idle_thread_get(unsigned int cpu)
void __init idle_thread_set_boot_cpu(void)
{
return per_cpu(idle_threads, cpu);
per_cpu(idle_threads, smp_processor_id()) = current;
}

void __init idle_thread_set_boot_cpu(void)
static inline void idle_init(unsigned int cpu)
{
per_cpu(idle_threads, smp_processor_id()) = current;
struct task_struct *tsk = per_cpu(idle_threads, cpu);

if (!tsk) {
tsk = fork_idle(cpu);
if (IS_ERR(tsk))
pr_err("SMP: fork_idle() failed for CPU %u\n", cpu);
else
per_cpu(idle_threads, cpu) = tsk;
}
}

/**
Expand All @@ -72,25 +50,13 @@ void __init idle_thread_set_boot_cpu(void)
*
* Creates the thread if it does not exist.
*/
static int __cpuinit idle_thread_init(unsigned int cpu)
void __init idle_threads_init(void)
{
struct task_struct *idle = get_idle_for_cpu(cpu);
unsigned int cpu;

if (IS_ERR(idle)) {
printk(KERN_ERR "failed fork for CPU %u\n", cpu);
return PTR_ERR(idle);
for_each_possible_cpu(cpu) {
if (cpu != smp_processor_id())
idle_init(cpu);
}
per_cpu(idle_threads, cpu) = idle;
return 0;
}
#else
static inline int idle_thread_init(unsigned int cpu) { return 0; }
#endif

/**
* smpboot_prepare - generic smpboot preparation
*/
int __cpuinit smpboot_prepare(unsigned int cpu)
{
return idle_thread_init(cpu);
}
2 changes: 2 additions & 0 deletions trunk/kernel/smpboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ int smpboot_prepare(unsigned int cpu);
#ifdef CONFIG_GENERIC_SMP_IDLE_THREAD
struct task_struct *idle_thread_get(unsigned int cpu);
void idle_thread_set_boot_cpu(void);
void idle_threads_init(void);
#else
static inline struct task_struct *idle_thread_get(unsigned int cpu) { return NULL; }
static inline void idle_thread_set_boot_cpu(void) { }
static inline void idle_threads_init(unsigned int cpu) { }
#endif

#endif

0 comments on commit 912c0ff

Please sign in to comment.