Skip to content

Commit 860a0ff

Browse files
committed
stop_machine: Store task reference in a separate per cpu variable
To allow the stopper thread being managed by the smpboot thread infrastructure separate out the task storage from the stopper data structure. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com> Cc: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com> Cc: Arjan van de Veen <arjan@infradead.org> Cc: Paul Turner <pjt@google.com> Cc: Richard Weinberger <rw@linutronix.de> Cc: Magnus Damm <magnus.damm@gmail.com> Link: http://lkml.kernel.org/r/20130131120741.626690384@linutronix.de Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 7d7e499 commit 860a0ff

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

‎kernel/stop_machine.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ struct cpu_stopper {
3737
spinlock_t lock;
3838
bool enabled; /* is this stopper enabled? */
3939
struct list_head works; /* list of pending works */
40-
struct task_struct *thread; /* stopper thread */
4140
};
4241

4342
static DEFINE_PER_CPU(struct cpu_stopper, cpu_stopper);
43+
static DEFINE_PER_CPU(struct task_struct *, cpu_stopper_task);
4444
static bool stop_machine_initialized = false;
4545

4646
static void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo)
@@ -62,16 +62,18 @@ static void cpu_stop_signal_done(struct cpu_stop_done *done, bool executed)
6262
}
6363

6464
/* queue @work to @stopper. if offline, @work is completed immediately */
65-
static void cpu_stop_queue_work(struct cpu_stopper *stopper,
66-
struct cpu_stop_work *work)
65+
static void cpu_stop_queue_work(unsigned int cpu, struct cpu_stop_work *work)
6766
{
67+
struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
68+
struct task_struct *p = per_cpu(cpu_stopper_task, cpu);
69+
6870
unsigned long flags;
6971

7072
spin_lock_irqsave(&stopper->lock, flags);
7173

7274
if (stopper->enabled) {
7375
list_add_tail(&work->list, &stopper->works);
74-
wake_up_process(stopper->thread);
76+
wake_up_process(p);
7577
} else
7678
cpu_stop_signal_done(work->done, false);
7779

@@ -108,7 +110,7 @@ int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
108110
struct cpu_stop_work work = { .fn = fn, .arg = arg, .done = &done };
109111

110112
cpu_stop_init_done(&done, 1);
111-
cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu), &work);
113+
cpu_stop_queue_work(cpu, &work);
112114
wait_for_completion(&done.completion);
113115
return done.executed ? done.ret : -ENOENT;
114116
}
@@ -130,7 +132,7 @@ void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
130132
struct cpu_stop_work *work_buf)
131133
{
132134
*work_buf = (struct cpu_stop_work){ .fn = fn, .arg = arg, };
133-
cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu), work_buf);
135+
cpu_stop_queue_work(cpu, work_buf);
134136
}
135137

136138
/* static data for stop_cpus */
@@ -159,8 +161,7 @@ static void queue_stop_cpus_work(const struct cpumask *cpumask,
159161
*/
160162
preempt_disable();
161163
for_each_cpu(cpu, cpumask)
162-
cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu),
163-
&per_cpu(stop_cpus_work, cpu));
164+
cpu_stop_queue_work(cpu, &per_cpu(stop_cpus_work, cpu));
164165
preempt_enable();
165166
}
166167

@@ -304,12 +305,11 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
304305
{
305306
unsigned int cpu = (unsigned long)hcpu;
306307
struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
307-
struct task_struct *p;
308+
struct task_struct *p = per_cpu(cpu_stopper_task, cpu);
308309

309310
switch (action & ~CPU_TASKS_FROZEN) {
310311
case CPU_UP_PREPARE:
311-
BUG_ON(stopper->thread || stopper->enabled ||
312-
!list_empty(&stopper->works));
312+
BUG_ON(p || stopper->enabled || !list_empty(&stopper->works));
313313
p = kthread_create_on_node(cpu_stopper_thread,
314314
stopper,
315315
cpu_to_node(cpu),
@@ -319,12 +319,12 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
319319
get_task_struct(p);
320320
kthread_bind(p, cpu);
321321
sched_set_stop_task(cpu, p);
322-
stopper->thread = p;
322+
per_cpu(cpu_stopper_task, cpu) = p;
323323
break;
324324

325325
case CPU_ONLINE:
326326
/* strictly unnecessary, as first user will wake it */
327-
wake_up_process(stopper->thread);
327+
wake_up_process(p);
328328
/* mark enabled */
329329
spin_lock_irq(&stopper->lock);
330330
stopper->enabled = true;
@@ -339,16 +339,16 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
339339

340340
sched_set_stop_task(cpu, NULL);
341341
/* kill the stopper */
342-
kthread_stop(stopper->thread);
342+
kthread_stop(p);
343343
/* drain remaining works */
344344
spin_lock_irq(&stopper->lock);
345345
list_for_each_entry(work, &stopper->works, list)
346346
cpu_stop_signal_done(work->done, false);
347347
stopper->enabled = false;
348348
spin_unlock_irq(&stopper->lock);
349349
/* release the stopper */
350-
put_task_struct(stopper->thread);
351-
stopper->thread = NULL;
350+
put_task_struct(p);
351+
per_cpu(cpu_stopper_task, cpu) = NULL;
352352
break;
353353
}
354354
#endif

0 commit comments

Comments
 (0)