39c715b717
This patch implements a number of smp_processor_id() cleanup ideas that Arjan van de Ven and I came up with. The previous __smp_processor_id/_smp_processor_id/smp_processor_id API spaghetti was hard to follow both on the implementational and on the usage side. Some of the complexity arose from picking wrong names, some of the complexity comes from the fact that not all architectures defined __smp_processor_id. In the new code, there are two externally visible symbols: - smp_processor_id(): debug variant. - raw_smp_processor_id(): nondebug variant. Replaces all existing uses of _smp_processor_id() and __smp_processor_id(). Defined by every SMP architecture in include/asm-*/smp.h. There is one new internal symbol, dependent on DEBUG_PREEMPT: - debug_smp_processor_id(): internal debug variant, mapped to smp_processor_id(). Also, i moved debug_smp_processor_id() from lib/kernel_lock.c into a new lib/smp_processor_id.c file. All related comments got updated and/or clarified. I have build/boot tested the following 8 .config combinations on x86: {SMP,UP} x {PREEMPT,!PREEMPT} x {DEBUG_PREEMPT,!DEBUG_PREEMPT} I have also build/boot tested x64 on UP/PREEMPT/DEBUG_PREEMPT. (Other architectures are untested, but should work just fine.) Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Arjan van de Ven <arjan@infradead.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
86 lines
1.9 KiB
C
86 lines
1.9 KiB
C
/*
|
|
* drivers/power/smp.c - Functions for stopping other CPUs.
|
|
*
|
|
* Copyright 2004 Pavel Machek <pavel@suse.cz>
|
|
* Copyright (C) 2002-2003 Nigel Cunningham <ncunningham@clear.net.nz>
|
|
*
|
|
* This file is released under the GPLv2.
|
|
*/
|
|
|
|
#undef DEBUG
|
|
|
|
#include <linux/smp_lock.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/suspend.h>
|
|
#include <linux/module.h>
|
|
#include <asm/atomic.h>
|
|
#include <asm/tlbflush.h>
|
|
|
|
static atomic_t cpu_counter, freeze;
|
|
|
|
|
|
static void smp_pause(void * data)
|
|
{
|
|
struct saved_context ctxt;
|
|
__save_processor_state(&ctxt);
|
|
printk("Sleeping in:\n");
|
|
dump_stack();
|
|
atomic_inc(&cpu_counter);
|
|
while (atomic_read(&freeze)) {
|
|
/* FIXME: restore takes place at random piece inside this.
|
|
This should probably be written in assembly, and
|
|
preserve general-purpose registers, too
|
|
|
|
What about stack? We may need to move to new stack here.
|
|
|
|
This should better be ran with interrupts disabled.
|
|
*/
|
|
cpu_relax();
|
|
barrier();
|
|
}
|
|
atomic_dec(&cpu_counter);
|
|
__restore_processor_state(&ctxt);
|
|
}
|
|
|
|
static cpumask_t oldmask;
|
|
|
|
void disable_nonboot_cpus(void)
|
|
{
|
|
oldmask = current->cpus_allowed;
|
|
set_cpus_allowed(current, cpumask_of_cpu(0));
|
|
printk("Freezing CPUs (at %d)", raw_smp_processor_id());
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
schedule_timeout(HZ);
|
|
printk("...");
|
|
BUG_ON(raw_smp_processor_id() != 0);
|
|
|
|
/* FIXME: for this to work, all the CPUs must be running
|
|
* "idle" thread (or we deadlock). Is that guaranteed? */
|
|
|
|
atomic_set(&cpu_counter, 0);
|
|
atomic_set(&freeze, 1);
|
|
smp_call_function(smp_pause, NULL, 0, 0);
|
|
while (atomic_read(&cpu_counter) < (num_online_cpus() - 1)) {
|
|
cpu_relax();
|
|
barrier();
|
|
}
|
|
printk("ok\n");
|
|
}
|
|
|
|
void enable_nonboot_cpus(void)
|
|
{
|
|
printk("Restarting CPUs");
|
|
atomic_set(&freeze, 0);
|
|
while (atomic_read(&cpu_counter)) {
|
|
cpu_relax();
|
|
barrier();
|
|
}
|
|
printk("...");
|
|
set_cpus_allowed(current, oldmask);
|
|
schedule();
|
|
printk("ok\n");
|
|
|
|
}
|
|
|
|
|