2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2012-03-11 15:59:26 +00:00
|
|
|
* SMP related functions
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2012-03-11 15:59:26 +00:00
|
|
|
* Copyright IBM Corp. 1999,2012
|
|
|
|
* Author(s): Denis Joseph Barrow,
|
|
|
|
* Martin Schwidefsky <schwidefsky@de.ibm.com>,
|
|
|
|
* Heiko Carstens <heiko.carstens@de.ibm.com>,
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2007-04-27 14:02:00 +00:00
|
|
|
* based on other smp stuff by
|
2005-04-16 22:20:36 +00:00
|
|
|
* (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net>
|
|
|
|
* (c) 1998 Ingo Molnar
|
|
|
|
*
|
2012-03-11 15:59:26 +00:00
|
|
|
* The code outside of smp.c uses logical cpu numbers, only smp.c does
|
|
|
|
* the translation of logical to physical cpu ids. All new code that
|
|
|
|
* operates on physical cpu numbers needs to go into smp.c.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-25 12:39:50 +00:00
|
|
|
#define KMSG_COMPONENT "cpu"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2011-01-05 11:48:08 +00:00
|
|
|
#include <linux/workqueue.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mm.h>
|
2007-07-29 22:36:13 +00:00
|
|
|
#include <linux/err.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
2009-03-26 14:23:56 +00:00
|
|
|
#include <linux/irqflags.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/cpu.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2011-10-30 14:16:40 +00:00
|
|
|
#include <linux/crash_dump.h>
|
2010-02-26 21:37:43 +00:00
|
|
|
#include <asm/asm-offsets.h>
|
2012-03-30 07:40:55 +00:00
|
|
|
#include <asm/switch_to.h>
|
|
|
|
#include <asm/facility.h>
|
2007-02-21 09:55:21 +00:00
|
|
|
#include <asm/ipl.h>
|
2007-02-05 20:16:47 +00:00
|
|
|
#include <asm/setup.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/tlbflush.h>
|
2007-02-05 20:16:47 +00:00
|
|
|
#include <asm/timer.h>
|
2007-04-27 14:01:49 +00:00
|
|
|
#include <asm/lowcore.h>
|
2008-01-26 13:10:56 +00:00
|
|
|
#include <asm/sclp.h>
|
2008-12-31 14:11:42 +00:00
|
|
|
#include <asm/vdso.h>
|
2012-03-11 15:59:32 +00:00
|
|
|
#include <asm/debug.h>
|
2012-03-11 15:59:34 +00:00
|
|
|
#include <asm/os_info.h>
|
2008-04-17 05:46:26 +00:00
|
|
|
#include "entry.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
enum {
|
|
|
|
sigp_sense = 1,
|
|
|
|
sigp_external_call = 2,
|
|
|
|
sigp_emergency_signal = 3,
|
|
|
|
sigp_start = 4,
|
|
|
|
sigp_stop = 5,
|
|
|
|
sigp_restart = 6,
|
|
|
|
sigp_stop_and_store_status = 9,
|
|
|
|
sigp_initial_cpu_reset = 11,
|
|
|
|
sigp_cpu_reset = 12,
|
|
|
|
sigp_set_prefix = 13,
|
|
|
|
sigp_store_status_at_address = 14,
|
|
|
|
sigp_store_extended_status_at_address = 15,
|
|
|
|
sigp_set_architecture = 18,
|
|
|
|
sigp_conditional_emergency_signal = 19,
|
|
|
|
sigp_sense_running = 21,
|
|
|
|
};
|
2010-01-13 19:44:37 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
enum {
|
|
|
|
sigp_order_code_accepted = 0,
|
|
|
|
sigp_status_stored = 1,
|
|
|
|
sigp_busy = 2,
|
|
|
|
sigp_not_operational = 3,
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
enum {
|
|
|
|
ec_schedule = 0,
|
|
|
|
ec_call_function,
|
|
|
|
ec_call_function_single,
|
|
|
|
ec_stop_cpu,
|
|
|
|
};
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
enum {
|
2008-01-26 13:10:56 +00:00
|
|
|
CPU_STATE_STANDBY,
|
|
|
|
CPU_STATE_CONFIGURED,
|
|
|
|
};
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
struct pcpu {
|
|
|
|
struct cpu cpu;
|
|
|
|
struct task_struct *idle; /* idle process for the cpu */
|
|
|
|
struct _lowcore *lowcore; /* lowcore page(s) for the cpu */
|
|
|
|
unsigned long async_stack; /* async stack for the cpu */
|
|
|
|
unsigned long panic_stack; /* panic stack for the cpu */
|
|
|
|
unsigned long ec_mask; /* bit mask for ec_xxx functions */
|
|
|
|
int state; /* physical cpu state */
|
|
|
|
u32 status; /* last status received via sigp */
|
|
|
|
u16 address; /* physical cpu address */
|
|
|
|
};
|
|
|
|
|
|
|
|
static u8 boot_cpu_type;
|
|
|
|
static u16 boot_cpu_address;
|
|
|
|
static struct pcpu pcpu_devices[NR_CPUS];
|
|
|
|
|
2008-04-17 05:46:12 +00:00
|
|
|
DEFINE_MUTEX(smp_cpu_state_mutex);
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
/*
|
|
|
|
* Signal processor helper functions.
|
|
|
|
*/
|
|
|
|
static inline int __pcpu_sigp(u16 addr, u8 order, u32 parm, u32 *status)
|
|
|
|
{
|
|
|
|
register unsigned int reg1 asm ("1") = parm;
|
|
|
|
int cc;
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
asm volatile(
|
|
|
|
" sigp %1,%2,0(%3)\n"
|
|
|
|
" ipm %0\n"
|
|
|
|
" srl %0,28\n"
|
|
|
|
: "=d" (cc), "+d" (reg1) : "d" (addr), "a" (order) : "cc");
|
|
|
|
if (status && cc == 1)
|
|
|
|
*status = reg1;
|
|
|
|
return cc;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
static inline int __pcpu_sigp_relax(u16 addr, u8 order, u32 parm, u32 *status)
|
2009-09-11 08:29:05 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
int cc;
|
2009-09-11 08:29:05 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
while (1) {
|
|
|
|
cc = __pcpu_sigp(addr, order, parm, status);
|
|
|
|
if (cc != sigp_busy)
|
|
|
|
return cc;
|
|
|
|
cpu_relax();
|
2009-09-11 08:29:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
static int pcpu_sigp_retry(struct pcpu *pcpu, u8 order, u32 parm)
|
2010-02-26 21:37:35 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
int cc, retry;
|
|
|
|
|
|
|
|
for (retry = 0; ; retry++) {
|
|
|
|
cc = __pcpu_sigp(pcpu->address, order, parm, &pcpu->status);
|
|
|
|
if (cc != sigp_busy)
|
|
|
|
break;
|
|
|
|
if (retry >= 3)
|
|
|
|
udelay(10);
|
|
|
|
}
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pcpu_stopped(struct pcpu *pcpu)
|
|
|
|
{
|
|
|
|
if (__pcpu_sigp(pcpu->address, sigp_sense,
|
|
|
|
0, &pcpu->status) != sigp_status_stored)
|
|
|
|
return 0;
|
|
|
|
/* Check for stopped and check stop state */
|
|
|
|
return !!(pcpu->status & 0x50);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pcpu_running(struct pcpu *pcpu)
|
2010-02-26 21:37:35 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
if (__pcpu_sigp(pcpu->address, sigp_sense_running,
|
|
|
|
0, &pcpu->status) != sigp_status_stored)
|
|
|
|
return 1;
|
|
|
|
/* Check for running status */
|
|
|
|
return !(pcpu->status & 0x400);
|
2010-02-26 21:37:35 +00:00
|
|
|
}
|
|
|
|
|
2011-10-30 14:16:38 +00:00
|
|
|
/*
|
2012-03-11 15:59:26 +00:00
|
|
|
* Find struct pcpu by cpu address.
|
2011-10-30 14:16:38 +00:00
|
|
|
*/
|
2012-03-11 15:59:26 +00:00
|
|
|
static struct pcpu *pcpu_find_address(const struct cpumask *mask, int address)
|
2011-10-30 14:16:38 +00:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
for_each_cpu(cpu, mask)
|
|
|
|
if (pcpu_devices[cpu].address == address)
|
|
|
|
return pcpu_devices + cpu;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcpu_ec_call(struct pcpu *pcpu, int ec_bit)
|
|
|
|
{
|
|
|
|
int order;
|
|
|
|
|
|
|
|
set_bit(ec_bit, &pcpu->ec_mask);
|
|
|
|
order = pcpu_running(pcpu) ?
|
|
|
|
sigp_external_call : sigp_emergency_signal;
|
|
|
|
pcpu_sigp_retry(pcpu, order, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __cpuinit pcpu_alloc_lowcore(struct pcpu *pcpu, int cpu)
|
|
|
|
{
|
|
|
|
struct _lowcore *lc;
|
|
|
|
|
|
|
|
if (pcpu != &pcpu_devices[0]) {
|
|
|
|
pcpu->lowcore = (struct _lowcore *)
|
|
|
|
__get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
|
|
|
|
pcpu->async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
|
|
|
|
pcpu->panic_stack = __get_free_page(GFP_KERNEL);
|
|
|
|
if (!pcpu->lowcore || !pcpu->panic_stack || !pcpu->async_stack)
|
|
|
|
goto out;
|
2011-10-30 14:16:38 +00:00
|
|
|
}
|
2012-03-11 15:59:26 +00:00
|
|
|
lc = pcpu->lowcore;
|
|
|
|
memcpy(lc, &S390_lowcore, 512);
|
|
|
|
memset((char *) lc + 512, 0, sizeof(*lc) - 512);
|
|
|
|
lc->async_stack = pcpu->async_stack + ASYNC_SIZE;
|
|
|
|
lc->panic_stack = pcpu->panic_stack + PAGE_SIZE;
|
|
|
|
lc->cpu_nr = cpu;
|
|
|
|
#ifndef CONFIG_64BIT
|
|
|
|
if (MACHINE_HAS_IEEE) {
|
|
|
|
lc->extended_save_area_addr = get_zeroed_page(GFP_KERNEL);
|
|
|
|
if (!lc->extended_save_area_addr)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (vdso_alloc_per_cpu(lc))
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
lowcore_ptr[cpu] = lc;
|
|
|
|
pcpu_sigp_retry(pcpu, sigp_set_prefix, (u32)(unsigned long) lc);
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
if (pcpu != &pcpu_devices[0]) {
|
|
|
|
free_page(pcpu->panic_stack);
|
|
|
|
free_pages(pcpu->async_stack, ASYNC_ORDER);
|
|
|
|
free_pages((unsigned long) pcpu->lowcore, LC_ORDER);
|
|
|
|
}
|
|
|
|
return -ENOMEM;
|
2011-10-30 14:16:38 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
static void pcpu_free_lowcore(struct pcpu *pcpu)
|
2010-02-26 21:37:34 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu_sigp_retry(pcpu, sigp_set_prefix, 0);
|
|
|
|
lowcore_ptr[pcpu - pcpu_devices] = NULL;
|
|
|
|
#ifndef CONFIG_64BIT
|
|
|
|
if (MACHINE_HAS_IEEE) {
|
|
|
|
struct _lowcore *lc = pcpu->lowcore;
|
|
|
|
|
|
|
|
free_page((unsigned long) lc->extended_save_area_addr);
|
|
|
|
lc->extended_save_area_addr = 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
vdso_free_per_cpu(pcpu->lowcore);
|
|
|
|
#endif
|
|
|
|
if (pcpu != &pcpu_devices[0]) {
|
|
|
|
free_page(pcpu->panic_stack);
|
|
|
|
free_pages(pcpu->async_stack, ASYNC_ORDER);
|
|
|
|
free_pages((unsigned long) pcpu->lowcore, LC_ORDER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcpu_prepare_secondary(struct pcpu *pcpu, int cpu)
|
|
|
|
{
|
|
|
|
struct _lowcore *lc = pcpu->lowcore;
|
|
|
|
|
|
|
|
atomic_inc(&init_mm.context.attach_count);
|
|
|
|
lc->cpu_nr = cpu;
|
|
|
|
lc->percpu_offset = __per_cpu_offset[cpu];
|
|
|
|
lc->kernel_asce = S390_lowcore.kernel_asce;
|
|
|
|
lc->machine_flags = S390_lowcore.machine_flags;
|
|
|
|
lc->ftrace_func = S390_lowcore.ftrace_func;
|
|
|
|
lc->user_timer = lc->system_timer = lc->steal_timer = 0;
|
|
|
|
__ctl_store(lc->cregs_save_area, 0, 15);
|
|
|
|
save_access_regs((unsigned int *) lc->access_regs_save_area);
|
|
|
|
memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
|
|
|
|
MAX_FACILITY_BIT/8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcpu_attach_task(struct pcpu *pcpu, struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
struct _lowcore *lc = pcpu->lowcore;
|
|
|
|
struct thread_info *ti = task_thread_info(tsk);
|
|
|
|
|
|
|
|
lc->kernel_stack = (unsigned long) task_stack_page(tsk) + THREAD_SIZE;
|
|
|
|
lc->thread_info = (unsigned long) task_thread_info(tsk);
|
|
|
|
lc->current_task = (unsigned long) tsk;
|
|
|
|
lc->user_timer = ti->user_timer;
|
|
|
|
lc->system_timer = ti->system_timer;
|
|
|
|
lc->steal_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcpu_start_fn(struct pcpu *pcpu, void (*func)(void *), void *data)
|
|
|
|
{
|
|
|
|
struct _lowcore *lc = pcpu->lowcore;
|
|
|
|
|
|
|
|
lc->restart_stack = lc->kernel_stack;
|
|
|
|
lc->restart_fn = (unsigned long) func;
|
|
|
|
lc->restart_data = (unsigned long) data;
|
|
|
|
lc->restart_source = -1UL;
|
|
|
|
pcpu_sigp_retry(pcpu, sigp_restart, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call function via PSW restart on pcpu and stop the current cpu.
|
|
|
|
*/
|
|
|
|
static void pcpu_delegate(struct pcpu *pcpu, void (*func)(void *),
|
|
|
|
void *data, unsigned long stack)
|
|
|
|
{
|
|
|
|
struct _lowcore *lc = pcpu->lowcore;
|
|
|
|
unsigned short this_cpu;
|
|
|
|
|
|
|
|
__load_psw_mask(psw_kernel_bits);
|
|
|
|
this_cpu = stap();
|
|
|
|
if (pcpu->address == this_cpu)
|
|
|
|
func(data); /* should not return */
|
|
|
|
/* Stop target cpu (if func returns this stops the current cpu). */
|
|
|
|
pcpu_sigp_retry(pcpu, sigp_stop, 0);
|
|
|
|
/* Restart func on the target cpu and stop the current cpu. */
|
|
|
|
lc->restart_stack = stack;
|
|
|
|
lc->restart_fn = (unsigned long) func;
|
|
|
|
lc->restart_data = (unsigned long) data;
|
|
|
|
lc->restart_source = (unsigned long) this_cpu;
|
|
|
|
asm volatile(
|
|
|
|
"0: sigp 0,%0,6 # sigp restart to target cpu\n"
|
|
|
|
" brc 2,0b # busy, try again\n"
|
|
|
|
"1: sigp 0,%1,5 # sigp stop to current cpu\n"
|
|
|
|
" brc 2,1b # busy, try again\n"
|
|
|
|
: : "d" (pcpu->address), "d" (this_cpu) : "0", "1", "cc");
|
|
|
|
for (;;) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call function on an online CPU.
|
|
|
|
*/
|
|
|
|
void smp_call_online_cpu(void (*func)(void *), void *data)
|
|
|
|
{
|
|
|
|
struct pcpu *pcpu;
|
|
|
|
|
|
|
|
/* Use the current cpu if it is online. */
|
|
|
|
pcpu = pcpu_find_address(cpu_online_mask, stap());
|
|
|
|
if (!pcpu)
|
|
|
|
/* Use the first online cpu. */
|
|
|
|
pcpu = pcpu_devices + cpumask_first(cpu_online_mask);
|
|
|
|
pcpu_delegate(pcpu, func, data, (unsigned long) restart_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call function on the ipl CPU.
|
|
|
|
*/
|
|
|
|
void smp_call_ipl_cpu(void (*func)(void *), void *data)
|
|
|
|
{
|
2012-03-13 15:25:08 +00:00
|
|
|
pcpu_delegate(&pcpu_devices[0], func, data,
|
|
|
|
pcpu_devices->panic_stack + PAGE_SIZE);
|
2012-03-11 15:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int smp_find_processor_id(u16 address)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for_each_present_cpu(cpu)
|
|
|
|
if (pcpu_devices[cpu].address == address)
|
|
|
|
return cpu;
|
|
|
|
return -1;
|
2010-02-26 21:37:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
int smp_vcpu_scheduled(int cpu)
|
2011-12-27 10:27:22 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
return pcpu_running(pcpu_devices + cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void smp_yield(void)
|
|
|
|
{
|
|
|
|
if (MACHINE_HAS_DIAG44)
|
|
|
|
asm volatile("diag 0,0,0x44");
|
2010-02-26 21:37:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
void smp_yield_cpu(int cpu)
|
2011-12-27 10:27:22 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
if (MACHINE_HAS_DIAG9C)
|
|
|
|
asm volatile("diag %0,0,0x9c"
|
|
|
|
: : "d" (pcpu_devices[cpu].address));
|
|
|
|
else if (MACHINE_HAS_DIAG44)
|
|
|
|
asm volatile("diag 0,0,0x44");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send cpus emergency shutdown signal. This gives the cpus the
|
|
|
|
* opportunity to complete outstanding interrupts.
|
|
|
|
*/
|
|
|
|
void smp_emergency_stop(cpumask_t *cpumask)
|
|
|
|
{
|
|
|
|
u64 end;
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
end = get_clock() + (1000000UL << 12);
|
|
|
|
for_each_cpu(cpu, cpumask) {
|
|
|
|
struct pcpu *pcpu = pcpu_devices + cpu;
|
|
|
|
set_bit(ec_stop_cpu, &pcpu->ec_mask);
|
|
|
|
while (__pcpu_sigp(pcpu->address, sigp_emergency_signal,
|
|
|
|
0, NULL) == sigp_busy &&
|
|
|
|
get_clock() < end)
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
while (get_clock() < end) {
|
|
|
|
for_each_cpu(cpu, cpumask)
|
|
|
|
if (pcpu_stopped(pcpu_devices + cpu))
|
|
|
|
cpumask_clear_cpu(cpu, cpumask);
|
|
|
|
if (cpumask_empty(cpumask))
|
|
|
|
break;
|
2011-12-27 10:27:22 +00:00
|
|
|
cpu_relax();
|
2012-03-11 15:59:26 +00:00
|
|
|
}
|
2011-12-27 10:27:22 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
/*
|
|
|
|
* Stop all cpus but the current one.
|
|
|
|
*/
|
2007-11-20 10:13:37 +00:00
|
|
|
void smp_send_stop(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-12-27 10:27:22 +00:00
|
|
|
cpumask_t cpumask;
|
|
|
|
int cpu;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-11-20 10:13:37 +00:00
|
|
|
/* Disable all interrupts/machine checks */
|
2011-10-30 14:16:50 +00:00
|
|
|
__load_psw_mask(psw_kernel_bits | PSW_MASK_DAT);
|
2009-03-26 14:23:56 +00:00
|
|
|
trace_hardirqs_off();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-11 15:59:32 +00:00
|
|
|
debug_set_critical();
|
2011-12-27 10:27:22 +00:00
|
|
|
cpumask_copy(&cpumask, cpu_online_mask);
|
|
|
|
cpumask_clear_cpu(smp_processor_id(), &cpumask);
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
if (oops_in_progress)
|
|
|
|
smp_emergency_stop(&cpumask);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-12-27 10:27:22 +00:00
|
|
|
/* stop all processors */
|
|
|
|
for_each_cpu(cpu, &cpumask) {
|
2012-03-11 15:59:26 +00:00
|
|
|
struct pcpu *pcpu = pcpu_devices + cpu;
|
|
|
|
pcpu_sigp_retry(pcpu, sigp_stop, 0);
|
|
|
|
while (!pcpu_stopped(pcpu))
|
2006-12-04 14:40:33 +00:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
/*
|
|
|
|
* Stop the current cpu.
|
|
|
|
*/
|
|
|
|
void smp_stop_cpu(void)
|
|
|
|
{
|
|
|
|
pcpu_sigp_retry(pcpu_devices + smp_processor_id(), sigp_stop, 0);
|
|
|
|
for (;;) ;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* This is the main routine where commands issued by other
|
|
|
|
* cpus are handled.
|
|
|
|
*/
|
2012-03-11 15:59:31 +00:00
|
|
|
static void do_ext_call_interrupt(struct ext_code ext_code,
|
2010-10-25 14:10:38 +00:00
|
|
|
unsigned int param32, unsigned long param64)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-04-27 14:02:00 +00:00
|
|
|
unsigned long bits;
|
2012-03-11 15:59:26 +00:00
|
|
|
int cpu;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
cpu = smp_processor_id();
|
2012-03-11 15:59:31 +00:00
|
|
|
if (ext_code.code == 0x1202)
|
2012-03-11 15:59:26 +00:00
|
|
|
kstat_cpu(cpu).irqs[EXTINT_EXC]++;
|
2011-10-30 14:17:19 +00:00
|
|
|
else
|
2012-03-11 15:59:26 +00:00
|
|
|
kstat_cpu(cpu).irqs[EXTINT_EMS]++;
|
2007-04-27 14:02:00 +00:00
|
|
|
/*
|
|
|
|
* handle bit signal external calls
|
|
|
|
*/
|
2012-03-11 15:59:26 +00:00
|
|
|
bits = xchg(&pcpu_devices[cpu].ec_mask, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-12-27 10:27:22 +00:00
|
|
|
if (test_bit(ec_stop_cpu, &bits))
|
|
|
|
smp_stop_cpu();
|
|
|
|
|
2011-04-05 15:23:39 +00:00
|
|
|
if (test_bit(ec_schedule, &bits))
|
|
|
|
scheduler_ipi();
|
|
|
|
|
2007-04-27 14:02:00 +00:00
|
|
|
if (test_bit(ec_call_function, &bits))
|
2008-12-25 12:38:39 +00:00
|
|
|
generic_smp_call_function_interrupt();
|
|
|
|
|
|
|
|
if (test_bit(ec_call_function_single, &bits))
|
|
|
|
generic_smp_call_function_single_interrupt();
|
2011-12-27 10:27:22 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-24 15:34:45 +00:00
|
|
|
void arch_send_call_function_ipi_mask(const struct cpumask *mask)
|
2008-12-25 12:38:39 +00:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
2009-09-24 15:34:45 +00:00
|
|
|
for_each_cpu(cpu, mask)
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu_ec_call(pcpu_devices + cpu, ec_call_function);
|
2008-12-25 12:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void arch_send_call_function_single_ipi(int cpu)
|
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu_ec_call(pcpu_devices + cpu, ec_call_function_single);
|
2008-12-25 12:38:39 +00:00
|
|
|
}
|
|
|
|
|
2006-01-06 08:19:28 +00:00
|
|
|
#ifndef CONFIG_64BIT
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* this function sends a 'purge tlb' signal to another CPU.
|
|
|
|
*/
|
2008-04-17 05:46:26 +00:00
|
|
|
static void smp_ptlb_callback(void *info)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
[S390] tlb flush fix.
The current tlb flushing code for page table entries violates the
s390 architecture in a small detail. The relevant section from the
principles of operation (SA22-7832-02 page 3-47):
"A valid table entry must not be changed while it is attached
to any CPU and may be used for translation by that CPU except to
(1) invalidate the entry by using INVALIDATE PAGE TABLE ENTRY or
INVALIDATE DAT TABLE ENTRY, (2) alter bits 56-63 of a page-table
entry, or (3) make a change by means of a COMPARE AND SWAP AND
PURGE instruction that purges the TLB."
That means if one thread of a multithreaded applciation uses a vma
while another thread does an unmap on it, the page table entries of
that vma needs to get removed with IPTE, IDTE or CSP. In some strange
and rare situations a cpu could check-stop (die) because a entry has
been pushed out of the TLB that is still needed to complete a
(milli-coded) instruction. I've never seen it happen with the current
code on any of the supported machines, so right now this is a
theoretical problem. But I want to fix it nevertheless, to avoid
headaches in the futures.
To get this implemented correctly without changing common code the
primitives ptep_get_and_clear, ptep_get_and_clear_full and
ptep_set_wrprotect need to use the IPTE instruction to invalidate the
pte before the new pte value gets stored. If IPTE is always used for
the three primitives three important operations will have a performace
hit: fork, mprotect and exit_mmap. Time for some workarounds:
* 1: ptep_get_and_clear_full is used in unmap_vmas to remove page
tables entries in a batched tlb gather operation. If the mmu_gather
context passed to unmap_vmas has been started with full_mm_flush==1
or if only one cpu is online or if the only user of a mm_struct is the
current process then the fullmm indication in the mmu_gather context is
set to one. All TLBs for mm_struct are flushed by the tlb_gather_mmu
call. No new TLBs can be created while the unmap is in progress. In
this case ptep_get_and_clear_full clears the ptes with a simple store.
* 2: ptep_get_and_clear is used in change_protection to clear the
ptes from the page tables before they are reentered with the new
access flags. At the end of the update flush_tlb_range clears the
remaining TLBs. In general the ptep_get_and_clear has to issue IPTE
for each pte and flush_tlb_range is a nop. But if there is only one
user of the mm_struct then ptep_get_and_clear uses simple stores
to do the update and flush_tlb_range will flush the TLBs.
* 3: Similar to 2, ptep_set_wrprotect is used in copy_page_range
for a fork to make all ptes of a cow mapping read-only. At the end of
of copy_page_range dup_mmap will flush the TLBs with a call to
flush_tlb_mm. Check for mm->mm_users and if there is only one user
avoid using IPTE in ptep_set_wrprotect and let flush_tlb_mm clear the
TLBs.
Overall for single threaded programs the tlb flush code now performs
better, for multi threaded programs it is slightly worse. In particular
exit_mmap() now does a single IDTE for the mm and then just frees every
page cache reference and every page table page directly without a delay
over the mmu_gather structure.
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2007-10-22 10:52:44 +00:00
|
|
|
__tlb_flush_local();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void smp_ptlb_all(void)
|
|
|
|
{
|
2008-05-09 07:39:44 +00:00
|
|
|
on_each_cpu(smp_ptlb_callback, NULL, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(smp_ptlb_all);
|
2006-01-06 08:19:28 +00:00
|
|
|
#endif /* ! CONFIG_64BIT */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* this function sends a 'reschedule' IPI to another CPU.
|
|
|
|
* it goes straight through and wastes no time serializing
|
|
|
|
* anything. Worst case is that we lose a reschedule ...
|
|
|
|
*/
|
|
|
|
void smp_send_reschedule(int cpu)
|
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu_ec_call(pcpu_devices + cpu, ec_schedule);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parameter area for the set/clear control bit callbacks
|
|
|
|
*/
|
2006-09-28 14:56:43 +00:00
|
|
|
struct ec_creg_mask_parms {
|
2012-03-11 15:59:26 +00:00
|
|
|
unsigned long orval;
|
|
|
|
unsigned long andval;
|
|
|
|
int cr;
|
2006-09-28 14:56:43 +00:00
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* callback for setting/clearing control bits
|
|
|
|
*/
|
2007-04-27 14:02:00 +00:00
|
|
|
static void smp_ctl_bit_callback(void *info)
|
|
|
|
{
|
2006-09-28 14:56:43 +00:00
|
|
|
struct ec_creg_mask_parms *pp = info;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long cregs[16];
|
2007-04-27 14:02:00 +00:00
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
__ctl_store(cregs, 0, 15);
|
2012-03-11 15:59:26 +00:00
|
|
|
cregs[pp->cr] = (cregs[pp->cr] & pp->andval) | pp->orval;
|
2006-09-28 14:56:43 +00:00
|
|
|
__ctl_load(cregs, 0, 15);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a bit in a control register of all cpus
|
|
|
|
*/
|
2006-09-28 14:56:43 +00:00
|
|
|
void smp_ctl_set_bit(int cr, int bit)
|
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct ec_creg_mask_parms parms = { 1UL << bit, -1UL, cr };
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-05-09 07:39:44 +00:00
|
|
|
on_each_cpu(smp_ctl_bit_callback, &parms, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-04-27 14:02:00 +00:00
|
|
|
EXPORT_SYMBOL(smp_ctl_set_bit);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear a bit in a control register of all cpus
|
|
|
|
*/
|
2006-09-28 14:56:43 +00:00
|
|
|
void smp_ctl_clear_bit(int cr, int bit)
|
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct ec_creg_mask_parms parms = { 0, ~(1UL << bit), cr };
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-05-09 07:39:44 +00:00
|
|
|
on_each_cpu(smp_ctl_bit_callback, &parms, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-04-27 14:02:00 +00:00
|
|
|
EXPORT_SYMBOL(smp_ctl_clear_bit);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-10-30 14:16:40 +00:00
|
|
|
#if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_CRASH_DUMP)
|
2007-04-27 14:01:49 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
struct save_area *zfcpdump_save_areas[NR_CPUS + 1];
|
|
|
|
EXPORT_SYMBOL_GPL(zfcpdump_save_areas);
|
|
|
|
|
|
|
|
static void __init smp_get_save_area(int cpu, u16 address)
|
2007-04-27 14:01:49 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
void *lc = pcpu_devices[0].lowcore;
|
|
|
|
struct save_area *save_area;
|
|
|
|
|
2011-10-30 14:16:40 +00:00
|
|
|
if (is_kdump_kernel())
|
2007-04-27 14:01:49 +00:00
|
|
|
return;
|
2012-03-11 15:59:26 +00:00
|
|
|
if (!OLDMEM_BASE && (address == boot_cpu_address ||
|
|
|
|
ipl_info.type != IPL_TYPE_FCP_DUMP))
|
|
|
|
return;
|
2007-07-10 09:24:13 +00:00
|
|
|
if (cpu >= NR_CPUS) {
|
2012-03-11 15:59:26 +00:00
|
|
|
pr_warning("CPU %i exceeds the maximum %i and is excluded "
|
|
|
|
"from the dump\n", cpu, NR_CPUS - 1);
|
2007-07-10 09:24:13 +00:00
|
|
|
return;
|
2007-04-27 14:01:49 +00:00
|
|
|
}
|
2012-03-11 15:59:26 +00:00
|
|
|
save_area = kmalloc(sizeof(struct save_area), GFP_KERNEL);
|
|
|
|
if (!save_area)
|
|
|
|
panic("could not allocate memory for save area\n");
|
|
|
|
zfcpdump_save_areas[cpu] = save_area;
|
|
|
|
#ifdef CONFIG_CRASH_DUMP
|
|
|
|
if (address == boot_cpu_address) {
|
|
|
|
/* Copy the registers of the boot cpu. */
|
|
|
|
copy_oldmem_page(1, (void *) save_area, sizeof(*save_area),
|
|
|
|
SAVE_AREA_BASE - PAGE_SIZE, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Get the registers of a non-boot cpu. */
|
|
|
|
__pcpu_sigp_relax(address, sigp_stop_and_store_status, 0, NULL);
|
|
|
|
memcpy_real(save_area, lc + SAVE_AREA_BASE, sizeof(*save_area));
|
2007-04-27 14:01:49 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
int smp_store_status(int cpu)
|
2008-01-26 13:10:56 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct pcpu *pcpu;
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu = pcpu_devices + cpu;
|
|
|
|
if (__pcpu_sigp_relax(pcpu->address, sigp_stop_and_store_status,
|
|
|
|
0, NULL) != sigp_order_code_accepted)
|
|
|
|
return -EIO;
|
2008-01-26 13:10:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
#else /* CONFIG_ZFCPDUMP || CONFIG_CRASH_DUMP */
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
static inline void smp_get_save_area(int cpu, u16 address) { }
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
#endif /* CONFIG_ZFCPDUMP || CONFIG_CRASH_DUMP */
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
static struct sclp_cpu_info *smp_get_cpu_info(void)
|
2008-01-26 13:10:56 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
static int use_sigp_detection;
|
2008-01-26 13:10:56 +00:00
|
|
|
struct sclp_cpu_info *info;
|
2012-03-11 15:59:26 +00:00
|
|
|
int address;
|
|
|
|
|
|
|
|
info = kzalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (info && (use_sigp_detection || sclp_get_cpu_info(info))) {
|
|
|
|
use_sigp_detection = 1;
|
|
|
|
for (address = 0; address <= MAX_CPU_ADDRESS; address++) {
|
|
|
|
if (__pcpu_sigp_relax(address, sigp_sense, 0, NULL) ==
|
|
|
|
sigp_not_operational)
|
|
|
|
continue;
|
|
|
|
info->cpu[info->configured].address = address;
|
|
|
|
info->configured++;
|
|
|
|
}
|
|
|
|
info->combined = info->configured;
|
2008-01-26 13:10:56 +00:00
|
|
|
}
|
2012-03-11 15:59:26 +00:00
|
|
|
return info;
|
2008-01-26 13:10:56 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
static int __devinit smp_add_present_cpu(int cpu);
|
|
|
|
|
|
|
|
static int __devinit __smp_rescan_cpus(struct sclp_cpu_info *info,
|
|
|
|
int sysfs_add)
|
2008-01-26 13:10:56 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct pcpu *pcpu;
|
2008-01-26 13:10:56 +00:00
|
|
|
cpumask_t avail;
|
2012-03-11 15:59:26 +00:00
|
|
|
int cpu, nr, i;
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
nr = 0;
|
2011-05-23 08:24:36 +00:00
|
|
|
cpumask_xor(&avail, cpu_possible_mask, cpu_present_mask);
|
2012-03-11 15:59:26 +00:00
|
|
|
cpu = cpumask_first(&avail);
|
|
|
|
for (i = 0; (i < info->combined) && (cpu < nr_cpu_ids); i++) {
|
|
|
|
if (info->has_cpu_type && info->cpu[i].type != boot_cpu_type)
|
|
|
|
continue;
|
|
|
|
if (pcpu_find_address(cpu_present_mask, info->cpu[i].address))
|
|
|
|
continue;
|
|
|
|
pcpu = pcpu_devices + cpu;
|
|
|
|
pcpu->address = info->cpu[i].address;
|
|
|
|
pcpu->state = (cpu >= info->configured) ?
|
|
|
|
CPU_STATE_STANDBY : CPU_STATE_CONFIGURED;
|
|
|
|
cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
|
|
|
|
set_cpu_present(cpu, true);
|
|
|
|
if (sysfs_add && smp_add_present_cpu(cpu) != 0)
|
|
|
|
set_cpu_present(cpu, false);
|
|
|
|
else
|
|
|
|
nr++;
|
|
|
|
cpu = cpumask_next(cpu, &avail);
|
|
|
|
}
|
|
|
|
return nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-26 13:11:05 +00:00
|
|
|
static void __init smp_detect_cpus(void)
|
|
|
|
{
|
|
|
|
unsigned int cpu, c_cpus, s_cpus;
|
|
|
|
struct sclp_cpu_info *info;
|
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
info = smp_get_cpu_info();
|
2008-01-26 13:11:05 +00:00
|
|
|
if (!info)
|
|
|
|
panic("smp_detect_cpus failed to allocate memory\n");
|
|
|
|
if (info->has_cpu_type) {
|
|
|
|
for (cpu = 0; cpu < info->combined; cpu++) {
|
2012-03-11 15:59:26 +00:00
|
|
|
if (info->cpu[cpu].address != boot_cpu_address)
|
|
|
|
continue;
|
|
|
|
/* The boot cpu dictates the cpu type. */
|
|
|
|
boot_cpu_type = info->cpu[cpu].type;
|
|
|
|
break;
|
2008-01-26 13:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-11 15:59:26 +00:00
|
|
|
c_cpus = s_cpus = 0;
|
2008-01-26 13:11:05 +00:00
|
|
|
for (cpu = 0; cpu < info->combined; cpu++) {
|
2012-03-11 15:59:26 +00:00
|
|
|
if (info->has_cpu_type && info->cpu[cpu].type != boot_cpu_type)
|
2008-01-26 13:11:05 +00:00
|
|
|
continue;
|
2012-03-11 15:59:26 +00:00
|
|
|
if (cpu < info->configured) {
|
|
|
|
smp_get_save_area(c_cpus, info->cpu[cpu].address);
|
|
|
|
c_cpus++;
|
|
|
|
} else
|
2008-01-26 13:11:05 +00:00
|
|
|
s_cpus++;
|
|
|
|
}
|
2008-12-25 12:39:50 +00:00
|
|
|
pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus, s_cpus);
|
2008-01-26 13:11:31 +00:00
|
|
|
get_online_cpus();
|
2012-03-11 15:59:26 +00:00
|
|
|
__smp_rescan_cpus(info, 0);
|
2008-01-26 13:11:31 +00:00
|
|
|
put_online_cpus();
|
2012-03-11 15:59:26 +00:00
|
|
|
kfree(info);
|
2008-01-26 13:11:05 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2007-04-27 14:02:00 +00:00
|
|
|
* Activate a secondary processor.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2012-03-11 15:59:26 +00:00
|
|
|
static void __cpuinit smp_start_secondary(void *cpuvoid)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
S390_lowcore.last_update_clock = get_clock();
|
|
|
|
S390_lowcore.restart_stack = (unsigned long) restart_stack;
|
|
|
|
S390_lowcore.restart_fn = (unsigned long) do_restart;
|
|
|
|
S390_lowcore.restart_data = 0;
|
|
|
|
S390_lowcore.restart_source = -1UL;
|
|
|
|
restore_access_regs(S390_lowcore.access_regs_save_area);
|
|
|
|
__ctl_load(S390_lowcore.cregs_save_area, 0, 15);
|
|
|
|
__load_psw_mask(psw_kernel_bits | PSW_MASK_DAT);
|
2007-04-27 14:02:00 +00:00
|
|
|
cpu_init();
|
2005-11-09 05:39:01 +00:00
|
|
|
preempt_disable();
|
2007-04-27 14:02:00 +00:00
|
|
|
init_cpu_timer();
|
|
|
|
init_cpu_vtimer();
|
2006-12-04 14:40:40 +00:00
|
|
|
pfault_init();
|
2008-09-07 14:57:22 +00:00
|
|
|
notify_cpu_starting(smp_processor_id());
|
2008-12-25 12:38:39 +00:00
|
|
|
ipi_call_lock();
|
2011-05-23 08:24:36 +00:00
|
|
|
set_cpu_online(smp_processor_id(), true);
|
2008-12-25 12:38:39 +00:00
|
|
|
ipi_call_unlock();
|
2005-04-16 22:20:36 +00:00
|
|
|
local_irq_enable();
|
2007-04-27 14:02:00 +00:00
|
|
|
/* cpu_idle will call schedule for us */
|
|
|
|
cpu_idle();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2011-01-05 11:48:08 +00:00
|
|
|
struct create_idle {
|
|
|
|
struct work_struct work;
|
|
|
|
struct task_struct *idle;
|
|
|
|
struct completion done;
|
|
|
|
int cpu;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __cpuinit smp_fork_idle(struct work_struct *work)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-01-05 11:48:08 +00:00
|
|
|
struct create_idle *c_idle;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-01-05 11:48:08 +00:00
|
|
|
c_idle = container_of(work, struct create_idle, work);
|
|
|
|
c_idle->idle = fork_idle(c_idle->cpu);
|
|
|
|
complete(&c_idle->done);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Upping and downing of CPUs */
|
2008-01-26 13:11:14 +00:00
|
|
|
int __cpuinit __cpu_up(unsigned int cpu)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-01-05 11:48:08 +00:00
|
|
|
struct create_idle c_idle;
|
2012-03-11 15:59:26 +00:00
|
|
|
struct pcpu *pcpu;
|
|
|
|
int rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu = pcpu_devices + cpu;
|
|
|
|
if (pcpu->state != CPU_STATE_CONFIGURED)
|
2008-01-26 13:10:56 +00:00
|
|
|
return -EIO;
|
2012-03-11 15:59:26 +00:00
|
|
|
if (pcpu_sigp_retry(pcpu, sigp_initial_cpu_reset, 0) !=
|
|
|
|
sigp_order_code_accepted)
|
2008-01-26 13:10:56 +00:00
|
|
|
return -EIO;
|
2012-03-11 15:59:26 +00:00
|
|
|
if (!pcpu->idle) {
|
2011-01-05 11:48:08 +00:00
|
|
|
c_idle.done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done);
|
|
|
|
INIT_WORK_ONSTACK(&c_idle.work, smp_fork_idle);
|
|
|
|
c_idle.cpu = cpu;
|
|
|
|
schedule_work(&c_idle.work);
|
|
|
|
wait_for_completion(&c_idle.done);
|
|
|
|
if (IS_ERR(c_idle.idle))
|
|
|
|
return PTR_ERR(c_idle.idle);
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu->idle = c_idle.idle;
|
2011-01-05 11:48:08 +00:00
|
|
|
}
|
2012-03-11 15:59:26 +00:00
|
|
|
init_idle(pcpu->idle, cpu);
|
|
|
|
rc = pcpu_alloc_lowcore(pcpu, cpu);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
pcpu_prepare_secondary(pcpu, cpu);
|
|
|
|
pcpu_attach_task(pcpu, pcpu->idle);
|
|
|
|
pcpu_start_fn(pcpu, smp_start_secondary, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
while (!cpu_online(cpu))
|
|
|
|
cpu_relax();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-26 13:11:05 +00:00
|
|
|
static int __init setup_possible_cpus(char *s)
|
2006-02-17 21:52:46 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
int max, cpu;
|
2006-02-17 21:52:46 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
if (kstrtoint(s, 0, &max) < 0)
|
|
|
|
return 0;
|
2009-04-14 13:36:25 +00:00
|
|
|
init_cpu_possible(cpumask_of(0));
|
2012-03-11 15:59:26 +00:00
|
|
|
for (cpu = 1; cpu < max && cpu < nr_cpu_ids; cpu++)
|
2009-03-26 14:25:00 +00:00
|
|
|
set_cpu_possible(cpu, true);
|
2006-02-17 21:52:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("possible_cpus", setup_possible_cpus);
|
|
|
|
|
2008-01-26 13:11:05 +00:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
|
2007-04-27 14:02:00 +00:00
|
|
|
int __cpu_disable(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
unsigned long cregs[16];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
set_cpu_online(smp_processor_id(), false);
|
|
|
|
/* Disable pseudo page faults on this cpu. */
|
2006-12-04 14:40:40 +00:00
|
|
|
pfault_fini();
|
2012-03-11 15:59:26 +00:00
|
|
|
/* Disable interrupt sources via control register. */
|
|
|
|
__ctl_store(cregs, 0, 15);
|
|
|
|
cregs[0] &= ~0x0000ee70UL; /* disable all external interrupts */
|
|
|
|
cregs[6] &= ~0xff000000UL; /* disable all I/O interrupts */
|
|
|
|
cregs[14] &= ~0x1f000000UL; /* disable most machine checks */
|
|
|
|
__ctl_load(cregs, 0, 15);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-27 14:02:00 +00:00
|
|
|
void __cpu_die(unsigned int cpu)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct pcpu *pcpu;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Wait until target cpu is down */
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu = pcpu_devices + cpu;
|
|
|
|
while (!pcpu_stopped(pcpu))
|
2005-04-16 22:20:36 +00:00
|
|
|
cpu_relax();
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu_free_lowcore(pcpu);
|
2010-08-24 07:26:21 +00:00
|
|
|
atomic_dec(&init_mm.context.attach_count);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 08:24:33 +00:00
|
|
|
void __noreturn cpu_die(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
idle_task_exit();
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu_sigp_retry(pcpu_devices + smp_processor_id(), sigp_stop, 0);
|
|
|
|
for (;;) ;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-02-17 21:52:46 +00:00
|
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
|
|
|
|
2012-03-11 15:59:34 +00:00
|
|
|
static void smp_call_os_info_init_fn(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-03-11 15:59:34 +00:00
|
|
|
int (*init_fn)(void);
|
|
|
|
unsigned long size;
|
2007-04-27 14:02:00 +00:00
|
|
|
|
2012-03-11 15:59:34 +00:00
|
|
|
init_fn = os_info_old_entry(OS_INFO_INIT_FN, &size);
|
|
|
|
if (!init_fn)
|
|
|
|
return;
|
|
|
|
init_fn();
|
|
|
|
}
|
2008-01-26 13:11:05 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
void __init smp_prepare_cpus(unsigned int max_cpus)
|
|
|
|
{
|
2007-04-27 14:02:00 +00:00
|
|
|
/* request the 0x1201 emergency signal external interrupt */
|
|
|
|
if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
|
|
|
|
panic("Couldn't request external interrupt 0x1201");
|
2011-10-30 14:16:58 +00:00
|
|
|
/* request the 0x1202 external call external interrupt */
|
|
|
|
if (register_external_interrupt(0x1202, do_ext_call_interrupt) != 0)
|
|
|
|
panic("Couldn't request external interrupt 0x1202");
|
2012-03-11 15:59:34 +00:00
|
|
|
smp_call_os_info_init_fn();
|
2012-03-11 15:59:26 +00:00
|
|
|
smp_detect_cpus();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 15:38:05 +00:00
|
|
|
void __init smp_prepare_boot_cpu(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct pcpu *pcpu = pcpu_devices;
|
|
|
|
|
|
|
|
boot_cpu_address = stap();
|
|
|
|
pcpu->idle = current;
|
|
|
|
pcpu->state = CPU_STATE_CONFIGURED;
|
|
|
|
pcpu->address = boot_cpu_address;
|
|
|
|
pcpu->lowcore = (struct _lowcore *)(unsigned long) store_prefix();
|
|
|
|
pcpu->async_stack = S390_lowcore.async_stack - ASYNC_SIZE;
|
|
|
|
pcpu->panic_stack = S390_lowcore.panic_stack - PAGE_SIZE;
|
2005-04-16 22:20:36 +00:00
|
|
|
S390_lowcore.percpu_offset = __per_cpu_offset[0];
|
2011-12-27 10:27:09 +00:00
|
|
|
cpu_set_polarization(0, POLARIZATION_UNKNOWN);
|
2012-03-11 15:59:26 +00:00
|
|
|
set_cpu_present(0, true);
|
|
|
|
set_cpu_online(0, true);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 15:38:05 +00:00
|
|
|
void __init smp_cpus_done(unsigned int max_cpus)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-13 19:44:34 +00:00
|
|
|
void __init smp_setup_processor_id(void)
|
|
|
|
{
|
|
|
|
S390_lowcore.cpu_nr = 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* the frequency of the profiling timer can be changed
|
|
|
|
* by writing a multiplier value into /proc/profile.
|
|
|
|
*
|
|
|
|
* usually you want to run this on all CPUs ;)
|
|
|
|
*/
|
|
|
|
int setup_profiling_timer(unsigned int multiplier)
|
|
|
|
{
|
2007-04-27 14:02:00 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-26 13:10:56 +00:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
2011-12-21 22:29:42 +00:00
|
|
|
static ssize_t cpu_configure_show(struct device *dev,
|
2012-03-11 15:59:26 +00:00
|
|
|
struct device_attribute *attr, char *buf)
|
2008-01-26 13:10:56 +00:00
|
|
|
{
|
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2012-03-11 15:59:26 +00:00
|
|
|
count = sprintf(buf, "%d\n", pcpu_devices[dev->id].state);
|
2008-01-26 13:10:56 +00:00
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-12-21 22:29:42 +00:00
|
|
|
static ssize_t cpu_configure_store(struct device *dev,
|
2012-03-11 15:59:26 +00:00
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2008-01-26 13:10:56 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct pcpu *pcpu;
|
|
|
|
int cpu, val, rc;
|
2008-01-26 13:10:56 +00:00
|
|
|
char delim;
|
|
|
|
|
|
|
|
if (sscanf(buf, "%d %c", &val, &delim) != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
if (val != 0 && val != 1)
|
|
|
|
return -EINVAL;
|
2008-01-26 13:11:31 +00:00
|
|
|
get_online_cpus();
|
2008-04-30 11:38:36 +00:00
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2008-01-26 13:10:56 +00:00
|
|
|
rc = -EBUSY;
|
2010-02-26 21:37:34 +00:00
|
|
|
/* disallow configuration changes of online cpus and cpu 0 */
|
2012-03-11 15:59:26 +00:00
|
|
|
cpu = dev->id;
|
2010-02-26 21:37:34 +00:00
|
|
|
if (cpu_online(cpu) || cpu == 0)
|
2008-01-26 13:10:56 +00:00
|
|
|
goto out;
|
2012-03-11 15:59:26 +00:00
|
|
|
pcpu = pcpu_devices + cpu;
|
2008-01-26 13:10:56 +00:00
|
|
|
rc = 0;
|
|
|
|
switch (val) {
|
|
|
|
case 0:
|
2012-03-11 15:59:26 +00:00
|
|
|
if (pcpu->state != CPU_STATE_CONFIGURED)
|
|
|
|
break;
|
|
|
|
rc = sclp_cpu_deconfigure(pcpu->address);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
pcpu->state = CPU_STATE_STANDBY;
|
|
|
|
cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
|
|
|
|
topology_expect_change();
|
2008-01-26 13:10:56 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-03-11 15:59:26 +00:00
|
|
|
if (pcpu->state != CPU_STATE_STANDBY)
|
|
|
|
break;
|
|
|
|
rc = sclp_cpu_configure(pcpu->address);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
pcpu->state = CPU_STATE_CONFIGURED;
|
|
|
|
cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
|
|
|
|
topology_expect_change();
|
2008-01-26 13:10:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
2008-04-30 11:38:36 +00:00
|
|
|
put_online_cpus();
|
2008-01-26 13:10:56 +00:00
|
|
|
return rc ? rc : count;
|
|
|
|
}
|
2011-12-21 22:29:42 +00:00
|
|
|
static DEVICE_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
|
2008-01-26 13:10:56 +00:00
|
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
|
|
|
|
2011-12-21 22:29:42 +00:00
|
|
|
static ssize_t show_cpu_address(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2008-01-26 13:10:56 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
return sprintf(buf, "%d\n", pcpu_devices[dev->id].address);
|
2008-01-26 13:10:56 +00:00
|
|
|
}
|
2011-12-21 22:29:42 +00:00
|
|
|
static DEVICE_ATTR(address, 0444, show_cpu_address, NULL);
|
2008-01-26 13:10:56 +00:00
|
|
|
|
|
|
|
static struct attribute *cpu_common_attrs[] = {
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
2011-12-21 22:29:42 +00:00
|
|
|
&dev_attr_configure.attr,
|
2008-01-26 13:10:56 +00:00
|
|
|
#endif
|
2011-12-21 22:29:42 +00:00
|
|
|
&dev_attr_address.attr,
|
2008-01-26 13:10:56 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group cpu_common_attr_group = {
|
|
|
|
.attrs = cpu_common_attrs,
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-12-21 22:29:42 +00:00
|
|
|
static ssize_t show_capability(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-04-27 14:01:56 +00:00
|
|
|
{
|
|
|
|
unsigned int capability;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = get_cpu_capability(&capability);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
return sprintf(buf, "%u\n", capability);
|
|
|
|
}
|
2011-12-21 22:29:42 +00:00
|
|
|
static DEVICE_ATTR(capability, 0444, show_capability, NULL);
|
2007-04-27 14:01:56 +00:00
|
|
|
|
2011-12-21 22:29:42 +00:00
|
|
|
static ssize_t show_idle_count(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-10-22 10:52:39 +00:00
|
|
|
{
|
2012-03-11 15:59:27 +00:00
|
|
|
struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
|
2007-10-22 10:52:39 +00:00
|
|
|
unsigned long long idle_count;
|
2009-06-22 10:08:20 +00:00
|
|
|
unsigned int sequence;
|
2007-10-22 10:52:39 +00:00
|
|
|
|
2012-03-11 15:59:27 +00:00
|
|
|
do {
|
|
|
|
sequence = ACCESS_ONCE(idle->sequence);
|
|
|
|
idle_count = ACCESS_ONCE(idle->idle_count);
|
|
|
|
if (ACCESS_ONCE(idle->idle_enter))
|
|
|
|
idle_count++;
|
|
|
|
} while ((sequence & 1) || (idle->sequence != sequence));
|
2007-10-22 10:52:39 +00:00
|
|
|
return sprintf(buf, "%llu\n", idle_count);
|
|
|
|
}
|
2011-12-21 22:29:42 +00:00
|
|
|
static DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
|
2007-10-22 10:52:39 +00:00
|
|
|
|
2011-12-21 22:29:42 +00:00
|
|
|
static ssize_t show_idle_time(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-10-22 10:52:39 +00:00
|
|
|
{
|
2012-03-11 15:59:27 +00:00
|
|
|
struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
|
|
|
|
unsigned long long now, idle_time, idle_enter, idle_exit;
|
2009-06-22 10:08:20 +00:00
|
|
|
unsigned int sequence;
|
2007-10-22 10:52:39 +00:00
|
|
|
|
2012-03-11 15:59:27 +00:00
|
|
|
do {
|
|
|
|
now = get_clock();
|
|
|
|
sequence = ACCESS_ONCE(idle->sequence);
|
|
|
|
idle_time = ACCESS_ONCE(idle->idle_time);
|
|
|
|
idle_enter = ACCESS_ONCE(idle->idle_enter);
|
|
|
|
idle_exit = ACCESS_ONCE(idle->idle_exit);
|
|
|
|
} while ((sequence & 1) || (idle->sequence != sequence));
|
|
|
|
idle_time += idle_enter ? ((idle_exit ? : now) - idle_enter) : 0;
|
2008-12-31 14:11:40 +00:00
|
|
|
return sprintf(buf, "%llu\n", idle_time >> 12);
|
2007-10-22 10:52:39 +00:00
|
|
|
}
|
2011-12-21 22:29:42 +00:00
|
|
|
static DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL);
|
2007-10-22 10:52:39 +00:00
|
|
|
|
2008-01-26 13:10:56 +00:00
|
|
|
static struct attribute *cpu_online_attrs[] = {
|
2011-12-21 22:29:42 +00:00
|
|
|
&dev_attr_capability.attr,
|
|
|
|
&dev_attr_idle_count.attr,
|
|
|
|
&dev_attr_idle_time_us.attr,
|
2007-10-22 10:52:39 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2008-01-26 13:10:56 +00:00
|
|
|
static struct attribute_group cpu_online_attr_group = {
|
|
|
|
.attrs = cpu_online_attrs,
|
2007-10-22 10:52:39 +00:00
|
|
|
};
|
|
|
|
|
2007-04-27 14:01:56 +00:00
|
|
|
static int __cpuinit smp_cpu_notify(struct notifier_block *self,
|
|
|
|
unsigned long action, void *hcpu)
|
|
|
|
{
|
|
|
|
unsigned int cpu = (unsigned int)(long)hcpu;
|
2012-03-11 15:59:26 +00:00
|
|
|
struct cpu *c = &pcpu_devices[cpu].cpu;
|
2011-12-21 22:29:42 +00:00
|
|
|
struct device *s = &c->dev;
|
2007-10-22 10:52:39 +00:00
|
|
|
struct s390_idle_data *idle;
|
2010-05-26 21:43:34 +00:00
|
|
|
int err = 0;
|
2007-04-27 14:01:56 +00:00
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case CPU_ONLINE:
|
2007-05-09 09:35:10 +00:00
|
|
|
case CPU_ONLINE_FROZEN:
|
2007-10-22 10:52:39 +00:00
|
|
|
idle = &per_cpu(s390_idle, cpu);
|
2009-06-22 10:08:20 +00:00
|
|
|
memset(idle, 0, sizeof(struct s390_idle_data));
|
2010-05-26 21:43:34 +00:00
|
|
|
err = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
|
2007-04-27 14:01:56 +00:00
|
|
|
break;
|
|
|
|
case CPU_DEAD:
|
2007-05-09 09:35:10 +00:00
|
|
|
case CPU_DEAD_FROZEN:
|
2008-01-26 13:10:56 +00:00
|
|
|
sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
|
2007-04-27 14:01:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-05-26 21:43:34 +00:00
|
|
|
return notifier_from_errno(err);
|
2007-04-27 14:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block __cpuinitdata smp_cpu_nb = {
|
2007-04-27 14:02:00 +00:00
|
|
|
.notifier_call = smp_cpu_notify,
|
2007-04-27 14:01:56 +00:00
|
|
|
};
|
|
|
|
|
2008-02-05 15:50:40 +00:00
|
|
|
static int __devinit smp_add_present_cpu(int cpu)
|
2008-01-26 13:10:56 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct cpu *c = &pcpu_devices[cpu].cpu;
|
2011-12-21 22:29:42 +00:00
|
|
|
struct device *s = &c->dev;
|
2008-01-26 13:10:56 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
c->hotpluggable = 1;
|
|
|
|
rc = register_cpu(c, cpu);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
rc = sysfs_create_group(&s->kobj, &cpu_common_attr_group);
|
|
|
|
if (rc)
|
|
|
|
goto out_cpu;
|
2011-12-27 10:27:09 +00:00
|
|
|
if (cpu_online(cpu)) {
|
|
|
|
rc = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
|
|
|
|
if (rc)
|
|
|
|
goto out_online;
|
|
|
|
}
|
|
|
|
rc = topology_cpu_init(c);
|
|
|
|
if (rc)
|
|
|
|
goto out_topology;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_topology:
|
|
|
|
if (cpu_online(cpu))
|
|
|
|
sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
|
|
|
|
out_online:
|
2008-01-26 13:10:56 +00:00
|
|
|
sysfs_remove_group(&s->kobj, &cpu_common_attr_group);
|
|
|
|
out_cpu:
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
unregister_cpu(c);
|
|
|
|
#endif
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
2008-04-30 11:38:37 +00:00
|
|
|
|
2008-05-30 08:03:27 +00:00
|
|
|
int __ref smp_rescan_cpus(void)
|
2008-01-26 13:10:56 +00:00
|
|
|
{
|
2012-03-11 15:59:26 +00:00
|
|
|
struct sclp_cpu_info *info;
|
|
|
|
int nr;
|
2008-01-26 13:10:56 +00:00
|
|
|
|
2012-03-11 15:59:26 +00:00
|
|
|
info = smp_get_cpu_info();
|
|
|
|
if (!info)
|
|
|
|
return -ENOMEM;
|
2008-01-26 13:11:31 +00:00
|
|
|
get_online_cpus();
|
2008-04-30 11:38:36 +00:00
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2012-03-11 15:59:26 +00:00
|
|
|
nr = __smp_rescan_cpus(info, 1);
|
2008-01-26 13:10:56 +00:00
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
2008-04-30 11:38:36 +00:00
|
|
|
put_online_cpus();
|
2012-03-11 15:59:26 +00:00
|
|
|
kfree(info);
|
|
|
|
if (nr)
|
2008-04-17 05:46:13 +00:00
|
|
|
topology_schedule_update();
|
2012-03-11 15:59:26 +00:00
|
|
|
return 0;
|
2008-04-30 11:38:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-21 22:29:42 +00:00
|
|
|
static ssize_t __ref rescan_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 11:47:58 +00:00
|
|
|
const char *buf,
|
2008-04-30 11:38:37 +00:00
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = smp_rescan_cpus();
|
2008-01-26 13:10:56 +00:00
|
|
|
return rc ? rc : count;
|
|
|
|
}
|
2011-12-21 22:29:42 +00:00
|
|
|
static DEVICE_ATTR(rescan, 0200, NULL, rescan_store);
|
2008-01-26 13:10:56 +00:00
|
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
|
|
|
|
2011-12-27 10:27:09 +00:00
|
|
|
static int __init s390_smp_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-12-27 10:27:09 +00:00
|
|
|
int cpu, rc;
|
2007-04-27 14:01:56 +00:00
|
|
|
|
|
|
|
register_cpu_notifier(&smp_cpu_nb);
|
2008-01-26 13:10:56 +00:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
2011-12-21 22:29:42 +00:00
|
|
|
rc = device_create_file(cpu_subsys.dev_root, &dev_attr_rescan);
|
2008-01-26 13:10:56 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
#endif
|
|
|
|
for_each_present_cpu(cpu) {
|
|
|
|
rc = smp_add_present_cpu(cpu);
|
2007-10-22 10:52:39 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-27 10:27:09 +00:00
|
|
|
subsys_initcall(s390_smp_init);
|